Device: Add GetComponentVersions and GetSupportedFeatures commands

Driver: Fix re-open and failed open cases for TCP

Also enforces even length packets for the RED2, FIRE3, and FIRE3 FlexRay devices.
This commit is contained in:
Jonathan Schwartz
2023-05-08 21:07:43 +00:00
parent b6d9ef4c7e
commit 32900ae263
22 changed files with 303 additions and 23 deletions
+29 -1
View File
@@ -217,6 +217,13 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
if(block) // Extensions say no
return false;
// Get component versions *after* the extension "onDeviceOpen" hooks (e.g. device reflashes)
if (auto compVersions = com->getComponentVersionsSync())
componentVersions = std::move(*compVersions);
else
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::EventWarning);
if(!settings->disabled) {
// Since we will not fail the open if a settings read fails,
// downgrade any errors to warnings. Otherwise the error will
@@ -303,6 +310,10 @@ APIEvent::Type Device::attemptToBeginCommunication() {
return getCommunicationNotEstablishedError();
}
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
return getCommunicationNotEstablishedError();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
auto serial = com->getSerialNumberSync();
int i = 0;
while(!serial) {
@@ -1751,4 +1762,21 @@ bool Device::setRTC(const std::chrono::time_point<std::chrono::system_clock>& ti
com->sendCommand(Command::SetRTC, bytestream);
return true;
}
}
std::optional<std::set<SupportedFeature>> Device::getSupportedFeatures() {
auto timeout = std::chrono::milliseconds(100);
std::shared_ptr<Message> msg = com->waitForMessageSync(
[this](){ return com->sendCommand(ExtendedCommand::GetSupportedFeatures, {}); },
std::make_shared<MessageFilter>(Message::Type::SupportedFeatures), timeout);
if(!msg) {
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
return std::nullopt;
}
const auto& typedResponse = std::dynamic_pointer_cast<SupportedFeaturesMessage>(msg);
if(!typedResponse) {
report(APIEvent::Type::UnexpectedResponse, APIEvent::Severity::Error);
return std::nullopt;
}
return std::move(typedResponse->features);
}