diff --git a/mavone/CMakeLists.txt b/mavone/CMakeLists.txt index 1331779..dda87ec 100644 --- a/mavone/CMakeLists.txt +++ b/mavone/CMakeLists.txt @@ -11,6 +11,7 @@ link_directories(/usr/lib/x86_64-linux-gnu) # for mysqlcppconn add_executable(mavone mavone.cpp + globals.cpp ) find_package(MAVSDK REQUIRED) diff --git a/mavone/config.txt b/mavone/config.txt index c2daddb..3f77e96 100644 --- a/mavone/config.txt +++ b/mavone/config.txt @@ -1,10 +1,10 @@ -C=3.14 -connectPort=udp://:14550 +MAVSDKListeningPort=udp://:14550 mysqlHost=140.120.108.238 mysqlPort=1880 mysqlUser=root mysqlPW=wp21qpck57 mysqlDatabase=Mav_one +C=3.14 EOC EOC 就是結尾了 所以這邊可以打註解 \ No newline at end of file diff --git a/mavone/globals.cpp b/mavone/globals.cpp new file mode 100644 index 0000000..e5f04dc --- /dev/null +++ b/mavone/globals.cpp @@ -0,0 +1,6 @@ + +#include "globals.h" + +extern std::map> gTelemetryInfo; +extern std::map> gVehicleCommand; +extern std::mutex gTeleMtx; \ No newline at end of file diff --git a/mavone/globals.h b/mavone/globals.h new file mode 100644 index 0000000..23a56f8 --- /dev/null +++ b/mavone/globals.h @@ -0,0 +1,13 @@ +// globals.h +#ifndef GLOBALS_H +#define GLOBALS_H + +#include +#include +#include + +extern std::map> gTelemetryInfo; +extern std::map> gVehicleCommand; +extern std::mutex gTeleMtx; + +#endif \ No newline at end of file diff --git a/mavone/mavone.cpp b/mavone/mavone.cpp index 6b5d03c..d57bae8 100644 --- a/mavone/mavone.cpp +++ b/mavone/mavone.cpp @@ -1,73 +1,11 @@ -// -// Simple example to demonstrate how takeoff and land using MAVSDK. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace mavsdk; -using std::chrono::seconds; -using std::chrono::milliseconds; -using std::this_thread::sleep_for; - -struct MavInitParameter { - std::string connectPort; - std::string connectPort2; - - float C; - std::string mysqlHost; - std::string mysqlPort; - std::string mysqlUser; - std::string mysqlPW; - std::string mysqlDatabase; -}; - -enum class systemHandlerState { - Init, // 剛剛交給 systemHandler 去處理 - Prologue, // 建立了 mysql row 並取得 serialNo - Ready, // 收到第一筆並放到 telemetryInfo 後 - Disconnected // mavsdk 判斷該系統斷線了 -}; - -struct systemHandlerInfo { - int systemID; - std::thread systemThread; - systemHandlerState handlerState; - int mysqlSN; - -}; - - +#include "mavone.h" // 我無法解決跨執行緒的 promise 變數生命週期問題 // 用最智障的全域變數 (砍掉 promise 結構簡單好多) -std::map> gTelemetryInfo; -std::map> gVehicleCommand; -std::mutex gTeleMtx; +#include "globals.h" -bool reset; - int initializeParameters(const std::string& filePath, MavInitParameter& initSetting) { std::ifstream configFile(filePath); @@ -399,7 +337,7 @@ int main(int argc, char** argv) stmt->execute(sqlString); case systemHandlerState::Ready : - std::cout << "SystemHandler:" << std::to_string(handlerInfo.systemID) << " at Ready " << std::endl; //debug + // std::cout << "SystemHandler:" << std::to_string(handlerInfo.systemID) << " at Ready " << std::endl; //debug // 確認系統是否仍連線 if(gVehicleCommand[handlerInfo.systemID]["is_connected"] == 0){ @@ -436,7 +374,7 @@ int main(int argc, char** argv) std::cout << "SystemHandler:" << std::to_string(handlerInfo.systemID) << " at Disconnected " << std::endl; //debug - // reset = true; //debug + reset = true; //debug break; } diff --git a/mavone/mavone.h b/mavone/mavone.h new file mode 100644 index 0000000..d279d5b --- /dev/null +++ b/mavone/mavone.h @@ -0,0 +1,62 @@ +#ifndef MAVONE_H +#define MAVONE_H + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +using namespace mavsdk; +using std::chrono::seconds; +using std::chrono::milliseconds; +using std::this_thread::sleep_for; + +struct MavInitParameter { + std::string connectPort; + std::string connectPort2; + + float C; + std::string mysqlHost; + std::string mysqlPort; + std::string mysqlUser; + std::string mysqlPW; + std::string mysqlDatabase; +}; + +enum class systemHandlerState { + Init, // 剛剛交給 systemHandler 去處理 + Prologue, // 建立了 mysql row 並取得 serialNo + Ready, // 收到第一筆並放到 telemetryInfo 後 + Disconnected // mavsdk 判斷該系統斷線了 +}; + +struct systemHandlerInfo { + int systemID; + std::thread systemThread; + systemHandlerState handlerState; + int mysqlSN; + +}; + +bool reset; + +#endif