Exemplo n.º 1
0
/***************************************************************************************************
 * @fn          MT_SpiWriteCfg
 *
 * @brief       Process Write Configuration Command
 *
 * @param       pBuf - pointer to received buffer
 *
 * @return      none
 ***************************************************************************************************/
void MT_SapiWriteCfg(uint8 *pBuf)
{
  uint8 retValue, cmdId;

  /* Parse header */
  cmdId = pBuf[MT_RPC_POS_CMD1];
  pBuf += MT_RPC_FRAME_HDR_SZ;

  if ((pBuf[0] != ZCD_NV_NIB) && (pBuf[0] != ZCD_NV_DEVICE_LIST) &&
      (pBuf[0] != ZCD_NV_ADDRMGR) && (pBuf[0] != ZCD_NV_NWKKEY))
  {
    if ((zb_WriteConfiguration(pBuf[0], pBuf[1], &pBuf[2])) == ZSUCCESS)
    {
      retValue = ZSuccess;
    }
    else
    {
      retValue = ZFailure;
    }
  }
  else
  {
    retValue = ZInvalidParameter;
  }

  /* Build and send back the response */
  MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SAPI), cmdId, 1, &retValue );
}
Exemplo n.º 2
0
void zb_StartDevice(struct bmi_zb *zb, unsigned char option)
{
	zb_WriteConfiguration(zb,ZCD_NV_STARTUP_OPTION,1,&option);
	zb_Reset(zb,ZB_RESET);   
	udelay(10);
	zb_Reset(zb,ZB_RELEASE); 
}
Exemplo n.º 3
0
/**
 * @brief   Maneja los eventos de teclas, generados cuando ocurre un pulsación
 *          en el joystick de la placa.
 * @param   shift   true si shift/alt está presionado.
 * @param   keys    Mascara de bits para los eventos de teclado. Válidos:
 *                  EVAL_SW4, EVAL_SW3, EVAL_SW2, EVAL_SW1.
 */
void zb_HandleKeys(uint8 shift, uint8 keys)
{
    static uint8 allowJoin = TRUE;
    uint8 logicalType;
    
    if (keys & HAL_KEY_CENTER)
    {
        if (appState == APP_INIT)
        {
            // configura el dispositivo como coordinador
            logicalType = ZG_DEVICETYPE_COORDINATOR;
            zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType);
            zb_SystemReset();
        }
    }
    if (keys & HAL_KEY_UP)
    {
        // configura condición de máxima carga (I RMS) en pasos de 0.1 A, hasta 2 A
        if (alarm_max_irms > 2)
            alarm_max_irms = 0.1;
        else
            alarm_max_irms += 0.1;
        HalLcdWriteString("MAX I RMS (mA)", HAL_LCD_LINE_1);
        HalLcdWriteStringValue("", (int)(alarm_max_irms*1000), 10, 2);
    }
    if (keys & HAL_KEY_DOWN)    // joystick abajo
    {
        // configura condicion de máximo consumo (E) en pasos de 50 Ws, hasta 400 Ws
        if (alarm_max_energy > 400)
            alarm_max_energy = 50;
        else
            alarm_max_energy += 50;
        HalLcdWriteString("MAX ENERGIA (Ws)", HAL_LCD_LINE_1);
        HalLcdWriteStringValue("", alarm_max_energy, 10, 2);
    }
    if (keys & HAL_KEY_RIGHT)    // joystick derecha
    {
        // inicia evento para pruebas
        msgReport.sequence = 0;
        osal_start_timerEx(sapi_TaskID, MY_TEST_EVT, 5000);
    }
    if (keys & HAL_KEY_LEFT)    // joystick izquierda
    {
        // controla si el dispositivo acepta join requests
        // refleja este estado en el LED 3
        allowJoin ^= 1;
        if (allowJoin)
        {
            NLME_PermitJoiningRequest(0xFF);
            HalLedSet(HAL_LED_3, HAL_LED_MODE_ON);
        }
        else
        {
            NLME_PermitJoiningRequest(0);
            HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF);
        }
    }
}
/*********************************************************************
 * @fn      SAPI_Init
 *
 * @brief   Initialization function for the Simple API Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notification ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void SAPI_Init( byte task_id )
{
  sapi_TaskID = task_id;
  sapi_bindInProgress = 0xffff;

  sapi_epDesc.task_id = &sapi_TaskID;
  sapi_epDesc.endPoint = 0;
  
#if ( SAPI_CB_FUNC )
  sapi_epDesc.endPoint = zb_SimpleDesc.EndPoint;
  sapi_epDesc.task_id = &sapi_TaskID;
  sapi_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&zb_SimpleDesc;
  sapi_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint/interface description with the AF
  afRegister( &sapi_epDesc );
#endif

  // Turn off match descriptor response by default
  afSetMatch(sapi_epDesc.simpleDesc->EndPoint, FALSE);

  // Register callback evetns from the ZDApp
  ZDO_RegisterForZDOMsg( sapi_TaskID, NWK_addr_rsp );
  ZDO_RegisterForZDOMsg( sapi_TaskID, Match_Desc_rsp );

#if ( SAPI_CB_FUNC )
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
  // Register for HAL events
  RegisterForKeys( sapi_TaskID );

  if ( HalKeyRead () == HAL_KEY_SW_5)
  {
    // If SW5 is pressed and held while powerup, force auto-start and nv-restore off and reset
    uint8 startOptions = ZCD_STARTOPT_CLEAR_STATE | ZCD_STARTOPT_CLEAR_CONFIG;
    zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions );
    zb_SystemReset();
  }
#endif // HAL_KEY

  // Set an event to start the application
  osal_set_event(task_id, ZB_ENTRY_EVENT);
#endif
}
Exemplo n.º 5
0
/*********************************************************************
 * @fn      zb_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 EVAL_SW4
 *                 EVAL_SW3
 *                 EVAL_SW2
 *                 EVAL_SW1
 *
 * @return  none
 */
