AT command firmware for MultiTech Dot devices.

Fork of mDot_AT_firmware by MultiTech

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.

libmDot-dev

Stable library for mDot.

libmDot

xDot Library

Development library for xDot.

libxDot-dev

Stable library for xDot.

libxDot

Committer:
Jason Reiss
Date:
Fri Aug 12 11:08:59 2022 -0500
Revision:
35:e17e00b8e022
Parent:
28:c222ca8383f4
Child:
36:b586cd6e91f3
Update AT Version to 4.1.5

Who changed what in which revision?

UserRevisionLine numberNew 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 1:e52ae6584f1c 36 #include "Commands.h"
Mike Fiore 1:e52ae6584f1c 37 #include "mDot.h"
Mike Fiore 9:ff62b20f7000 38 #include "mDotEvent.h"
jenkins@jenkinsdm1 18:63f098f042b2 39 #include "Fota.h"
Jason Reiss 28:c222ca8383f4 40 #include "ATSerial.h"
Mike Fiore 14:f9a77400b622 41
Mike Fiore 1:e52ae6584f1c 42 /* Define to prevent recursive inclusion -------------------------------------*/
Mike Fiore 1:e52ae6584f1c 43 #ifndef __command_terminal_H__
Mike Fiore 1:e52ae6584f1c 44 #define __command_terminal_H__
Mike Fiore 1:e52ae6584f1c 45
Jason Reiss 28:c222ca8383f4 46 #ifndef MTS_CMD_TERM_TEST_COMMANDS
Jason Reiss 28:c222ca8383f4 47 #define MTS_CMD_TERM_TEST_COMMANDS 1
Jason Reiss 28:c222ca8383f4 48 #endif
Jason Reiss 28:c222ca8383f4 49
Jason Reiss 28:c222ca8383f4 50 #ifndef MTS_CMD_TERM_VERBOSE
Jason Reiss 28:c222ca8383f4 51 #define MTS_CMD_TERM_VERBOSE 1
Jason Reiss 28:c222ca8383f4 52 #endif
Jason Reiss 28:c222ca8383f4 53
Mike Fiore 14:f9a77400b622 54 typedef uint32_t (*action_ptr_t)(std::vector<std::string> args);
Mike Fiore 14:f9a77400b622 55 typedef bool (*verify_ptr_t)(std::vector<std::string> args);
Mike Fiore 14:f9a77400b622 56
Mike Fiore 14:f9a77400b622 57 class Command;
Mike Fiore 14:f9a77400b622 58
Mike Fiore 1:e52ae6584f1c 59 class CommandTerminal {
Mike Fiore 1:e52ae6584f1c 60
Mike Fiore 14:f9a77400b622 61 class RadioEvent : public mDotEvent {
Mike Fiore 9:ff62b20f7000 62
jenkins@jenkinsdm1 18:63f098f042b2 63 public:
Mike Fiore 14:f9a77400b622 64 RadioEvent() : _sendAck(false) {}
Mike Fiore 9:ff62b20f7000 65
Mike Fiore 9:ff62b20f7000 66 virtual ~RadioEvent() {}
Mike Fiore 9:ff62b20f7000 67
Mike Fiore 14:f9a77400b622 68 virtual void TxDone(uint8_t dr) {
Mike Fiore 14:f9a77400b622 69 mDotEvent::TxDone(dr);
Mike Fiore 14:f9a77400b622 70
Mike Fiore 14:f9a77400b622 71 logDebug("RadioEvent - TxDone");
Mike Fiore 14:f9a77400b622 72 }
Mike Fiore 14:f9a77400b622 73
Mike Fiore 14:f9a77400b622 74 virtual void TxTimeout(void) {
Mike Fiore 14:f9a77400b622 75 mDotEvent::TxTimeout();
Mike Fiore 14:f9a77400b622 76
Mike Fiore 14:f9a77400b622 77 logDebug("RadioEvent - TxTimeout");
Mike Fiore 14:f9a77400b622 78 }
Mike Fiore 14:f9a77400b622 79
Jason Reiss 27:5fafd3b26ac3 80 virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr) {
Mike Fiore 14:f9a77400b622 81 mDotEvent::JoinAccept(payload, size, rssi, snr);
Mike Fiore 14:f9a77400b622 82
Mike Fiore 14:f9a77400b622 83 logDebug("RadioEvent - JoinAccept");
Mike Fiore 14:f9a77400b622 84 }
Mike Fiore 14:f9a77400b622 85
Jason Reiss 27:5fafd3b26ac3 86 virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr) {
jenkins@jenkinsdm1 16:d5cf2af81a6d 87 mDotEvent::JoinFailed(payload, size, rssi, snr);
jenkins@jenkinsdm1 16:d5cf2af81a6d 88
jenkins@jenkinsdm1 16:d5cf2af81a6d 89 logDebug("RadioEvent - JoinFailed");
jenkins@jenkinsdm1 16:d5cf2af81a6d 90 }
jenkins@jenkinsdm1 16:d5cf2af81a6d 91
Jason Reiss 28:c222ca8383f4 92 virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, uint32_t fcnt, bool dupRx);
Jason Reiss 27:5fafd3b26ac3 93
Jason Reiss 27:5fafd3b26ac3 94 virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr, lora::DownlinkControl ctrl, uint8_t slot);
Mike Fiore 14:f9a77400b622 95
Jason Reiss 27:5fafd3b26ac3 96 virtual void RxTimeout(uint8_t slot);
Mike Fiore 14:f9a77400b622 97
Jason Reiss 27:5fafd3b26ac3 98 virtual void Pong(int16_t m_rssi, int16_t m_snr, int16_t s_rssi, int16_t s_snr) {
Mike Fiore 14:f9a77400b622 99 mDotEvent::Pong(m_rssi, m_snr, s_rssi, s_snr);
Mike Fiore 14:f9a77400b622 100
Mike Fiore 14:f9a77400b622 101 logDebug("RadioEvent - Pong");
Mike Fiore 14:f9a77400b622 102 }
Mike Fiore 14:f9a77400b622 103
Jason Reiss 27:5fafd3b26ac3 104 virtual void NetworkLinkCheck(int16_t m_rssi, int16_t m_snr, int16_t s_snr, uint8_t s_gateways) {
Mike Fiore 14:f9a77400b622 105 mDotEvent::NetworkLinkCheck(m_rssi, m_snr, s_snr, s_gateways);
Mike Fiore 14:f9a77400b622 106
Mike Fiore 14:f9a77400b622 107 logDebug("RadioEvent - NetworkLinkCheck");
Mike Fiore 14:f9a77400b622 108 }
Mike Fiore 14:f9a77400b622 109
Jason Reiss 27:5fafd3b26ac3 110 virtual void ServerTime(uint32_t seconds, uint8_t sub_seconds) {
Jason Reiss 27:5fafd3b26ac3 111 mDotEvent::ServerTime(seconds, sub_seconds);
Mike Fiore 14:f9a77400b622 112
Jason Reiss 27:5fafd3b26ac3 113 Fota::getInstance()->setClockOffset(seconds);
Mike Fiore 14:f9a77400b622 114 }
Mike Fiore 14:f9a77400b622 115
Mike Fiore 14:f9a77400b622 116 virtual void RxError(uint8_t slot) {
Mike Fiore 14:f9a77400b622 117 mDotEvent::RxError(slot);
Mike Fiore 14:f9a77400b622 118
Mike Fiore 14:f9a77400b622 119 logDebug("RadioEvent - RxError");
Mike Fiore 14:f9a77400b622 120 }
Mike Fiore 9:ff62b20f7000 121
Mike Fiore 9:ff62b20f7000 122 virtual uint8_t MeasureBattery(void) {
jenkins@jenkinsdm1 18:63f098f042b2 123 return CommandTerminal::getBatteryLevel();
Mike Fiore 9:ff62b20f7000 124 }
Mike Fiore 9:ff62b20f7000 125
jenkins@jenkinsdm1 16:d5cf2af81a6d 126 virtual void MissedAck(uint8_t retries) {
jenkins@jenkinsdm1 16:d5cf2af81a6d 127 mDotEvent::MissedAck(retries);
jenkins@jenkinsdm1 16:d5cf2af81a6d 128 }
jenkins@jenkinsdm1 16:d5cf2af81a6d 129
Mike Fiore 14:f9a77400b622 130 bool SendAck() {
Mike Fiore 14:f9a77400b622 131 bool val = _sendAck;
Mike Fiore 14:f9a77400b622 132 _sendAck = false;
Mike Fiore 14:f9a77400b622 133 return val;
Mike Fiore 14:f9a77400b622 134 }
Mike Fiore 9:ff62b20f7000 135
Mike Fiore 14:f9a77400b622 136 bool _sendAck;
Jason Reiss 28:c222ca8383f4 137
Jason Reiss 28:c222ca8383f4 138 void handleTestModePacket();
Mike Fiore 14:f9a77400b622 139 };
Mike Fiore 14:f9a77400b622 140
jenkins@jenkinsdm1 18:63f098f042b2 141 public:
Mike Fiore 1:e52ae6584f1c 142
Mike Fiore 1:e52ae6584f1c 143 enum WaitType {
Mike Fiore 1:e52ae6584f1c 144 WAIT_JOIN,
Mike Fiore 1:e52ae6584f1c 145 WAIT_RECV,
Mike Fiore 1:e52ae6584f1c 146 WAIT_LINK,
Mike Fiore 1:e52ae6584f1c 147 WAIT_SEND,
Mike Fiore 1:e52ae6584f1c 148 WAIT_NA
Mike Fiore 1:e52ae6584f1c 149 };
Mike Fiore 1:e52ae6584f1c 150
Mike Fiore 14:f9a77400b622 151 CommandTerminal(mts::ATSerial& serial);
Mike Fiore 9:ff62b20f7000 152 virtual ~CommandTerminal();
Mike Fiore 14:f9a77400b622 153
Mike Fiore 14:f9a77400b622 154 void init();
Mike Fiore 14:f9a77400b622 155
Mike Fiore 1:e52ae6584f1c 156 // Command prompt text...
Mike Fiore 1:e52ae6584f1c 157 static const char banner[];
Mike Fiore 1:e52ae6584f1c 158 static const char helpline[];
Mike Fiore 1:e52ae6584f1c 159 static const char prompt[];
Mike Fiore 14:f9a77400b622 160
Mike Fiore 1:e52ae6584f1c 161 // Command error text...
Mike Fiore 1:e52ae6584f1c 162 static const char command_error[];
Mike Fiore 14:f9a77400b622 163
Mike Fiore 1:e52ae6584f1c 164 // Response texts...
Mike Fiore 1:e52ae6584f1c 165 static const char help[];
Mike Fiore 1:e52ae6584f1c 166 static const char cmd_error[];
Mike Fiore 1:e52ae6584f1c 167 static const char newline[];
Mike Fiore 9:ff62b20f7000 168 static const char connect[];
Mike Fiore 9:ff62b20f7000 169 static const char no_carrier[];
Mike Fiore 1:e52ae6584f1c 170 static const char done[];
Mike Fiore 1:e52ae6584f1c 171 static const char error[];
Mike Fiore 1:e52ae6584f1c 172
Mike Fiore 1:e52ae6584f1c 173 // Escape sequence
Mike Fiore 1:e52ae6584f1c 174 static const char escape_sequence[];
Mike Fiore 14:f9a77400b622 175
Mike Fiore 1:e52ae6584f1c 176 static std::string formatPacketData(const std::vector<uint8_t>& data, const uint8_t& format);
Mike Fiore 1:e52ae6584f1c 177 static bool waitForEscape(int timeout, mDot* dot=NULL, WaitType wait=WAIT_NA);
Mike Fiore 1:e52ae6584f1c 178
Mike Fiore 1:e52ae6584f1c 179 void start();
Mike Fiore 14:f9a77400b622 180
Mike Fiore 14:f9a77400b622 181 static mts::ATSerial* Serial() {return _serialp;}
Jason Reiss 23:4f0a981c0349 182
Mike Fiore 14:f9a77400b622 183 static mDot* Dot() {return _dot;}
Mike Fiore 14:f9a77400b622 184 static mDot* _dot;
Mike Fiore 1:e52ae6584f1c 185
Jason Reiss 23:4f0a981c0349 186 static const RadioEvent* Events() { return _events; }
Jason Reiss 23:4f0a981c0349 187
Mike Fiore 14:f9a77400b622 188 static void setErrorMessage(const char* message);
Mike Fiore 14:f9a77400b622 189 static void setErrorMessage(const std::string& message);
Jason Reiss 27:5fafd3b26ac3 190
jenkins@jenkinsdm1 18:63f098f042b2 191 static uint8_t getBatteryLevel();
jenkins@jenkinsdm1 18:63f098f042b2 192 static void setBatteryLevel(const uint8_t battery_level);
Mike Fiore 14:f9a77400b622 193
Jason Reiss 27:5fafd3b26ac3 194 static void formatPacket(uint8_t* payload, uint16_t size, bool hex = false);
Jason Reiss 27:5fafd3b26ac3 195 static std::string formatPacket(std::vector<uint8_t> payload, bool hex = false);
Jason Reiss 23:4f0a981c0349 196 static void formatPacketSDSend(std::vector<uint8_t> &payload);
jenkins@jenkinsdm1 18:63f098f042b2 197 protected:
Mike Fiore 14:f9a77400b622 198 static std::string _errorMessage;
Mike Fiore 14:f9a77400b622 199
jenkins@jenkinsdm1 18:63f098f042b2 200 private:
Mike Fiore 9:ff62b20f7000 201 mts::ATSerial& _serial;
Mike Fiore 9:ff62b20f7000 202 static mts::ATSerial* _serialp;
Mike Fiore 1:e52ae6584f1c 203
Mike Fiore 14:f9a77400b622 204 static CommandTerminal::RadioEvent* _events;
Mike Fiore 1:e52ae6584f1c 205 mDot::Mode _mode;
Mike Fiore 14:f9a77400b622 206
Mike Fiore 1:e52ae6584f1c 207 bool _sleep_standby;
Mike Fiore 1:e52ae6584f1c 208 DigitalOut _xbee_on_sleep;
Mike Fiore 14:f9a77400b622 209 bool _autoOTAEnabled;
Mike Fiore 1:e52ae6584f1c 210
Mike Fiore 9:ff62b20f7000 211 void serialLoop();
Mike Fiore 1:e52ae6584f1c 212 bool autoJoinCheck();
Jason Reiss 28:c222ca8383f4 213 #if MTS_CMD_TERM_VERBOSE
Mike Fiore 1:e52ae6584f1c 214 void printHelp();
Jason Reiss 28:c222ca8383f4 215 #endif
Mike Fiore 1:e52ae6584f1c 216
Mike Fiore 14:f9a77400b622 217 static bool readable();
Mike Fiore 14:f9a77400b622 218 static bool writeable();
Mike Fiore 14:f9a77400b622 219 static char read();
Mike Fiore 14:f9a77400b622 220 static void write(const char* message);
Mike Fiore 14:f9a77400b622 221 static void writef(const char* format, ... );
Mike Fiore 1:e52ae6584f1c 222
Mike Fiore 1:e52ae6584f1c 223 void sleep(bool standby);
Mike Fiore 9:ff62b20f7000 224 void wakeup(void);
Mike Fiore 14:f9a77400b622 225
jenkins@jenkinsdm1 18:63f098f042b2 226 uint8_t* _payload;
jenkins@jenkinsdm1 18:63f098f042b2 227 uint8_t _size;
jenkins@jenkinsdm1 18:63f098f042b2 228 uint8_t _port;
jenkins@jenkinsdm1 18:63f098f042b2 229 std::vector<uint8_t> data;
Mike Fiore 1:e52ae6584f1c 230 };
Mike Fiore 1:e52ae6584f1c 231
Mike Fiore 1:e52ae6584f1c 232 #endif // __command_terminal_H__