MultiTech / Mbed OS mDot_AT_firmware_CUSTOM

Dependencies:   libmDot-Custom MTS-Serial

Fork of mDot_AT_firmware_CUSTOM by Jason Reiss

To change channel plans replace AS923 with AU915, EU868, KR920 or US915 on line 15

#define CHANNEL_PLAN CP_AS923

See Supported Channel Plans

Committer:
jreiss
Date:
Thu Mar 23 20:40:54 2017 +0000
Revision:
29:15b59b827ac7
Parent:
17:17963e6bd07d
update libmDot-Custom

Who changed what in which revision?

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