예제 #1
0
/**
 * @brief   Esta función es llamada por el SO cuando se debe atender un
 *          evento de la tarea.
 * @param   event   Mascara de bits conteniendo los eventos a atender
 */
void zb_HandleOsalEvent(uint16 event)
{
    uint8 logicalType;
    
    if (event & SYS_EVENT_MSG)
    {      
    }
    if (event & ZB_ENTRY_EVENT)
    {  
        // inicializa UART
        initUart(uartRxCB);
        // blick LED 1 para indicar que se está uniendo a la red
        HalLedBlink(HAL_LED_1, 0, 50, 500 );
        HalLedSet(HAL_LED_2, HAL_LED_MODE_OFF);   
        // lee tipo de logical device desde la memoria NV
        zb_ReadConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType);
        // inicia la red
        zb_StartRequest();
    }
    if (event & MY_START_EVT)
    {
        // inicia la red
        zb_StartRequest();
    }
    if (event & SEND_UART_MSG)
    {
        // envia mensaje por UART a la PC
        //HalLcdWriteString("UART_EVT", HAL_LCD_LINE_1);
        sendUartMessage(&msgReport, &alarmFlags);
    }
    if (event & MY_TEST_EVT)
    {
        // crea mensaje de prueba
        msgReport.msgType = MSG_TYPE_REPORT;
        msgReport.sequence++;
        msgReport.lenData = MSG_LEN_DATA_REPORT;
        for (uint8 i = 0; i < 8; i++)
            msgReport.mac[i] = i;
        // datos de prueba
        static double d[10] = {220.5, 0.354, 85.12, 88.33, 85.06, 0.98, 1.23, 3.25, 0.97, 4.55};
        for (int i = 0; i < 10; i++)
            memcpy(&(msgReport.data[i*4]), &(d[i]), sizeof(double));
        // flags de prueba
        uint16 flags = 0;
        // imprime info en LCD
        HalLcdWriteString("TEST_EVT", HAL_LCD_LINE_1);
        HalLcdWriteStringValue("#", msgReport.sequence, 10, HAL_LCD_LINE_2);
        // envia mensaje por UART
        sendUartMessage(&msgReport, &flags);
        // crea evento nuevamente
        osal_start_timerEx(sapi_TaskID, MY_TEST_EVT, 5000);
    }
}
/*********************************************************************
 * @fn      zclSampleTemperatureSensor_ProcessIdentifyTimeChange
 *
 * @brief   Called to process any change to the IdentifyTime attribute.
 *
 * @param   none
 *
 * @return  none
 */
static void zclSampleTemperatureSensor_ProcessIdentifyTimeChange( void )
{
  if ( zclSampleTemperatureSensor_IdentifyTime > 0 )
  {
    osal_start_timerEx( zclSampleTemperatureSensor_TaskID, SAMPLETEMPERATURESENSOR_IDENTIFY_TIMEOUT_EVT, 1000 );
    HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  }
  else
  {
    if ( zclSampleTemperatureSensor_OnOff )
    {
      HalLedSet ( HAL_LED_4, HAL_LED_MODE_ON );
    }
    else
    {
      HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
    }

    osal_stop_timerEx( zclSampleTemperatureSensor_TaskID, SAMPLETEMPERATURESENSOR_IDENTIFY_TIMEOUT_EVT );
  }
}
/*********************************************************************
 * @fn      zclSampleTemperatureSensor_LcdDisplayUpdate
 *
 * @brief   Called to update the LCD display.
 *
 * @param   none
 *
 * @return  none
 */
void zclSampleTemperatureSensor_LcdDisplayUpdate( void )
{
  // turn on red LED for temperatures >= 24.00C
  if ( zclSampleTemperatureSensor_MeasuredValue >= 2400 )
  {
    HalLedSet ( HAL_LED_1, HAL_LED_MODE_OFF );
    HalLedSet ( HAL_LED_2, HAL_LED_MODE_ON );
  }
  // turn on green LED for temperatures <= 20.00C
  else if ( zclSampleTemperatureSensor_MeasuredValue <= 2000 )
  {
    HalLedSet ( HAL_LED_1, HAL_LED_MODE_ON );
    HalLedSet ( HAL_LED_2, HAL_LED_MODE_OFF );
  }
  // turn on both red and green LEDs for temperatures between 20.00C and 24.00C
  else
  {
    HalLedSet ( HAL_LED_1, HAL_LED_MODE_ON );
    HalLedSet ( HAL_LED_2, HAL_LED_MODE_ON );
  }

  if ( giTemperatureSensorScreenMode == TEMPSENSE_HELPMODE )
  {
    zclSampleTemperatureSensor_LcdDisplayHelpMode();
  }
  else
  {
    zclSampleTemperatureSensor_LcdDisplayMainMode();
  }
}
예제 #4
0
/*********************************************************************
 * @fn      zclSampleSw_ProcessZDOMsgs()
 *
 * @brief   Process response messages
 *
 * @param   none
 *
 * @return  none
 */
