Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal.h
00001 /** 00002 ****************************************************************************** 00003 * File Name : command.h 00004 * Date : 18/04/2014 10:57:12 00005 * Description : This file provides code for command line prompt 00006 ****************************************************************************** 00007 * 00008 * COPYRIGHT(c) 2014 MultiTech Systems, Inc. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 1. Redistributions of source code must retain the above copyright notice, 00013 * this list of conditions and the following disclaimer. 00014 * 2. Redistributions in binary form must reproduce the above copyright notice, 00015 * this list of conditions and the following disclaimer in the documentation 00016 * and/or other materials provided with the distribution. 00017 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00030 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 ****************************************************************************** 00033 */ 00034 00035 #include "mbed.h" 00036 #include "ATSerial.h" 00037 #include "MTSSerial.h" 00038 #include "MTSSerialFlowControl.h" 00039 #include "Commands.h" 00040 #include "mDot.h" 00041 #include "mDotEvent.h" 00042 00043 /* Define to prevent recursive inclusion -------------------------------------*/ 00044 #ifndef __command_terminal_H__ 00045 #define __command_terminal_H__ 00046 00047 typedef uint32_t (*action_ptr_t)(std::vector<std::string> args); 00048 typedef bool (*verify_ptr_t)(std::vector<std::string> args); 00049 00050 class Command; 00051 00052 class CommandTerminal { 00053 00054 class RadioEvent : public mDotEvent { 00055 00056 public: 00057 RadioEvent() : _sendAck(false) {} 00058 00059 virtual ~RadioEvent() {} 00060 00061 virtual void TxDone(uint8_t dr) { 00062 mDotEvent::TxDone(dr); 00063 00064 logDebug("RadioEvent - TxDone"); 00065 } 00066 00067 virtual void TxTimeout(void) { 00068 mDotEvent::TxTimeout(); 00069 00070 logDebug("RadioEvent - TxTimeout"); 00071 } 00072 00073 virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { 00074 mDotEvent::JoinAccept(payload, size, rssi, snr); 00075 00076 logDebug("RadioEvent - JoinAccept"); 00077 } 00078 00079 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); 00080 00081 virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot) { 00082 mDotEvent::RxDone(payload, size, rssi, snr, ctrl, slot); 00083 00084 logDebug("RadioEvent - RxDone"); 00085 } 00086 00087 virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) { 00088 mDotEvent::Pong(m_rssi, m_snr, s_rssi, s_snr); 00089 00090 logDebug("RadioEvent - Pong"); 00091 } 00092 00093 virtual void NetworkLinkCheck(int16_t m_rssi, int8_t m_snr, int8_t s_snr, uint8_t s_gateways) { 00094 mDotEvent::NetworkLinkCheck(m_rssi, m_snr, s_snr, s_gateways); 00095 00096 logDebug("RadioEvent - NetworkLinkCheck"); 00097 } 00098 00099 virtual void RxTimeout(uint8_t slot) { 00100 mDotEvent::RxTimeout(slot); 00101 00102 // logDebug("RadioEvent - RxTimeout"); 00103 } 00104 00105 virtual void RxError(uint8_t slot) { 00106 mDotEvent::RxError(slot); 00107 00108 logDebug("RadioEvent - RxError"); 00109 } 00110 00111 virtual uint8_t MeasureBattery(void) { 00112 return 255; 00113 } 00114 00115 bool SendAck() { 00116 bool val = _sendAck; 00117 _sendAck = false; 00118 return val; 00119 } 00120 00121 bool _sendAck; 00122 }; 00123 00124 public: 00125 00126 enum WaitType { 00127 WAIT_JOIN, 00128 WAIT_RECV, 00129 WAIT_LINK, 00130 WAIT_SEND, 00131 WAIT_NA 00132 }; 00133 00134 CommandTerminal(mts::ATSerial& serial); 00135 virtual ~CommandTerminal(); 00136 00137 void init(); 00138 00139 // Command prompt text... 00140 static const char banner[]; 00141 static const char helpline[]; 00142 static const char prompt[]; 00143 00144 // Command error text... 00145 static const char command_error[]; 00146 00147 // Response texts... 00148 static const char help[]; 00149 static const char cmd_error[]; 00150 static const char newline[]; 00151 static const char connect[]; 00152 static const char no_carrier[]; 00153 static const char done[]; 00154 static const char error[]; 00155 00156 // Escape sequence 00157 static const char escape_sequence[]; 00158 00159 static std::string formatPacketData(const std::vector<uint8_t>& data, const uint8_t& format); 00160 static bool waitForEscape(int timeout, mDot* dot=NULL, WaitType wait=WAIT_NA); 00161 00162 void start(); 00163 00164 static mts::ATSerial* Serial() {return _serialp;} 00165 static mDot* Dot() {return _dot;} 00166 static mDot* _dot; 00167 00168 static void setErrorMessage(const char* message); 00169 static void setErrorMessage(const std::string& message); 00170 00171 protected: 00172 00173 static std::string _errorMessage; 00174 00175 private: 00176 00177 mts::ATSerial& _serial; 00178 static mts::ATSerial* _serialp; 00179 00180 static CommandTerminal::RadioEvent* _events; 00181 mDot::Mode _mode; 00182 00183 static const Command _commands[NO_OF_COMMANDS]; 00184 static const verify_ptr_t _verify[NO_OF_COMMANDS]; 00185 static const action_ptr_t _action[NO_OF_COMMANDS]; 00186 00187 bool _sleep_standby; 00188 DigitalOut _xbee_on_sleep; 00189 bool _autoOTAEnabled; 00190 00191 void serialLoop(); 00192 bool autoJoinCheck(); 00193 00194 void printHelp(); 00195 00196 static bool readable(); 00197 static bool writeable(); 00198 static char read(); 00199 static void write(const char* message); 00200 static void writef(const char* format, ... ); 00201 00202 void sleep(bool standby); 00203 void wakeup(void); 00204 00205 }; 00206 00207 #endif // __command_terminal_H__
Generated on Tue Jul 12 2022 20:40:04 by
