mirror of
https://github.com/intrepidcs/icsscand.git
synced 2026-09-20 08:08:27 +02:00
Rework reconnection logic
This commit is contained in:
committed by
Jonathan Schwartz
parent
4801a60598
commit
4a38ebda34
+20
-10
@@ -579,8 +579,8 @@ void terminateSignal(int signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void searchForDevices() {
|
void searchForDevices() {
|
||||||
auto found = icsneo::FindAllDevices();
|
|
||||||
std::lock_guard<std::mutex> lg(openDevicesMutex);
|
std::lock_guard<std::mutex> lg(openDevicesMutex);
|
||||||
|
auto found = icsneo::FindAllDevices();
|
||||||
|
|
||||||
// Open devices we have not seen before
|
// Open devices we have not seen before
|
||||||
for(auto& dev : found) {
|
for(auto& dev : found) {
|
||||||
@@ -934,25 +934,35 @@ int main(int argc, char** argv) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sent = false;
|
const auto transmit = [&] {
|
||||||
std::lock_guard<std::mutex> lg(openDevicesMutex);
|
std::lock_guard<std::mutex> lg(openDevicesMutex);
|
||||||
for(auto& dev : openDevices) {
|
for(auto it = openDevices.begin(); it != openDevices.end(); ++it) {
|
||||||
|
auto& dev = *it;
|
||||||
for(auto& netifPair : dev.interfaces) {
|
for(auto& netifPair : dev.interfaces) {
|
||||||
if(netifPair.second->getKernelHandle() != msg->netid)
|
if(netifPair.second->getKernelHandle() != msg->netid)
|
||||||
continue;
|
continue;
|
||||||
|
if(!dev.device->isOpen() || !dev.device->isOnline() || dev.device->isDisconnected()) {
|
||||||
|
LOGF(LOG_ERR, "Message dropped, %s is not open and online\n", dev.device->getSerial().c_str());
|
||||||
|
openDevices.erase(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
msg->netid = static_cast<uint16_t>(netifPair.first);
|
msg->netid = static_cast<uint16_t>(netifPair.first);
|
||||||
auto txMsg = icsneo::CreateMessageFromNeoMessage(reinterpret_cast<neomessage_t*>(msg));
|
auto txMsg = icsneo::CreateMessageFromNeoMessage(reinterpret_cast<neomessage_t*>(msg));
|
||||||
auto tx = std::dynamic_pointer_cast<icsneo::Frame>(txMsg);
|
auto tx = std::dynamic_pointer_cast<icsneo::Frame>(txMsg);
|
||||||
if(!tx || !dev.device->transmit(tx))
|
if(!tx) {
|
||||||
break;
|
LOG(LOG_ERR, "Message dropped, invalid transmit message\n");
|
||||||
sent = true;
|
return;
|
||||||
break;
|
}
|
||||||
|
if(!dev.device->transmit(tx)) {
|
||||||
|
LOGF(LOG_ERR, "Message dropped, unable to transmit: %s\n", icsneo::GetLastError().describe().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(sent)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if(!sent)
|
|
||||||
LOG(LOG_ERR, "Message dropped, could not find the device the kernel referenced\n");
|
LOG(LOG_ERR, "Message dropped, could not find the device the kernel referenced\n");
|
||||||
|
};
|
||||||
|
transmit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
Submodule third-party/libicsneo updated: bb711ae7e2...3aaacb6cc8
Reference in New Issue
Block a user