Fix a bug where settings were not read properly
parent
3e51e39f3e
commit
ccd26a3637
|
|
@ -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<uint8_t> arguments) {
|
|||
}
|
||||
|
||||
bool Communication::getSettingsSync(std::vector<uint8_t>& data, std::chrono::milliseconds timeout) {
|
||||
sendCommand(Command::GetSettings);
|
||||
std::shared_ptr<Message> 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<Message> msg = waitForMessageSync(MessageFilter(Network::NetID::ReadSettings), timeout);
|
||||
if(!msg)
|
||||
return false;
|
||||
|
||||
std::shared_ptr<ReadSettingsMessage> gsmsg = std::dynamic_pointer_cast<ReadSettingsMessage>(msg);
|
||||
if(!gsmsg)
|
||||
return false;
|
||||
|
||||
if(gsmsg->response != ReadSettingsMessage::Response::OK)
|
||||
return false;
|
||||
|
||||
data = std::move(msg->data);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -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 <iostream>
|
||||
|
|
@ -171,6 +172,26 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
|||
packet->data.resize(length);
|
||||
return decode(result, packet);
|
||||
}
|
||||
case Network::NetID::ReadSettings: {
|
||||
auto msg = std::make_shared<ReadSettingsMessage>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue