Wait on the correct netid for the correct time for serial numbers
Serial number decoding not implemented yetpull/4/head
parent
da4d9e46be
commit
6284223650
|
|
@ -85,7 +85,7 @@ bool Communication::getSettingsSync(std::vector<uint8_t>& data, std::chrono::mil
|
||||||
|
|
||||||
bool Communication::getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout) {
|
bool Communication::getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout) {
|
||||||
sendCommand(Command::RequestSerialNumber);
|
sendCommand(Command::RequestSerialNumber);
|
||||||
std::shared_ptr<Message> msg = waitForMessageSync(MessageFilter(Network::NetID::Main51), timeout);
|
std::shared_ptr<Message> msg = waitForMessageSync(MessageFilter(Network::NetID::RED_OLDFORMAT), timeout);
|
||||||
if(!msg)
|
if(!msg)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -95,6 +95,7 @@ bool Communication::getSerialNumberSync(std::string& serial, std::chrono::millis
|
||||||
if(i % 16 == 15)
|
if(i % 16 == 15)
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Communication::addMessageCallback(const MessageCallback& cb) {
|
int Communication::addMessageCallback(const MessageCallback& cb) {
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,12 @@ public:
|
||||||
};
|
};
|
||||||
virtual bool sendCommand(Command cmd, bool boolean) { return sendCommand(cmd, std::vector<uint8_t>({ (uint8_t)boolean })); }
|
virtual bool sendCommand(Command cmd, bool boolean) { return sendCommand(cmd, std::vector<uint8_t>({ (uint8_t)boolean })); }
|
||||||
virtual bool sendCommand(Command cmd, std::vector<uint8_t> arguments = {});
|
virtual bool sendCommand(Command cmd, std::vector<uint8_t> arguments = {});
|
||||||
bool getSettingsSync(std::vector<uint8_t>& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(10));
|
bool getSettingsSync(std::vector<uint8_t>& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||||
bool getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout = std::chrono::milliseconds(10));
|
bool getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||||
|
|
||||||
int addMessageCallback(const MessageCallback& cb);
|
int addMessageCallback(const MessageCallback& cb);
|
||||||
bool removeMessageCallback(int id);
|
bool removeMessageCallback(int id);
|
||||||
std::shared_ptr<Message> waitForMessageSync(MessageFilter f = MessageFilter(), std::chrono::milliseconds timeout = std::chrono::milliseconds(10));
|
std::shared_ptr<Message> waitForMessageSync(MessageFilter f = MessageFilter(), std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||||
|
|
||||||
void setAlign16Bit(bool enable) { align16bit = enable; }
|
void setAlign16Bit(bool enable) { align16bit = enable; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,9 @@ bool Device::open() {
|
||||||
if(!com)
|
if(!com)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if(settings)
|
||||||
|
settings->refresh();
|
||||||
|
|
||||||
return com->open();
|
return com->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,12 +132,14 @@ bool Device::close() {
|
||||||
if(!com)
|
if(!com)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
settings = nullptr;
|
||||||
|
|
||||||
return com->close();
|
return com->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::goOnline() {
|
bool Device::goOnline() {
|
||||||
std::string serial;
|
std::string serial;
|
||||||
while(!com->getSerialNumberSync(serial, std::chrono::milliseconds(500))) {
|
while(!com->getSerialNumberSync(serial)) {
|
||||||
std::cout << "Serial number not here yet" << std::endl;
|
std::cout << "Serial number not here yet" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,11 @@ class IDeviceSettings {
|
||||||
public:
|
public:
|
||||||
static uint16_t CalculateGSChecksum(const std::vector<uint8_t>& settings);
|
static uint16_t CalculateGSChecksum(const std::vector<uint8_t>& settings);
|
||||||
|
|
||||||
IDeviceSettings(std::shared_ptr<Communication> com) : com(com) {
|
IDeviceSettings(std::shared_ptr<Communication> com) : com(com) {}
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
virtual void refresh();
|
virtual void refresh();
|
||||||
virtual void commit() = 0;
|
//virtual void commit() = 0;
|
||||||
virtual void* getStructure() { return settings.data(); }
|
virtual void* getStructure() { return settings.data(); }
|
||||||
virtual bool setBaudrate(int baud) = 0;
|
//virtual bool setBaudrate(int baud) = 0;
|
||||||
protected:
|
protected:
|
||||||
bool settingsLoaded = false;
|
bool settingsLoaded = false;
|
||||||
std::vector<uint8_t> settings;
|
std::vector<uint8_t> settings;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue