| AVR Z-LINKŪ | |||||
The handleNewCommand() is called whenever a new AT command has been indicated by polling of the dataAvailable( ). Rest of the function members in this file are internal (static) and will only be called by handleNewCommand().
Definition in file atParser.c.
#include <stdbool.h>
#include <stdint.h>
#include "compiler.h"
#include "ieee_const.h"
#include "ieee_types.h"
#include "wpan_mac.h"
#include "chat.h"
#include "atParser.h"
#include "serialPortHAL.h"
#include "utilities.h"
Include dependency graph for atParser.c:

Go to the source code of this file.
Functions | |
| void | handleNewCommand (void) |
| This function is called to handle a newly arrived AT command. | |
| static void | sendMsg (uint8_t msgLength, uint8_t *msg) |
| This function will send the supplied data to the other end of the link. | |
| static void | startNetworkOperation (uint8_t channelToScan) |
| This function will send an mlme_scan.request. | |
| static void | stopNetworkOperation (void) |
| This function defines the procedure for terminate a network. | |
Variables | |
| unsigned char __flash | ATC [] = "AT+C" |
| unsigned char __flash | ATD [] = "AT+D" |
| The AT+C string. | |
| unsigned char __flash | ATR [] = "AT+R" |
| The AT+D string. | |
| unsigned char __flash | ATT [] = "AT+T" |
| The AT+R string. | |
| uint8_t | chatChannel = DEFAULT_CHANNEL |
| The AT+C string. | |
| uint16_t | chatPANID = DEFAULT_PANID |
| chatRole_t | role = UNDEFINED |
| chatState_t | state = CHAT_IDLE |
| void handleNewCommand | ( | void | ) |
This function is called to handle a newly arrived AT command.
When new data/a command is received through one of the serial interfaces (USART or USB) it must be parsed. The parsing procedure is done as follows:
Definition at line 77 of file atParser.c.
References ATC, ATD, ATR, ATT, CHAT_CONNECTED, CHAT_IDLE, CHAT_RESET_PENDING, chatChannel, chatPANID, COORDINATOR, DATA_CONVERSION_FAILED, DEVICE_TYPE_COORDINATOR, DEVICE_TYPE_END_DEVICE, END_DEVICE, getATCommand(), getParameterNumber(), htoi16(), htoi8(), INCONSISTENT_STATE, INVALID_REQUEST, PARAMETER_1, PARAMETER_2, PARAMETER_3, role, sendERROR(), sendMsg(), startNetworkOperation(), state, stopNetworkOperation(), stringCompare(), UNKNOWN_AT_COMMAND, and UNKNOWN_DEVICE_TYPE.
Referenced by main().
00077 { 00078 00079 uint8_t *ATCommand; 00080 uint8_t *msg; 00081 uint8_t msgLength; 00082 uint8_t deviceType; 00083 00084 //Read new AT-Command from the receive buffer. 00085 ATCommand = getATCommand( ); 00086 00087 //Check if the received command is known. 00088 00089 //Start network operation. 00090 if( stringCompare( ATCommand, ATC ) ){ 00091 00092 //Ensure that this function is only called after reset. 00093 if( state != CHAT_IDLE ){ 00094 00095 sendERROR( INVALID_REQUEST ); 00096 return; 00097 } 00098 00099 //Extract and check channel to chat on. 00100 if( !htoi8( getParameterNumber( PARAMETER_1 ), &chatChannel ) ){ 00101 00102 //Error occured during conversion. Send error message and end. 00103 sendERROR( DATA_CONVERSION_FAILED ); 00104 return; 00105 } 00106 00107 //Extract and check PANID. 00108 if( !htoi16( getParameterNumber( PARAMETER_2 ), &chatPANID ) ){ 00109 00110 //Error occured during conversion. Send error message and end. 00111 sendERROR( DATA_CONVERSION_FAILED ); 00112 return; 00113 } 00114 00115 //Read device type. Will be checked below. 00116 deviceType = *( getParameterNumber( PARAMETER_3 ) ); 00117 00118 00119 //Check if desired device type equals coordinator. 00120 if( deviceType == DEVICE_TYPE_COORDINATOR ){ 00121 00122 role = COORDINATOR; 00123 } 00124 00125 //Check if desired device type equals end-device. 00126 else if( deviceType == DEVICE_TYPE_END_DEVICE ){ 00127 00128 role = END_DEVICE; 00129 } 00130 00131 //This is not a valid device type. 00132 else{ 00133 00134 sendERROR( UNKNOWN_DEVICE_TYPE ); 00135 return; 00136 } 00137 00138 //It is now safe to start opertaion on current channel and PANID. 00139 startNetworkOperation( chatChannel ); 00140 } 00141 00142 //Stop network...disassociation procedure. 00143 else if( stringCompare( ATCommand, ATD ) ){ 00144 00145 stopNetworkOperation( ); 00146 } 00147 00148 //Reset. 00149 else if( stringCompare( ATCommand, ATR ) ){ 00150 00151 //wpan_init( ); 00152 wpan_mlme_reset_request( true ); 00153 state = CHAT_RESET_PENDING; 00154 } 00155 00156 //Send data. 00157 else if( stringCompare( ATCommand, ATT ) ){ 00158 00159 //Important that messages are not sent without being connected. 00160 if( state != CHAT_CONNECTED ){ 00161 00162 sendERROR( INCONSISTENT_STATE ); 00163 return; 00164 } 00165 00166 //Extract and check length of data. 00167 if( !htoi8( getParameterNumber( PARAMETER_1 ), &msgLength ) ){ 00168 00169 //Error occured during conversion. Send error message and end. 00170 sendERROR( DATA_CONVERSION_FAILED ); 00171 return; 00172 } 00173 00174 //Extract the data it self. No checks will be done. 00175 msg = getParameterNumber( PARAMETER_2 ); 00176 sendMsg( msgLength, msg ); 00177 } 00178 00179 //Received an AT command that is not supported. 00180 else{ 00181 00182 sendERROR( UNKNOWN_AT_COMMAND ); 00183 } 00184 }
Here is the call graph for this function:

| static void sendMsg | ( | uint8_t | msgLength, | |
| uint8_t * | msg | |||
| ) | [static] |
This function will send the supplied data to the other end of the link.
In advance of the call to this function the correct state and data length has been verified. Then it is safe to use the mcps_data.request directly. This primitive will send the data to the other peer in the link.
| msgLength | Length of data/message to send in bytes. | |
| msg | Pointer to the actual payload. |
Definition at line 230 of file atParser.c.
References chatPANID, COORD_SHORT_ADDRESS, COORDINATOR, END_DEVICE_SHORT_ADDRESS, EVENT_BUFFER_FULL, INVALID_REQUEST, MAX_MSG_LENGTH, role, and sendERROR().
Referenced by handleNewCommand().
00230 { 00231 00232 //Setup address and PAN information. 00233 wpan_mcpsdata_addr_t addr_info; 00234 addr_info.SrcAddrMode = WPAN_ADDRMODE_SHORT; 00235 addr_info.DstAddrMode = WPAN_ADDRMODE_SHORT; 00236 addr_info.SrcPANId = chatPANID; 00237 addr_info.DstPANId = chatPANID; 00238 00239 //Check length of message. 00240 if( !( msgLength <= MAX_MSG_LENGTH ) ){ 00241 00242 sendERROR( INVALID_REQUEST ); 00243 return; 00244 } 00245 00246 00247 //Coordinator. 00248 if( role == COORDINATOR ){ 00249 00250 addr_info.SrcAddr = COORD_SHORT_ADDRESS; 00251 addr_info.DstAddr = END_DEVICE_SHORT_ADDRESS; 00252 } 00253 00254 //End-device. 00255 else{ 00256 00257 addr_info.SrcAddr = END_DEVICE_SHORT_ADDRESS; 00258 addr_info.DstAddr = COORD_SHORT_ADDRESS; 00259 } 00260 00261 00262 if( wpan_mcps_data_request( &addr_info, 0x01, WPAN_TXOPT_ACK, msg, msgLength ) ){ 00263 00264 ; 00265 } 00266 00267 else{ 00268 00269 sendERROR( EVENT_BUFFER_FULL ); 00270 } 00271 }
Here is the call graph for this function:

| static void startNetworkOperation | ( | uint8_t | channelToScan | ) | [static] |
This function will send an mlme_scan.request.
The mlme_scan.request will initiate the steps needed to establish/start a new peer-to-peer link (Coordinator), the process to become the other peer (End-device) in this link (associate).
| channelToScan | Channel to start the new network on, or to associate to. |
Definition at line 197 of file atParser.c.
References CHAT_ACTIVE_SCAN_PENDING, chatChannel, SCANDURATION, and state.
Referenced by handleNewCommand().
00197 { 00198 00199 uint32_t channelMask = 1UL; 00200 00201 //Generate channel mask as defined in MLME_SCAN_request. 00202 channelMask = channelMask << chatChannel; 00203 00204 //Issue an active scan on the given channel for a define period. 00205 wpan_mlme_scan_request( MLME_SCAN_TYPE_ACTIVE, channelMask, 00206 SCANDURATION ); 00207 00208 state = CHAT_ACTIVE_SCAN_PENDING; 00209 }
| static void stopNetworkOperation | ( | void | ) | [static] |
This function defines the procedure for terminate a network.
Not implemented yet. Is not supported by the GUI application.
Definition at line 216 of file atParser.c.
Referenced by handleNewCommand().
| unsigned char __flash ATC[] = "AT+C" |
| unsigned char __flash ATD[] = "AT+D" |
| unsigned char __flash ATR[] = "AT+R" |
| unsigned char __flash ATT[] = "AT+T" |
| uint8_t chatChannel = DEFAULT_CHANNEL |
The AT+C string.
Definition at line 50 of file atParser.c.
Referenced by handleNewCommand(), startNetworkOperation(), usr_mlme_scan_conf(), and usr_mlme_set_conf().
| uint16_t chatPANID = DEFAULT_PANID |
Definition at line 51 of file atParser.c.
Referenced by handleNewCommand(), sendMsg(), usr_mlme_scan_conf(), and usr_mlme_set_conf().
| chatRole_t role = UNDEFINED |
Definition at line 53 of file atParser.c.
Referenced by handleNewCommand(), sendMsg(), and usr_mlme_scan_conf().
| chatState_t state = CHAT_IDLE |
Definition at line 52 of file atParser.c.
Referenced by handleNewCommand(), startNetworkOperation(), usr_mcps_data_ind(), usr_mlme_associate_conf(), usr_mlme_associate_ind(), usr_mlme_comm_status_ind(), usr_mlme_reset_conf(), usr_mlme_scan_conf(), usr_mlme_set_conf(), and usr_mlme_start_conf().
Generated on Sat Dec 2 16:05:51 2006 for AVR414 User's Guide - ATAVRRZ502 - Accessory Kit by 1.4.7
|