void zb_HandleKeys( uint8 shift, uint8 keys )
{
  uint8 startOptions;
  uint8 logicalType;

  // Shift is used to make each button/switch dual purpose.
  if ( shift )
  {
    if ( keys & HAL_KEY_SW_1 )
    {
    }
    if ( keys & HAL_KEY_SW_2 )
    {
    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
  else
  {
    if ( keys & HAL_KEY_SW_1 )
    {
      if ( myAppState == APP_INIT  )
      {
        // In the init state, keys are used to indicate the logical mode.
        // Key 1 starts device as a coordinator

        zb_ReadConfiguration( ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType );
        if ( logicalType != ZG_DEVICETYPE_ENDDEVICE )
        {
          logicalType = ZG_DEVICETYPE_COORDINATOR;
          zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType);
        }

        // Do more configuration if necessary and then restart device with auto-start bit set
        // write endpoint to simple desc...dont pass it in start req..then reset


        zb_ReadConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions );
        startOptions = ZCD_STARTOPT_AUTO_START;
        zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions );
        zb_SystemReset();

      }
      else
      {
        // Turn ON Allow Bind mode indefinitely
        zb_AllowBind( 0xFF );
        HalLedSet( HAL_LED_1, HAL_LED_MODE_ON );
      }
    }
    if ( keys & HAL_KEY_SW_2 )
    {
      if ( myAppState == APP_INIT )
      {
        // In the init state, keys are used to indicate the logical mode.
        // Key 2 starts device as a router

        zb_ReadConfiguration( ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType );
        if ( logicalType != ZG_DEVICETYPE_ENDDEVICE )
        {
          logicalType = ZG_DEVICETYPE_ROUTER;
          zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType);
        }

        zb_ReadConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions );
        startOptions = ZCD_STARTOPT_AUTO_START;
        zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions );
        zb_SystemReset();
      }
      else
      {
        // Turn OFF Allow Bind mode indefinitely
        zb_AllowBind( 0x00 );
        HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );
      }
    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
}
Exemplo n.º 6
0
/******************************************************************************
 * @fn      zb_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 EVAL_SW4
 *                 EVAL_SW3
 *                 EVAL_SW2
 *                 EVAL_SW1
 *
 * @return  none
 */
void zb_HandleKeys( uint8 shift, uint8 keys )
{
  static uint8 allowBind=FALSE;
  static uint8 allowJoin=TRUE;
  uint8 logicalType;  
  
  // Shift is used to make each button/switch dual purpose.
  if ( shift )
  {
    if ( keys & HAL_KEY_SW_1 )
    {
    }
    if ( keys & HAL_KEY_SW_2 )
    {
    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
  else
  {
    if ( keys & HAL_KEY_SW_1 )
    {
      if ( appState == APP_INIT  )
      {
        // Key 1 starts device as a coordinator
        logicalType = ZG_DEVICETYPE_COORDINATOR;
        zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType);
                
        // Reset the device with new configuration
        zb_SystemReset();
      }
    }
    if ( keys & HAL_KEY_SW_2 )
    {
      allowBind ^= 1;
      if (allowBind) 
      {
        // Turn ON Allow Bind mode infinitly
        zb_AllowBind( 0xFF );
        HalLedSet( HAL_LED_2, HAL_LED_MODE_ON );
        //This node is the gateway node
        isGateWay = TRUE;
        
        // Update the display
        #if defined ( LCD_SUPPORTED )
        HalLcdWriteString( "Gateway Mode", HAL_LCD_LINE_2 );
        #endif
      }
      else
      {
        // Turn OFF Allow Bind mode infinitly
        zb_AllowBind( 0x00 );
        HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF );
        isGateWay = FALSE;
        
        // Update the display
        #if defined ( LCD_SUPPORTED )
        HalLcdWriteString( "Collector", HAL_LCD_LINE_2 );
        #endif
      }
    }
    if ( keys & HAL_KEY_SW_3 )
    {
      // Start reporting
      osal_set_event( sapi_TaskID, MY_REPORT_EVT );
    }
    if ( keys & HAL_KEY_SW_4 )
    {
      // Key 4 is used to control which routers 
      // that can accept join requests
      allowJoin ^= 1;
      if(allowJoin)
      {
        NLME_PermitJoiningRequest(0xFF);
      }
      else {
        NLME_PermitJoiningRequest(0);
      }
    }
#if 0
    if( keys & HAL_KEY_SW_6 )
    {
      if( onoff )
      {
        st( P0_5 = !1; );
        onoff = 0;
      }
      else
      {
        st(P0_5 = !!1; );
        onoff = 1;
      }