uint16 ACC_ProcessEvent( uint8 task_id, uint16 events ){






  if ( events & start_acc )
  {
   
    
    
    
   osal_start_timerEx( ACC_TaskID, ACC_PERIODIC_EVT, ACC_PERIODIC_EVT_PERIOD );
   osal_start_timerEx( ACC_TaskID, sample_blink_EVT, ACC_PERIODIC_EVT_PERIOD );

    return ( events ^ start_acc );
  }



 if ( events & sample_blink_EVT )
  {
     // HalLedSet (HAL_LED_2, HAL_LED_MODE_ON );
   
    
      HalLedSet (HAL_LED_1, HAL_LED_MODE_BLINK );
  
      
      
      osal_start_timerEx( ACC_TaskID, sample_blink_EVT, ACC_PERIODIC_EVT_PERIOD );
    return ( events ^ sample_blink_EVT);
  }
  


if ( events & ACC_PERIODIC_EVT )
  {
    // Restart timer
    if ( ACC_PERIODIC_EVT_PERIOD )
    {
      osal_start_timerEx( ACC_TaskID, ACC_PERIODIC_EVT, ACC_PERIODIC_EVT_PERIOD );
    }

    // Perform periodic application task
    performPeriodicTask();

    return (events ^ ACC_PERIODIC_EVT);
  }








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;
}
Beispiel #3
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      HidKbdMouse_ProcessEvent
*
* @brief   HidKbdMouse Application Task event processor.  This function
*          include timers, messages and any other user defined events.
*          is called to process all events for the task.  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 HidKbdMouse_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( hidKbdMouseTaskId )) != NULL )
    {
      hidKbdMouse_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 )
  {
    // Set timer for first periodic event
    osal_start_timerEx( hidKbdMouseTaskId, SBP_PERIODIC_EVT, KEEP_CONNECTION_ALIVE_50s );
    
    return ( events ^ START_DEVICE_EVT );
  }
  
  //Added to test UART  
  if ( events & SBP_PERIODIC_EVT )
  {
    // Restart timer
    if ( KEEP_CONNECTION_ALIVE_50s )
    {
      osal_start_timerEx( hidKbdMouseTaskId, SBP_PERIODIC_EVT, KEEP_CONNECTION_ALIVE_50s );
    }
    
    // Perform periodic application task
    performPeriodicTask();
    
    return (events ^ SBP_PERIODIC_EVT);
  }
  
  return 0;
}
Beispiel #5
0
/*********************************************************************
 * @fn      Thermometer_ProcessEvent
 *
 * @brief   Thermometer 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 Thermometer_ProcessEvent( uint8 task_id, uint16 events )
{

    VOID task_id; // OSAL required parameter that isn't used in this function
    uint8 notify_interval;
    int32 n32;

    if ( events & SYS_EVENT_MSG )
    {
        uint8 *pMsg;

        if ( (pMsg = osal_msg_receive( thermometerTaskId )) != NULL )
        {
            thermometer_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 & TH_START_DEVICE_EVT )
    {
        // Start the Device
        VOID GAPRole_StartDevice( &thermometer_PeripheralCBs );

        // Register with bond manager after starting device
        VOID GAPBondMgr_Register( &thermometer_BondMgrCBs );

        updateUI();

        return ( events ^ TH_START_DEVICE_EVT );
    }

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

        timeAppDiscState = timeAppDiscStart();

        return ( events ^ TH_START_DISCOVERY_EVT );
    }

    //periodic indications - if enabled
    if ( events & TH_PERIODIC_MEAS_EVT )
    {
        // Perform periodic application task
        performPeriodicTask();
        return (events ^ TH_PERIODIC_MEAS_EVT);
    }
    //periodic notifications for IMEAS
    if ( events & TH_PERIODIC_IMEAS_EVT )
    {
        // Perform periodic application task
        performPeriodicImeasTask();
        return (events ^ TH_PERIODIC_IMEAS_EVT);
    }

    // Disconnect after sending measurement
    if ( events & TH_DISCONNECT_EVT )
    {

        uint8 advEnable = FALSE;

        //disable advertising on disconnect
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advEnable );

        // Terminate Connection
        GAPRole_TerminateConnection();

        return (events ^ TH_DISCONNECT_EVT);
    }

    if ( events & TH_CCC_UPDATE_EVT )

        //This event is triggered when CCC is enabled
        if (gapProfileState == GAPROLE_CONNECTED)
        {
            temperatureMeasCharConfig = true;

            //if previously connected and measurements are active send stored
            if( connectedToLastAddress == true)
            {
                //send stored measurements
                thermometerSendStoredMeas();
            }

            //Only start meas timer if it's not running
            if(thMeasTimerRunning == FALSE)
            {
                //read stored interval value
                Thermometer_GetParameter( THERMOMETER_INTERVAL, &notify_interval );
                n32 = ((uint32)(notify_interval)) * (1000);

                //zero interval means should not perform meas
                if (n32 !=0)
                {
                    // Start interval timer
                    osal_start_timerEx( thermometerTaskId, TH_PERIODIC_MEAS_EVT, n32 );
                    thMeasTimerRunning = TRUE;
                }
            }
            return (events ^ TH_CCC_UPDATE_EVT);
        }

    return 0;
}
Beispiel #6
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_RX_TIME_OUT_EVT )
  {
    uint8 data[20];
    uint8 send;
    while(rxLen != 0)
    {
      if(rxLen <= 20)
      {
        send = rxLen;
        rxLen = 0;
      }
      else
      { 
        send = 20;      
        rxLen -= 20;
      }
      for(uint8 i=0; i<send; i++)
      {
        data[i] = RXBuf[rxTail];
        rxTail++;
        if(rxTail == MAX_RX_LEN)
        {
          rxTail = 0;
        }
      }
      TXRX_SetParameter(TX_DATA_CHAR, send, data);
    }

    return (events ^ SBP_RX_TIME_OUT_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      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 )
	{
		// Start the Device
		VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );
		
		// Start Bond Manager
		VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );
		
		// Set timer for first periodic event
		osal_start_timerEx( simpleBLEPeripheral_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( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
		}
		
		// Perform periodic application task
		performPeriodicTask();
		
		return (events ^ SBP_PERIODIC_EVT);
	}
	
	if ( events & SBP_LED_TOGGLE_EVT )
	{
		// Assuming that the LED is on P0_4 in the circuit.
		if(led_toggle_flag == 0)
		{
			P0_4 = 1;
			led_toggle_flag = 1;
		}
		else
		{
			P0_4 = 0;
			led_toggle_flag = 0;
		}
		
		VOID osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_LED_TOGGLE_EVT, 1000 );
		return ( events ^ SBP_LED_TOGGLE_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) {

	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
		GAPRole_StartDevice(&simpleBLEPeripheral_PeripheralCBs);

		// Start Bond Manager
		GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs);

		// Set timer for first periodic event
		osal_start_timerEx(simpleBLEPeripheral_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(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
		}

		// Perform periodic application task
		performPeriodicTask();

		return (events ^ SBP_PERIODIC_EVT);
	}

	if (events & SBP_ZEKEZANG_EVT) {
		uint8 initial_advertising_enable = FALSE;
		GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &initial_advertising_enable);
		return (events ^ SBP_ZEKEZANG_EVT);
	}

	if (events & SBP_SEND_IRDATA_EVT) {
		HalLcdWriteString("send plan complete...", HAL_LCD_LINE_4);
		return (events ^ SBP_SEND_IRDATA_EVT);
	}

	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);
	}

	return 0;
}
/*********************************************************************
 * @fn      SimpleBLEPeriph(P0 &= 0xFD)eral_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
  uint8 value = 0;
  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
    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, advert_internal * 1000);

    return ( events ^ SBP_START_DEVICE_EVT );
  }

  if ( events & SBP_PERIODIC_EVT )
  {
      if (!gOpenDoorStep)
        performPeriodicTask();
      osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, advert_internal * 1000);

    return (events ^ SBP_PERIODIC_EVT);
  }

  if(events & SBP_OPENDOOR_DEVICE_EVT)
  {
    switch(gOpenDoorStep)
    {
    case 1:
      //P0.0 ->0
      P0 &= 0xFE;
      DelayMS(20);
      P0 &= 0xFE;
      gOpenDoorStep++;
      osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_OPENDOOR_DEVICE_EVT, 0 );
      break;
    case 2:
      //P0.1 ->1; P0.2 ->0; keep 2s
      //P01_LOW;
      P01_HIGH;
      DelayMS(20);
      //P02_HIGH;
      P02_LOW;
      DelayMS(20);
//      P0 |= 0x02;
//      DelayMS(20);
//      P0 &= 0xFB;
//      DelayMS(20);
      gOpenDoorStep++;
      osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_OPENDOOR_DEVICE_EVT, 500 );
      break;
    case 3:
      //P0.1 ->0; P0.2 ->0; keep 5s
      P0 &= 0xFD;
      DelayMS(20);
      P0 &= 0xFB;
      DelayMS(20);
      gOpenDoorStep++;
      osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_OPENDOOR_DEVICE_EVT, 3500 );
      break;
    case 4:
      //P0.1 ->0; P0.2 ->1; keep 2s
      P0 &= 0xFD;
      DelayMS(20);
      P0 |= 0x04;
      DelayMS(20);
      gOpenDoorStep++;
      osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_OPENDOOR_DEVICE_EVT, 1000 );
      break;
    case 5:
      //P0.0 ->1
      P0 |= 0x01;
      P01_LOW;
      P02_LOW;
      DelayMS(20);
      gOpenDoorStep =0;
      SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, sizeof ( uint8 ), &value );
      break;
    default:
      gOpenDoorStep =0;
      break;
    }
    return (events ^ SBP_OPENDOOR_DEVICE_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;
}
/*********************************************************************
 * @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);
  }
  
  //user add
  if ( events & ZIGBEE_READ_ZM516X_INFO_EVT )
  {
    static uint8 state = 0;
    switch(state)
    {
    case 0:     
      init_zigbee_zm516x( task_id, ZIGBEE_READ_ZM516X_INFO_EVT );
      state = 1;
      break;
    case 1:
      HalGpioSet(HAL_GPIO_ZM516X_ALL,1); 
      HalGpioSet( HAL_GPIO_ZM516X_RESET,1 );
      osal_start_timerEx( task_id, ZIGBEE_READ_ZM516X_INFO_EVT, 100 );
      state = 2;
      break;
    case 2:
      HalGpioSet(HAL_GPIO_ZM516X_ALL,1); 
      read_local_cfg();
      state = 3;
      break;
    case 3:
      UartReceiveData( task_id, ZIGBEE_READ_ZM516X_INFO_EVT );
      state = 2;
      osal_start_timerEx( task_id, ZIGBEE_READ_ZM516X_INFO_EVT, 100 );
      break;
    default:
      break;
    }
    return (events ^ ZIGBEE_READ_ZM516X_INFO_EVT);
  }
  
  if ( events & UART_RECEIVE_EVT )
  {
    static unsigned char lenold = 0;
    unsigned char len = 0;
    //; NPI_ReadTransport(buf,len);
    if((len = NPI_RxBufLen()) > 0)
    {
      if(lenold == len)
      {
        osal_set_event( task_id, ZIGBEE_READ_ZM516X_INFO_EVT );
        lenold = 0;
      }
      else
      {
        lenold = len;
        osal_stop_timerEx( task_id, UART_RECEIVE_EVT );
        osal_start_timerEx( task_id, UART_RECEIVE_EVT, 3 );
      }
      return ( events ^ UART_RECEIVE_EVT );
    }
    else
    {
      //if(lenold > 0)
      //osal_set_event( task_id, SBP_READ_ZM516X_INFO_EVT );
      //lenold = len;
      //osal_start_timerEx( task_id, UART_RECEIVE_EVT, 10 );
      //osal_set_event( task_id, SBP_READ_ZM516X_INFO_EVT );
      return ( events ^ UART_RECEIVE_EVT );
    }
  }
  //end user add
  
  
  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
    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    
    // user add : start user event
    osal_set_event( simpleBLEPeripheral_TaskID, ZIGBEE_READ_ZM516X_INFO_EVT );

    return ( events ^ SBP_START_DEVICE_EVT );
  }

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

    // Perform periodic application task
    performPeriodicTask();

    return (events ^ SBP_PERIODIC_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 )
{

    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 )
    {
        // << Wayne >> << -23dB TX Power >> ++
        HCI_EXT_SetTxPowerCmd(LL_EXT_TX_POWER_MINUS_23_DBM);
        // << Wayne >> << -23dB TX Power >> --
        // Start the Device
        VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );

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

        // Set timer for first periodic event
        osal_start_timerEx( simpleBLEPeripheral_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( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
        }

        // Perform periodic application task
        performPeriodicTask();
        return (events ^ SBP_PERIODIC_EVT);
    }

    // << Wayne >> << Clock >> ++
    if ( events & SBP_CLOCK_UPDATE_EVT )
    {
         if ( DEFAULT_CLOCK_UPDATE_PERIOD )
        {
          osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_CLOCK_UPDATE_EVT, DEFAULT_CLOCK_UPDATE_PERIOD );
        }
        timeAppClockDisplay();
        if(storeCloseTime(23,59))
        {
          UART_SEND_DEBUG_MSG( "Action > CleanCounter\r\n", 23 );
            dbExchangeCounter = 0;
        }
        // Restart clock tick timer
        
        return (events ^ SBP_CLOCK_UPDATE_EVT);
    }
    // << Wayne >> << Clock >> --
    // << Wayne >> <<  Check Connect  Overtime> > ++
    if ( events & SBP_CONNECT_OVERTIME_EVT )
    {      
        Application_TerminateConnection();
        UART_SEND_DEBUG_MSG( "Action > Terminate\r\n", 20 );
        return (events ^ SBP_CONNECT_OVERTIME_EVT);
    }
    // << Wayne >> <<  Check Connect  Overtime> > --
    // Discard unknown events
    return 0;
}
Beispiel #12
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 )
{
  extern uint8 ssid_modify_flag;
  extern uint8 new_ssid[];
  extern uint8 feedback_pwd_state; 
  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
    osal_start_timerEx( simpleBLEPeripheral_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 )
    {
      //周期性触发定时器,使simpleBLEPeripheral_TaskID对应的任务周期性地执行
      osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );                                                                  
    }
    
    // Perform periodic application task
    performPeriodicTask();          //执行周期性的任务
    
    return (events ^ SBP_PERIODIC_EVT);
  }
  
  //pwd state
  if(feedback_pwd_state != 0)
  {
    char2_notify(get_pwd_state());
    feedback_pwd_state = 0;
  }
  
  carlockseatctrol();//car lock control up or down
  
  //Rf470M_sendDelayTimeRXmodeDelayTime();        //  sent data and RXmode                    
  
  if(ssid_modify_flag == 1)                     //Update ssid in ssid changed
  {  
    ssid_modify_flag = 0;
    osal_memcpy(scanRspData + 2, new_ssid, 6);
    osal_memcpy(attDeviceName, new_ssid, 6);

    GAP_UpdateAdvertisingData( simpleBLEPeripheral_TaskID, FALSE, sizeof( scanRspData ), scanRspData );
    GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );
  }
  
  if(immediatly_report_flag == 1)
  {
    immediatly_report_flag = 0;
    report_hub();
  }

  return 0;
}