/*********************************************************************
 * @fn      SimpleBLEBroadcaster_ProcessEvent
 *
 * @brief   Simple BLE Broadcaster 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  events not processed
 */
uint16 SimpleBLEBroadcaster_ProcessEvent( uint8 task_id, uint16 events )
{
  
  VOID task_id; // OSAL required parameter that isn't used in this function
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( simpleBLEBroadcaster_TaskID )) != NULL )
    {
      simpleBLEBroadcaster_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & SBP_START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &simpleBLEBroadcaster_BroadcasterCBs );
    
    return ( events ^ SBP_START_DEVICE_EVT );
  }
  
  // Discard unknown events
  return 0;
}
Exemple #2
0
/*********************************************************************
 * @fn      CyclingService_ProcessEvent
 *
 * @brief   process incoming event.
 *
 * @param   task_id - OSAL task id.
 *
 * @param   events - event bit(s) set for the task(s)
 *
 * @return  none
 */
uint16 CyclingService_ProcessEvent( uint8 task_id, uint16 events )
{
  VOID task_id;

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( cyclingService_TaskID )) != NULL )
    {
      cycling_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & CSC_CMD_IND_SEND_EVT )
  {
    GATT_Indication( connectionHandle, &cscCmdInd, FALSE, cyclingService_TaskID );

    // Set Control Point Cfg done
    scOpInProgress = FALSE;

    return ( events ^ CSC_CMD_IND_SEND_EVT );
  }

  return 0;
}
Exemple #3
0
/*********************************************************************
 * @fn      HidEmuKbd_ProcessEvent
 *
 * @brief   HidEmuKbd 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  events not processed
 */
uint16 HidEmuKbd_ProcessEvent( uint8 task_id, uint16 events )
{

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( hidEmuKbdTaskId )) != NULL )
    {
      hidEmuKbd_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & START_DEVICE_EVT )
  {
    return ( events ^ START_DEVICE_EVT );
  }

   return 0;
}
Exemple #4
0
/**
 * @brief   Central Profile Task event processing function.
 *
 * @param   taskId - Task ID
 * @param   events - Events.
 *
 * @return  events not processed
 */
uint16 GAPCentralRole_ProcessEvent( uint8 taskId, uint16 events )
{
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( gapCentralRoleTaskId )) != NULL )
    {
      gapCentralRole_ProcessOSALMsg( (osal_event_hdr_t *) pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & GAP_EVENT_SIGN_COUNTER_CHANGED )
  {
    // Sign counter changed, save it to NV
    VOID osal_snv_write( BLE_NVID_SIGNCOUNTER, sizeof( uint32 ), &gapCentralRoleSignCounter );

    return ( events ^ GAP_EVENT_SIGN_COUNTER_CHANGED );
  }

  // Discard unknown events
  return 0;
}
Exemple #5
0
uint16 FanProcessEvent(uint8 taskId, uint16 events)
{
	if (events & SYS_EVENT_MSG)
	{
		uint8* message = NULL;

		if ((message = osal_msg_receive(fanTaskId)) != NULL)
		{
			FanProcessOSALMessage((osal_event_hdr_t*)message);
			osal_msg_deallocate(message);
		}

		return (events ^ SYS_EVENT_MSG);
	}

	if (events & FAN_START_DEVICE_EVT)
	{
		GAPRole_StartDevice(&fanPeripheralCallBacks);
		GAPBondMgr_Register(&fanBondManagerCallBacks);
	
		return (events ^ FAN_START_DEVICE_EVT);
	}

	if (events & FAN_UPDATE_STATUS_EVT)
	{
		FanUpdateStatus();
	
		return (events ^ FAN_UPDATE_STATUS_EVT);
	}

	return 0;
};
Exemple #6
0
void MT_UartProcessZToolData ( uint8 port, uint8 event )
{
  uint8 flag=0,i,j=0;   //flag是判断有没有收到数据,j记录数据长度
  uint8 buf[128];     //串口buffer最大缓冲默认是128,我们这里用128.
  (void)event;        // Intentionally unreferenced parameter  

  while (Hal_UART_RxBufLen(port)) //检测串口数据是否接收完成

  {
    HalUARTRead (port,&buf[j], 1);  //把数据接收放到buf中
    j++;                           //记录字符数
    flag=1;                         //已经从串口接收到信息
  } 

  if(flag==1)       //已经从串口接收到信息

  {     /* Allocate memory for the data */
	    //分配内存空间,为机构体内容+数据内容+1个记录长度的数据
   pMsg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof  
          ( mtOSALSerialData_t )+j+1);
  //事件号用原来的CMD_SERIAL_MSG
  pMsg->hdr.event = CMD_SERIAL_MSG;
  pMsg->msg = (uint8*)(pMsg+1);  // 把数据定位到结构体数据部分
  pMsg->msg [0]= j;              //给上层的数据第一个是长度
  for(i=0;i<j;i++)                //从第二个开始记录数据 
  pMsg->msg [i+1]= buf[i];   
  osal_msg_send( App_TaskID, (byte *)pMsg );  //登记任务,发往上层
  /* deallocate the msg */
  osal_msg_deallocate ( (uint8 *)pMsg );      //释放内存
  }
}
/**************************************************************************************************
 * @fn      Hal_ProcessEvent
 *
 * @brief   Hal Process Event
 *
 * @param   task_id - Hal TaskId
 *          events - events
 *
 * @return  None
 **************************************************************************************************/
uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
{
  uint8 *msgPtr;

  (void)task_id;  // Intentionally unreferenced parameter
  
  //--------------------------------------------------------------------------//
  // processing the system message
  //--------------------------------------------------------------------------//
  if ( events & SYS_EVENT_MSG )
  {
    msgPtr = osal_msg_receive(Hal_TaskID);

    while (msgPtr)
    {
      /* Do something here - for now, just deallocate the msg and move on */

      /* De-allocate */
      osal_msg_deallocate( msgPtr );
      /* Next */
      msgPtr = osal_msg_receive( Hal_TaskID );
    }
    return events ^ SYS_EVENT_MSG;
  }
  
  return 0;
}
Exemple #8
0
/**************************************************************************************************
 * @fn          MHMSSysEvtMsg
 *
 * @brief       This function is called by MHMSAppEvt() to process all of the pending OSAL messages.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void MHMSSysEvtMsg(void)
{
    uint8 *msg;

    while ((msg = osal_msg_receive(MHMSTaskId)))
    {
        switch (*msg)
        {
#if TVSA_DATA_CNF  //MHMS Question what is this for?
        case AF_DATA_CONFIRM_CMD:
            if (ZSuccess != ((afDataConfirm_t *)msg)->hdr.status)
            {
                if (0 == ++MHMSCnfErrCnt)
                {
                    MHMSCnfErrCnt = 255;
                }
            }
            break;
#endif

        case AF_INCOMING_MSG_CMD:  //MHMS this a router processing the incomming command from the coordinator
            MHMSAfMsgRx((afIncomingMSGPacket_t *)msg);
            break;

        case ZDO_STATE_CHANGE:
            MHMSZdoStateChange();
            break;

        default:
            break;
        }

        (void)osal_msg_deallocate(msg);  // Receiving task is responsible for releasing the memory.
    }
}
Exemple #9
0
/*********************************************************************
 * @fn      TimeApp_ProcessEvent
 *
 * @brief   Time App 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  events not processed
 */
uint16 TimeApp_ProcessEvent( uint8 task_id, uint16 events )
{
  
  VOID task_id; // OSAL required parameter that isn't used in this function
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( timeAppTaskId )) != NULL )
    {
      timeApp_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return ( events ^ SYS_EVENT_MSG );
  }

  if ( events & START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &timeAppPeripheralCB );

    // Register with bond manager after starting device
    GAPBondMgr_Register( (gapBondCBs_t *) &timeAppBondCB );

    return ( events ^ START_DEVICE_EVT );
  }

  if ( events & START_DISCOVERY_EVT )
  {
    if ( timeAppPairingStarted )
    {
      // Postpone discovery until pairing completes
      timeAppDiscPostponed = TRUE;
    }
    else
    {
      timeAppDiscState = timeAppDiscStart();
    }  
    return ( events ^ START_DISCOVERY_EVT );
  }

  if ( events & CLOCK_UPDATE_EVT )
  {
    timeAppClockDisplay();

    // Restart clock tick timer
    osal_start_timerEx( timeAppTaskId, CLOCK_UPDATE_EVT, DEFAULT_CLOCK_UPDATE_PERIOD );

    return ( events ^ CLOCK_UPDATE_EVT );
  }
     
  // Discard unknown events
  return 0;
}
/*********************************************************************
 * @fn      SimpleBLEPeripheral_ProcessEvent
 *
 * @brief   Simple BLE Peripheral 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  events not processed
 */
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
{
  //tasksArr[] ÊÇ11¸öTaskµÄ×îºóÒ»¸ö£¬ÓÉOSAL ϵͳ½øÐе÷¶È¡£ÓÐʱ¼äÀ´ÁË£¬Óø÷½·¨´¦Àí¡£³õʼ»¯OSAL_SimpleBLEperipheal

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
    {
      simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & SBP_START_DEVICE_EVT )
  {
    // Start the Device   Õâ¸öÊÇÉ豸ÓÐ״̬±ä»¯²Å»áµ÷ÓõĻص÷º¯Êý
    VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );

    // Start Bond Manager
    VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );
    
    // Set timer for first periodic event
    //init LED
    PWM_init();
    init_QI_Switch(1);
    //dataChange(1,0);
    
    //osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    //LedChange();
    return ( events ^ SBP_START_DEVICE_EVT );
  }
  
 if ( events & SBP_PERIODIC_EVT )
  {
    //osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    //Ö´ÐеƹâchangeµÄº¯Êý
    
    if(P1_1 == 1){
        //HalLcdWriteString("HEIGH",HAL_LCD_LINE_4);
    }else{
        //HalLcdWriteString("LOW",HAL_LCD_LINE_4);
    }

    LedChange();
    return (events ^ SBP_PERIODIC_EVT);
  }

  // Discard unknown events
  return 0;
}
Exemple #11
0
/**************************************************************************************************
 * @fn      Hal_ProcessEvent
 *
 * @brief   Hal Process Event
 *
 * @param   task_id - Hal TaskId
 *          events - events
 *
 * @return  None
 **************************************************************************************************/
uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
{
  uint8 *msgPtr;
  
  (void)task_id;  // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
    msgPtr = osal_msg_receive(Hal_TaskID);

    while (msgPtr)
    {
      /* Do something here - for now, just deallocate the msg and move on */

      /* De-allocate */
      osal_msg_deallocate( msgPtr );
      /* Next */
      msgPtr = osal_msg_receive( Hal_TaskID );
    }
    return events ^ SYS_EVENT_MSG;
  }

  if ( events & HAL_LED_BLINK_EVENT )
  {
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
    HalLedUpdate();
#endif /* BLINK_LEDS && HAL_LED */
    return events ^ HAL_LED_BLINK_EVENT;
  }

  if (events & HAL_KEY_EVENT)
  {

#if (defined HAL_KEY) && (HAL_KEY == TRUE)
    /* Check for keys */
    HalKeyPoll();

    /* if interrupt disabled, do next polling */
    if (!Hal_KeyIntEnable)
    {
      osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
    }
#endif // HAL_KEY

    return events ^ HAL_KEY_EVENT;
  }

#ifdef POWER_SAVING
  if ( events & HAL_SLEEP_TIMER_EVENT )
  {
    halRestoreSleepLevel();
    return events ^ HAL_SLEEP_TIMER_EVENT;
  }
#endif

  /* Nothing interested, discard the message */
  return 0;

}
Exemple #12
0
/*********************************************************************
 * @fn          afBuildMSGIncoming
 *
 * @brief       Build the message for the app
 *
 * @param
 *
 * @return      pointer to next in data buffer
 */
static void afBuildMSGIncoming( aps_FrameFormat_t *aff, endPointDesc_t *epDesc,
                 zAddrType_t *SrcAddress, uint16 SrcPanId, NLDE_Signal_t *sig,
                 uint8 nwkSeqNum, uint8 SecurityUse, uint32 timestamp, uint8 radius )
{
  afIncomingMSGPacket_t *MSGpkt;
  const uint8 len = sizeof( afIncomingMSGPacket_t ) + aff->asduLength;
  uint8 *asdu = aff->asdu;
  MSGpkt = (afIncomingMSGPacket_t *)osal_msg_allocate( len );

  if ( MSGpkt == NULL )
  {
    return;
  }

  MSGpkt->hdr.event = AF_INCOMING_MSG_CMD;
  MSGpkt->groupId = aff->GroupID;
  MSGpkt->clusterId = aff->ClusterID;
  afCopyAddress( &MSGpkt->srcAddr, SrcAddress );
  MSGpkt->srcAddr.endPoint = aff->SrcEndPoint;
  MSGpkt->endPoint = epDesc->endPoint;
  MSGpkt->wasBroadcast = aff->wasBroadcast;
  MSGpkt->LinkQuality = sig->LinkQuality;
  MSGpkt->correlation = sig->correlation;
  MSGpkt->rssi = sig->rssi;
  MSGpkt->SecurityUse = SecurityUse;
  MSGpkt->timestamp = timestamp;
  MSGpkt->nwkSeqNum = nwkSeqNum;
  MSGpkt->macSrcAddr = aff->macSrcAddr;
  MSGpkt->macDestAddr = aff->macDestAddr;
  MSGpkt->srcAddr.panId = SrcPanId;
  MSGpkt->cmd.TransSeqNumber = 0;
  MSGpkt->cmd.DataLength = aff->asduLength;
  MSGpkt->radius = radius;

  if ( MSGpkt->cmd.DataLength )
  {
    MSGpkt->cmd.Data = (uint8 *)(MSGpkt + 1);
    osal_memcpy( MSGpkt->cmd.Data, asdu, MSGpkt->cmd.DataLength );
  }
  else
  {
    MSGpkt->cmd.Data = NULL;
  }

#if defined ( MT_AF_CB_FUNC )
  // If ZDO or SAPI have registered for this endpoint, dont intercept it here
  if (AFCB_CHECK(CB_ID_AF_DATA_IND, *(epDesc->task_id)))
  {
    MT_AfIncomingMsg( (void *)MSGpkt );
    // Release the memory.
    osal_msg_deallocate( (void *)MSGpkt );
  }
  else
#endif
  {
    // Send message through task message.
    osal_msg_send( *(epDesc->task_id), (uint8 *)MSGpkt );
  }
}
/**
 * @brief   Central Profile Task event processing function.
 *
 * @param   taskId - Task ID
 * @param   events - Events.
 *
 * @return  events not processed
 */
