diff --git a/communication/communication.cpp b/communication/communication.cpp index 092e482..5b413e6 100644 --- a/communication/communication.cpp +++ b/communication/communication.cpp @@ -11,6 +11,7 @@ #include "icsneo/communication/packetizer.h" #include "icsneo/communication/message/serialnumbermessage.h" #include "icsneo/communication/message/filter/main51messagefilter.h" +#include "icsneo/communication/message/readsettingsmessage.h" using namespace icsneo; @@ -59,10 +60,17 @@ bool Communication::sendCommand(Command cmd, std::vector arguments) { } bool Communication::getSettingsSync(std::vector& data, std::chrono::milliseconds timeout) { - sendCommand(Command::GetSettings); - std::shared_ptr msg = waitForMessageSync(MessageFilter(Network::NetID::RED_READ_BAUD_SETTINGS), timeout); + sendCommand(Command::ReadSettings, { 0, 0, 0, 1 /* Get Global Settings */, 0, 1 /* Subversion 1 */ }); + std::shared_ptr msg = waitForMessageSync(MessageFilter(Network::NetID::ReadSettings), timeout); if(!msg) return false; + + std::shared_ptr gsmsg = std::dynamic_pointer_cast(msg); + if(!gsmsg) + return false; + + if(gsmsg->response != ReadSettingsMessage::Response::OK) + return false; data = std::move(msg->data); return true; diff --git a/communication/decoder.cpp b/communication/decoder.cpp index b8a44ae..0a3fe36 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -2,6 +2,7 @@ #include "icsneo/communication/communication.h" #include "icsneo/communication/message/serialnumbermessage.h" #include "icsneo/communication/message/resetstatusmessage.h" +#include "icsneo/communication/message/readsettingsmessage.h" #include "icsneo/communication/command.h" #include "icsneo/device/device.h" #include @@ -171,6 +172,26 @@ bool Decoder::decode(std::shared_ptr& result, const std::shared_ptrdata.resize(length); return decode(result, packet); } + case Network::NetID::ReadSettings: { + auto msg = std::make_shared(); + msg->network = packet->network; + msg->response = ReadSettingsMessage::Response(packet->data[0]); + + if(msg->response == ReadSettingsMessage::Response::OK) { + // The global settings structure is the payload of the message in this case + msg->data.insert(msg->data.begin(), packet->data.begin() + 10, packet->data.end()); + uint16_t resp_len = msg->data[8] | (msg->data[9] << 8); + if(msg->data.size() - 1 == resp_len) // There is a padding byte at the end + msg->data.pop_back(); + result = msg; + return true; + } + + // We did not get a successful response, so the payload is all of the data + msg->data.insert(msg->data.begin(), packet->data.begin(), packet->data.end()); + result = msg; + return true; + } } } diff --git a/include/icsneo/communication/command.h b/include/icsneo/communication/command.h index 6869be6..6d4716a 100644 --- a/include/icsneo/communication/command.h +++ b/include/icsneo/communication/command.h @@ -7,9 +7,10 @@ enum class Command : uint8_t { EnableNetworkCommunication = 0x07, RequestSerialNumber = 0xA1, SetSettings = 0xA4, // Previously known as RED_CMD_SET_BAUD_REQ, follow up with SaveSettings to write to EEPROM - GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ + //GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused SaveSettings = 0xA6, - SetDefaultSettings = 0xA8 // Follow up with SaveSettings to write to EEPROM + SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM + ReadSettings = 0xC7 // Previously known as 3G_READ_SETTINGS_EX }; } diff --git a/include/icsneo/communication/message/readsettingsmessage.h b/include/icsneo/communication/message/readsettingsmessage.h new file mode 100644 index 0000000..d617797 --- /dev/null +++ b/include/icsneo/communication/message/readsettingsmessage.h @@ -0,0 +1,28 @@ +#ifndef __READSETTINGSMESSAGE_H_ +#define __READSETTINGSMESSAGE_H_ + +#include "icsneo/communication/message/message.h" +#include "icsneo/communication/communication.h" + +namespace icsneo { + +class ReadSettingsMessage : public Message { +public: + virtual ~ReadSettingsMessage() = default; + + enum class Response : uint8_t { + OK = 0, + GeneralFailure = 1, + InvalidSubcommand = 2, + InvalidSubversion = 3, + NotEnoughMemory = 4, + APIFailure = 5, + APIUnsupported = 6 + }; + + Response response; +}; + +} + +#endif \ No newline at end of file diff --git a/include/icsneo/communication/network.h b/include/icsneo/communication/network.h index 1c75404..79bfb3c 100644 --- a/include/icsneo/communication/network.h +++ b/include/icsneo/communication/network.h @@ -79,7 +79,7 @@ public: Read_Datalink_Cm_Tx_Msg = 57, Read_Datalink_Cm_Rx_Msg = 58, Logging_Overflow = 59, - Read_Settings_Ex = 60, + ReadSettings = 60, HSCAN4 = 61, HSCAN5 = 62, RS232 = 63, @@ -313,8 +313,8 @@ public: return "Read Datalink Cm Rx Msg"; case NetID::Logging_Overflow: return "Logging Overflow"; - case NetID::Read_Settings_Ex: - return "Read Settings Ex"; + case NetID::ReadSettings: + return "Read Settings"; case NetID::HSCAN4: return "HSCAN 4"; case NetID::HSCAN5: @@ -485,7 +485,7 @@ CONSTEXPR uint16_t ICSNEO_NETID_APP_SIGNAL_STATUS = 56; CONSTEXPR uint16_t ICSNEO_NETID_READ_DATALINK_CM_TX_MSG = 57; CONSTEXPR uint16_t ICSNEO_NETID_READ_DATALINK_CM_RX_MSG = 58; CONSTEXPR uint16_t ICSNEO_NETID_LOGGING_OVERFLOW = 59; -CONSTEXPR uint16_t ICSNEO_NETID_READ_SETTINGS_EX = 60; +CONSTEXPR uint16_t ICSNEO_NETID_READ_SETTINGS = 60; CONSTEXPR uint16_t ICSNEO_NETID_HSCAN4 = 61; CONSTEXPR uint16_t ICSNEO_NETID_HSCAN5 = 62; CONSTEXPR uint16_t ICSNEO_NETID_RS232 = 63;