AT terminal for the mDot using the USB debug port instead of the serial port.
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CommandTerminal.h@14:f9a77400b622, 2016-11-04 (annotated)
- Committer:
- Mike Fiore
- Date:
- Fri Nov 04 14:25:43 2016 -0500
- Revision:
- 14:f9a77400b622
- Parent:
- 9:ff62b20f7000
- Child:
- 16:d5cf2af81a6d
update from git revision 2.0.16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:e52ae6584f1c | 1 | /** |
Mike Fiore |
14:f9a77400b622 | 2 | ****************************************************************************** |
Mike Fiore |
14:f9a77400b622 | 3 | * File Name : command.h |
Mike Fiore |
14:f9a77400b622 | 4 | * Date : 18/04/2014 10:57:12 |
Mike Fiore |
14:f9a77400b622 | 5 | * Description : This file provides code for command line prompt |
Mike Fiore |
14:f9a77400b622 | 6 | ****************************************************************************** |
Mike Fiore |
14:f9a77400b622 | 7 | * |
Mike Fiore |
14:f9a77400b622 | 8 | * COPYRIGHT(c) 2014 MultiTech Systems, Inc. |
Mike Fiore |
14:f9a77400b622 | 9 | * |
Mike Fiore |
14:f9a77400b622 | 10 | * Redistribution and use in source and binary forms, with or without modification, |
Mike Fiore |
14:f9a77400b622 | 11 | * are permitted provided that the following conditions are met: |
Mike Fiore |
14:f9a77400b622 | 12 | * 1. Redistributions of source code must retain the above copyright notice, |
Mike Fiore |
14:f9a77400b622 | 13 | * this list of conditions and the following disclaimer. |
Mike Fiore |
14:f9a77400b622 | 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Mike Fiore |
14:f9a77400b622 | 15 | * this list of conditions and the following disclaimer in the documentation |
Mike Fiore |
14:f9a77400b622 | 16 | * and/or other materials provided with the distribution. |
Mike Fiore |
14:f9a77400b622 | 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Mike Fiore |
14:f9a77400b622 | 18 | * may be used to endorse or promote products derived from this software |
Mike Fiore |
14:f9a77400b622 | 19 | * without specific prior written permission. |
Mike Fiore |
14:f9a77400b622 | 20 | * |
Mike Fiore |
14:f9a77400b622 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Mike Fiore |
14:f9a77400b622 | 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Mike Fiore |
14:f9a77400b622 | 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Mike Fiore |
14:f9a77400b622 | 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Mike Fiore |
14:f9a77400b622 | 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Mike Fiore |
14:f9a77400b622 | 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Mike Fiore |
14:f9a77400b622 | 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Mike Fiore |
14:f9a77400b622 | 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Mike Fiore |
14:f9a77400b622 | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Mike Fiore |
14:f9a77400b622 | 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Mike Fiore |
14:f9a77400b622 | 31 | * |
Mike Fiore |
14:f9a77400b622 | 32 | ****************************************************************************** |
Mike Fiore |
14:f9a77400b622 | 33 | */ |
Mike Fiore |
14:f9a77400b622 | 34 | |
Mike Fiore |
1:e52ae6584f1c | 35 | #include "mbed.h" |
Mike Fiore |
9:ff62b20f7000 | 36 | #include "ATSerial.h" |
Mike Fiore |
1:e52ae6584f1c | 37 | #include "MTSSerial.h" |
Mike Fiore |
9:ff62b20f7000 | 38 | #include "MTSSerialFlowControl.h" |
Mike Fiore |
1:e52ae6584f1c | 39 | #include "Commands.h" |
Mike Fiore |
1:e52ae6584f1c | 40 | #include "mDot.h" |
Mike Fiore |
9:ff62b20f7000 | 41 | #include "mDotEvent.h" |
Mike Fiore |
14:f9a77400b622 | 42 | |
Mike Fiore |
1:e52ae6584f1c | 43 | /* Define to prevent recursive inclusion -------------------------------------*/ |
Mike Fiore |
1:e52ae6584f1c | 44 | #ifndef __command_terminal_H__ |
Mike Fiore |
1:e52ae6584f1c | 45 | #define __command_terminal_H__ |
Mike Fiore |
1:e52ae6584f1c | 46 | |
Mike Fiore |
14:f9a77400b622 | 47 | typedef uint32_t (*action_ptr_t)(std::vector<std::string> args); |
Mike Fiore |
14:f9a77400b622 | 48 | typedef bool (*verify_ptr_t)(std::vector<std::string> args); |
Mike Fiore |
14:f9a77400b622 | 49 | |
Mike Fiore |
14:f9a77400b622 | 50 | class Command; |
Mike Fiore |
14:f9a77400b622 | 51 | |
Mike Fiore |
1:e52ae6584f1c | 52 | class CommandTerminal { |
Mike Fiore |
1:e52ae6584f1c | 53 | |
Mike Fiore |
14:f9a77400b622 | 54 | class RadioEvent : public mDotEvent { |
Mike Fiore |
9:ff62b20f7000 | 55 | |
Mike Fiore |
14:f9a77400b622 | 56 | public: |
Mike Fiore |
14:f9a77400b622 | 57 | RadioEvent() : _sendAck(false) {} |
Mike Fiore |
9:ff62b20f7000 | 58 | |
Mike Fiore |
9:ff62b20f7000 | 59 | virtual ~RadioEvent() {} |
Mike Fiore |
9:ff62b20f7000 | 60 | |
Mike Fiore |
14:f9a77400b622 | 61 | virtual void TxDone(uint8_t dr) { |
Mike Fiore |
14:f9a77400b622 | 62 | mDotEvent::TxDone(dr); |
Mike Fiore |
14:f9a77400b622 | 63 | |
Mike Fiore |
14:f9a77400b622 | 64 | logDebug("RadioEvent - TxDone"); |
Mike Fiore |
14:f9a77400b622 | 65 | } |
Mike Fiore |
14:f9a77400b622 | 66 | |
Mike Fiore |
14:f9a77400b622 | 67 | virtual void TxTimeout(void) { |
Mike Fiore |
14:f9a77400b622 | 68 | mDotEvent::TxTimeout(); |
Mike Fiore |
14:f9a77400b622 | 69 | |
Mike Fiore |
14:f9a77400b622 | 70 | logDebug("RadioEvent - TxTimeout"); |
Mike Fiore |
14:f9a77400b622 | 71 | } |
Mike Fiore |
14:f9a77400b622 | 72 | |
Mike Fiore |
14:f9a77400b622 | 73 | virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { |
Mike Fiore |
14:f9a77400b622 | 74 | mDotEvent::JoinAccept(payload, size, rssi, snr); |
Mike Fiore |
14:f9a77400b622 | 75 | |
Mike Fiore |
14:f9a77400b622 | 76 | logDebug("RadioEvent - JoinAccept"); |
Mike Fiore |
14:f9a77400b622 | 77 | } |
Mike Fiore |
14:f9a77400b622 | 78 | |
Mike Fiore |
14:f9a77400b622 | 79 | virtual void 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 = 0); |
Mike Fiore |
14:f9a77400b622 | 80 | |
Mike Fiore |
14:f9a77400b622 | 81 | virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot) { |
Mike Fiore |
14:f9a77400b622 | 82 | mDotEvent::RxDone(payload, size, rssi, snr, ctrl, slot); |
Mike Fiore |
14:f9a77400b622 | 83 | |
Mike Fiore |
14:f9a77400b622 | 84 | logDebug("RadioEvent - RxDone"); |
Mike Fiore |
14:f9a77400b622 | 85 | } |
Mike Fiore |
14:f9a77400b622 | 86 | |
Mike Fiore |
14:f9a77400b622 | 87 | virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) { |
Mike Fiore |
14:f9a77400b622 | 88 | mDotEvent::Pong(m_rssi, m_snr, s_rssi, s_snr); |
Mike Fiore |
14:f9a77400b622 | 89 | |
Mike Fiore |
14:f9a77400b622 | 90 | logDebug("RadioEvent - Pong"); |
Mike Fiore |
14:f9a77400b622 | 91 | } |
Mike Fiore |
14:f9a77400b622 | 92 | |
Mike Fiore |
14:f9a77400b622 | 93 | virtual void NetworkLinkCheck(int16_t m_rssi, int8_t m_snr, int8_t s_snr, uint8_t s_gateways) { |
Mike Fiore |
14:f9a77400b622 | 94 | mDotEvent::NetworkLinkCheck(m_rssi, m_snr, s_snr, s_gateways); |
Mike Fiore |
14:f9a77400b622 | 95 | |
Mike Fiore |
14:f9a77400b622 | 96 | logDebug("RadioEvent - NetworkLinkCheck"); |
Mike Fiore |
14:f9a77400b622 | 97 | } |
Mike Fiore |
14:f9a77400b622 | 98 | |
Mike Fiore |
14:f9a77400b622 | 99 | virtual void RxTimeout(uint8_t slot) { |
Mike Fiore |
14:f9a77400b622 | 100 | mDotEvent::RxTimeout(slot); |
Mike Fiore |
14:f9a77400b622 | 101 | |
Mike Fiore |
14:f9a77400b622 | 102 | // logDebug("RadioEvent - RxTimeout"); |
Mike Fiore |
14:f9a77400b622 | 103 | } |
Mike Fiore |
14:f9a77400b622 | 104 | |
Mike Fiore |
14:f9a77400b622 | 105 | virtual void RxError(uint8_t slot) { |
Mike Fiore |
14:f9a77400b622 | 106 | mDotEvent::RxError(slot); |
Mike Fiore |
14:f9a77400b622 | 107 | |
Mike Fiore |
14:f9a77400b622 | 108 | logDebug("RadioEvent - RxError"); |
Mike Fiore |
14:f9a77400b622 | 109 | } |
Mike Fiore |
9:ff62b20f7000 | 110 | |
Mike Fiore |
9:ff62b20f7000 | 111 | virtual uint8_t MeasureBattery(void) { |
Mike Fiore |
9:ff62b20f7000 | 112 | return 255; |
Mike Fiore |
9:ff62b20f7000 | 113 | } |
Mike Fiore |
9:ff62b20f7000 | 114 | |
Mike Fiore |
14:f9a77400b622 | 115 | bool SendAck() { |
Mike Fiore |
14:f9a77400b622 | 116 | bool val = _sendAck; |
Mike Fiore |
14:f9a77400b622 | 117 | _sendAck = false; |
Mike Fiore |
14:f9a77400b622 | 118 | return val; |
Mike Fiore |
14:f9a77400b622 | 119 | } |
Mike Fiore |
9:ff62b20f7000 | 120 | |
Mike Fiore |
14:f9a77400b622 | 121 | bool _sendAck; |
Mike Fiore |
14:f9a77400b622 | 122 | }; |
Mike Fiore |
14:f9a77400b622 | 123 | |
Mike Fiore |
14:f9a77400b622 | 124 | public: |
Mike Fiore |
1:e52ae6584f1c | 125 | |
Mike Fiore |
1:e52ae6584f1c | 126 | enum WaitType { |
Mike Fiore |
1:e52ae6584f1c | 127 | WAIT_JOIN, |
Mike Fiore |
1:e52ae6584f1c | 128 | WAIT_RECV, |
Mike Fiore |
1:e52ae6584f1c | 129 | WAIT_LINK, |
Mike Fiore |
1:e52ae6584f1c | 130 | WAIT_SEND, |
Mike Fiore |
1:e52ae6584f1c | 131 | WAIT_NA |
Mike Fiore |
1:e52ae6584f1c | 132 | }; |
Mike Fiore |
1:e52ae6584f1c | 133 | |
Mike Fiore |
14:f9a77400b622 | 134 | CommandTerminal(mts::ATSerial& serial); |
Mike Fiore |
9:ff62b20f7000 | 135 | virtual ~CommandTerminal(); |
Mike Fiore |
14:f9a77400b622 | 136 | |
Mike Fiore |
14:f9a77400b622 | 137 | void init(); |
Mike Fiore |
14:f9a77400b622 | 138 | |
Mike Fiore |
1:e52ae6584f1c | 139 | // Command prompt text... |
Mike Fiore |
1:e52ae6584f1c | 140 | static const char banner[]; |
Mike Fiore |
1:e52ae6584f1c | 141 | static const char helpline[]; |
Mike Fiore |
1:e52ae6584f1c | 142 | static const char prompt[]; |
Mike Fiore |
14:f9a77400b622 | 143 | |
Mike Fiore |
1:e52ae6584f1c | 144 | // Command error text... |
Mike Fiore |
1:e52ae6584f1c | 145 | static const char command_error[]; |
Mike Fiore |
14:f9a77400b622 | 146 | |
Mike Fiore |
1:e52ae6584f1c | 147 | // Response texts... |
Mike Fiore |
1:e52ae6584f1c | 148 | static const char help[]; |
Mike Fiore |
1:e52ae6584f1c | 149 | static const char cmd_error[]; |
Mike Fiore |
1:e52ae6584f1c | 150 | static const char newline[]; |
Mike Fiore |
9:ff62b20f7000 | 151 | static const char connect[]; |
Mike Fiore |
9:ff62b20f7000 | 152 | static const char no_carrier[]; |
Mike Fiore |
1:e52ae6584f1c | 153 | static const char done[]; |
Mike Fiore |
1:e52ae6584f1c | 154 | static const char error[]; |
Mike Fiore |
1:e52ae6584f1c | 155 | |
Mike Fiore |
1:e52ae6584f1c | 156 | // Escape sequence |
Mike Fiore |
1:e52ae6584f1c | 157 | static const char escape_sequence[]; |
Mike Fiore |
14:f9a77400b622 | 158 | |
Mike Fiore |
1:e52ae6584f1c | 159 | static std::string formatPacketData(const std::vector<uint8_t>& data, const uint8_t& format); |
Mike Fiore |
1:e52ae6584f1c | 160 | static bool waitForEscape(int timeout, mDot* dot=NULL, WaitType wait=WAIT_NA); |
Mike Fiore |
1:e52ae6584f1c | 161 | |
Mike Fiore |
1:e52ae6584f1c | 162 | void start(); |
Mike Fiore |
14:f9a77400b622 | 163 | |
Mike Fiore |
14:f9a77400b622 | 164 | static mts::ATSerial* Serial() {return _serialp;} |
Mike Fiore |
14:f9a77400b622 | 165 | static mDot* Dot() {return _dot;} |
Mike Fiore |
14:f9a77400b622 | 166 | static mDot* _dot; |
Mike Fiore |
1:e52ae6584f1c | 167 | |
Mike Fiore |
14:f9a77400b622 | 168 | static void setErrorMessage(const char* message); |
Mike Fiore |
14:f9a77400b622 | 169 | static void setErrorMessage(const std::string& message); |
Mike Fiore |
14:f9a77400b622 | 170 | |
Mike Fiore |
14:f9a77400b622 | 171 | protected: |
Mike Fiore |
14:f9a77400b622 | 172 | |
Mike Fiore |
14:f9a77400b622 | 173 | static std::string _errorMessage; |
Mike Fiore |
14:f9a77400b622 | 174 | |
Mike Fiore |
14:f9a77400b622 | 175 | private: |
Mike Fiore |
4:666017851052 | 176 | |
Mike Fiore |
9:ff62b20f7000 | 177 | mts::ATSerial& _serial; |
Mike Fiore |
9:ff62b20f7000 | 178 | static mts::ATSerial* _serialp; |
Mike Fiore |
1:e52ae6584f1c | 179 | |
Mike Fiore |
14:f9a77400b622 | 180 | static CommandTerminal::RadioEvent* _events; |
Mike Fiore |
1:e52ae6584f1c | 181 | mDot::Mode _mode; |
Mike Fiore |
14:f9a77400b622 | 182 | |
Mike Fiore |
14:f9a77400b622 | 183 | static const Command _commands[NO_OF_COMMANDS]; |
Mike Fiore |
14:f9a77400b622 | 184 | static const verify_ptr_t _verify[NO_OF_COMMANDS]; |
Mike Fiore |
14:f9a77400b622 | 185 | static const action_ptr_t _action[NO_OF_COMMANDS]; |
Mike Fiore |
14:f9a77400b622 | 186 | |
Mike Fiore |
1:e52ae6584f1c | 187 | bool _sleep_standby; |
Mike Fiore |
1:e52ae6584f1c | 188 | DigitalOut _xbee_on_sleep; |
Mike Fiore |
14:f9a77400b622 | 189 | bool _autoOTAEnabled; |
Mike Fiore |
1:e52ae6584f1c | 190 | |
Mike Fiore |
9:ff62b20f7000 | 191 | void serialLoop(); |
Mike Fiore |
1:e52ae6584f1c | 192 | bool autoJoinCheck(); |
Mike Fiore |
1:e52ae6584f1c | 193 | |
Mike Fiore |
1:e52ae6584f1c | 194 | void printHelp(); |
Mike Fiore |
1:e52ae6584f1c | 195 | |
Mike Fiore |
14:f9a77400b622 | 196 | static bool readable(); |
Mike Fiore |
14:f9a77400b622 | 197 | static bool writeable(); |
Mike Fiore |
14:f9a77400b622 | 198 | static char read(); |
Mike Fiore |
14:f9a77400b622 | 199 | static void write(const char* message); |
Mike Fiore |
14:f9a77400b622 | 200 | static void writef(const char* format, ... ); |
Mike Fiore |
1:e52ae6584f1c | 201 | |
Mike Fiore |
1:e52ae6584f1c | 202 | void sleep(bool standby); |
Mike Fiore |
9:ff62b20f7000 | 203 | void wakeup(void); |
Mike Fiore |
14:f9a77400b622 | 204 | |
Mike Fiore |
1:e52ae6584f1c | 205 | }; |
Mike Fiore |
1:e52ae6584f1c | 206 | |
Mike Fiore |
1:e52ae6584f1c | 207 | #endif // __command_terminal_H__ |