AVR Z-LINKŪ


atParser.h File Reference


Detailed Description

Header file for the atParser.c.

Application note:
AVR414: User's Guide - ATAVRRZ502 - Accessory Kit
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
Revision
1.2
RCSfile
ATInterface.h,v
Date
2006/09/15 17:02:19

Definition in file atParser.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DEVICE_TYPE_COORDINATOR   'C'
#define DEVICE_TYPE_END_DEVICE   'E'

Functions

void handleNewCommand (void)
 This function is called to handle a newly arrived AT command.


Define Documentation

#define DEVICE_TYPE_COORDINATOR   'C'

Definition at line 29 of file atParser.h.

Referenced by handleNewCommand().

#define DEVICE_TYPE_END_DEVICE   'E'

Definition at line 30 of file atParser.h.

Referenced by handleNewCommand().


Function Documentation

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:

  1. extract AT command field from data buffer.
  2. check if the received command is one of the four valid.
  3. if valid:
    • check if it is possible to execute the command. That the current state is valid etc.
    • extract and check range of associated parameters. Return with DATA_CONVERSION_FAILED if the check failed.
    • start execution by calling one of the internal (static) members in this file.
  4. if not valid:
    • return with error messsage (UNKNOWN_AT_COMMAND).

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:

@DOC_TITLE@
Generated on Sat Dec 2 16:05:51 2006 for AVR414 User's Guide - ATAVRRZ502 - Accessory Kit by doxygen 1.4.7