![](/media/cache/group/MultiTech_Logo_Color_w_Tagline_PNG_1000px.png.50x50_q85.png)
AT command firmware for MultiTech Dot devices.
Fork of mDot_AT_firmware by
Dot Library Not Included!
Because these example programs can be used for both mDot and xDot devices, the LoRa stack is not included. The libmDot library should be imported if building for mDot devices. The libxDot library should be imported if building for xDot devices. The AT firmware was last tested with mbed-os-5.4.7. Using a version past mbed-os-5.4.7 will cause the build to fail. The library used with the AT firmware has to match the mbed-os version.
Dot Library Version 3 Updates
Dot Library versions 3.x.x require a channel plan to be injected into the stack. The Dot-Examples and Dot-AT-Firmware do this by defining a macro called "CHANNEL_PLAN" that controls the channel plan that will be used in the examples. Available channel plans will be in the Dot Library repository in the plans folder.
Revision 20 and earlier of Dot-Examples and revision 15 and earlier of Dot-AT-Firmware should be used with Dot Library versions prior to 3.0.0.
Fota Library
Th Fota Library must be added to compile for mDot 3.1.0 with Fota support. Latest dev libraries and 3.2.0 release will include Fota with libmDot/libxDot.
AT Firmware Description
This AT Firmware is what ships on mDot and xDot devices. It provides an AT command interface for using the mDot or xDot for LoRa communication.
AT command documentation can be found on Multitech.com.
The firmware changelog can be found here.
The library changelog can be found here.
Dot Libraries
Dot Library Limitations
The commit messages in libmDot-mbed5 and libmDot-dev-mbed5 specify the version of the Dot library the commit contains and the version of mbed-os it was compiled against. We recommend building your application with the version of mbed-os specified in the commit message of the version of the Dot library you're using. This will ensure that you don't run into any runtime issues caused by differences in the mbed-os versions.
Stable and development libraries are available for both mDot and xDot platforms. The library chosen must match the target platform. Compiling for the mDot platform with the xDot library or vice versa will not succeed.
mDot Library
Development library for mDot.
Stable library for mDot.
xDot Library
Development library for xDot.
Stable library for xDot.
CommandTerminal/CommandTerminal.cpp@16:d5cf2af81a6d, 2017-06-19 (annotated)
- Committer:
- jenkins@jenkinsdm1
- Date:
- Mon Jun 19 14:33:21 2017 -0500
- Revision:
- 16:d5cf2af81a6d
- Parent:
- 14:f9a77400b622
- Child:
- 18:63f098f042b2
mdot-firmware revision 3.0.0-rc7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | #include "ctype.h" |
Mike Fiore |
1:e52ae6584f1c | 2 | #include "CommandTerminal.h" |
Mike Fiore |
1:e52ae6584f1c | 3 | #include "Command.h" |
Mike Fiore |
4:666017851052 | 4 | #include "MTSLog.h" |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 5 | #include "ChannelPlan.h" |
Mike Fiore |
1:e52ae6584f1c | 6 | #include <cstdarg> |
Mike Fiore |
4:666017851052 | 7 | #include <deque> |
Mike Fiore |
14:f9a77400b622 | 8 | #if defined(TARGET_XDOT_L151CC) |
Mike Fiore |
14:f9a77400b622 | 9 | #include "xdot_low_power.h" |
Mike Fiore |
14:f9a77400b622 | 10 | #endif |
Mike Fiore |
1:e52ae6584f1c | 11 | |
Mike Fiore |
14:f9a77400b622 | 12 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
1:e52ae6584f1c | 13 | const char CommandTerminal::banner[] = "\r\n\nMultiTech Systems LoRa XBee Module\r\n\n"; |
Mike Fiore |
14:f9a77400b622 | 14 | #else |
Mike Fiore |
14:f9a77400b622 | 15 | const char CommandTerminal::banner[] = "\r\n\nMultiTech Systems LoRa xDot Module\r\n\n"; |
Mike Fiore |
14:f9a77400b622 | 16 | #endif |
Mike Fiore |
1:e52ae6584f1c | 17 | const char CommandTerminal::helpline[] = "Enter '?' for help\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 18 | |
Mike Fiore |
1:e52ae6584f1c | 19 | const char CommandTerminal::newline[] = "\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 20 | |
Mike Fiore |
1:e52ae6584f1c | 21 | // Command error text... |
Mike Fiore |
1:e52ae6584f1c | 22 | const char CommandTerminal::command_error[] = "Command not found!\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 23 | |
Mike Fiore |
1:e52ae6584f1c | 24 | // Response texts... |
Mike Fiore |
1:e52ae6584f1c | 25 | const char CommandTerminal::help[] = "\r\nHelp\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 26 | const char CommandTerminal::cmd_error[] = "Invalid command\r\n"; |
Mike Fiore |
9:ff62b20f7000 | 27 | const char CommandTerminal::connect[] = "\r\nCONNECT\r\n"; |
Mike Fiore |
9:ff62b20f7000 | 28 | const char CommandTerminal::no_carrier[] = "\r\nNO CARRIER\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 29 | const char CommandTerminal::done[] = "\r\nOK\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 30 | const char CommandTerminal::error[] = "\r\nERROR\r\n"; |
Mike Fiore |
1:e52ae6584f1c | 31 | |
Mike Fiore |
1:e52ae6584f1c | 32 | // Escape sequence... |
Mike Fiore |
1:e52ae6584f1c | 33 | const char CommandTerminal::escape_sequence[] = "+++"; |
Mike Fiore |
1:e52ae6584f1c | 34 | |
Mike Fiore |
9:ff62b20f7000 | 35 | mts::ATSerial* CommandTerminal::_serialp = NULL; |
Mike Fiore |
14:f9a77400b622 | 36 | mDot* CommandTerminal::_dot = NULL; |
Mike Fiore |
14:f9a77400b622 | 37 | |
Mike Fiore |
14:f9a77400b622 | 38 | CommandTerminal::RadioEvent* CommandTerminal::_events = new RadioEvent(); |
Mike Fiore |
9:ff62b20f7000 | 39 | |
Mike Fiore |
9:ff62b20f7000 | 40 | static bool serial_data_mode = false; |
Mike Fiore |
9:ff62b20f7000 | 41 | static bool peer_to_peer = false; |
Mike Fiore |
1:e52ae6584f1c | 42 | |
Mike Fiore |
14:f9a77400b622 | 43 | std::string CommandTerminal::_errorMessage = ""; |
Mike Fiore |
14:f9a77400b622 | 44 | |
Mike Fiore |
14:f9a77400b622 | 45 | void CommandTerminal::setErrorMessage(const char* message) { |
Mike Fiore |
14:f9a77400b622 | 46 | _errorMessage.assign(message); |
Mike Fiore |
14:f9a77400b622 | 47 | } |
Mike Fiore |
14:f9a77400b622 | 48 | |
Mike Fiore |
14:f9a77400b622 | 49 | void CommandTerminal::setErrorMessage(const std::string& message) { |
Mike Fiore |
14:f9a77400b622 | 50 | _errorMessage.assign(message); |
Mike Fiore |
1:e52ae6584f1c | 51 | } |
Mike Fiore |
1:e52ae6584f1c | 52 | |
Mike Fiore |
14:f9a77400b622 | 53 | const Command CommandTerminal::_commands[NO_OF_COMMANDS] = { |
Mike Fiore |
14:f9a77400b622 | 54 | CmdAttention(), |
Mike Fiore |
14:f9a77400b622 | 55 | CmdIdentification(), |
Mike Fiore |
14:f9a77400b622 | 56 | CmdResetCpu(), |
Mike Fiore |
14:f9a77400b622 | 57 | CmdDummy("Enable/Disable Echo", "ATE", "ATE0: disable, ATE1: enable", "(0,1)"), |
Mike Fiore |
14:f9a77400b622 | 58 | CmdDummy("Enable/Disable Verbose", "ATV", "ATV0: disable, ATV1: enable", "(0,1)"), |
Mike Fiore |
14:f9a77400b622 | 59 | CmdDummy("Hardware Flow Control", "AT&K", "AT&K0: disable, AT&K3: enable", "(0,3)"), |
Mike Fiore |
14:f9a77400b622 | 60 | |
Mike Fiore |
14:f9a77400b622 | 61 | CmdFactoryDefault(), |
Mike Fiore |
14:f9a77400b622 | 62 | CmdSaveConfig(), |
Mike Fiore |
14:f9a77400b622 | 63 | CmdDisplayConfig(), |
Mike Fiore |
14:f9a77400b622 | 64 | CmdDisplayStats(), |
Mike Fiore |
14:f9a77400b622 | 65 | CmdResetStats(), |
Mike Fiore |
14:f9a77400b622 | 66 | CmdSerialBaudRate(), |
Mike Fiore |
14:f9a77400b622 | 67 | CmdDebugBaudRate(), |
Mike Fiore |
14:f9a77400b622 | 68 | CmdStartUpMode(), |
Mike Fiore |
14:f9a77400b622 | 69 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 70 | CmdDefaultFrequencyBand(), |
Mike Fiore |
14:f9a77400b622 | 71 | CmdFrequencyBand(), |
Mike Fiore |
14:f9a77400b622 | 72 | CmdFrequencySubBand(), |
Mike Fiore |
14:f9a77400b622 | 73 | CmdPublicNetwork(), |
Mike Fiore |
14:f9a77400b622 | 74 | CmdDeviceId(), |
Mike Fiore |
14:f9a77400b622 | 75 | CmdDeviceClass(), |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 76 | CmdLbt(), |
Mike Fiore |
14:f9a77400b622 | 77 | |
Mike Fiore |
14:f9a77400b622 | 78 | CmdAppPort(), |
Mike Fiore |
14:f9a77400b622 | 79 | CmdNetworkAddress(), |
Mike Fiore |
14:f9a77400b622 | 80 | CmdNetworkSessionKey(), |
Mike Fiore |
14:f9a77400b622 | 81 | CmdDataSessionKey(), |
Mike Fiore |
14:f9a77400b622 | 82 | CmdUplinkCounter(), |
Mike Fiore |
14:f9a77400b622 | 83 | CmdDownlinkCounter(), |
Mike Fiore |
14:f9a77400b622 | 84 | CmdSaveSession(), |
Mike Fiore |
14:f9a77400b622 | 85 | CmdRestoreSession(), |
Mike Fiore |
14:f9a77400b622 | 86 | CmdNetworkKey(), |
Mike Fiore |
14:f9a77400b622 | 87 | CmdNetworkId(), |
Mike Fiore |
1:e52ae6584f1c | 88 | |
Mike Fiore |
14:f9a77400b622 | 89 | CmdJoinDelay(), |
Mike Fiore |
14:f9a77400b622 | 90 | // Remove join settings commands until valid case for changing default settings |
Mike Fiore |
14:f9a77400b622 | 91 | // CmdJoinRx1Offset(), |
Mike Fiore |
14:f9a77400b622 | 92 | // CmdJoinRx2Datarate(), |
Mike Fiore |
14:f9a77400b622 | 93 | // CmdJoinRx2Frequency(), |
Mike Fiore |
14:f9a77400b622 | 94 | CmdJoinRequest(), |
Mike Fiore |
14:f9a77400b622 | 95 | CmdJoinRetries(), |
Mike Fiore |
14:f9a77400b622 | 96 | CmdJoinByteOrder(), |
Mike Fiore |
14:f9a77400b622 | 97 | CmdNetworkJoinMode(), |
Mike Fiore |
14:f9a77400b622 | 98 | CmdPreserveSession(), |
Mike Fiore |
14:f9a77400b622 | 99 | CmdNetworkJoinStatus(), |
Mike Fiore |
14:f9a77400b622 | 100 | CmdNetworkLinkCheck(), |
Mike Fiore |
14:f9a77400b622 | 101 | CmdLinkCheckCount(), |
Mike Fiore |
14:f9a77400b622 | 102 | CmdLinkCheckThreshold(), |
Mike Fiore |
14:f9a77400b622 | 103 | CmdEncryption(), |
Mike Fiore |
14:f9a77400b622 | 104 | |
Mike Fiore |
14:f9a77400b622 | 105 | CmdRssi(), |
Mike Fiore |
14:f9a77400b622 | 106 | CmdSnr(), |
Mike Fiore |
14:f9a77400b622 | 107 | CmdDataPending(), |
Mike Fiore |
14:f9a77400b622 | 108 | |
Mike Fiore |
14:f9a77400b622 | 109 | CmdSessionDataRate(), |
Mike Fiore |
14:f9a77400b622 | 110 | CmdChannelMask(), |
Mike Fiore |
1:e52ae6584f1c | 111 | |
Mike Fiore |
14:f9a77400b622 | 112 | CmdTxDataRate(), |
Mike Fiore |
14:f9a77400b622 | 113 | CmdTxPower(), |
Mike Fiore |
14:f9a77400b622 | 114 | CmdAntennaGain(), |
Mike Fiore |
14:f9a77400b622 | 115 | CmdTxFrequency(), |
Mike Fiore |
14:f9a77400b622 | 116 | CmdTxInverted(), |
Mike Fiore |
14:f9a77400b622 | 117 | CmdTxWait(), |
Mike Fiore |
14:f9a77400b622 | 118 | CmdTxChannel(), |
Mike Fiore |
14:f9a77400b622 | 119 | CmdTxNextMs(), |
Mike Fiore |
14:f9a77400b622 | 120 | CmdTimeOnAir(), |
Mike Fiore |
14:f9a77400b622 | 121 | |
Mike Fiore |
14:f9a77400b622 | 122 | CmdRxDelay(), |
Mike Fiore |
14:f9a77400b622 | 123 | CmdRxOutput(), |
Mike Fiore |
14:f9a77400b622 | 124 | CmdRxInverted(), |
Mike Fiore |
14:f9a77400b622 | 125 | |
Mike Fiore |
14:f9a77400b622 | 126 | CmdErrorCorrection(), |
Mike Fiore |
14:f9a77400b622 | 127 | CmdCRC(), |
Mike Fiore |
14:f9a77400b622 | 128 | CmdAdaptiveDataRate(), |
Mike Fiore |
14:f9a77400b622 | 129 | |
Mike Fiore |
14:f9a77400b622 | 130 | CmdACKAttempts(), |
Mike Fiore |
14:f9a77400b622 | 131 | CmdRepeat(), |
Mike Fiore |
14:f9a77400b622 | 132 | CmdMacCmd(), |
Mike Fiore |
14:f9a77400b622 | 133 | |
Mike Fiore |
14:f9a77400b622 | 134 | CmdSendString(), |
Mike Fiore |
14:f9a77400b622 | 135 | CmdSendBinary(), |
Mike Fiore |
14:f9a77400b622 | 136 | CmdReceiveOnce(), |
Mike Fiore |
1:e52ae6584f1c | 137 | |
Mike Fiore |
14:f9a77400b622 | 138 | CmdDummy("Serial Data Mode", "AT+SD", "Enter serial data mode, exit with '+++'", "NONE"), |
Mike Fiore |
14:f9a77400b622 | 139 | CmdDummy("Sleep Mode", "AT+SLEEP", "Enter sleep mode (0:deepsleep,1:sleep)", "(0,1)"), |
Mike Fiore |
14:f9a77400b622 | 140 | CmdSerialClearOnError(), |
Mike Fiore |
14:f9a77400b622 | 141 | CmdWakeMode(), |
Mike Fiore |
14:f9a77400b622 | 142 | CmdWakeInterval(), |
Mike Fiore |
14:f9a77400b622 | 143 | CmdWakePin(), |
Mike Fiore |
14:f9a77400b622 | 144 | CmdWakeDelay(), |
Mike Fiore |
14:f9a77400b622 | 145 | CmdWakeTimeout(), |
Mike Fiore |
14:f9a77400b622 | 146 | CmdPing(), |
Mike Fiore |
14:f9a77400b622 | 147 | CmdLogLevel(), |
Mike Fiore |
14:f9a77400b622 | 148 | |
Mike Fiore |
14:f9a77400b622 | 149 | CmdDummy("***** Test Commands *****", "", "", ""), |
Mike Fiore |
14:f9a77400b622 | 150 | CmdRxDataRate(), |
Mike Fiore |
14:f9a77400b622 | 151 | CmdRxFrequency(), |
Mike Fiore |
14:f9a77400b622 | 152 | CmdReceiveContinuous(), |
Mike Fiore |
14:f9a77400b622 | 153 | CmdSendStringOnInterval(), |
Mike Fiore |
14:f9a77400b622 | 154 | |
Mike Fiore |
14:f9a77400b622 | 155 | #ifdef MTS_RADIO_DEBUG_COMMANDS |
Mike Fiore |
14:f9a77400b622 | 156 | CmdDummy("***** Debug Commands *****", "", "", ""), |
Mike Fiore |
14:f9a77400b622 | 157 | CmdSendContinuous(), |
Mike Fiore |
14:f9a77400b622 | 158 | CmdWriteProtectedConfig(), |
Mike Fiore |
14:f9a77400b622 | 159 | CmdDumpRegisters(), |
Mike Fiore |
14:f9a77400b622 | 160 | CmdEraseFlash(), |
Mike Fiore |
14:f9a77400b622 | 161 | CmdDisableDutyCycle(), |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 162 | CmdLBTRSSI(), |
Mike Fiore |
14:f9a77400b622 | 163 | #endif |
Mike Fiore |
14:f9a77400b622 | 164 | |
Mike Fiore |
14:f9a77400b622 | 165 | }; |
Mike Fiore |
14:f9a77400b622 | 166 | |
Mike Fiore |
14:f9a77400b622 | 167 | const verify_ptr_t CommandTerminal::_verify[NO_OF_COMMANDS] = { |
Mike Fiore |
14:f9a77400b622 | 168 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 169 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 170 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 171 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 172 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 173 | CmdDummy::verify, |
Mike Fiore |
1:e52ae6584f1c | 174 | |
Mike Fiore |
14:f9a77400b622 | 175 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 176 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 177 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 178 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 179 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 180 | CmdSerialBaudRate::verify, |
Mike Fiore |
14:f9a77400b622 | 181 | CmdDebugBaudRate::verify, |
Mike Fiore |
14:f9a77400b622 | 182 | CmdStartUpMode::verify, |
Mike Fiore |
14:f9a77400b622 | 183 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 184 | CmdDefaultFrequencyBand::verify, |
Mike Fiore |
14:f9a77400b622 | 185 | CmdFrequencyBand::verify, |
Mike Fiore |
14:f9a77400b622 | 186 | CmdFrequencySubBand::verify, |
Mike Fiore |
14:f9a77400b622 | 187 | CmdPublicNetwork::verify, |
Mike Fiore |
14:f9a77400b622 | 188 | CmdDeviceId::verify, |
Mike Fiore |
14:f9a77400b622 | 189 | CmdDeviceClass::verify, |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 190 | CmdLbt::verify, |
Mike Fiore |
1:e52ae6584f1c | 191 | |
Mike Fiore |
14:f9a77400b622 | 192 | CmdAppPort::verify, |
Mike Fiore |
14:f9a77400b622 | 193 | CmdNetworkAddress::verify, |
Mike Fiore |
14:f9a77400b622 | 194 | CmdNetworkSessionKey::verify, |
Mike Fiore |
14:f9a77400b622 | 195 | CmdDataSessionKey::verify, |
Mike Fiore |
14:f9a77400b622 | 196 | CmdUplinkCounter::verify, |
Mike Fiore |
14:f9a77400b622 | 197 | CmdDownlinkCounter::verify, |
Mike Fiore |
14:f9a77400b622 | 198 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 199 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 200 | CmdNetworkKey::verify, |
Mike Fiore |
14:f9a77400b622 | 201 | CmdNetworkId::verify, |
Mike Fiore |
14:f9a77400b622 | 202 | |
Mike Fiore |
14:f9a77400b622 | 203 | CmdJoinDelay::verify, |
Mike Fiore |
14:f9a77400b622 | 204 | // Remove join settings commands until valid case for changing default settings |
Mike Fiore |
14:f9a77400b622 | 205 | // CmdJoinRx1Offset::verify, |
Mike Fiore |
14:f9a77400b622 | 206 | // CmdJoinRx2Datarate::verify, |
Mike Fiore |
14:f9a77400b622 | 207 | // CmdJoinRx2Frequency::verify, |
Mike Fiore |
14:f9a77400b622 | 208 | CmdJoinRequest::verify, |
Mike Fiore |
14:f9a77400b622 | 209 | CmdJoinRetries::verify, |
Mike Fiore |
14:f9a77400b622 | 210 | CmdJoinByteOrder::verify, |
Mike Fiore |
14:f9a77400b622 | 211 | CmdNetworkJoinMode::verify, |
Mike Fiore |
14:f9a77400b622 | 212 | CmdPreserveSession::verify, |
Mike Fiore |
14:f9a77400b622 | 213 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 214 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 215 | CmdLinkCheckCount::verify, |
Mike Fiore |
14:f9a77400b622 | 216 | CmdLinkCheckThreshold::verify, |
Mike Fiore |
14:f9a77400b622 | 217 | CmdEncryption::verify, |
Mike Fiore |
14:f9a77400b622 | 218 | |
Mike Fiore |
14:f9a77400b622 | 219 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 220 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 221 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 222 | |
Mike Fiore |
14:f9a77400b622 | 223 | CmdSessionDataRate::verify, |
Mike Fiore |
14:f9a77400b622 | 224 | CmdChannelMask::verify, |
Mike Fiore |
1:e52ae6584f1c | 225 | |
Mike Fiore |
14:f9a77400b622 | 226 | CmdTxDataRate::verify, |
Mike Fiore |
14:f9a77400b622 | 227 | CmdTxPower::verify, |
Mike Fiore |
14:f9a77400b622 | 228 | CmdAntennaGain::verify, |
Mike Fiore |
14:f9a77400b622 | 229 | CmdTxFrequency::verify, |
Mike Fiore |
14:f9a77400b622 | 230 | CmdTxInverted::verify, |
Mike Fiore |
14:f9a77400b622 | 231 | CmdTxWait::verify, |
Mike Fiore |
14:f9a77400b622 | 232 | CmdTxChannel::verify, |
Mike Fiore |
14:f9a77400b622 | 233 | CmdTxNextMs::verify, |
Mike Fiore |
14:f9a77400b622 | 234 | CmdTimeOnAir::verify, |
Mike Fiore |
14:f9a77400b622 | 235 | |
Mike Fiore |
14:f9a77400b622 | 236 | CmdRxDelay::verify, |
Mike Fiore |
14:f9a77400b622 | 237 | CmdRxOutput::verify, |
Mike Fiore |
14:f9a77400b622 | 238 | CmdRxInverted::verify, |
Mike Fiore |
14:f9a77400b622 | 239 | |
Mike Fiore |
14:f9a77400b622 | 240 | CmdErrorCorrection::verify, |
Mike Fiore |
14:f9a77400b622 | 241 | CmdCRC::verify, |
Mike Fiore |
14:f9a77400b622 | 242 | CmdAdaptiveDataRate::verify, |
Mike Fiore |
14:f9a77400b622 | 243 | |
Mike Fiore |
14:f9a77400b622 | 244 | CmdACKAttempts::verify, |
Mike Fiore |
14:f9a77400b622 | 245 | CmdRepeat::verify, |
Mike Fiore |
14:f9a77400b622 | 246 | CmdMacCmd::verify, |
Mike Fiore |
14:f9a77400b622 | 247 | |
Mike Fiore |
14:f9a77400b622 | 248 | CmdSendString::verify, |
Mike Fiore |
14:f9a77400b622 | 249 | CmdSendBinary::verify, |
Mike Fiore |
14:f9a77400b622 | 250 | CmdReceiveOnce::verify, |
Mike Fiore |
14:f9a77400b622 | 251 | |
Mike Fiore |
14:f9a77400b622 | 252 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 253 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 254 | CmdSerialClearOnError::verify, |
Mike Fiore |
14:f9a77400b622 | 255 | CmdWakeMode::verify, |
Mike Fiore |
14:f9a77400b622 | 256 | CmdWakeInterval::verify, |
Mike Fiore |
14:f9a77400b622 | 257 | CmdWakePin::verify, |
Mike Fiore |
14:f9a77400b622 | 258 | CmdWakeDelay::verify, |
Mike Fiore |
14:f9a77400b622 | 259 | CmdWakeTimeout::verify, |
Mike Fiore |
14:f9a77400b622 | 260 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 261 | CmdLogLevel::verify, |
Mike Fiore |
14:f9a77400b622 | 262 | |
Mike Fiore |
14:f9a77400b622 | 263 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 264 | CmdRxDataRate::verify, |
Mike Fiore |
14:f9a77400b622 | 265 | CmdRxFrequency::verify, |
Mike Fiore |
14:f9a77400b622 | 266 | CmdReceiveContinuous::verify, |
Mike Fiore |
14:f9a77400b622 | 267 | CmdSendStringOnInterval::verify, |
Mike Fiore |
1:e52ae6584f1c | 268 | |
Mike Fiore |
14:f9a77400b622 | 269 | #ifdef MTS_RADIO_DEBUG_COMMANDS |
Mike Fiore |
14:f9a77400b622 | 270 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 271 | CmdSendContinuous::verify, |
Mike Fiore |
14:f9a77400b622 | 272 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 273 | CmdDummy::verify, |
Mike Fiore |
14:f9a77400b622 | 274 | CmdEraseFlash::verify, |
Mike Fiore |
14:f9a77400b622 | 275 | CmdDisableDutyCycle::verify, |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 276 | CmdLBTRSSI::verify, |
Mike Fiore |
14:f9a77400b622 | 277 | #endif |
Mike Fiore |
1:e52ae6584f1c | 278 | |
Mike Fiore |
14:f9a77400b622 | 279 | }; |
Mike Fiore |
14:f9a77400b622 | 280 | |
Mike Fiore |
14:f9a77400b622 | 281 | const action_ptr_t CommandTerminal::_action[NO_OF_COMMANDS] = { |
Mike Fiore |
14:f9a77400b622 | 282 | CmdAttention::action, |
Mike Fiore |
14:f9a77400b622 | 283 | CmdIdentification::action, |
Mike Fiore |
14:f9a77400b622 | 284 | CmdResetCpu::action, |
Mike Fiore |
14:f9a77400b622 | 285 | CmdDummy::action, |
Mike Fiore |
14:f9a77400b622 | 286 | CmdDummy::action, |
Mike Fiore |
14:f9a77400b622 | 287 | CmdDummy::action, |
Mike Fiore |
9:ff62b20f7000 | 288 | |
Mike Fiore |
14:f9a77400b622 | 289 | CmdFactoryDefault::action, |
Mike Fiore |
14:f9a77400b622 | 290 | CmdSaveConfig::action, |
Mike Fiore |
14:f9a77400b622 | 291 | CmdDisplayConfig::action, |
Mike Fiore |
14:f9a77400b622 | 292 | CmdDisplayStats::action, |
Mike Fiore |
14:f9a77400b622 | 293 | CmdResetStats::action, |
Mike Fiore |
14:f9a77400b622 | 294 | CmdSerialBaudRate::action, |
Mike Fiore |
14:f9a77400b622 | 295 | CmdDebugBaudRate::action, |
Mike Fiore |
14:f9a77400b622 | 296 | CmdStartUpMode::action, |
Mike Fiore |
14:f9a77400b622 | 297 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 298 | CmdDefaultFrequencyBand::action, |
Mike Fiore |
14:f9a77400b622 | 299 | CmdFrequencyBand::action, |
Mike Fiore |
14:f9a77400b622 | 300 | CmdFrequencySubBand::action, |
Mike Fiore |
14:f9a77400b622 | 301 | CmdPublicNetwork::action, |
Mike Fiore |
14:f9a77400b622 | 302 | CmdDeviceId::action, |
Mike Fiore |
14:f9a77400b622 | 303 | CmdDeviceClass::action, |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 304 | CmdLbt::action, |
Mike Fiore |
14:f9a77400b622 | 305 | |
Mike Fiore |
14:f9a77400b622 | 306 | CmdAppPort::action, |
Mike Fiore |
14:f9a77400b622 | 307 | CmdNetworkAddress::action, |
Mike Fiore |
14:f9a77400b622 | 308 | CmdNetworkSessionKey::action, |
Mike Fiore |
14:f9a77400b622 | 309 | CmdDataSessionKey::action, |
Mike Fiore |
14:f9a77400b622 | 310 | CmdUplinkCounter::action, |
Mike Fiore |
14:f9a77400b622 | 311 | CmdDownlinkCounter::action, |
Mike Fiore |
14:f9a77400b622 | 312 | CmdSaveSession::action, |
Mike Fiore |
14:f9a77400b622 | 313 | CmdRestoreSession::action, |
Mike Fiore |
14:f9a77400b622 | 314 | CmdNetworkKey::action, |
Mike Fiore |
14:f9a77400b622 | 315 | CmdNetworkId::action, |
Mike Fiore |
1:e52ae6584f1c | 316 | |
Mike Fiore |
14:f9a77400b622 | 317 | CmdJoinDelay::action, |
Mike Fiore |
14:f9a77400b622 | 318 | // Remove join settings commands until valid case for changing default settings |
Mike Fiore |
14:f9a77400b622 | 319 | // CmdJoinRx1Offset::action, |
Mike Fiore |
14:f9a77400b622 | 320 | // CmdJoinRx2Datarate::action, |
Mike Fiore |
14:f9a77400b622 | 321 | // CmdJoinRx2Frequency::action, |
Mike Fiore |
14:f9a77400b622 | 322 | CmdJoinRequest::action, |
Mike Fiore |
14:f9a77400b622 | 323 | CmdJoinRetries::action, |
Mike Fiore |
14:f9a77400b622 | 324 | CmdJoinByteOrder::action, |
Mike Fiore |
14:f9a77400b622 | 325 | CmdNetworkJoinMode::action, |
Mike Fiore |
14:f9a77400b622 | 326 | CmdPreserveSession::action, |
Mike Fiore |
14:f9a77400b622 | 327 | CmdNetworkJoinStatus::action, |
Mike Fiore |
14:f9a77400b622 | 328 | CmdNetworkLinkCheck::action, |
Mike Fiore |
14:f9a77400b622 | 329 | CmdLinkCheckCount::action, |
Mike Fiore |
14:f9a77400b622 | 330 | CmdLinkCheckThreshold::action, |
Mike Fiore |
14:f9a77400b622 | 331 | CmdEncryption::action, |
Mike Fiore |
14:f9a77400b622 | 332 | |
Mike Fiore |
14:f9a77400b622 | 333 | CmdRssi::action, |
Mike Fiore |
14:f9a77400b622 | 334 | CmdSnr::action, |
Mike Fiore |
14:f9a77400b622 | 335 | CmdDataPending::action, |
Mike Fiore |
1:e52ae6584f1c | 336 | |
Mike Fiore |
14:f9a77400b622 | 337 | CmdSessionDataRate::action, |
Mike Fiore |
14:f9a77400b622 | 338 | CmdChannelMask::action, |
Mike Fiore |
1:e52ae6584f1c | 339 | |
Mike Fiore |
14:f9a77400b622 | 340 | CmdTxDataRate::action, |
Mike Fiore |
14:f9a77400b622 | 341 | CmdTxPower::action, |
Mike Fiore |
14:f9a77400b622 | 342 | CmdAntennaGain::action, |
Mike Fiore |
14:f9a77400b622 | 343 | CmdTxFrequency::action, |
Mike Fiore |
14:f9a77400b622 | 344 | CmdTxInverted::action, |
Mike Fiore |
14:f9a77400b622 | 345 | CmdTxWait::action, |
Mike Fiore |
14:f9a77400b622 | 346 | CmdTxChannel::action, |
Mike Fiore |
14:f9a77400b622 | 347 | CmdTxNextMs::action, |
Mike Fiore |
14:f9a77400b622 | 348 | CmdTimeOnAir::action, |
Mike Fiore |
1:e52ae6584f1c | 349 | |
Mike Fiore |
14:f9a77400b622 | 350 | CmdRxDelay::action, |
Mike Fiore |
14:f9a77400b622 | 351 | CmdRxOutput::action, |
Mike Fiore |
14:f9a77400b622 | 352 | CmdRxInverted::action, |
Mike Fiore |
14:f9a77400b622 | 353 | |
Mike Fiore |
14:f9a77400b622 | 354 | CmdErrorCorrection::action, |
Mike Fiore |
14:f9a77400b622 | 355 | CmdCRC::action, |
Mike Fiore |
14:f9a77400b622 | 356 | CmdAdaptiveDataRate::action, |
Mike Fiore |
14:f9a77400b622 | 357 | |
Mike Fiore |
14:f9a77400b622 | 358 | CmdACKAttempts::action, |
Mike Fiore |
14:f9a77400b622 | 359 | CmdRepeat::action, |
Mike Fiore |
14:f9a77400b622 | 360 | CmdMacCmd::action, |
Mike Fiore |
1:e52ae6584f1c | 361 | |
Mike Fiore |
14:f9a77400b622 | 362 | CmdSendString::action, |
Mike Fiore |
14:f9a77400b622 | 363 | CmdSendBinary::action, |
Mike Fiore |
14:f9a77400b622 | 364 | CmdReceiveOnce::action, |
Mike Fiore |
14:f9a77400b622 | 365 | |
Mike Fiore |
14:f9a77400b622 | 366 | CmdDummy::action, |
Mike Fiore |
14:f9a77400b622 | 367 | CmdDummy::action, |
Mike Fiore |
14:f9a77400b622 | 368 | CmdSerialClearOnError::action, |
Mike Fiore |
14:f9a77400b622 | 369 | CmdWakeMode::action, |
Mike Fiore |
14:f9a77400b622 | 370 | CmdWakeInterval::action, |
Mike Fiore |
14:f9a77400b622 | 371 | CmdWakePin::action, |
Mike Fiore |
14:f9a77400b622 | 372 | CmdWakeDelay::action, |
Mike Fiore |
14:f9a77400b622 | 373 | CmdWakeTimeout::action, |
Mike Fiore |
14:f9a77400b622 | 374 | CmdPing::action, |
Mike Fiore |
14:f9a77400b622 | 375 | CmdLogLevel::action, |
Mike Fiore |
14:f9a77400b622 | 376 | |
Mike Fiore |
14:f9a77400b622 | 377 | CmdDummy::action, |
Mike Fiore |
14:f9a77400b622 | 378 | CmdRxDataRate::action, |
Mike Fiore |
14:f9a77400b622 | 379 | CmdRxFrequency::action, |
Mike Fiore |
14:f9a77400b622 | 380 | CmdReceiveContinuous::action, |
Mike Fiore |
14:f9a77400b622 | 381 | CmdSendStringOnInterval::action, |
Mike Fiore |
9:ff62b20f7000 | 382 | |
Mike Fiore |
14:f9a77400b622 | 383 | #ifdef MTS_RADIO_DEBUG_COMMANDS |
Mike Fiore |
14:f9a77400b622 | 384 | CmdDummy::action, |
Mike Fiore |
14:f9a77400b622 | 385 | CmdSendContinuous::action, |
Mike Fiore |
14:f9a77400b622 | 386 | CmdWriteProtectedConfig::action, |
Mike Fiore |
14:f9a77400b622 | 387 | CmdDumpRegisters::action, |
Mike Fiore |
14:f9a77400b622 | 388 | CmdEraseFlash::action, |
Mike Fiore |
14:f9a77400b622 | 389 | CmdDisableDutyCycle::action, |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 390 | CmdLBTRSSI::action, |
Mike Fiore |
14:f9a77400b622 | 391 | #endif |
Mike Fiore |
14:f9a77400b622 | 392 | |
Mike Fiore |
14:f9a77400b622 | 393 | }; |
Mike Fiore |
14:f9a77400b622 | 394 | |
Mike Fiore |
14:f9a77400b622 | 395 | CommandTerminal::CommandTerminal(mts::ATSerial& serial) : |
Mike Fiore |
14:f9a77400b622 | 396 | _serial(serial), |
Mike Fiore |
14:f9a77400b622 | 397 | _mode(mDot::COMMAND_MODE), |
Mike Fiore |
14:f9a77400b622 | 398 | _sleep_standby(true), |
Mike Fiore |
14:f9a77400b622 | 399 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
14:f9a77400b622 | 400 | _xbee_on_sleep(XBEE_ON_SLEEP), |
Mike Fiore |
14:f9a77400b622 | 401 | #else |
Mike Fiore |
14:f9a77400b622 | 402 | _xbee_on_sleep(GPIO2), |
Mike Fiore |
14:f9a77400b622 | 403 | #endif |
Mike Fiore |
14:f9a77400b622 | 404 | _autoOTAEnabled(false) |
Mike Fiore |
14:f9a77400b622 | 405 | { |
Mike Fiore |
14:f9a77400b622 | 406 | _serialp = &serial; |
Mike Fiore |
14:f9a77400b622 | 407 | } |
Mike Fiore |
14:f9a77400b622 | 408 | |
Mike Fiore |
14:f9a77400b622 | 409 | void CommandTerminal::init() { |
Mike Fiore |
14:f9a77400b622 | 410 | _dot->setEvents(_events); |
Mike Fiore |
1:e52ae6584f1c | 411 | } |
Mike Fiore |
1:e52ae6584f1c | 412 | |
Mike Fiore |
1:e52ae6584f1c | 413 | void CommandTerminal::printHelp() { |
Mike Fiore |
1:e52ae6584f1c | 414 | const char* name = NULL; |
Mike Fiore |
1:e52ae6584f1c | 415 | const char* text = NULL; |
Mike Fiore |
1:e52ae6584f1c | 416 | const char* desc = NULL; |
Mike Fiore |
1:e52ae6584f1c | 417 | const char* tab = "\t"; |
Mike Fiore |
1:e52ae6584f1c | 418 | |
Mike Fiore |
1:e52ae6584f1c | 419 | std::string header("Command"); |
Mike Fiore |
1:e52ae6584f1c | 420 | header.append(tab); |
Mike Fiore |
1:e52ae6584f1c | 421 | header.append(tab); |
Mike Fiore |
1:e52ae6584f1c | 422 | header.append("Name"); |
Mike Fiore |
1:e52ae6584f1c | 423 | header.append(tab); |
Mike Fiore |
1:e52ae6584f1c | 424 | header.append(tab); |
Mike Fiore |
1:e52ae6584f1c | 425 | header.append(tab); |
Mike Fiore |
1:e52ae6584f1c | 426 | header.append("Description"); |
Mike Fiore |
1:e52ae6584f1c | 427 | |
Mike Fiore |
1:e52ae6584f1c | 428 | write(newline); |
Mike Fiore |
1:e52ae6584f1c | 429 | write(header.c_str()); |
Mike Fiore |
1:e52ae6584f1c | 430 | write(newline); |
Mike Fiore |
1:e52ae6584f1c | 431 | write(newline); |
Mike Fiore |
14:f9a77400b622 | 432 | |
Mike Fiore |
14:f9a77400b622 | 433 | for (int i = 0; i < NO_OF_COMMANDS; i++) { |
Mike Fiore |
14:f9a77400b622 | 434 | name = _commands[i].name(); |
Mike Fiore |
14:f9a77400b622 | 435 | text = _commands[i].text(); |
Mike Fiore |
14:f9a77400b622 | 436 | desc = _commands[i].desc(); |
Mike Fiore |
1:e52ae6584f1c | 437 | write(text); |
Mike Fiore |
1:e52ae6584f1c | 438 | if (strlen(text) < 8) |
Mike Fiore |
1:e52ae6584f1c | 439 | write(tab); |
Mike Fiore |
1:e52ae6584f1c | 440 | write(tab); |
Mike Fiore |
1:e52ae6584f1c | 441 | write(name); |
Mike Fiore |
1:e52ae6584f1c | 442 | if (strlen(name) < 8) |
Mike Fiore |
1:e52ae6584f1c | 443 | write(tab); |
Mike Fiore |
1:e52ae6584f1c | 444 | if (strlen(name) < 16) |
Mike Fiore |
1:e52ae6584f1c | 445 | write(tab); |
Mike Fiore |
1:e52ae6584f1c | 446 | write(tab); |
Mike Fiore |
1:e52ae6584f1c | 447 | write(desc); |
Mike Fiore |
1:e52ae6584f1c | 448 | write(newline); |
Mike Fiore |
1:e52ae6584f1c | 449 | } |
Mike Fiore |
1:e52ae6584f1c | 450 | |
Mike Fiore |
1:e52ae6584f1c | 451 | write(newline); |
Mike Fiore |
1:e52ae6584f1c | 452 | } |
Mike Fiore |
1:e52ae6584f1c | 453 | |
Mike Fiore |
1:e52ae6584f1c | 454 | bool CommandTerminal::writeable() { |
Mike Fiore |
14:f9a77400b622 | 455 | return _serialp->writeable(); |
Mike Fiore |
1:e52ae6584f1c | 456 | } |
Mike Fiore |
1:e52ae6584f1c | 457 | |
Mike Fiore |
1:e52ae6584f1c | 458 | bool CommandTerminal::readable() { |
Mike Fiore |
14:f9a77400b622 | 459 | return _serialp->readable(); |
Mike Fiore |
1:e52ae6584f1c | 460 | } |
Mike Fiore |
1:e52ae6584f1c | 461 | |
Mike Fiore |
1:e52ae6584f1c | 462 | char CommandTerminal::read() { |
Mike Fiore |
1:e52ae6584f1c | 463 | char ch; |
Mike Fiore |
14:f9a77400b622 | 464 | _serialp->read(&ch, 1); |
Mike Fiore |
1:e52ae6584f1c | 465 | return ch; |
Mike Fiore |
1:e52ae6584f1c | 466 | } |
Mike Fiore |
1:e52ae6584f1c | 467 | |
Mike Fiore |
1:e52ae6584f1c | 468 | void CommandTerminal::write(const char* message) { |
Mike Fiore |
1:e52ae6584f1c | 469 | while (!writeable()) |
Mike Fiore |
1:e52ae6584f1c | 470 | ; |
Mike Fiore |
14:f9a77400b622 | 471 | _serialp->write(message, strlen(message)); |
Mike Fiore |
1:e52ae6584f1c | 472 | } |
Mike Fiore |
1:e52ae6584f1c | 473 | |
Mike Fiore |
1:e52ae6584f1c | 474 | void CommandTerminal::writef(const char* format, ...) { |
Mike Fiore |
1:e52ae6584f1c | 475 | char buff[256]; |
Mike Fiore |
1:e52ae6584f1c | 476 | |
Mike Fiore |
1:e52ae6584f1c | 477 | va_list ap; |
Mike Fiore |
1:e52ae6584f1c | 478 | va_start(ap, format); |
Mike Fiore |
1:e52ae6584f1c | 479 | int size = vsnprintf(buff, 256, format, ap); |
Mike Fiore |
1:e52ae6584f1c | 480 | while (!writeable()) |
Mike Fiore |
1:e52ae6584f1c | 481 | ; |
Mike Fiore |
14:f9a77400b622 | 482 | _serialp->write(buff, size); |
Mike Fiore |
1:e52ae6584f1c | 483 | va_end(ap); |
Mike Fiore |
1:e52ae6584f1c | 484 | } |
Mike Fiore |
1:e52ae6584f1c | 485 | |
Mike Fiore |
9:ff62b20f7000 | 486 | void CommandTerminal::serialLoop() { |
Mike Fiore |
1:e52ae6584f1c | 487 | Timer serial_read_timer; |
Mike Fiore |
1:e52ae6584f1c | 488 | std::vector<uint8_t> serial_buffer; |
Mike Fiore |
9:ff62b20f7000 | 489 | std::vector<uint8_t> data; |
Mike Fiore |
9:ff62b20f7000 | 490 | int timeout = 0; |
Mike Fiore |
1:e52ae6584f1c | 491 | |
Mike Fiore |
9:ff62b20f7000 | 492 | serial_read_timer.start(); |
Mike Fiore |
1:e52ae6584f1c | 493 | |
Mike Fiore |
9:ff62b20f7000 | 494 | if (_dot->getStartUpMode() == mDot::SERIAL_MODE) { |
Mike Fiore |
9:ff62b20f7000 | 495 | _xbee_on_sleep = GPIO_PIN_SET; |
Mike Fiore |
1:e52ae6584f1c | 496 | |
Mike Fiore |
9:ff62b20f7000 | 497 | timeout = _dot->getWakeDelay(); |
Mike Fiore |
1:e52ae6584f1c | 498 | |
Mike Fiore |
9:ff62b20f7000 | 499 | // wait for timeout or start of serial data |
Mike Fiore |
14:f9a77400b622 | 500 | while (!readable() && serial_read_timer.read_ms() < timeout && !_serialp->escaped()) { |
Mike Fiore |
9:ff62b20f7000 | 501 | osDelay(2); |
Mike Fiore |
1:e52ae6584f1c | 502 | } |
Mike Fiore |
1:e52ae6584f1c | 503 | } |
Mike Fiore |
1:e52ae6584f1c | 504 | |
Mike Fiore |
14:f9a77400b622 | 505 | if (!readable() && _events->SendAck()) { |
Mike Fiore |
14:f9a77400b622 | 506 | logDebug("SERIAL NOT READABLE and ACK REQUESTED"); |
Mike Fiore |
14:f9a77400b622 | 507 | goto L_SEND; |
Mike Fiore |
14:f9a77400b622 | 508 | } |
Mike Fiore |
14:f9a77400b622 | 509 | |
Mike Fiore |
14:f9a77400b622 | 510 | if (readable() && !_serialp->escaped()) { |
Mike Fiore |
6:e27eaad36a0c | 511 | |
Mike Fiore |
6:e27eaad36a0c | 512 | serial_read_timer.reset(); |
Mike Fiore |
6:e27eaad36a0c | 513 | timeout = _dot->getWakeTimeout(); |
Mike Fiore |
9:ff62b20f7000 | 514 | |
Mike Fiore |
9:ff62b20f7000 | 515 | while (serial_read_timer.read_ms() < timeout && serial_buffer.size() <= _dot->getMaxPacketLength()) { |
Mike Fiore |
9:ff62b20f7000 | 516 | while (readable() && serial_buffer.size() < _dot->getMaxPacketLength()) { |
Mike Fiore |
1:e52ae6584f1c | 517 | serial_buffer.push_back(read()); |
Mike Fiore |
1:e52ae6584f1c | 518 | serial_read_timer.reset(); |
Mike Fiore |
9:ff62b20f7000 | 519 | |
Mike Fiore |
14:f9a77400b622 | 520 | if (_serialp->escaped()) |
Mike Fiore |
9:ff62b20f7000 | 521 | break; |
Mike Fiore |
1:e52ae6584f1c | 522 | } |
Mike Fiore |
1:e52ae6584f1c | 523 | } |
Mike Fiore |
9:ff62b20f7000 | 524 | |
Mike Fiore |
1:e52ae6584f1c | 525 | serial_read_timer.stop(), serial_read_timer.reset(); |
Mike Fiore |
1:e52ae6584f1c | 526 | |
Mike Fiore |
1:e52ae6584f1c | 527 | if (!serial_buffer.empty()) { |
Mike Fiore |
9:ff62b20f7000 | 528 | if (_dot->getStartUpMode() == mDot::SERIAL_MODE) |
Mike Fiore |
14:f9a77400b622 | 529 | _xbee_on_sleep = GPIO_PIN_RESET; |
Mike Fiore |
9:ff62b20f7000 | 530 | |
Mike Fiore |
14:f9a77400b622 | 531 | L_SEND: |
Mike Fiore |
9:ff62b20f7000 | 532 | // wait for any duty cycle limit to expire |
Mike Fiore |
14:f9a77400b622 | 533 | while (_dot->getNextTxMs() > 0 && !_serialp->escaped()) { |
Mike Fiore |
9:ff62b20f7000 | 534 | osDelay(10); |
Mike Fiore |
9:ff62b20f7000 | 535 | } |
Mike Fiore |
9:ff62b20f7000 | 536 | |
Mike Fiore |
14:f9a77400b622 | 537 | if (_dot->getIsIdle()) { |
Mike Fiore |
9:ff62b20f7000 | 538 | logDebug("Received serial data, sending out radio."); |
Mike Fiore |
9:ff62b20f7000 | 539 | |
Mike Fiore |
9:ff62b20f7000 | 540 | if (_dot->send(serial_buffer, false) != mDot::MDOT_OK) { |
Mike Fiore |
9:ff62b20f7000 | 541 | logDebug("Send failed."); |
Mike Fiore |
9:ff62b20f7000 | 542 | // If the data should be tossed after send failure, clear buffer |
Mike Fiore |
9:ff62b20f7000 | 543 | if (_dot->getSerialClearOnError()) { |
Mike Fiore |
9:ff62b20f7000 | 544 | serial_buffer.clear(); |
Mike Fiore |
9:ff62b20f7000 | 545 | } |
Mike Fiore |
9:ff62b20f7000 | 546 | } else { |
Mike Fiore |
1:e52ae6584f1c | 547 | |
Mike Fiore |
9:ff62b20f7000 | 548 | // wait for send to finish |
Mike Fiore |
14:f9a77400b622 | 549 | while (!_dot->getIsIdle() && !_serialp->escaped()) { |
Mike Fiore |
9:ff62b20f7000 | 550 | osDelay(10); |
Mike Fiore |
14:f9a77400b622 | 551 | } |
Mike Fiore |
9:ff62b20f7000 | 552 | |
Mike Fiore |
9:ff62b20f7000 | 553 | // call recv to wait for any packet before sending again |
Mike Fiore |
14:f9a77400b622 | 554 | if (!_serialp->escaped()) |
Mike Fiore |
9:ff62b20f7000 | 555 | _dot->recv(data); |
Mike Fiore |
9:ff62b20f7000 | 556 | |
Mike Fiore |
9:ff62b20f7000 | 557 | // Clear the serial buffer if send is success |
Mike Fiore |
9:ff62b20f7000 | 558 | serial_buffer.clear(); |
Mike Fiore |
14:f9a77400b622 | 559 | |
Mike Fiore |
14:f9a77400b622 | 560 | // In class C mode pending data will be sent automatically without uplink |
Mike Fiore |
14:f9a77400b622 | 561 | if (_dot->getClass() != "C") { |
Mike Fiore |
14:f9a77400b622 | 562 | if (_dot->getDataPending()) { |
Mike Fiore |
14:f9a77400b622 | 563 | logDebug("Data is pending"); |
Mike Fiore |
14:f9a77400b622 | 564 | goto L_SEND; |
Mike Fiore |
14:f9a77400b622 | 565 | } |
Mike Fiore |
14:f9a77400b622 | 566 | if (_dot->getAckRequested()) { |
Mike Fiore |
14:f9a77400b622 | 567 | logDebug("Ack requested"); |
Mike Fiore |
14:f9a77400b622 | 568 | goto L_SEND; |
Mike Fiore |
14:f9a77400b622 | 569 | } |
Mike Fiore |
14:f9a77400b622 | 570 | } |
Mike Fiore |
9:ff62b20f7000 | 571 | } |
Mike Fiore |
1:e52ae6584f1c | 572 | } else { |
Mike Fiore |
6:e27eaad36a0c | 573 | logDebug("Radio is busy, cannot send.\r\n"); |
Mike Fiore |
9:ff62b20f7000 | 574 | osDelay(10); |
Mike Fiore |
1:e52ae6584f1c | 575 | } |
Mike Fiore |
1:e52ae6584f1c | 576 | |
Mike Fiore |
1:e52ae6584f1c | 577 | } else { |
Mike Fiore |
6:e27eaad36a0c | 578 | logDebug("No data received from serial to send.\r\n"); |
Mike Fiore |
1:e52ae6584f1c | 579 | } |
Mike Fiore |
9:ff62b20f7000 | 580 | } |
Mike Fiore |
9:ff62b20f7000 | 581 | |
Mike Fiore |
14:f9a77400b622 | 582 | if (!_serialp->readable() && _dot->getStartUpMode() == mDot::SERIAL_MODE && !_serialp->escaped()) { |
Mike Fiore |
14:f9a77400b622 | 583 | sleep(true); |
Mike Fiore |
1:e52ae6584f1c | 584 | } |
Mike Fiore |
9:ff62b20f7000 | 585 | |
Mike Fiore |
14:f9a77400b622 | 586 | if (_serialp->escaped()) { |
Mike Fiore |
14:f9a77400b622 | 587 | _serialp->clearEscaped(); |
Mike Fiore |
14:f9a77400b622 | 588 | _serialp->rxClear(); |
Mike Fiore |
9:ff62b20f7000 | 589 | serial_data_mode = false; |
Mike Fiore |
9:ff62b20f7000 | 590 | _mode = mDot::COMMAND_MODE; |
Mike Fiore |
9:ff62b20f7000 | 591 | logDebug("Exit Serial Mode"); |
Mike Fiore |
9:ff62b20f7000 | 592 | write(done); |
Mike Fiore |
9:ff62b20f7000 | 593 | return; |
Mike Fiore |
9:ff62b20f7000 | 594 | } |
Mike Fiore |
9:ff62b20f7000 | 595 | |
Mike Fiore |
9:ff62b20f7000 | 596 | if (!_dot->getNetworkJoinStatus()) { |
Mike Fiore |
9:ff62b20f7000 | 597 | serial_data_mode = false; |
Mike Fiore |
9:ff62b20f7000 | 598 | _mode = mDot::COMMAND_MODE; |
Mike Fiore |
9:ff62b20f7000 | 599 | logDebug("Exit Serial Mode"); |
Mike Fiore |
9:ff62b20f7000 | 600 | write(no_carrier); |
Mike Fiore |
9:ff62b20f7000 | 601 | return; |
Mike Fiore |
9:ff62b20f7000 | 602 | } |
Mike Fiore |
1:e52ae6584f1c | 603 | } |
Mike Fiore |
1:e52ae6584f1c | 604 | |
Mike Fiore |
1:e52ae6584f1c | 605 | bool CommandTerminal::autoJoinCheck() { |
Mike Fiore |
1:e52ae6584f1c | 606 | |
Mike Fiore |
1:e52ae6584f1c | 607 | std::string escape_buffer; |
Mike Fiore |
1:e52ae6584f1c | 608 | int sleep = 1000; |
Mike Fiore |
1:e52ae6584f1c | 609 | Timer tmr; |
Mike Fiore |
9:ff62b20f7000 | 610 | tmr.start(); |
Mike Fiore |
1:e52ae6584f1c | 611 | int cnt = 0; |
Mike Fiore |
1:e52ae6584f1c | 612 | |
Mike Fiore |
1:e52ae6584f1c | 613 | while (!_dot->getNetworkJoinStatus()) { |
Mike Fiore |
14:f9a77400b622 | 614 | if (!serial_data_mode) { |
Mike Fiore |
14:f9a77400b622 | 615 | write("\r\nJoining network... "); |
Mike Fiore |
14:f9a77400b622 | 616 | } |
Mike Fiore |
14:f9a77400b622 | 617 | logInfo("Joining network... "); |
Mike Fiore |
1:e52ae6584f1c | 618 | |
Mike Fiore |
9:ff62b20f7000 | 619 | if (_dot->getNextTxMs() > 0) { |
Mike Fiore |
14:f9a77400b622 | 620 | if (!serial_data_mode) { |
Mike Fiore |
14:f9a77400b622 | 621 | writef("\r\nWaiting %lu s before next join attempt\r\n", _dot->getNextTxMs() / 1000); |
Mike Fiore |
14:f9a77400b622 | 622 | } |
Mike Fiore |
14:f9a77400b622 | 623 | logInfo("Waiting %lu s before next join attempt", _dot->getNextTxMs() / 1000); |
Mike Fiore |
9:ff62b20f7000 | 624 | |
Mike Fiore |
9:ff62b20f7000 | 625 | tmr.reset(); |
Mike Fiore |
9:ff62b20f7000 | 626 | while (_dot->getNextTxMs() > 0 && !_serial.escaped()) { |
Mike Fiore |
14:f9a77400b622 | 627 | osDelay(20); |
Mike Fiore |
1:e52ae6584f1c | 628 | } |
Mike Fiore |
1:e52ae6584f1c | 629 | } |
Mike Fiore |
1:e52ae6584f1c | 630 | |
Mike Fiore |
9:ff62b20f7000 | 631 | if (!_serial.escaped() && _dot->joinNetworkOnce() == mDot::MDOT_OK) { |
Mike Fiore |
14:f9a77400b622 | 632 | if (!serial_data_mode) { |
Mike Fiore |
14:f9a77400b622 | 633 | write("Network Joined\r\n"); |
Mike Fiore |
14:f9a77400b622 | 634 | write(done); |
Mike Fiore |
14:f9a77400b622 | 635 | } |
Mike Fiore |
14:f9a77400b622 | 636 | logInfo("Network Joined"); |
Mike Fiore |
1:e52ae6584f1c | 637 | return false; |
Mike Fiore |
1:e52ae6584f1c | 638 | } |
Mike Fiore |
1:e52ae6584f1c | 639 | |
Mike Fiore |
14:f9a77400b622 | 640 | if (!serial_data_mode) { |
Mike Fiore |
14:f9a77400b622 | 641 | write("Network Join failed\r\n"); |
Mike Fiore |
14:f9a77400b622 | 642 | write(error); |
Mike Fiore |
14:f9a77400b622 | 643 | } |
Mike Fiore |
14:f9a77400b622 | 644 | logInfo("Network Join failed"); |
Mike Fiore |
1:e52ae6584f1c | 645 | |
Mike Fiore |
14:f9a77400b622 | 646 | if (!_serial.escaped() && _dot->getFrequencySubBand() != 0 && _dot->getJoinRetries() > 0 && cnt++ > _dot->getJoinRetries()) { |
Mike Fiore |
1:e52ae6584f1c | 647 | cnt = 0; |
Mike Fiore |
1:e52ae6584f1c | 648 | |
jenkins@jenkinsdm1 | 16:d5cf2af81a6d | 649 | if (lora::ChannelPlan::IsPlanFixed(_dot->getFrequencyBand())) { |
Mike Fiore |
1:e52ae6584f1c | 650 | uint8_t band = ((_dot->getFrequencySubBand()) % 8) + 1; |
Mike Fiore |
9:ff62b20f7000 | 651 | logWarning("Join retries exhausted, switching to sub band %u", band); |
Mike Fiore |
1:e52ae6584f1c | 652 | _dot->setFrequencySubBand(band); |
Mike Fiore |
1:e52ae6584f1c | 653 | } |
Mike Fiore |
1:e52ae6584f1c | 654 | } |
Mike Fiore |
1:e52ae6584f1c | 655 | |
Mike Fiore |
1:e52ae6584f1c | 656 | tmr.reset(); |
Mike Fiore |
9:ff62b20f7000 | 657 | while (tmr.read_ms() < sleep && !_serial.escaped()) { |
Mike Fiore |
9:ff62b20f7000 | 658 | osDelay(10); |
Mike Fiore |
1:e52ae6584f1c | 659 | } |
Mike Fiore |
1:e52ae6584f1c | 660 | |
Mike Fiore |
9:ff62b20f7000 | 661 | if (_serial.escaped()) { |
Mike Fiore |
9:ff62b20f7000 | 662 | _serial.clearEscaped(); |
Mike Fiore |
9:ff62b20f7000 | 663 | serial_data_mode = false; |
Mike Fiore |
9:ff62b20f7000 | 664 | _mode = mDot::COMMAND_MODE; |
Mike Fiore |
14:f9a77400b622 | 665 | if (!serial_data_mode) { |
Mike Fiore |
14:f9a77400b622 | 666 | write("Join Canceled\r\n"); |
Mike Fiore |
14:f9a77400b622 | 667 | write(done); |
Mike Fiore |
14:f9a77400b622 | 668 | } |
Mike Fiore |
14:f9a77400b622 | 669 | logInfo("Join Canceled\r\n"); |
Mike Fiore |
9:ff62b20f7000 | 670 | return true; |
Mike Fiore |
9:ff62b20f7000 | 671 | } |
Mike Fiore |
1:e52ae6584f1c | 672 | } |
Mike Fiore |
1:e52ae6584f1c | 673 | |
Mike Fiore |
1:e52ae6584f1c | 674 | return false; |
Mike Fiore |
1:e52ae6584f1c | 675 | } |
Mike Fiore |
1:e52ae6584f1c | 676 | |
Mike Fiore |
1:e52ae6584f1c | 677 | void CommandTerminal::start() { |
Mike Fiore |
1:e52ae6584f1c | 678 | |
Mike Fiore |
1:e52ae6584f1c | 679 | char ch; |
Mike Fiore |
1:e52ae6584f1c | 680 | bool running = true; |
Mike Fiore |
1:e52ae6584f1c | 681 | bool echo = _dot->getEcho(); |
Mike Fiore |
1:e52ae6584f1c | 682 | std::string command; |
Mike Fiore |
14:f9a77400b622 | 683 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
4:666017851052 | 684 | std::deque<std::string> history; |
Mike Fiore |
4:666017851052 | 685 | int history_index = -1; |
Mike Fiore |
14:f9a77400b622 | 686 | #endif |
Mike Fiore |
1:e52ae6584f1c | 687 | std::vector<std::string> args; |
Mike Fiore |
9:ff62b20f7000 | 688 | bool join_canceled = false; |
Mike Fiore |
1:e52ae6584f1c | 689 | |
Mike Fiore |
14:f9a77400b622 | 690 | _autoOTAEnabled = _dot->getJoinMode() == mDot::AUTO_OTA; |
Mike Fiore |
14:f9a77400b622 | 691 | |
Mike Fiore |
1:e52ae6584f1c | 692 | if (_dot->getStartUpMode() == mDot::SERIAL_MODE) { |
Mike Fiore |
9:ff62b20f7000 | 693 | |
Mike Fiore |
9:ff62b20f7000 | 694 | serial_data_mode = true; |
Mike Fiore |
9:ff62b20f7000 | 695 | _mode = mDot::SERIAL_MODE; |
Mike Fiore |
1:e52ae6584f1c | 696 | |
Mike Fiore |
1:e52ae6584f1c | 697 | std::string escape_buffer; |
Mike Fiore |
1:e52ae6584f1c | 698 | char ch; |
Mike Fiore |
1:e52ae6584f1c | 699 | |
Mike Fiore |
9:ff62b20f7000 | 700 | if (!_dot->getStandbyFlag()) { |
Mike Fiore |
9:ff62b20f7000 | 701 | // wake up from power-on/reset |
Mike Fiore |
9:ff62b20f7000 | 702 | |
Mike Fiore |
9:ff62b20f7000 | 703 | int escape_timeout = 1000; |
Mike Fiore |
9:ff62b20f7000 | 704 | Timer tmr; |
Mike Fiore |
9:ff62b20f7000 | 705 | Timer escape_tmr; |
Mike Fiore |
1:e52ae6584f1c | 706 | |
Mike Fiore |
9:ff62b20f7000 | 707 | // wait one second for possible escape by user pressing '+' key |
Mike Fiore |
9:ff62b20f7000 | 708 | tmr.reset(); |
Mike Fiore |
9:ff62b20f7000 | 709 | tmr.start(); |
Mike Fiore |
9:ff62b20f7000 | 710 | escape_tmr.reset(); |
Mike Fiore |
9:ff62b20f7000 | 711 | escape_tmr.start(); |
Mike Fiore |
9:ff62b20f7000 | 712 | while (tmr.read_ms() < escape_timeout) { |
Mike Fiore |
9:ff62b20f7000 | 713 | if (_serial.readable()) { |
Mike Fiore |
9:ff62b20f7000 | 714 | _serial.read(&ch, 1); |
Mike Fiore |
9:ff62b20f7000 | 715 | escape_buffer += ch; |
Mike Fiore |
9:ff62b20f7000 | 716 | } |
Mike Fiore |
1:e52ae6584f1c | 717 | |
Mike Fiore |
9:ff62b20f7000 | 718 | if (escape_buffer.find("+") != std::string::npos) { |
Mike Fiore |
9:ff62b20f7000 | 719 | logInfo("Escape detected"); |
Mike Fiore |
9:ff62b20f7000 | 720 | join_canceled = true; |
Mike Fiore |
9:ff62b20f7000 | 721 | serial_data_mode = false; |
Mike Fiore |
9:ff62b20f7000 | 722 | _mode = mDot::COMMAND_MODE; |
Mike Fiore |
9:ff62b20f7000 | 723 | command.clear(); |
Mike Fiore |
9:ff62b20f7000 | 724 | break; |
Mike Fiore |
9:ff62b20f7000 | 725 | } |
Mike Fiore |
9:ff62b20f7000 | 726 | |
Mike Fiore |
9:ff62b20f7000 | 727 | if (escape_tmr.read_ms() > escape_timeout) |
Mike Fiore |
9:ff62b20f7000 | 728 | escape_buffer.clear(); |
Mike Fiore |
9:ff62b20f7000 | 729 | |
Mike Fiore |
9:ff62b20f7000 | 730 | osDelay(1); |
Mike Fiore |
1:e52ae6584f1c | 731 | } |
Mike Fiore |
1:e52ae6584f1c | 732 | } |
Mike Fiore |
1:e52ae6584f1c | 733 | |
Mike Fiore |
9:ff62b20f7000 | 734 | if (_mode == mDot::SERIAL_MODE && !_dot->getNetworkJoinStatus() && _dot->getJoinMode() == mDot::OTA) { |
Mike Fiore |
9:ff62b20f7000 | 735 | if (_dot->joinNetworkOnce() != mDot::MDOT_OK) { |
Mike Fiore |
9:ff62b20f7000 | 736 | serial_data_mode = false; |
Mike Fiore |
9:ff62b20f7000 | 737 | _mode = mDot::COMMAND_MODE; |
Mike Fiore |
9:ff62b20f7000 | 738 | |
Mike Fiore |
9:ff62b20f7000 | 739 | logWarning("Start Up Mode set to SERIAL_MODE, but join failed."); |
Mike Fiore |
9:ff62b20f7000 | 740 | _serial.writef("Network Not Joined\r\n"); |
Mike Fiore |
9:ff62b20f7000 | 741 | _serial.writef(error); |
Mike Fiore |
9:ff62b20f7000 | 742 | } |
Mike Fiore |
9:ff62b20f7000 | 743 | } |
Mike Fiore |
1:e52ae6584f1c | 744 | } |
Mike Fiore |
1:e52ae6584f1c | 745 | |
Mike Fiore |
9:ff62b20f7000 | 746 | if (_dot->getJoinMode() == mDot::PEER_TO_PEER) { |
Mike Fiore |
9:ff62b20f7000 | 747 | peer_to_peer = true; |
Mike Fiore |
9:ff62b20f7000 | 748 | } else { |
Mike Fiore |
9:ff62b20f7000 | 749 | peer_to_peer = false; |
Mike Fiore |
9:ff62b20f7000 | 750 | } |
Mike Fiore |
9:ff62b20f7000 | 751 | |
Mike Fiore |
1:e52ae6584f1c | 752 | //Run terminal session |
Mike Fiore |
1:e52ae6584f1c | 753 | while (running) { |
Mike Fiore |
9:ff62b20f7000 | 754 | |
Mike Fiore |
9:ff62b20f7000 | 755 | // wait for input to reduce at command idle current |
Mike Fiore |
9:ff62b20f7000 | 756 | while (!readable() || _mode == mDot::SERIAL_MODE) { |
Mike Fiore |
14:f9a77400b622 | 757 | if (!join_canceled && _autoOTAEnabled) { |
Mike Fiore |
9:ff62b20f7000 | 758 | join_canceled = autoJoinCheck(); |
Mike Fiore |
9:ff62b20f7000 | 759 | if (join_canceled) |
Mike Fiore |
9:ff62b20f7000 | 760 | command.clear(); |
Mike Fiore |
9:ff62b20f7000 | 761 | } |
Mike Fiore |
1:e52ae6584f1c | 762 | |
Mike Fiore |
14:f9a77400b622 | 763 | if (!_autoOTAEnabled || (!join_canceled && _autoOTAEnabled)) { |
Mike Fiore |
9:ff62b20f7000 | 764 | switch (_mode) { |
Mike Fiore |
9:ff62b20f7000 | 765 | case mDot::SERIAL_MODE: |
Mike Fiore |
9:ff62b20f7000 | 766 | // signal wakeup, read serial and output to radio |
Mike Fiore |
9:ff62b20f7000 | 767 | serialLoop(); |
Mike Fiore |
9:ff62b20f7000 | 768 | continue; |
Mike Fiore |
9:ff62b20f7000 | 769 | break; |
Mike Fiore |
9:ff62b20f7000 | 770 | default: |
Mike Fiore |
9:ff62b20f7000 | 771 | break; |
Mike Fiore |
9:ff62b20f7000 | 772 | } |
Mike Fiore |
1:e52ae6584f1c | 773 | } |
Mike Fiore |
9:ff62b20f7000 | 774 | |
Mike Fiore |
9:ff62b20f7000 | 775 | ch = '\0'; |
Mike Fiore |
1:e52ae6584f1c | 776 | |
Mike Fiore |
9:ff62b20f7000 | 777 | wait(0.00001); // 10 us |
Mike Fiore |
9:ff62b20f7000 | 778 | _serial.escaped(); |
Mike Fiore |
9:ff62b20f7000 | 779 | } |
Mike Fiore |
1:e52ae6584f1c | 780 | |
Mike Fiore |
1:e52ae6584f1c | 781 | // read characters |
Mike Fiore |
1:e52ae6584f1c | 782 | if (readable()) { |
Mike Fiore |
1:e52ae6584f1c | 783 | ch = read(); |
Mike Fiore |
1:e52ae6584f1c | 784 | |
Mike Fiore |
4:666017851052 | 785 | if (ch == '\b' || ch == 0x7f) { |
Mike Fiore |
1:e52ae6584f1c | 786 | if (!command.empty()) { |
Mike Fiore |
1:e52ae6584f1c | 787 | writef("\b \b"); |
Mike Fiore |
1:e52ae6584f1c | 788 | command.erase(command.size() - 1); |
Mike Fiore |
1:e52ae6584f1c | 789 | } |
Mike Fiore |
1:e52ae6584f1c | 790 | continue; |
Mike Fiore |
4:666017851052 | 791 | } else if (ch == 0x1b || ch == 0x09) { |
Mike Fiore |
4:666017851052 | 792 | osDelay(20); |
Mike Fiore |
4:666017851052 | 793 | // catch escape sequence, or tab |
Mike Fiore |
9:ff62b20f7000 | 794 | char ch1 = 0x00, ch2 = 0x00; |
Mike Fiore |
4:666017851052 | 795 | |
Mike Fiore |
4:666017851052 | 796 | if (readable()) { |
Mike Fiore |
4:666017851052 | 797 | ch1 = read(); |
Mike Fiore |
4:666017851052 | 798 | if (readable()) |
Mike Fiore |
4:666017851052 | 799 | ch2 = read(); |
Mike Fiore |
4:666017851052 | 800 | |
Mike Fiore |
14:f9a77400b622 | 801 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
4:666017851052 | 802 | if (ch1 == 0x5b && ch2 == 0x41) { |
Mike Fiore |
4:666017851052 | 803 | // up key |
Mike Fiore |
9:ff62b20f7000 | 804 | for (size_t i = 0; i < command.size() + 1; i++) { |
Mike Fiore |
4:666017851052 | 805 | writef("\b \b"); |
Mike Fiore |
4:666017851052 | 806 | } |
Mike Fiore |
4:666017851052 | 807 | if (history.size() > 0) { |
Mike Fiore |
9:ff62b20f7000 | 808 | if (++history_index >= int(history.size() - 1)) |
Mike Fiore |
4:666017851052 | 809 | history_index = history.size() - 1; |
Mike Fiore |
4:666017851052 | 810 | |
Mike Fiore |
4:666017851052 | 811 | command = history[history_index]; |
Mike Fiore |
4:666017851052 | 812 | writef("%s", history[history_index].c_str()); |
Mike Fiore |
4:666017851052 | 813 | } else { |
Mike Fiore |
4:666017851052 | 814 | command.clear(); |
Mike Fiore |
4:666017851052 | 815 | } |
Mike Fiore |
4:666017851052 | 816 | } else if (ch1 == 0x5b && ch2 == 0x42) { |
Mike Fiore |
4:666017851052 | 817 | |
Mike Fiore |
4:666017851052 | 818 | // down key |
Mike Fiore |
9:ff62b20f7000 | 819 | for (size_t i = 0; i < command.size() + 1; i++) { |
Mike Fiore |
4:666017851052 | 820 | writef("\b \b"); |
Mike Fiore |
4:666017851052 | 821 | } |
Mike Fiore |
4:666017851052 | 822 | |
Mike Fiore |
4:666017851052 | 823 | if (--history_index < 0) { |
Mike Fiore |
4:666017851052 | 824 | history_index = -1; |
Mike Fiore |
4:666017851052 | 825 | command.clear(); |
Mike Fiore |
4:666017851052 | 826 | } else { |
Mike Fiore |
4:666017851052 | 827 | command = history[history_index]; |
Mike Fiore |
4:666017851052 | 828 | writef("%s", history[history_index].c_str()); |
Mike Fiore |
4:666017851052 | 829 | } |
Mike Fiore |
4:666017851052 | 830 | } |
Mike Fiore |
14:f9a77400b622 | 831 | #endif |
Mike Fiore |
4:666017851052 | 832 | } |
Mike Fiore |
9:ff62b20f7000 | 833 | while (readable()) |
Mike Fiore |
9:ff62b20f7000 | 834 | read(); |
Mike Fiore |
4:666017851052 | 835 | continue; |
Mike Fiore |
1:e52ae6584f1c | 836 | } else { |
Mike Fiore |
1:e52ae6584f1c | 837 | command += ch; |
Mike Fiore |
1:e52ae6584f1c | 838 | } |
Mike Fiore |
1:e52ae6584f1c | 839 | |
Mike Fiore |
1:e52ae6584f1c | 840 | // echo chars if enabled |
Mike Fiore |
1:e52ae6584f1c | 841 | if (echo && !(ch == '\r' || ch == '\n')) |
Mike Fiore |
1:e52ae6584f1c | 842 | writef("%c", ch); |
Mike Fiore |
1:e52ae6584f1c | 843 | } |
Mike Fiore |
1:e52ae6584f1c | 844 | |
Mike Fiore |
1:e52ae6584f1c | 845 | // look for end of command line |
Mike Fiore |
1:e52ae6584f1c | 846 | if (command.find("\n") != std::string::npos || command.find("\r") != std::string::npos) { |
Mike Fiore |
1:e52ae6584f1c | 847 | // remove new line or cr character |
Mike Fiore |
1:e52ae6584f1c | 848 | command.erase(command.size() - 1); |
Mike Fiore |
1:e52ae6584f1c | 849 | write("\r"); // match standard modem output |
Mike Fiore |
1:e52ae6584f1c | 850 | write(newline); |
Mike Fiore |
1:e52ae6584f1c | 851 | } else { |
Mike Fiore |
1:e52ae6584f1c | 852 | continue; |
Mike Fiore |
1:e52ae6584f1c | 853 | } |
Mike Fiore |
1:e52ae6584f1c | 854 | |
Mike Fiore |
1:e52ae6584f1c | 855 | // trim whitespace from command |
Mike Fiore |
1:e52ae6584f1c | 856 | mts::Text::trim(command, "\r\n\t "); |
Mike Fiore |
1:e52ae6584f1c | 857 | |
Mike Fiore |
1:e52ae6584f1c | 858 | if (command.size() < 1) { |
Mike Fiore |
1:e52ae6584f1c | 859 | command.clear(); |
Mike Fiore |
1:e52ae6584f1c | 860 | continue; |
Mike Fiore |
1:e52ae6584f1c | 861 | } |
Mike Fiore |
1:e52ae6584f1c | 862 | |
Mike Fiore |
1:e52ae6584f1c | 863 | // parse command and args |
Mike Fiore |
1:e52ae6584f1c | 864 | args.clear(); |
Mike Fiore |
1:e52ae6584f1c | 865 | |
Mike Fiore |
1:e52ae6584f1c | 866 | // find first '=' character |
Mike Fiore |
1:e52ae6584f1c | 867 | size_t delim_index = command.find("="); |
Mike Fiore |
1:e52ae6584f1c | 868 | if (delim_index != std::string::npos) { |
Mike Fiore |
1:e52ae6584f1c | 869 | args.push_back(command.substr(0, delim_index)); |
Mike Fiore |
1:e52ae6584f1c | 870 | } else { |
Mike Fiore |
1:e52ae6584f1c | 871 | // find first ' ' character |
Mike Fiore |
1:e52ae6584f1c | 872 | delim_index = command.find(" "); |
Mike Fiore |
1:e52ae6584f1c | 873 | if (delim_index != std::string::npos) { |
Mike Fiore |
1:e52ae6584f1c | 874 | args.push_back(command.substr(0, delim_index)); |
Mike Fiore |
1:e52ae6584f1c | 875 | } else { |
Mike Fiore |
1:e52ae6584f1c | 876 | args.push_back(command); |
Mike Fiore |
1:e52ae6584f1c | 877 | } |
Mike Fiore |
1:e52ae6584f1c | 878 | } |
Mike Fiore |
1:e52ae6584f1c | 879 | |
Mike Fiore |
1:e52ae6584f1c | 880 | if (delim_index != std::string::npos) { |
Mike Fiore |
1:e52ae6584f1c | 881 | std::vector<std::string> params = mts::Text::split(command.substr(delim_index + 1), ","); |
Mike Fiore |
1:e52ae6584f1c | 882 | args.insert(args.end(), params.begin(), params.end()); |
Mike Fiore |
1:e52ae6584f1c | 883 | } |
Mike Fiore |
1:e52ae6584f1c | 884 | |
Mike Fiore |
1:e52ae6584f1c | 885 | args[0] = mts::Text::toUpper(args[0]); |
Mike Fiore |
1:e52ae6584f1c | 886 | |
Mike Fiore |
1:e52ae6584f1c | 887 | // print help |
Mike Fiore |
1:e52ae6584f1c | 888 | if ((args[0].find("?") == 0 || args[0].find("HELP") == 0) && args.size() == 1) { |
Mike Fiore |
1:e52ae6584f1c | 889 | printHelp(); |
Mike Fiore |
1:e52ae6584f1c | 890 | command.clear(); |
Mike Fiore |
9:ff62b20f7000 | 891 | } else if ((args[0].find("ATE?") == 0 && args[0].length() == 4) || (args[0].find("ATE") == 0 && args[0].length() == 3)) { |
Mike Fiore |
9:ff62b20f7000 | 892 | writef("%d\r\n", _dot->getEcho()); |
Mike Fiore |
9:ff62b20f7000 | 893 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 894 | } else if (args[0].find("ATE0") == 0 && args[0].length() == 4) { |
Mike Fiore |
1:e52ae6584f1c | 895 | _dot->setEcho(false); |
Mike Fiore |
1:e52ae6584f1c | 896 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 897 | echo = _dot->getEcho(); |
Mike Fiore |
1:e52ae6584f1c | 898 | } else if (args[0].find("ATE1") == 0 && args[0].length() == 4) { |
Mike Fiore |
1:e52ae6584f1c | 899 | _dot->setEcho(true); |
Mike Fiore |
1:e52ae6584f1c | 900 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 901 | echo = _dot->getEcho(); |
Mike Fiore |
9:ff62b20f7000 | 902 | } else if ((args[0].find("ATV?") == 0 && args[0].length() == 4) || (args[0].find("ATV") == 0 && args[0].length() == 3)) { |
Mike Fiore |
9:ff62b20f7000 | 903 | writef("%d\r\n", _dot->getVerbose()); |
Mike Fiore |
9:ff62b20f7000 | 904 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 905 | } else if (args[0].find("ATV0") == 0 && args[0].length() == 4) { |
Mike Fiore |
1:e52ae6584f1c | 906 | _dot->setVerbose(false); |
Mike Fiore |
1:e52ae6584f1c | 907 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 908 | } else if (args[0].find("ATV1") == 0 && args[0].length() == 4) { |
Mike Fiore |
1:e52ae6584f1c | 909 | _dot->setVerbose(true); |
Mike Fiore |
1:e52ae6584f1c | 910 | write(done); |
Mike Fiore |
9:ff62b20f7000 | 911 | } else if ((args[0].find("AT&K?") == 0 && args[0].length() == 5) || (args[0].find("AT&K") == 0 && args[0].length() == 4)) { |
Mike Fiore |
9:ff62b20f7000 | 912 | writef("%d\r\n", (_dot->getFlowControl() ? 3 : 0)); |
Mike Fiore |
9:ff62b20f7000 | 913 | write(done); |
Mike Fiore |
9:ff62b20f7000 | 914 | } else if (args[0].find("AT&K0") == 0 && args[0].length() == 5) { |
Mike Fiore |
9:ff62b20f7000 | 915 | _dot->setFlowControl(false); |
Mike Fiore |
9:ff62b20f7000 | 916 | write(done); |
Mike Fiore |
9:ff62b20f7000 | 917 | } else if (args[0].find("AT&K3") == 0 && args[0].length() == 5) { |
Mike Fiore |
9:ff62b20f7000 | 918 | _dot->setFlowControl(true); |
Mike Fiore |
9:ff62b20f7000 | 919 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 920 | } else if (args[0] == "AT+SD") { |
Mike Fiore |
9:ff62b20f7000 | 921 | if (_dot->getNetworkJoinStatus()) { |
Mike Fiore |
9:ff62b20f7000 | 922 | logDebug("Enter Serial Mode"); |
Mike Fiore |
9:ff62b20f7000 | 923 | write(connect); |
Mike Fiore |
9:ff62b20f7000 | 924 | serial_data_mode = true; |
Mike Fiore |
9:ff62b20f7000 | 925 | _mode = mDot::SERIAL_MODE; |
Mike Fiore |
9:ff62b20f7000 | 926 | } else { |
Mike Fiore |
9:ff62b20f7000 | 927 | logDebug("Network Not Joined"); |
Mike Fiore |
9:ff62b20f7000 | 928 | write("Network Not Joined\r\n"); |
Mike Fiore |
9:ff62b20f7000 | 929 | write(error); |
Mike Fiore |
9:ff62b20f7000 | 930 | } |
Mike Fiore |
4:666017851052 | 931 | } else if (args[0] == "AT+SLEEP") { |
Mike Fiore |
9:ff62b20f7000 | 932 | if (args.size() > 2 && (args[1] != "?")) { |
Mike Fiore |
4:666017851052 | 933 | write("Invalid argument\r\n"); |
Mike Fiore |
4:666017851052 | 934 | write(error); |
Mike Fiore |
4:666017851052 | 935 | } else { |
Mike Fiore |
4:666017851052 | 936 | if (args.size() > 1 && args[1] == "?") { |
Mike Fiore |
9:ff62b20f7000 | 937 | write("(0:deepsleep,1:sleep)\r\n"); |
Mike Fiore |
4:666017851052 | 938 | write(done); |
Mike Fiore |
4:666017851052 | 939 | } else { |
Mike Fiore |
4:666017851052 | 940 | _sleep_standby = !(args.size() > 1 && args[1] == "1"); |
Mike Fiore |
14:f9a77400b622 | 941 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
14:f9a77400b622 | 942 | //Read the board ID. If all 0's, it is revision B. This hardware does not support deep sleep. |
Mike Fiore |
14:f9a77400b622 | 943 | DigitalIn ID2(PC_4); |
Mike Fiore |
14:f9a77400b622 | 944 | DigitalIn ID1(PC_5); |
Mike Fiore |
14:f9a77400b622 | 945 | DigitalIn ID0(PD_2); |
Mike Fiore |
14:f9a77400b622 | 946 | if(ID2 == 0 && ID1 == 0 && ID0 == 0 && _sleep_standby == 1){ |
Mike Fiore |
14:f9a77400b622 | 947 | _sleep_standby = 0; |
Mike Fiore |
14:f9a77400b622 | 948 | logWarning("This hardware version does not support deep sleep. Using sleep mode instead."); |
Mike Fiore |
14:f9a77400b622 | 949 | } |
Mike Fiore |
14:f9a77400b622 | 950 | #endif |
Mike Fiore |
9:ff62b20f7000 | 951 | write(done); |
Mike Fiore |
14:f9a77400b622 | 952 | osDelay(5); |
Mike Fiore |
4:666017851052 | 953 | this->sleep(_sleep_standby); |
Mike Fiore |
14:f9a77400b622 | 954 | osDelay(1); |
Mike Fiore |
4:666017851052 | 955 | } |
Mike Fiore |
4:666017851052 | 956 | } |
Mike Fiore |
1:e52ae6584f1c | 957 | } else { |
Mike Fiore |
1:e52ae6584f1c | 958 | bool found = false; |
Mike Fiore |
1:e52ae6584f1c | 959 | bool query = false; |
Mike Fiore |
1:e52ae6584f1c | 960 | |
Mike Fiore |
1:e52ae6584f1c | 961 | std::string lookfor = args[0]; |
Mike Fiore |
1:e52ae6584f1c | 962 | |
Mike Fiore |
1:e52ae6584f1c | 963 | // per command help |
Mike Fiore |
1:e52ae6584f1c | 964 | if ((args[0].find("?") == 0 || args[0].find("HELP") == 0)) |
Mike Fiore |
1:e52ae6584f1c | 965 | lookfor = mts::Text::toUpper(args[1]); |
Mike Fiore |
1:e52ae6584f1c | 966 | |
Mike Fiore |
1:e52ae6584f1c | 967 | // trim off any trailing '?' and mark as a query command |
Mike Fiore |
1:e52ae6584f1c | 968 | if (args[0].rfind("?") == args[0].length() - 1) { |
Mike Fiore |
1:e52ae6584f1c | 969 | query = true; |
Mike Fiore |
1:e52ae6584f1c | 970 | lookfor = args[0].substr(0, args[0].length() - 1); |
Mike Fiore |
1:e52ae6584f1c | 971 | } |
Mike Fiore |
1:e52ae6584f1c | 972 | |
Mike Fiore |
1:e52ae6584f1c | 973 | // search for command |
Mike Fiore |
14:f9a77400b622 | 974 | for (int i = 0; i < NO_OF_COMMANDS; i++) { |
Mike Fiore |
1:e52ae6584f1c | 975 | |
Mike Fiore |
1:e52ae6584f1c | 976 | // match CMD or CMD? syntax if command is queryable |
Mike Fiore |
14:f9a77400b622 | 977 | if (lookfor == _commands[i].text() && (!query || (query && _commands[i].queryable()))) { |
Mike Fiore |
1:e52ae6584f1c | 978 | found = true; |
Mike Fiore |
1:e52ae6584f1c | 979 | if (args[0] == "HELP") { |
Mike Fiore |
14:f9a77400b622 | 980 | writef("%s%s", _commands[i].help().c_str(), newline); |
Mike Fiore |
1:e52ae6584f1c | 981 | write(done); |
Mike Fiore |
1:e52ae6584f1c | 982 | } |
Mike Fiore |
1:e52ae6584f1c | 983 | |
Mike Fiore |
1:e52ae6584f1c | 984 | else if (args.size() > 1 && args[1] == "?") { |
Mike Fiore |
14:f9a77400b622 | 985 | writef("%s%s", _commands[i].usage().c_str(), newline); |
Mike Fiore |
1:e52ae6584f1c | 986 | write(done); |
Mike Fiore |
14:f9a77400b622 | 987 | } else if (!_verify[i](args)) { |
Mike Fiore |
14:f9a77400b622 | 988 | writef("%s%s", _errorMessage.c_str(), newline); |
Mike Fiore |
1:e52ae6584f1c | 989 | writef("%s", error); |
Mike Fiore |
1:e52ae6584f1c | 990 | } else { |
Mike Fiore |
14:f9a77400b622 | 991 | if (_action[i](args) == 0) { |
Mike Fiore |
1:e52ae6584f1c | 992 | writef("%s", done); |
Mike Fiore |
1:e52ae6584f1c | 993 | } else { |
Mike Fiore |
14:f9a77400b622 | 994 | writef("%s%s", _errorMessage.c_str(), newline); |
Mike Fiore |
1:e52ae6584f1c | 995 | writef("%s", error); |
Mike Fiore |
1:e52ae6584f1c | 996 | } |
Mike Fiore |
1:e52ae6584f1c | 997 | } |
Mike Fiore |
1:e52ae6584f1c | 998 | } |
Mike Fiore |
1:e52ae6584f1c | 999 | } |
Mike Fiore |
1:e52ae6584f1c | 1000 | |
Mike Fiore |
1:e52ae6584f1c | 1001 | if (!found) { |
Mike Fiore |
1:e52ae6584f1c | 1002 | writef("%s", command_error); |
Mike Fiore |
1:e52ae6584f1c | 1003 | writef("%s", error); |
Mike Fiore |
1:e52ae6584f1c | 1004 | } |
Mike Fiore |
1:e52ae6584f1c | 1005 | } |
Mike Fiore |
1:e52ae6584f1c | 1006 | |
Mike Fiore |
14:f9a77400b622 | 1007 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
4:666017851052 | 1008 | if (history.size() == 0 || history.front() != command) |
Mike Fiore |
4:666017851052 | 1009 | history.push_front(command); |
Mike Fiore |
4:666017851052 | 1010 | history_index = -1; |
Mike Fiore |
1:e52ae6584f1c | 1011 | command.clear(); |
Mike Fiore |
1:e52ae6584f1c | 1012 | |
Mike Fiore |
4:666017851052 | 1013 | while (history.size() > 10) |
Mike Fiore |
4:666017851052 | 1014 | history.pop_back(); |
Mike Fiore |
14:f9a77400b622 | 1015 | #else |
Mike Fiore |
14:f9a77400b622 | 1016 | command.clear(); |
Mike Fiore |
14:f9a77400b622 | 1017 | #endif |
Mike Fiore |
1:e52ae6584f1c | 1018 | } |
Mike Fiore |
1:e52ae6584f1c | 1019 | } |
Mike Fiore |
1:e52ae6584f1c | 1020 | |
Mike Fiore |
1:e52ae6584f1c | 1021 | void CommandTerminal::sleep(bool standby) { |
Mike Fiore |
1:e52ae6584f1c | 1022 | _xbee_on_sleep = GPIO_PIN_RESET; |
Mike Fiore |
1:e52ae6584f1c | 1023 | |
Mike Fiore |
4:666017851052 | 1024 | _serial.rxClear(); |
Mike Fiore |
4:666017851052 | 1025 | _serial.txClear(); |
Mike Fiore |
1:e52ae6584f1c | 1026 | |
Mike Fiore |
14:f9a77400b622 | 1027 | #if defined(TARGET_XDOT_L151CC) |
Mike Fiore |
14:f9a77400b622 | 1028 | xdot_save_gpio_state(); |
Mike Fiore |
14:f9a77400b622 | 1029 | |
Mike Fiore |
14:f9a77400b622 | 1030 | /* GPIO Ports Clock Enable */ |
Mike Fiore |
14:f9a77400b622 | 1031 | __GPIOA_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1032 | __GPIOB_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1033 | __GPIOC_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1034 | __GPIOH_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1035 | |
Mike Fiore |
14:f9a77400b622 | 1036 | GPIO_InitTypeDef GPIO_InitStruct; |
Mike Fiore |
14:f9a77400b622 | 1037 | |
Mike Fiore |
14:f9a77400b622 | 1038 | // UART1_TX, UART1_RTS & UART1_CTS to analog nopull - RX could be a wakeup source |
Mike Fiore |
14:f9a77400b622 | 1039 | GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_11 | GPIO_PIN_12; |
Mike Fiore |
14:f9a77400b622 | 1040 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1041 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1042 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1043 | |
Mike Fiore |
14:f9a77400b622 | 1044 | // I2C_SDA & I2C_SCL to analog nopull |
Mike Fiore |
14:f9a77400b622 | 1045 | GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; |
Mike Fiore |
14:f9a77400b622 | 1046 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1047 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1048 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1049 | |
Mike Fiore |
14:f9a77400b622 | 1050 | // SPI_MOSI, SPI_MISO, SPI_SCK, & SPI_NSS to analog nopull |
Mike Fiore |
14:f9a77400b622 | 1051 | GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
Mike Fiore |
14:f9a77400b622 | 1052 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1053 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1054 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1055 | |
Mike Fiore |
14:f9a77400b622 | 1056 | // iterate through potential wake pins - leave the configured wake pin alone if one is needed |
Mike Fiore |
14:f9a77400b622 | 1057 | if (_dot->getWakePin() != WAKE || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1058 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
Mike Fiore |
14:f9a77400b622 | 1059 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1060 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1061 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1062 | } |
Mike Fiore |
14:f9a77400b622 | 1063 | if (_dot->getWakePin() != GPIO0 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1064 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
Mike Fiore |
14:f9a77400b622 | 1065 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1066 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1067 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1068 | } |
Mike Fiore |
14:f9a77400b622 | 1069 | if (_dot->getWakePin() != GPIO1 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1070 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
Mike Fiore |
14:f9a77400b622 | 1071 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1072 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1073 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1074 | } |
Mike Fiore |
14:f9a77400b622 | 1075 | if (_dot->getWakePin() != GPIO2 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1076 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
Mike Fiore |
14:f9a77400b622 | 1077 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1078 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1079 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1080 | } |
Mike Fiore |
14:f9a77400b622 | 1081 | if (_dot->getWakePin() != GPIO3 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1082 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
Mike Fiore |
14:f9a77400b622 | 1083 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1084 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1085 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1086 | } |
Mike Fiore |
14:f9a77400b622 | 1087 | if (_dot->getWakePin() != UART1_RX || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1088 | GPIO_InitStruct.Pin = GPIO_PIN_10; |
Mike Fiore |
14:f9a77400b622 | 1089 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1090 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1091 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1092 | } |
Mike Fiore |
14:f9a77400b622 | 1093 | #else |
Mike Fiore |
14:f9a77400b622 | 1094 | uint32_t portA[6]; |
Mike Fiore |
14:f9a77400b622 | 1095 | uint32_t portB[6]; |
Mike Fiore |
14:f9a77400b622 | 1096 | uint32_t portC[6]; |
Mike Fiore |
14:f9a77400b622 | 1097 | uint32_t portD[6]; |
Mike Fiore |
14:f9a77400b622 | 1098 | uint32_t portH[6]; |
Mike Fiore |
14:f9a77400b622 | 1099 | |
Mike Fiore |
14:f9a77400b622 | 1100 | //Save the GPIO state. |
Mike Fiore |
14:f9a77400b622 | 1101 | portA[0] = GPIOA->MODER; |
Mike Fiore |
14:f9a77400b622 | 1102 | portA[1] = GPIOA->OTYPER; |
Mike Fiore |
14:f9a77400b622 | 1103 | portA[2] = GPIOA->OSPEEDR; |
Mike Fiore |
14:f9a77400b622 | 1104 | portA[3] = GPIOA->PUPDR; |
Mike Fiore |
14:f9a77400b622 | 1105 | portA[4] = GPIOA->AFR[0]; |
Mike Fiore |
14:f9a77400b622 | 1106 | portA[5] = GPIOA->AFR[1]; |
Mike Fiore |
14:f9a77400b622 | 1107 | |
Mike Fiore |
14:f9a77400b622 | 1108 | portB[0] = GPIOB->MODER; |
Mike Fiore |
14:f9a77400b622 | 1109 | portB[1] = GPIOB->OTYPER; |
Mike Fiore |
14:f9a77400b622 | 1110 | portB[2] = GPIOB->OSPEEDR; |
Mike Fiore |
14:f9a77400b622 | 1111 | portB[3] = GPIOB->PUPDR; |
Mike Fiore |
14:f9a77400b622 | 1112 | portB[4] = GPIOB->AFR[0]; |
Mike Fiore |
14:f9a77400b622 | 1113 | portB[5] = GPIOB->AFR[1]; |
Mike Fiore |
14:f9a77400b622 | 1114 | |
Mike Fiore |
14:f9a77400b622 | 1115 | portC[0] = GPIOC->MODER; |
Mike Fiore |
14:f9a77400b622 | 1116 | portC[1] = GPIOC->OTYPER; |
Mike Fiore |
14:f9a77400b622 | 1117 | portC[2] = GPIOC->OSPEEDR; |
Mike Fiore |
14:f9a77400b622 | 1118 | portC[3] = GPIOC->PUPDR; |
Mike Fiore |
14:f9a77400b622 | 1119 | portC[4] = GPIOC->AFR[0]; |
Mike Fiore |
14:f9a77400b622 | 1120 | portC[5] = GPIOC->AFR[1]; |
Mike Fiore |
14:f9a77400b622 | 1121 | |
Mike Fiore |
14:f9a77400b622 | 1122 | portD[0] = GPIOD->MODER; |
Mike Fiore |
14:f9a77400b622 | 1123 | portD[1] = GPIOD->OTYPER; |
Mike Fiore |
14:f9a77400b622 | 1124 | portD[2] = GPIOD->OSPEEDR; |
Mike Fiore |
14:f9a77400b622 | 1125 | portD[3] = GPIOD->PUPDR; |
Mike Fiore |
14:f9a77400b622 | 1126 | portD[4] = GPIOD->AFR[0]; |
Mike Fiore |
14:f9a77400b622 | 1127 | portD[5] = GPIOD->AFR[1]; |
Mike Fiore |
14:f9a77400b622 | 1128 | |
Mike Fiore |
14:f9a77400b622 | 1129 | portH[0] = GPIOH->MODER; |
Mike Fiore |
14:f9a77400b622 | 1130 | portH[1] = GPIOH->OTYPER; |
Mike Fiore |
14:f9a77400b622 | 1131 | portH[2] = GPIOH->OSPEEDR; |
Mike Fiore |
14:f9a77400b622 | 1132 | portH[3] = GPIOH->PUPDR; |
Mike Fiore |
14:f9a77400b622 | 1133 | portH[4] = GPIOH->AFR[0]; |
Mike Fiore |
14:f9a77400b622 | 1134 | portH[5] = GPIOH->AFR[1]; |
Mike Fiore |
14:f9a77400b622 | 1135 | |
Mike Fiore |
14:f9a77400b622 | 1136 | /* GPIO Ports Clock Enable */ |
Mike Fiore |
14:f9a77400b622 | 1137 | __GPIOA_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1138 | __GPIOB_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1139 | __GPIOC_CLK_ENABLE(); |
Mike Fiore |
14:f9a77400b622 | 1140 | |
Mike Fiore |
14:f9a77400b622 | 1141 | GPIO_InitTypeDef GPIO_InitStruct; |
Mike Fiore |
14:f9a77400b622 | 1142 | |
Mike Fiore |
14:f9a77400b622 | 1143 | // Set port A pins to analog nopull |
Mike Fiore |
14:f9a77400b622 | 1144 | GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 |
Mike Fiore |
14:f9a77400b622 | 1145 | | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
Mike Fiore |
14:f9a77400b622 | 1146 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1147 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1148 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1149 | |
Mike Fiore |
14:f9a77400b622 | 1150 | // Set port B pins to analog nopull |
Mike Fiore |
14:f9a77400b622 | 1151 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4; |
Mike Fiore |
14:f9a77400b622 | 1152 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1153 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1154 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1155 | |
Mike Fiore |
14:f9a77400b622 | 1156 | // Set port C pins to analog nopull |
Mike Fiore |
14:f9a77400b622 | 1157 | GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_13; |
Mike Fiore |
14:f9a77400b622 | 1158 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1159 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1160 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1161 | |
Mike Fiore |
14:f9a77400b622 | 1162 | // iterate through potential wake pins - leave the configured wake pin alone if one is needed |
Mike Fiore |
14:f9a77400b622 | 1163 | // XBEE_DIN - PA3 |
Mike Fiore |
14:f9a77400b622 | 1164 | // XBEE_DIO2 - PA5 |
Mike Fiore |
14:f9a77400b622 | 1165 | // XBEE_DIO3 - PA4 |
Mike Fiore |
14:f9a77400b622 | 1166 | // XBEE_DIO4 - PA7 |
Mike Fiore |
14:f9a77400b622 | 1167 | // XBEE_DIO5 - PC1 |
Mike Fiore |
14:f9a77400b622 | 1168 | // XBEE_DIO6 - PA1 |
Mike Fiore |
14:f9a77400b622 | 1169 | // XBEE_DIO7 - PA0 |
Mike Fiore |
14:f9a77400b622 | 1170 | // XBEE_SLEEPRQ - PA11 |
Mike Fiore |
14:f9a77400b622 | 1171 | |
Mike Fiore |
14:f9a77400b622 | 1172 | if (_dot->getWakePin() != XBEE_DIN || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1173 | GPIO_InitStruct.Pin = GPIO_PIN_3; |
Mike Fiore |
14:f9a77400b622 | 1174 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1175 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1176 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1177 | } |
Mike Fiore |
14:f9a77400b622 | 1178 | |
Mike Fiore |
14:f9a77400b622 | 1179 | if (_dot->getWakePin() != XBEE_DIO2 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1180 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
Mike Fiore |
14:f9a77400b622 | 1181 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1182 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1183 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1184 | } |
Mike Fiore |
14:f9a77400b622 | 1185 | |
Mike Fiore |
14:f9a77400b622 | 1186 | if (_dot->getWakePin() != XBEE_DIO3 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1187 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
Mike Fiore |
14:f9a77400b622 | 1188 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1189 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1190 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1191 | } |
Mike Fiore |
14:f9a77400b622 | 1192 | |
Mike Fiore |
14:f9a77400b622 | 1193 | if (_dot->getWakePin() != XBEE_DIO4 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1194 | GPIO_InitStruct.Pin = GPIO_PIN_7; |
Mike Fiore |
14:f9a77400b622 | 1195 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1196 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1197 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1198 | } |
Mike Fiore |
14:f9a77400b622 | 1199 | |
Mike Fiore |
14:f9a77400b622 | 1200 | if (_dot->getWakePin() != XBEE_DIO5 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1201 | GPIO_InitStruct.Pin = GPIO_PIN_1; |
Mike Fiore |
14:f9a77400b622 | 1202 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1203 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1204 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1205 | } |
Mike Fiore |
14:f9a77400b622 | 1206 | |
Mike Fiore |
14:f9a77400b622 | 1207 | if (_dot->getWakePin() != XBEE_DIO6 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1208 | GPIO_InitStruct.Pin = GPIO_PIN_1; |
Mike Fiore |
14:f9a77400b622 | 1209 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1210 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1211 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1212 | } |
Mike Fiore |
14:f9a77400b622 | 1213 | |
Mike Fiore |
14:f9a77400b622 | 1214 | if (_dot->getWakePin() != XBEE_DIO7 || _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1215 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
Mike Fiore |
14:f9a77400b622 | 1216 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1217 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1218 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1219 | } |
Mike Fiore |
14:f9a77400b622 | 1220 | |
Mike Fiore |
14:f9a77400b622 | 1221 | if (_dot->getWakePin() != XBEE_SLEEPRQ|| _dot->getWakeMode() == mDot::RTC_ALARM) { |
Mike Fiore |
14:f9a77400b622 | 1222 | GPIO_InitStruct.Pin = GPIO_PIN_11; |
Mike Fiore |
14:f9a77400b622 | 1223 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
Mike Fiore |
14:f9a77400b622 | 1224 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Mike Fiore |
14:f9a77400b622 | 1225 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
Mike Fiore |
14:f9a77400b622 | 1226 | } |
Mike Fiore |
14:f9a77400b622 | 1227 | |
Mike Fiore |
14:f9a77400b622 | 1228 | #endif |
Mike Fiore |
4:666017851052 | 1229 | _dot->sleep(_dot->getWakeInterval(), _dot->getWakeMode(), standby); |
Mike Fiore |
14:f9a77400b622 | 1230 | |
Mike Fiore |
14:f9a77400b622 | 1231 | #if defined(TARGET_XDOT_L151CC) |
Mike Fiore |
14:f9a77400b622 | 1232 | xdot_restore_gpio_state(); |
Mike Fiore |
14:f9a77400b622 | 1233 | #else |
Mike Fiore |
14:f9a77400b622 | 1234 | //Restore the GPIO state. |
Mike Fiore |
14:f9a77400b622 | 1235 | GPIOA->MODER = portA[0]; |
Mike Fiore |
14:f9a77400b622 | 1236 | GPIOA->OTYPER = portA[1]; |
Mike Fiore |
14:f9a77400b622 | 1237 | GPIOA->OSPEEDR = portA[2]; |
Mike Fiore |
14:f9a77400b622 | 1238 | GPIOA->PUPDR = portA[3]; |
Mike Fiore |
14:f9a77400b622 | 1239 | GPIOA->AFR[0] = portA[4]; |
Mike Fiore |
14:f9a77400b622 | 1240 | GPIOA->AFR[1] = portA[5]; |
Mike Fiore |
14:f9a77400b622 | 1241 | |
Mike Fiore |
14:f9a77400b622 | 1242 | GPIOB->MODER = portB[0]; |
Mike Fiore |
14:f9a77400b622 | 1243 | GPIOB->OTYPER = portB[1]; |
Mike Fiore |
14:f9a77400b622 | 1244 | GPIOB->OSPEEDR = portB[2]; |
Mike Fiore |
14:f9a77400b622 | 1245 | GPIOB->PUPDR = portB[3]; |
Mike Fiore |
14:f9a77400b622 | 1246 | GPIOB->AFR[0] = portB[4]; |
Mike Fiore |
14:f9a77400b622 | 1247 | GPIOB->AFR[1] = portB[5]; |
Mike Fiore |
14:f9a77400b622 | 1248 | |
Mike Fiore |
14:f9a77400b622 | 1249 | GPIOC->MODER = portC[0]; |
Mike Fiore |
14:f9a77400b622 | 1250 | GPIOC->OTYPER = portC[1]; |
Mike Fiore |
14:f9a77400b622 | 1251 | GPIOC->OSPEEDR = portC[2]; |
Mike Fiore |
14:f9a77400b622 | 1252 | GPIOC->PUPDR = portC[3]; |
Mike Fiore |
14:f9a77400b622 | 1253 | GPIOC->AFR[0] = portC[4]; |
Mike Fiore |
14:f9a77400b622 | 1254 | GPIOC->AFR[1] = portC[5]; |
Mike Fiore |
14:f9a77400b622 | 1255 | |
Mike Fiore |
14:f9a77400b622 | 1256 | GPIOD->MODER = portD[0]; |
Mike Fiore |
14:f9a77400b622 | 1257 | GPIOD->OTYPER = portD[1]; |
Mike Fiore |
14:f9a77400b622 | 1258 | GPIOD->OSPEEDR = portD[2]; |
Mike Fiore |
14:f9a77400b622 | 1259 | GPIOD->PUPDR = portD[3]; |
Mike Fiore |
14:f9a77400b622 | 1260 | GPIOD->AFR[0] = portD[4]; |
Mike Fiore |
14:f9a77400b622 | 1261 | GPIOD->AFR[1] = portD[5]; |
Mike Fiore |
14:f9a77400b622 | 1262 | |
Mike Fiore |
14:f9a77400b622 | 1263 | GPIOH->MODER = portH[0]; |
Mike Fiore |
14:f9a77400b622 | 1264 | GPIOH->OTYPER = portH[1]; |
Mike Fiore |
14:f9a77400b622 | 1265 | GPIOH->OSPEEDR = portH[2]; |
Mike Fiore |
14:f9a77400b622 | 1266 | GPIOH->PUPDR = portH[3]; |
Mike Fiore |
14:f9a77400b622 | 1267 | GPIOH->AFR[0] = portH[4]; |
Mike Fiore |
14:f9a77400b622 | 1268 | GPIOH->AFR[1] = portH[5]; |
Mike Fiore |
14:f9a77400b622 | 1269 | #endif |
Mike Fiore |
14:f9a77400b622 | 1270 | |
Mike Fiore |
14:f9a77400b622 | 1271 | _serial.rxClear(); |
Mike Fiore |
14:f9a77400b622 | 1272 | _serial.txClear(); |
Mike Fiore |
14:f9a77400b622 | 1273 | } |
Mike Fiore |
14:f9a77400b622 | 1274 | |
Mike Fiore |
14:f9a77400b622 | 1275 | std::string CommandTerminal::formatPacketData(const std::vector<uint8_t>& data, const uint8_t& format) { |
Mike Fiore |
14:f9a77400b622 | 1276 | if (format == mDot::HEXADECIMAL) |
Mike Fiore |
14:f9a77400b622 | 1277 | return mts::Text::bin2hexString(data); |
Mike Fiore |
14:f9a77400b622 | 1278 | else |
Mike Fiore |
14:f9a77400b622 | 1279 | return std::string(data.begin(), data.end()); |
Mike Fiore |
1:e52ae6584f1c | 1280 | } |
Mike Fiore |
1:e52ae6584f1c | 1281 | |
Mike Fiore |
1:e52ae6584f1c | 1282 | bool CommandTerminal::waitForEscape(int timeout, mDot* dot, WaitType wait) { |
Mike Fiore |
1:e52ae6584f1c | 1283 | Timer timer; |
Mike Fiore |
1:e52ae6584f1c | 1284 | |
Mike Fiore |
1:e52ae6584f1c | 1285 | timer.start(); |
Mike Fiore |
1:e52ae6584f1c | 1286 | while (timer.read_ms() < timeout) { |
Mike Fiore |
1:e52ae6584f1c | 1287 | |
Mike Fiore |
1:e52ae6584f1c | 1288 | if (dot != NULL) { |
Mike Fiore |
1:e52ae6584f1c | 1289 | if (wait == WAIT_SEND && (!dot->getIsTransmitting())) { |
Mike Fiore |
1:e52ae6584f1c | 1290 | return false; |
Mike Fiore |
1:e52ae6584f1c | 1291 | } |
Mike Fiore |
1:e52ae6584f1c | 1292 | } |
Mike Fiore |
1:e52ae6584f1c | 1293 | |
Mike Fiore |
9:ff62b20f7000 | 1294 | if (_serialp != NULL && _serialp->escaped()) { |
Mike Fiore |
9:ff62b20f7000 | 1295 | _serialp->clearEscaped(); |
Mike Fiore |
9:ff62b20f7000 | 1296 | return true; |
Mike Fiore |
1:e52ae6584f1c | 1297 | } |
Mike Fiore |
1:e52ae6584f1c | 1298 | |
Mike Fiore |
1:e52ae6584f1c | 1299 | osDelay(10); |
Mike Fiore |
1:e52ae6584f1c | 1300 | } |
Mike Fiore |
1:e52ae6584f1c | 1301 | |
Mike Fiore |
1:e52ae6584f1c | 1302 | return false; |
Mike Fiore |
1:e52ae6584f1c | 1303 | } |
Mike Fiore |
1:e52ae6584f1c | 1304 | |
Mike Fiore |
9:ff62b20f7000 | 1305 | void CommandTerminal::wakeup(void) { |
Mike Fiore |
9:ff62b20f7000 | 1306 | } |
Mike Fiore |
9:ff62b20f7000 | 1307 | |
Mike Fiore |
14:f9a77400b622 | 1308 | void CommandTerminal::RadioEvent::PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries) { |
Mike Fiore |
14:f9a77400b622 | 1309 | mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, retries); |
Mike Fiore |
1:e52ae6584f1c | 1310 | |
Mike Fiore |
14:f9a77400b622 | 1311 | if (serial_data_mode) { |
Mike Fiore |
14:f9a77400b622 | 1312 | logDebug("Rx %d bytes", size); |
Mike Fiore |
14:f9a77400b622 | 1313 | if (size > 0) { |
Mike Fiore |
14:f9a77400b622 | 1314 | CommandTerminal::Serial()->write((char*) RxPayload, RxPayloadSize); |
Mike Fiore |
9:ff62b20f7000 | 1315 | } |
Mike Fiore |
14:f9a77400b622 | 1316 | if (!CommandTerminal::Serial()->readable() && _dot->getAckRequested() && _dot->getClass() == "C") { |
Mike Fiore |
14:f9a77400b622 | 1317 | _sendAck = true; |
Mike Fiore |
9:ff62b20f7000 | 1318 | } |
Mike Fiore |
9:ff62b20f7000 | 1319 | } |
Mike Fiore |
1:e52ae6584f1c | 1320 | } |
Mike Fiore |
9:ff62b20f7000 | 1321 | |
Mike Fiore |
9:ff62b20f7000 | 1322 | CommandTerminal::~CommandTerminal() { |
Mike Fiore |
9:ff62b20f7000 | 1323 | delete _events; |
Mike Fiore |
9:ff62b20f7000 | 1324 | } |