From a4a42c870494426a72ae381b1ef3385f46593322 Mon Sep 17 00:00:00 2001 From: EricLiu2000 Date: Fri, 14 Jun 2019 16:09:19 -0400 Subject: [PATCH] Reworked updating LEDState to use sendCommand() instead of transmit() --- communication/encoder.cpp | 22 ++++++++++++++++++---- device/device.cpp | 11 ++--------- include/icsneo/communication/command.h | 3 ++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/communication/encoder.cpp b/communication/encoder.cpp index 1e5f53c..a5c14ef 100644 --- a/communication/encoder.cpp +++ b/communication/encoder.cpp @@ -103,9 +103,23 @@ bool Encoder::encode(std::vector& result, const std::shared_ptr& result, Command cmd, std::vector arguments) { auto msg = std::make_shared(); - msg->network = Network::NetID::Main51; - msg->data.reserve(arguments.size() + 1); - msg->data.push_back((uint8_t)cmd); - msg->data.insert(msg->data.end(), std::make_move_iterator(arguments.begin()), std::make_move_iterator(arguments.end())); + if(cmd == Command::UpdateLEDState) { + /* NetID::Device is a super old command type. + * It has a leading 0x00 byte, a byte for command, and a byte for an argument. + * In this case, command 0x06 is SetLEDState. + * This old command type is not really used anywhere else. + */ + msg->network = Network::NetID::Device; + msg->data.reserve(3); + msg->data.push_back(0x00); + msg->data.push_back(0x06); + msg->data.push_back(arguments.at(0)); + } else { + msg->network = Network::NetID::Main51; + msg->data.reserve(arguments.size() + 1); + msg->data.push_back((uint8_t)cmd); + msg->data.insert(msg->data.end(), std::make_move_iterator(arguments.begin()), std::make_move_iterator(arguments.end())); + } + return encode(result, msg); } \ No newline at end of file diff --git a/device/device.cpp b/device/device.cpp index d926818..131e8ca 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -300,13 +300,6 @@ void Device::handleInternalMessage(std::shared_ptr message) { } void Device::updateLEDState() { - /* NetID::Device is a super old command type. - * It has a leading 0x00 byte, a byte for command, and a byte for an argument. - * In this case, command 0x06 is SetLEDState. - * This old command type is not really used anywhere else. - */ - auto msg = std::make_shared(); - msg->network = Network::NetID::Device; - msg->data = {0x00, 0x06, uint8_t(ledState)}; - transmit(msg); + std::vector args {(uint8_t) ledState}; + com->sendCommand(Command::UpdateLEDState, args); } \ No newline at end of file diff --git a/include/icsneo/communication/command.h b/include/icsneo/communication/command.h index 6d4716a..8f61740 100644 --- a/include/icsneo/communication/command.h +++ b/include/icsneo/communication/command.h @@ -10,7 +10,8 @@ enum class Command : uint8_t { //GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused SaveSettings = 0xA6, SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM - ReadSettings = 0xC7 // Previously known as 3G_READ_SETTINGS_EX + ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX + UpdateLEDState = 0xA7 }; }