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

Committer:
Issus
Date:
Mon Jul 25 22:18:30 2016 +0000
Revision:
6:b0445108f82f
Parent:
4:2ac0b9a7f43a
Child:
7:25e64602dc61
Added new methods to get data from the module

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 2:2c0b7246d769 491
Issus 3:8d794c196710 492 // 2.4 ms for the data rate change packet to be transmitted.
Issus 3:8d794c196710 493 wait_ms(3);
Issus 3:8d794c196710 494
Issus 2:2c0b7246d769 495 switch (u8HostDataRate)
Issus 2:2c0b7246d769 496 {
Issus 2:2c0b7246d769 497 case LSR_MODULE_HOST_DATA_RATE_1200:
Issus 2:2c0b7246d769 498 baud(1200);
Issus 2:2c0b7246d769 499 break;
Issus 2:2c0b7246d769 500 case LSR_MODULE_HOST_DATA_RATE_2400:
Issus 2:2c0b7246d769 501 baud(2400);
Issus 2:2c0b7246d769 502 break;
Issus 2:2c0b7246d769 503 case LSR_MODULE_HOST_DATA_RATE_4800:
Issus 2:2c0b7246d769 504 baud(4800);
Issus 2:2c0b7246d769 505 break;
Issus 2:2c0b7246d769 506 case LSR_MODULE_HOST_DATA_RATE_9600:
Issus 2:2c0b7246d769 507 baud(9600);
Issus 2:2c0b7246d769 508 break;
Issus 2:2c0b7246d769 509 case LSR_MODULE_HOST_DATA_RATE_19200:
Issus 2:2c0b7246d769 510 baud(19200);
Issus 2:2c0b7246d769 511 break;
Issus 2:2c0b7246d769 512 case LSR_MODULE_HOST_DATA_RATE_38400:
Issus 2:2c0b7246d769 513 baud(38400);
Issus 2:2c0b7246d769 514 break;
Issus 2:2c0b7246d769 515 case LSR_MODULE_HOST_DATA_RATE_57600:
Issus 2:2c0b7246d769 516 baud(57600);
Issus 2:2c0b7246d769 517 break;
Issus 2:2c0b7246d769 518 case LSR_MODULE_HOST_DATA_RATE_115200:
Issus 2:2c0b7246d769 519 baud(115200);
Issus 2:2c0b7246d769 520 break;
Issus 2:2c0b7246d769 521 case LSR_MODULE_HOST_DATA_RATE_230400:
Issus 2:2c0b7246d769 522 baud(230400);
Issus 2:2c0b7246d769 523 break;
Issus 2:2c0b7246d769 524 case LSR_MODULE_HOST_DATA_RATE_460800:
Issus 2:2c0b7246d769 525 baud(460800);
Issus 2:2c0b7246d769 526 break;
Issus 2:2c0b7246d769 527 case LSR_MODULE_HOST_DATA_RATE_921600:
Issus 2:2c0b7246d769 528 baud(921600);
Issus 2:2c0b7246d769 529 break;
Issus 2:2c0b7246d769 530 }
Issus 0:f9cf4a19bb84 531 }
Issus 0:f9cf4a19bb84 532 } /*** End SetHostDataRateMsg ***/
Issus 0:f9cf4a19bb84 533
Issus 0:f9cf4a19bb84 534
Issus 0:f9cf4a19bb84 535 /**
Issus 4:2ac0b9a7f43a 536 * Sends message type 0x19 (Set RF Data Rate) to the module via UART communication. This will spark an ACK message
Issus 4:2ac0b9a7f43a 537 * from the module to the Arduino of type 0x98. Subscribing to 0x98 in your main application will allow you to parse
Issus 4:2ac0b9a7f43a 538 * the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 4:2ac0b9a7f43a 539 *
Issus 4:2ac0b9a7f43a 540 */
Issus 4:2ac0b9a7f43a 541 void LsrModule::SetRfDataRateMsg(uint8_t u8RfDataRate ///< Data rate for module to use when communicating via radio:
Issus 4:2ac0b9a7f43a 542 ///< 0 = 1,200 bits/s
Issus 4:2ac0b9a7f43a 543 ///< 1 = 2,400 bits/s
Issus 4:2ac0b9a7f43a 544 ///< 2 = 4,800 bits/s
Issus 4:2ac0b9a7f43a 545 ///< 3 = 9,600 bits/s
Issus 4:2ac0b9a7f43a 546 ///< 4 = 19,200 bits/s
Issus 4:2ac0b9a7f43a 547 ///< 5 = 38,400 bits/s
Issus 4:2ac0b9a7f43a 548 ///< 6 = 57,600 bits/s
Issus 4:2ac0b9a7f43a 549 ///< 7 = 115,200 bits/s
Issus 4:2ac0b9a7f43a 550 )
Issus 4:2ac0b9a7f43a 551 {
Issus 4:2ac0b9a7f43a 552 if (u8RfDataRate <= LSR_MODULE_RF_DATA_RATE_MAX)
Issus 4:2ac0b9a7f43a 553 {
Issus 4:2ac0b9a7f43a 554 AddSerialMsgHeader(LSR_MODULE_SET_RF_DATA_RATE_MSG_TYPE, 6);
Issus 4:2ac0b9a7f43a 555 AddSerialByteToMsgBuffer(u8RfDataRate);
Issus 4:2ac0b9a7f43a 556 AddSerialMsgTrailer();
Issus 4:2ac0b9a7f43a 557 }
Issus 4:2ac0b9a7f43a 558 } /*** End SetRfDataRateMsg ***/
Issus 4:2ac0b9a7f43a 559
Issus 4:2ac0b9a7f43a 560 /**
Issus 0:f9cf4a19bb84 561 * Sends message type 0x20 (Send Simple Short Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 562 * This will spark an ACK message from the module to the Arduino of type 0xA0. Subscribing to 0xA0 in
Issus 0:f9cf4a19bb84 563 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 564 * for more information.
Issus 0:f9cf4a19bb84 565 *
Issus 0:f9cf4a19bb84 566 * Example:
Issus 0:f9cf4a19bb84 567 *
Issus 0:f9cf4a19bb84 568 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 569 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 570 *
Issus 0:f9cf4a19bb84 571 * SendSimpleShortAddrRfDataPacketMsg(&u8Data, sizeof(u8Data, 213, 0, packetID++);
Issus 0:f9cf4a19bb84 572 *
Issus 0:f9cf4a19bb84 573 */
Issus 0:f9cf4a19bb84 574 void LsrModule::SendSimpleShortAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 575 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 576 , uint16_t u16DestAddress ///< 2 byte destination address.
Issus 0:f9cf4a19bb84 577 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 578 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 579 )
Issus 0:f9cf4a19bb84 580 {
Issus 0:f9cf4a19bb84 581 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 582 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_SIMPLE_SHORT_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 583 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_SIMPLE_SHORT_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 584 {
Issus 0:f9cf4a19bb84 585 AddSerialMsgHeader(LSR_MODULE_SEND_SIMPLE_SHORT_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 9));
Issus 0:f9cf4a19bb84 586
Issus 0:f9cf4a19bb84 587 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 588 AddSerialByteToMsgBuffer(u16DestAddress % 256);
Issus 0:f9cf4a19bb84 589 AddSerialByteToMsgBuffer(u16DestAddress >> 8);
Issus 0:f9cf4a19bb84 590 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 591
Issus 0:f9cf4a19bb84 592 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 593 {
Issus 0:f9cf4a19bb84 594 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 595 pu8Data++;
Issus 0:f9cf4a19bb84 596 u8DataLength--;
Issus 0:f9cf4a19bb84 597 }
Issus 0:f9cf4a19bb84 598
Issus 0:f9cf4a19bb84 599 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 600 }
Issus 0:f9cf4a19bb84 601 } /*** End SendSimpleShortAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 602
Issus 0:f9cf4a19bb84 603
Issus 0:f9cf4a19bb84 604 /**
Issus 0:f9cf4a19bb84 605 * Sends message type 0x22 (Send Advanced Short Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 606 * This will spark an ACK message from the module to the Arduino of type 0xA2. Subscribing to 0xA2 in
Issus 0:f9cf4a19bb84 607 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 608 * for more information.
Issus 0:f9cf4a19bb84 609 *
Issus 0:f9cf4a19bb84 610 * Example:
Issus 0:f9cf4a19bb84 611 *
Issus 0:f9cf4a19bb84 612 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 613 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 614 *
Issus 0:f9cf4a19bb84 615 * SendAdvancedShortAddrRfDataPacketMsg(&u8Data, sizeof(u8Data, 1111, 213, 0, packetID++);
Issus 0:f9cf4a19bb84 616 *
Issus 0:f9cf4a19bb84 617 */
Issus 0:f9cf4a19bb84 618 void LsrModule::SendAdvancedShortAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 619 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 620 , uint16_t u16DestPanId ///< 2 byte Personal Area Network (PAN) ID.
Issus 0:f9cf4a19bb84 621 , uint16_t u16DestAddress ///< 2 byte destination address.
Issus 0:f9cf4a19bb84 622 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 623 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 624 )
Issus 0:f9cf4a19bb84 625 {
Issus 0:f9cf4a19bb84 626 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 627 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_ADVANCED_SHORT_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 628 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_ADVANCED_SHORT_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 629 {
Issus 0:f9cf4a19bb84 630 AddSerialMsgHeader(LSR_MODULE_SEND_ADVANCED_SHORT_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 11));
Issus 0:f9cf4a19bb84 631
Issus 0:f9cf4a19bb84 632 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 633 AddSerialByteToMsgBuffer(u16DestPanId % 256);
Issus 0:f9cf4a19bb84 634 AddSerialByteToMsgBuffer(u16DestPanId >> 8);
Issus 0:f9cf4a19bb84 635 AddSerialByteToMsgBuffer(u16DestAddress % 256);
Issus 0:f9cf4a19bb84 636 AddSerialByteToMsgBuffer(u16DestAddress >> 8);
Issus 0:f9cf4a19bb84 637 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 638
Issus 0:f9cf4a19bb84 639 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 640 {
Issus 0:f9cf4a19bb84 641 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 642 pu8Data++;
Issus 0:f9cf4a19bb84 643 u8DataLength--;
Issus 0:f9cf4a19bb84 644 }
Issus 0:f9cf4a19bb84 645
Issus 0:f9cf4a19bb84 646 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 647 }
Issus 0:f9cf4a19bb84 648 } /*** End SendAdvancedShortAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 649
Issus 0:f9cf4a19bb84 650
Issus 0:f9cf4a19bb84 651 /**
Issus 0:f9cf4a19bb84 652 * Sends message type 0x24 (Send Simple Long Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 653 * This will spark an ACK message from the module to the Arduino of type 0xA4. Subscribing to 0xA4 in
Issus 0:f9cf4a19bb84 654 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 655 * for more information.
Issus 0:f9cf4a19bb84 656 *
Issus 0:f9cf4a19bb84 657 * Example:
Issus 0:f9cf4a19bb84 658 *
Issus 0:f9cf4a19bb84 659 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 660 * uint8_t u8DestAddress[8] = {2, 3, 6, 5, 2, 3, 6, 5};
Issus 0:f9cf4a19bb84 661 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 662 *
Issus 0:f9cf4a19bb84 663 * SendSimpleLongAddrRfDataPacketMsg(&u8Data, sizeof(u8Data), &u8DestAddress, 0, packetID++);
Issus 0:f9cf4a19bb84 664 *
Issus 0:f9cf4a19bb84 665 */
Issus 0:f9cf4a19bb84 666 void LsrModule::SendSimpleLongAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 667 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 668 , uint8_t* pu8DestAddress ///< Pointer to 8 byte destination address.
Issus 0:f9cf4a19bb84 669 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 670 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 671 )
Issus 0:f9cf4a19bb84 672 {
Issus 0:f9cf4a19bb84 673 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 674 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_SIMPLE_LONG_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 675 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_SIMPLE_LONG_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 676 {
Issus 0:f9cf4a19bb84 677 AddSerialMsgHeader(LSR_MODULE_SEND_SIMPLE_LONG_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 15));
Issus 0:f9cf4a19bb84 678
Issus 0:f9cf4a19bb84 679 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 680
Issus 0:f9cf4a19bb84 681 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 682 {
Issus 0:f9cf4a19bb84 683 AddSerialByteToMsgBuffer(*pu8DestAddress);
Issus 0:f9cf4a19bb84 684 pu8DestAddress++;
Issus 0:f9cf4a19bb84 685 }
Issus 0:f9cf4a19bb84 686
Issus 0:f9cf4a19bb84 687 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 688
Issus 0:f9cf4a19bb84 689 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 690 {
Issus 0:f9cf4a19bb84 691 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 692 pu8Data++;
Issus 0:f9cf4a19bb84 693 u8DataLength--;
Issus 0:f9cf4a19bb84 694 }
Issus 0:f9cf4a19bb84 695
Issus 0:f9cf4a19bb84 696 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 697 }
Issus 0:f9cf4a19bb84 698 } /*** End SendSimpleLongAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 699
Issus 0:f9cf4a19bb84 700
Issus 0:f9cf4a19bb84 701 /**
Issus 0:f9cf4a19bb84 702 * Sends message type 0x26 (Send Advanced Long Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 703 * This will spark an ACK message from the module to the Arduino of type 0xA6. Subscribing to 0xA6 in
Issus 0:f9cf4a19bb84 704 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 705 * for more information.
Issus 0:f9cf4a19bb84 706 *
Issus 0:f9cf4a19bb84 707 * Example:
Issus 0:f9cf4a19bb84 708 *
Issus 0:f9cf4a19bb84 709 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 710 * uint8_t u8DestAddress[8] = {2, 3, 6, 5, 2, 3, 6, 5};
Issus 0:f9cf4a19bb84 711 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 712 *
Issus 0:f9cf4a19bb84 713 * SendAdvancedLongAddrRfDataPacketMsg(&u8Data, sizeof(u8Data), 1111, &u8DestAddress, 0, packetID++);
Issus 0:f9cf4a19bb84 714 *
Issus 0:f9cf4a19bb84 715 */
Issus 0:f9cf4a19bb84 716 void LsrModule::SendAdvancedLongAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 717 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 718 , uint16_t u16DestPanId ///< 2 byte Personal Area Network (PAN) ID.
Issus 0:f9cf4a19bb84 719 , uint8_t* pu8DestAddress ///< Pointer to 8 byte destination address.
Issus 0:f9cf4a19bb84 720 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 721 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 722 )
Issus 0:f9cf4a19bb84 723 {
Issus 0:f9cf4a19bb84 724 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 725 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_ADVANCED_LONG_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 726 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_ADVANCED_LONG_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 727 {
Issus 0:f9cf4a19bb84 728 AddSerialMsgHeader(LSR_MODULE_SEND_ADVANCED_LONG_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 17));
Issus 0:f9cf4a19bb84 729
Issus 0:f9cf4a19bb84 730 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 731 AddSerialByteToMsgBuffer(u16DestPanId % 256);
Issus 0:f9cf4a19bb84 732 AddSerialByteToMsgBuffer(u16DestPanId >> 8);
Issus 0:f9cf4a19bb84 733
Issus 0:f9cf4a19bb84 734 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 735 {
Issus 0:f9cf4a19bb84 736 AddSerialByteToMsgBuffer(*pu8DestAddress);
Issus 0:f9cf4a19bb84 737 pu8DestAddress++;
Issus 0:f9cf4a19bb84 738 }
Issus 0:f9cf4a19bb84 739
Issus 0:f9cf4a19bb84 740 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 741
Issus 0:f9cf4a19bb84 742 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 743 {
Issus 0:f9cf4a19bb84 744 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 745 pu8Data++;
Issus 0:f9cf4a19bb84 746 u8DataLength--;
Issus 0:f9cf4a19bb84 747 }
Issus 0:f9cf4a19bb84 748
Issus 0:f9cf4a19bb84 749 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 750 }
Issus 0:f9cf4a19bb84 751 } /*** End SendAdvancedLongAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 752
Issus 0:f9cf4a19bb84 753
Issus 0:f9cf4a19bb84 754 /**
Issus 0:f9cf4a19bb84 755 * Sends message type 0x44 (Channel Energy Scan) to the module via UART communication. This will spark a response message from the module
Issus 6:b0445108f82f 756 * to the host of type 0xC5. Subscribing to 0xC5 in your main application will allow you to parse the response
Issus 0:f9cf4a19bb84 757 * data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 758 *
Issus 0:f9cf4a19bb84 759 * Example (Channel 5 for SiFLEX02, Channel 15 for ProFLEX01):
Issus 0:f9cf4a19bb84 760 *
Issus 0:f9cf4a19bb84 761 * ChannelEnergyScanMsg(11110111, 7);
Issus 0:f9cf4a19bb84 762 *
Issus 0:f9cf4a19bb84 763 */
Issus 0:f9cf4a19bb84 764 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 765 , uint8_t u8ScanDuration ///< Duration to scan for:
Issus 0:f9cf4a19bb84 766 ///< 0 = 61.4 mSec
Issus 0:f9cf4a19bb84 767 ///< 1 = 92.2 mSec
Issus 0:f9cf4a19bb84 768 ///< 2 = 154 mSec
Issus 0:f9cf4a19bb84 769 ///< 3 = 276 mSec
Issus 0:f9cf4a19bb84 770 ///< 4 = 522 mSec
Issus 0:f9cf4a19bb84 771 ///< 5 = 1.01 Sec
Issus 0:f9cf4a19bb84 772 ///< 6 = 2.00 Sec
Issus 0:f9cf4a19bb84 773 ///< 7 = 3.96 Sec
Issus 0:f9cf4a19bb84 774 ///< 8 = 7.90 Sec
Issus 0:f9cf4a19bb84 775 ///< 9 = 15.8 Sec
Issus 0:f9cf4a19bb84 776 ///< 10 = 31.5 Sec
Issus 0:f9cf4a19bb84 777 ///< 11 = 62.9 Sec
Issus 0:f9cf4a19bb84 778 ///< 12 = 126 Sec
Issus 0:f9cf4a19bb84 779 ///< 13 = 252 Sec
Issus 0:f9cf4a19bb84 780 ///< 14 = 503 Sec
Issus 0:f9cf4a19bb84 781
Issus 0:f9cf4a19bb84 782 )
Issus 0:f9cf4a19bb84 783 {
Issus 0:f9cf4a19bb84 784 Wordu_t wuChannelMask;
Issus 0:f9cf4a19bb84 785
Issus 0:f9cf4a19bb84 786 wuChannelMask.u16 = u16ChannelMask;
Issus 0:f9cf4a19bb84 787
Issus 0:f9cf4a19bb84 788 if (u8ScanDuration <= LSR_MODULE_SCAN_DURATION_MAX)
Issus 0:f9cf4a19bb84 789 {
Issus 0:f9cf4a19bb84 790 AddSerialMsgHeader(LSR_MODULE_CHANNEL_ENERGY_SCAN_MSG_TYPE, 8);
Issus 0:f9cf4a19bb84 791 AddSerialByteToMsgBuffer(wuChannelMask.ws.lb);
Issus 0:f9cf4a19bb84 792 AddSerialByteToMsgBuffer(wuChannelMask.ws.hb);
Issus 0:f9cf4a19bb84 793 AddSerialByteToMsgBuffer(u8ScanDuration);
Issus 0:f9cf4a19bb84 794 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 795 }
Issus 0:f9cf4a19bb84 796 } /*** End ChannelEnergyScanMsg ***/
Issus 0:f9cf4a19bb84 797
Issus 6:b0445108f82f 798 /**
Issus 6:b0445108f82f 799 * Sends message type 0x51 (Query Host Interface Configuration) to the module via UART communication. This will spark a
Issus 6:b0445108f82f 800 * response message from the module to the host of type 0xD1. Subscribing to 0xD1 in your main application
Issus 6:b0445108f82f 801 * will allow you to parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 6:b0445108f82f 802 *
Issus 6:b0445108f82f 803 */
Issus 6:b0445108f82f 804 void LsrModule::QueryHostInterfaceConfiguration(void)
Issus 6:b0445108f82f 805 {
Issus 6:b0445108f82f 806 AddSerialMsgHeader(LSR_MODULE_QUERY_HOST_INTERFACE_CONFIGURATION, 5);
Issus 6:b0445108f82f 807 AddSerialMsgTrailer();
Issus 6:b0445108f82f 808 } /*** End QuerySupplyVoltageMsg ***/
Issus 6:b0445108f82f 809
Issus 6:b0445108f82f 810
Issus 0:f9cf4a19bb84 811
Issus 0:f9cf4a19bb84 812 /**
Issus 0:f9cf4a19bb84 813 * Verifies msg type and length.
Issus 0:f9cf4a19bb84 814 * @return True: Valid msg length and type. False: Invalid msg length or type.
Issus 0:f9cf4a19bb84 815 *
Issus 0:f9cf4a19bb84 816 */
Issus 0:f9cf4a19bb84 817 bool LsrModule::ValidMsgLengthAndType(uint8_t u8MsgType ///< Received UART message type.
Issus 0:f9cf4a19bb84 818 , uint8_t u8MsgLength ///< Received UART message length.
Issus 0:f9cf4a19bb84 819 )
Issus 0:f9cf4a19bb84 820 {
Issus 0:f9cf4a19bb84 821 if ((u8MsgLength >= cau8RxMsgLengthAndTypeTable[u8MsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE][0]) &&
Issus 0:f9cf4a19bb84 822 (u8MsgLength <= cau8RxMsgLengthAndTypeTable[u8MsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE][1]))
Issus 0:f9cf4a19bb84 823 {
Issus 0:f9cf4a19bb84 824 return true;
Issus 0:f9cf4a19bb84 825 }
Issus 0:f9cf4a19bb84 826 return false;
Issus 0:f9cf4a19bb84 827 } /*** End ValidMsgLengthAndType ***/
Issus 0:f9cf4a19bb84 828
Issus 0:f9cf4a19bb84 829
Issus 0:f9cf4a19bb84 830 /**
Issus 0:f9cf4a19bb84 831 * Verifies message checksum.
Issus 0:f9cf4a19bb84 832 * @return True: Valid checksum. False: Invalid checksum.
Issus 0:f9cf4a19bb84 833 *
Issus 0:f9cf4a19bb84 834 */
Issus 0:f9cf4a19bb84 835 bool LsrModule::ValidRxChecksum(uint8_t* pu8MsgBuffer ///< Pointer to received UART buffer.
Issus 0:f9cf4a19bb84 836 , uint8_t u8MsgLength ///< Received UART message length.
Issus 0:f9cf4a19bb84 837 )
Issus 0:f9cf4a19bb84 838 {
Issus 0:f9cf4a19bb84 839 uint8_t u8Checksum = 0;
Issus 0:f9cf4a19bb84 840
Issus 0:f9cf4a19bb84 841 for (u8ForLoopCounter = 0; u8ForLoopCounter < (u8MsgLength - 2); u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 842 {
Issus 0:f9cf4a19bb84 843 u8Checksum += au8UartRxBuffer[u8ForLoopCounter];
Issus 0:f9cf4a19bb84 844 }
Issus 0:f9cf4a19bb84 845
Issus 0:f9cf4a19bb84 846 if (au8UartRxBuffer[u8MsgLength-2] == u8Checksum)
Issus 0:f9cf4a19bb84 847 {
Issus 0:f9cf4a19bb84 848 return true;
Issus 0:f9cf4a19bb84 849 }
Issus 0:f9cf4a19bb84 850
Issus 0:f9cf4a19bb84 851 return false;
Issus 0:f9cf4a19bb84 852 } /*** End ValidRxChecksum ***/
Issus 0:f9cf4a19bb84 853
Issus 0:f9cf4a19bb84 854
Issus 0:f9cf4a19bb84 855 /**
Issus 0:f9cf4a19bb84 856 * Calls appropriate callback function for received message.
Issus 0:f9cf4a19bb84 857 *
Issus 0:f9cf4a19bb84 858 */
Issus 0:f9cf4a19bb84 859 void LsrModule::HostProcessCallbackMsgStart(uint8_t* pu8MsgBuffer ///< Pointer to received message.
Issus 0:f9cf4a19bb84 860 , uint8_t u8Length ///< Length of received message.
Issus 0:f9cf4a19bb84 861 )
Issus 0:f9cf4a19bb84 862 {
Issus 0:f9cf4a19bb84 863 if ((ptrRxMsgCallbackTable[(*(pu8MsgBuffer + LSR_MODULE_MSG_TYPE_BYTE_INDEX)) - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE]) != NULL)
Issus 0:f9cf4a19bb84 864 {
Issus 0:f9cf4a19bb84 865 ptrRxMsgCallbackTable[(*(pu8MsgBuffer + LSR_MODULE_MSG_TYPE_BYTE_INDEX)) - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE]();
Issus 0:f9cf4a19bb84 866 }
Issus 0:f9cf4a19bb84 867 } /*** End HostProcessCallbackMsgStart ***/
Issus 0:f9cf4a19bb84 868
Issus 0:f9cf4a19bb84 869
Issus 0:f9cf4a19bb84 870 /**
Issus 0:f9cf4a19bb84 871 * Determines if appropriate serial port is available.
Issus 0:f9cf4a19bb84 872 * @return True: Serial is available. False: Serial is unavailable.
Issus 0:f9cf4a19bb84 873 *
Issus 0:f9cf4a19bb84 874 */
Issus 0:f9cf4a19bb84 875 bool LsrModule::SerialAvailable(void)
Issus 0:f9cf4a19bb84 876 {
Issus 0:f9cf4a19bb84 877 if (readable())
Issus 0:f9cf4a19bb84 878 {
Issus 0:f9cf4a19bb84 879 return true;
Issus 0:f9cf4a19bb84 880 }
Issus 0:f9cf4a19bb84 881
Issus 0:f9cf4a19bb84 882 return false;
Issus 0:f9cf4a19bb84 883 } /*** End SerialAvailable ***/
Issus 0:f9cf4a19bb84 884
Issus 0:f9cf4a19bb84 885
Issus 0:f9cf4a19bb84 886 /**
Issus 0:f9cf4a19bb84 887 * Reads appropriate serial port.
Issus 0:f9cf4a19bb84 888 * @return Byte read.
Issus 0:f9cf4a19bb84 889 *
Issus 0:f9cf4a19bb84 890 */
Issus 0:f9cf4a19bb84 891 uint8_t LsrModule::SerialRead(void)
Issus 0:f9cf4a19bb84 892 {
Issus 0:f9cf4a19bb84 893 return getc();
Issus 0:f9cf4a19bb84 894
Issus 0:f9cf4a19bb84 895 } /*** End SerialRead ***/
Issus 0:f9cf4a19bb84 896
Issus 0:f9cf4a19bb84 897
Issus 0:f9cf4a19bb84 898 /**
Issus 0:f9cf4a19bb84 899 * Refreshes and restarts Rx state machine.
Issus 0:f9cf4a19bb84 900 *
Issus 0:f9cf4a19bb84 901 */
Issus 0:f9cf4a19bb84 902 void LsrModule::SerialRxCleanupRestart(void)
Issus 0:f9cf4a19bb84 903 {
Issus 0:f9cf4a19bb84 904 SerialFlush();
Issus 0:f9cf4a19bb84 905 u8UartRxBufferIndex = LSR_MODULE_MSG_START_BYTE_INDEX;
Issus 0:f9cf4a19bb84 906 ptrHostState = &LsrModule::HostRxWaitForMsgStartByteState;
Issus 0:f9cf4a19bb84 907 } /*** End SerialRxCleanupRestart ***/
Issus 0:f9cf4a19bb84 908
Issus 0:f9cf4a19bb84 909
Issus 0:f9cf4a19bb84 910 /**
Issus 0:f9cf4a19bb84 911 * Waits for data packet start byte.
Issus 0:f9cf4a19bb84 912 *
Issus 0:f9cf4a19bb84 913 */
Issus 0:f9cf4a19bb84 914 void LsrModule::HostRxWaitForMsgStartByteState(void)
Issus 0:f9cf4a19bb84 915 {
Issus 0:f9cf4a19bb84 916 if (SerialAvailable() && (SerialRead() == LSR_MODULE_SERIAL_MSG_START_BYTE))
Issus 0:f9cf4a19bb84 917 {
Issus 0:f9cf4a19bb84 918 au8UartRxBuffer[u8UartRxBufferIndex++] = LSR_MODULE_SERIAL_MSG_START_BYTE;
Issus 0:f9cf4a19bb84 919 ptrHostState = &LsrModule::HostRxGetMsgLengthState;
Issus 0:f9cf4a19bb84 920 }
Issus 0:f9cf4a19bb84 921 } /*** End HostRxWaitForMsgStartByteState ***/
Issus 0:f9cf4a19bb84 922
Issus 0:f9cf4a19bb84 923
Issus 0:f9cf4a19bb84 924 /**
Issus 0:f9cf4a19bb84 925 * Gets data packet length byte.
Issus 0:f9cf4a19bb84 926 *
Issus 0:f9cf4a19bb84 927 */
Issus 0:f9cf4a19bb84 928 void LsrModule::HostRxGetMsgLengthState(void)
Issus 0:f9cf4a19bb84 929 {
Issus 0:f9cf4a19bb84 930 if (SerialAvailable())
Issus 0:f9cf4a19bb84 931 {
Issus 0:f9cf4a19bb84 932 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 933
Issus 0:f9cf4a19bb84 934 if ((u8RxReadByte >= LSR_MODULE_MIN_SERIAL_RX_MSG_LENGTH) &&
Issus 0:f9cf4a19bb84 935 (u8RxReadByte <= LSR_MODULE_MAX_SERIAL_RX_MSG_LENGTH))
Issus 0:f9cf4a19bb84 936 {
Issus 0:f9cf4a19bb84 937 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 938 ptrHostState = &LsrModule::HostRxGetMsgTypeState;
Issus 0:f9cf4a19bb84 939 }
Issus 0:f9cf4a19bb84 940 else
Issus 0:f9cf4a19bb84 941 {
Issus 0:f9cf4a19bb84 942 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 943 }
Issus 0:f9cf4a19bb84 944 }
Issus 0:f9cf4a19bb84 945 } /*** End HostRxGetMsgLengthState ***/
Issus 0:f9cf4a19bb84 946
Issus 0:f9cf4a19bb84 947
Issus 0:f9cf4a19bb84 948 /**
Issus 0:f9cf4a19bb84 949 * Gets data packet type byte.
Issus 0:f9cf4a19bb84 950 *
Issus 0:f9cf4a19bb84 951 */
Issus 0:f9cf4a19bb84 952 void LsrModule::HostRxGetMsgTypeState(void)
Issus 0:f9cf4a19bb84 953 {
Issus 0:f9cf4a19bb84 954 if (SerialAvailable())
Issus 0:f9cf4a19bb84 955 {
Issus 0:f9cf4a19bb84 956
Issus 0:f9cf4a19bb84 957 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 958
Issus 0:f9cf4a19bb84 959 if (ValidMsgLengthAndType(u8RxReadByte, au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]))
Issus 0:f9cf4a19bb84 960 {
Issus 0:f9cf4a19bb84 961 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 962 ptrHostState = &LsrModule::HostRxWaitToGetRestOfMsgState;
Issus 0:f9cf4a19bb84 963 }
Issus 0:f9cf4a19bb84 964 else
Issus 0:f9cf4a19bb84 965 {
Issus 0:f9cf4a19bb84 966 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 967 }
Issus 0:f9cf4a19bb84 968 }
Issus 0:f9cf4a19bb84 969 } /*** End HostRxGetMsgTypeState ***/
Issus 0:f9cf4a19bb84 970
Issus 0:f9cf4a19bb84 971
Issus 0:f9cf4a19bb84 972 /**
Issus 0:f9cf4a19bb84 973 * Grabs rest of data packet bytes.
Issus 0:f9cf4a19bb84 974 *
Issus 0:f9cf4a19bb84 975 */
Issus 0:f9cf4a19bb84 976 void LsrModule::HostRxWaitToGetRestOfMsgState(void)
Issus 0:f9cf4a19bb84 977 {
Issus 0:f9cf4a19bb84 978 if (SerialAvailable())
Issus 0:f9cf4a19bb84 979 {
Issus 0:f9cf4a19bb84 980 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 981 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 982
Issus 0:f9cf4a19bb84 983 if (u8UartRxBufferIndex > LSR_MODULE_MAX_SERIAL_RX_MSG_LENGTH)
Issus 0:f9cf4a19bb84 984 {
Issus 0:f9cf4a19bb84 985 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 986 }
Issus 0:f9cf4a19bb84 987 else if ((u8RxReadByte == LSR_MODULE_SERIAL_MSG_END_BYTE) && (u8UartRxBufferIndex == au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]))
Issus 0:f9cf4a19bb84 988 {
Issus 0:f9cf4a19bb84 989 ptrHostState = &LsrModule::HostRxValidateMsgState;
Issus 0:f9cf4a19bb84 990 }
Issus 0:f9cf4a19bb84 991 }
Issus 0:f9cf4a19bb84 992 } /*** End HostRxWaitToGetRestOfMsgState ***/
Issus 0:f9cf4a19bb84 993
Issus 0:f9cf4a19bb84 994
Issus 0:f9cf4a19bb84 995 /**
Issus 0:f9cf4a19bb84 996 * Validates received message.
Issus 0:f9cf4a19bb84 997 *
Issus 0:f9cf4a19bb84 998 */
Issus 0:f9cf4a19bb84 999 void LsrModule::HostRxValidateMsgState(void)
Issus 0:f9cf4a19bb84 1000 {
Issus 0:f9cf4a19bb84 1001
Issus 0:f9cf4a19bb84 1002 if (ValidRxChecksum(au8UartRxBuffer, au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX])) // Is checksum good?
Issus 0:f9cf4a19bb84 1003 {
Issus 0:f9cf4a19bb84 1004 ptrHostState = &LsrModule::HostRxGoodMsgState; // Good checksum - next state
Issus 0:f9cf4a19bb84 1005 }
Issus 0:f9cf4a19bb84 1006 else
Issus 0:f9cf4a19bb84 1007 {
Issus 0:f9cf4a19bb84 1008 ptrHostState = &LsrModule::SerialRxCleanupRestart; // Bad checksum - restart
Issus 0:f9cf4a19bb84 1009 }
Issus 0:f9cf4a19bb84 1010 } /*** End HostRxValidateMsgState ***/
Issus 0:f9cf4a19bb84 1011
Issus 0:f9cf4a19bb84 1012
Issus 0:f9cf4a19bb84 1013 /**
Issus 0:f9cf4a19bb84 1014 * Calls appropriate received UART message callback and starts state machine over.
Issus 0:f9cf4a19bb84 1015 *
Issus 0:f9cf4a19bb84 1016 */
Issus 0:f9cf4a19bb84 1017 void LsrModule::HostRxGoodMsgState(void)
Issus 0:f9cf4a19bb84 1018 {
Issus 0:f9cf4a19bb84 1019 pu8RxBuffer = au8UartRxBuffer;
Issus 0:f9cf4a19bb84 1020 u8RxMsgLength = au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX];
Issus 0:f9cf4a19bb84 1021 HostProcessCallbackMsgStart(au8UartRxBuffer, u8RxMsgLength);
Issus 0:f9cf4a19bb84 1022 ptrHostState = &LsrModule::SerialRxCleanupRestart; // Start new RX sequence
Issus 0:f9cf4a19bb84 1023 } /*** End HostRxGoodMsgState ***/