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 11 13:16:33 2020 -0500
Revision:
27:5fafd3b26ac3
Parent:
23:4f0a981c0349
Child:
28:c222ca8383f4
Update to Dot 3.3.6

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