Fixed wait check in device online/offline
parent
5112e1d2f9
commit
9629864f1b
|
|
@ -15,27 +15,6 @@ void EventManager::ResetInstance() {
|
||||||
singleton = std::unique_ptr<EventManager>(new EventManager());
|
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) {
|
int EventManager::addEventCallback(const EventCallback &cb) {
|
||||||
std::lock_guard<std::mutex> lk(callbacksMutex);
|
std::lock_guard<std::mutex> lk(callbacksMutex);
|
||||||
callbacks.insert({callbackID, cb});
|
callbacks.insert({callbackID, cb});
|
||||||
|
|
|
||||||
|
|
@ -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
|
// We have now added the callback, wait for it to return from the other thread
|
||||||
std::unique_lock<std::mutex> lk(m);
|
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)
|
// 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);
|
removeMessageCallback(cb);
|
||||||
|
|
|
||||||
|
|
@ -222,15 +222,24 @@ bool Device::goOnline() {
|
||||||
|
|
||||||
ledState = LEDState::Online;
|
ledState = LEDState::Online;
|
||||||
|
|
||||||
online = true;
|
|
||||||
updateLEDState();
|
updateLEDState();
|
||||||
|
|
||||||
|
MessageFilter filter(Network::NetID::Reset_Status);
|
||||||
|
filter.includeInternalInAny = true;
|
||||||
|
|
||||||
// wait until communication is enabled or 10 seconds, whichever comes first
|
// 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)
|
if(latestResetStatus && latestResetStatus->comEnabled)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
if(!com->sendCommand(Command::RequestStatusUpdate))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
com->waitForMessageSync(filter, std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
online = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,13 +252,22 @@ bool Device::goOffline() {
|
||||||
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
|
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
|
||||||
|
|
||||||
updateLEDState();
|
updateLEDState();
|
||||||
online = false;
|
|
||||||
|
MessageFilter filter(Network::NetID::Reset_Status);
|
||||||
|
filter.includeInternalInAny = true;
|
||||||
|
|
||||||
// wait until communication is disabled or 10 seconds, whichever comes first
|
// 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)
|
if(latestResetStatus && !latestResetStatus->comEnabled)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if(!com->sendCommand(Command::RequestStatusUpdate))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
com->waitForMessageSync(filter, std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
online = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,26 @@ public:
|
||||||
|
|
||||||
static void ResetInstance();
|
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);
|
int addEventCallback(const EventCallback &cb);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ enum class Command : uint8_t {
|
||||||
//GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused
|
//GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused
|
||||||
SaveSettings = 0xA6,
|
SaveSettings = 0xA6,
|
||||||
SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM
|
SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM
|
||||||
|
RequestStatusUpdate = 0xBC,
|
||||||
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
|
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
|
||||||
UpdateLEDState = 0xA7
|
UpdateLEDState = 0xA7
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ void VCP::readTask() {
|
||||||
} else
|
} else
|
||||||
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
||||||
}
|
}
|
||||||
if(ret == WAIT_ABANDONED) {
|
if(ret == WAIT_ABANDONED || ret == WAIT_FAILED) {
|
||||||
state = LAUNCH;
|
state = LAUNCH;
|
||||||
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue