![](/media/cache/group/MultiTech_Logo_Color_w_Tagline_PNG_1000px.png.50x50_q85.png)
AT command firmware for MultiTech Dot devices.
Fork of mDot_AT_firmware by
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.
Stable library for mDot.
xDot Library
Development library for xDot.
Stable library for xDot.
Diff: CommandTerminal/CommandTerminal.cpp
- Revision:
- 23:4f0a981c0349
- Parent:
- 22:a13ac7df92c0
- Child:
- 27:5fafd3b26ac3
--- a/CommandTerminal/CommandTerminal.cpp Mon Apr 22 10:28:29 2019 -0500 +++ b/CommandTerminal/CommandTerminal.cpp Wed Apr 24 10:47:25 2019 -0500 @@ -45,6 +45,9 @@ static uint8_t _battery_level = 0xFF; +static uint8_t f_data[252]; //max payload 242 plus 10 bytes for format +static uint32_t _rxAddress = 0; + void CommandTerminal::setErrorMessage(const char* message) { _errorMessage.assign(message); } @@ -52,7 +55,7 @@ void CommandTerminal::setErrorMessage(const std::string& message) { _errorMessage.assign(message); } - + CommandTerminal::CommandTerminal(mts::ATSerial& serial) : _serial(serial), _mode(mDot::COMMAND_MODE), @@ -177,8 +180,8 @@ serial_read_timer.reset(); timeout = _dot->getWakeTimeout(); - while (serial_read_timer.read_ms() < timeout && serial_buffer.size() <= _dot->getMaxPacketLength()) { - while (readable() && serial_buffer.size() < _dot->getMaxPacketLength()) { + while (serial_read_timer.read_ms() < timeout && serial_buffer.size() <= _dot->getNextTxMaxSize()) { + while (readable() && serial_buffer.size() < _dot->getNextTxMaxSize()) { serial_buffer.push_back(read()); serial_read_timer.reset(); @@ -201,7 +204,9 @@ if (_dot->getIsIdle()) { logDebug("Received serial data, sending out radio."); - + if(_dot->getRxOutput() == mDot::EXTENDED) { + formatPacketSDSend(serial_buffer); + } if (_dot->send(serial_buffer, false) != mDot::MDOT_OK) { logDebug("Send failed."); // If the data should be tossed after send failure, clear buffer @@ -216,14 +221,16 @@ } // call recv to wait for any packet before sending again - if (!_serialp->escaped()) + if (!_serialp->escaped()) { + data.clear(); _dot->recv(data); + } // Clear the serial buffer if send is success serial_buffer.clear(); // In class C mode pending data will be sent automatically without uplink - if (_dot->getClass() != "C") { + if (_dot->getClass() == "A") { if (_dot->getDataPending()) { logDebug("Data is pending"); goto L_SEND; @@ -232,6 +239,10 @@ logDebug("Ack requested"); goto L_SEND; } + if (_dot->hasMacCommands()) { + logDebug("Pending MAC answers"); + goto L_SEND; + } } } } else { @@ -585,6 +596,7 @@ logDebug("Enter Serial Mode"); write(connect); serial_data_mode = true; + _serialp->clearEscaped(); _mode = mDot::SERIAL_MODE; } else { logDebug("Network Not Joined"); @@ -610,9 +622,14 @@ _sleep_standby = 0; logWarning("This hardware version does not support deep sleep. Using sleep mode instead."); } -#endif +#endif write(done); - osDelay(5); + if (_dot->getBaud() < 9600) + osDelay(20); + else if (_dot->getBaud() > 57600) + osDelay(2); + else + osDelay(5); this->sleep(_sleep_standby); osDelay(1); } @@ -808,23 +825,23 @@ GPIO_InitTypeDef GPIO_InitStruct; // Set port A pins to analog nopull - GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 + GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Set port B pins to analog nopull GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); // Set port C pins to analog nopull GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); // iterate through potential wake pins - leave the configured wake pin alone if one is needed // XBEE_DIN - PA3 @@ -835,7 +852,7 @@ // XBEE_DIO6 - PA1 // XBEE_DIO7 - PA0 // XBEE_SLEEPRQ - PA11 - + if (_dot->getWakePin() != XBEE_DIN || _dot->getWakeMode() == mDot::RTC_ALARM) { GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; @@ -891,7 +908,7 @@ GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } - + #endif _dot->sleep(_dot->getWakeInterval(), _dot->getWakeMode(), standby); @@ -937,14 +954,23 @@ _serial.rxClear(); _serial.txClear(); - fota::getInstance()->fixEventQueue(); + Fota::getInstance()->fixEventQueue(); } std::string CommandTerminal::formatPacketData(const std::vector<uint8_t>& data, const uint8_t& format) { - if (format == mDot::HEXADECIMAL) - return mts::Text::bin2hexString(data); - else - return std::string(data.begin(), data.end()); + switch(format) { + case(mDot::HEXADECIMAL): + return mts::Text::bin2hexString(data); + + case(mDot::BINARY): + return std::string(data.begin(), data.end()); + + case(mDot::EXTENDED): + return formatPacket(data); + + default: + return ""; + } } bool CommandTerminal::waitForEscape(int timeout, mDot* dot, WaitType wait) { @@ -976,14 +1002,22 @@ void CommandTerminal::RadioEvent::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, uint32_t address, bool dupRx) { mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, slot, retries, address, dupRx); if(port == 200 || port == 201 || port == 202) { - fota::getInstance()->processCmd(payload, port, size); + Fota::getInstance()->processCmd(payload, port, size); } if (serial_data_mode && port != 0) { logDebug("Rx %d bytes", size); if (size > 0) { - CommandTerminal::Serial()->write((char*) RxPayload, RxPayloadSize); + if(CommandTerminal::Dot()->getRxOutput() == mDot::EXTENDED) { + formatPacket(RxPayload, size); + _rxAddress = address; + } else { + CommandTerminal::Serial()->write((char*) RxPayload, RxPayloadSize); + } } - if (!CommandTerminal::Serial()->readable() && _dot->getAckRequested() && _dot->getClass() == "C") { + if (!CommandTerminal::Serial()->readable() + && (_dot->getAckRequested() + || _dot->hasMacCommands()) + && (_dot->getClass() == "C" || _dot->getSettings()->Session.Class == lora::CLASS_B)) { _sendAck = true; } } @@ -993,10 +1027,85 @@ return _battery_level; } -void CommandTerminal::setBatteryLevel(uint8_t battery_level) { +void CommandTerminal::setBatteryLevel(uint8_t battery_level) { _battery_level = battery_level; } +void CommandTerminal::formatPacket(uint8_t* payload, uint16_t size) { + uint32_t fcnt = _dot->getDownLinkCounter(); + + if(_dot->getAckRequested()) { + f_data[0] = 0; + } else { + f_data[0] = 1; + } + + f_data[1] = _rxAddress & 0xFF; + f_data[2] = (_rxAddress >> 8) & 0xFF; + f_data[3] = (_rxAddress >> 16) & 0xFF; + f_data[4] = (_rxAddress >> 24) & 0xFF; + f_data[5] = fcnt & 0xFF; + f_data[6] = (fcnt >> 8) & 0xFF; + f_data[7] = (fcnt >> 16) & 0xFF; + f_data[8] = (fcnt >> 24) & 0xFF; + f_data[9] = _events->RxPort; + + for(int i = 0; i < size; i++) + f_data[i+10] = payload[i]; + + CommandTerminal::Serial()->write((char*)f_data, size + 10); +} + + +std::string CommandTerminal::formatPacket(std::vector<uint8_t> payload) { + uint32_t fcnt = _dot->getDownLinkCounter(); + + if(_dot->getAckRequested()) { + f_data[0] = 0; + } else { + f_data[0] = 1; + } + + f_data[1] = _rxAddress & 0xFF; + f_data[2] = (_rxAddress >> 8) & 0xFF; + f_data[3] = (_rxAddress >> 16) & 0xFF; + f_data[4] = (_rxAddress >> 24) & 0xFF; + f_data[5] = fcnt & 0xFF; + f_data[6] = (fcnt >> 8) & 0xFF; + f_data[7] = (fcnt >> 16) & 0xFF; + f_data[8] = (fcnt >> 24) & 0xFF; + f_data[9] = _events->RxPort; + + for(int i = 0; i < payload.size(); i++) + f_data[i+10] = payload.at(i); + + std::string ret((char*)f_data, payload.size() + 10); + return ret; +} + + + +void CommandTerminal::formatPacketSDSend(std::vector<uint8_t> &payload) { + if(payload.size() >= 3) { + _dot->setAppPort(payload[0]); + _dot->setRepeat(0); + _dot->setAck(0); + switch(payload[1]) { + case 0: + _dot->setAck(payload[2]); + break; + case 1: + _dot->setRepeat(payload[2]); + break; + default: + break; + } + payload.erase(payload.begin(), payload.begin()+3); + } +} + + + CommandTerminal::~CommandTerminal() { delete _events; }