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:
jreiss
Date:
Fri May 03 18:49:18 2019 +0000
Revision:
26:35c201bc5205
Parent:
9:ff62b20f7000
Child:
27:5fafd3b26ac3
Update to Dot 3.2.1 release; Remove AutoSleep command; Update mbed-os to 5.11.1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 9:ff62b20f7000 1 #include "mbed.h"
Mike Fiore 9:ff62b20f7000 2 #include "ATSerial.h"
Mike Fiore 9:ff62b20f7000 3 #include "MTSLog.h"
Mike Fiore 9:ff62b20f7000 4
Mike Fiore 9:ff62b20f7000 5 using namespace mts;
Mike Fiore 9:ff62b20f7000 6
Mike Fiore 9:ff62b20f7000 7 ATSerial::ATSerial(PinName TXD, PinName RXD, int txBufferSize, int rxBufferSize)
Mike Fiore 9:ff62b20f7000 8 : MTSSerial(TXD, RXD, txBufferSize, rxBufferSize)
Mike Fiore 9:ff62b20f7000 9 , _serial(new RawSerial(TXD,RXD)),
Mike Fiore 9:ff62b20f7000 10 _baudrate(9600),
Mike Fiore 9:ff62b20f7000 11 _bits(8),
Mike Fiore 9:ff62b20f7000 12 _parity(mbed::SerialBase::None),
Mike Fiore 9:ff62b20f7000 13 _stop_bits(1),
Mike Fiore 9:ff62b20f7000 14 _last_time(0),
Mike Fiore 9:ff62b20f7000 15 _esc_cnt(0),
Mike Fiore 9:ff62b20f7000 16 _esc_ch('+'),
Mike Fiore 9:ff62b20f7000 17 _escaped(false)
Mike Fiore 9:ff62b20f7000 18 {
Mike Fiore 9:ff62b20f7000 19 timer.start();
Mike Fiore 9:ff62b20f7000 20 _serial->attach(this, &ATSerial::handleRead, Serial::RxIrq);
Mike Fiore 9:ff62b20f7000 21 }
Mike Fiore 9:ff62b20f7000 22
Mike Fiore 9:ff62b20f7000 23 ATSerial::~ATSerial()
Mike Fiore 9:ff62b20f7000 24 {
Mike Fiore 9:ff62b20f7000 25 delete _serial;
Mike Fiore 9:ff62b20f7000 26 }
Mike Fiore 9:ff62b20f7000 27
Mike Fiore 9:ff62b20f7000 28
Mike Fiore 9:ff62b20f7000 29
Mike Fiore 9:ff62b20f7000 30 void ATSerial::baud(int baudrate)
Mike Fiore 9:ff62b20f7000 31 {
Mike Fiore 9:ff62b20f7000 32 _baudrate = baudrate;
Mike Fiore 9:ff62b20f7000 33 _serial->baud(_baudrate);
Mike Fiore 9:ff62b20f7000 34 }
Mike Fiore 9:ff62b20f7000 35
Mike Fiore 9:ff62b20f7000 36 void ATSerial::format(int bits, SerialBase::Parity parity, int stop_bits)
Mike Fiore 9:ff62b20f7000 37 {
Mike Fiore 9:ff62b20f7000 38 _bits = bits;
Mike Fiore 9:ff62b20f7000 39 _parity = parity;
Mike Fiore 9:ff62b20f7000 40 _stop_bits = stop_bits;
Mike Fiore 9:ff62b20f7000 41 _serial->format(_bits, _parity, _stop_bits);
Mike Fiore 9:ff62b20f7000 42 }
Mike Fiore 9:ff62b20f7000 43
Mike Fiore 9:ff62b20f7000 44 void ATSerial::handleWrite()
Mike Fiore 9:ff62b20f7000 45 {
Mike Fiore 9:ff62b20f7000 46 while(txBuffer.size() != 0) {
Mike Fiore 9:ff62b20f7000 47 if (_serial->writeable()) {
Mike Fiore 9:ff62b20f7000 48 char byte;
Mike Fiore 9:ff62b20f7000 49 if(txBuffer.read(byte) == 1) {
Mike Fiore 9:ff62b20f7000 50 _serial->attach(NULL, Serial::RxIrq);
Mike Fiore 9:ff62b20f7000 51 _serial->putc(byte);
Mike Fiore 9:ff62b20f7000 52 _serial->attach(this, &ATSerial::handleRead, Serial::RxIrq);
Mike Fiore 9:ff62b20f7000 53 }
Mike Fiore 9:ff62b20f7000 54 } else {
Mike Fiore 9:ff62b20f7000 55 return;
Mike Fiore 9:ff62b20f7000 56 }
Mike Fiore 9:ff62b20f7000 57 }
Mike Fiore 9:ff62b20f7000 58 }
Mike Fiore 9:ff62b20f7000 59
Mike Fiore 9:ff62b20f7000 60 void mts::ATSerial::reattach(PinName TXD, PinName RXD) {
Mike Fiore 9:ff62b20f7000 61 delete _serial;
Mike Fiore 9:ff62b20f7000 62 _serial = new RawSerial(TXD, RXD);
Mike Fiore 9:ff62b20f7000 63 _serial->attach(this, &ATSerial::handleRead, Serial::RxIrq);
Mike Fiore 9:ff62b20f7000 64 _serial->baud(_baudrate);
Mike Fiore 9:ff62b20f7000 65 _serial->format(_bits, _parity, _stop_bits);
Mike Fiore 9:ff62b20f7000 66 rxBuffer.clear();
Mike Fiore 9:ff62b20f7000 67 txBuffer.clear();
Mike Fiore 9:ff62b20f7000 68 }
Mike Fiore 9:ff62b20f7000 69
Mike Fiore 9:ff62b20f7000 70 void mts::ATSerial::sendBreak() {
Mike Fiore 9:ff62b20f7000 71 _serial->send_break();
Mike Fiore 9:ff62b20f7000 72 }
Mike Fiore 9:ff62b20f7000 73
Mike Fiore 9:ff62b20f7000 74 bool ATSerial::escaped() {
Mike Fiore 9:ff62b20f7000 75
Mike Fiore 9:ff62b20f7000 76 int now = timer.read_ms();
Mike Fiore 9:ff62b20f7000 77
Mike Fiore 9:ff62b20f7000 78 // Have we seen three esc chars and 1 sec end guard has passed
Mike Fiore 9:ff62b20f7000 79 if (_escaped || (_esc_cnt == 3 && (now - _last_time > 1000))) {
Mike Fiore 9:ff62b20f7000 80 _escaped = true;
Mike Fiore 9:ff62b20f7000 81 return true;
Mike Fiore 9:ff62b20f7000 82
Mike Fiore 9:ff62b20f7000 83 // Have we seen a couple esc chars but nothing in 500 ms
Mike Fiore 9:ff62b20f7000 84 } else if (_esc_cnt > 0 && _esc_cnt != 3 && now - _last_time > 500) {
Mike Fiore 9:ff62b20f7000 85 // Write seen esc chars
Mike Fiore 9:ff62b20f7000 86 while (_esc_cnt) {
Mike Fiore 9:ff62b20f7000 87 rxBuffer.write(_esc_ch);
Mike Fiore 9:ff62b20f7000 88 _esc_cnt--;
Mike Fiore 9:ff62b20f7000 89 }
Mike Fiore 9:ff62b20f7000 90 }
Mike Fiore 9:ff62b20f7000 91
Mike Fiore 9:ff62b20f7000 92 return false;
Mike Fiore 9:ff62b20f7000 93 }
Mike Fiore 9:ff62b20f7000 94
Mike Fiore 9:ff62b20f7000 95 void ATSerial::clearEscaped() {
Mike Fiore 9:ff62b20f7000 96 _esc_cnt = 0;
Mike Fiore 9:ff62b20f7000 97 _escaped = false;
Mike Fiore 9:ff62b20f7000 98 }
Mike Fiore 9:ff62b20f7000 99
Mike Fiore 9:ff62b20f7000 100 void ATSerial::handleRead()
Mike Fiore 9:ff62b20f7000 101 {
Mike Fiore 9:ff62b20f7000 102 char byte = _serial->getc();
Mike Fiore 9:ff62b20f7000 103 int now = timer.read_ms();
Mike Fiore 9:ff62b20f7000 104
Mike Fiore 9:ff62b20f7000 105 // Have we seen 3 esc chars but this char is before 1 sec end guard time
Mike Fiore 9:ff62b20f7000 106 if (_esc_cnt == 3 && (now - _last_time < 1000)) {
Mike Fiore 9:ff62b20f7000 107 // Write the three chars we held back
Mike Fiore 9:ff62b20f7000 108 while (_esc_cnt) {
Mike Fiore 9:ff62b20f7000 109 rxBuffer.write(_esc_ch);
Mike Fiore 9:ff62b20f7000 110 _esc_cnt--;
Mike Fiore 9:ff62b20f7000 111 }
Mike Fiore 9:ff62b20f7000 112 } else if (byte == _esc_ch) {
Mike Fiore 9:ff62b20f7000 113 // Has 1 second passed before last char
Mike Fiore 9:ff62b20f7000 114 if (now - _last_time > 1000) {
Mike Fiore 9:ff62b20f7000 115 _esc_cnt = 1;
Mike Fiore 9:ff62b20f7000 116 // Is this second or third esc char
Mike Fiore 9:ff62b20f7000 117 } else if (_esc_cnt > 0 && _esc_cnt < 3) {
Mike Fiore 9:ff62b20f7000 118 _esc_cnt++;
Mike Fiore 9:ff62b20f7000 119 }
Mike Fiore 9:ff62b20f7000 120 } else if (_esc_cnt > 0) {
Mike Fiore 9:ff62b20f7000 121 // Write any esc chars held back
Mike Fiore 9:ff62b20f7000 122 while (_esc_cnt) {
Mike Fiore 9:ff62b20f7000 123 rxBuffer.write(_esc_ch);
Mike Fiore 9:ff62b20f7000 124 _esc_cnt--;
Mike Fiore 9:ff62b20f7000 125 }
Mike Fiore 9:ff62b20f7000 126 }
Mike Fiore 9:ff62b20f7000 127
Mike Fiore 9:ff62b20f7000 128 if(_esc_cnt == 0 && rxBuffer.write(byte) != 1) {
Mike Fiore 9:ff62b20f7000 129 // logError("Serial Rx Byte Dropped [%c][0x%02X]", byte, byte);
Mike Fiore 9:ff62b20f7000 130 }
Mike Fiore 9:ff62b20f7000 131
Mike Fiore 9:ff62b20f7000 132 _last_time = timer.read_ms();
Mike Fiore 9:ff62b20f7000 133 }
Mike Fiore 9:ff62b20f7000 134
Mike Fiore 9:ff62b20f7000 135 void ATSerial::escapeChar(char esc) {
Mike Fiore 9:ff62b20f7000 136 _esc_ch = esc;
Mike Fiore 9:ff62b20f7000 137 }
Mike Fiore 9:ff62b20f7000 138
Mike Fiore 9:ff62b20f7000 139 char ATSerial::escapeChar() {
Mike Fiore 9:ff62b20f7000 140 return _esc_ch;
Mike Fiore 9:ff62b20f7000 141 }