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