uint16 GAPCentralRole_ProcessEvent( uint8 taskId, uint16 events )
{
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( gapCentralRoleTaskId )) != NULL )
    {
      gapCentralRole_ProcessOSALMsg( (osal_event_hdr_t *) pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & GAP_EVENT_SIGN_COUNTER_CHANGED )
  {
    // Sign counter changed, save it to NV
    VOID osal_snv_write( BLE_NVID_SIGNCOUNTER, sizeof( uint32 ), &gapCentralRoleSignCounter );

    return ( events ^ GAP_EVENT_SIGN_COUNTER_CHANGED );
  }

  if ( events & START_ADVERTISING_EVT )
  {
    if ( gapRole_AdvEnabled )
    {
      gapAdvertisingParams_t params;

      // Setup advertisement parameters
      params.eventType = gapRole_AdvEventType;
      params.initiatorAddrType = gapRole_AdvDirectType;
      VOID osal_memcpy( params.initiatorAddr, gapRole_AdvDirectAddr, B_ADDR_LEN );
      params.channelMap = gapRole_AdvChanMap;
      params.filterPolicy = gapRole_AdvFilterPolicy;

      if ( GAP_MakeDiscoverable( gapRole_TaskID, &params ) != SUCCESS )
      {
        gapRole_state = GAPROLE_ERROR;
        // Notify the application
        if ( pGapCentralRoleCB && pGapCentralRoleCB->broadcastCB )
        {
          pGapCentralRoleCB->broadcastCB( gapRole_state );
        }
      }
    }

    return ( events ^ START_ADVERTISING_EVT );
  }  
  
  
  
  // Discard unknown events
  return 0;
}
Exemple #14
0
/**************************************************************************************************
 * @fn          zapSBL_SysEvtMsg
 *
 * @brief       This function is called by zapSBL_Evt() to process all pending OSAL messages.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void zapSBL_SysEvtMsg(void)
{
  uint8 *msg;

  while ((msg = osal_msg_receive(zapSBL_TaskId)))
  {
    (void)osal_msg_deallocate(msg);  // Receiving task is responsible for releasing the memory.
  }
}
/*********************************************************************
 * @fn      SimpleBLEPeripheral_ProcessEvent
 *
 * @brief   Simple BLE Peripheral 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  events not processed
 */
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
{

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
    {
      simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & SBP_START_DEVICE_EVT )
  {
    P0_7 = 0;  //防止继电器跳变,初始化为高
    P0DIR |= BV(7); //设置为输出
    P0SEL &=~BV(7); //设置该脚为普通GPIO
    //HCI_EXT_SetTxPowerCmd (HCI_EXT_TX_POWER_MINUS_23_DBM);
    // Start the Device
    VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );

    // Start Bond Manager
    VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );

    return ( events ^ SBP_START_DEVICE_EVT );
  }

  if ( events & SBP_PERIODIC_EVT )
  {
    //成功写入后,重启从机
    HAL_SYSTEM_RESET();
    return (events ^ SBP_PERIODIC_EVT);
  }

#if defined ( PLUS_BROADCASTER )
  if ( events & SBP_ADV_IN_CONNECTION_EVT )
  {
    uint8 turnOnAdv = TRUE;
    // Turn on advertising while in a connection
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &turnOnAdv );

    return (events ^ SBP_ADV_IN_CONNECTION_EVT);
  }
#endif // PLUS_BROADCASTER

  // Discard unknown events
  return 0;
}
Exemple #16
0
/*********************************************************************
 * @fn      PIRSensor_ProcessEvent
 *
 * @brief   Simple BLE Peripheral 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  events not processed
 */
uint16 PIRSensor_ProcessEvent( uint8 task_id, uint16 events )
{

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( PIRSensor_TaskID )) != NULL )
    {
      PIRSensor_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & SBP_START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &PIRSensor_PeripheralCBs );

    // Start Bond Manager
    VOID GAPBondMgr_Register( &PIRSensor_BondMgrCBs );

    return ( events ^ SBP_START_DEVICE_EVT );
  }

  //////////////////////////
  //         AIN          //
  //////////////////////////
  if ( events & SBP_READ_AIN_EVT )
  {
    if(ainEnabled)
    {
      uint16 ainData;
      ainData = readAdcData(HAL_ADC_CHANNEL_6);
      Ain_SetParameter(SENSOR_DATA, AIN_DATA_LEN, &ainData);
      
      osal_start_timerEx( PIRSensor_TaskID, SBP_READ_AIN_EVT, sensorAinPeriod );
    }
    else
    {
      resetCharacteristicValue( AIN_SERV_UUID, SENSOR_DATA, 0, AIN_DATA_LEN);
      resetCharacteristicValue( AIN_SERV_UUID, SENSOR_CONF, ST_CFG_SENSOR_DISABLE, sizeof ( uint8 ));
    }

    return (events ^ SBP_READ_AIN_EVT);
  }

  // Discard unknown events
  return 0;
}
Exemple #17
0
/*********************************************************************
 * @fn      SoftCmd_ProcessEvent
 *
 * @brief   Soft Command 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  events not processed
 */
