Library for using the LSR SiFlex/ProFlex RF modules with mbed.

Committer:
Issus
Date:
Mon Jul 25 16:18:48 2016 +0000
Revision:
0:f9cf4a19bb84
Child:
2:2c0b7246d769
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Issus 0:f9cf4a19bb84 1 /**
Issus 0:f9cf4a19bb84 2 * @file LsrModule.cpp
Issus 0:f9cf4a19bb84 3 * @author LS Research LLC
Issus 0:f9cf4a19bb84 4 * @version 1.0
Issus 0:f9cf4a19bb84 5 *
Issus 0:f9cf4a19bb84 6 * @section LICENSE
Issus 0:f9cf4a19bb84 7 *
Issus 0:f9cf4a19bb84 8 * This program is free software; you can redistribute it and/or
Issus 0:f9cf4a19bb84 9 * modify it under the terms of the GNU General Public License as
Issus 0:f9cf4a19bb84 10 * published by the Free Software Foundation; either version 2 of
Issus 0:f9cf4a19bb84 11 * the License, or (at your option) any later version.
Issus 0:f9cf4a19bb84 12 *
Issus 0:f9cf4a19bb84 13 * This program is distributed in the hope that it will be useful, but
Issus 0:f9cf4a19bb84 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
Issus 0:f9cf4a19bb84 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Issus 0:f9cf4a19bb84 16 * General Public License for more details at
Issus 0:f9cf4a19bb84 17 * http://www.gnu.org/copyleft/gpl.html
Issus 0:f9cf4a19bb84 18 *
Issus 0:f9cf4a19bb84 19 * @section DESCRIPTION
Issus 0:f9cf4a19bb84 20 *
Issus 0:f9cf4a19bb84 21 * Implementation of contents in LsrModule.h.
Issus 0:f9cf4a19bb84 22 */
Issus 0:f9cf4a19bb84 23
Issus 0:f9cf4a19bb84 24 /**
Issus 0:f9cf4a19bb84 25 * Modified by Mark Harris at SAIT.ca
Issus 0:f9cf4a19bb84 26 * Improved functionality for mbed
Issus 0:f9cf4a19bb84 27 */
Issus 0:f9cf4a19bb84 28
Issus 0:f9cf4a19bb84 29 #include "LsrModule.h"
Issus 0:f9cf4a19bb84 30 #include "mbed.h"
Issus 0:f9cf4a19bb84 31
Issus 0:f9cf4a19bb84 32 /**
Issus 0:f9cf4a19bb84 33 * C function pointer typedef.
Issus 0:f9cf4a19bb84 34 *
Issus 0:f9cf4a19bb84 35 */
Issus 0:f9cf4a19bb84 36 typedef void (*ptrRxMsgCallback)(void);
Issus 0:f9cf4a19bb84 37
Issus 0:f9cf4a19bb84 38 /**
Issus 0:f9cf4a19bb84 39 * Table used for subscribing callback functions for
Issus 0:f9cf4a19bb84 40 * received UART messages.
Issus 0:f9cf4a19bb84 41 */
Issus 0:f9cf4a19bb84 42 ptrRxMsgCallback ptrRxMsgCallbackTable[69];
Issus 0:f9cf4a19bb84 43
Issus 0:f9cf4a19bb84 44
Issus 0:f9cf4a19bb84 45 /**
Issus 0:f9cf4a19bb84 46 * This table contains the min and max length for each message type. The first array index
Issus 0:f9cf4a19bb84 47 * is the message type and the second index is the min value (0) or max value (1).
Issus 0:f9cf4a19bb84 48 */
Issus 0:f9cf4a19bb84 49 const uint8_t cau8RxMsgLengthAndTypeTable[69][2] = {
Issus 0:f9cf4a19bb84 50 {12, 39}, // 0x81 - Query Firmware Version Response
Issus 0:f9cf4a19bb84 51 {0, 0}, // 0x82 - Invalid message type
Issus 0:f9cf4a19bb84 52 {0, 0}, // 0x83 - Invalid message type
Issus 0:f9cf4a19bb84 53 {0, 0}, // 0x84 - Invalid message type
Issus 0:f9cf4a19bb84 54 {0, 0}, // 0x85 - Invalid message type
Issus 0:f9cf4a19bb84 55 {0, 0}, // 0x86 - Invalid message type
Issus 0:f9cf4a19bb84 56 {0, 0}, // 0x87 - Invalid message type
Issus 0:f9cf4a19bb84 57 {0, 0}, // 0x88 - Invalid message type
Issus 0:f9cf4a19bb84 58 {0, 0}, // 0x89 - Invalid message type
Issus 0:f9cf4a19bb84 59 {0, 0}, // 0x8A - Invalid message type
Issus 0:f9cf4a19bb84 60 {0, 0}, // 0x8B - Invalid message type
Issus 0:f9cf4a19bb84 61 {5, 5}, // 0x8C - Set Security Transmit Frame Counter Ack
Issus 0:f9cf4a19bb84 62 {11, 11}, // 0x8D - Query Security Transmit Frame Counter Response
Issus 0:f9cf4a19bb84 63 {0, 0}, // 0x8E - Invalid message type
Issus 0:f9cf4a19bb84 64 {0, 0}, // 0x8F - Invalid message type
Issus 0:f9cf4a19bb84 65 {5, 5}, // 0x90 - Set Basic RF Settings Ack
Issus 0:f9cf4a19bb84 66 {39, 39}, // 0x91 - Query Basic RF Settings Response
Issus 0:f9cf4a19bb84 67 {5, 5}, // 0x92 - Save Settings to NV Memory Ack
Issus 0:f9cf4a19bb84 68 {5, 5}, // 0x93 - Reset Request Ack
Issus 0:f9cf4a19bb84 69 {9, 9}, // 0x94 - Query Supply Voltage Response
Issus 0:f9cf4a19bb84 70 {21, 21}, // 0x95 - Query Statistics Response
Issus 0:f9cf4a19bb84 71 {5, 5}, // 0x96 - Clear Statistics Ack
Issus 0:f9cf4a19bb84 72 {0, 0}, // 0x97 - Invalid message type
Issus 0:f9cf4a19bb84 73 {5, 5}, // 0x98 - Set Host Data Rate Ack
Issus 0:f9cf4a19bb84 74 {0, 0}, // 0x99 - Invalid message type
Issus 0:f9cf4a19bb84 75 {0, 0}, // 0x9A - Invalid message type
Issus 0:f9cf4a19bb84 76 {0, 0}, // 0x9B - Invalid message type
Issus 0:f9cf4a19bb84 77 {0, 0}, // 0x9C - Invalid message type
Issus 0:f9cf4a19bb84 78 {0, 0}, // 0x9D - Invalid message type
Issus 0:f9cf4a19bb84 79 {0, 0}, // 0x9E - Invalid message type
Issus 0:f9cf4a19bb84 80 {0, 0}, // 0x9F - Invalid message type
Issus 0:f9cf4a19bb84 81 {7, 7}, // 0xA0 - Send Simple Short Address RF Data Packet Ack
Issus 0:f9cf4a19bb84 82 {17, 115}, // 0xA1 - Received Simple Short Address RF Data Packet
Issus 0:f9cf4a19bb84 83 {7, 7}, // 0xA2 - Send Advanced Short Address RF Data Packet Ack
Issus 0:f9cf4a19bb84 84 {21, 119}, // 0xA3 - Received Advanced Short Address RF Data Packet
Issus 0:f9cf4a19bb84 85 {7, 7}, // 0xA4 - Send Simple Long Address RF Data Packet Ack
Issus 0:f9cf4a19bb84 86 {29, 127}, // 0xA5 - Received Simple Long Address RF Data Packet
Issus 0:f9cf4a19bb84 87 {7, 7}, // 0xA6 - Send Advanced Long Address RF Data Packet Ack
Issus 0:f9cf4a19bb84 88 {33, 131}, // 0xA7 - Received Advanced Long Address RF Data Packet
Issus 0:f9cf4a19bb84 89 {0, 0}, // 0xA8 - Invalid message type
Issus 0:f9cf4a19bb84 90 {0, 0}, // 0xA9 - Invalid message type
Issus 0:f9cf4a19bb84 91 {0, 0}, // 0xAA - Invalid message type
Issus 0:f9cf4a19bb84 92 {0, 0}, // 0xAB - Invalid message type
Issus 0:f9cf4a19bb84 93 {0, 0}, // 0xAC - Invalid message type
Issus 0:f9cf4a19bb84 94 {0, 0}, // 0xAD - Invalid message type
Issus 0:f9cf4a19bb84 95 {13, 131}, // 0xAE - Received Promiscuous Mode Packet
Issus 0:f9cf4a19bb84 96 {0, 0}, // 0xAF - Invalid message type
Issus 0:f9cf4a19bb84 97 {0, 0}, // 0xB0 - Invalid message type
Issus 0:f9cf4a19bb84 98 {0, 0}, // 0xB1 - Invalid message type
Issus 0:f9cf4a19bb84 99 {0, 0}, // 0xB2 - Invalid message type
Issus 0:f9cf4a19bb84 100 {0, 0}, // 0xB3 - Invalid message type
Issus 0:f9cf4a19bb84 101 {0, 0}, // 0xB4 - Invalid message type
Issus 0:f9cf4a19bb84 102 {0, 0}, // 0xB5 - Invalid message type
Issus 0:f9cf4a19bb84 103 {0, 0}, // 0xB6 - Invalid message type
Issus 0:f9cf4a19bb84 104 {0, 0}, // 0xB7 - Invalid message type
Issus 0:f9cf4a19bb84 105 {0, 0}, // 0xB8 - Invalid message type
Issus 0:f9cf4a19bb84 106 {0, 0}, // 0xB9 - Invalid message type
Issus 0:f9cf4a19bb84 107 {0, 0}, // 0xBA - Invalid message type
Issus 0:f9cf4a19bb84 108 {0, 0}, // 0xBB - Invalid message type
Issus 0:f9cf4a19bb84 109 {0, 0}, // 0xBC - Invalid message type
Issus 0:f9cf4a19bb84 110 {0, 0}, // 0xBD - Invalid message type
Issus 0:f9cf4a19bb84 111 {0, 0}, // 0xBE - Invalid message type
Issus 0:f9cf4a19bb84 112 {0, 0}, // 0xBF - Invalid message type
Issus 0:f9cf4a19bb84 113 {0, 0}, // 0xC0 - Invalid message type
Issus 0:f9cf4a19bb84 114 {0, 0}, // 0xC1 - Invalid message type
Issus 0:f9cf4a19bb84 115 {0, 0}, // 0xC2 - Invalid message type
Issus 0:f9cf4a19bb84 116 {0 ,0}, // 0xC3 - Invalid message type
Issus 0:f9cf4a19bb84 117 {5, 5}, // 0xC4 - Channel Energy Scan Ack
Issus 0:f9cf4a19bb84 118 {23, 23} // 0xC5 - Channel Energy Scan Results
Issus 0:f9cf4a19bb84 119 };
Issus 0:f9cf4a19bb84 120
Issus 0:f9cf4a19bb84 121 /**
Issus 0:f9cf4a19bb84 122 * Construnctor.
Issus 0:f9cf4a19bb84 123 *
Issus 0:f9cf4a19bb84 124 * Example:
Issus 0:f9cf4a19bb84 125 *
Issus 0:f9cf4a19bb84 126 * LsrModule(false, 19200);
Issus 0:f9cf4a19bb84 127 *
Issus 0:f9cf4a19bb84 128 */
Issus 0:f9cf4a19bb84 129 LsrModule::LsrModule(PinName tx, PinName rx, int baudRate) : Serial(tx, rx)
Issus 0:f9cf4a19bb84 130 {
Issus 0:f9cf4a19bb84 131 baud(baudRate);
Issus 0:f9cf4a19bb84 132
Issus 0:f9cf4a19bb84 133 ptrHostState = &LsrModule::HostRxWaitForMsgStartByteState;
Issus 0:f9cf4a19bb84 134 } /*** End LsrModule ***/
Issus 0:f9cf4a19bb84 135
Issus 0:f9cf4a19bb84 136
Issus 0:f9cf4a19bb84 137 /**
Issus 0:f9cf4a19bb84 138 * Destructor. Called automatically, de-allocates resources.
Issus 0:f9cf4a19bb84 139 *
Issus 0:f9cf4a19bb84 140 */
Issus 0:f9cf4a19bb84 141 LsrModule::~LsrModule(void)
Issus 0:f9cf4a19bb84 142 {
Issus 0:f9cf4a19bb84 143 pu8RxBuffer = NULL;
Issus 0:f9cf4a19bb84 144 ptrHostState = NULL;
Issus 0:f9cf4a19bb84 145 ptrHostProcessCallbackState = NULL;
Issus 0:f9cf4a19bb84 146
Issus 0:f9cf4a19bb84 147 for (u8ForLoopCounter = 0; u8ForLoopCounter < sizeof(ptrRxMsgCallbackTable); u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 148 {
Issus 0:f9cf4a19bb84 149 ptrRxMsgCallbackTable[u8ForLoopCounter] = NULL;
Issus 0:f9cf4a19bb84 150 }
Issus 0:f9cf4a19bb84 151 } /*** End ~LsrModule ***/
Issus 0:f9cf4a19bb84 152
Issus 0:f9cf4a19bb84 153
Issus 0:f9cf4a19bb84 154 /**
Issus 0:f9cf4a19bb84 155 * Creates a callback for specific received UART message. Call this function from your main application in
Issus 0:f9cf4a19bb84 156 * this manner: "SubscribeRxMsgCallback(0xA1, &simpleShortAddrCallback)", where simpleShortAddrCallback is
Issus 0:f9cf4a19bb84 157 * defined like this: void simpleShortAddrCallback(void) in your main application.
Issus 0:f9cf4a19bb84 158 * IMPORTANT: All user defined callback methods must return void and take no parameters (void).
Issus 0:f9cf4a19bb84 159 *
Issus 0:f9cf4a19bb84 160 * @return True: Subscribed callback. False: Did not subscribe callback.
Issus 0:f9cf4a19bb84 161 *
Issus 0:f9cf4a19bb84 162 */
Issus 0:f9cf4a19bb84 163 bool LsrModule::SubscribeRxMsgCallback(uint8_t u8RxMsgType ///< The received message for which you want the callback to execute.
Issus 0:f9cf4a19bb84 164 , void (*callback)(void) ///< C function pointer to the specified callback function.
Issus 0:f9cf4a19bb84 165 )
Issus 0:f9cf4a19bb84 166 {
Issus 0:f9cf4a19bb84 167 if ((u8RxMsgType > LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE) && (u8RxMsgType < LSR_MODULE_MAX_SERIAL_RX_MSG_TYPE))
Issus 0:f9cf4a19bb84 168 {
Issus 0:f9cf4a19bb84 169 ptrRxMsgCallbackTable[u8RxMsgType- LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE] = callback;
Issus 0:f9cf4a19bb84 170 return true;
Issus 0:f9cf4a19bb84 171 }
Issus 0:f9cf4a19bb84 172
Issus 0:f9cf4a19bb84 173 return false;
Issus 0:f9cf4a19bb84 174 } /*** End SubscribeRxMsgCallback ***/
Issus 0:f9cf4a19bb84 175
Issus 0:f9cf4a19bb84 176
Issus 0:f9cf4a19bb84 177 /**
Issus 0:f9cf4a19bb84 178 * Removes a callback for specific received UART message. See SubscribeRxMsgCallback's description for
Issus 0:f9cf4a19bb84 179 * more information.
Issus 0:f9cf4a19bb84 180 *
Issus 0:f9cf4a19bb84 181 * @return True: Unsubscribed callback. False: Did not unsubscribed callback.
Issus 0:f9cf4a19bb84 182 *
Issus 0:f9cf4a19bb84 183 */
Issus 0:f9cf4a19bb84 184 bool LsrModule::UnsubscribeRxMsgCallback(uint8_t u8RxMsgType ///< The received message for which you want the callback to be removed.
Issus 0:f9cf4a19bb84 185 )
Issus 0:f9cf4a19bb84 186 {
Issus 0:f9cf4a19bb84 187 if ((u8RxMsgType > LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE) && (u8RxMsgType < LSR_MODULE_MAX_SERIAL_RX_MSG_TYPE))
Issus 0:f9cf4a19bb84 188 {
Issus 0:f9cf4a19bb84 189 ptrRxMsgCallbackTable[u8RxMsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE] = NULL;
Issus 0:f9cf4a19bb84 190 return true;
Issus 0:f9cf4a19bb84 191 }
Issus 0:f9cf4a19bb84 192
Issus 0:f9cf4a19bb84 193 return false;
Issus 0:f9cf4a19bb84 194 } /*** End UnsubscribeRxMsgCallback ***/
Issus 0:f9cf4a19bb84 195
Issus 0:f9cf4a19bb84 196
Issus 0:f9cf4a19bb84 197 /**
Issus 0:f9cf4a19bb84 198 * Executes host RX state machine. This function must be executed continually from the loop function in your main
Issus 0:f9cf4a19bb84 199 * application.
Issus 0:f9cf4a19bb84 200 *
Issus 0:f9cf4a19bb84 201 */
Issus 0:f9cf4a19bb84 202 void LsrModule::RunHostRxStateMachine(void)
Issus 0:f9cf4a19bb84 203 {
Issus 0:f9cf4a19bb84 204 (this->*ptrHostState)();
Issus 0:f9cf4a19bb84 205 } /*** End RunHostRxStateMachine ***/
Issus 0:f9cf4a19bb84 206
Issus 0:f9cf4a19bb84 207
Issus 0:f9cf4a19bb84 208 /**
Issus 0:f9cf4a19bb84 209 * Flushes appropriate serial port.
Issus 0:f9cf4a19bb84 210 *
Issus 0:f9cf4a19bb84 211 */
Issus 0:f9cf4a19bb84 212 void LsrModule::SerialFlush(void)
Issus 0:f9cf4a19bb84 213 {
Issus 0:f9cf4a19bb84 214 // Serial.flush();
Issus 0:f9cf4a19bb84 215 // i think this is meant to clean out the rx buffer
Issus 0:f9cf4a19bb84 216 /*** End SerialFlush ***/
Issus 0:f9cf4a19bb84 217 }
Issus 0:f9cf4a19bb84 218
Issus 0:f9cf4a19bb84 219 /**
Issus 0:f9cf4a19bb84 220 * Adds header to the UART transmit buffer.
Issus 0:f9cf4a19bb84 221 *
Issus 0:f9cf4a19bb84 222 */
Issus 0:f9cf4a19bb84 223 void LsrModule::AddSerialMsgHeader(uint8_t u8MsgType, uint8_t u8MsgLength)
Issus 0:f9cf4a19bb84 224 {
Issus 0:f9cf4a19bb84 225 SerialFlush();
Issus 0:f9cf4a19bb84 226 u8UartTxBufferIndex = LSR_MODULE_MSG_START_BYTE_INDEX;
Issus 0:f9cf4a19bb84 227 au8UartTxBuffer[u8UartTxBufferIndex++] = LSR_MODULE_SERIAL_MSG_START_BYTE;
Issus 0:f9cf4a19bb84 228 au8UartTxBuffer[u8UartTxBufferIndex++] = u8MsgLength;
Issus 0:f9cf4a19bb84 229 au8UartTxBuffer[u8UartTxBufferIndex++] = u8MsgType;
Issus 0:f9cf4a19bb84 230 u8TxMsgChecksum = (LSR_MODULE_SERIAL_MSG_START_BYTE + u8MsgLength + u8MsgType);
Issus 0:f9cf4a19bb84 231 } /*** End LsrModuleAddSerialMsgHeader ***/
Issus 0:f9cf4a19bb84 232
Issus 0:f9cf4a19bb84 233
Issus 0:f9cf4a19bb84 234 /**
Issus 0:f9cf4a19bb84 235 * Adds data bytes to the UART transmit buffer.
Issus 0:f9cf4a19bb84 236 *
Issus 0:f9cf4a19bb84 237 */
Issus 0:f9cf4a19bb84 238 void LsrModule::AddSerialByteToMsgBuffer(uint8_t u8Data ///< The data to add.
Issus 0:f9cf4a19bb84 239 )
Issus 0:f9cf4a19bb84 240 {
Issus 0:f9cf4a19bb84 241 au8UartTxBuffer[u8UartTxBufferIndex++] = u8Data;
Issus 0:f9cf4a19bb84 242 u8TxMsgChecksum += u8Data;
Issus 0:f9cf4a19bb84 243 } /*** End LsrModuleAddSerialByteToMsgBuffer ***/
Issus 0:f9cf4a19bb84 244
Issus 0:f9cf4a19bb84 245
Issus 0:f9cf4a19bb84 246 /**
Issus 0:f9cf4a19bb84 247 * Adds message trailer to the UART transmit buffer.
Issus 0:f9cf4a19bb84 248 *
Issus 0:f9cf4a19bb84 249 */
Issus 0:f9cf4a19bb84 250 void LsrModule::AddSerialMsgTrailer(void)
Issus 0:f9cf4a19bb84 251 {
Issus 0:f9cf4a19bb84 252 au8UartTxBuffer[u8UartTxBufferIndex++] = u8TxMsgChecksum;
Issus 0:f9cf4a19bb84 253 au8UartTxBuffer[u8UartTxBufferIndex] = LSR_MODULE_SERIAL_MSG_END_BYTE;
Issus 0:f9cf4a19bb84 254 WriteSerialMsg();
Issus 0:f9cf4a19bb84 255 } /*** End AddSerialMsgTrailer ***/
Issus 0:f9cf4a19bb84 256
Issus 0:f9cf4a19bb84 257
Issus 0:f9cf4a19bb84 258 /**
Issus 0:f9cf4a19bb84 259 * Writes the UART transmit buffer using the appropriate serial port.
Issus 0:f9cf4a19bb84 260 *
Issus 0:f9cf4a19bb84 261 */
Issus 0:f9cf4a19bb84 262 void LsrModule::WriteSerialMsg(void)
Issus 0:f9cf4a19bb84 263 {
Issus 0:f9cf4a19bb84 264 //write (const uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
Issus 0:f9cf4a19bb84 265 write(au8UartTxBuffer, au8UartTxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]);
Issus 0:f9cf4a19bb84 266
Issus 0:f9cf4a19bb84 267 } /*** End WriteSerialMsg ***/
Issus 0:f9cf4a19bb84 268
Issus 0:f9cf4a19bb84 269
Issus 0:f9cf4a19bb84 270 /**
Issus 0:f9cf4a19bb84 271 * Sends message type 0x01 (Query Version) to the module via UART communication. This will spark
Issus 0:f9cf4a19bb84 272 * a response message from the module to the Arduino of type 0x81. Subscribing to 0x81 in
Issus 0:f9cf4a19bb84 273 * your main application will allow you to parse the response data. See the description for
Issus 0:f9cf4a19bb84 274 * SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 275 *
Issus 0:f9cf4a19bb84 276 */
Issus 0:f9cf4a19bb84 277 void LsrModule::QueryVersionMsg(void)
Issus 0:f9cf4a19bb84 278 {
Issus 0:f9cf4a19bb84 279 AddSerialMsgHeader(LSR_MODULE_QUERY_VERSION_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 280 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 281 } /*** End QueryVersionMsg ***/
Issus 0:f9cf4a19bb84 282
Issus 0:f9cf4a19bb84 283
Issus 0:f9cf4a19bb84 284 /**
Issus 0:f9cf4a19bb84 285 * Sends message type 0x0C (Sets Security Transmit Frame Counter) to the module via UART communication.
Issus 0:f9cf4a19bb84 286 * This frame counter is used with RF messages transmitted with security to ensure sequential freshness.
Issus 0:f9cf4a19bb84 287 * This sets the starting frame count and is automatically incremented on every secured packet sent.
Issus 0:f9cf4a19bb84 288 * This will spark an ACK message from the module to the Arduino of type 0x8C. Subscribing to 0x8C in
Issus 0:f9cf4a19bb84 289 * your main application will allow you to parse the response data. See the description for
Issus 0:f9cf4a19bb84 290 * SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 291 *
Issus 0:f9cf4a19bb84 292 * Example:
Issus 0:f9cf4a19bb84 293 *
Issus 0:f9cf4a19bb84 294 * uint32_t u32FrameCounter = 0xAEDFEDFA;
Issus 0:f9cf4a19bb84 295 * SetSecurityTransmitFrameCounterMsg(&u32FrameCounter);
Issus 0:f9cf4a19bb84 296 *
Issus 0:f9cf4a19bb84 297 */
Issus 0:f9cf4a19bb84 298 void LsrModule::SetSecurityTransmitFrameCounterMsg(uint32_t* pu32FrameCounter ///< Pointer to 4 byte frame counter (LSB to MSB).
Issus 0:f9cf4a19bb84 299 )
Issus 0:f9cf4a19bb84 300 {
Issus 0:f9cf4a19bb84 301 DWordu_t dwuFrameCounter;
Issus 0:f9cf4a19bb84 302
Issus 0:f9cf4a19bb84 303 dwuFrameCounter.u32 = *pu32FrameCounter;
Issus 0:f9cf4a19bb84 304
Issus 0:f9cf4a19bb84 305 AddSerialMsgHeader(LSR_MODULE_SET_SECURITY_TX_FRAME_COUNTER_MSG_TYPE, 11);
Issus 0:f9cf4a19bb84 306 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.lb);
Issus 0:f9cf4a19bb84 307 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.mlb);
Issus 0:f9cf4a19bb84 308 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.mhb);
Issus 0:f9cf4a19bb84 309 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.hb);
Issus 0:f9cf4a19bb84 310 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 311 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 312 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 313 } /*** End SetSecurityTransmitFrameCounterMsg ***/
Issus 0:f9cf4a19bb84 314
Issus 0:f9cf4a19bb84 315
Issus 0:f9cf4a19bb84 316 /**
Issus 0:f9cf4a19bb84 317 * Sends message type 0x0D (Query Security Transmit Frame Counter) to the module via UART communication. This
Issus 0:f9cf4a19bb84 318 * will spark a response message from the module to the Arduino of type 0x8D. Subscribing to 0x8D in your main
Issus 0:f9cf4a19bb84 319 * application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 320 * for more information.
Issus 0:f9cf4a19bb84 321 *
Issus 0:f9cf4a19bb84 322 */
Issus 0:f9cf4a19bb84 323 void LsrModule::QuerySecurityTransmitFrameCounterMsg(void)
Issus 0:f9cf4a19bb84 324 {
Issus 0:f9cf4a19bb84 325 AddSerialMsgHeader(LSR_MODULE_QUERY_SECURITY_TX_FRAME_COUNTER_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 326 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 327 } /*** End QuerySecurityTransmitFrameCounterMsg ***/
Issus 0:f9cf4a19bb84 328
Issus 0:f9cf4a19bb84 329
Issus 0:f9cf4a19bb84 330 /**
Issus 0:f9cf4a19bb84 331 * Sends message type 0x10 (Set Basic RF Settings) to the module via UART communication.
Issus 0:f9cf4a19bb84 332 * This will spark an ACK message from the module to the Arduino of type 0x90. Subscribing to 0x90 in
Issus 0:f9cf4a19bb84 333 * your main application will allow you to parse the response data. See the description for
Issus 0:f9cf4a19bb84 334 * SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 335 *
Issus 0:f9cf4a19bb84 336 */
Issus 0:f9cf4a19bb84 337 void LsrModule::SetBasicRfSettingsMsg(uint16_t u16PanId ///< Personal Area Network (PAN) ID assigned to module.
Issus 0:f9cf4a19bb84 338 , uint16_t u16AddrShort ///< 2 byte short address assigned to module.
Issus 0:f9cf4a19bb84 339 , uint8_t* pu8AddrLong ///< Pointer to 8 byte long address assigned to module. Do not assign a zero, even if using short addressing.
Issus 0:f9cf4a19bb84 340 , uint8_t u8RfChannel ///< RF channel assigned to module.
Issus 0:f9cf4a19bb84 341 , uint8_t u8TxPowerLevel ///< Transmit power assigned to module.
Issus 0:f9cf4a19bb84 342 , uint8_t u8ReceiverConfig ///< 1 byte bitmask of receiver options.
Issus 0:f9cf4a19bb84 343 , uint8_t* pu8SecurityKey ///< Pointer to 32 byte security key assigned to module.
Issus 0:f9cf4a19bb84 344 )
Issus 0:f9cf4a19bb84 345 {
Issus 0:f9cf4a19bb84 346 Wordu_t wuPanId;
Issus 0:f9cf4a19bb84 347 Wordu_t wuShortAddr;
Issus 0:f9cf4a19bb84 348
Issus 0:f9cf4a19bb84 349 wuPanId.u16 = u16PanId;
Issus 0:f9cf4a19bb84 350 wuShortAddr.u16 = u16AddrShort;
Issus 0:f9cf4a19bb84 351
Issus 0:f9cf4a19bb84 352 if ((u8RfChannel >= LSR_MODULE_RF_CHANNEL_MIN) && (u8RfChannel <= LSR_MODULE_RF_CHANNEL_MAX) &&
Issus 0:f9cf4a19bb84 353 (u8TxPowerLevel <= LSR_MODULE_TX_POWER_LEVEL_MAX) &&
Issus 0:f9cf4a19bb84 354 (u8ReceiverConfig <= LSR_MODULE_RX_CONFIG_MAX))
Issus 0:f9cf4a19bb84 355 {
Issus 0:f9cf4a19bb84 356 AddSerialMsgHeader(LSR_MODULE_SET_BASIC_RF_SETTINGS_MSG_TYPE, 39);
Issus 0:f9cf4a19bb84 357 AddSerialByteToMsgBuffer(wuPanId.ws.lb);
Issus 0:f9cf4a19bb84 358 AddSerialByteToMsgBuffer(wuPanId.ws.hb);
Issus 0:f9cf4a19bb84 359 AddSerialByteToMsgBuffer(wuShortAddr.ws.lb);
Issus 0:f9cf4a19bb84 360 AddSerialByteToMsgBuffer(wuShortAddr.ws.hb);
Issus 0:f9cf4a19bb84 361
Issus 0:f9cf4a19bb84 362 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 363 {
Issus 0:f9cf4a19bb84 364 AddSerialByteToMsgBuffer(*pu8AddrLong);
Issus 0:f9cf4a19bb84 365 pu8AddrLong++;
Issus 0:f9cf4a19bb84 366 }
Issus 0:f9cf4a19bb84 367
Issus 0:f9cf4a19bb84 368 AddSerialByteToMsgBuffer(u8RfChannel);
Issus 0:f9cf4a19bb84 369 AddSerialByteToMsgBuffer(u8TxPowerLevel);
Issus 0:f9cf4a19bb84 370 AddSerialByteToMsgBuffer(u8ReceiverConfig);
Issus 0:f9cf4a19bb84 371
Issus 0:f9cf4a19bb84 372 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 373 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 374 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 375
Issus 0:f9cf4a19bb84 376 for (u8ForLoopCounter = 0; u8ForLoopCounter < 16; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 377 {
Issus 0:f9cf4a19bb84 378 AddSerialByteToMsgBuffer(*pu8SecurityKey);
Issus 0:f9cf4a19bb84 379 pu8SecurityKey++;
Issus 0:f9cf4a19bb84 380 }
Issus 0:f9cf4a19bb84 381
Issus 0:f9cf4a19bb84 382 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 383 }
Issus 0:f9cf4a19bb84 384 } /*** End SetBasicRfSettingsMsg ***/
Issus 0:f9cf4a19bb84 385
Issus 0:f9cf4a19bb84 386
Issus 0:f9cf4a19bb84 387 /**
Issus 0:f9cf4a19bb84 388 * Sends message type 0x11 (Query Basic RF Settings) to the module via UART communication. This will spark
Issus 0:f9cf4a19bb84 389 * a response message from the module to the Arduino of type 0x91. Subscribing to 0x91 in your main
Issus 0:f9cf4a19bb84 390 * application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 391 * for more information.
Issus 0:f9cf4a19bb84 392 *
Issus 0:f9cf4a19bb84 393 */
Issus 0:f9cf4a19bb84 394 void LsrModule::QueryBasicRfSettingsMsg(void)
Issus 0:f9cf4a19bb84 395 {
Issus 0:f9cf4a19bb84 396 AddSerialMsgHeader(LSR_MODULE_QUERY_BASIC_RF_SETTINGS_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 397 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 398 } /*** End QueryBasicRfSettingsMsg ***/
Issus 0:f9cf4a19bb84 399
Issus 0:f9cf4a19bb84 400
Issus 0:f9cf4a19bb84 401 /**
Issus 0:f9cf4a19bb84 402 * Sends message type 0x12 (Save Settings to non-volatile Memory) to the module via UART communication. Calling
Issus 0:f9cf4a19bb84 403 * this command will make your module retain all basic configuration settings on boot up. This will spark an ACK
Issus 0:f9cf4a19bb84 404 * message from the module to the Arduino of type 0x92. Subscribing to 0x92 in your main application will allow
Issus 0:f9cf4a19bb84 405 * you to parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 406 *
Issus 0:f9cf4a19bb84 407 */
Issus 0:f9cf4a19bb84 408 void LsrModule::SaveSettingsToNVMemoryMsg(void)
Issus 0:f9cf4a19bb84 409 {
Issus 0:f9cf4a19bb84 410 AddSerialMsgHeader(LSR_MODULE_SAVE_SETTINGS_TO_NV_MEMORY_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 411 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 412 } /*** End SaveSettingsToNVMemoryMsg ***/
Issus 0:f9cf4a19bb84 413
Issus 0:f9cf4a19bb84 414
Issus 0:f9cf4a19bb84 415 /**
Issus 0:f9cf4a19bb84 416 * Sends message type 0x13 (Reset Request) to the module via UART communication. This will make your module perform
Issus 0:f9cf4a19bb84 417 * a restart. This will spark an ACK message from the module to the Arduino of type 0x93. Subscribing to 0x93 in
Issus 0:f9cf4a19bb84 418 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 419 * for more information.
Issus 0:f9cf4a19bb84 420 *
Issus 0:f9cf4a19bb84 421 */
Issus 0:f9cf4a19bb84 422 void LsrModule::ResetRequestMsg(void)
Issus 0:f9cf4a19bb84 423 {
Issus 0:f9cf4a19bb84 424 AddSerialMsgHeader(LSR_MODULE_RESET_REQUEST_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 425 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 426 } /*** End ResetRequestMsg ***/
Issus 0:f9cf4a19bb84 427
Issus 0:f9cf4a19bb84 428
Issus 0:f9cf4a19bb84 429 /**
Issus 0:f9cf4a19bb84 430 * Sends message type 0x14 (Query Supply Voltage) to the module via UART communication. This will spark a
Issus 0:f9cf4a19bb84 431 * response message from the module to the Arduino of type 0x94. Subscribing to 0x94 in your main application
Issus 0:f9cf4a19bb84 432 * will allow you to parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 433 *
Issus 0:f9cf4a19bb84 434 */
Issus 0:f9cf4a19bb84 435 void LsrModule::QuerySupplyVoltageMsg(void)
Issus 0:f9cf4a19bb84 436 {
Issus 0:f9cf4a19bb84 437 AddSerialMsgHeader(LSR_MODULE_QUERY_SUPPLY_VOLTAGE_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 438 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 439 } /*** End QuerySupplyVoltageMsg ***/
Issus 0:f9cf4a19bb84 440
Issus 0:f9cf4a19bb84 441
Issus 0:f9cf4a19bb84 442 /**
Issus 0:f9cf4a19bb84 443 * Sends message type 0x15 (Query Statistics) to the module via UART communication. Statistics include packets sent,
Issus 0:f9cf4a19bb84 444 * acks received, packets received and broadcast packets received. This will spark a response message from the module
Issus 0:f9cf4a19bb84 445 * to the Arduino of type 0x95. Subscribing to 0x94 in your main application will allow you to parse the response
Issus 0:f9cf4a19bb84 446 * data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 447 *
Issus 0:f9cf4a19bb84 448 */
Issus 0:f9cf4a19bb84 449 void LsrModule::QueryStatisticsMsg(void)
Issus 0:f9cf4a19bb84 450 {
Issus 0:f9cf4a19bb84 451 AddSerialMsgHeader(LSR_MODULE_QUERY_STATISTICS_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 452 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 453 } /*** End QueryStatisticsMsg ***/
Issus 0:f9cf4a19bb84 454
Issus 0:f9cf4a19bb84 455
Issus 0:f9cf4a19bb84 456 /**
Issus 0:f9cf4a19bb84 457 * Sends message type 0x16 (Clear Statistics) to the module via UART communication. This will spark an ACK message
Issus 0:f9cf4a19bb84 458 * from the module to the Arduino of type 0x96. Subscribing to 0x96 in your main application will allow you to
Issus 0:f9cf4a19bb84 459 * Parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 460 *
Issus 0:f9cf4a19bb84 461 */
Issus 0:f9cf4a19bb84 462 void LsrModule::ClearStatisticsMsg(void)
Issus 0:f9cf4a19bb84 463 {
Issus 0:f9cf4a19bb84 464 AddSerialMsgHeader(LSR_MODULE_CLEAR_STATISTICS_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 465 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 466 } /*** End ClearStatisticsMsg ***/
Issus 0:f9cf4a19bb84 467
Issus 0:f9cf4a19bb84 468
Issus 0:f9cf4a19bb84 469 /**
Issus 0:f9cf4a19bb84 470 * Sends message type 0x18 (Set Host Data Rate) to the module via UART communication. This will spark an ACK message
Issus 0:f9cf4a19bb84 471 * from the module to the Arduino of type 0x98. Subscribing to 0x98 in your main application will allow you to parse
Issus 0:f9cf4a19bb84 472 * the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 473 *
Issus 0:f9cf4a19bb84 474 */
Issus 0:f9cf4a19bb84 475 void LsrModule::SetHostDataRateMsg(uint8_t u8HostDataRate ///< Data rate for module to use when communicating via UART:
Issus 0:f9cf4a19bb84 476 ///< 0 = 1,200 bits/s
Issus 0:f9cf4a19bb84 477 ///< 1 = 2,400 bits/s
Issus 0:f9cf4a19bb84 478 ///< 2 = 4,800 bits/s
Issus 0:f9cf4a19bb84 479 ///< 3 = 9,600 bits/s
Issus 0:f9cf4a19bb84 480 ///< 4 = 19,200 bits/s
Issus 0:f9cf4a19bb84 481 ///< 5 = 38,400 bits/s
Issus 0:f9cf4a19bb84 482 ///< 6 = 57,600 bits/s
Issus 0:f9cf4a19bb84 483 ///< 7 = 115,200 bits/s
Issus 0:f9cf4a19bb84 484 )
Issus 0:f9cf4a19bb84 485 {
Issus 0:f9cf4a19bb84 486 if (u8HostDataRate <= LSR_MODULE_HOST_DATA_RATE_MAX)
Issus 0:f9cf4a19bb84 487 {
Issus 0:f9cf4a19bb84 488 AddSerialMsgHeader(LSR_MODULE_SET_HOST_DATA_RATE_MSG_TYPE, 6);
Issus 0:f9cf4a19bb84 489 AddSerialByteToMsgBuffer(u8HostDataRate);
Issus 0:f9cf4a19bb84 490 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 491 }
Issus 0:f9cf4a19bb84 492 } /*** End SetHostDataRateMsg ***/
Issus 0:f9cf4a19bb84 493
Issus 0:f9cf4a19bb84 494
Issus 0:f9cf4a19bb84 495 /**
Issus 0:f9cf4a19bb84 496 * Sends message type 0x20 (Send Simple Short Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 497 * This will spark an ACK message from the module to the Arduino of type 0xA0. Subscribing to 0xA0 in
Issus 0:f9cf4a19bb84 498 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 499 * for more information.
Issus 0:f9cf4a19bb84 500 *
Issus 0:f9cf4a19bb84 501 * Example:
Issus 0:f9cf4a19bb84 502 *
Issus 0:f9cf4a19bb84 503 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 504 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 505 *
Issus 0:f9cf4a19bb84 506 * SendSimpleShortAddrRfDataPacketMsg(&u8Data, sizeof(u8Data, 213, 0, packetID++);
Issus 0:f9cf4a19bb84 507 *
Issus 0:f9cf4a19bb84 508 */
Issus 0:f9cf4a19bb84 509 void LsrModule::SendSimpleShortAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 510 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 511 , uint16_t u16DestAddress ///< 2 byte destination address.
Issus 0:f9cf4a19bb84 512 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 513 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 514 )
Issus 0:f9cf4a19bb84 515 {
Issus 0:f9cf4a19bb84 516 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 517 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_SIMPLE_SHORT_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 518 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_SIMPLE_SHORT_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 519 {
Issus 0:f9cf4a19bb84 520 AddSerialMsgHeader(LSR_MODULE_SEND_SIMPLE_SHORT_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 9));
Issus 0:f9cf4a19bb84 521
Issus 0:f9cf4a19bb84 522 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 523 AddSerialByteToMsgBuffer(u16DestAddress % 256);
Issus 0:f9cf4a19bb84 524 AddSerialByteToMsgBuffer(u16DestAddress >> 8);
Issus 0:f9cf4a19bb84 525 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 526
Issus 0:f9cf4a19bb84 527 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 528 {
Issus 0:f9cf4a19bb84 529 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 530 pu8Data++;
Issus 0:f9cf4a19bb84 531 u8DataLength--;
Issus 0:f9cf4a19bb84 532 }
Issus 0:f9cf4a19bb84 533
Issus 0:f9cf4a19bb84 534 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 535 }
Issus 0:f9cf4a19bb84 536 } /*** End SendSimpleShortAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 537
Issus 0:f9cf4a19bb84 538
Issus 0:f9cf4a19bb84 539 /**
Issus 0:f9cf4a19bb84 540 * Sends message type 0x22 (Send Advanced Short Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 541 * This will spark an ACK message from the module to the Arduino of type 0xA2. Subscribing to 0xA2 in
Issus 0:f9cf4a19bb84 542 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 543 * for more information.
Issus 0:f9cf4a19bb84 544 *
Issus 0:f9cf4a19bb84 545 * Example:
Issus 0:f9cf4a19bb84 546 *
Issus 0:f9cf4a19bb84 547 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 548 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 549 *
Issus 0:f9cf4a19bb84 550 * SendAdvancedShortAddrRfDataPacketMsg(&u8Data, sizeof(u8Data, 1111, 213, 0, packetID++);
Issus 0:f9cf4a19bb84 551 *
Issus 0:f9cf4a19bb84 552 */
Issus 0:f9cf4a19bb84 553 void LsrModule::SendAdvancedShortAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 554 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 555 , uint16_t u16DestPanId ///< 2 byte Personal Area Network (PAN) ID.
Issus 0:f9cf4a19bb84 556 , uint16_t u16DestAddress ///< 2 byte destination address.
Issus 0:f9cf4a19bb84 557 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 558 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 559 )
Issus 0:f9cf4a19bb84 560 {
Issus 0:f9cf4a19bb84 561 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 562 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_ADVANCED_SHORT_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 563 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_ADVANCED_SHORT_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 564 {
Issus 0:f9cf4a19bb84 565 AddSerialMsgHeader(LSR_MODULE_SEND_ADVANCED_SHORT_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 11));
Issus 0:f9cf4a19bb84 566
Issus 0:f9cf4a19bb84 567 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 568 AddSerialByteToMsgBuffer(u16DestPanId % 256);
Issus 0:f9cf4a19bb84 569 AddSerialByteToMsgBuffer(u16DestPanId >> 8);
Issus 0:f9cf4a19bb84 570 AddSerialByteToMsgBuffer(u16DestAddress % 256);
Issus 0:f9cf4a19bb84 571 AddSerialByteToMsgBuffer(u16DestAddress >> 8);
Issus 0:f9cf4a19bb84 572 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 573
Issus 0:f9cf4a19bb84 574 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 575 {
Issus 0:f9cf4a19bb84 576 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 577 pu8Data++;
Issus 0:f9cf4a19bb84 578 u8DataLength--;
Issus 0:f9cf4a19bb84 579 }
Issus 0:f9cf4a19bb84 580
Issus 0:f9cf4a19bb84 581 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 582 }
Issus 0:f9cf4a19bb84 583 } /*** End SendAdvancedShortAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 584
Issus 0:f9cf4a19bb84 585
Issus 0:f9cf4a19bb84 586 /**
Issus 0:f9cf4a19bb84 587 * Sends message type 0x24 (Send Simple Long Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 588 * This will spark an ACK message from the module to the Arduino of type 0xA4. Subscribing to 0xA4 in
Issus 0:f9cf4a19bb84 589 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 590 * for more information.
Issus 0:f9cf4a19bb84 591 *
Issus 0:f9cf4a19bb84 592 * Example:
Issus 0:f9cf4a19bb84 593 *
Issus 0:f9cf4a19bb84 594 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 595 * uint8_t u8DestAddress[8] = {2, 3, 6, 5, 2, 3, 6, 5};
Issus 0:f9cf4a19bb84 596 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 597 *
Issus 0:f9cf4a19bb84 598 * SendSimpleLongAddrRfDataPacketMsg(&u8Data, sizeof(u8Data), &u8DestAddress, 0, packetID++);
Issus 0:f9cf4a19bb84 599 *
Issus 0:f9cf4a19bb84 600 */
Issus 0:f9cf4a19bb84 601 void LsrModule::SendSimpleLongAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 602 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 603 , uint8_t* pu8DestAddress ///< Pointer to 8 byte destination address.
Issus 0:f9cf4a19bb84 604 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 605 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 606 )
Issus 0:f9cf4a19bb84 607 {
Issus 0:f9cf4a19bb84 608 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 609 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_SIMPLE_LONG_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 610 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_SIMPLE_LONG_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 611 {
Issus 0:f9cf4a19bb84 612 AddSerialMsgHeader(LSR_MODULE_SEND_SIMPLE_LONG_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 15));
Issus 0:f9cf4a19bb84 613
Issus 0:f9cf4a19bb84 614 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 615
Issus 0:f9cf4a19bb84 616 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 617 {
Issus 0:f9cf4a19bb84 618 AddSerialByteToMsgBuffer(*pu8DestAddress);
Issus 0:f9cf4a19bb84 619 pu8DestAddress++;
Issus 0:f9cf4a19bb84 620 }
Issus 0:f9cf4a19bb84 621
Issus 0:f9cf4a19bb84 622 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 623
Issus 0:f9cf4a19bb84 624 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 625 {
Issus 0:f9cf4a19bb84 626 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 627 pu8Data++;
Issus 0:f9cf4a19bb84 628 u8DataLength--;
Issus 0:f9cf4a19bb84 629 }
Issus 0:f9cf4a19bb84 630
Issus 0:f9cf4a19bb84 631 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 632 }
Issus 0:f9cf4a19bb84 633 } /*** End SendSimpleLongAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 634
Issus 0:f9cf4a19bb84 635
Issus 0:f9cf4a19bb84 636 /**
Issus 0:f9cf4a19bb84 637 * Sends message type 0x26 (Send Advanced Long Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 638 * This will spark an ACK message from the module to the Arduino of type 0xA6. Subscribing to 0xA6 in
Issus 0:f9cf4a19bb84 639 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 640 * for more information.
Issus 0:f9cf4a19bb84 641 *
Issus 0:f9cf4a19bb84 642 * Example:
Issus 0:f9cf4a19bb84 643 *
Issus 0:f9cf4a19bb84 644 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 645 * uint8_t u8DestAddress[8] = {2, 3, 6, 5, 2, 3, 6, 5};
Issus 0:f9cf4a19bb84 646 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 647 *
Issus 0:f9cf4a19bb84 648 * SendAdvancedLongAddrRfDataPacketMsg(&u8Data, sizeof(u8Data), 1111, &u8DestAddress, 0, packetID++);
Issus 0:f9cf4a19bb84 649 *
Issus 0:f9cf4a19bb84 650 */
Issus 0:f9cf4a19bb84 651 void LsrModule::SendAdvancedLongAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 652 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 653 , uint16_t u16DestPanId ///< 2 byte Personal Area Network (PAN) ID.
Issus 0:f9cf4a19bb84 654 , uint8_t* pu8DestAddress ///< Pointer to 8 byte destination address.
Issus 0:f9cf4a19bb84 655 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 656 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 657 )
Issus 0:f9cf4a19bb84 658 {
Issus 0:f9cf4a19bb84 659 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 660 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_ADVANCED_LONG_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 661 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_ADVANCED_LONG_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 662 {
Issus 0:f9cf4a19bb84 663 AddSerialMsgHeader(LSR_MODULE_SEND_ADVANCED_LONG_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 17));
Issus 0:f9cf4a19bb84 664
Issus 0:f9cf4a19bb84 665 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 666 AddSerialByteToMsgBuffer(u16DestPanId % 256);
Issus 0:f9cf4a19bb84 667 AddSerialByteToMsgBuffer(u16DestPanId >> 8);
Issus 0:f9cf4a19bb84 668
Issus 0:f9cf4a19bb84 669 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 670 {
Issus 0:f9cf4a19bb84 671 AddSerialByteToMsgBuffer(*pu8DestAddress);
Issus 0:f9cf4a19bb84 672 pu8DestAddress++;
Issus 0:f9cf4a19bb84 673 }
Issus 0:f9cf4a19bb84 674
Issus 0:f9cf4a19bb84 675 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 676
Issus 0:f9cf4a19bb84 677 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 678 {
Issus 0:f9cf4a19bb84 679 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 680 pu8Data++;
Issus 0:f9cf4a19bb84 681 u8DataLength--;
Issus 0:f9cf4a19bb84 682 }
Issus 0:f9cf4a19bb84 683
Issus 0:f9cf4a19bb84 684 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 685 }
Issus 0:f9cf4a19bb84 686 } /*** End SendAdvancedLongAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 687
Issus 0:f9cf4a19bb84 688
Issus 0:f9cf4a19bb84 689 /**
Issus 0:f9cf4a19bb84 690 * Sends message type 0x44 (Channel Energy Scan) to the module via UART communication. This will spark a response message from the module
Issus 0:f9cf4a19bb84 691 * to the Arduino of type 0xC5. Subscribing to 0xC5 in your main application will allow you to parse the response
Issus 0:f9cf4a19bb84 692 * data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 693 *
Issus 0:f9cf4a19bb84 694 * Example (Channel 5 for SiFLEX02, Channel 15 for ProFLEX01):
Issus 0:f9cf4a19bb84 695 *
Issus 0:f9cf4a19bb84 696 * ChannelEnergyScanMsg(11110111, 7);
Issus 0:f9cf4a19bb84 697 *
Issus 0:f9cf4a19bb84 698 */
Issus 0:f9cf4a19bb84 699 void LsrModule::ChannelEnergyScanMsg(uint16_t u16ChannelMask ///< Two byte bitmask (LSB to MSB) of the RF channels to perfom an enrgy scan on.
Issus 0:f9cf4a19bb84 700 , uint8_t u8ScanDuration ///< Duration to scan for:
Issus 0:f9cf4a19bb84 701 ///< 0 = 61.4 mSec
Issus 0:f9cf4a19bb84 702 ///< 1 = 92.2 mSec
Issus 0:f9cf4a19bb84 703 ///< 2 = 154 mSec
Issus 0:f9cf4a19bb84 704 ///< 3 = 276 mSec
Issus 0:f9cf4a19bb84 705 ///< 4 = 522 mSec
Issus 0:f9cf4a19bb84 706 ///< 5 = 1.01 Sec
Issus 0:f9cf4a19bb84 707 ///< 6 = 2.00 Sec
Issus 0:f9cf4a19bb84 708 ///< 7 = 3.96 Sec
Issus 0:f9cf4a19bb84 709 ///< 8 = 7.90 Sec
Issus 0:f9cf4a19bb84 710 ///< 9 = 15.8 Sec
Issus 0:f9cf4a19bb84 711 ///< 10 = 31.5 Sec
Issus 0:f9cf4a19bb84 712 ///< 11 = 62.9 Sec
Issus 0:f9cf4a19bb84 713 ///< 12 = 126 Sec
Issus 0:f9cf4a19bb84 714 ///< 13 = 252 Sec
Issus 0:f9cf4a19bb84 715 ///< 14 = 503 Sec
Issus 0:f9cf4a19bb84 716
Issus 0:f9cf4a19bb84 717 )
Issus 0:f9cf4a19bb84 718 {
Issus 0:f9cf4a19bb84 719 Wordu_t wuChannelMask;
Issus 0:f9cf4a19bb84 720
Issus 0:f9cf4a19bb84 721 wuChannelMask.u16 = u16ChannelMask;
Issus 0:f9cf4a19bb84 722
Issus 0:f9cf4a19bb84 723 if (u8ScanDuration <= LSR_MODULE_SCAN_DURATION_MAX)
Issus 0:f9cf4a19bb84 724 {
Issus 0:f9cf4a19bb84 725 AddSerialMsgHeader(LSR_MODULE_CHANNEL_ENERGY_SCAN_MSG_TYPE, 8);
Issus 0:f9cf4a19bb84 726 AddSerialByteToMsgBuffer(wuChannelMask.ws.lb);
Issus 0:f9cf4a19bb84 727 AddSerialByteToMsgBuffer(wuChannelMask.ws.hb);
Issus 0:f9cf4a19bb84 728 AddSerialByteToMsgBuffer(u8ScanDuration);
Issus 0:f9cf4a19bb84 729 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 730 }
Issus 0:f9cf4a19bb84 731 } /*** End ChannelEnergyScanMsg ***/
Issus 0:f9cf4a19bb84 732
Issus 0:f9cf4a19bb84 733
Issus 0:f9cf4a19bb84 734 /**
Issus 0:f9cf4a19bb84 735 * Verifies msg type and length.
Issus 0:f9cf4a19bb84 736 * @return True: Valid msg length and type. False: Invalid msg length or type.
Issus 0:f9cf4a19bb84 737 *
Issus 0:f9cf4a19bb84 738 */
Issus 0:f9cf4a19bb84 739 bool LsrModule::ValidMsgLengthAndType(uint8_t u8MsgType ///< Received UART message type.
Issus 0:f9cf4a19bb84 740 , uint8_t u8MsgLength ///< Received UART message length.
Issus 0:f9cf4a19bb84 741 )
Issus 0:f9cf4a19bb84 742 {
Issus 0:f9cf4a19bb84 743 if ((u8MsgLength >= cau8RxMsgLengthAndTypeTable[u8MsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE][0]) &&
Issus 0:f9cf4a19bb84 744 (u8MsgLength <= cau8RxMsgLengthAndTypeTable[u8MsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE][1]))
Issus 0:f9cf4a19bb84 745 {
Issus 0:f9cf4a19bb84 746 return true;
Issus 0:f9cf4a19bb84 747 }
Issus 0:f9cf4a19bb84 748 return false;
Issus 0:f9cf4a19bb84 749 } /*** End ValidMsgLengthAndType ***/
Issus 0:f9cf4a19bb84 750
Issus 0:f9cf4a19bb84 751
Issus 0:f9cf4a19bb84 752 /**
Issus 0:f9cf4a19bb84 753 * Verifies message checksum.
Issus 0:f9cf4a19bb84 754 * @return True: Valid checksum. False: Invalid checksum.
Issus 0:f9cf4a19bb84 755 *
Issus 0:f9cf4a19bb84 756 */
Issus 0:f9cf4a19bb84 757 bool LsrModule::ValidRxChecksum(uint8_t* pu8MsgBuffer ///< Pointer to received UART buffer.
Issus 0:f9cf4a19bb84 758 , uint8_t u8MsgLength ///< Received UART message length.
Issus 0:f9cf4a19bb84 759 )
Issus 0:f9cf4a19bb84 760 {
Issus 0:f9cf4a19bb84 761 uint8_t u8Checksum = 0;
Issus 0:f9cf4a19bb84 762
Issus 0:f9cf4a19bb84 763 for (u8ForLoopCounter = 0; u8ForLoopCounter < (u8MsgLength - 2); u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 764 {
Issus 0:f9cf4a19bb84 765 u8Checksum += au8UartRxBuffer[u8ForLoopCounter];
Issus 0:f9cf4a19bb84 766 }
Issus 0:f9cf4a19bb84 767
Issus 0:f9cf4a19bb84 768 if (au8UartRxBuffer[u8MsgLength-2] == u8Checksum)
Issus 0:f9cf4a19bb84 769 {
Issus 0:f9cf4a19bb84 770 return true;
Issus 0:f9cf4a19bb84 771 }
Issus 0:f9cf4a19bb84 772
Issus 0:f9cf4a19bb84 773 return false;
Issus 0:f9cf4a19bb84 774 } /*** End ValidRxChecksum ***/
Issus 0:f9cf4a19bb84 775
Issus 0:f9cf4a19bb84 776
Issus 0:f9cf4a19bb84 777 /**
Issus 0:f9cf4a19bb84 778 * Calls appropriate callback function for received message.
Issus 0:f9cf4a19bb84 779 *
Issus 0:f9cf4a19bb84 780 */
Issus 0:f9cf4a19bb84 781 void LsrModule::HostProcessCallbackMsgStart(uint8_t* pu8MsgBuffer ///< Pointer to received message.
Issus 0:f9cf4a19bb84 782 , uint8_t u8Length ///< Length of received message.
Issus 0:f9cf4a19bb84 783 )
Issus 0:f9cf4a19bb84 784 {
Issus 0:f9cf4a19bb84 785 if ((ptrRxMsgCallbackTable[(*(pu8MsgBuffer + LSR_MODULE_MSG_TYPE_BYTE_INDEX)) - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE]) != NULL)
Issus 0:f9cf4a19bb84 786 {
Issus 0:f9cf4a19bb84 787 ptrRxMsgCallbackTable[(*(pu8MsgBuffer + LSR_MODULE_MSG_TYPE_BYTE_INDEX)) - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE]();
Issus 0:f9cf4a19bb84 788 }
Issus 0:f9cf4a19bb84 789 } /*** End HostProcessCallbackMsgStart ***/
Issus 0:f9cf4a19bb84 790
Issus 0:f9cf4a19bb84 791
Issus 0:f9cf4a19bb84 792 /**
Issus 0:f9cf4a19bb84 793 * Determines if appropriate serial port is available.
Issus 0:f9cf4a19bb84 794 * @return True: Serial is available. False: Serial is unavailable.
Issus 0:f9cf4a19bb84 795 *
Issus 0:f9cf4a19bb84 796 */
Issus 0:f9cf4a19bb84 797 bool LsrModule::SerialAvailable(void)
Issus 0:f9cf4a19bb84 798 {
Issus 0:f9cf4a19bb84 799 if (readable())
Issus 0:f9cf4a19bb84 800 {
Issus 0:f9cf4a19bb84 801 return true;
Issus 0:f9cf4a19bb84 802 }
Issus 0:f9cf4a19bb84 803
Issus 0:f9cf4a19bb84 804 return false;
Issus 0:f9cf4a19bb84 805 } /*** End SerialAvailable ***/
Issus 0:f9cf4a19bb84 806
Issus 0:f9cf4a19bb84 807
Issus 0:f9cf4a19bb84 808 /**
Issus 0:f9cf4a19bb84 809 * Reads appropriate serial port.
Issus 0:f9cf4a19bb84 810 * @return Byte read.
Issus 0:f9cf4a19bb84 811 *
Issus 0:f9cf4a19bb84 812 */
Issus 0:f9cf4a19bb84 813 uint8_t LsrModule::SerialRead(void)
Issus 0:f9cf4a19bb84 814 {
Issus 0:f9cf4a19bb84 815 return getc();
Issus 0:f9cf4a19bb84 816
Issus 0:f9cf4a19bb84 817 } /*** End SerialRead ***/
Issus 0:f9cf4a19bb84 818
Issus 0:f9cf4a19bb84 819
Issus 0:f9cf4a19bb84 820 /**
Issus 0:f9cf4a19bb84 821 * Refreshes and restarts Rx state machine.
Issus 0:f9cf4a19bb84 822 *
Issus 0:f9cf4a19bb84 823 */
Issus 0:f9cf4a19bb84 824 void LsrModule::SerialRxCleanupRestart(void)
Issus 0:f9cf4a19bb84 825 {
Issus 0:f9cf4a19bb84 826 SerialFlush();
Issus 0:f9cf4a19bb84 827 u8UartRxBufferIndex = LSR_MODULE_MSG_START_BYTE_INDEX;
Issus 0:f9cf4a19bb84 828 ptrHostState = &LsrModule::HostRxWaitForMsgStartByteState;
Issus 0:f9cf4a19bb84 829 } /*** End SerialRxCleanupRestart ***/
Issus 0:f9cf4a19bb84 830
Issus 0:f9cf4a19bb84 831
Issus 0:f9cf4a19bb84 832 /**
Issus 0:f9cf4a19bb84 833 * Waits for data packet start byte.
Issus 0:f9cf4a19bb84 834 *
Issus 0:f9cf4a19bb84 835 */
Issus 0:f9cf4a19bb84 836 void LsrModule::HostRxWaitForMsgStartByteState(void)
Issus 0:f9cf4a19bb84 837 {
Issus 0:f9cf4a19bb84 838 if (SerialAvailable() && (SerialRead() == LSR_MODULE_SERIAL_MSG_START_BYTE))
Issus 0:f9cf4a19bb84 839 {
Issus 0:f9cf4a19bb84 840 au8UartRxBuffer[u8UartRxBufferIndex++] = LSR_MODULE_SERIAL_MSG_START_BYTE;
Issus 0:f9cf4a19bb84 841 ptrHostState = &LsrModule::HostRxGetMsgLengthState;
Issus 0:f9cf4a19bb84 842 }
Issus 0:f9cf4a19bb84 843 } /*** End HostRxWaitForMsgStartByteState ***/
Issus 0:f9cf4a19bb84 844
Issus 0:f9cf4a19bb84 845
Issus 0:f9cf4a19bb84 846 /**
Issus 0:f9cf4a19bb84 847 * Gets data packet length byte.
Issus 0:f9cf4a19bb84 848 *
Issus 0:f9cf4a19bb84 849 */
Issus 0:f9cf4a19bb84 850 void LsrModule::HostRxGetMsgLengthState(void)
Issus 0:f9cf4a19bb84 851 {
Issus 0:f9cf4a19bb84 852 if (SerialAvailable())
Issus 0:f9cf4a19bb84 853 {
Issus 0:f9cf4a19bb84 854 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 855
Issus 0:f9cf4a19bb84 856 if ((u8RxReadByte >= LSR_MODULE_MIN_SERIAL_RX_MSG_LENGTH) &&
Issus 0:f9cf4a19bb84 857 (u8RxReadByte <= LSR_MODULE_MAX_SERIAL_RX_MSG_LENGTH))
Issus 0:f9cf4a19bb84 858 {
Issus 0:f9cf4a19bb84 859 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 860 ptrHostState = &LsrModule::HostRxGetMsgTypeState;
Issus 0:f9cf4a19bb84 861 }
Issus 0:f9cf4a19bb84 862 else
Issus 0:f9cf4a19bb84 863 {
Issus 0:f9cf4a19bb84 864 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 865 }
Issus 0:f9cf4a19bb84 866 }
Issus 0:f9cf4a19bb84 867 } /*** End HostRxGetMsgLengthState ***/
Issus 0:f9cf4a19bb84 868
Issus 0:f9cf4a19bb84 869
Issus 0:f9cf4a19bb84 870 /**
Issus 0:f9cf4a19bb84 871 * Gets data packet type byte.
Issus 0:f9cf4a19bb84 872 *
Issus 0:f9cf4a19bb84 873 */
Issus 0:f9cf4a19bb84 874 void LsrModule::HostRxGetMsgTypeState(void)
Issus 0:f9cf4a19bb84 875 {
Issus 0:f9cf4a19bb84 876 if (SerialAvailable())
Issus 0:f9cf4a19bb84 877 {
Issus 0:f9cf4a19bb84 878
Issus 0:f9cf4a19bb84 879 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 880
Issus 0:f9cf4a19bb84 881 if (ValidMsgLengthAndType(u8RxReadByte, au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]))
Issus 0:f9cf4a19bb84 882 {
Issus 0:f9cf4a19bb84 883 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 884 ptrHostState = &LsrModule::HostRxWaitToGetRestOfMsgState;
Issus 0:f9cf4a19bb84 885 }
Issus 0:f9cf4a19bb84 886 else
Issus 0:f9cf4a19bb84 887 {
Issus 0:f9cf4a19bb84 888 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 889 }
Issus 0:f9cf4a19bb84 890 }
Issus 0:f9cf4a19bb84 891 } /*** End HostRxGetMsgTypeState ***/
Issus 0:f9cf4a19bb84 892
Issus 0:f9cf4a19bb84 893
Issus 0:f9cf4a19bb84 894 /**
Issus 0:f9cf4a19bb84 895 * Grabs rest of data packet bytes.
Issus 0:f9cf4a19bb84 896 *
Issus 0:f9cf4a19bb84 897 */
Issus 0:f9cf4a19bb84 898 void LsrModule::HostRxWaitToGetRestOfMsgState(void)
Issus 0:f9cf4a19bb84 899 {
Issus 0:f9cf4a19bb84 900 if (SerialAvailable())
Issus 0:f9cf4a19bb84 901 {
Issus 0:f9cf4a19bb84 902 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 903 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 904
Issus 0:f9cf4a19bb84 905 if (u8UartRxBufferIndex > LSR_MODULE_MAX_SERIAL_RX_MSG_LENGTH)
Issus 0:f9cf4a19bb84 906 {
Issus 0:f9cf4a19bb84 907 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 908 }
Issus 0:f9cf4a19bb84 909 else if ((u8RxReadByte == LSR_MODULE_SERIAL_MSG_END_BYTE) && (u8UartRxBufferIndex == au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]))
Issus 0:f9cf4a19bb84 910 {
Issus 0:f9cf4a19bb84 911 ptrHostState = &LsrModule::HostRxValidateMsgState;
Issus 0:f9cf4a19bb84 912 }
Issus 0:f9cf4a19bb84 913 }
Issus 0:f9cf4a19bb84 914 } /*** End HostRxWaitToGetRestOfMsgState ***/
Issus 0:f9cf4a19bb84 915
Issus 0:f9cf4a19bb84 916
Issus 0:f9cf4a19bb84 917 /**
Issus 0:f9cf4a19bb84 918 * Validates received message.
Issus 0:f9cf4a19bb84 919 *
Issus 0:f9cf4a19bb84 920 */
Issus 0:f9cf4a19bb84 921 void LsrModule::HostRxValidateMsgState(void)
Issus 0:f9cf4a19bb84 922 {
Issus 0:f9cf4a19bb84 923
Issus 0:f9cf4a19bb84 924 if (ValidRxChecksum(au8UartRxBuffer, au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX])) // Is checksum good?
Issus 0:f9cf4a19bb84 925 {
Issus 0:f9cf4a19bb84 926 ptrHostState = &LsrModule::HostRxGoodMsgState; // Good checksum - next state
Issus 0:f9cf4a19bb84 927 }
Issus 0:f9cf4a19bb84 928 else
Issus 0:f9cf4a19bb84 929 {
Issus 0:f9cf4a19bb84 930 ptrHostState = &LsrModule::SerialRxCleanupRestart; // Bad checksum - restart
Issus 0:f9cf4a19bb84 931 }
Issus 0:f9cf4a19bb84 932 } /*** End HostRxValidateMsgState ***/
Issus 0:f9cf4a19bb84 933
Issus 0:f9cf4a19bb84 934
Issus 0:f9cf4a19bb84 935 /**
Issus 0:f9cf4a19bb84 936 * Calls appropriate received UART message callback and starts state machine over.
Issus 0:f9cf4a19bb84 937 *
Issus 0:f9cf4a19bb84 938 */
Issus 0:f9cf4a19bb84 939 void LsrModule::HostRxGoodMsgState(void)
Issus 0:f9cf4a19bb84 940 {
Issus 0:f9cf4a19bb84 941 pu8RxBuffer = au8UartRxBuffer;
Issus 0:f9cf4a19bb84 942 u8RxMsgLength = au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX];
Issus 0:f9cf4a19bb84 943 HostProcessCallbackMsgStart(au8UartRxBuffer, u8RxMsgLength);
Issus 0:f9cf4a19bb84 944 ptrHostState = &LsrModule::SerialRxCleanupRestart; // Start new RX sequence
Issus 0:f9cf4a19bb84 945 } /*** End HostRxGoodMsgState ***/