void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
{
  switch ( inMsg->clusterID )
  {
    case End_Device_Bind_rsp:
      if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
      {
        // Light LED
        HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
      }
#if defined(BLINK_LEDS)
      else
      {
        // Flash LED to show failure
        HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
      }
#endif
      break;

    case Match_Desc_rsp:
      {
        ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
        if ( pRsp )
        {
          if ( pRsp->status == ZSuccess && pRsp->cnt )
          {
            zclSampleSw_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
            zclSampleSw_DstAddr.addr.shortAddr = pRsp->nwkAddr;
            // Take the first endpoint, Can be changed to search through endpoints
            zclSampleSw_DstAddr.endPoint = pRsp->epList[0];

            // Light LED
            HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
          }
          osal_mem_free( pRsp );
        }
      }
      break;
  }
}
예제 #5
0
/*********************************************************************
 * @fn      SimpleBLECentral_Init
 *
 * @brief   Initialization function for the Simple BLE Central App 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 SimpleBLECentral_Init( uint8 task_id )
{
  simpleBLETaskId = task_id;

  // 串口初始化
  NPI_InitTransport(uart_NpiSerialCallback); 
  //NPI_WriteTransport("SimpleBLECentral_Init\r\n", 23);

  // Setup Central Profile
  {
    uint8 scanRes = DEFAULT_MAX_SCAN_RES;
    GAPCentralRole_SetParameter ( GAPCENTRALROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );
  }
  
  // Setup GAP
  GAP_SetParamValue( TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION );
  GAP_SetParamValue( TGAP_LIM_DISC_SCAN, DEFAULT_SCAN_DURATION );
  GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (uint8 *) simpleBLEDeviceName );

  // Setup the GAP Bond Manager
  {
    uint32 passkey = DEFAULT_PASSCODE;
    uint8 pairMode = DEFAULT_PAIRING_MODE;
    uint8 mitm = DEFAULT_MITM_MODE;
    uint8 ioCap = DEFAULT_IO_CAPABILITIES;
    uint8 bonding = DEFAULT_BONDING_MODE;
    GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof( uint32 ), &passkey );
    GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof( uint8 ), &pairMode );
    GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof( uint8 ), &mitm );
    GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof( uint8 ), &ioCap );
    GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof( uint8 ), &bonding );
  }  

  // Initialize GATT Client
  VOID GATT_InitClient();

  // Register to receive incoming ATT Indications/Notifications
  GATT_RegisterForInd( simpleBLETaskId );

  // Initialize GATT attributes
  GGS_AddService( GATT_ALL_SERVICES );         // GAP
  GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes

  // Register for all key events - This app will handle all key events
  RegisterForKeys( simpleBLETaskId );
  
  // makes sure LEDs are off
  HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF );
  
  // Setup a delayed profile startup
  osal_set_event( simpleBLETaskId, START_DEVICE_EVT );
}
예제 #6
0
파일: SampleApp.c 프로젝트: howar82003/LLL
/*********************************************************************
 * @fn      SampleApp_MessageMSGCB
 *
 * @brief   Data message processor callback.  This function processes
 *          any incoming data - probably from other devices.  So, based
 *          on cluster ID, perform the intended action.
 *
 * @param   none
 *
 * @return  none
 */
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) //接收數據
{
 // uint16 flashTime;
  
  switch ( pkt->clusterId )
  {
    
    case SAMPLEAPP_P2P_CLUSTERID:
      osal_memcpy(periodicData, pkt->cmd.Data, 27);
      LedState=LedState+1;
      if(LedState == 1)
         HalLedSet(HAL_LED_3, HAL_LED_MODE_ON);
      else if(LedState == 2)
         {HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF);
          LedState=0;}
      break;

    case SAMPLEAPP_PERIODIC_CLUSTERID:
      // osal_memset(periodicData, 0 , 15);
      osal_memcpy(periodicData, pkt->cmd.Data, 27);
      
       LedState=LedState+1;
      // HalUARTWrite(0, "Rx:", 3);        //提示信息
      // HalUARTWrite(0, pkt->cmd.Data, pkt->cmd.DataLength); //輸出接收到的數據
      // HalUARTWrite(0, "\n", 1);         //迴車換行
   
        if(LedState == 1)
         HalLedSet(HAL_LED_3, HAL_LED_MODE_ON);
        else if(LedState == 2)
         {HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF);
          LedState=0;}
      break;

    case SAMPLEAPP_FLASH_CLUSTERID:     //此實驗沒有使用,到後面實驗詳解
    //   flashTime = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[2] );
       HalLedBlink( HAL_LED_3, 2, 25 ,100 );
       break;
  }
}
예제 #7
0
/*********************************************************************
 * @fn      rangeext_ProcessIdentifyTimeChange
 *
 * @brief   Called to blink led for specified IdentifyTime attribute value
 *
 * @param   none
 *
 * @return  none
 */