uint16 SoftCmd_ProcessEvent( uint8 task_id, uint16 events )
{
  
  VOID task_id; // OSAL required parameter that isn't used in this function
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( softCmdTaskId )) != NULL )
    {
      softCmd_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &softCmdPeripheralCBs );

    // Register with bond manager after starting device
    GAPBondMgr_Register( (gapBondCBs_t *) &softCmdBondCB );
    
    return ( events ^ START_DEVICE_EVT );
  }

  if ( events & START_DISCOVERY_EVT )
  {
    if ( softCmdPairingStarted )
    {
      // Postpone discovery until pairing completes
      softCmdDiscPostponed = TRUE;
    }
    else
    {
      softCmdDiscState = softCmdDiscStart();
    }  
    return ( events ^ START_DISCOVERY_EVT );
  }

  if ( events & BATT_PERIODIC_EVT )
  {
    // Perform periodic battery task
    softCmdBattPeriodicTask();
    
    return (events ^ BATT_PERIODIC_EVT);
  }  
  
  // Discard unknown events
  return 0;
}
/*********************************************************************
 * @fn      SimpleBLECentral_ProcessEvent
 *
 * @brief   Simple BLE Central 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  events not processed
 */
uint16 SimpleBLECentral_ProcessEvent( uint8 task_id, uint16 events )
{
  
  VOID task_id; // OSAL required parameter that isn't used in this function
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( simpleBLETaskId )) != NULL )
    {
      simpleBLECentral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPCentralRole_StartDevice( (gapCentralRoleCB_t *) &simpleBLERoleCB );

    // Register with bond manager after starting device
    GAPBondMgr_Register( (gapBondCBs_t *) &simpleBLEBondCB );

    return ( events ^ START_DEVICE_EVT );
  }

  if ( events & START_DISCOVERY_EVT )
  {
    simpleBLECentralStartDiscovery( );
    
    return ( events ^ START_DISCOVERY_EVT );
  }
  
  if ( events & SBP_PERIODIC_EVT )
  {
    // Restart timer
    if ( SBP_PERIODIC_EVT_PERIOD && simpleBLEState == BLE_STATE_CONNECTED )
    {
      osal_start_timerEx( simpleBLETaskId, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    }

    // Perform periodic application task
    performPeriodicTask();

    return (events ^ SBP_PERIODIC_EVT);
  }
  
  // Discard unknown events
  return 0;
}
Exemple #19
0
/**************************************************************************************************
 * @fn          afRetrieve
 *
 * @brief       This function retrieves the data of a huge incoming message. On an failure during
 *              the retrieval, the incoming message is freed. Otherwise, the incoming message is
 *              forwarded to the corresponding task.
 *
 * input parameters
 *
 * @param       pMsg - Pointer to the incoming AF message.
 * @param       taskId - The task ID corresponding to the destination endpoint of the message.
 *
 * output parameters
 *
 * @param       pMsg->cmd.Data - The incoming message data buffer member is filled.
 *
 * @return      None.
 **************************************************************************************************
 */
static void afRetrieve(uint8 taskId, afIncomingMSGPacket_t *pMsg)
{
  #define ZAP_AF_RTV_MSG_HDR  7  // Retrieve message header length.
  #define ZAP_AF_RTV_RPY_HDR  2  // Retrieve-reply message header length.
  #define ZAP_AF_RTV_DAT_MAX (MT_RPC_DATA_MAX - ZAP_AF_RTV_RPY_HDR)

  uint16 idx = 0, len = pMsg->cmd.DataLength;
  uint8 *pBuf, rtrn, tmpLen = 0;

  do {
    /* This trick to pre-decrement (with zero on the first pass) allows the while() test to
     * succeed and loop to send a zero data length message which will trigger the ZNP to
     * de-allocate the huge incoming message being held.
     */
    len -= tmpLen;
    idx += tmpLen;

    if (len > ZAP_AF_RTV_DAT_MAX)
    {
      tmpLen = ZAP_AF_RTV_DAT_MAX;
    }
    else
    {
      tmpLen = len;
    }

    if ((pBuf = zap_msg_allocate(ZAP_AF_RTV_MSG_HDR, ((uint8)MT_RPC_SYS_AF | MT_RPC_CMD_SREQ),
                                                             MT_AF_DATA_RETRIEVE)) == NULL)
    {
      rtrn = afStatus_MEM_FAIL;
      break;
    }

    pBuf[0] = BREAK_UINT32(pMsg->timestamp, 0);
    pBuf[1] = BREAK_UINT32(pMsg->timestamp, 1);
    pBuf[2] = BREAK_UINT32(pMsg->timestamp, 2);
    pBuf[3] = BREAK_UINT32(pMsg->timestamp, 3);
    pBuf[4] = LO_UINT16(idx);
    pBuf[5] = HI_UINT16(idx);
    pBuf[6] = tmpLen;
    zapPhySend(zapAppPort, pBuf);
    rtrn = (afStatus_t)ZAP_SRSP_STATUS(pBuf);
    (void)osal_memcpy(pMsg->cmd.Data+idx, pBuf+ZAP_AF_RTV_RPY_HDR, tmpLen);
    zap_msg_deallocate(&pBuf);
  } while ((rtrn == afStatus_SUCCESS) && len);

  if (rtrn == afStatus_SUCCESS)
  {
    (void)osal_msg_send(taskId, (uint8 *)pMsg);
  }
  else
  {
    (void)osal_msg_deallocate((uint8 *)pMsg);
  }
}
Exemple #20
0
uint16 DisplayTaskEventLoop(uint8 task_id, uint16 events)
{
	   Dis_Msg_t *msg = NULL;
	
	   if(events & SYS_EVENT_MSG)
		 {
			  msg = (Dis_Msg_t *)osal_msg_receive(task_id);
			 
			  while(msg)
				{
					 switch(msg->hdr.event)
					 {
                case DIS_UPDATE:
									if(false == IS_Flag_Valid(DISPLAY_UPDATE_LOCK)){
										dispaly_update_handler(gSystem_t, cur_menu->id, msg->value);
									}
									break;
								
								case DIS_JUMP:
									dispaly_update_handler(gSystem_t, (menu_id_t)msg->value, 0);
									break;
								
								default:
									break;
					 }
					 
					 osal_msg_deallocate((uint8 *) msg);
					 
					 msg = (Dis_Msg_t *)osal_msg_receive(task_id);
				}
				
				return (events ^ SYS_EVENT_MSG);
		 }
		 
		 if(events & VOL_DIS_BACK_MSG){
			 vol_dis_timeout_handler();
			 return (events ^ VOL_DIS_BACK_MSG);
		 }
		 
		 if(events & SRC_MENU_TIMEOUT_MSG){
			 src_dis_timeout_handler();
			 return (events ^ SRC_MENU_TIMEOUT_MSG);
		 }
		 
		 if(events & SRC_MENU_TO_FILE_LIST_TIMEOUT_MSG){
			 
			 src_menu_to_file_list_handler();
			 
			 return(events ^ SRC_MENU_TO_FILE_LIST_TIMEOUT_MSG);
		 }
		 
		 return 0;
 }
