stable v0.4

- 修正 disconnected 後不斷重刷的問題
- 修正 相同 sysid 再連接會產生抓錯的問題
- 增加 非 autopilot 裝置被 subscribe telemetry 問題
master
chiyu1468 2 years ago
parent feb441d2f4
commit 98e399cbd5

@ -22,7 +22,11 @@ gVehicleCommand
gHandlerMask gHandlerMask
gHandlerMask[sysid]["is_connected"]
Loop
gHandlerMask[sysid]["cutoff"]
*/ */

@ -81,7 +81,6 @@ int main(int argc, char** argv)
// For store Discover systems in a list // For store Discover systems in a list
std::vector<systemHandlerInfo> systemHandlerInfos; std::vector<systemHandlerInfo> systemHandlerInfos;
// Subscribe to new system discovery // Subscribe to new system discovery
mavsdk.subscribe_on_new_system([&mavsdk, &systemHandlerInfos]() { mavsdk.subscribe_on_new_system([&mavsdk, &systemHandlerInfos]() {
// Get the last subscribed system // Get the last subscribed system
@ -91,19 +90,21 @@ int main(int argc, char** argv)
// Avoid Duplicate System ID // Avoid Duplicate System ID
bool duplicated; bool duplicated;
for(int i=0; i<comingSystems.size(); i++){ // for(int i=0; i<comingSystems.size(); i++){
for(int i=comingSystems.size()-1; i>=0; i--){
sys = comingSystems[i]; sys = comingSystems[i];
if (!sys->is_connected()) {continue;}
sysid = static_cast<int>(sys->get_system_id()); sysid = static_cast<int>(sys->get_system_id());
duplicated = false; duplicated = false;
for(int j=0; j<systemHandlerInfos.size(); j++){ for(int j=0; j<systemHandlerInfos.size(); j++){
if(sysid == systemHandlerInfos[j].systemID){ if(sysid == systemHandlerInfos[j].systemID){
duplicated = true; duplicated = true;
break; break; // this will break the j for loop
} }
} }
if(duplicated == false){ if(duplicated == false){
// Get New System // Get New System
System& new_system = *sys; // make std::shared_ptr<MAVSDK::System> back to MAVSDK::System System& new_system = *sys; // make std::shared_ptr<MAVSDK::System> back to MAVSDK::System
std::cout << "(mavone.cpp:subscribe_on_new_system) system detect sysid : " << sysid << "(Debug)"<< std::endl; // debug std::cout << "(mavone.cpp:subscribe_on_new_system) system detect sysid : " << sysid << "(Debug)"<< std::endl; // debug
@ -120,12 +121,10 @@ int main(int argc, char** argv)
}); });
// only get ONE system each time // only get ONE system each time
break; break; // this will break the i for loop
} }
} }
// Need some extra time fpr complete init
// sleep_for(milliseconds(500));
}); });
// MySQL connection is here // MySQL connection is here
@ -261,12 +260,17 @@ int main(int argc, char** argv)
} }
// 刪除 Disconnected 的 handlerInfo
for (auto it = systemHandlerInfos.begin(); it != systemHandlerInfos.end(); /* no increment here */) {
// 刪除被輪尋到的 handlerInfo if (it->handlerState == systemHandlerState::Disconnected) {
// systemHandlerInfos.erase(std::remove_if(systemHandlerInfos.begin(), systemHandlerInfos.end(), [&](const auto& info) { if (it->systemThread.joinable()) {
// return info.handlerState == systemHandlerState::Disconnected; it->systemThread.join();
// }), systemHandlerInfos.end()); }
it = systemHandlerInfos.erase(it);
} else {
++it;
}
}
} }
@ -285,9 +289,6 @@ int main(int argc, char** argv)
handlerInfo.systemThread.join(); handlerInfo.systemThread.join();
} }
// delete mavsdk;
// ~mavsdk;
return 0; return 0;
} }

@ -46,7 +46,8 @@ enum class systemHandlerState {
Init, // 剛剛交給 systemHandler 去處理 Init, // 剛剛交給 systemHandler 去處理
Prologue, // 建立了 mysql row 並取得 serialNo Prologue, // 建立了 mysql row 並取得 serialNo
Ready, // 收到第一筆並放到 telemetryInfo 後 Ready, // 收到第一筆並放到 telemetryInfo 後
Disconnected // mavsdk 判斷該系統斷線了 Disconnected, // mavsdk 判斷該系統斷線了
// Void
}; };
struct systemHandlerInfo { struct systemHandlerInfo {

@ -48,7 +48,10 @@ void systemHandler(System& system) {
// //
int _counter; int _counter;
// std::cout << "Has AutoPilot : " << system.has_autopilot() << std::endl; // debug
// Put all the subscriber init in this section // Put all the subscriber init in this section
if (system.has_autopilot()) {
telemetry.subscribe_position([&system, &telemetryInfo](Telemetry::Position position) { telemetry.subscribe_position([&system, &telemetryInfo](Telemetry::Position position) {
// 轉換數字到字串用的暫存變數 // 轉換數字到字串用的暫存變數
std::ostringstream num_str_ss; std::ostringstream num_str_ss;
@ -131,14 +134,14 @@ void systemHandler(System& system) {
telemetryInfo["drone_arm"] = "0"; telemetryInfo["drone_arm"] = "0";
} }
}); });
}
// Wait Until telemetryInfo get something. and if nothing get from System for 10 sec will cut off this connection. // Wait Until telemetryInfo get something. and if nothing get from System for 10 sec will cut off this connection.
_counter = 0; _counter = 0;
while(telemetryInfo.empty()){ while(telemetryInfo.empty()){
sleep_for(seconds(1)); sleep_for(seconds(1));
if(_counter++ > 10) { if(_counter++ > 10) {
reset = true; reset = true;
std::cout << "mark B " << sysid << " retry : " << _counter << std::endl; std::cout << "(systemHandler.cpp:systemHandler) System " << sysid << " waiting too long without any coming info." << std::endl;
break; break;
} }
} }
@ -161,9 +164,11 @@ void systemHandler(System& system) {
} }
// Destroy
gHandlerMask[sysid]["is_connected"] = 0;
// Thread Terminate // Thread Terminate
std::cout << "(systemHandler.cpp:systemHandler) Thread Out " << sysid << std::endl; //debug std::cout << "(systemHandler.cpp:systemHandler) Thread Out " << sysid << std::endl; //debug
// Destroy
gHandlerMask[sysid]["is_connected"] = 0;
} }

Loading…
Cancel
Save