From 6284223650b31d089b56a743dcffb8872184b484 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 24 Sep 2018 18:54:45 -0400 Subject: [PATCH] Wait on the correct netid for the correct time for serial numbers Serial number decoding not implemented yet --- communication/communication.cpp | 3 ++- communication/include/communication.h | 6 +++--- device/device.cpp | 7 ++++++- device/include/idevicesettings.h | 8 +++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/communication/communication.cpp b/communication/communication.cpp index 1a6396e..36618ed 100644 --- a/communication/communication.cpp +++ b/communication/communication.cpp @@ -85,7 +85,7 @@ bool Communication::getSettingsSync(std::vector& data, std::chrono::mil bool Communication::getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout) { sendCommand(Command::RequestSerialNumber); - std::shared_ptr msg = waitForMessageSync(MessageFilter(Network::NetID::Main51), timeout); + std::shared_ptr msg = waitForMessageSync(MessageFilter(Network::NetID::RED_OLDFORMAT), timeout); if(!msg) return false; @@ -95,6 +95,7 @@ bool Communication::getSerialNumberSync(std::string& serial, std::chrono::millis if(i % 16 == 15) std::cout << std::endl; } + return true; } int Communication::addMessageCallback(const MessageCallback& cb) { diff --git a/communication/include/communication.h b/communication/include/communication.h index fcf9336..7764bb4 100644 --- a/communication/include/communication.h +++ b/communication/include/communication.h @@ -37,12 +37,12 @@ public: }; virtual bool sendCommand(Command cmd, bool boolean) { return sendCommand(cmd, std::vector({ (uint8_t)boolean })); } virtual bool sendCommand(Command cmd, std::vector arguments = {}); - bool getSettingsSync(std::vector& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(10)); - bool getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout = std::chrono::milliseconds(10)); + bool getSettingsSync(std::vector& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); + bool getSerialNumberSync(std::string& serial, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); int addMessageCallback(const MessageCallback& cb); bool removeMessageCallback(int id); - std::shared_ptr waitForMessageSync(MessageFilter f = MessageFilter(), std::chrono::milliseconds timeout = std::chrono::milliseconds(10)); + std::shared_ptr waitForMessageSync(MessageFilter f = MessageFilter(), std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); void setAlign16Bit(bool enable) { align16bit = enable; } diff --git a/device/device.cpp b/device/device.cpp index 6788b10..64cb091 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -122,6 +122,9 @@ bool Device::open() { if(!com) return false; + if(settings) + settings->refresh(); + return com->open(); } @@ -129,12 +132,14 @@ bool Device::close() { if(!com) return false; + settings = nullptr; + return com->close(); } bool Device::goOnline() { std::string serial; - while(!com->getSerialNumberSync(serial, std::chrono::milliseconds(500))) { + while(!com->getSerialNumberSync(serial)) { std::cout << "Serial number not here yet" << std::endl; } diff --git a/device/include/idevicesettings.h b/device/include/idevicesettings.h index 0c64627..32186a3 100644 --- a/device/include/idevicesettings.h +++ b/device/include/idevicesettings.h @@ -13,13 +13,11 @@ class IDeviceSettings { public: static uint16_t CalculateGSChecksum(const std::vector& settings); - IDeviceSettings(std::shared_ptr com) : com(com) { - refresh(); - } + IDeviceSettings(std::shared_ptr com) : com(com) {} virtual void refresh(); - virtual void commit() = 0; + //virtual void commit() = 0; virtual void* getStructure() { return settings.data(); } - virtual bool setBaudrate(int baud) = 0; + //virtual bool setBaudrate(int baud) = 0; protected: bool settingsLoaded = false; std::vector settings;