Exemple #21
0
/*********************************************************************
 * @fn      StubAPS_ProcessEvent()
 *
 * @brief   Main event loop for Stub APS task. This function should be called
 *          at periodic intervals when event occur.
 *
 * @param   task_id - Task ID
 * @param   events  - Bitmap of events
 *
 * @return  none
 */
UINT16 StubAPS_ProcessEvent( uint8 task_id, uint16 events )
{
  (void)task_id; // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
    osal_event_hdr_t *msg_ptr;

    while ( (msg_ptr = (osal_event_hdr_t *)osal_msg_receive( StubAPS_TaskID )) != NULL )
    {
      if ( msg_ptr->event == MAC_MCPS_DATA_CNF )
      {
        INTERP_DataConfirm( (ZMacDataCnf_t *)msg_ptr );
      }
      else if ( msg_ptr->event == MAC_MCPS_DATA_IND )
      {
        INTERP_DataIndication( (macMcpsDataInd_t *)msg_ptr );
      }

      osal_msg_deallocate( (uint8 *)msg_ptr );
    }

    // Return unproccessed events
    return ( events ^ SYS_EVENT_MSG );
  }

  if ( events & CHANNEL_CHANGE_EVT )
  {
    // try to change to the new channel
    ZStatus_t status = StubAPS_SetNewChannel( newChannel );
    if ( status != ZSuccess )
    {
      // turn MAC receiver back on
      uint8 rxOnIdle = true;
      ZMacSetReq( ZMacRxOnIdle, &rxOnIdle );

      // set NWK task to run
      nwk_setStateIdle( FALSE );

      channelChangeInProgress = FALSE;
    }

    // notify the application
    StubAPS_NotifyApp( status );

    return ( events ^ CHANNEL_CHANGE_EVT );
  }

  // If reach here, the events are unknown
  // Discard or make more handlers
  return 0;

} /* StubAPS_ProcessEvent() */
Exemple #22
0
/*********************************************************************
 * @fn      Biscuit_ProcessEvent
 *
 * @brief   Simple BLE Peripheral 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  events not processed
 */
uint16 Biscuit_ProcessEvent( uint8 task_id, uint16 events )
{

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( biscuit_TaskID )) != NULL )
    {
      biscuit_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & SBP_START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &biscuit_PeripheralCBs );

    // Start Bond Manager
    VOID GAPBondMgr_Register( &biscuit_BondMgrCBs );

    // Set timer for first periodic event
    osal_start_timerEx( biscuit_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );

    return ( events ^ SBP_START_DEVICE_EVT );
  }

  if ( events & SBP_PERIODIC_EVT )
  {
    // Restart timer
    if ( SBP_PERIODIC_EVT_PERIOD )
    {
      osal_start_timerEx( biscuit_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    }

    // Perform periodic application task
    performPeriodicTask();

    return (events ^ SBP_PERIODIC_EVT);
  }

  // Discard unknown events
  return 0;
}
/*********************************************************************
 * @fn      SampleApp_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 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
{
  afIncomingMSGPacket_t *MSGpkt;
  (void)task_id;  // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
    MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
    //Databuf = osal_mem_alloc(MSGpkt->cmd.DataLength);
    while ( MSGpkt )
    {
        switch ( MSGpkt->hdr.event )
        {        
          // Received when a messages is received (OTA) for this endpoint
          case AF_INCOMING_MSG_CMD:
            SampleApp_MessageMSGCB( MSGpkt );
            break;  
          default:
            break;
        }    
        
      // Release the memory
      osal_msg_deallocate((uint8 *)MSGpkt );
     
      // Next - if one is available
      MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
    }
  
    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  // Send a message out - This event is generated by a timer
  //  (setup in SampleApp_Init()).
  if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT )
  {
     
     SampleApp_SendPeriodicMessage();  //发送数据函数
     
    // Setup to send message again in normal period (+ a little jitter)
   
    osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
        (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) );

    // return unprocessed events
    return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT);
  }

  // Discard unknown events
  return 0;
}
Exemple #24
0
/*********************************************************************
 * @fn      HeartRate_ProcessEvent
 *
 * @brief   Heart Rate 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  events not processed
 */
uint16 HeartRate_ProcessEvent( uint8 task_id, uint16 events )
{
  
  VOID task_id; // OSAL required parameter that isn't used in this function
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( heartRate_TaskID )) != NULL )
    {
      heartRate_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &heartRatePeripheralCB );

    // Register with bond manager after starting device
    GAPBondMgr_Register( (gapBondCBs_t *) &heartRateBondCB );
    
    return ( events ^ START_DEVICE_EVT );
  }

  if ( events & HEART_PERIODIC_EVT )
  {
    // Perform periodic heart rate task
    heartRatePeriodicTask();
    
    return (events ^ HEART_PERIODIC_EVT);
  }  

  if ( events & BATT_PERIODIC_EVT )
  {
    // Perform periodic battery task
    heartRateBattPeriodicTask();
    
    return (events ^ BATT_PERIODIC_EVT);
  }  
  
  // Discard unknown events
  return 0;
}
/*********************************************************************
 * @fn          zclHomelink_event_loop
 *
 * @brief       Event Loop Processor for zclGeneral.
 *
 * @param       none
 *
 * @return      none
 */
uint16 zclHomelink_event_loop( uint8 task_id, uint16 events )
{
  afIncomingMSGPacket_t *MSGpkt;
  (void)task_id;  // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
    while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclHomelink_TaskID )) )
    {
      switch ( MSGpkt->hdr.event )
      {
        case ZCL_INCOMING_MSG:
          // Incoming ZCL Foundation command/response messages
          zclHomelink_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
          break;

        case KEY_CHANGE:
          zclHomelink_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
          break;

        case ZDO_STATE_CHANGE:
          zclHomelink_NwkState = (devStates_t)(MSGpkt->hdr.status);

          // now on the network
          if ( (zclHomelink_NwkState == DEV_ZB_COORD) ||
               (zclHomelink_NwkState == DEV_ROUTER)   ||
               (zclHomelink_NwkState == DEV_END_DEVICE) )
          {
            if (initState == 0)
            {
              initState = 1;
            }
          }
          break;
          
        default:
          break;
      }

      // Release the memory
      osal_msg_deallocate( (uint8 *)MSGpkt );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  // Discard unknown events
  return 0;
}
Exemple #26
0
/***************************************************************************************************
 * @fn      MT_ProcessDebugMsg
 *
 * @brief   Build and send a debug message.
 *
 * @param   byte *data - pointer to the data portion of the debug message
 *
 * @return  void
 ***************************************************************************************************/
void MT_ProcessDebugMsg( mtDebugMsg_t *msg )
{
  byte *msg_ptr;
  byte dataLen;
  uint8 buf[11];
  uint8 *pBuf;

  /* Calculate the data length based */
  dataLen = 5 + (msg->numParams * sizeof ( uint16 ));

  /* Get a message buffer to build the debug message */
  msg_ptr = osal_msg_allocate( (byte)(SPI_0DATA_MSG_LEN + dataLen + 1) );
  if ( msg_ptr )
  {
    /* Build the message */
    pBuf = buf;
    *pBuf++ = msg->compID;
    *pBuf++ = msg->severity;
    *pBuf++ = msg->numParams;

    if ( msg->numParams >= 1 )
    {
      *pBuf++ = LO_UINT16( msg->param1 );
      *pBuf++ = HI_UINT16( msg->param1 );
    }

    if ( msg->numParams >= 2 )
    {
      *pBuf++ = LO_UINT16( msg->param2 );
      *pBuf++ = HI_UINT16( msg->param2 );
    }

    if ( msg->numParams == 3 )
    {
      *pBuf++ = LO_UINT16( msg->param3 );
      *pBuf++ = HI_UINT16( msg->param3 );
    }

    *pBuf++ = LO_UINT16( msg->timestamp );
    *pBuf = HI_UINT16( msg->timestamp );

#ifdef MT_UART_DEFAULT_PORT
    /* Debug message is set to AREQ CMD 0x80 for now */
    /* Build and send back the response */
    MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), 0x80, dataLen, buf);
#endif
    osal_msg_deallocate( msg_ptr );
  }
}
Exemple #27
0
/*********************************************************************
 * @brief   Task Event Processor function.
 *
 * Internal function defined in broadcaster.h.
 */
