firm newest

Dependencies:   MTS-Serial libmDot-dev-mbed5-deprecated

Committer:
nguyenhoang9x5555
Date:
Mon Oct 22 01:56:09 2018 +0000
Revision:
1:c1c6549b9333
Parent:
0:3c869a8cb8f8
hey

Who changed what in which revision?

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