static void rangeext_ProcessIdentifyTimeChange( void )
{
  if ( rangeExtIdentifyTime > 0 )
  {
    osal_start_timerEx( rangeExtTaskID, RANGEEXT_IDENTIFY_TIMEOUT_EVT, 1000 );
    HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  }
  else
  {
    HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
    osal_stop_timerEx( rangeExtTaskID, RANGEEXT_IDENTIFY_TIMEOUT_EVT );
  }
}
예제 #8
0
/*********************************************************************
 * @fn      zclSampleLight_ProcessIdentifyTimeChange
 *
 * @brief   Called to process any change to the IdentifyTime attribute.
 *
 * @param   none
 *
 * @return  none
 */
static void zclSampleLight_ProcessIdentifyTimeChange( void )
{
  
  if ( zclSampleLight_IdentifyTime > 0 )
  {
    osal_start_timerEx( zclSampleLight_TaskID, SAMPLELIGHT_IDENTIFY_TIMEOUT_EVT, 1000 );
    HalLedBlink ( HAL_LED_1, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  }
  else
  {
    if ( zclSampleLight_OnOff )
    {
      HalLedSet ( HAL_LED_2, HAL_LED_MODE_ON );
    }
    else
      {
        HalLedSet ( HAL_LED_2, HAL_LED_MODE_OFF );
        osal_stop_timerEx( zclSampleLight_TaskID, SAMPLELIGHT_IDENTIFY_TIMEOUT_EVT );
      }
      
  }
}
예제 #9
0
/*********************************************************************
 * @fn      loadcontrol_ProcessIdentifyTimeChange
 *
 * @brief   Called to blink led for specified IdentifyTime attribute value
 *
 * @param   none
 *
 * @return  none
 */
static void loadcontrol_ProcessIdentifyTimeChange( void )
{
  if ( loadControlIdentifyTime > 0 )
  {
    osal_start_timerEx( loadControlTaskID, LOADCONTROL_IDENTIFY_TIMEOUT_EVT, 1000 );
    HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  }
  else
  {
    HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
    osal_stop_timerEx( loadControlTaskID, LOADCONTROL_IDENTIFY_TIMEOUT_EVT );
  }
}
예제 #10
0
/*********************************************************************
 * @fn      keyfobapp_StopAlert
 *
 * @brief   Stops an alert
 *
 * @param   none
 *
 * @return  none
 */
void keyfobapp_StopAlert( void )
{

  keyfobAlertState = ALERT_STATE_OFF;

  buzzerStop();
  buzzer_state = BUZZER_OFF;
  HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF );


  #if defined ( POWER_SAVING )
    osal_pwrmgr_device( PWRMGR_BATTERY );
  #endif
}
예제 #11
0
파일: MT_UTIL.c 프로젝트: 12019/hellowsn
/***************************************************************************************************
 * @fn      MT_UtilLedControl
 *
 * @brief   Process the LED Control Message
 *
 * @param   pBuf - pointer to the received data
 *
 * @return  None
 ***************************************************************************************************/
