コード例 #1
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;
}
コード例 #2
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 )
  {
    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;
}
コード例 #3
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);
	}

	// Discard unknown events
	return 0;
}
コード例 #4
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;
}
コード例 #5
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;
}
コード例 #6
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 );

//    sys_config.pwm[0] = 0; //blue
//    sys_config.pwm[1] = 0;//green
//    sys_config.pwm[2] = 0;//red
//    sys_config.pwm[3] = 0;//white


    ti_pwm_init(2500, sys_config.pwm[0], sys_config.pwm[1], sys_config.pwm[2], sys_config.pwm[3]);  

    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_SET_PWM_EVT, 100 );


    //if(g_initFlag == FALSE)
    {   
        // 进行自测 SBP_SELF_TEST_EVT
        osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_SELF_TEST_EVT, 200 );
    }

    return ( events ^ SBP_START_DEVICE_EVT );
  }


  if ( events & SBP_SELF_TEST_EVT )
  {
    static uint8 count = 0;

    if(count%3 == 0)
    {
        sys_config.pwm[3] = 0; // 白色
        sys_config.pwm[2] = 0; // 红色
        sys_config.pwm[1] = 0; // 绿色
        sys_config.pwm[0] = 255; // 蓝色  
    }    
    else if(count%3 == 1)
    {
        sys_config.pwm[3] = 0; // 白色
        sys_config.pwm[2] = 0; // 红色
        sys_config.pwm[1] = 255; // 绿色
        sys_config.pwm[0] = 0; // 蓝色  
    }    
    else if(count%3 == 2)
    {
        sys_config.pwm[3] = 0; // 白色
        sys_config.pwm[2] = 255; // 红色
        sys_config.pwm[1] = 0; // 绿色
        sys_config.pwm[0] = 0; // 蓝色  
    }

    count++;
    if(count < 10)
    {
        osal_set_event( simpleBLEPeripheral_TaskID, SBP_SET_PWM_EVT);
        osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_SELF_TEST_EVT, 800 );
    }
    return (events ^ SBP_SELF_TEST_EVT);
  }



  if ( events & SBP_PERIODIC_EVT )
  {
    // Restart timer
    if ( SBP_PERIODIC_EVT_PERIOD )
    {

    }

    // Perform periodic application task
    //performPeriodicTask();

    return (events ^ SBP_PERIODIC_EVT);
  }


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

  if ( events & KFD_BATTERY_CHECK_EVT )
  {
    // Restart timer
    if ( BATTERY_CHECK_PERIOD )
    {
      osal_start_timerEx( simpleBLEPeripheral_TaskID, KFD_BATTERY_CHECK_EVT, BATTERY_CHECK_PERIOD );
    }

    // perform battery level check
    Batt_MeasLevel( );

    return (events ^ KFD_BATTERY_CHECK_EVT);
  }


  if ( events & SBP_SET_PWM_EVT )
  {
    ti_pwm_set_period(PWM1_P11, sys_config.pwm[0], 300);  
    ti_pwm_set_period(PWM2_P10, sys_config.pwm[1], 300);  
    ti_pwm_set_period(PWM3_P07, sys_config.pwm[2], 300);  
    ti_pwm_set_period(PWM4_P06, sys_config.pwm[3], 300);
    
    return (events ^ SBP_SET_PWM_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;
}
コード例 #7
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;
}
コード例 #8
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;
}
コード例 #9
0
ファイル: simpleBLETest.c プロジェクト: liu470895/car_lock
/*********************************************************************
 * @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;
}