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

Committer:
Issus
Date:
Fri Jul 29 17:36:33 2016 +0000
Revision:
9:98edda6ea79e
Parent:
8:10f8dbd8dfff
Removed auto attached serial, not reliable enough.

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 8:10f8dbd8dfff 133 ptrHostState = &LsrModule::HostRxWaitForMsgStartByteState;
Issus 8:10f8dbd8dfff 134
Issus 9:98edda6ea79e 135 //attach(this, &LsrModule::RunHostRxStateMachine);
Issus 0:f9cf4a19bb84 136 } /*** End LsrModule ***/
Issus 0:f9cf4a19bb84 137
Issus 0:f9cf4a19bb84 138
Issus 0:f9cf4a19bb84 139 /**
Issus 0:f9cf4a19bb84 140 * Destructor. Called automatically, de-allocates resources.
Issus 0:f9cf4a19bb84 141 *
Issus 0:f9cf4a19bb84 142 */
Issus 0:f9cf4a19bb84 143 LsrModule::~LsrModule(void)
Issus 0:f9cf4a19bb84 144 {
Issus 0:f9cf4a19bb84 145 pu8RxBuffer = NULL;
Issus 0:f9cf4a19bb84 146 ptrHostState = NULL;
Issus 0:f9cf4a19bb84 147 ptrHostProcessCallbackState = NULL;
Issus 0:f9cf4a19bb84 148
Issus 0:f9cf4a19bb84 149 for (u8ForLoopCounter = 0; u8ForLoopCounter < sizeof(ptrRxMsgCallbackTable); u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 150 {
Issus 0:f9cf4a19bb84 151 ptrRxMsgCallbackTable[u8ForLoopCounter] = NULL;
Issus 0:f9cf4a19bb84 152 }
Issus 0:f9cf4a19bb84 153 } /*** End ~LsrModule ***/
Issus 0:f9cf4a19bb84 154
Issus 0:f9cf4a19bb84 155
Issus 0:f9cf4a19bb84 156 /**
Issus 0:f9cf4a19bb84 157 * Creates a callback for specific received UART message. Call this function from your main application in
Issus 0:f9cf4a19bb84 158 * this manner: "SubscribeRxMsgCallback(0xA1, &simpleShortAddrCallback)", where simpleShortAddrCallback is
Issus 0:f9cf4a19bb84 159 * defined like this: void simpleShortAddrCallback(void) in your main application.
Issus 0:f9cf4a19bb84 160 * IMPORTANT: All user defined callback methods must return void and take no parameters (void).
Issus 0:f9cf4a19bb84 161 *
Issus 0:f9cf4a19bb84 162 * @return True: Subscribed callback. False: Did not subscribe callback.
Issus 0:f9cf4a19bb84 163 *
Issus 0:f9cf4a19bb84 164 */
Issus 0:f9cf4a19bb84 165 bool LsrModule::SubscribeRxMsgCallback(uint8_t u8RxMsgType ///< The received message for which you want the callback to execute.
Issus 0:f9cf4a19bb84 166 , void (*callback)(void) ///< C function pointer to the specified callback function.
Issus 0:f9cf4a19bb84 167 )
Issus 0:f9cf4a19bb84 168 {
Issus 0:f9cf4a19bb84 169 if ((u8RxMsgType > LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE) && (u8RxMsgType < LSR_MODULE_MAX_SERIAL_RX_MSG_TYPE))
Issus 0:f9cf4a19bb84 170 {
Issus 0:f9cf4a19bb84 171 ptrRxMsgCallbackTable[u8RxMsgType- LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE] = callback;
Issus 0:f9cf4a19bb84 172 return true;
Issus 0:f9cf4a19bb84 173 }
Issus 0:f9cf4a19bb84 174
Issus 0:f9cf4a19bb84 175 return false;
Issus 0:f9cf4a19bb84 176 } /*** End SubscribeRxMsgCallback ***/
Issus 0:f9cf4a19bb84 177
Issus 0:f9cf4a19bb84 178
Issus 0:f9cf4a19bb84 179 /**
Issus 0:f9cf4a19bb84 180 * Removes a callback for specific received UART message. See SubscribeRxMsgCallback's description for
Issus 0:f9cf4a19bb84 181 * more information.
Issus 0:f9cf4a19bb84 182 *
Issus 0:f9cf4a19bb84 183 * @return True: Unsubscribed callback. False: Did not unsubscribed callback.
Issus 0:f9cf4a19bb84 184 *
Issus 0:f9cf4a19bb84 185 */
Issus 0:f9cf4a19bb84 186 bool LsrModule::UnsubscribeRxMsgCallback(uint8_t u8RxMsgType ///< The received message for which you want the callback to be removed.
Issus 0:f9cf4a19bb84 187 )
Issus 0:f9cf4a19bb84 188 {
Issus 0:f9cf4a19bb84 189 if ((u8RxMsgType > LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE) && (u8RxMsgType < LSR_MODULE_MAX_SERIAL_RX_MSG_TYPE))
Issus 0:f9cf4a19bb84 190 {
Issus 0:f9cf4a19bb84 191 ptrRxMsgCallbackTable[u8RxMsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE] = NULL;
Issus 0:f9cf4a19bb84 192 return true;
Issus 0:f9cf4a19bb84 193 }
Issus 0:f9cf4a19bb84 194
Issus 0:f9cf4a19bb84 195 return false;
Issus 0:f9cf4a19bb84 196 } /*** End UnsubscribeRxMsgCallback ***/
Issus 0:f9cf4a19bb84 197
Issus 0:f9cf4a19bb84 198
Issus 0:f9cf4a19bb84 199 /**
Issus 0:f9cf4a19bb84 200 * Executes host RX state machine. This function must be executed continually from the loop function in your main
Issus 0:f9cf4a19bb84 201 * application.
Issus 0:f9cf4a19bb84 202 *
Issus 0:f9cf4a19bb84 203 */
Issus 0:f9cf4a19bb84 204 void LsrModule::RunHostRxStateMachine(void)
Issus 0:f9cf4a19bb84 205 {
Issus 0:f9cf4a19bb84 206 (this->*ptrHostState)();
Issus 0:f9cf4a19bb84 207 } /*** End RunHostRxStateMachine ***/
Issus 0:f9cf4a19bb84 208
Issus 0:f9cf4a19bb84 209
Issus 0:f9cf4a19bb84 210 /**
Issus 0:f9cf4a19bb84 211 * Flushes appropriate serial port.
Issus 0:f9cf4a19bb84 212 *
Issus 0:f9cf4a19bb84 213 */
Issus 0:f9cf4a19bb84 214 void LsrModule::SerialFlush(void)
Issus 0:f9cf4a19bb84 215 {
Issus 0:f9cf4a19bb84 216 // Serial.flush();
Issus 0:f9cf4a19bb84 217 // i think this is meant to clean out the rx buffer
Issus 0:f9cf4a19bb84 218 /*** End SerialFlush ***/
Issus 0:f9cf4a19bb84 219 }
Issus 0:f9cf4a19bb84 220
Issus 0:f9cf4a19bb84 221 /**
Issus 0:f9cf4a19bb84 222 * Adds header to the UART transmit buffer.
Issus 0:f9cf4a19bb84 223 *
Issus 0:f9cf4a19bb84 224 */
Issus 0:f9cf4a19bb84 225 void LsrModule::AddSerialMsgHeader(uint8_t u8MsgType, uint8_t u8MsgLength)
Issus 0:f9cf4a19bb84 226 {
Issus 0:f9cf4a19bb84 227 SerialFlush();
Issus 0:f9cf4a19bb84 228 u8UartTxBufferIndex = LSR_MODULE_MSG_START_BYTE_INDEX;
Issus 0:f9cf4a19bb84 229 au8UartTxBuffer[u8UartTxBufferIndex++] = LSR_MODULE_SERIAL_MSG_START_BYTE;
Issus 0:f9cf4a19bb84 230 au8UartTxBuffer[u8UartTxBufferIndex++] = u8MsgLength;
Issus 0:f9cf4a19bb84 231 au8UartTxBuffer[u8UartTxBufferIndex++] = u8MsgType;
Issus 0:f9cf4a19bb84 232 u8TxMsgChecksum = (LSR_MODULE_SERIAL_MSG_START_BYTE + u8MsgLength + u8MsgType);
Issus 0:f9cf4a19bb84 233 } /*** End LsrModuleAddSerialMsgHeader ***/
Issus 0:f9cf4a19bb84 234
Issus 0:f9cf4a19bb84 235
Issus 0:f9cf4a19bb84 236 /**
Issus 0:f9cf4a19bb84 237 * Adds data bytes to the UART transmit buffer.
Issus 0:f9cf4a19bb84 238 *
Issus 0:f9cf4a19bb84 239 */
Issus 0:f9cf4a19bb84 240 void LsrModule::AddSerialByteToMsgBuffer(uint8_t u8Data ///< The data to add.
Issus 0:f9cf4a19bb84 241 )
Issus 0:f9cf4a19bb84 242 {
Issus 0:f9cf4a19bb84 243 au8UartTxBuffer[u8UartTxBufferIndex++] = u8Data;
Issus 0:f9cf4a19bb84 244 u8TxMsgChecksum += u8Data;
Issus 0:f9cf4a19bb84 245 } /*** End LsrModuleAddSerialByteToMsgBuffer ***/
Issus 0:f9cf4a19bb84 246
Issus 0:f9cf4a19bb84 247
Issus 0:f9cf4a19bb84 248 /**
Issus 0:f9cf4a19bb84 249 * Adds message trailer to the UART transmit buffer.
Issus 0:f9cf4a19bb84 250 *
Issus 0:f9cf4a19bb84 251 */
Issus 0:f9cf4a19bb84 252 void LsrModule::AddSerialMsgTrailer(void)
Issus 0:f9cf4a19bb84 253 {
Issus 0:f9cf4a19bb84 254 au8UartTxBuffer[u8UartTxBufferIndex++] = u8TxMsgChecksum;
Issus 0:f9cf4a19bb84 255 au8UartTxBuffer[u8UartTxBufferIndex] = LSR_MODULE_SERIAL_MSG_END_BYTE;
Issus 0:f9cf4a19bb84 256 WriteSerialMsg();
Issus 0:f9cf4a19bb84 257 } /*** End AddSerialMsgTrailer ***/
Issus 0:f9cf4a19bb84 258
Issus 0:f9cf4a19bb84 259
Issus 0:f9cf4a19bb84 260 /**
Issus 0:f9cf4a19bb84 261 * Writes the UART transmit buffer using the appropriate serial port.
Issus 0:f9cf4a19bb84 262 *
Issus 0:f9cf4a19bb84 263 */
Issus 0:f9cf4a19bb84 264 void LsrModule::WriteSerialMsg(void)
Issus 0:f9cf4a19bb84 265 {
Issus 0:f9cf4a19bb84 266 //write (const uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE)
Issus 0:f9cf4a19bb84 267 write(au8UartTxBuffer, au8UartTxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]);
Issus 0:f9cf4a19bb84 268
Issus 0:f9cf4a19bb84 269 } /*** End WriteSerialMsg ***/
Issus 0:f9cf4a19bb84 270
Issus 0:f9cf4a19bb84 271
Issus 0:f9cf4a19bb84 272 /**
Issus 0:f9cf4a19bb84 273 * Sends message type 0x01 (Query Version) to the module via UART communication. This will spark
Issus 0:f9cf4a19bb84 274 * a response message from the module to the Arduino of type 0x81. Subscribing to 0x81 in
Issus 0:f9cf4a19bb84 275 * your main application will allow you to parse the response data. See the description for
Issus 0:f9cf4a19bb84 276 * SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 277 *
Issus 0:f9cf4a19bb84 278 */
Issus 0:f9cf4a19bb84 279 void LsrModule::QueryVersionMsg(void)
Issus 0:f9cf4a19bb84 280 {
Issus 0:f9cf4a19bb84 281 AddSerialMsgHeader(LSR_MODULE_QUERY_VERSION_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 282 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 283 } /*** End QueryVersionMsg ***/
Issus 0:f9cf4a19bb84 284
Issus 0:f9cf4a19bb84 285
Issus 0:f9cf4a19bb84 286 /**
Issus 0:f9cf4a19bb84 287 * Sends message type 0x0C (Sets Security Transmit Frame Counter) to the module via UART communication.
Issus 0:f9cf4a19bb84 288 * This frame counter is used with RF messages transmitted with security to ensure sequential freshness.
Issus 0:f9cf4a19bb84 289 * This sets the starting frame count and is automatically incremented on every secured packet sent.
Issus 0:f9cf4a19bb84 290 * This will spark an ACK message from the module to the Arduino of type 0x8C. Subscribing to 0x8C in
Issus 0:f9cf4a19bb84 291 * your main application will allow you to parse the response data. See the description for
Issus 0:f9cf4a19bb84 292 * SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 293 *
Issus 0:f9cf4a19bb84 294 * Example:
Issus 0:f9cf4a19bb84 295 *
Issus 0:f9cf4a19bb84 296 * uint32_t u32FrameCounter = 0xAEDFEDFA;
Issus 0:f9cf4a19bb84 297 * SetSecurityTransmitFrameCounterMsg(&u32FrameCounter);
Issus 0:f9cf4a19bb84 298 *
Issus 0:f9cf4a19bb84 299 */
Issus 0:f9cf4a19bb84 300 void LsrModule::SetSecurityTransmitFrameCounterMsg(uint32_t* pu32FrameCounter ///< Pointer to 4 byte frame counter (LSB to MSB).
Issus 0:f9cf4a19bb84 301 )
Issus 0:f9cf4a19bb84 302 {
Issus 0:f9cf4a19bb84 303 DWordu_t dwuFrameCounter;
Issus 0:f9cf4a19bb84 304
Issus 0:f9cf4a19bb84 305 dwuFrameCounter.u32 = *pu32FrameCounter;
Issus 0:f9cf4a19bb84 306
Issus 0:f9cf4a19bb84 307 AddSerialMsgHeader(LSR_MODULE_SET_SECURITY_TX_FRAME_COUNTER_MSG_TYPE, 11);
Issus 0:f9cf4a19bb84 308 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.lb);
Issus 0:f9cf4a19bb84 309 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.mlb);
Issus 0:f9cf4a19bb84 310 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.mhb);
Issus 0:f9cf4a19bb84 311 AddSerialByteToMsgBuffer(dwuFrameCounter.dws.hb);
Issus 0:f9cf4a19bb84 312 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 313 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 314 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 315 } /*** End SetSecurityTransmitFrameCounterMsg ***/
Issus 0:f9cf4a19bb84 316
Issus 0:f9cf4a19bb84 317
Issus 0:f9cf4a19bb84 318 /**
Issus 0:f9cf4a19bb84 319 * Sends message type 0x0D (Query Security Transmit Frame Counter) to the module via UART communication. This
Issus 0:f9cf4a19bb84 320 * will spark a response message from the module to the Arduino of type 0x8D. Subscribing to 0x8D in your main
Issus 0:f9cf4a19bb84 321 * application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 322 * for more information.
Issus 0:f9cf4a19bb84 323 *
Issus 0:f9cf4a19bb84 324 */
Issus 0:f9cf4a19bb84 325 void LsrModule::QuerySecurityTransmitFrameCounterMsg(void)
Issus 0:f9cf4a19bb84 326 {
Issus 0:f9cf4a19bb84 327 AddSerialMsgHeader(LSR_MODULE_QUERY_SECURITY_TX_FRAME_COUNTER_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 328 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 329 } /*** End QuerySecurityTransmitFrameCounterMsg ***/
Issus 0:f9cf4a19bb84 330
Issus 0:f9cf4a19bb84 331
Issus 0:f9cf4a19bb84 332 /**
Issus 0:f9cf4a19bb84 333 * Sends message type 0x10 (Set Basic RF Settings) to the module via UART communication.
Issus 0:f9cf4a19bb84 334 * This will spark an ACK message from the module to the Arduino of type 0x90. Subscribing to 0x90 in
Issus 0:f9cf4a19bb84 335 * your main application will allow you to parse the response data. See the description for
Issus 0:f9cf4a19bb84 336 * SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 337 *
Issus 0:f9cf4a19bb84 338 */
Issus 0:f9cf4a19bb84 339 void LsrModule::SetBasicRfSettingsMsg(uint16_t u16PanId ///< Personal Area Network (PAN) ID assigned to module.
Issus 0:f9cf4a19bb84 340 , uint16_t u16AddrShort ///< 2 byte short address assigned to module.
Issus 0:f9cf4a19bb84 341 , 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 342 , uint8_t u8RfChannel ///< RF channel assigned to module.
Issus 0:f9cf4a19bb84 343 , uint8_t u8TxPowerLevel ///< Transmit power assigned to module.
Issus 0:f9cf4a19bb84 344 , uint8_t u8ReceiverConfig ///< 1 byte bitmask of receiver options.
Issus 0:f9cf4a19bb84 345 , uint8_t* pu8SecurityKey ///< Pointer to 32 byte security key assigned to module.
Issus 0:f9cf4a19bb84 346 )
Issus 0:f9cf4a19bb84 347 {
Issus 0:f9cf4a19bb84 348 Wordu_t wuPanId;
Issus 0:f9cf4a19bb84 349 Wordu_t wuShortAddr;
Issus 0:f9cf4a19bb84 350
Issus 0:f9cf4a19bb84 351 wuPanId.u16 = u16PanId;
Issus 0:f9cf4a19bb84 352 wuShortAddr.u16 = u16AddrShort;
Issus 0:f9cf4a19bb84 353
Issus 0:f9cf4a19bb84 354 if ((u8RfChannel >= LSR_MODULE_RF_CHANNEL_MIN) && (u8RfChannel <= LSR_MODULE_RF_CHANNEL_MAX) &&
Issus 0:f9cf4a19bb84 355 (u8TxPowerLevel <= LSR_MODULE_TX_POWER_LEVEL_MAX) &&
Issus 0:f9cf4a19bb84 356 (u8ReceiverConfig <= LSR_MODULE_RX_CONFIG_MAX))
Issus 0:f9cf4a19bb84 357 {
Issus 0:f9cf4a19bb84 358 AddSerialMsgHeader(LSR_MODULE_SET_BASIC_RF_SETTINGS_MSG_TYPE, 39);
Issus 0:f9cf4a19bb84 359 AddSerialByteToMsgBuffer(wuPanId.ws.lb);
Issus 0:f9cf4a19bb84 360 AddSerialByteToMsgBuffer(wuPanId.ws.hb);
Issus 0:f9cf4a19bb84 361 AddSerialByteToMsgBuffer(wuShortAddr.ws.lb);
Issus 0:f9cf4a19bb84 362 AddSerialByteToMsgBuffer(wuShortAddr.ws.hb);
Issus 0:f9cf4a19bb84 363
Issus 0:f9cf4a19bb84 364 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 365 {
Issus 0:f9cf4a19bb84 366 AddSerialByteToMsgBuffer(*pu8AddrLong);
Issus 0:f9cf4a19bb84 367 pu8AddrLong++;
Issus 0:f9cf4a19bb84 368 }
Issus 0:f9cf4a19bb84 369
Issus 0:f9cf4a19bb84 370 AddSerialByteToMsgBuffer(u8RfChannel);
Issus 0:f9cf4a19bb84 371 AddSerialByteToMsgBuffer(u8TxPowerLevel);
Issus 0:f9cf4a19bb84 372 AddSerialByteToMsgBuffer(u8ReceiverConfig);
Issus 0:f9cf4a19bb84 373
Issus 0:f9cf4a19bb84 374 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 375 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 376 AddSerialByteToMsgBuffer(0x00); // Add filler byte.
Issus 0:f9cf4a19bb84 377
Issus 0:f9cf4a19bb84 378 for (u8ForLoopCounter = 0; u8ForLoopCounter < 16; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 379 {
Issus 0:f9cf4a19bb84 380 AddSerialByteToMsgBuffer(*pu8SecurityKey);
Issus 0:f9cf4a19bb84 381 pu8SecurityKey++;
Issus 0:f9cf4a19bb84 382 }
Issus 0:f9cf4a19bb84 383
Issus 0:f9cf4a19bb84 384 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 385 }
Issus 0:f9cf4a19bb84 386 } /*** End SetBasicRfSettingsMsg ***/
Issus 0:f9cf4a19bb84 387
Issus 0:f9cf4a19bb84 388
Issus 0:f9cf4a19bb84 389 /**
Issus 0:f9cf4a19bb84 390 * Sends message type 0x11 (Query Basic RF Settings) to the module via UART communication. This will spark
Issus 0:f9cf4a19bb84 391 * a response message from the module to the Arduino of type 0x91. Subscribing to 0x91 in your main
Issus 0:f9cf4a19bb84 392 * application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 393 * for more information.
Issus 0:f9cf4a19bb84 394 *
Issus 0:f9cf4a19bb84 395 */
Issus 0:f9cf4a19bb84 396 void LsrModule::QueryBasicRfSettingsMsg(void)
Issus 0:f9cf4a19bb84 397 {
Issus 0:f9cf4a19bb84 398 AddSerialMsgHeader(LSR_MODULE_QUERY_BASIC_RF_SETTINGS_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 399 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 400 } /*** End QueryBasicRfSettingsMsg ***/
Issus 0:f9cf4a19bb84 401
Issus 0:f9cf4a19bb84 402
Issus 0:f9cf4a19bb84 403 /**
Issus 0:f9cf4a19bb84 404 * Sends message type 0x12 (Save Settings to non-volatile Memory) to the module via UART communication. Calling
Issus 0:f9cf4a19bb84 405 * this command will make your module retain all basic configuration settings on boot up. This will spark an ACK
Issus 0:f9cf4a19bb84 406 * message from the module to the Arduino of type 0x92. Subscribing to 0x92 in your main application will allow
Issus 0:f9cf4a19bb84 407 * you to parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 408 *
Issus 0:f9cf4a19bb84 409 */
Issus 0:f9cf4a19bb84 410 void LsrModule::SaveSettingsToNVMemoryMsg(void)
Issus 0:f9cf4a19bb84 411 {
Issus 0:f9cf4a19bb84 412 AddSerialMsgHeader(LSR_MODULE_SAVE_SETTINGS_TO_NV_MEMORY_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 413 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 414 } /*** End SaveSettingsToNVMemoryMsg ***/
Issus 0:f9cf4a19bb84 415
Issus 0:f9cf4a19bb84 416
Issus 0:f9cf4a19bb84 417 /**
Issus 0:f9cf4a19bb84 418 * Sends message type 0x13 (Reset Request) to the module via UART communication. This will make your module perform
Issus 0:f9cf4a19bb84 419 * a restart. This will spark an ACK message from the module to the Arduino of type 0x93. Subscribing to 0x93 in
Issus 0:f9cf4a19bb84 420 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 421 * for more information.
Issus 0:f9cf4a19bb84 422 *
Issus 0:f9cf4a19bb84 423 */
Issus 0:f9cf4a19bb84 424 void LsrModule::ResetRequestMsg(void)
Issus 0:f9cf4a19bb84 425 {
Issus 0:f9cf4a19bb84 426 AddSerialMsgHeader(LSR_MODULE_RESET_REQUEST_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 427 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 428 } /*** End ResetRequestMsg ***/
Issus 0:f9cf4a19bb84 429
Issus 0:f9cf4a19bb84 430
Issus 0:f9cf4a19bb84 431 /**
Issus 0:f9cf4a19bb84 432 * Sends message type 0x14 (Query Supply Voltage) to the module via UART communication. This will spark a
Issus 0:f9cf4a19bb84 433 * response message from the module to the Arduino of type 0x94. Subscribing to 0x94 in your main application
Issus 0:f9cf4a19bb84 434 * will allow you to parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 435 *
Issus 0:f9cf4a19bb84 436 */
Issus 0:f9cf4a19bb84 437 void LsrModule::QuerySupplyVoltageMsg(void)
Issus 0:f9cf4a19bb84 438 {
Issus 0:f9cf4a19bb84 439 AddSerialMsgHeader(LSR_MODULE_QUERY_SUPPLY_VOLTAGE_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 440 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 441 } /*** End QuerySupplyVoltageMsg ***/
Issus 0:f9cf4a19bb84 442
Issus 0:f9cf4a19bb84 443
Issus 0:f9cf4a19bb84 444 /**
Issus 0:f9cf4a19bb84 445 * Sends message type 0x15 (Query Statistics) to the module via UART communication. Statistics include packets sent,
Issus 0:f9cf4a19bb84 446 * acks received, packets received and broadcast packets received. This will spark a response message from the module
Issus 0:f9cf4a19bb84 447 * to the Arduino of type 0x95. Subscribing to 0x94 in your main application will allow you to parse the response
Issus 0:f9cf4a19bb84 448 * data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 449 *
Issus 0:f9cf4a19bb84 450 */
Issus 0:f9cf4a19bb84 451 void LsrModule::QueryStatisticsMsg(void)
Issus 0:f9cf4a19bb84 452 {
Issus 0:f9cf4a19bb84 453 AddSerialMsgHeader(LSR_MODULE_QUERY_STATISTICS_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 454 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 455 } /*** End QueryStatisticsMsg ***/
Issus 0:f9cf4a19bb84 456
Issus 0:f9cf4a19bb84 457
Issus 0:f9cf4a19bb84 458 /**
Issus 0:f9cf4a19bb84 459 * Sends message type 0x16 (Clear Statistics) to the module via UART communication. This will spark an ACK message
Issus 0:f9cf4a19bb84 460 * from the module to the Arduino of type 0x96. Subscribing to 0x96 in your main application will allow you to
Issus 0:f9cf4a19bb84 461 * Parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 462 *
Issus 0:f9cf4a19bb84 463 */
Issus 0:f9cf4a19bb84 464 void LsrModule::ClearStatisticsMsg(void)
Issus 0:f9cf4a19bb84 465 {
Issus 0:f9cf4a19bb84 466 AddSerialMsgHeader(LSR_MODULE_CLEAR_STATISTICS_MSG_TYPE, 5);
Issus 0:f9cf4a19bb84 467 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 468 } /*** End ClearStatisticsMsg ***/
Issus 0:f9cf4a19bb84 469
Issus 0:f9cf4a19bb84 470
Issus 0:f9cf4a19bb84 471 /**
Issus 0:f9cf4a19bb84 472 * Sends message type 0x18 (Set Host Data Rate) to the module via UART communication. This will spark an ACK message
Issus 0:f9cf4a19bb84 473 * from the module to the Arduino of type 0x98. Subscribing to 0x98 in your main application will allow you to parse
Issus 0:f9cf4a19bb84 474 * the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 475 *
Issus 0:f9cf4a19bb84 476 */
Issus 0:f9cf4a19bb84 477 void LsrModule::SetHostDataRateMsg(uint8_t u8HostDataRate ///< Data rate for module to use when communicating via UART:
Issus 0:f9cf4a19bb84 478 ///< 0 = 1,200 bits/s
Issus 0:f9cf4a19bb84 479 ///< 1 = 2,400 bits/s
Issus 0:f9cf4a19bb84 480 ///< 2 = 4,800 bits/s
Issus 0:f9cf4a19bb84 481 ///< 3 = 9,600 bits/s
Issus 0:f9cf4a19bb84 482 ///< 4 = 19,200 bits/s
Issus 0:f9cf4a19bb84 483 ///< 5 = 38,400 bits/s
Issus 0:f9cf4a19bb84 484 ///< 6 = 57,600 bits/s
Issus 0:f9cf4a19bb84 485 ///< 7 = 115,200 bits/s
Issus 0:f9cf4a19bb84 486 )
Issus 0:f9cf4a19bb84 487 {
Issus 0:f9cf4a19bb84 488 if (u8HostDataRate <= LSR_MODULE_HOST_DATA_RATE_MAX)
Issus 0:f9cf4a19bb84 489 {
Issus 0:f9cf4a19bb84 490 AddSerialMsgHeader(LSR_MODULE_SET_HOST_DATA_RATE_MSG_TYPE, 6);
Issus 0:f9cf4a19bb84 491 AddSerialByteToMsgBuffer(u8HostDataRate);
Issus 0:f9cf4a19bb84 492 AddSerialMsgTrailer();
Issus 2:2c0b7246d769 493
Issus 3:8d794c196710 494 // 2.4 ms for the data rate change packet to be transmitted.
Issus 3:8d794c196710 495 wait_ms(3);
Issus 3:8d794c196710 496
Issus 2:2c0b7246d769 497 switch (u8HostDataRate)
Issus 2:2c0b7246d769 498 {
Issus 2:2c0b7246d769 499 case LSR_MODULE_HOST_DATA_RATE_1200:
Issus 2:2c0b7246d769 500 baud(1200);
Issus 2:2c0b7246d769 501 break;
Issus 2:2c0b7246d769 502 case LSR_MODULE_HOST_DATA_RATE_2400:
Issus 2:2c0b7246d769 503 baud(2400);
Issus 2:2c0b7246d769 504 break;
Issus 2:2c0b7246d769 505 case LSR_MODULE_HOST_DATA_RATE_4800:
Issus 2:2c0b7246d769 506 baud(4800);
Issus 2:2c0b7246d769 507 break;
Issus 2:2c0b7246d769 508 case LSR_MODULE_HOST_DATA_RATE_9600:
Issus 2:2c0b7246d769 509 baud(9600);
Issus 2:2c0b7246d769 510 break;
Issus 2:2c0b7246d769 511 case LSR_MODULE_HOST_DATA_RATE_19200:
Issus 2:2c0b7246d769 512 baud(19200);
Issus 2:2c0b7246d769 513 break;
Issus 2:2c0b7246d769 514 case LSR_MODULE_HOST_DATA_RATE_38400:
Issus 2:2c0b7246d769 515 baud(38400);
Issus 2:2c0b7246d769 516 break;
Issus 2:2c0b7246d769 517 case LSR_MODULE_HOST_DATA_RATE_57600:
Issus 2:2c0b7246d769 518 baud(57600);
Issus 2:2c0b7246d769 519 break;
Issus 2:2c0b7246d769 520 case LSR_MODULE_HOST_DATA_RATE_115200:
Issus 2:2c0b7246d769 521 baud(115200);
Issus 2:2c0b7246d769 522 break;
Issus 2:2c0b7246d769 523 case LSR_MODULE_HOST_DATA_RATE_230400:
Issus 2:2c0b7246d769 524 baud(230400);
Issus 2:2c0b7246d769 525 break;
Issus 2:2c0b7246d769 526 case LSR_MODULE_HOST_DATA_RATE_460800:
Issus 2:2c0b7246d769 527 baud(460800);
Issus 2:2c0b7246d769 528 break;
Issus 2:2c0b7246d769 529 case LSR_MODULE_HOST_DATA_RATE_921600:
Issus 2:2c0b7246d769 530 baud(921600);
Issus 2:2c0b7246d769 531 break;
Issus 2:2c0b7246d769 532 }
Issus 0:f9cf4a19bb84 533 }
Issus 0:f9cf4a19bb84 534 } /*** End SetHostDataRateMsg ***/
Issus 0:f9cf4a19bb84 535
Issus 0:f9cf4a19bb84 536
Issus 0:f9cf4a19bb84 537 /**
Issus 4:2ac0b9a7f43a 538 * Sends message type 0x19 (Set RF Data Rate) to the module via UART communication. This will spark an ACK message
Issus 4:2ac0b9a7f43a 539 * from the module to the Arduino of type 0x98. Subscribing to 0x98 in your main application will allow you to parse
Issus 4:2ac0b9a7f43a 540 * the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 4:2ac0b9a7f43a 541 *
Issus 4:2ac0b9a7f43a 542 */
Issus 4:2ac0b9a7f43a 543 void LsrModule::SetRfDataRateMsg(uint8_t u8RfDataRate ///< Data rate for module to use when communicating via radio:
Issus 4:2ac0b9a7f43a 544 ///< 0 = 1,200 bits/s
Issus 4:2ac0b9a7f43a 545 ///< 1 = 2,400 bits/s
Issus 4:2ac0b9a7f43a 546 ///< 2 = 4,800 bits/s
Issus 4:2ac0b9a7f43a 547 ///< 3 = 9,600 bits/s
Issus 4:2ac0b9a7f43a 548 ///< 4 = 19,200 bits/s
Issus 4:2ac0b9a7f43a 549 ///< 5 = 38,400 bits/s
Issus 4:2ac0b9a7f43a 550 ///< 6 = 57,600 bits/s
Issus 4:2ac0b9a7f43a 551 ///< 7 = 115,200 bits/s
Issus 4:2ac0b9a7f43a 552 )
Issus 4:2ac0b9a7f43a 553 {
Issus 4:2ac0b9a7f43a 554 if (u8RfDataRate <= LSR_MODULE_RF_DATA_RATE_MAX)
Issus 4:2ac0b9a7f43a 555 {
Issus 4:2ac0b9a7f43a 556 AddSerialMsgHeader(LSR_MODULE_SET_RF_DATA_RATE_MSG_TYPE, 6);
Issus 4:2ac0b9a7f43a 557 AddSerialByteToMsgBuffer(u8RfDataRate);
Issus 4:2ac0b9a7f43a 558 AddSerialMsgTrailer();
Issus 4:2ac0b9a7f43a 559 }
Issus 4:2ac0b9a7f43a 560 } /*** End SetRfDataRateMsg ***/
Issus 4:2ac0b9a7f43a 561
Issus 4:2ac0b9a7f43a 562 /**
Issus 0:f9cf4a19bb84 563 * Sends message type 0x20 (Send Simple Short Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 564 * This will spark an ACK message from the module to the Arduino of type 0xA0. Subscribing to 0xA0 in
Issus 0:f9cf4a19bb84 565 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 566 * for more information.
Issus 0:f9cf4a19bb84 567 *
Issus 0:f9cf4a19bb84 568 * Example:
Issus 0:f9cf4a19bb84 569 *
Issus 0:f9cf4a19bb84 570 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 571 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 572 *
Issus 0:f9cf4a19bb84 573 * SendSimpleShortAddrRfDataPacketMsg(&u8Data, sizeof(u8Data, 213, 0, packetID++);
Issus 0:f9cf4a19bb84 574 *
Issus 0:f9cf4a19bb84 575 */
Issus 0:f9cf4a19bb84 576 void LsrModule::SendSimpleShortAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 577 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 578 , uint16_t u16DestAddress ///< 2 byte destination address.
Issus 0:f9cf4a19bb84 579 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 580 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 581 )
Issus 0:f9cf4a19bb84 582 {
Issus 0:f9cf4a19bb84 583 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 584 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_SIMPLE_SHORT_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 585 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_SIMPLE_SHORT_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 586 {
Issus 0:f9cf4a19bb84 587 AddSerialMsgHeader(LSR_MODULE_SEND_SIMPLE_SHORT_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 9));
Issus 0:f9cf4a19bb84 588
Issus 0:f9cf4a19bb84 589 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 590 AddSerialByteToMsgBuffer(u16DestAddress % 256);
Issus 0:f9cf4a19bb84 591 AddSerialByteToMsgBuffer(u16DestAddress >> 8);
Issus 0:f9cf4a19bb84 592 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 593
Issus 0:f9cf4a19bb84 594 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 595 {
Issus 0:f9cf4a19bb84 596 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 597 pu8Data++;
Issus 0:f9cf4a19bb84 598 u8DataLength--;
Issus 0:f9cf4a19bb84 599 }
Issus 0:f9cf4a19bb84 600
Issus 0:f9cf4a19bb84 601 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 602 }
Issus 0:f9cf4a19bb84 603 } /*** End SendSimpleShortAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 604
Issus 0:f9cf4a19bb84 605
Issus 0:f9cf4a19bb84 606 /**
Issus 0:f9cf4a19bb84 607 * Sends message type 0x22 (Send Advanced Short Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 608 * This will spark an ACK message from the module to the Arduino of type 0xA2. Subscribing to 0xA2 in
Issus 0:f9cf4a19bb84 609 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 610 * for more information.
Issus 0:f9cf4a19bb84 611 *
Issus 0:f9cf4a19bb84 612 * Example:
Issus 0:f9cf4a19bb84 613 *
Issus 0:f9cf4a19bb84 614 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 615 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 616 *
Issus 0:f9cf4a19bb84 617 * SendAdvancedShortAddrRfDataPacketMsg(&u8Data, sizeof(u8Data, 1111, 213, 0, packetID++);
Issus 0:f9cf4a19bb84 618 *
Issus 0:f9cf4a19bb84 619 */
Issus 0:f9cf4a19bb84 620 void LsrModule::SendAdvancedShortAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 621 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 622 , uint16_t u16DestPanId ///< 2 byte Personal Area Network (PAN) ID.
Issus 0:f9cf4a19bb84 623 , uint16_t u16DestAddress ///< 2 byte destination address.
Issus 0:f9cf4a19bb84 624 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 625 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 626 )
Issus 0:f9cf4a19bb84 627 {
Issus 0:f9cf4a19bb84 628 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 629 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_ADVANCED_SHORT_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 630 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_ADVANCED_SHORT_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 631 {
Issus 0:f9cf4a19bb84 632 AddSerialMsgHeader(LSR_MODULE_SEND_ADVANCED_SHORT_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 11));
Issus 0:f9cf4a19bb84 633
Issus 0:f9cf4a19bb84 634 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 635 AddSerialByteToMsgBuffer(u16DestPanId % 256);
Issus 0:f9cf4a19bb84 636 AddSerialByteToMsgBuffer(u16DestPanId >> 8);
Issus 0:f9cf4a19bb84 637 AddSerialByteToMsgBuffer(u16DestAddress % 256);
Issus 0:f9cf4a19bb84 638 AddSerialByteToMsgBuffer(u16DestAddress >> 8);
Issus 0:f9cf4a19bb84 639 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 640
Issus 0:f9cf4a19bb84 641 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 642 {
Issus 0:f9cf4a19bb84 643 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 644 pu8Data++;
Issus 0:f9cf4a19bb84 645 u8DataLength--;
Issus 0:f9cf4a19bb84 646 }
Issus 0:f9cf4a19bb84 647
Issus 0:f9cf4a19bb84 648 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 649 }
Issus 0:f9cf4a19bb84 650 } /*** End SendAdvancedShortAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 651
Issus 0:f9cf4a19bb84 652
Issus 0:f9cf4a19bb84 653 /**
Issus 0:f9cf4a19bb84 654 * Sends message type 0x24 (Send Simple Long Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 655 * This will spark an ACK message from the module to the Arduino of type 0xA4. Subscribing to 0xA4 in
Issus 0:f9cf4a19bb84 656 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 657 * for more information.
Issus 0:f9cf4a19bb84 658 *
Issus 0:f9cf4a19bb84 659 * Example:
Issus 0:f9cf4a19bb84 660 *
Issus 0:f9cf4a19bb84 661 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 662 * uint8_t u8DestAddress[8] = {2, 3, 6, 5, 2, 3, 6, 5};
Issus 0:f9cf4a19bb84 663 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 664 *
Issus 0:f9cf4a19bb84 665 * SendSimpleLongAddrRfDataPacketMsg(&u8Data, sizeof(u8Data), &u8DestAddress, 0, packetID++);
Issus 0:f9cf4a19bb84 666 *
Issus 0:f9cf4a19bb84 667 */
Issus 0:f9cf4a19bb84 668 void LsrModule::SendSimpleLongAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 669 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 670 , uint8_t* pu8DestAddress ///< Pointer to 8 byte destination address.
Issus 0:f9cf4a19bb84 671 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 672 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 673 )
Issus 0:f9cf4a19bb84 674 {
Issus 0:f9cf4a19bb84 675 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 676 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_SIMPLE_LONG_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 677 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_SIMPLE_LONG_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 678 {
Issus 0:f9cf4a19bb84 679 AddSerialMsgHeader(LSR_MODULE_SEND_SIMPLE_LONG_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 15));
Issus 0:f9cf4a19bb84 680
Issus 0:f9cf4a19bb84 681 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 682
Issus 0:f9cf4a19bb84 683 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 684 {
Issus 0:f9cf4a19bb84 685 AddSerialByteToMsgBuffer(*pu8DestAddress);
Issus 0:f9cf4a19bb84 686 pu8DestAddress++;
Issus 0:f9cf4a19bb84 687 }
Issus 0:f9cf4a19bb84 688
Issus 0:f9cf4a19bb84 689 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 690
Issus 0:f9cf4a19bb84 691 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 692 {
Issus 0:f9cf4a19bb84 693 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 694 pu8Data++;
Issus 0:f9cf4a19bb84 695 u8DataLength--;
Issus 0:f9cf4a19bb84 696 }
Issus 0:f9cf4a19bb84 697
Issus 0:f9cf4a19bb84 698 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 699 }
Issus 0:f9cf4a19bb84 700 } /*** End SendSimpleLongAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 701
Issus 0:f9cf4a19bb84 702
Issus 0:f9cf4a19bb84 703 /**
Issus 0:f9cf4a19bb84 704 * Sends message type 0x26 (Send Advanced Long Address RF Data Packet) to the module via UART communication.
Issus 0:f9cf4a19bb84 705 * This will spark an ACK message from the module to the Arduino of type 0xA6. Subscribing to 0xA6 in
Issus 0:f9cf4a19bb84 706 * your main application will allow you to parse the response data. See the description for SubscribeRxMsgCallback
Issus 0:f9cf4a19bb84 707 * for more information.
Issus 0:f9cf4a19bb84 708 *
Issus 0:f9cf4a19bb84 709 * Example:
Issus 0:f9cf4a19bb84 710 *
Issus 0:f9cf4a19bb84 711 * uint8_t u8Data[5] = {4, 7, 3, 5, 8};
Issus 0:f9cf4a19bb84 712 * uint8_t u8DestAddress[8] = {2, 3, 6, 5, 2, 3, 6, 5};
Issus 0:f9cf4a19bb84 713 * uint8_t u8PacketID;
Issus 0:f9cf4a19bb84 714 *
Issus 0:f9cf4a19bb84 715 * SendAdvancedLongAddrRfDataPacketMsg(&u8Data, sizeof(u8Data), 1111, &u8DestAddress, 0, packetID++);
Issus 0:f9cf4a19bb84 716 *
Issus 0:f9cf4a19bb84 717 */
Issus 0:f9cf4a19bb84 718 void LsrModule::SendAdvancedLongAddrRfDataPacketMsg(uint8_t* pu8Data ///< Pointer to data being sent.
Issus 0:f9cf4a19bb84 719 , uint8_t u8DataLength ///< Length of data being sent.
Issus 0:f9cf4a19bb84 720 , uint16_t u16DestPanId ///< 2 byte Personal Area Network (PAN) ID.
Issus 0:f9cf4a19bb84 721 , uint8_t* pu8DestAddress ///< Pointer to 8 byte destination address.
Issus 0:f9cf4a19bb84 722 , uint8_t u8TxOptions ///< 1 byte bit mask of transmit options.
Issus 0:f9cf4a19bb84 723 , uint8_t u8PacketId ///< ID assigned to packet.
Issus 0:f9cf4a19bb84 724 )
Issus 0:f9cf4a19bb84 725 {
Issus 0:f9cf4a19bb84 726 if ((u8TxOptions <= LSR_MODULE_TX_OPTIONS_MAX) &&
Issus 0:f9cf4a19bb84 727 ((((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) != 0) && (u8DataLength <= (LSR_MODULE_ADVANCED_LONG_RF_DATA_LENGTH - LSR_MODULE_SECURITY_OVERHEAD))) ||
Issus 0:f9cf4a19bb84 728 (((u8TxOptions & LSR_MODULE_TX_OPTIONS_USE_SECURITY_BITMASK) == 0) && (u8DataLength <= LSR_MODULE_ADVANCED_LONG_RF_DATA_LENGTH))))
Issus 0:f9cf4a19bb84 729 {
Issus 0:f9cf4a19bb84 730 AddSerialMsgHeader(LSR_MODULE_SEND_ADVANCED_LONG_RF_DATA_PACKET_MSG_TYPE, (u8DataLength + 17));
Issus 0:f9cf4a19bb84 731
Issus 0:f9cf4a19bb84 732 AddSerialByteToMsgBuffer(u8TxOptions);
Issus 0:f9cf4a19bb84 733 AddSerialByteToMsgBuffer(u16DestPanId % 256);
Issus 0:f9cf4a19bb84 734 AddSerialByteToMsgBuffer(u16DestPanId >> 8);
Issus 0:f9cf4a19bb84 735
Issus 0:f9cf4a19bb84 736 for (u8ForLoopCounter = 0; u8ForLoopCounter < 8; u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 737 {
Issus 0:f9cf4a19bb84 738 AddSerialByteToMsgBuffer(*pu8DestAddress);
Issus 0:f9cf4a19bb84 739 pu8DestAddress++;
Issus 0:f9cf4a19bb84 740 }
Issus 0:f9cf4a19bb84 741
Issus 0:f9cf4a19bb84 742 AddSerialByteToMsgBuffer(u8PacketId);
Issus 0:f9cf4a19bb84 743
Issus 0:f9cf4a19bb84 744 while (u8DataLength != 0)
Issus 0:f9cf4a19bb84 745 {
Issus 0:f9cf4a19bb84 746 AddSerialByteToMsgBuffer(*pu8Data);
Issus 0:f9cf4a19bb84 747 pu8Data++;
Issus 0:f9cf4a19bb84 748 u8DataLength--;
Issus 0:f9cf4a19bb84 749 }
Issus 0:f9cf4a19bb84 750
Issus 0:f9cf4a19bb84 751 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 752 }
Issus 0:f9cf4a19bb84 753 } /*** End SendAdvancedLongAddrRfDataPacketMsg ***/
Issus 0:f9cf4a19bb84 754
Issus 0:f9cf4a19bb84 755
Issus 0:f9cf4a19bb84 756 /**
Issus 0:f9cf4a19bb84 757 * 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 758 * to the host of type 0xC5. Subscribing to 0xC5 in your main application will allow you to parse the response
Issus 0:f9cf4a19bb84 759 * data. See the description for SubscribeRxMsgCallback for more information.
Issus 0:f9cf4a19bb84 760 *
Issus 0:f9cf4a19bb84 761 * Example (Channel 5 for SiFLEX02, Channel 15 for ProFLEX01):
Issus 0:f9cf4a19bb84 762 *
Issus 0:f9cf4a19bb84 763 * ChannelEnergyScanMsg(11110111, 7);
Issus 0:f9cf4a19bb84 764 *
Issus 0:f9cf4a19bb84 765 */
Issus 0:f9cf4a19bb84 766 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 767 , uint8_t u8ScanDuration ///< Duration to scan for:
Issus 0:f9cf4a19bb84 768 ///< 0 = 61.4 mSec
Issus 0:f9cf4a19bb84 769 ///< 1 = 92.2 mSec
Issus 0:f9cf4a19bb84 770 ///< 2 = 154 mSec
Issus 0:f9cf4a19bb84 771 ///< 3 = 276 mSec
Issus 0:f9cf4a19bb84 772 ///< 4 = 522 mSec
Issus 0:f9cf4a19bb84 773 ///< 5 = 1.01 Sec
Issus 0:f9cf4a19bb84 774 ///< 6 = 2.00 Sec
Issus 0:f9cf4a19bb84 775 ///< 7 = 3.96 Sec
Issus 0:f9cf4a19bb84 776 ///< 8 = 7.90 Sec
Issus 0:f9cf4a19bb84 777 ///< 9 = 15.8 Sec
Issus 0:f9cf4a19bb84 778 ///< 10 = 31.5 Sec
Issus 0:f9cf4a19bb84 779 ///< 11 = 62.9 Sec
Issus 0:f9cf4a19bb84 780 ///< 12 = 126 Sec
Issus 0:f9cf4a19bb84 781 ///< 13 = 252 Sec
Issus 0:f9cf4a19bb84 782 ///< 14 = 503 Sec
Issus 0:f9cf4a19bb84 783
Issus 0:f9cf4a19bb84 784 )
Issus 0:f9cf4a19bb84 785 {
Issus 0:f9cf4a19bb84 786 Wordu_t wuChannelMask;
Issus 0:f9cf4a19bb84 787
Issus 0:f9cf4a19bb84 788 wuChannelMask.u16 = u16ChannelMask;
Issus 0:f9cf4a19bb84 789
Issus 0:f9cf4a19bb84 790 if (u8ScanDuration <= LSR_MODULE_SCAN_DURATION_MAX)
Issus 0:f9cf4a19bb84 791 {
Issus 0:f9cf4a19bb84 792 AddSerialMsgHeader(LSR_MODULE_CHANNEL_ENERGY_SCAN_MSG_TYPE, 8);
Issus 0:f9cf4a19bb84 793 AddSerialByteToMsgBuffer(wuChannelMask.ws.lb);
Issus 0:f9cf4a19bb84 794 AddSerialByteToMsgBuffer(wuChannelMask.ws.hb);
Issus 0:f9cf4a19bb84 795 AddSerialByteToMsgBuffer(u8ScanDuration);
Issus 0:f9cf4a19bb84 796 AddSerialMsgTrailer();
Issus 0:f9cf4a19bb84 797 }
Issus 0:f9cf4a19bb84 798 } /*** End ChannelEnergyScanMsg ***/
Issus 0:f9cf4a19bb84 799
Issus 6:b0445108f82f 800 /**
Issus 6:b0445108f82f 801 * Sends message type 0x51 (Query Host Interface Configuration) to the module via UART communication. This will spark a
Issus 6:b0445108f82f 802 * response message from the module to the host of type 0xD1. Subscribing to 0xD1 in your main application
Issus 6:b0445108f82f 803 * will allow you to parse the response data. See the description for SubscribeRxMsgCallback for more information.
Issus 6:b0445108f82f 804 *
Issus 6:b0445108f82f 805 */
Issus 6:b0445108f82f 806 void LsrModule::QueryHostInterfaceConfiguration(void)
Issus 6:b0445108f82f 807 {
Issus 6:b0445108f82f 808 AddSerialMsgHeader(LSR_MODULE_QUERY_HOST_INTERFACE_CONFIGURATION, 5);
Issus 6:b0445108f82f 809 AddSerialMsgTrailer();
Issus 6:b0445108f82f 810 } /*** End QuerySupplyVoltageMsg ***/
Issus 6:b0445108f82f 811
Issus 6:b0445108f82f 812
Issus 0:f9cf4a19bb84 813
Issus 0:f9cf4a19bb84 814 /**
Issus 0:f9cf4a19bb84 815 * Verifies msg type and length.
Issus 0:f9cf4a19bb84 816 * @return True: Valid msg length and type. False: Invalid msg length or type.
Issus 0:f9cf4a19bb84 817 *
Issus 0:f9cf4a19bb84 818 */
Issus 0:f9cf4a19bb84 819 bool LsrModule::ValidMsgLengthAndType(uint8_t u8MsgType ///< Received UART message type.
Issus 0:f9cf4a19bb84 820 , uint8_t u8MsgLength ///< Received UART message length.
Issus 0:f9cf4a19bb84 821 )
Issus 0:f9cf4a19bb84 822 {
Issus 0:f9cf4a19bb84 823 if ((u8MsgLength >= cau8RxMsgLengthAndTypeTable[u8MsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE][0]) &&
Issus 0:f9cf4a19bb84 824 (u8MsgLength <= cau8RxMsgLengthAndTypeTable[u8MsgType - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE][1]))
Issus 0:f9cf4a19bb84 825 {
Issus 0:f9cf4a19bb84 826 return true;
Issus 0:f9cf4a19bb84 827 }
Issus 0:f9cf4a19bb84 828 return false;
Issus 0:f9cf4a19bb84 829 } /*** End ValidMsgLengthAndType ***/
Issus 0:f9cf4a19bb84 830
Issus 0:f9cf4a19bb84 831
Issus 0:f9cf4a19bb84 832 /**
Issus 0:f9cf4a19bb84 833 * Verifies message checksum.
Issus 0:f9cf4a19bb84 834 * @return True: Valid checksum. False: Invalid checksum.
Issus 0:f9cf4a19bb84 835 *
Issus 0:f9cf4a19bb84 836 */
Issus 0:f9cf4a19bb84 837 bool LsrModule::ValidRxChecksum(uint8_t* pu8MsgBuffer ///< Pointer to received UART buffer.
Issus 0:f9cf4a19bb84 838 , uint8_t u8MsgLength ///< Received UART message length.
Issus 0:f9cf4a19bb84 839 )
Issus 0:f9cf4a19bb84 840 {
Issus 0:f9cf4a19bb84 841 uint8_t u8Checksum = 0;
Issus 0:f9cf4a19bb84 842
Issus 0:f9cf4a19bb84 843 for (u8ForLoopCounter = 0; u8ForLoopCounter < (u8MsgLength - 2); u8ForLoopCounter++)
Issus 0:f9cf4a19bb84 844 {
Issus 0:f9cf4a19bb84 845 u8Checksum += au8UartRxBuffer[u8ForLoopCounter];
Issus 0:f9cf4a19bb84 846 }
Issus 0:f9cf4a19bb84 847
Issus 0:f9cf4a19bb84 848 if (au8UartRxBuffer[u8MsgLength-2] == u8Checksum)
Issus 0:f9cf4a19bb84 849 {
Issus 0:f9cf4a19bb84 850 return true;
Issus 0:f9cf4a19bb84 851 }
Issus 0:f9cf4a19bb84 852
Issus 0:f9cf4a19bb84 853 return false;
Issus 0:f9cf4a19bb84 854 } /*** End ValidRxChecksum ***/
Issus 0:f9cf4a19bb84 855
Issus 0:f9cf4a19bb84 856
Issus 0:f9cf4a19bb84 857 /**
Issus 0:f9cf4a19bb84 858 * Calls appropriate callback function for received message.
Issus 0:f9cf4a19bb84 859 *
Issus 0:f9cf4a19bb84 860 */
Issus 0:f9cf4a19bb84 861 void LsrModule::HostProcessCallbackMsgStart(uint8_t* pu8MsgBuffer ///< Pointer to received message.
Issus 0:f9cf4a19bb84 862 , uint8_t u8Length ///< Length of received message.
Issus 0:f9cf4a19bb84 863 )
Issus 0:f9cf4a19bb84 864 {
Issus 0:f9cf4a19bb84 865 if ((ptrRxMsgCallbackTable[(*(pu8MsgBuffer + LSR_MODULE_MSG_TYPE_BYTE_INDEX)) - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE]) != NULL)
Issus 0:f9cf4a19bb84 866 {
Issus 0:f9cf4a19bb84 867 ptrRxMsgCallbackTable[(*(pu8MsgBuffer + LSR_MODULE_MSG_TYPE_BYTE_INDEX)) - LSR_MODULE_MIN_SERIAL_RX_MSG_TYPE]();
Issus 0:f9cf4a19bb84 868 }
Issus 0:f9cf4a19bb84 869 } /*** End HostProcessCallbackMsgStart ***/
Issus 0:f9cf4a19bb84 870
Issus 0:f9cf4a19bb84 871
Issus 0:f9cf4a19bb84 872 /**
Issus 0:f9cf4a19bb84 873 * Determines if appropriate serial port is available.
Issus 0:f9cf4a19bb84 874 * @return True: Serial is available. False: Serial is unavailable.
Issus 0:f9cf4a19bb84 875 *
Issus 0:f9cf4a19bb84 876 */
Issus 0:f9cf4a19bb84 877 bool LsrModule::SerialAvailable(void)
Issus 0:f9cf4a19bb84 878 {
Issus 0:f9cf4a19bb84 879 if (readable())
Issus 0:f9cf4a19bb84 880 {
Issus 0:f9cf4a19bb84 881 return true;
Issus 0:f9cf4a19bb84 882 }
Issus 0:f9cf4a19bb84 883
Issus 0:f9cf4a19bb84 884 return false;
Issus 0:f9cf4a19bb84 885 } /*** End SerialAvailable ***/
Issus 0:f9cf4a19bb84 886
Issus 0:f9cf4a19bb84 887
Issus 0:f9cf4a19bb84 888 /**
Issus 0:f9cf4a19bb84 889 * Reads appropriate serial port.
Issus 0:f9cf4a19bb84 890 * @return Byte read.
Issus 0:f9cf4a19bb84 891 *
Issus 0:f9cf4a19bb84 892 */
Issus 0:f9cf4a19bb84 893 uint8_t LsrModule::SerialRead(void)
Issus 0:f9cf4a19bb84 894 {
Issus 0:f9cf4a19bb84 895 return getc();
Issus 0:f9cf4a19bb84 896
Issus 0:f9cf4a19bb84 897 } /*** End SerialRead ***/
Issus 0:f9cf4a19bb84 898
Issus 0:f9cf4a19bb84 899
Issus 0:f9cf4a19bb84 900 /**
Issus 0:f9cf4a19bb84 901 * Refreshes and restarts Rx state machine.
Issus 0:f9cf4a19bb84 902 *
Issus 0:f9cf4a19bb84 903 */
Issus 0:f9cf4a19bb84 904 void LsrModule::SerialRxCleanupRestart(void)
Issus 0:f9cf4a19bb84 905 {
Issus 0:f9cf4a19bb84 906 SerialFlush();
Issus 0:f9cf4a19bb84 907 u8UartRxBufferIndex = LSR_MODULE_MSG_START_BYTE_INDEX;
Issus 0:f9cf4a19bb84 908 ptrHostState = &LsrModule::HostRxWaitForMsgStartByteState;
Issus 0:f9cf4a19bb84 909 } /*** End SerialRxCleanupRestart ***/
Issus 0:f9cf4a19bb84 910
Issus 0:f9cf4a19bb84 911
Issus 0:f9cf4a19bb84 912 /**
Issus 0:f9cf4a19bb84 913 * Waits for data packet start byte.
Issus 0:f9cf4a19bb84 914 *
Issus 0:f9cf4a19bb84 915 */
Issus 0:f9cf4a19bb84 916 void LsrModule::HostRxWaitForMsgStartByteState(void)
Issus 0:f9cf4a19bb84 917 {
Issus 9:98edda6ea79e 918 while (readable() && (SerialRead() == LSR_MODULE_SERIAL_MSG_START_BYTE))
Issus 0:f9cf4a19bb84 919 {
Issus 0:f9cf4a19bb84 920 au8UartRxBuffer[u8UartRxBufferIndex++] = LSR_MODULE_SERIAL_MSG_START_BYTE;
Issus 0:f9cf4a19bb84 921 ptrHostState = &LsrModule::HostRxGetMsgLengthState;
Issus 0:f9cf4a19bb84 922 }
Issus 0:f9cf4a19bb84 923 } /*** End HostRxWaitForMsgStartByteState ***/
Issus 0:f9cf4a19bb84 924
Issus 0:f9cf4a19bb84 925
Issus 0:f9cf4a19bb84 926 /**
Issus 0:f9cf4a19bb84 927 * Gets data packet length byte.
Issus 0:f9cf4a19bb84 928 *
Issus 0:f9cf4a19bb84 929 */
Issus 0:f9cf4a19bb84 930 void LsrModule::HostRxGetMsgLengthState(void)
Issus 0:f9cf4a19bb84 931 {
Issus 9:98edda6ea79e 932 while (readable())
Issus 0:f9cf4a19bb84 933 {
Issus 0:f9cf4a19bb84 934 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 935
Issus 0:f9cf4a19bb84 936 if ((u8RxReadByte >= LSR_MODULE_MIN_SERIAL_RX_MSG_LENGTH) &&
Issus 0:f9cf4a19bb84 937 (u8RxReadByte <= LSR_MODULE_MAX_SERIAL_RX_MSG_LENGTH))
Issus 0:f9cf4a19bb84 938 {
Issus 0:f9cf4a19bb84 939 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 940 ptrHostState = &LsrModule::HostRxGetMsgTypeState;
Issus 0:f9cf4a19bb84 941 }
Issus 0:f9cf4a19bb84 942 else
Issus 0:f9cf4a19bb84 943 {
Issus 0:f9cf4a19bb84 944 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 945 }
Issus 0:f9cf4a19bb84 946 }
Issus 0:f9cf4a19bb84 947 } /*** End HostRxGetMsgLengthState ***/
Issus 0:f9cf4a19bb84 948
Issus 0:f9cf4a19bb84 949
Issus 0:f9cf4a19bb84 950 /**
Issus 0:f9cf4a19bb84 951 * Gets data packet type byte.
Issus 0:f9cf4a19bb84 952 *
Issus 0:f9cf4a19bb84 953 */
Issus 0:f9cf4a19bb84 954 void LsrModule::HostRxGetMsgTypeState(void)
Issus 0:f9cf4a19bb84 955 {
Issus 9:98edda6ea79e 956 while (readable())
Issus 0:f9cf4a19bb84 957 {
Issus 0:f9cf4a19bb84 958
Issus 0:f9cf4a19bb84 959 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 960
Issus 0:f9cf4a19bb84 961 if (ValidMsgLengthAndType(u8RxReadByte, au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]))
Issus 0:f9cf4a19bb84 962 {
Issus 0:f9cf4a19bb84 963 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 964 ptrHostState = &LsrModule::HostRxWaitToGetRestOfMsgState;
Issus 0:f9cf4a19bb84 965 }
Issus 0:f9cf4a19bb84 966 else
Issus 0:f9cf4a19bb84 967 {
Issus 0:f9cf4a19bb84 968 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 969 }
Issus 0:f9cf4a19bb84 970 }
Issus 0:f9cf4a19bb84 971 } /*** End HostRxGetMsgTypeState ***/
Issus 0:f9cf4a19bb84 972
Issus 0:f9cf4a19bb84 973
Issus 0:f9cf4a19bb84 974 /**
Issus 0:f9cf4a19bb84 975 * Grabs rest of data packet bytes.
Issus 0:f9cf4a19bb84 976 *
Issus 0:f9cf4a19bb84 977 */
Issus 0:f9cf4a19bb84 978 void LsrModule::HostRxWaitToGetRestOfMsgState(void)
Issus 0:f9cf4a19bb84 979 {
Issus 9:98edda6ea79e 980 while (readable())
Issus 0:f9cf4a19bb84 981 {
Issus 0:f9cf4a19bb84 982 u8RxReadByte = SerialRead();
Issus 0:f9cf4a19bb84 983 au8UartRxBuffer[u8UartRxBufferIndex++] = u8RxReadByte;
Issus 0:f9cf4a19bb84 984
Issus 0:f9cf4a19bb84 985 if (u8UartRxBufferIndex > LSR_MODULE_MAX_SERIAL_RX_MSG_LENGTH)
Issus 0:f9cf4a19bb84 986 {
Issus 0:f9cf4a19bb84 987 ptrHostState = &LsrModule::SerialRxCleanupRestart;
Issus 0:f9cf4a19bb84 988 }
Issus 0:f9cf4a19bb84 989 else if ((u8RxReadByte == LSR_MODULE_SERIAL_MSG_END_BYTE) && (u8UartRxBufferIndex == au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX]))
Issus 0:f9cf4a19bb84 990 {
Issus 0:f9cf4a19bb84 991 ptrHostState = &LsrModule::HostRxValidateMsgState;
Issus 0:f9cf4a19bb84 992 }
Issus 0:f9cf4a19bb84 993 }
Issus 0:f9cf4a19bb84 994 } /*** End HostRxWaitToGetRestOfMsgState ***/
Issus 0:f9cf4a19bb84 995
Issus 0:f9cf4a19bb84 996
Issus 0:f9cf4a19bb84 997 /**
Issus 0:f9cf4a19bb84 998 * Validates received message.
Issus 0:f9cf4a19bb84 999 *
Issus 0:f9cf4a19bb84 1000 */
Issus 0:f9cf4a19bb84 1001 void LsrModule::HostRxValidateMsgState(void)
Issus 0:f9cf4a19bb84 1002 {
Issus 0:f9cf4a19bb84 1003
Issus 0:f9cf4a19bb84 1004 if (ValidRxChecksum(au8UartRxBuffer, au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX])) // Is checksum good?
Issus 0:f9cf4a19bb84 1005 {
Issus 0:f9cf4a19bb84 1006 ptrHostState = &LsrModule::HostRxGoodMsgState; // Good checksum - next state
Issus 0:f9cf4a19bb84 1007 }
Issus 0:f9cf4a19bb84 1008 else
Issus 0:f9cf4a19bb84 1009 {
Issus 0:f9cf4a19bb84 1010 ptrHostState = &LsrModule::SerialRxCleanupRestart; // Bad checksum - restart
Issus 0:f9cf4a19bb84 1011 }
Issus 0:f9cf4a19bb84 1012 } /*** End HostRxValidateMsgState ***/
Issus 0:f9cf4a19bb84 1013
Issus 0:f9cf4a19bb84 1014
Issus 0:f9cf4a19bb84 1015 /**
Issus 0:f9cf4a19bb84 1016 * Calls appropriate received UART message callback and starts state machine over.
Issus 0:f9cf4a19bb84 1017 *
Issus 0:f9cf4a19bb84 1018 */
Issus 0:f9cf4a19bb84 1019 void LsrModule::HostRxGoodMsgState(void)
Issus 0:f9cf4a19bb84 1020 {
Issus 0:f9cf4a19bb84 1021 pu8RxBuffer = au8UartRxBuffer;
Issus 0:f9cf4a19bb84 1022 u8RxMsgLength = au8UartRxBuffer[LSR_MODULE_MSG_LENGTH_BYTE_INDEX];
Issus 0:f9cf4a19bb84 1023 HostProcessCallbackMsgStart(au8UartRxBuffer, u8RxMsgLength);
Issus 0:f9cf4a19bb84 1024 ptrHostState = &LsrModule::SerialRxCleanupRestart; // Start new RX sequence
Issus 0:f9cf4a19bb84 1025 } /*** End HostRxGoodMsgState ***/