void MT_UtilLedControl(uint8 *pBuf)
{
  uint8 iLed, Led, iMode, Mode, cmdId;
  uint8 retValue = ZFailure;

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

  /* LED and Mode */
  iLed = *pBuf++;
  iMode = *pBuf;

  if ( iLed == 1 )
    Led = HAL_LED_1;
  else if ( iLed == 2 )
    Led = HAL_LED_2;
  else if ( iLed == 3 )
    Led = HAL_LED_3;
  else if ( iLed == 4 )
    Led = HAL_LED_4;
  else if ( iLed == 0xFF )
    Led = HAL_LED_ALL;
  else
    Led = 0;

  if ( iMode == 0 )
    Mode = HAL_LED_MODE_OFF;
  else if ( iMode == 1 )
    Mode = HAL_LED_MODE_ON;
  else if ( iMode == 2 )
    Mode = HAL_LED_MODE_BLINK;
  else if ( iMode == 3 )
    Mode = HAL_LED_MODE_FLASH;
  else if ( iMode == 4 )
    Mode = HAL_LED_MODE_TOGGLE;
  else
    Led = 0;

  if ( Led != 0 )
  {
    HalLedSet (Led, Mode);
    retValue = ZSuccess;
  }

  /* Build and send back the response */
  MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue );

}
예제 #12
0
/*********************************************************************
 * @fn      zclSampleLight_OnOffCB
 *
 * @brief   Callback from the ZCL General Cluster Library when
 *          it received an On/Off Command for this application.
 *
 * @param   cmd - COMMAND_ON, COMMAND_OFF or COMMAND_TOGGLE
 *
 * @return  none
 */
static void zclSampleLight_OnOffCB( uint8 cmd )
{ 
  if ( cmd == COMMAND_ON )// Turn on the light
    zclSampleLight_OnOff = LIGHT_ON;

  else if ( cmd == COMMAND_OFF )// Turn off the light
    zclSampleLight_OnOff = LIGHT_OFF;

  else // Toggle the light
  {
    if ( zclSampleLight_OnOff == LIGHT_OFF )
          zclSampleLight_OnOff = LIGHT_ON;
    else
          zclSampleLight_OnOff = LIGHT_OFF;
  }

  // In this sample app, we use LED4 to simulate the Light  
  if ( zclSampleLight_OnOff == LIGHT_ON )
  {
    HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); // setting the LED_1 on
  }
  else
    HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF ); // setting the LED_1 off
}
예제 #13
0
/***************************************************************************************************
 * @fn      HalLedInit
 *
 * @brief   Initialize LED Service
 *
 * @param   init - pointer to void that contains the initialized value
 *
 * @return  None
 ***************************************************************************************************/
void HalLedInit (void)
{
#if (HAL_LED == TRUE)
  HAL_TURN_OFF_LED1();
  LED1_DDR |= LED1_BV;
  HAL_TURN_OFF_LED2();
  LED2_DDR |= LED2_BV;
  /* Initialize all LEDs to OFF */
  HalLedSet (HAL_LED_ALL, HAL_LED_MODE_OFF);
#endif /* HAL_LED */
#ifdef BLINK_LEDS
  /* Initialize sleepActive to FALSE */
  HalLedStatusControl.sleepActive = FALSE;
#endif
}
예제 #14
0
/*********************************************************************
 * @fn      zllSampleBridge_ProcessIdentifyTimeChange
 *
 * @brief   Called to process any change to the IdentifyTime attribute.
 *
 * @param   none
 *
 * @return  none
 */
static void zllSampleBridge_ProcessIdentifyTimeChange( void )
{
  if ( zllSampleBridge_IdentifyTime > 0 )
  {
    osal_start_timerEx( zllSampleBridge_TaskID, SAMPLEBRIDGE_IDENTIFY_TIMEOUT_EVT, 1000 );
#if ( HAL_LED == TRUE )
    HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
#endif
  }
  else
  {
#if ( HAL_LED == TRUE )
    HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
#endif
    osal_stop_timerEx( zllSampleBridge_TaskID, SAMPLEBRIDGE_IDENTIFY_TIMEOUT_EVT );
  }
}
예제 #15
0
/*********************************************************************
 * @fn      InitBoard()
 * @brief   Initialize the CC2540DB Board Peripherals
 * @param   level: COLD,WARM,READY
 * @return  None
 */
void InitBoard( uint8 level )
{
  if ( level == OB_COLD )
  {
    // Interrupts off
    osal_int_disable( INTS_ALL );
    // Turn all LEDs off
    HalLedSet( HAL_LED_ALL, HAL_LED_MODE_OFF );
    // Check for Brown-Out reset
    // ChkReset();
  }
  else  // !OB_COLD
  {
    /* Initialize Key stuff */
    OnboardKeyIntEnable = HAL_KEY_INTERRUPT_ENABLE;
    HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback);
  }
}
예제 #16
0
파일: hal_led.c 프로젝트: nevinxu/HM502B1
/***************************************************************************************************
 * @fn      HalLedInit
 *
 * @brief   Initialize LED Service
 *
 * @param   init - pointer to void that contains the initialized value
 *
 * @return  None
 ***************************************************************************************************/
