![](/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@29:e05e35976cfe, 2017-01-09 (annotated)
- Committer:
- Matt Briggs
- Date:
- Mon Jan 09 14:45:42 2017 -0700
- Revision:
- 29:e05e35976cfe
- Parent:
- 28:b14b2926e916
- Child:
- 30:2e673a672884
Added IO example code.
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" |
Matt Briggs | 26:9411b26a5084 | 4 | #include <math.h> |
Mike Fiore |
11:d2e31743433a | 5 | |
Matt Briggs | 22:9453658b8d4b | 6 | |
mfiore | 17:d4f82e16de5f | 7 | ///////////////////////////////////////////////////////////////////////////// |
mfiore | 17:d4f82e16de5f | 8 | // -------------------- DOT LIBRARY REQUIRED ------------------------------// |
mfiore | 17:d4f82e16de5f | 9 | // * Because these example programs can be used for both mDot and xDot // |
mfiore | 17:d4f82e16de5f | 10 | // devices, the LoRa stack is not included. The libmDot library should // |
mfiore | 17:d4f82e16de5f | 11 | // be imported if building for mDot devices. The libxDot library // |
mfiore | 17:d4f82e16de5f | 12 | // should be imported if building for xDot devices. // |
mfiore | 17:d4f82e16de5f | 13 | // * https://developer.mbed.org/teams/MultiTech/code/libmDot-dev-mbed5/ // |
mfiore | 17:d4f82e16de5f | 14 | // * https://developer.mbed.org/teams/MultiTech/code/libmDot-mbed5/ // |
mfiore | 17:d4f82e16de5f | 15 | // * https://developer.mbed.org/teams/MultiTech/code/libxDot-dev-mbed5/ // |
mfiore | 17:d4f82e16de5f | 16 | // * https://developer.mbed.org/teams/MultiTech/code/libxDot-mbed5/ // |
mfiore | 17:d4f82e16de5f | 17 | ///////////////////////////////////////////////////////////////////////////// |
mfiore | 17:d4f82e16de5f | 18 | |
Mike Fiore |
11:d2e31743433a | 19 | ///////////////////////////////////////////////////////////// |
Mike Fiore |
11:d2e31743433a | 20 | // * these options must match between the two devices in // |
Mike Fiore |
11:d2e31743433a | 21 | // order for communication to be successful |
Mike Fiore |
11:d2e31743433a | 22 | ///////////////////////////////////////////////////////////// |
Mike Fiore |
11:d2e31743433a | 23 | static uint8_t network_address[] = { 0x01, 0x02, 0x03, 0x04 }; |
Mike Fiore |
11:d2e31743433a | 24 | 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 | 25 | 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 | 26 | |
Matt Briggs | 26:9411b26a5084 | 27 | // wireless bridge protocol |
Matt Briggs | 26:9411b26a5084 | 28 | //const float dutyCycle = 0.01; // 1% |
Matt Briggs | 27:6b68ff715ae1 | 29 | const float rxSleepTime = 2000; // ms (one second resolution, min 2 seconds) |
Matt Briggs | 26:9411b26a5084 | 30 | const uint8_t maxPayloadSize = 10; // Number of bytes (used for toa calcultion) |
Matt Briggs | 26:9411b26a5084 | 31 | |
Matt Briggs | 29:e05e35976cfe | 32 | DigitalOut led1(GPIO0); |
Matt Briggs | 29:e05e35976cfe | 33 | |
Matt Briggs | 29:e05e35976cfe | 34 | AnalogIn an1(GPIO1); |
Matt Briggs | 29:e05e35976cfe | 35 | AnalogIn an2(GPIO2); |
Matt Briggs | 29:e05e35976cfe | 36 | |
Matt Briggs | 29:e05e35976cfe | 37 | // Inputs |
Matt Briggs | 29:e05e35976cfe | 38 | DigitalIn gpio3(GPIO3); |
Matt Briggs | 29:e05e35976cfe | 39 | DigitalIn wake_DOUT(WAKE); |
Matt Briggs | 29:e05e35976cfe | 40 | DigitalIn i2cOut1(I2C1_SCL); |
Matt Briggs | 29:e05e35976cfe | 41 | DigitalIn i2cOut2(I2C1_SDA); |
Matt Briggs | 29:e05e35976cfe | 42 | |
Matt Briggs | 29:e05e35976cfe | 43 | DigitalIn uartOut1(UART1_CTS); |
Matt Briggs | 29:e05e35976cfe | 44 | DigitalIn uartOut2(UART1_RTS); |
Matt Briggs | 29:e05e35976cfe | 45 | |
Matt Briggs | 29:e05e35976cfe | 46 | // Outputs |
Matt Briggs | 29:e05e35976cfe | 47 | //DigitalOut gpio3(GPIO3); |
Matt Briggs | 29:e05e35976cfe | 48 | ////DigitalOut wake_DOUT(WAKE); |
Matt Briggs | 29:e05e35976cfe | 49 | //DigitalOut i2cOut1(I2C1_SCL); |
Matt Briggs | 29:e05e35976cfe | 50 | //DigitalOut i2cOut2(I2C1_SDA); |
Matt Briggs | 29:e05e35976cfe | 51 | // |
Matt Briggs | 29:e05e35976cfe | 52 | //DigitalOut uartOut1(UART1_CTS); |
Matt Briggs | 29:e05e35976cfe | 53 | //DigitalOut uartOut2(UART1_RTS); |
Matt Briggs | 29:e05e35976cfe | 54 | |
Mike Fiore |
11:d2e31743433a | 55 | mDot* dot = NULL; |
Mike Fiore |
11:d2e31743433a | 56 | |
Mike Fiore |
11:d2e31743433a | 57 | Serial pc(USBTX, USBRX); |
Mike Fiore |
11:d2e31743433a | 58 | |
Matt Briggs | 27:6b68ff715ae1 | 59 | //Ticker t; |
Matt Briggs | 27:6b68ff715ae1 | 60 | // |
Matt Briggs | 27:6b68ff715ae1 | 61 | //class RxHandler { |
Matt Briggs | 27:6b68ff715ae1 | 62 | // private: |
Matt Briggs | 27:6b68ff715ae1 | 63 | // uint m_dwnLink; |
Matt Briggs | 27:6b68ff715ae1 | 64 | // mDot *m_dot; |
Matt Briggs | 27:6b68ff715ae1 | 65 | // public: |
Matt Briggs | 27:6b68ff715ae1 | 66 | // RxHandler (mDot *dot) { |
Matt Briggs | 27:6b68ff715ae1 | 67 | // m_dot = dot; |
Matt Briggs | 27:6b68ff715ae1 | 68 | // m_dwnLink = dot->getDownLinkCounter(); |
Matt Briggs | 27:6b68ff715ae1 | 69 | // } |
Matt Briggs | 27:6b68ff715ae1 | 70 | // void listen() { |
Matt Briggs | 27:6b68ff715ae1 | 71 | // std::vector<uint8_t> data; |
Matt Briggs | 27:6b68ff715ae1 | 72 | // led1 = 1; // FIXME |
Matt Briggs | 27:6b68ff715ae1 | 73 | // logInfo("Listening for new message current DLC: %d, time: %lu", m_dwnLink, us_ticker_read()); |
Matt Briggs | 27:6b68ff715ae1 | 74 | // wait(0.060); // Wait twice the time on air |
Matt Briggs | 27:6b68ff715ae1 | 75 | // if (m_dwnLink < dot->getDownLinkCounter()) { |
Matt Briggs | 27:6b68ff715ae1 | 76 | // m_dwnLink = dot->getDownLinkCounter(); |
Matt Briggs | 27:6b68ff715ae1 | 77 | // m_dot->recv(data); |
Matt Briggs | 27:6b68ff715ae1 | 78 | // std::string dataStr(data.begin(), data.end()); |
Matt Briggs | 27:6b68ff715ae1 | 79 | // logInfo("Got msg num: -, payload: %s", dataStr.c_str()); |
Matt Briggs | 27:6b68ff715ae1 | 80 | // wait(0.5); |
Matt Briggs | 27:6b68ff715ae1 | 81 | // } |
Matt Briggs | 27:6b68ff715ae1 | 82 | // led1=0; |
Matt Briggs | 27:6b68ff715ae1 | 83 | // } |
Matt Briggs | 27:6b68ff715ae1 | 84 | //}; |
Matt Briggs | 27:6b68ff715ae1 | 85 | |
Mike Fiore |
11:d2e31743433a | 86 | int main() { |
Mike Fiore |
14:19fae4509473 | 87 | // Custom event handler for automatically displaying RX data |
Mike Fiore |
11:d2e31743433a | 88 | RadioEvent events; |
Mike Fiore |
11:d2e31743433a | 89 | uint32_t tx_frequency; |
Mike Fiore |
11:d2e31743433a | 90 | uint8_t tx_datarate; |
Mike Fiore |
11:d2e31743433a | 91 | uint8_t tx_power; |
Mike Fiore |
11:d2e31743433a | 92 | uint8_t frequency_band; |
Mike Fiore |
11:d2e31743433a | 93 | |
Mike Fiore |
11:d2e31743433a | 94 | pc.baud(115200); |
Mike Fiore |
11:d2e31743433a | 95 | |
Matt Briggs | 27:6b68ff715ae1 | 96 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); |
Mike Fiore |
11:d2e31743433a | 97 | |
Mike Fiore |
11:d2e31743433a | 98 | dot = mDot::getInstance(); |
Mike Fiore |
11:d2e31743433a | 99 | |
Mike Fiore |
16:a3832552dfe1 | 100 | logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); |
Mike Fiore |
16:a3832552dfe1 | 101 | |
Mike Fiore |
12:ec9768677cea | 102 | // start from a well-known state |
Mike Fiore |
12:ec9768677cea | 103 | logInfo("defaulting Dot configuration"); |
Mike Fiore |
12:ec9768677cea | 104 | dot->resetConfig(); |
Mike Fiore |
12:ec9768677cea | 105 | |
Mike Fiore |
11:d2e31743433a | 106 | // make sure library logging is turned on |
Matt Briggs | 27:6b68ff715ae1 | 107 | dot->setLogLevel(mts::MTSLog::INFO_LEVEL); |
Mike Fiore |
11:d2e31743433a | 108 | |
Mike Fiore |
11:d2e31743433a | 109 | // attach the custom events handler |
Mike Fiore |
11:d2e31743433a | 110 | dot->setEvents(&events); |
Mike Fiore |
11:d2e31743433a | 111 | |
Mike Fiore |
11:d2e31743433a | 112 | // update configuration if necessary |
Mike Fiore |
11:d2e31743433a | 113 | if (dot->getJoinMode() != mDot::PEER_TO_PEER) { |
Mike Fiore |
11:d2e31743433a | 114 | logInfo("changing network join mode to PEER_TO_PEER"); |
Mike Fiore |
11:d2e31743433a | 115 | if (dot->setJoinMode(mDot::PEER_TO_PEER) != mDot::MDOT_OK) { |
Mike Fiore |
11:d2e31743433a | 116 | logError("failed to set network join mode to PEER_TO_PEER"); |
Mike Fiore |
11:d2e31743433a | 117 | } |
Mike Fiore |
11:d2e31743433a | 118 | } |
Mike Fiore |
11:d2e31743433a | 119 | frequency_band = dot->getFrequencyBand(); |
Mike Fiore |
11:d2e31743433a | 120 | switch (frequency_band) { |
Mike Fiore |
11:d2e31743433a | 121 | case mDot::FB_EU868: |
Mike Fiore |
11:d2e31743433a | 122 | // 250kHz channels achieve higher throughput |
Mike Fiore |
11:d2e31743433a | 123 | // DR6 : SF7 @ 250kHz |
Mike Fiore |
11:d2e31743433a | 124 | // DR0 - DR5 (125kHz channels) available but much slower |
Mike Fiore |
11:d2e31743433a | 125 | tx_frequency = 869850000; |
Mike Fiore |
11:d2e31743433a | 126 | tx_datarate = mDot::DR6; |
Mike Fiore |
11:d2e31743433a | 127 | // 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 | 128 | tx_power = 4; |
Mike Fiore |
11:d2e31743433a | 129 | break; |
Mike Fiore |
11:d2e31743433a | 130 | case mDot::FB_US915: |
Mike Fiore |
11:d2e31743433a | 131 | case mDot::FB_AU915: |
Mike Fiore |
11:d2e31743433a | 132 | default: |
Mike Fiore |
11:d2e31743433a | 133 | // 500kHz channels achieve highest throughput |
Mike Fiore |
11:d2e31743433a | 134 | // DR8 : SF12 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 135 | // DR9 : SF11 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 136 | // DR10 : SF10 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 137 | // DR11 : SF9 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 138 | // DR12 : SF8 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 139 | // DR13 : SF7 @ 500kHz |
Mike Fiore |
11:d2e31743433a | 140 | // DR0 - DR3 (125kHz channels) available but much slower |
Mike Fiore |
11:d2e31743433a | 141 | tx_frequency = 915500000; |
Mike Fiore |
11:d2e31743433a | 142 | tx_datarate = mDot::DR13; |
Mike Fiore |
11:d2e31743433a | 143 | // 915 bands have no duty cycle restrictions, set tx power to max |
Mike Fiore |
11:d2e31743433a | 144 | tx_power = 20; |
Mike Fiore |
11:d2e31743433a | 145 | break; |
Mike Fiore |
11:d2e31743433a | 146 | } |
Mike Fiore |
11:d2e31743433a | 147 | // in PEER_TO_PEER mode there is no join request/response transaction |
Mike Fiore |
11:d2e31743433a | 148 | // as long as both Dots are configured correctly, they should be able to communicate |
Mike Fiore |
11:d2e31743433a | 149 | update_peer_to_peer_config(network_address, network_session_key, data_session_key, tx_frequency, tx_datarate, tx_power); |
Mike Fiore |
11:d2e31743433a | 150 | |
Matt Briggs | 24:fdf87e4b72e5 | 151 | |
Matt Briggs | 24:fdf87e4b72e5 | 152 | unsigned int wakeMode; |
Matt Briggs | 26:9411b26a5084 | 153 | |
Matt Briggs | 24:fdf87e4b72e5 | 154 | /////////////////////////////// |
Matt Briggs | 24:fdf87e4b72e5 | 155 | // Transmitter Configuration // |
Matt Briggs | 24:fdf87e4b72e5 | 156 | /////////////////////////////// |
Matt Briggs | 27:6b68ff715ae1 | 157 | #if BRIDGE_TX_BRUTE |
Matt Briggs | 24:fdf87e4b72e5 | 158 | wakeMode = mDot::INTERRUPT; |
Matt Briggs | 29:e05e35976cfe | 159 | dot->setTxWait(false); |
Matt Briggs | 29:e05e35976cfe | 160 | dot->setAck(0); // Disable Ack |
Matt Briggs | 29:e05e35976cfe | 161 | #endif |
Matt Briggs | 29:e05e35976cfe | 162 | |
Matt Briggs | 29:e05e35976cfe | 163 | #if BRIDGE_TX_ACK |
Matt Briggs | 29:e05e35976cfe | 164 | wakeMode = mDot::INTERRUPT; |
Matt Briggs | 29:e05e35976cfe | 165 | dot->setTxWait(true); |
Matt Briggs | 29:e05e35976cfe | 166 | dot->setAck(1); // Enable Ack |
Matt Briggs | 29:e05e35976cfe | 167 | dot->setRepeat(1); // No auto repeats |
Matt Briggs | 29:e05e35976cfe | 168 | dot->setRxDelay(1); |
Matt Briggs | 24:fdf87e4b72e5 | 169 | #endif |
Matt Briggs | 24:fdf87e4b72e5 | 170 | |
Matt Briggs | 24:fdf87e4b72e5 | 171 | //////////////////////////// |
Matt Briggs | 24:fdf87e4b72e5 | 172 | // Receiver Configuration // |
Matt Briggs | 24:fdf87e4b72e5 | 173 | //////////////////////////// |
Matt Briggs | 27:6b68ff715ae1 | 174 | #if BRIDGE_RX_BRUTE |
Matt Briggs | 24:fdf87e4b72e5 | 175 | wakeMode = mDot::RTC_ALARM_OR_INTERRUPT; |
Matt Briggs | 29:e05e35976cfe | 176 | dot->setTxWait(false); |
Matt Briggs | 29:e05e35976cfe | 177 | dot->setAck(0); // Disable Ack |
Matt Briggs | 24:fdf87e4b72e5 | 178 | #endif |
Matt Briggs | 24:fdf87e4b72e5 | 179 | |
Matt Briggs | 24:fdf87e4b72e5 | 180 | // Common Configuration |
Matt Briggs | 25:fea776239709 | 181 | dot->setWakePin(WAKE); // Use the wake pin as sleep interrupt |
Matt Briggs | 25:fea776239709 | 182 | dot->setClass("C"); // Set class C |
Matt Briggs | 28:b14b2926e916 | 183 | dot->setTxPower(20); // 20 dBm |
Matt Briggs | 24:fdf87e4b72e5 | 184 | |
Mike Fiore |
11:d2e31743433a | 185 | // save changes to configuration |
Mike Fiore |
11:d2e31743433a | 186 | logInfo("saving configuration"); |
Mike Fiore |
11:d2e31743433a | 187 | if (!dot->saveConfig()) { |
Mike Fiore |
11:d2e31743433a | 188 | logError("failed to save configuration"); |
Mike Fiore |
11:d2e31743433a | 189 | } |
Mike Fiore |
11:d2e31743433a | 190 | |
Mike Fiore |
11:d2e31743433a | 191 | // display configuration |
Mike Fiore |
11:d2e31743433a | 192 | display_config(); |
Mike Fiore |
11:d2e31743433a | 193 | |
Matt Briggs | 26:9411b26a5084 | 194 | |
Matt Briggs | 27:6b68ff715ae1 | 195 | uint32_t txTime = 30; // in ms |
Matt Briggs | 27:6b68ff715ae1 | 196 | unsigned int nTimesToTx = ceil(rxSleepTime / ((float)txTime)); |
Matt Briggs | 27:6b68ff715ae1 | 197 | logInfo("rxSleepTime %f, timeOnAir %lu, nTimesToTx %lu", rxSleepTime, txTime, nTimesToTx); |
Matt Briggs | 26:9411b26a5084 | 198 | |
mbriggs_vortex | 23:4ed894108882 | 199 | uint16_t seqNum=0; |
Matt Briggs | 26:9411b26a5084 | 200 | uint32_t cDwnLink = dot->getDownLinkCounter(); |
Mike Fiore |
11:d2e31743433a | 201 | while (true) { |
Matt Briggs | 25:fea776239709 | 202 | std::vector<uint8_t> data; |
Matt Briggs | 29:e05e35976cfe | 203 | // led1=0; FIXME |
Mike Fiore |
11:d2e31743433a | 204 | |
Mike Fiore |
11:d2e31743433a | 205 | // join network if not joined |
Mike Fiore |
11:d2e31743433a | 206 | if (!dot->getNetworkJoinStatus()) { |
Mike Fiore |
11:d2e31743433a | 207 | join_network(); |
Mike Fiore |
11:d2e31743433a | 208 | } |
Mike Fiore |
11:d2e31743433a | 209 | |
Matt Briggs | 27:6b68ff715ae1 | 210 | ////////////////////////////////////////// |
Matt Briggs | 27:6b68ff715ae1 | 211 | // Brute Protocol Transmitter main loop // |
Matt Briggs | 27:6b68ff715ae1 | 212 | ////////////////////////////////////////// |
Matt Briggs | 27:6b68ff715ae1 | 213 | #if BRIDGE_TX_BRUTE |
Matt Briggs | 26:9411b26a5084 | 214 | led1=1; |
Matt Briggs | 25:fea776239709 | 215 | data.push_back((seqNum >> 8) & 0xFF); |
Matt Briggs | 25:fea776239709 | 216 | data.push_back(seqNum & 0xFF); |
Matt Briggs | 27:6b68ff715ae1 | 217 | logInfo("Starting TX. Time: %lu, seqNum: %lu", us_ticker_read(), seqNum); |
Matt Briggs | 26:9411b26a5084 | 218 | for(uint i=0;i<nTimesToTx;++i) { |
Matt Briggs | 27:6b68ff715ae1 | 219 | dot->send(data); |
Matt Briggs | 26:9411b26a5084 | 220 | } |
mbriggs_vortex | 23:4ed894108882 | 221 | seqNum++; |
Matt Briggs | 25:fea776239709 | 222 | led1=0; |
Matt Briggs | 27:6b68ff715ae1 | 223 | logInfo("Finished TX. Time: %lu", us_ticker_read()); |
mbriggs_vortex | 23:4ed894108882 | 224 | |
Matt Briggs | 28:b14b2926e916 | 225 | sleep_save_io(); |
Matt Briggs | 28:b14b2926e916 | 226 | sleep_configure_io(); |
Matt Briggs | 24:fdf87e4b72e5 | 227 | dot->sleep(0, wakeMode, false); // Go to sleep until wake button |
Matt Briggs | 28:b14b2926e916 | 228 | sleep_restore_io(); |
Matt Briggs | 24:fdf87e4b72e5 | 229 | #endif |
Matt Briggs | 27:6b68ff715ae1 | 230 | |
Matt Briggs | 29:e05e35976cfe | 231 | #if BRIDGE_TX_ACK |
Matt Briggs | 29:e05e35976cfe | 232 | led1=1; |
Matt Briggs | 29:e05e35976cfe | 233 | data.push_back((seqNum >> 8) & 0xFF); |
Matt Briggs | 29:e05e35976cfe | 234 | data.push_back(seqNum & 0xFF); |
Matt Briggs | 29:e05e35976cfe | 235 | logInfo("Starting TX. Time: %lu, seqNum: %lu", us_ticker_read(), seqNum); |
Matt Briggs | 29:e05e35976cfe | 236 | uint32_t pktRtn = -1024; |
Matt Briggs | 29:e05e35976cfe | 237 | for(uint i=0;i<nTimesToTx;++i) { |
Matt Briggs | 29:e05e35976cfe | 238 | pktRtn = dot->send(data); |
Matt Briggs | 29:e05e35976cfe | 239 | if (pktRtn == mDot::MDOT_OK) { |
Matt Briggs | 29:e05e35976cfe | 240 | logInfo("Successful TX. Time: %lu Try: %d", us_ticker_read(), i); |
Matt Briggs | 29:e05e35976cfe | 241 | break; |
Matt Briggs | 29:e05e35976cfe | 242 | } |
Matt Briggs | 29:e05e35976cfe | 243 | else { |
Matt Briggs | 29:e05e35976cfe | 244 | logInfo(" Bad TX. Time: %lu Try: %d", us_ticker_read(), i); |
Matt Briggs | 29:e05e35976cfe | 245 | } |
Matt Briggs | 29:e05e35976cfe | 246 | } |
Matt Briggs | 29:e05e35976cfe | 247 | seqNum++; |
Matt Briggs | 29:e05e35976cfe | 248 | led1=0; |
Matt Briggs | 29:e05e35976cfe | 249 | logInfo("Finished TX. Time: %lu", us_ticker_read()); |
Matt Briggs | 29:e05e35976cfe | 250 | |
Matt Briggs | 29:e05e35976cfe | 251 | sleep_save_io(); |
Matt Briggs | 29:e05e35976cfe | 252 | sleep_configure_io(); |
Matt Briggs | 29:e05e35976cfe | 253 | dot->sleep(0, wakeMode, false); // Go to sleep until wake button |
Matt Briggs | 29:e05e35976cfe | 254 | sleep_restore_io(); |
Matt Briggs | 29:e05e35976cfe | 255 | #endif |
Matt Briggs | 29:e05e35976cfe | 256 | |
Matt Briggs | 27:6b68ff715ae1 | 257 | /////////////////////////////////////// |
Matt Briggs | 27:6b68ff715ae1 | 258 | // Brute Protocol Receiver main loop // |
Matt Briggs | 27:6b68ff715ae1 | 259 | /////////////////////////////////////// |
Matt Briggs | 27:6b68ff715ae1 | 260 | |
Matt Briggs | 27:6b68ff715ae1 | 261 | #if BRIDGE_RX_BRUTE |
Matt Briggs | 27:6b68ff715ae1 | 262 | logInfo("Waiting for new message current DLC: %d, Time %d", cDwnLink, us_ticker_read()); |
Matt Briggs | 27:6b68ff715ae1 | 263 | wait(txTime*2.0/1000.0); // Wait twice the txTime |
Matt Briggs | 26:9411b26a5084 | 264 | if (cDwnLink < dot->getDownLinkCounter()) { |
Matt Briggs | 26:9411b26a5084 | 265 | led1 = 1; |
Matt Briggs | 26:9411b26a5084 | 266 | cDwnLink = dot->getDownLinkCounter(); |
Matt Briggs | 26:9411b26a5084 | 267 | dot->recv(data); |
Matt Briggs | 26:9411b26a5084 | 268 | std::string dataStr(data.begin(), data.end()); |
Matt Briggs | 26:9411b26a5084 | 269 | logInfo("Got msg num: %d, payload: %s", seqNum, dataStr.c_str()); |
Matt Briggs | 26:9411b26a5084 | 270 | seqNum++; |
Matt Briggs | 26:9411b26a5084 | 271 | wait(0.5); |
Matt Briggs | 25:fea776239709 | 272 | } |
Matt Briggs | 26:9411b26a5084 | 273 | led1=0; |
Matt Briggs | 27:6b68ff715ae1 | 274 | logInfo("Sleeping. Time %d", us_ticker_read()); |
Matt Briggs | 28:b14b2926e916 | 275 | sleep_save_io(); |
Matt Briggs | 28:b14b2926e916 | 276 | sleep_configure_io(); |
Matt Briggs | 26:9411b26a5084 | 277 | dot->sleep(2, wakeMode, false); // Go to sleep until wake button |
Matt Briggs | 28:b14b2926e916 | 278 | sleep_restore_io(); |
Matt Briggs | 25:fea776239709 | 279 | #endif |
Matt Briggs | 27:6b68ff715ae1 | 280 | // // Idea to Setup Ticker |
Matt Briggs | 27:6b68ff715ae1 | 281 | // RxHandler rxHandler(dot); |
Matt Briggs | 27:6b68ff715ae1 | 282 | // t.attach(&rxHandler, &RxHandler::listen, 1.5); |
Matt Briggs | 27:6b68ff715ae1 | 283 | // wait(5.0); |
Matt Briggs | 27:6b68ff715ae1 | 284 | // while (true) { |
Matt Briggs | 27:6b68ff715ae1 | 285 | // dot->sleep(0, wakeMode, false); // Go to sleep until wake button |
Matt Briggs | 27:6b68ff715ae1 | 286 | // //sleep(); |
Matt Briggs | 27:6b68ff715ae1 | 287 | // } |
Matt Briggs | 29:e05e35976cfe | 288 | ////////////// |
Matt Briggs | 29:e05e35976cfe | 289 | // I/O Play // |
Matt Briggs | 29:e05e35976cfe | 290 | ////////////// |
Matt Briggs | 29:e05e35976cfe | 291 | |
Matt Briggs | 29:e05e35976cfe | 292 | // Check Analog |
Matt Briggs | 29:e05e35976cfe | 293 | logInfo("Read AN1/GPIO1: %f", an1.read()); |
Matt Briggs | 29:e05e35976cfe | 294 | logInfo("Read AN2/GPIO2: %f", an2.read()); // Ranges from 0.0 to 1.0 |
Matt Briggs | 29:e05e35976cfe | 295 | |
Matt Briggs | 29:e05e35976cfe | 296 | // check inputs |
Matt Briggs | 29:e05e35976cfe | 297 | logInfo("Read GPIO3: %d", gpio3.read()); |
Matt Briggs | 29:e05e35976cfe | 298 | logInfo("Read wake_DOUT: %d", wake_DOUT.read()); |
Matt Briggs | 29:e05e35976cfe | 299 | logInfo("Read i2cOut1: %d", i2cOut1.read()); // Appears to be pulled up |
Matt Briggs | 29:e05e35976cfe | 300 | logInfo("Read i2cOut2: %d", i2cOut2.read()); // Appears to be pulled up |
Matt Briggs | 29:e05e35976cfe | 301 | logInfo("Read uartOut1: %d", uartOut1.read()); |
Matt Briggs | 29:e05e35976cfe | 302 | logInfo("Read uartOut2: %d", uartOut2.read()); |
Matt Briggs | 29:e05e35976cfe | 303 | |
Matt Briggs | 29:e05e35976cfe | 304 | // check digital outputs |
Matt Briggs | 29:e05e35976cfe | 305 | // led1 = !led1; |
Matt Briggs | 29:e05e35976cfe | 306 | // gpio3 = !gpio3; |
Matt Briggs | 29:e05e35976cfe | 307 | //// wake_DOUT = !wake_DOUT; |
Matt Briggs | 29:e05e35976cfe | 308 | // i2cOut1 = !i2cOut1; |
Matt Briggs | 29:e05e35976cfe | 309 | // i2cOut2 = !i2cOut2; |
Matt Briggs | 29:e05e35976cfe | 310 | // |
Matt Briggs | 29:e05e35976cfe | 311 | // uartOut1 = !uartOut1; |
Matt Briggs | 29:e05e35976cfe | 312 | // uartOut2 = !uartOut2; |
Matt Briggs | 29:e05e35976cfe | 313 | |
Matt Briggs | 29:e05e35976cfe | 314 | logInfo("================================"); |
Matt Briggs | 29:e05e35976cfe | 315 | |
Matt Briggs | 29:e05e35976cfe | 316 | wait(1.0); |
Mike Fiore |
11:d2e31743433a | 317 | } |
Mike Fiore |
11:d2e31743433a | 318 | |
Mike Fiore |
11:d2e31743433a | 319 | return 0; |
Mike Fiore |
11:d2e31743433a | 320 | } |
Mike Fiore |
11:d2e31743433a | 321 | |
Matt Briggs | 27:6b68ff715ae1 | 322 |