![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
xDotBridge/src/main.cpp@23:4ed894108882, 2016-12-30 (annotated)
- Committer:
- mbriggs_vortex
- Date:
- Fri Dec 30 19:10:41 2016 +0000
- Revision:
- 23:4ed894108882
- Parent:
- 22:9453658b8d4b
- Child:
- 24:fdf87e4b72e5
Started playing with transmitter side
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matt Briggs | 22:9453658b8d4b | 1 | #include "config.h" |
Mike Fiore |
11:d2e31743433a | 2 | #include "dot_util.h" |
Mike Fiore |
14:19fae4509473 | 3 | #include "RadioEvent.h" |
Mike Fiore |
11:d2e31743433a | 4 | |
Matt Briggs | 22:9453658b8d4b | 5 | |
mfiore | 17:d4f82e16de5f | 6 | ///////////////////////////////////////////////////////////////////////////// |
mfiore | 17:d4f82e16de5f | 7 | // -------------------- DOT LIBRARY REQUIRED ------------------------------// |
mfiore | 17:d4f82e16de5f | 8 | // * Because these example programs can be used for both mDot and xDot // |
mfiore | 17:d4f82e16de5f | 9 | // devices, the LoRa stack is not included. The libmDot library should // |
mfiore | 17:d4f82e16de5f | 10 | // be imported if building for mDot devices. The libxDot library // |
mfiore | 17:d4f82e16de5f | 11 | // should be imported if building for xDot devices. // |
mfiore | 17:d4f82e16de5f | 12 | // * https://developer.mbed.org/teams/MultiTech/code/libmDot-dev-mbed5/ // |
mfiore | 17:d4f82e16de5f | 13 | // * https://developer.mbed.org/teams/MultiTech/code/libmDot-mbed5/ // |
mfiore | 17:d4f82e16de5f | 14 | // * https://developer.mbed.org/teams/MultiTech/code/libxDot-dev-mbed5/ // |
mfiore | 17:d4f82e16de5f | 15 | // * https://developer.mbed.org/teams/MultiTech/code/libxDot-mbed5/ // |
mfiore | 17:d4f82e16de5f | 16 | ///////////////////////////////////////////////////////////////////////////// |
mfiore | 17:d4f82e16de5f | 17 | |
Mike Fiore |
11:d2e31743433a | 18 | ///////////////////////////////////////////////////////////// |
Mike Fiore |
11:d2e31743433a | 19 | // * these options must match between the two devices in // |
Mike Fiore |
11:d2e31743433a | 20 | // order for communication to be successful |
Mike Fiore |
11:d2e31743433a | 21 | ///////////////////////////////////////////////////////////// |
Mike Fiore |
11:d2e31743433a | 22 | static uint8_t network_address[] = { 0x01, 0x02, 0x03, 0x04 }; |
Mike Fiore |
11:d2e31743433a | 23 | static uint8_t network_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; |
mbriggs_vortex | 19:75b28b4117cc | 24 | static uint8_t data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; |
Mike Fiore |
11:d2e31743433a | 25 | |
Mike Fiore |
11:d2e31743433a | 26 | mDot* dot = NULL; |
Mike Fiore |
11:d2e31743433a | 27 | |
Mike Fiore |
11:d2e31743433a | 28 | Serial pc(USBTX, USBRX); |
Mike Fiore |
11:d2e31743433a | 29 | |
Mike Fiore |
11:d2e31743433a | 30 | int main() { |
Mike Fiore |
14:19fae4509473 | 31 | // Custom event handler for automatically displaying RX data |
Mike Fiore |
11:d2e31743433a | 32 | RadioEvent events; |
Mike Fiore |
11:d2e31743433a | 33 | uint32_t tx_frequency; |
Mike Fiore |
11:d2e31743433a | 34 | uint8_t tx_datarate; |
Mike Fiore |
11:d2e31743433a | 35 | uint8_t tx_power; |
Mike Fiore |
11:d2e31743433a | 36 | uint8_t frequency_band; |
Mike Fiore |
11:d2e31743433a | 37 | |
Mike Fiore |
11:d2e31743433a | 38 | pc.baud(115200); |
Mike Fiore |
11:d2e31743433a | 39 | |
Mike Fiore |
11:d2e31743433a | 40 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); |
Mike Fiore |
11:d2e31743433a | 41 | |
Mike Fiore |
11:d2e31743433a | 42 | dot = mDot::getInstance(); |
Mike Fiore |
11:d2e31743433a | 43 | |
Mike Fiore |
16:a3832552dfe1 | 44 | logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); |
Mike Fiore |
16:a3832552dfe1 | 45 | |
Mike Fiore |
12:ec9768677cea | 46 | // start from a well-known state |
Mike Fiore |
12:ec9768677cea | 47 | logInfo("defaulting Dot configuration"); |
Mike Fiore |
12:ec9768677cea | 48 | dot->resetConfig(); |
Mike Fiore |
12:ec9768677cea | 49 | |
Mike Fiore |
11:d2e31743433a | 50 | // make sure library logging is turned on |
Mike Fiore |
11:d2e31743433a | 51 | dot->setLogLevel(mts::MTSLog::INFO_LEVEL); |
Mike Fiore |
11:d2e31743433a | 52 | |
Mike Fiore |
11:d2e31743433a | 53 | // attach the custom events handler |
Mike Fiore |
11:d2e31743433a | 54 | dot->setEvents(&events); |
Mike Fiore |
11:d2e31743433a | 55 | |
Mike Fiore |
11:d2e31743433a | 56 | // update configuration if necessary |
Mike Fiore |
11:d2e31743433a | 57 | if (dot->getJoinMode() != mDot::PEER_TO_PEER) { |
Mike Fiore |
11:d2e31743433a | 58 | logInfo("changing network join mode to PEER_TO_PEER"); |
Mike Fiore |
11:d2e31743433a | 59 | if (dot->setJoinMode(mDot::PEER_TO_PEER) != mDot::MDOT_OK) { |
Mike Fiore |
11:d2e31743433a | 60 | logError("failed to set network join mode to PEER_TO_PEER"); |
Mike Fiore |
11:d2e31743433a | 61 | } |
Mike Fiore |
11:d2e31743433a | 62 | } |
Mike Fiore |
11:d2e31743433a | 63 | frequency_band = dot->getFrequencyBand(); |
Mike Fiore |
11:d2e31743433a | 64 | switch (frequency_band) { |
Mike Fiore |
11:d2e31743433a | 65 | case mDot::FB_EU868: |
Mike Fiore |
11:d2e31743433a | 66 | // 250kHz channels achieve higher throughput |
Mike Fiore |
11:d2e31743433a | 67 | // DR6 : SF7 @ 250kHz |
Mike Fiore |
11:d2e31743433a | 68 | // DR0 - DR5 (125kHz channels) available but much slower |
Mike Fiore |
11:d2e31743433a | 69 | tx_frequency = 869850000; |
Mike Fiore |
11:d2e31743433a | 70 | tx_datarate = mDot::DR6; |
Mike Fiore |
11:d2e31743433a | 71 | // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7 |
Mike Fiore |
11:d2e31743433a | 72 | tx_power = 4; |
Mike Fiore |
11:d2e31743433a | 73 | break; |
Mike Fiore |
11:d2e31743433a | 74 | case mDot::FB_US915: |
Mike Fiore |
11:d2e31743433a | 75 | case mDot::FB_AU915: |
Mike Fiore |
11:d2e31743433a | 76 | default: |
Mike Fiore |
11:d2e31743433a | 77 | // 500kHz channels achieve highest throughput |
Mike Fiore |
11:d2e31743433a | 78 | // DR8 : SF12 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 79 | // DR9 : SF11 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 80 | // DR10 : SF10 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 81 | // DR11 : SF9 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 82 | // DR12 : SF8 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 83 | // DR13 : SF7 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 84 | // DR0 - DR3 (125kHz channels) available but much slower |
Mike Fiore |
11:d2e31743433a | 85 | tx_frequency = 915500000; |
Mike Fiore |
11:d2e31743433a | 86 | tx_datarate = mDot::DR13; |
Mike Fiore |
11:d2e31743433a | 87 | // 915 bands have no duty cycle restrictions, set tx power to max |
Mike Fiore |
11:d2e31743433a | 88 | tx_power = 20; |
Mike Fiore |
11:d2e31743433a | 89 | break; |
Mike Fiore |
11:d2e31743433a | 90 | } |
Mike Fiore |
11:d2e31743433a | 91 | // in PEER_TO_PEER mode there is no join request/response transaction |
Mike Fiore |
11:d2e31743433a | 92 | // as long as both Dots are configured correctly, they should be able to communicate |
Mike Fiore |
11:d2e31743433a | 93 | update_peer_to_peer_config(network_address, network_session_key, data_session_key, tx_frequency, tx_datarate, tx_power); |
Mike Fiore |
11:d2e31743433a | 94 | |
Mike Fiore |
11:d2e31743433a | 95 | // save changes to configuration |
Mike Fiore |
11:d2e31743433a | 96 | logInfo("saving configuration"); |
Mike Fiore |
11:d2e31743433a | 97 | if (!dot->saveConfig()) { |
Mike Fiore |
11:d2e31743433a | 98 | logError("failed to save configuration"); |
Mike Fiore |
11:d2e31743433a | 99 | } |
Mike Fiore |
11:d2e31743433a | 100 | |
Mike Fiore |
11:d2e31743433a | 101 | // display configuration |
Mike Fiore |
11:d2e31743433a | 102 | display_config(); |
Mike Fiore |
11:d2e31743433a | 103 | |
mbriggs_vortex | 23:4ed894108882 | 104 | uint16_t seqNum=0; |
Mike Fiore |
11:d2e31743433a | 105 | while (true) { |
Mike Fiore |
11:d2e31743433a | 106 | std::vector<uint8_t> tx_data; |
Mike Fiore |
11:d2e31743433a | 107 | |
Mike Fiore |
11:d2e31743433a | 108 | // join network if not joined |
Mike Fiore |
11:d2e31743433a | 109 | if (!dot->getNetworkJoinStatus()) { |
Mike Fiore |
11:d2e31743433a | 110 | join_network(); |
Mike Fiore |
11:d2e31743433a | 111 | } |
Mike Fiore |
11:d2e31743433a | 112 | |
mbriggs_vortex | 23:4ed894108882 | 113 | tx_data.push_back((seqNum >> 8) & 0xFF); |
mbriggs_vortex | 23:4ed894108882 | 114 | tx_data.push_back(seqNum & 0xFF); |
mbriggs_vortex | 23:4ed894108882 | 115 | logInfo("seqNum: %lu", seqNum); |
Mike Fiore |
11:d2e31743433a | 116 | send_data(tx_data); |
mbriggs_vortex | 23:4ed894108882 | 117 | seqNum++; |
mbriggs_vortex | 23:4ed894108882 | 118 | |
mbriggs_vortex | 23:4ed894108882 | 119 | |
mbriggs_vortex | 23:4ed894108882 | 120 | dot->sleep(); |
Mike Fiore |
11:d2e31743433a | 121 | } |
Mike Fiore |
11:d2e31743433a | 122 | |
Mike Fiore |
11:d2e31743433a | 123 | return 0; |
Mike Fiore |
11:d2e31743433a | 124 | } |
Mike Fiore |
11:d2e31743433a | 125 |