void HalLedInit (void)
{
#if (HAL_LED == TRUE)
  HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF);  // Initialize all LEDs to OFF.

  // Set LED GPIOs to outputs.
  LED1_DDR |= LED1_BV;
  LED2_DDR |= LED2_BV;
//#if (!defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590)
//  LED2_DDR |= LED2_BV;
//#if (!defined CC2540_MINIDK && !defined HAL_BOARD_CC2540USB)
//  LED3_DDR |= LED3_BV;
//#endif
//#endif
#if defined BLINK_LEDS
  HalLedStatusControl.sleepActive = FALSE;  // Initialize sleepActive to FALSE.
#endif
#endif
}
예제 #17
0
/**
 * @brief   Este callback es llamado por el stack de ZigBee luego de que la 
 *          operación de Start Request es completada.
 * @param   status  El estado de la operación. ZB_SUCCESS indica que la
 *                  operación fue completada exitosamente. Sino, el estado es
 *                  un código de error.
 */
void zb_StartConfirm(uint8 status)
{ 
    // si el dispositivo se inicio correctamente, cambia el estado
    if (status == ZB_SUCCESS)
    {
        // enciende LED 1 para indicar que el coordinador inició la red
        HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
        // actualiza display LCD
        HalLcdWriteString("COORD. INICIADO", HAL_LCD_LINE_1);
        HalLcdWriteString("", HAL_LCD_LINE_2);
        // cambia estado de la app a iniciada
        appState = APP_START;
    }
    else
    {
        // reintenta iniciarse con un tiempo de espera
        osal_start_timerEx(sapi_TaskID, MY_START_EVT, myStartRetryDelay);
    }
}
예제 #18
0
파일: uApp.c 프로젝트: DRuffer/coinForth
/*********************************************************************
 * @fn      GenericApp_ProcessEvent
 *
 * @brief   Generic Application Task event processor.  This function
 *          is called to process all events for the task.  Events
 *          include timers, messages and any other user defined events.
 *
 * @param   task_id  - The OSAL assigned task ID.
 * @param   events - events to process.  This is a bit map and can
 *                   contain more than one event.
 *
 * @return  none
 */
uint16 uApp_ProcessEvent( uint8 task_id, uint16 events )
{
  if ( events & SYS_EVENT_MSG )
  {
    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }
  
  if ( events & UAPP_EVENT_1)
  {
	  HalLedSet(HAL_LED_4, HAL_LED_MODE_TOGGLE);
	  osal_start_timerEx(uApp_TaskID, UAPP_EVENT_1, 500);
	  //osal_set_event(uApp_TaskID, UAPP_EVENT_1);
	  return events ^ UAPP_EVENT_1;
  }

  // Discard unknown events
  return 0;
}
예제 #19
0
/*********************************************************************
 * @fn      HalSensorTest
 *
 * @brief   Run a self-test on all the sensors
 *
 * @param   none
 *
 * @return  bitmask of error flags
 */
uint16 HalSensorTest(void)
{
  uint16 i;
  uint8 selfTestResult;

  halSensorEnableMap = 0;
  selfTestResult = 0;
  HalGyroTurnOn();

  for  (i=0; i<N_TEST_RUNS; i++)
  {
    HalLedSet(HAL_LED_2,HAL_LED_MODE_TOGGLE);

    // 1. Temp sensor test
    if (HalIRTempTest())
      selfTestResult |= ST_IRTEMP;

    // 2. Humidity  sensor test
    if (HalHumiTest())
      selfTestResult |= ST_HUMID;

    // 3. Magnetometer test
    if (HalMagTest())
      selfTestResult |= ST_MAGN;

    // 4. Accelerometer test
    if (HalAccTest())
      selfTestResult |= ST_ACC;

    // 5. Barometer test
    if (HalBarTest())
      selfTestResult |= ST_PRESS;

    // 6. Gyro test
    if (HalGyroTest())
      selfTestResult |= ST_GYRO;
  }

  HalGyroTurnOff();

  return selfTestResult;
}
예제 #20
0
/*********************************************************************
 * @fn      TransmitApp_MessageMSGCB
 *
 * @brief   Data message processor callback.  This function processes
 *          any incoming data - probably from other devices.  So, based
 *          on cluster ID, perform the intended action.
 *
 * @param   none
 *
 * @return  none
 */
void TransmitApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
  int16 i;
  uint8 error = FALSE;

  switch ( pkt->clusterId )
  {
    case TRANSMITAPP_CLUSTERID_TESTMSG:
      if (pkt->cmd.DataLength != TransmitApp_MaxDataLength)
      {
        error = TRUE;
      }

      for (i=4; i<pkt->cmd.DataLength; i++)
      {
        if (pkt->cmd.Data[i] != i%256)
          error = TRUE;
      }

      if (error)
      {
        // Display error LED
        HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
      }
      else
      {
        if ( !timerOn )
        {
          osal_start_timerEx( TransmitApp_TaskID, TRANSMITAPP_RCVTIMER_EVT,
                                                  TRANSMITAPP_DISPLAY_TIMER );
          clkShdw = osal_GetSystemClock();
          timerOn = TRUE;
        }
        rxAccum += pkt->cmd.DataLength;
      }
      break;

    // Could receive control messages in the future.
    default:
      break;
  }
}
예제 #21
0
/* Private functions ---------------------------------------------------------*/
void APP_Init(u8 task_id)
{
	//LoRaMacAppPara_t appData;

	//LoRaMacMacPara_t macData;

	//LoRaMacAppPara_t g_appData;
    //LoRaMacMacPara_t g_macData;

	APP_taskID = task_id;

	g_appData.devAddr = 0x00120560;
	LoRaMac_setAppLayerParameter(&g_appData, PARAMETER_DEV_ADDR);
	LoRaMac_getAppLayerParameter(&g_appData, PARAMETER_DEV_ADDR);
	APP_ShowMoteID(g_appData.devAddr);


	//memset( &g_macData , 0 , sizeof(g_macData) );
	//g_macData.channels[0].Frequency = 779500000;
	//g_macData.channels[0].DrRange.Value = 0x50;
	//g_macData.channels[0].Band = 0;

#if 0
	g_macData.channels[1].Frequency = 779500000;
	g_macData.channels[1].DrRange.Value = 0x50;
	g_macData.channels[1].Band = 0;

	g_macData.channels[2].Frequency = 779500000;
	g_macData.channels[2].DrRange.Value = 0x50;
	g_macData.channels[2].Band = 0;

	LoRaMac_setMacLayerParameter(&g_macData, PARAMETER_CHANNELS);
#endif

	//RedLED(OFF);
	//GreenLED(OFF);
	HalLedSet (HAL_LED_ALL, HAL_LED_MODE_OFF);

 	osal_set_event(APP_taskID,APP_PERIOD_SEND);
  //osal_set_event(APP_taskID,APP_TEST_UART);

}
예제 #22
0
/*********************************************************************
 * @fn      testChangeCB
 *
 * @brief   Callback from Test indicating a value change
 *
 * @param   paramID - parameter ID of the value that was changed.
 *
 * @return  none
 */
static void testChangeCB( uint8 paramID )
{
  if( paramID == TEST_CONF_ATTR )
  {
    uint8 newValue;

    Test_GetParameter( TEST_CONF_ATTR, &newValue );

    if (newValue & TEST_MODE_ENABLE)
    {
      testMode = TRUE;
    }
    else
    {
      testMode = FALSE;
    }

    if (testMode)
    {
      // Test mode: possible to operate LEDs. Key hits will cause notifications,
      // side key does not influence connection state
      if (newValue & 0x01)
      {
        HalLedSet(HAL_LED_1,HAL_LED_MODE_ON);
      }
      else
      {
        HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF);
      }

      if (newValue & 0x02)
      {
        HalLedSet(HAL_LED_2,HAL_LED_MODE_ON);
      }
      else
      {
        HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF);
      }
    }
    else
    {
      // Normal mode; make sure LEDs are reset and attribute cleared
      HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF);
      HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF);
      newValue = 0x00;
      Test_SetParameter( TEST_CONF_ATTR, 1, &newValue );
    }
  }
}
예제 #23
0
/******************************************************************************
 * @fn          zb_BindConfirm
 *
 * @brief       The zb_BindConfirm callback is called by the ZigBee stack
 *              after a bind operation completes.
 *
 * @param       commandId - The command ID of the binding being confirmed.
 *              status - The status of the bind operation.
 *
 * @return      none
 */
