mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Fix a bug where settings were not read properly
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user