uint16 GAPRole_ProcessEvent( uint8 task_id, uint16 events )
{
  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( gapRole_TaskID )) != NULL )
    {
      gapRole_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );

      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & START_ADVERTISING_EVT )
  {
    if ( gapRole_AdvEnabled )
    {
      gapAdvertisingParams_t params;

      // Setup advertisement parameters
      params.eventType = gapRole_AdvEventType;
      params.initiatorAddrType = gapRole_AdvDirectType;
      VOID osal_memcpy( params.initiatorAddr, gapRole_AdvDirectAddr, B_ADDR_LEN );
      params.channelMap = gapRole_AdvChanMap;
      params.filterPolicy = gapRole_AdvFilterPolicy;

      if ( GAP_MakeDiscoverable( gapRole_TaskID, &params ) != SUCCESS )
      {
        gapRole_state = GAPROLE_ERROR;
        if ( pGapRoles_AppCGs && pGapRoles_AppCGs->pfnStateChange )
        {
          pGapRoles_AppCGs->pfnStateChange( gapRole_state );
        }
      }
    }

    return ( events ^ START_ADVERTISING_EVT );
  }

  // Discard unknown events
  return 0;
}
Exemple #28
0
/*---------------------------------------------------------------------------
* Application event processor.  This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
* - task_id: The OSAL assigned task ID.
* - events: Events to process.  This is a bit map and can contain more 
*           than one event.
*-------------------------------------------------------------------------*/
uint16 PMD_processEvent( uint8 taskId, uint16 events )
{
  
  if ( events & START_STREAMING)
  {
    attHandleValueNoti_t nData2;
    nData2.len = 20;
    nData2.handle = 20;
    getNameWithAddressInfo(nData2);
    
    GATT_Notification( 0, &nData2, FALSE );

    return (events ^ START_STREAMING);
  }
  
  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( pmd.taskId )) != NULL )
    {
      processOSALMsg( (osal_event_hdr_t *)pMsg );

      VOID osal_msg_deallocate( pMsg );
    }

    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & PMD_START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &peripheralRoleCallbacks );

    // Start Bond Manager
    VOID GAPBondMgr_Register( &bondMgrCallbacks );       

    
    // Flash red LED twice
    //cbLED_flash(cbLED_RED, 2, 250, 500);
    PMD_INT_init();

    return ( events ^ PMD_START_DEVICE_EVT );    
  }


  // Discard unknown events
  return 0;
}
Exemple #29
0
/*********************************************************************
 * @fn          zclSample_event_loop
 *
 * @brief       Event Loop Processor for zclGeneral.
 *
 * @param       none
 *
 * @return      none
 */
uint16 zclSampleSw_event_loop( uint8 task_id, uint16 events )
{
  afIncomingMSGPacket_t *MSGpkt;
  (void)task_id;  // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
    while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclSampleSw_TaskID )) )
    {
      switch ( MSGpkt->hdr.event )
      {
        case ZCL_INCOMING_MSG:
          // Incoming ZCL Foundation command/response messages
          zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
          break;

        case ZDO_CB_MSG:
          zclSampleSw_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
          break;

        case KEY_CHANGE:
          zclSampleSw_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
          break;

        default:
          break;
      }
      
      // Release the memory
      osal_msg_deallocate( (uint8 *)MSGpkt );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & SAMPLESW_IDENTIFY_TIMEOUT_EVT )
  {
    zclSampleSw_IdentifyTime = 10;
    zclSampleSw_ProcessIdentifyTimeChange();

    return ( events ^ SAMPLESW_IDENTIFY_TIMEOUT_EVT );
  }

  // Discard unknown events
  return 0;
}
/* @fn      LoacationApp_ProcessEvent
 * @brief   Generic Application Task event processor.
 * @param   task_id  - The OSAL assigned task ID.
 * @param   events - Bit map of events to process.
 * @return  none*/
uint16 LoacationApp_ProcessEvent( uint8 task_id, uint16 events ) {
  if ( events & SYS_EVENT_MSG ) {
    afIncomingMSGPacket_t *MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(
                                                             LoacationApp_TaskID );
    while ( MSGpkt != NULL ) {
      switch ( MSGpkt->hdr.event ) {
      case KEY_CHANGE:
        handleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
        break;
      case AF_DATA_CONFIRM_CMD:
#if !defined( RTR_NWK )
        {
        // This message is received as a confirmation of a data packet sent.
        // The status is of ZStatus_t type [defined in ZComDef.h]
        afDataConfirm_t *afDataConfirm = (afDataConfirm_t *)MSGpkt;
        /* No ACK from the MAC layer implies that mobile device is out of
         * range of most recent parent. Therefore, begin an orphan scan
         * to try to find a former parent.
         * NOTE: To get the fastest action in the process of finding a new
         * parent, set the MAX_JOIN_ATTEMPTS in ZDApp.c to 1.*/
        if(afDataConfirm->hdr.status == ZMacNoACK) LoacationApp_NoACK();
        else{}// Some other error -- Do something.
        }
#endif
        break;
      case AF_INCOMING_MSG_CMD:
        processMSGCmd( MSGpkt );
        break;
      case ZDO_STATE_CHANGE:
#if defined( POWER_SAVING )
        if(rejoinPending) {
          rejoinPending = FALSE;
          LoacationApp_Sleep(TRUE); //Ok to resume power saving ops.
        }
#endif
        break;
      default:
        break;
      }
      osal_msg_deallocate( (uint8 *)MSGpkt );
      MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(LoacationApp_TaskID);
    }
    return (events ^ SYS_EVENT_MSG);  // Return unprocessed events.
  }
  return 0;  // Discard unknown events
}