void zb_BindConfirm( uint16 commandId, uint8 status )
{
  if( status == ZB_SUCCESS )
  {   
    appState = APP_REPORT;
    HalLedSet( HAL_LED_2, HAL_LED_MODE_ON );
    
    // After failure reporting start automatically when the device
    // is binded to a new gateway
    if ( reportState ) 
    {
      // Start reporting
      osal_set_event( sapi_TaskID, MY_REPORT_EVT );
    }
  }
  else
  {
    osal_start_timerEx( sapi_TaskID, MY_FIND_COLLECTOR_EVT, myBindRetryDelay );
  }
}
예제 #24
0
/**
 * @brief   Este callback es llamado asincrónicamente por el stack de ZigBee
 *          para notificar a la aplicación que se recibieron datos, enviados 
 *          por otro nodo de la red.
 * @param   source  Short Address (NWK) del nodo que envío los datos.
 * @param   command ID del comando asociado con los datos.
 * @param   len     Cantidad de bytes del parámetro pData.
 * @param   pData   Puntero al inicio de los datos envíados por el nodo.
 */
void zb_ReceiveDataIndication(uint16 source, uint16 command, uint16 len, uint8 *pData)
{ 
    // imprime la dirección fuente en el display
    HalLcdWriteStringValue("RCB", source, 16, 1);
    // flashea el LED 2 para indicar que se recibió un mensaje
    HalLedSet(HAL_LED_2, HAL_LED_MODE_FLASH);
    
    // deserealiza mensaje recibido
    msgReport = deserializeMessage(pData);
    
    if (msgReport.msgType == MSG_TYPE_REPORT)
    {
        HalLcdWriteStringValue("#", msgReport.sequence, 10, 2);
        // verifica condiciones de alarmas
        alarmFlags = checkAlarms(&msgReport);
        // imprime alarma en LCD
        //HalLcdWriteStringValue("ALARM", alarmFlags, 16, 2);
        
        if (alarmFlags != 0)
        {
            // crea paquete de respuesta con igual MAC y nº de secuencia
            struct message_t msgAlarm;
            msgAlarm.sequence = msgReport.sequence;
            memcpy(&(msgAlarm.mac), &(msgReport.mac), sizeof(msgReport.mac));
            msgAlarm.msgType = MSG_TYPE_ALARM;
            msgAlarm.lenData = MSG_LEN_DATA_ALARM;
            // flags en little-endian
            msgAlarm.data[0] = LO_UINT16(alarmFlags);
            msgAlarm.data[1] = HI_UINT16(alarmFlags);
            
            // serializa mensaje y lo envía
            serializeMessage(&(msgAlarm), msgBuf);
            zb_SendDataRequest(source, MESSAGE_CLUSTER,
                               getSizeOfMessage(&(msgAlarm)),
                               msgBuf, 0, AF_TX_OPTIONS_NONE, 0);
        }
        // crea evento para enviar el reporte por UART a la PC, añandiendo
        // los flags
        osal_start_timerEx(sapi_TaskID, SEND_UART_MSG, 0);
    }
}
예제 #25
0
파일: DemoSensor.c 프로젝트: Billyhq/ZigBee
/******************************************************************************
 * @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 )
{
#ifdef SYS_DEBUG_RELAY
  static uint8 onoff;
#endif
  // 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 )
    {
      HalLedSet( HAL_LED_ALL, HAL_LED_MODE_ON );
    }
    if ( keys & HAL_KEY_SW_2 )
    {
#ifdef SYS_DEBUG_RELAY
      if( onoff )
      {
        st( P0_5 = !1; );
        onoff = 0;
      }
      else
      {
        st(P0_5 = !!1; );
        onoff = 1;
      }
예제 #26
0
파일: hidapp.c 프로젝트: AubrCool/BLE
/*********************************************************************
 *
 * @fn      hidappHandleKey
 *
 * @brief   Handle service for keys
 *
 * @param   keys  - key that was pressed (i.e. the scanned row/col index)
 *          state - shifted
 *
 * @return  void
 */
