在系统初始化之后,需要进行ZigBee无线模块的选取,因为在系统中可以集成成都无线龙的ZigBee模块,还有上海的悦动05无线模块。因为无线龙的模块需要按键(超过1秒)才能选定,所以在程序中20*1000usdelay,也就大约20ms。SELECT_MODULE_MAX_WAIT_COUNT=5000,所以这个块的最大的延迟时间就是在非无线龙的模块时,需要最多延时5000*1000us=5s。
while(SelectModuleWaitCount <= SELECT_MODULE_MAX_WAIT_COUNT) { while(!erasoc_gpio_read(5)) // have a key { PressCount++; delay(1000); SelectModuleWaitCount++; } if(PressCount >= 20) { PressCount = 0; sysPrintf("Select module:trigger a key!/n"); SendMsgMode = WXL_FLYRF; sysPrintf("SendMsgMode:%d/n", SendMsgMode); break; } PressCount = 0; //clear increased PressCount because of key jitter delay(1000); SelectModuleWaitCount++; }
如果选择的是“无线龙”模块需要进行一些配置,而上海的悦动模块不需要进行配置。在无线龙的模块的配置过程中,需要保证配置成功,因此用了C语言不提倡的goto语句。主要是对发送了一些Config Command的一些步骤://set channel number,//set panid number,//set device type//reset system//start a network
/*const u8 ConfigCmd[][CMD_LENTH] = { {0xFE,0x00,0x13,0x02,0x00,0x01,0x13,0xFF}, //read mac address {0xFE,0x00,0x12,0x07,0x00,0x84,0x04,0x00,0x80,0x00,0x00,0x14,0xFF},//set channel number {0xFE,0x00,0x12,0x05,0x00,0x83,0x02,0x01,0x00,0x15,0xFF}, //set panid number {0xFE,0x00,0x12,0x04,0x00,0x87,0x01,0x00,0x11,0xFF}, //set device type {0xFE,0x00,0x05,0x01,0x00,0x01,0xFF}, //reset system {0xFE,0x0A,0x18,0x00,0x11,0xFF}, //start a network {0xFE,0x00,0x14,0x01,0x00,0x11,0xFF}, //read device information {0xFE,0x01,0xA0,0xFF} };*/ if(SendMsgMode == WXL_FLYRF) { eraSerialBaudSet(&EraSerialChan[1], 38400); delay(10000); chan_num: send_zigbee_cmd(ConfigCmd[CHAN_NUM]); GlobalFrameStatus = rec_zigbee_rly(ConfigCmd[CHAN_NUM], STATUS_00); sysPrintf("CHAN_NUM---GlobalFrameStatus:%d/n", GlobalFrameStatus); if(GlobalFrameStatus == -1) goto chan_num; pan_id: send_zigbee_cmd(ConfigCmd[PAN_ID]); GlobalFrameStatus = rec_zigbee_rly(ConfigCmd[PAN_ID], STATUS_00); sysPrintf("PAN_ID---GlobalFrameStatus:%d/n", GlobalFrameStatus); if(GlobalFrameStatus == -1) goto pan_id; set_dev_type: send_zigbee_cmd(ConfigCmd[SET_DEV_TYPE]); GlobalFrameStatus = rec_zigbee_rly(ConfigCmd[SET_DEV_TYPE], STATUS_00); sysPrintf("SET_DEV_TYPE---GlobalFrameStatus:%d/n", GlobalFrameStatus); if(GlobalFrameStatus == -1) goto set_dev_type; reset_sys: send_zigbee_cmd(ConfigCmd[RESET_SYS]); GlobalFrameStatus = rec_zigbee_rly(ConfigCmd[RESET_SYS], STATUS_00); sysPrintf("RESET_SYS---GlobalFrameStatus:%d/n", GlobalFrameStatus); if(GlobalFrameStatus == -1) goto reset_sys; start_net: send_zigbee_cmd(ConfigCmd[START_NET]); GlobalFrameStatus = rec_zigbee_rly(ConfigCmd[START_NET], STATUS_01); sysPrintf("START_NET---GlobalFrameStatus:%d/n", GlobalFrameStatus); if(GlobalFrameStatus == -1) goto start_net; int read_dev_cnt; for(read_dev_cnt = 0; read_dev_cnt < MAX_READ_DEV_STATUS_COUNT; read_dev_cnt++) // for(read_dev_cnt = 0; ; read_dev_cnt++) { delay(3000000); NetFormationFlag = read_zigbee_dev_status(ConfigCmd[READ_DEV_INFO]); sysPrintf("NetFormationFlag:%d/n", NetFormationFlag); if(!NetFormationFlag) { sysPrintf("break read_dev_cnt:%d/n", read_dev_cnt); break; } } if(read_dev_cnt >= MAX_READ_DEV_STATUS_COUNT) goto chan_num; }