1
0
Fork 0

remove promises/futures for now

This commit is contained in:
Kevin Matz 2023-04-14 10:07:58 -04:00
parent 0bb177c68e
commit a58ffc5c4a
2 changed files with 5 additions and 51 deletions

View File

@ -296,18 +296,11 @@ bool Widget::writeFirmware(const uint8_t *data, const size_t size)
rebootBootloader();
auto msg = std::make_shared<Pro::MsgProgramFlashPageRequest>();
std::future<bool> ftr;
bool success;
bool success = false;
for (uint i = 0; i < size / sizeof(msg->page);)
{
{
std::scoped_lock lock(mtx_metadata_);
reply_firmwarePage_ = std::promise<bool>(); // expect a reply to this message
ftr = reply_firmwarePage_.get_future();
}
std::copy(data + (i*sizeof(msg->page)), data + ((i+1)*sizeof(msg->page)), msg->page);
sendMessage(msg);
success = ftr.get();
if (success)
i++; // page write was successful, do the next.
}
@ -527,29 +520,11 @@ void Widget::rebootBootloader()
/**
* @brief Widget::getSerialNumber
* @param timeout Milliseconds to block while waiting for the device to reply.
* @return True if the serial number has been updated.
*/
bool Widget::getSerialNumber(int timeout)
void Widget::getSerialNumber()
{
auto msg = std::make_shared<Pro::MsgGetWidgetSerialRequest>();
std::future<bool> ftr;
{
std::scoped_lock lock(mtx_metadata_);
reply_serialNumber_ = std::promise<bool>(); // expect a reply to this message
ftr = reply_serialNumber_.get_future();
}
sendMessage(msg);
switch (ftr.wait_for(std::chrono::milliseconds(timeout))) {
case std::future_status::ready:
return true;
case std::future_status::timeout:
return false;
default:
return false;
}
}
@ -562,24 +537,8 @@ bool Widget::getSerialNumber(int timeout)
bool Widget::getParameters(size_t user_length, int timeout)
{
auto msg = std::make_shared<Pro::MsgGetWidgetParametersRequest>();
std::future<bool> ftr;
{
std::scoped_lock lock(mtx_metadata_);
reply_parameters_ = std::promise<bool>(); // expect a reply to this message
ftr = reply_parameters_.get_future();
}
msg->size = std::min(user_length, Pro::USER_CONFIGURATION_MAX);
sendMessage(msg);
switch (ftr.wait_for(std::chrono::milliseconds(timeout))) {
case std::future_status::ready:
return true;
case std::future_status::timeout:
return false;
default:
return false;
}
}
@ -625,10 +584,8 @@ void Widget::rxMsgHello()
sendMessage(std::make_shared<Pro::MsgNoop>()); // mirror the message back to the host
break;
case USBhost:
reply_hello_.set_value(true); // device was polite
break;
default:
reply_hello_.set_value(false); // anonyomous hello?
break;
}
}
@ -661,7 +618,7 @@ void Widget::rxMsgProgramFlashPageRequest(std::shared_ptr<Pro::MsgProgramFlashPa
*/
void Widget::rxMsgProgramFlashPageReply(std::shared_ptr<Pro::MsgProgramFlashPageReply> msg)
{
reply_firmwarePage_.set_value(msg->success);
(void)msg;
}

View File

@ -85,6 +85,8 @@ public:
const std::vector<uint8_t> &userData() const;
void setUserData(std::vector<uint8_t>);
void getSerialNumber();
bool writeFirmware(const uint8_t *, const size_t);
/// @brief The OperatingMode enum
@ -104,7 +106,6 @@ protected:
virtual void rebootBootloader();
bool getParameters(size_t user_length = 0, int timeout = 0);
void setParameters() const;
bool getSerialNumber(int timeout = 0);
void sendDmx(bool trimmed = true) const;
/**
@ -144,10 +145,6 @@ private:
mutable std::mutex mtx_metadata_;
std::shared_ptr<void> token_data_changed_;
std::promise<bool> reply_hello_;
std::promise<bool> reply_firmwarePage_;
std::promise<bool> reply_parameters_;
std::promise<bool> reply_serialNumber_;
};
} // namespace ENTTEC