static void hidappHandleKeys( uint8 keys, uint8 state )
{
  // Unused arguments
  (void) state;

  if (keys & HAL_KEY_SW_1)
  {
    // If bonds exist, erase all of them
    if ( ( hidappBondCount() > 0 ) && ( hidappBLEState != BLE_STATE_CONNECTED ) )
    {
      if ( hidappBLEState == BLE_STATE_CONNECTING )
      {
        hidappBLEState = BLE_STATE_DISCONNECTING;
        VOID GAPCentralRole_TerminateLink( GAP_CONNHANDLE_INIT );
      }

      VOID GAPBondMgr_SetParameter( GAPBOND_ERASE_ALLBONDS, 0, NULL );
    }
  }

  if (keys & HAL_KEY_SW_2)
  {
    if ( hidappBLEState == BLE_STATE_CONNECTED )
    {
      hidappBLEState = BLE_STATE_DISCONNECTING;
      VOID GAPCentralRole_TerminateLink( connHandle );
    }
    else if ( hidappBLEState == BLE_STATE_IDLE )
    {
      #if defined ( NANO_DONGLE )

      HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF ); // red led

      // Notify our task to start initial discovey
      osal_set_event( hidappTaskId, HIDAPP_EVT_START_DISCOVERY );

      #endif //  #if defined ( NANO_DONGLE )
    }
  }
}
예제 #27
0
/*********************************************************************
 * @fn      SimpleBLEObserver_Init
 *
 * @brief   Initialization function for the Simple BLE Observer App 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 SimpleBLEObserver_Init( uint8 task_id )
{
  simpleBLETaskId = task_id;

  // Setup Observer Profile
  {
    uint8 scanRes = DEFAULT_MAX_SCAN_RES;
    GAPObserverRole_SetParameter ( GAPOBSERVERROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );
  }
  
  // Setup GAP
  GAP_SetParamValue( TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION );
  GAP_SetParamValue( TGAP_LIM_DISC_SCAN, DEFAULT_SCAN_DURATION );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( simpleBLETaskId );
  
  // makes sure LEDs are off
  HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF );
  
  // Setup a delayed profile startup
  osal_set_event( simpleBLETaskId, START_DEVICE_EVT );
}
/******************************************************************************
 * @fn          zb_StartConfirm
 *
 * @brief       The zb_StartConfirm callback is called by the ZigBee stack
 *              after a start request operation completes
 *
 * @param       status - The status of the start operation.  Status of
 *                       ZB_SUCCESS indicates the start operation completed
 *                       successfully.  Else the status is an error code.
 *
 * @return      none
 */
void zb_StartConfirm( uint8 status )
{ 
  // If the device sucessfully started, change state to running
  if ( status == ZB_SUCCESS )   
  {
    // Set LED 1 to indicate that node is operational on the network
    HalLedSet( HAL_LED_1, HAL_LED_MODE_ON );
    
    // Change application state
    appState = APP_START;
    
    // Set event to bind to a collector
    osal_set_event( sapi_TaskID, MY_FIND_COLLECTOR_EVT );
       
     // Store parent short address
    zb_GetDeviceInfo(ZB_INFO_PARENT_SHORT_ADDR, &parentShortAddr);
  }
  else
  {
    // Try again later with a delay
    osal_start_timerEx( sapi_TaskID, MY_START_EVT, myStartRetryDelay );
  }
}
예제 #29
0
파일: uApp.c 프로젝트: DRuffer/coinForth
/*********************************************************************
 * @fn      uApp_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:
 *                 HAL_KEY_SW_4
 *                 HAL_KEY_SW_3
 *                 HAL_KEY_SW_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 *********************************************************************/
void uApp_HandleKeys( uint8 shift, uint8 keys )
{ 
  // 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 )
    {
		DebugMsg("DebugMsg example - Toggle LED 1", 0);
		HalLedSet(HAL_LED_1, HAL_LED_MODE_TOGGLE);
    }
    if ( keys & HAL_KEY_SW_2 )
    {

    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
}
예제 #30
0
/******************************************************************************
 * @fn          zb_StartConfirm
 *
 * @brief       The zb_StartConfirm callback is called by the ZigBee stack
 *              after a start request operation completes
 *
 * @param       status - The status of the start operation.  Status of
 *                       ZB_SUCCESS indicates the start operation completed
 *                       successfully.  Else the status is an error code.
 *
 * @return      none
 */
void zb_StartConfirm( uint8 status )
{
  // If the device sucessfully started, change state to running
  if ( status == ZB_SUCCESS ) 
  {
    // Change application state
    appState = APP_START;
    
    // Set LED 1 to indicate that node is operational on the network
    HalLedSet( HAL_LED_1, HAL_LED_MODE_ON );
    
    // Update the display
    #if defined ( LCD_SUPPORTED )
    HalLcdWriteString( "SensorDemo", HAL_LCD_LINE_1 );
    HalLcdWriteString( "Sensor", HAL_LCD_LINE_2 );
    #endif
    
    // Store parent short address
    zb_GetDeviceInfo(ZB_INFO_PARENT_SHORT_ADDR, &parentShortAddr);
    
    // Set event to bind to a collector
    osal_set_event( sapi_TaskID, MY_FIND_COLLECTOR_EVT );  
  }
}