Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Committer:
Matt Briggs
Date:
Thu Jan 26 17:36:59 2017 -0700
Revision:
40:2ec4be320961
Child:
41:9ef4c4d77711
Fixed include hell.  Refactored to group all header in same location

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Matt Briggs 40:2ec4be320961 1 /**
Matt Briggs 40:2ec4be320961 2 * Library for LoRa Peer to Peer Brute Force Protocol
Matt Briggs 40:2ec4be320961 3 */
Matt Briggs 40:2ec4be320961 4
Matt Briggs 40:2ec4be320961 5 #ifndef PEERBRUTECOMMPROTOCOL_H_
Matt Briggs 40:2ec4be320961 6 #define PEERBRUTECOMMPROTOCOL_H_
Matt Briggs 40:2ec4be320961 7
Matt Briggs 40:2ec4be320961 8 #include "../config.h"
Matt Briggs 40:2ec4be320961 9
Matt Briggs 40:2ec4be320961 10 // TODO make base class to allow different protocols to be used with easy
Matt Briggs 40:2ec4be320961 11 static uint8_t pair_network_address[] = { 0x01, 0x02, 0x03, 0x04 };
Matt Briggs 40:2ec4be320961 12 static uint8_t pair_network_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 };
Matt Briggs 40:2ec4be320961 13 static uint8_t pair_data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 };
Matt Briggs 40:2ec4be320961 14
Matt Briggs 40:2ec4be320961 15 /**
Matt Briggs 40:2ec4be320961 16 * @class PeerBruteCommProtocol
Matt Briggs 40:2ec4be320961 17 * @brief This class implements a peer brute force protocol. The protocol
Matt Briggs 40:2ec4be320961 18 * consists of at a minimum one transmitter (TX) and one receiver (RX) which
Matt Briggs 40:2ec4be320961 19 * communicate via the 900MHz LoRa modulation. The concept is that the RX is
Matt Briggs 40:2ec4be320961 20 * cycling on and off thus only listening for a small period of time. Since
Matt Briggs 40:2ec4be320961 21 * we are not relying on a common time-base or other synchronization mechanism
Matt Briggs 40:2ec4be320961 22 * the TX simply transmits for a duration long enough guarantee that the RX will
Matt Briggs 40:2ec4be320961 23 * have at least one receive window during that time period. Hence the name
Matt Briggs 40:2ec4be320961 24 * brute since the TX is just transmitting plenty for the RX to hear it.
Matt Briggs 40:2ec4be320961 25 */
Matt Briggs 40:2ec4be320961 26 class PeerBruteCommProtocol
Matt Briggs 40:2ec4be320961 27 {
Matt Briggs 40:2ec4be320961 28 public:
Matt Briggs 40:2ec4be320961 29 PeerBruteCommProtocol(bool isTx);
Matt Briggs 40:2ec4be320961 30 void init();
Matt Briggs 40:2ec4be320961 31
Matt Briggs 40:2ec4be320961 32 bool isTx();
Matt Briggs 40:2ec4be320961 33 bool isRx() {return !isTx();}
Matt Briggs 40:2ec4be320961 34
Matt Briggs 40:2ec4be320961 35 uint32_t getDLC();
Matt Briggs 40:2ec4be320961 36 uint32_t getULC();
Matt Briggs 40:2ec4be320961 37
Matt Briggs 40:2ec4be320961 38 CmdResult clearPair();
Matt Briggs 40:2ec4be320961 39
Matt Briggs 40:2ec4be320961 40 // TX focused
Matt Briggs 40:2ec4be320961 41 CmdResult send (const std::vector<uint8_t> &msg);
Matt Briggs 40:2ec4be320961 42 CmdResult sendPairReq();
Matt Briggs 40:2ec4be320961 43
Matt Briggs 40:2ec4be320961 44 // RX focused
Matt Briggs 40:2ec4be320961 45 CmdResult listen (bool &msgPending);
Matt Briggs 40:2ec4be320961 46 CmdResult recv (std::vector<uint8_t> &msg);
Matt Briggs 40:2ec4be320961 47 CmdResult waitForPairing(float waitTime);
Matt Briggs 40:2ec4be320961 48
Matt Briggs 40:2ec4be320961 49 private:
Matt Briggs 40:2ec4be320961 50 uint8_t mNetworkAddr[4];
Matt Briggs 40:2ec4be320961 51 uint8_t pair_network_session_key[16];
Matt Briggs 40:2ec4be320961 52 uint8_t pair_data_session_key[16];
Matt Briggs 40:2ec4be320961 53 bool mIsTx;
Matt Briggs 40:2ec4be320961 54
Matt Briggs 40:2ec4be320961 55 /**
Matt Briggs 40:2ec4be320961 56 * @brief Reads baseboard information from non-volatile memory (NVM)
Matt Briggs 40:2ec4be320961 57 *
Matt Briggs 40:2ec4be320961 58 * @details This data is read from the xDot's internal EEPROM. This
Matt Briggs 40:2ec4be320961 59 * method is called from init(). The following
Matt Briggs 40:2ec4be320961 60 * is stored:
Matt Briggs 40:2ec4be320961 61 * 1. Peer Brute Storage code word
Matt Briggs 40:2ec4be320961 62 * 2. 8-bit protocol version
Matt Briggs 40:2ec4be320961 63 * 3. 16-bit Baseboard serial number
Matt Briggs 40:2ec4be320961 64 * 4. 4 Byte network address
Matt Briggs 40:2ec4be320961 65 * 5. 16 Byte network session key
Matt Briggs 40:2ec4be320961 66 * 6. 16 Byte data session key
Matt Briggs 40:2ec4be320961 67 * 7. 4 Byte DLC
Matt Briggs 40:2ec4be320961 68 * 8. 4 Byte ULC
Matt Briggs 40:2ec4be320961 69 *
Matt Briggs 40:2ec4be320961 70 * TODO add memory map information
Matt Briggs 40:2ec4be320961 71 *
Matt Briggs 40:2ec4be320961 72 * @return CmdResult
Matt Briggs 40:2ec4be320961 73 */
Matt Briggs 40:2ec4be320961 74 CmdResult readInfoFromNVM();
Matt Briggs 40:2ec4be320961 75
Matt Briggs 40:2ec4be320961 76 /**
Matt Briggs 40:2ec4be320961 77 * @brief Stores baseboard information to non-volatile memory (NVM)
Matt Briggs 40:2ec4be320961 78 *
Matt Briggs 40:2ec4be320961 79 * @details This method is called during special configuration events like first time boot or factory reset.
Matt Briggs 40:2ec4be320961 80 *
Matt Briggs 40:2ec4be320961 81 * TODO add memory map information
Matt Briggs 40:2ec4be320961 82 *
Matt Briggs 40:2ec4be320961 83 * @return CmdResult
Matt Briggs 40:2ec4be320961 84 */
Matt Briggs 40:2ec4be320961 85 CmdResult writeInfoToNVM();
Matt Briggs 40:2ec4be320961 86
Matt Briggs 40:2ec4be320961 87 CmdResult resetCounters();
Matt Briggs 40:2ec4be320961 88
Matt Briggs 40:2ec4be320961 89 CmdResult genEncypKeys();
Matt Briggs 40:2ec4be320961 90 };
Matt Briggs 40:2ec4be320961 91
Matt Briggs 40:2ec4be320961 92 #endif