Download Development of a ZigBee Wireless Sensor Node
Transcript
if(cnt>0)
strcpy(readbuff, readbuff+cnt);
for( cnt=0 ; cnt< Nchar ; cnt++ ){ // Search for CR character
if( readbuff[cnt] == '\r'){
CR_pos = cnt;
readbuff[cnt+1] = '\0'; // Appends NULL after CR
strcpy(command, readbuff);
break;
}
else
readbuff[cnt] = toupper(readbuff[cnt]); // Converts to uppercase
}
if( CR_pos > 2 ){ // If CR was detected
if( !strncmp(command, "AT", 2) ) // "AT" prefix detected
valid_AT = 1; // Correct AT command syntax
else if( !strncmp(command, "AD+", 3) ) // "AD+" prefix detected
valid_AD = 1; // Correct AD+ command syntax
else if( !strncmp(command, "HWRESET", 7) ){
hw_reset();
valid_other=1;
}
else if( !strncmp(command, "EUI64=", 6) ){
strncpy(remote_device_eui64, &command[6],16);
sprinti(writebuff, "NEW REMOTE_EUI64=%s\r\nOK\r\n", remote_device_eui64);
while( !HID_Write(writebuff,64) );
valid_other=1;
}
else if( !strncmp(command, "EUI64?", 6) ){
sprinti(writebuff, "CURRENT REMOTE_EUI64=%s\r\nOK\r\n", remote_device_eui64);
while( !HID_Write(writebuff,64) );
valid_other=1;
}
else if( !strncmp(command, "DEFAULTCONF", 11) ){
UART1_Write_Text("ATS0E=0000\r"); // Restore prompts (almost all enabled)
UART1_Write_Text("ATS0F=0006\r");
UART1_Write_Text("ATS12=0C20\r");
UART1_Write_Text("ATS11=0205\r");
// Uart: 115200bps + flow control mode
// Enable wake up on uart activity
sprinti(writebuff, "All prompts enabled, Uart: 115200bps + flow control mode\r\nOK\r\n", remote
_device_eui64);
while( !HID_Write(writebuff,64) );
valid_other=1;
}
}
}
/* This function is immediately called after get_command().
When a valid AT command structure has been detected then it is sent to the ZigBee module through the UART.
Then this function waits for the response of the ZigBee module until an OK or an ERROR:XX message is
received.
When an invalid AD command or an invalid command structure was introduced this function prompts the
subsequent error messages.
When a valid AD command structure has been detected then it is processed in this function. The implemented
AD commands are:
AD+INIT : Initilizes the AD converter calling the function AD_init(). The supported call forms are:
AD+INIT : initializes only channel 0
AD+INITXXXX : initializes the channels selected by XXXX (four hexadecimal digits).
Each channel number is associated to a bit position of XXXX.
For instance: FFFF initializes all the 16 channels.
AD+INITX : initilizes one channel selected by X (an hexadecimal number).
AD+INITdd : initializes one channel selected by dd (two decimal digits from 00 to 15).
AD+RADIO : When the AD is turned on with AD+ON the samples will be transferred to the ZigBee module.
AD+USB :
When the AD is turned on with AD+ON the samples will be transferred to the USB port.
AD+FREQ=<new_frequency> : Changes the frequency of the AD converter to 'new_frequency'.
AD+ON :
Activates the AD converter, it starts sampling.
AD+OFF :
Deactivates the AD converter, it stops sampling. */
void command_process(){
if( valid_AT ){ //AT command issued
UART1_Write_Text(command); // Sends the command to the ETRX module
cnt=0;
while(1){ // LOOPS UNTIL AN OK OR AN ERROR:XX IS RECEIVED
if( uart_semaphore > 0 ){ // uart_rd data waiting to be read
62