【正文】
******************************** This application isn39。t intended to do anything useful, it is intended to be a simple example of an application39。s structure. This application sends it39。s messages either as broadcast or broadcast filtered group messages. The other (more normal) message addressing is unicast. Most of the other sample applications are written to support the unicast message model. Key control: SW1: Sends a flash mand to all devices in Group 1. SW2: Adds/Removes (toggles) this device in and out of Group 1. This will enable and disable the reception of the flash mand.*********************************************************************//********************************************************************* * INCLUDES */include include include include include include include include /* HAL */include include include include include include include include include include include /********************************************************************* * MACROS11 級計算機科學(xué)與技術(shù)37 *//********************************************************************* * CONSTANTS *//********************************************************************* * TYPEDEFS *//********************************************************************* * GLOBAL VARIABLES */// This list should be filled with Application specific Cluster IDs.const cId_t SampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS] ={ SAMPLEAPP_PERIODIC_CLUSTERID, SAMPLEAPP_FLASH_CLUSTERID}。const SimpleDescriptionFormat_t SampleApp_SimpleDesc ={ SAMPLEAPP_ENDPOINT, // int Endpoint。 SAMPLEAPP_PROFID, // uint16 AppProfId[2]。 SAMPLEAPP_DEVICEID, // uint16 AppDeviceId[2]。 SAMPLEAPP_DEVICE_VERSION, // int AppDevVer:4。 SAMPLEAPP_FLAGS, // int AppFlags:4。 SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters。 (cId_t *)SampleApp_ClusterList, // uint8 *pAppInClusterList。 SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters。 (cId_t *)SampleApp_ClusterList // uint8 *pAppInClusterList。}。// This is the Endpoint/Interface description. It is defined here, but// filledin in SampleApp_Init(). Another way to go would be to fill// in the structure here and make it a const (in code space). The// way it39。s defined in this sample app it is define in RAM.endPointDesc_t SampleApp_epDesc。/********************************************************************* * EXTERNAL VARIABLES *//********************************************************************* * EXTERNAL FUNCTIONS *//********************************************************************* * LOCAL VARIABLES11 級計算機科學(xué)與技術(shù)38 */uint8 SampleApp_TaskID。 // Task ID for internal task/event processing // This variable will be received when // SampleApp_Init() is called.devStates_t SampleApp_NwkState。uint8 SampleApp_TransID。 // This is the unique message ID (counter)afAddrType_t SampleApp_Periodic_DstAddr。 //廣播afAddrType_t SampleApp_Flash_DstAddr。 //組播afAddrType_t SampleApp_P2P_DstAddr。 //點播aps_Group_t SampleApp_Group。uint8 SampleAppPeriodicCounter = 0。uint8 SampleAppFlashCounter = 0。define MY_DEFINI_UART_PORT 0 //自定義串口;ifndef RX_MAX_LENGTH //最大緩沖區(qū)字節(jié)數(shù); define RX_MAX_LENGTH 20endifuint8 RX_BUFFER[RX_MAX_LENGTH]。 //緩沖區(qū);uint8 RX_Length。 //接收到字符串的長度;void APP_CallBackFunction(uint8 port , uint8 event)。 //回調(diào)函數(shù);//static unsigned char endpoint_id = 1。 //ID 為 1 的終端節(jié)點?。。。。。。。。。。。。。。。。。。?!static unsigned char endpoint_id = 2。 //ID 為 2 的終端節(jié)點?。。。。。。。。。。。。。。。。。。?!//static unsigned char endpoint_id = 3。 //ID 為 3 的終端節(jié)點?。。。。。。。。。。。。。。。。。。?!static unsigned char first_start_flag = 1。/********************************************************************* * LOCAL FUNCTIONS */void SampleApp_HandleKeys( uint8 shift, uint8 keys )。void SampleApp_MessageMSGCB( afIningMSGPacket_t *pckt )。void SampleApp_SendPeriodicMessage( void )。void SampleApp_SendFlashMessage( uint16 flashTime )。void SampleApp_Send_P2P_Message(void)。/********************************************************************* * NETWORK LAYER CALLBACKS *//********************************************************************* * PUBLIC FUNCTIONS11 級計算機科學(xué)與技術(shù)39 *//********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */void SampleApp_Init( uint8 task_id ){ u8 ctl_i。 halUARTCfg_t uartConfig。 for(ctl_i=0。ctl_imax_room_num。ctl_i++) { room_list[ctl_i].status = 0x0。 } HalAdcInit()。 //初始化 adc OLED_Init()。 Clear_Black。 SampleApp_TaskID = task_id。 SampleApp_NwkState = DEV_INIT。 SampleApp_TransID = 0。 // Device hardware initialization can be added here or in main() (). // If the hardware is application specific add it here. // If the hardware is other parts of the device add it in main(). if defined ( BUILD_ALL_DEVICES ) // The Demo target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in ) to be jumpered // together if they are we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR。 else zgD