Stephen Davis
/
BT_Hub
Library set up as dummy module on mbed to mimic Nordic.
rs485.cpp@2:9ab591cf81b8, 2016-12-13 (annotated)
- Committer:
- Stephen_NewVistas
- Date:
- Tue Dec 13 00:20:29 2016 +0000
- Revision:
- 2:9ab591cf81b8
- Parent:
- 1:d6b18299a715
everything commented . now going to strip out mbed stuff.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stephen_NewVistas | 0:226550611f0d | 1 | #include <string.h> |
Stephen_NewVistas | 0:226550611f0d | 2 | #include <stdio.h> |
Stephen_NewVistas | 0:226550611f0d | 3 | |
Stephen_NewVistas | 0:226550611f0d | 4 | #include "rs485.h" |
Stephen_NewVistas | 0:226550611f0d | 5 | |
Stephen_NewVistas | 0:226550611f0d | 6 | #define DEBUG |
Stephen_NewVistas | 0:226550611f0d | 7 | |
Stephen_NewVistas | 0:226550611f0d | 8 | static list_t functionList = { .index = 0 }; |
Stephen_NewVistas | 0:226550611f0d | 9 | |
Stephen_NewVistas | 0:226550611f0d | 10 | Packet buildPacket; |
Stephen_NewVistas | 0:226550611f0d | 11 | static unsigned int buffPtr; |
Stephen_NewVistas | 0:226550611f0d | 12 | static unsigned char buffer[128+1]; |
Stephen_NewVistas | 0:226550611f0d | 13 | int checksum; |
Stephen_NewVistas | 0:226550611f0d | 14 | int pState = START; |
Stephen_NewVistas | 0:226550611f0d | 15 | int returnState; |
Stephen_NewVistas | 0:226550611f0d | 16 | unsigned int plength; |
Stephen_NewVistas | 0:226550611f0d | 17 | unsigned char command; |
Stephen_NewVistas | 0:226550611f0d | 18 | int message; |
Stephen_NewVistas | 0:226550611f0d | 19 | static unsigned char packetBuffer[128]; |
Stephen_NewVistas | 0:226550611f0d | 20 | static unsigned int packetBufferSize; |
Stephen_NewVistas | 0:226550611f0d | 21 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 22 | /************************** External Functions******************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 23 | * These functions need to be externall defined to be able to process packets |
Stephen_NewVistas | 2:9ab591cf81b8 | 24 | * and to send out chars over the bus. |
Stephen_NewVistas | 2:9ab591cf81b8 | 25 | /************************** External Functions********************************/ |
Stephen_NewVistas | 0:226550611f0d | 26 | extern int Bluetooth_ReceivePacket( Packet *_packet ); |
Stephen_NewVistas | 0:226550611f0d | 27 | extern int Bluetooth_SendChar( unsigned char ); |
Stephen_NewVistas | 2:9ab591cf81b8 | 28 | extern const unsigned char DEVADDRESS; |
Stephen_NewVistas | 0:226550611f0d | 29 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 30 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 31 | * Function void RegisterCommand( command , function ) |
Stephen_NewVistas | 2:9ab591cf81b8 | 32 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 33 | * When a command is registered with this function it will be added to the function |
Stephen_NewVistas | 2:9ab591cf81b8 | 34 | * list. Once on the list, when a packet is received on the bus containing that |
Stephen_NewVistas | 2:9ab591cf81b8 | 35 | * command the associated function will get called and it will be passed the data |
Stephen_NewVistas | 2:9ab591cf81b8 | 36 | * within the packet as a parameter. |
Stephen_NewVistas | 2:9ab591cf81b8 | 37 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 38 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 39 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 40 | * Input: 'command' - command byte |
Stephen_NewVistas | 2:9ab591cf81b8 | 41 | * 'function' - pointer to function to be called |
Stephen_NewVistas | 2:9ab591cf81b8 | 42 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 43 | * Output: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 44 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 45 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 46 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 47 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 48 | unsigned char RegisterCommand( unsigned char _command , void (*_function)( unsigned char *) ){ |
Stephen_NewVistas | 0:226550611f0d | 49 | functionList.list[ functionList.index ].function = _function; |
Stephen_NewVistas | 0:226550611f0d | 50 | functionList.list[ functionList.index ].command = _command; |
Stephen_NewVistas | 0:226550611f0d | 51 | functionList.index++; |
Stephen_NewVistas | 0:226550611f0d | 52 | return 0; |
Stephen_NewVistas | 0:226550611f0d | 53 | } |
Stephen_NewVistas | 0:226550611f0d | 54 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 55 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 56 | * Function void CheckFunction( Packet * ) |
Stephen_NewVistas | 2:9ab591cf81b8 | 57 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 58 | * This passes in a packet and compares the command byte with a list of registered |
Stephen_NewVistas | 2:9ab591cf81b8 | 59 | * commands. If it finds a match it will call that function along with the data |
Stephen_NewVistas | 2:9ab591cf81b8 | 60 | * in the packet. |
Stephen_NewVistas | 2:9ab591cf81b8 | 61 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 62 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 63 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 64 | * Input: '_packet' - packet containing command byte and data |
Stephen_NewVistas | 2:9ab591cf81b8 | 65 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 66 | * Output: '1' - command matched and function called |
Stephen_NewVistas | 2:9ab591cf81b8 | 67 | * '2' - no command found |
Stephen_NewVistas | 2:9ab591cf81b8 | 68 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 69 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 70 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 71 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 72 | int CheckFunction( Packet *_packet ){ |
Stephen_NewVistas | 0:226550611f0d | 73 | int i = 0; |
Stephen_NewVistas | 0:226550611f0d | 74 | void (*Caller)(unsigned char *); |
Stephen_NewVistas | 0:226550611f0d | 75 | for( i = 0 ; i < functionList.index ; i++ ){ |
Stephen_NewVistas | 0:226550611f0d | 76 | if( _packet->command == functionList.list[i].command ){ |
Stephen_NewVistas | 0:226550611f0d | 77 | Caller = (void (*)(unsigned char *))functionList.list[i].function; |
Stephen_NewVistas | 0:226550611f0d | 78 | Caller( (unsigned char *)_packet->packetData ); |
Stephen_NewVistas | 0:226550611f0d | 79 | return 1; |
Stephen_NewVistas | 0:226550611f0d | 80 | } |
Stephen_NewVistas | 0:226550611f0d | 81 | } |
Stephen_NewVistas | 0:226550611f0d | 82 | return 0; |
Stephen_NewVistas | 0:226550611f0d | 83 | } |
Stephen_NewVistas | 0:226550611f0d | 84 | |
Stephen_NewVistas | 0:226550611f0d | 85 | void RS495_Init( void ){ |
Stephen_NewVistas | 0:226550611f0d | 86 | |
Stephen_NewVistas | 0:226550611f0d | 87 | } |
Stephen_NewVistas | 0:226550611f0d | 88 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 89 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 90 | * Function void SendAck( void ) |
Stephen_NewVistas | 2:9ab591cf81b8 | 91 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 92 | * Sends an acknowledge byte over the bus. It calls an external function to |
Stephen_NewVistas | 2:9ab591cf81b8 | 93 | * handle the actual hardware communication. |
Stephen_NewVistas | 2:9ab591cf81b8 | 94 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 95 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 96 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 97 | * Input: '_packet' - prebuilt packet to send |
Stephen_NewVistas | 2:9ab591cf81b8 | 98 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 99 | * Output: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 100 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 101 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 102 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 103 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 104 | static void SendAck( void ){ |
Stephen_NewVistas | 0:226550611f0d | 105 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 106 | pc.printf( "\n\rAck Sent.\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 107 | #endif // DEBUG |
Stephen_NewVistas | 0:226550611f0d | 108 | unsigned char ack = ACKCHAR; |
Stephen_NewVistas | 0:226550611f0d | 109 | Bluetooth_SendChar( ack ); |
Stephen_NewVistas | 0:226550611f0d | 110 | } |
Stephen_NewVistas | 0:226550611f0d | 111 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 112 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 113 | * Function void SendNack( void ) |
Stephen_NewVistas | 2:9ab591cf81b8 | 114 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 115 | * Sends a non acknowledge byte over the bus. It calls an external function to |
Stephen_NewVistas | 2:9ab591cf81b8 | 116 | * handle the actual hardware communication. |
Stephen_NewVistas | 2:9ab591cf81b8 | 117 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 118 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 119 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 120 | * Input: '_packet' - prebuilt packet to send |
Stephen_NewVistas | 2:9ab591cf81b8 | 121 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 122 | * Output: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 123 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 124 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 125 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 126 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 127 | static void SendNack( void ){ |
Stephen_NewVistas | 0:226550611f0d | 128 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 129 | pc.printf( "\n\rNack Sent.\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 130 | #endif // DEBUG |
Stephen_NewVistas | 0:226550611f0d | 131 | unsigned char nack = NAKCHAR; |
Stephen_NewVistas | 0:226550611f0d | 132 | Bluetooth_SendChar( nack ); |
Stephen_NewVistas | 0:226550611f0d | 133 | } |
Stephen_NewVistas | 0:226550611f0d | 134 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 135 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 136 | * Function void ProcessPacket( Packet *) |
Stephen_NewVistas | 2:9ab591cf81b8 | 137 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 138 | * Gets automatically called once an entire packet is successfully received. |
Stephen_NewVistas | 2:9ab591cf81b8 | 139 | * May modify what is done, but it should just pass the packet over to |
Stephen_NewVistas | 2:9ab591cf81b8 | 140 | * an external function where it can be correctly handled. |
Stephen_NewVistas | 2:9ab591cf81b8 | 141 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 142 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 143 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 144 | * Input: '_packet' - packet received on bus |
Stephen_NewVistas | 2:9ab591cf81b8 | 145 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 146 | * Output: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 147 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 148 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 149 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 150 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 151 | static int ProcessPacket( Packet *_packet ){ |
Stephen_NewVistas | 0:226550611f0d | 152 | return Bluetooth_ReceivePacket( _packet ); |
Stephen_NewVistas | 0:226550611f0d | 153 | } |
Stephen_NewVistas | 2:9ab591cf81b8 | 154 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 155 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 156 | * Function void setResponse(int, int, int) |
Stephen_NewVistas | 2:9ab591cf81b8 | 157 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 158 | * This function sets the feedback information to be send in the master device. |
Stephen_NewVistas | 2:9ab591cf81b8 | 159 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 160 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 161 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 162 | * Input: '_packet' - prebuilt packet to send |
Stephen_NewVistas | 2:9ab591cf81b8 | 163 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 164 | * Output: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 165 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 166 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 167 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 168 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 169 | void SendMessage( void ){ |
Stephen_NewVistas | 0:226550611f0d | 170 | int j = 0; |
Stephen_NewVistas | 0:226550611f0d | 171 | Bluetooth_SendChar( packetBuffer[ j++ ] ); |
Stephen_NewVistas | 0:226550611f0d | 172 | while( j < packetBufferSize ){ |
Stephen_NewVistas | 0:226550611f0d | 173 | if( packetBuffer[ j ] == STARTPACK ){ |
Stephen_NewVistas | 0:226550611f0d | 174 | Bluetooth_SendChar( ESCAPE ); // #SCD Added this line, I think it should be here |
Stephen_NewVistas | 0:226550611f0d | 175 | Bluetooth_SendChar( 0x01 ); |
Stephen_NewVistas | 0:226550611f0d | 176 | j++; |
Stephen_NewVistas | 0:226550611f0d | 177 | } |
Stephen_NewVistas | 0:226550611f0d | 178 | else if( packetBuffer[ j ] == ESCAPE ){ |
Stephen_NewVistas | 0:226550611f0d | 179 | Bluetooth_SendChar( ESCAPE ); |
Stephen_NewVistas | 0:226550611f0d | 180 | Bluetooth_SendChar( ESCAPE ); |
Stephen_NewVistas | 0:226550611f0d | 181 | j++; |
Stephen_NewVistas | 0:226550611f0d | 182 | } |
Stephen_NewVistas | 0:226550611f0d | 183 | else if( packetBuffer[ j ] == STARTPOLL ){ |
Stephen_NewVistas | 0:226550611f0d | 184 | Bluetooth_SendChar( ESCAPE ); |
Stephen_NewVistas | 0:226550611f0d | 185 | Bluetooth_SendChar( 0x02 ); |
Stephen_NewVistas | 0:226550611f0d | 186 | j++; |
Stephen_NewVistas | 0:226550611f0d | 187 | } |
Stephen_NewVistas | 0:226550611f0d | 188 | else{ |
Stephen_NewVistas | 0:226550611f0d | 189 | Bluetooth_SendChar( packetBuffer[ j++ ] ); |
Stephen_NewVistas | 0:226550611f0d | 190 | } |
Stephen_NewVistas | 0:226550611f0d | 191 | } |
Stephen_NewVistas | 0:226550611f0d | 192 | } |
Stephen_NewVistas | 0:226550611f0d | 193 | |
Stephen_NewVistas | 0:226550611f0d | 194 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 195 | * Function void SetResponse( Packet *_packet ) |
Stephen_NewVistas | 0:226550611f0d | 196 | * |
Stephen_NewVistas | 0:226550611f0d | 197 | * This function sets the feedback information to be send in the master device. |
Stephen_NewVistas | 0:226550611f0d | 198 | * |
Stephen_NewVistas | 0:226550611f0d | 199 | * PreCondition: None |
Stephen_NewVistas | 0:226550611f0d | 200 | * |
Stephen_NewVistas | 0:226550611f0d | 201 | * Input: '_packet' - prebuilt packet to send |
Stephen_NewVistas | 0:226550611f0d | 202 | * |
Stephen_NewVistas | 0:226550611f0d | 203 | * Output: None |
Stephen_NewVistas | 0:226550611f0d | 204 | * |
Stephen_NewVistas | 0:226550611f0d | 205 | * Side Effects: None |
Stephen_NewVistas | 0:226550611f0d | 206 | * |
Stephen_NewVistas | 0:226550611f0d | 207 | *****************************************************************************/ |
Stephen_NewVistas | 2:9ab591cf81b8 | 208 | void SetResponsePacket( Packet *_packet ){ |
Stephen_NewVistas | 1:d6b18299a715 | 209 | packetBufferSize = getFormattedPacket(_packet, packetBuffer); |
Stephen_NewVistas | 0:226550611f0d | 210 | message = 1; |
Stephen_NewVistas | 0:226550611f0d | 211 | } |
Stephen_NewVistas | 0:226550611f0d | 212 | |
Stephen_NewVistas | 0:226550611f0d | 213 | /****************************************************************************** |
Stephen_NewVistas | 2:9ab591cf81b8 | 214 | * Function void SetResponseWithData( unsigned char deviceID, unsigned char |
Stephen_NewVistas | 2:9ab591cf81b8 | 215 | command, unsigned char * data, unsigned short dataLength) |
Stephen_NewVistas | 2:9ab591cf81b8 | 216 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 217 | * This function sets the feedback information to be send in the master device. |
Stephen_NewVistas | 2:9ab591cf81b8 | 218 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 219 | * PreCondition: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 220 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 221 | * Input: 'deviceID' - address where the packet is going |
Stephen_NewVistas | 2:9ab591cf81b8 | 222 | 'command' - command to be sent |
Stephen_NewVistas | 2:9ab591cf81b8 | 223 | '*data' - point to unsiged char array packet with data |
Stephen_NewVistas | 2:9ab591cf81b8 | 224 | 'dataLength' - length of 'data' |
Stephen_NewVistas | 2:9ab591cf81b8 | 225 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 226 | * Output: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 227 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 228 | * Side Effects: None |
Stephen_NewVistas | 2:9ab591cf81b8 | 229 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 230 | *****************************************************************************/ |
Stephen_NewVistas | 2:9ab591cf81b8 | 231 | void SetResponseWithData( unsigned char deviceID, unsigned char command, unsigned char * data, unsigned short dataLength){ |
Stephen_NewVistas | 2:9ab591cf81b8 | 232 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 233 | // build packet to be sent |
Stephen_NewVistas | 2:9ab591cf81b8 | 234 | Packet packet; |
Stephen_NewVistas | 2:9ab591cf81b8 | 235 | packet.deviceID = deviceID; |
Stephen_NewVistas | 2:9ab591cf81b8 | 236 | packet.sourceID = DEVADDRESS; |
Stephen_NewVistas | 2:9ab591cf81b8 | 237 | packet.command = command; |
Stephen_NewVistas | 2:9ab591cf81b8 | 238 | packet.packetLength = dataLength; |
Stephen_NewVistas | 2:9ab591cf81b8 | 239 | memcpy( packet.packetData , data , dataLength ); |
Stephen_NewVistas | 2:9ab591cf81b8 | 240 | packetBufferSize = getFormattedPacket(&packet, packetBuffer); |
Stephen_NewVistas | 2:9ab591cf81b8 | 241 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 242 | // print message to be sent |
Stephen_NewVistas | 2:9ab591cf81b8 | 243 | #ifdef DEBUG |
Stephen_NewVistas | 2:9ab591cf81b8 | 244 | pc.printf( "Message to send: "); |
Stephen_NewVistas | 2:9ab591cf81b8 | 245 | unsigned short length = 0; |
Stephen_NewVistas | 2:9ab591cf81b8 | 246 | for( length = 1 ; length < ( dataLength + sizeof( packet.deviceID ) + sizeof( packet.sourceID ) + sizeof( packet.command ) + sizeof( packet.packetLength ) + 1 ) ; length++ ){ |
Stephen_NewVistas | 2:9ab591cf81b8 | 247 | pc.printf( "%x " , packetBuffer[ length ] ); |
Stephen_NewVistas | 2:9ab591cf81b8 | 248 | } |
Stephen_NewVistas | 2:9ab591cf81b8 | 249 | pc.printf( "\n\r" ); |
Stephen_NewVistas | 2:9ab591cf81b8 | 250 | #endif |
Stephen_NewVistas | 2:9ab591cf81b8 | 251 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 252 | message = 1; |
Stephen_NewVistas | 2:9ab591cf81b8 | 253 | } |
Stephen_NewVistas | 2:9ab591cf81b8 | 254 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 255 | /****************************************************************************** |
Stephen_NewVistas | 0:226550611f0d | 256 | * Function void SerialHandler(unsigned char ) |
Stephen_NewVistas | 0:226550611f0d | 257 | * |
Stephen_NewVistas | 0:226550611f0d | 258 | * This function handles the received data from the Serial Communication. |
Stephen_NewVistas | 0:226550611f0d | 259 | * |
Stephen_NewVistas | 0:226550611f0d | 260 | * PreCondition: None |
Stephen_NewVistas | 0:226550611f0d | 261 | * |
Stephen_NewVistas | 0:226550611f0d | 262 | * Input: 'RXByte' - the received data from Serial Communication |
Stephen_NewVistas | 0:226550611f0d | 263 | * |
Stephen_NewVistas | 0:226550611f0d | 264 | * |
Stephen_NewVistas | 0:226550611f0d | 265 | * Output: None |
Stephen_NewVistas | 0:226550611f0d | 266 | * |
Stephen_NewVistas | 2:9ab591cf81b8 | 267 | * Side Effects: Will call functions to send ACK, NACK and process a packet |
Stephen_NewVistas | 2:9ab591cf81b8 | 268 | * once an entire packet is received. |
Stephen_NewVistas | 0:226550611f0d | 269 | * |
Stephen_NewVistas | 0:226550611f0d | 270 | *****************************************************************************/ |
Stephen_NewVistas | 0:226550611f0d | 271 | void SerialHandler(unsigned char RXByte){ |
Stephen_NewVistas | 0:226550611f0d | 272 | |
Stephen_NewVistas | 0:226550611f0d | 273 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 274 | pc.printf( "RXByte: %x" , RXByte ); |
Stephen_NewVistas | 0:226550611f0d | 275 | #endif |
Stephen_NewVistas | 0:226550611f0d | 276 | |
Stephen_NewVistas | 0:226550611f0d | 277 | |
Stephen_NewVistas | 0:226550611f0d | 278 | // check the incoming byte for special characters |
Stephen_NewVistas | 0:226550611f0d | 279 | if( RXByte == STARTPACK ){ // start of packet byte |
Stephen_NewVistas | 0:226550611f0d | 280 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 281 | pc.printf( " - STARTBYTE\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 282 | #endif |
Stephen_NewVistas | 0:226550611f0d | 283 | pState = DEVICEADDRESS; // move on to check the destination address |
Stephen_NewVistas | 0:226550611f0d | 284 | buffPtr = 0; // reset buffer pointer |
Stephen_NewVistas | 0:226550611f0d | 285 | buffer[buffPtr++] = STARTPACK; // load RXByte into buffer |
Stephen_NewVistas | 0:226550611f0d | 286 | checksum = STARTPACK; // add to checksum |
Stephen_NewVistas | 0:226550611f0d | 287 | return; // exit function, will be called again in next state |
Stephen_NewVistas | 0:226550611f0d | 288 | } |
Stephen_NewVistas | 0:226550611f0d | 289 | else if( RXByte == STARTPOLL ){ // poll byte |
Stephen_NewVistas | 0:226550611f0d | 290 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 291 | pc.printf( " - STARTPOLL\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 292 | #endif |
Stephen_NewVistas | 0:226550611f0d | 293 | pState = POLL; // move on to check the distination address |
Stephen_NewVistas | 0:226550611f0d | 294 | return; // exit function, will be called again in next state |
Stephen_NewVistas | 0:226550611f0d | 295 | } |
Stephen_NewVistas | 0:226550611f0d | 296 | else if( RXByte == ESCAPE ){ // escape byte |
Stephen_NewVistas | 0:226550611f0d | 297 | if( pState == HANDLEESCAPE ){ // if this is the second escape byte in a row |
Stephen_NewVistas | 0:226550611f0d | 298 | } |
Stephen_NewVistas | 0:226550611f0d | 299 | else{ |
Stephen_NewVistas | 0:226550611f0d | 300 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 301 | pc.printf( " - ESCAPE TO " ); |
Stephen_NewVistas | 0:226550611f0d | 302 | #endif |
Stephen_NewVistas | 0:226550611f0d | 303 | returnState = pState; // if this is the first escape byte, record the current state |
Stephen_NewVistas | 0:226550611f0d | 304 | pState = HANDLEESCAPE; // change state |
Stephen_NewVistas | 0:226550611f0d | 305 | return; // exit function, will be called again in next state |
Stephen_NewVistas | 0:226550611f0d | 306 | } |
Stephen_NewVistas | 0:226550611f0d | 307 | } |
Stephen_NewVistas | 0:226550611f0d | 308 | |
Stephen_NewVistas | 0:226550611f0d | 309 | if( pState == HANDLEESCAPE ){ // if entering here RXByte needs to be unescaped |
Stephen_NewVistas | 0:226550611f0d | 310 | switch( RXByte ){ |
Stephen_NewVistas | 0:226550611f0d | 311 | case 1: // unescape a 0x7F/Start of packet byte |
Stephen_NewVistas | 0:226550611f0d | 312 | RXByte = 0x7F; |
Stephen_NewVistas | 0:226550611f0d | 313 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 314 | pc.printf( " -> %x" , RXByte ); |
Stephen_NewVistas | 0:226550611f0d | 315 | #endif |
Stephen_NewVistas | 0:226550611f0d | 316 | break; |
Stephen_NewVistas | 0:226550611f0d | 317 | |
Stephen_NewVistas | 0:226550611f0d | 318 | case 2: // unescape a 0x8F/Poll byte |
Stephen_NewVistas | 0:226550611f0d | 319 | RXByte = 0x8F; |
Stephen_NewVistas | 0:226550611f0d | 320 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 321 | pc.printf( " -> %x" , RXByte ); |
Stephen_NewVistas | 0:226550611f0d | 322 | #endif |
Stephen_NewVistas | 0:226550611f0d | 323 | break; |
Stephen_NewVistas | 0:226550611f0d | 324 | |
Stephen_NewVistas | 0:226550611f0d | 325 | case ESCAPE: // unescape a 0x8E/Escape byte |
Stephen_NewVistas | 0:226550611f0d | 326 | RXByte = 0x8E; |
Stephen_NewVistas | 0:226550611f0d | 327 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 328 | pc.printf( " -> %x" , RXByte ); |
Stephen_NewVistas | 0:226550611f0d | 329 | #endif |
Stephen_NewVistas | 0:226550611f0d | 330 | break; |
Stephen_NewVistas | 0:226550611f0d | 331 | } |
Stephen_NewVistas | 0:226550611f0d | 332 | pState = returnState; // change back to state before escape byte received |
Stephen_NewVistas | 0:226550611f0d | 333 | } |
Stephen_NewVistas | 0:226550611f0d | 334 | |
Stephen_NewVistas | 0:226550611f0d | 335 | switch( pState ){ |
Stephen_NewVistas | 0:226550611f0d | 336 | |
Stephen_NewVistas | 0:226550611f0d | 337 | case POLL: // of switch( pState ) // poll state checks RXByte to see if there is an address match |
Stephen_NewVistas | 0:226550611f0d | 338 | |
Stephen_NewVistas | 0:226550611f0d | 339 | |
Stephen_NewVistas | 0:226550611f0d | 340 | if( RXByte == DEVADDRESS ){ // if the device is being polled... |
Stephen_NewVistas | 0:226550611f0d | 341 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 342 | pc.printf( " - Address Match: %x" , DEVADDRESS ); |
Stephen_NewVistas | 0:226550611f0d | 343 | #endif |
Stephen_NewVistas | 0:226550611f0d | 344 | |
Stephen_NewVistas | 0:226550611f0d | 345 | if( message ){ // if a message is available send it |
Stephen_NewVistas | 0:226550611f0d | 346 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 347 | pc.printf( " - Message to Send\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 348 | #endif |
Stephen_NewVistas | 0:226550611f0d | 349 | SendMessage(); // #SCD haven't tested this |
Stephen_NewVistas | 0:226550611f0d | 350 | pState = RESPONSE; // change state to wait for ACK or NACK |
Stephen_NewVistas | 0:226550611f0d | 351 | } |
Stephen_NewVistas | 0:226550611f0d | 352 | else{ // device is pulled but no message to be sent |
Stephen_NewVistas | 0:226550611f0d | 353 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 354 | pc.printf( " - No message to Send\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 355 | #endif |
Stephen_NewVistas | 0:226550611f0d | 356 | SendAck(); // just send an ACK |
Stephen_NewVistas | 0:226550611f0d | 357 | pState = START; |
Stephen_NewVistas | 0:226550611f0d | 358 | } |
Stephen_NewVistas | 0:226550611f0d | 359 | } |
Stephen_NewVistas | 0:226550611f0d | 360 | else{ |
Stephen_NewVistas | 0:226550611f0d | 361 | pState = START; // device not addressed, do nothing |
Stephen_NewVistas | 0:226550611f0d | 362 | } |
Stephen_NewVistas | 0:226550611f0d | 363 | break; |
Stephen_NewVistas | 0:226550611f0d | 364 | |
Stephen_NewVistas | 0:226550611f0d | 365 | case START: // of switch( pState ) // this state really does nothing and just waits for |
Stephen_NewVistas | 0:226550611f0d | 366 | pState = START; // if the device is not addressed in a packet |
Stephen_NewVistas | 0:226550611f0d | 367 | break; |
Stephen_NewVistas | 0:226550611f0d | 368 | |
Stephen_NewVistas | 0:226550611f0d | 369 | case RESPONSE: // of switch( pState ) // a message was sent it last state and now this state is |
Stephen_NewVistas | 0:226550611f0d | 370 | |
Stephen_NewVistas | 0:226550611f0d | 371 | switch( RXByte ){ |
Stephen_NewVistas | 0:226550611f0d | 372 | |
Stephen_NewVistas | 0:226550611f0d | 373 | case ACKCHAR: // ACK is received - message successful, clear message to be sent |
Stephen_NewVistas | 0:226550611f0d | 374 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 375 | pc.printf( " - ACK RECEIVED\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 376 | #endif |
Stephen_NewVistas | 0:226550611f0d | 377 | message = 0; |
Stephen_NewVistas | 0:226550611f0d | 378 | pState = START; |
Stephen_NewVistas | 0:226550611f0d | 379 | break; |
Stephen_NewVistas | 0:226550611f0d | 380 | |
Stephen_NewVistas | 0:226550611f0d | 381 | case NAKCHAR: // NACK is received - message not successful |
Stephen_NewVistas | 0:226550611f0d | 382 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 383 | pc.printf( " - NACK RECEIVED\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 384 | #endif |
Stephen_NewVistas | 0:226550611f0d | 385 | if( message ){ // if a message still needs to be sent, send again |
Stephen_NewVistas | 0:226550611f0d | 386 | SendMessage(); |
Stephen_NewVistas | 0:226550611f0d | 387 | message = 0; // clear message after this seconda attempt to prevent too many tries |
Stephen_NewVistas | 0:226550611f0d | 388 | pState = RESPONSE; // set state to come by here next time around |
Stephen_NewVistas | 0:226550611f0d | 389 | } |
Stephen_NewVistas | 0:226550611f0d | 390 | else{ // if a NACK is received for the second time in a row |
Stephen_NewVistas | 0:226550611f0d | 391 | //#error #SCD // throw an error and do not resend |
Stephen_NewVistas | 0:226550611f0d | 392 | pc.printf( "Received two NACKs from master. Message failed.\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 393 | } |
Stephen_NewVistas | 0:226550611f0d | 394 | break; |
Stephen_NewVistas | 0:226550611f0d | 395 | |
Stephen_NewVistas | 0:226550611f0d | 396 | default: |
Stephen_NewVistas | 0:226550611f0d | 397 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 398 | pc.printf( " - EXPECTED ACK or NACK\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 399 | #endif |
Stephen_NewVistas | 0:226550611f0d | 400 | pState = START; // if neither an ACK nor NACK is received, reset state |
Stephen_NewVistas | 0:226550611f0d | 401 | break; |
Stephen_NewVistas | 0:226550611f0d | 402 | |
Stephen_NewVistas | 0:226550611f0d | 403 | } |
Stephen_NewVistas | 0:226550611f0d | 404 | break; |
Stephen_NewVistas | 0:226550611f0d | 405 | |
Stephen_NewVistas | 0:226550611f0d | 406 | case DEVICEADDRESS: // of switch( pState ) // checks to see if device is addressed in current packet |
Stephen_NewVistas | 0:226550611f0d | 407 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 408 | pc.printf( " - DEVICEADDRESS\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 409 | #endif |
Stephen_NewVistas | 0:226550611f0d | 410 | |
Stephen_NewVistas | 0:226550611f0d | 411 | if( RXByte == DEVADDRESS ){ |
Stephen_NewVistas | 0:226550611f0d | 412 | #ifdef PRINT_ADDRESS_MATCH |
Stephen_NewVistas | 0:226550611f0d | 413 | pc.printf( "Address Match: %d\n\r" , DEVADDRESS ); |
Stephen_NewVistas | 0:226550611f0d | 414 | #endif |
Stephen_NewVistas | 0:226550611f0d | 415 | |
Stephen_NewVistas | 0:226550611f0d | 416 | pState = SOURCEADD; // next state is grabbing the source device ID |
Stephen_NewVistas | 0:226550611f0d | 417 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 418 | buildPacket.deviceID = RXByte; // build packet |
Stephen_NewVistas | 0:226550611f0d | 419 | checksum += RXByte; // add RXByte to checksum |
Stephen_NewVistas | 0:226550611f0d | 420 | } |
Stephen_NewVistas | 0:226550611f0d | 421 | else{ |
Stephen_NewVistas | 0:226550611f0d | 422 | pState = START; // if device is not addressed reset state |
Stephen_NewVistas | 0:226550611f0d | 423 | } |
Stephen_NewVistas | 0:226550611f0d | 424 | |
Stephen_NewVistas | 0:226550611f0d | 425 | break; |
Stephen_NewVistas | 0:226550611f0d | 426 | |
Stephen_NewVistas | 0:226550611f0d | 427 | case SOURCEADD: // of switch( pState ) // records the source address of the packet |
Stephen_NewVistas | 0:226550611f0d | 428 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 429 | pc.printf( " - SOURCEADD\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 430 | #endif |
Stephen_NewVistas | 0:226550611f0d | 431 | |
Stephen_NewVistas | 0:226550611f0d | 432 | pState = COLLECTCOMMAND; // state advances to get the command byte |
Stephen_NewVistas | 0:226550611f0d | 433 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 434 | buildPacket.sourceID = RXByte; // build packet |
Stephen_NewVistas | 0:226550611f0d | 435 | checksum += RXByte; // add RXByte to checksum |
Stephen_NewVistas | 0:226550611f0d | 436 | break; |
Stephen_NewVistas | 0:226550611f0d | 437 | |
Stephen_NewVistas | 0:226550611f0d | 438 | case COLLECTCOMMAND: // of switch( pState )// records the command byte of the packet |
Stephen_NewVistas | 0:226550611f0d | 439 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 440 | pc.printf( " - COMMAND\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 441 | #endif |
Stephen_NewVistas | 0:226550611f0d | 442 | |
Stephen_NewVistas | 0:226550611f0d | 443 | command = RXByte; // record command byte |
Stephen_NewVistas | 0:226550611f0d | 444 | buildPacket.command = RXByte; // build packet |
Stephen_NewVistas | 0:226550611f0d | 445 | pState = COLLECTCOUNT1; // advance to get packetLength |
Stephen_NewVistas | 0:226550611f0d | 446 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 447 | checksum += RXByte; // add RXByte to checksum |
Stephen_NewVistas | 0:226550611f0d | 448 | break; |
Stephen_NewVistas | 0:226550611f0d | 449 | |
Stephen_NewVistas | 0:226550611f0d | 450 | case COLLECTCOUNT1: // of switch( pState ) // records first byte of packetLength |
Stephen_NewVistas | 0:226550611f0d | 451 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 452 | pc.printf( " - COUNT MSB \n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 453 | #endif |
Stephen_NewVistas | 0:226550611f0d | 454 | |
Stephen_NewVistas | 0:226550611f0d | 455 | pState = COLLECTCOUNT2; // advance state to get next byte of packetLength |
Stephen_NewVistas | 0:226550611f0d | 456 | plength = RXByte; |
Stephen_NewVistas | 0:226550611f0d | 457 | plength <<= 8; // store byte in packetLength #SCD is this storing correctly? |
Stephen_NewVistas | 0:226550611f0d | 458 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 459 | checksum += RXByte; // add RXByte to checksum |
Stephen_NewVistas | 0:226550611f0d | 460 | break; |
Stephen_NewVistas | 0:226550611f0d | 461 | |
Stephen_NewVistas | 0:226550611f0d | 462 | case COLLECTCOUNT2: // of switch( pState ) // records second byte of packetLength |
Stephen_NewVistas | 0:226550611f0d | 463 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 464 | pc.printf( " - COUNT LSB\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 465 | #endif |
Stephen_NewVistas | 0:226550611f0d | 466 | |
Stephen_NewVistas | 0:226550611f0d | 467 | plength += RXByte; // add RXByte to packetLength total |
Stephen_NewVistas | 0:226550611f0d | 468 | buildPacket.packetLength = plength; // build packet |
Stephen_NewVistas | 0:226550611f0d | 469 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 470 | checksum += RXByte; // add RXByte to checksum |
Stephen_NewVistas | 0:226550611f0d | 471 | if( plength == 0 ) // if packetLength is 0, advance to checksum state |
Stephen_NewVistas | 0:226550611f0d | 472 | pState = COLLECTCHECKSUM; |
Stephen_NewVistas | 0:226550611f0d | 473 | else // otherwise move on to collect packet payload |
Stephen_NewVistas | 0:226550611f0d | 474 | pState = COLLECTPACKET; |
Stephen_NewVistas | 0:226550611f0d | 475 | break; |
Stephen_NewVistas | 0:226550611f0d | 476 | |
Stephen_NewVistas | 0:226550611f0d | 477 | case COLLECTPACKET: // of switch( pState ) // collects packetData, enters this state multiple times |
Stephen_NewVistas | 0:226550611f0d | 478 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 479 | pc.printf( " - PACKETDATA \n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 480 | #endif |
Stephen_NewVistas | 0:226550611f0d | 481 | |
Stephen_NewVistas | 0:226550611f0d | 482 | plength--; // decrement length |
Stephen_NewVistas | 0:226550611f0d | 483 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 484 | checksum += RXByte; // add RXByte to checksum |
Stephen_NewVistas | 0:226550611f0d | 485 | |
Stephen_NewVistas | 0:226550611f0d | 486 | if( plength == 0 ){ // if collected all packetData advance state |
Stephen_NewVistas | 0:226550611f0d | 487 | pState = COLLECTCHECKSUM; |
Stephen_NewVistas | 0:226550611f0d | 488 | } |
Stephen_NewVistas | 0:226550611f0d | 489 | break; |
Stephen_NewVistas | 0:226550611f0d | 490 | |
Stephen_NewVistas | 0:226550611f0d | 491 | case COLLECTCHECKSUM:// of switch( pState ) // collects checksum of packet and checks for validity |
Stephen_NewVistas | 0:226550611f0d | 492 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 493 | pc.printf( " - CHECKSUM\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 494 | #endif |
Stephen_NewVistas | 0:226550611f0d | 495 | memcpy( &buildPacket.packetData , &buffer[6] , buildPacket.packetLength ); |
Stephen_NewVistas | 0:226550611f0d | 496 | |
Stephen_NewVistas | 0:226550611f0d | 497 | if( RXByte == ( ( checksum* - 1 ) & 0xFF ) ){ // compares RXByte with LSB of checksum |
Stephen_NewVistas | 0:226550611f0d | 498 | message = 0; // if checksum is correct clear message #SCD could a message be waiting? |
Stephen_NewVistas | 0:226550611f0d | 499 | memset(packetBuffer, '\0', 128); // clear packetBuffer |
Stephen_NewVistas | 0:226550611f0d | 500 | |
Stephen_NewVistas | 0:226550611f0d | 501 | buffer[buffPtr++] = RXByte; // add RXByte to buffer |
Stephen_NewVistas | 0:226550611f0d | 502 | |
Stephen_NewVistas | 2:9ab591cf81b8 | 503 | #ifdef DEBUG |
Stephen_NewVistas | 0:226550611f0d | 504 | pc.printf( "Receive Buffer: " ); // debug print received packet |
Stephen_NewVistas | 0:226550611f0d | 505 | unsigned int i = 0; |
Stephen_NewVistas | 0:226550611f0d | 506 | for( i = 0 ; i < buffPtr ; i++ ){ |
Stephen_NewVistas | 0:226550611f0d | 507 | pc.printf( "%x " , buffer[ i ] ); |
Stephen_NewVistas | 0:226550611f0d | 508 | } |
Stephen_NewVistas | 0:226550611f0d | 509 | pc.printf( "\n\r" ); |
Stephen_NewVistas | 0:226550611f0d | 510 | #endif |
Stephen_NewVistas | 0:226550611f0d | 511 | |
Stephen_NewVistas | 0:226550611f0d | 512 | int errorResult = ProcessPacket( &buildPacket ); |
Stephen_NewVistas | 0:226550611f0d | 513 | |
Stephen_NewVistas | 0:226550611f0d | 514 | if( errorResult == -1 ){ // check to make sure function performed properly |
Stephen_NewVistas | 0:226550611f0d | 515 | //#SCD setResponse(RPIADDRESS, command, ERRORCOMMAND); |
Stephen_NewVistas | 0:226550611f0d | 516 | } |
Stephen_NewVistas | 0:226550611f0d | 517 | SendAck(); // send an ACK |
Stephen_NewVistas | 0:226550611f0d | 518 | } |
Stephen_NewVistas | 0:226550611f0d | 519 | else{ |
Stephen_NewVistas | 0:226550611f0d | 520 | SendNack(); // if checksum is not corret, send a NACK |
Stephen_NewVistas | 0:226550611f0d | 521 | } |
Stephen_NewVistas | 0:226550611f0d | 522 | |
Stephen_NewVistas | 0:226550611f0d | 523 | pState = START; |
Stephen_NewVistas | 0:226550611f0d | 524 | break; |
Stephen_NewVistas | 0:226550611f0d | 525 | |
Stephen_NewVistas | 0:226550611f0d | 526 | } // end switch( pState ) |
Stephen_NewVistas | 0:226550611f0d | 527 | |
Stephen_NewVistas | 0:226550611f0d | 528 | } // end serial2Handler function |
Stephen_NewVistas | 0:226550611f0d | 529 | |
Stephen_NewVistas | 0:226550611f0d | 530 |