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 Sep 08 08:34:24 2023 -0500
Revision:
36:b586cd6e91f3
Parent:
28:c222ca8383f4
Update AT Version to 4.2.1

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