Fixed wait check in device online/offline

checksum-failure-logging
EricLiu2000 2019-08-07 10:05:09 -04:00
parent 5112e1d2f9
commit 9629864f1b
6 changed files with 46 additions and 30 deletions

View File

@ -15,27 +15,6 @@ void EventManager::ResetInstance() {
singleton = std::unique_ptr<EventManager>(new EventManager());
}
// If this thread is not in the map, add it to be ignored
// If it is, set it to be ignored
void EventManager::downgradeErrorsOnCurrentThread() {
std::lock_guard<std::mutex> lk(downgradedThreadsMutex);
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end()) {
i->second = true;
} else {
downgradedThreads.insert({std::this_thread::get_id(), true});
}
}
// If this thread exists in the map, turn off downgrading
void EventManager::cancelErrorDowngradingOnCurrentThread() {
std::lock_guard<std::mutex> lk(downgradedThreadsMutex);
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end()) {
i->second = false;
}
}
int EventManager::addEventCallback(const EventCallback &cb) {
std::lock_guard<std::mutex> lk(callbacksMutex);
callbacks.insert({callbackID, cb});

View File

@ -131,7 +131,8 @@ std::shared_ptr<Message> Communication::waitForMessageSync(std::shared_ptr<Messa
// We have now added the callback, wait for it to return from the other thread
std::unique_lock<std::mutex> lk(m);
cv.wait_for(lk, timeout, [&returnedMessage]{ return !!returnedMessage; }); // `!!shared_ptr` checks if the ptr has a value
cv.wait_for(lk, timeout, [&returnedMessage] { return !!returnedMessage; }); // `!!shared_ptr` checks if the ptr has a value
lk.unlock();
// We don't actually check that we got a message, because either way we want to remove the callback (since it should only happen once)
removeMessageCallback(cb);

View File

@ -222,15 +222,24 @@ bool Device::goOnline() {
ledState = LEDState::Online;
online = true;
updateLEDState();
MessageFilter filter(Network::NetID::Reset_Status);
filter.includeInternalInAny = true;
// wait until communication is enabled or 10 seconds, whichever comes first
while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds::duration(10)) {
while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds::duration(5)) {
if(latestResetStatus && latestResetStatus->comEnabled)
break;
}
if(!com->sendCommand(Command::RequestStatusUpdate))
return false;
com->waitForMessageSync(filter, std::chrono::milliseconds(100));
}
online = true;
return true;
}
@ -243,13 +252,22 @@ bool Device::goOffline() {
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
updateLEDState();
online = false;
MessageFilter filter(Network::NetID::Reset_Status);
filter.includeInternalInAny = true;
// wait until communication is disabled or 10 seconds, whichever comes first
while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds::duration(10)) {
while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds::duration(5)) {
if(latestResetStatus && !latestResetStatus->comEnabled)
break;
if(!com->sendCommand(Command::RequestStatusUpdate))
return false;
com->waitForMessageSync(filter, std::chrono::milliseconds(100));
}
online = false;
return true;
}

View File

@ -21,9 +21,26 @@ public:
static void ResetInstance();
void downgradeErrorsOnCurrentThread();
// If this thread is not in the map, add it to be ignored
// If it is, set it to be ignored
void downgradeErrorsOnCurrentThread() {
std::lock_guard<std::mutex> lk(downgradedThreadsMutex);
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end()) {
i->second = true;
} else {
downgradedThreads.insert({std::this_thread::get_id(), true});
}
}
void cancelErrorDowngradingOnCurrentThread();
// If this thread exists in the map, turn off downgrading
void cancelErrorDowngradingOnCurrentThread() {
std::lock_guard<std::mutex> lk(downgradedThreadsMutex);
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end()) {
i->second = false;
}
}
int addEventCallback(const EventCallback &cb);

View File

@ -10,6 +10,7 @@ enum class Command : uint8_t {
//GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused
SaveSettings = 0xA6,
SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM
RequestStatusUpdate = 0xBC,
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
UpdateLEDState = 0xA7
};

View File

@ -378,7 +378,7 @@ void VCP::readTask() {
} else
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
}
if(ret == WAIT_ABANDONED) {
if(ret == WAIT_ABANDONED || ret == WAIT_FAILED) {
state = LAUNCH;
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
}