for andy debug
This commit is contained in:
@@ -11,6 +11,7 @@ link_directories(/usr/lib/x86_64-linux-gnu) # for mysqlcppconn
|
|||||||
|
|
||||||
add_executable(mavone
|
add_executable(mavone
|
||||||
mavone.cpp
|
mavone.cpp
|
||||||
|
globals.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(MAVSDK REQUIRED)
|
find_package(MAVSDK REQUIRED)
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
C=3.14
|
MAVSDKListeningPort=udp://:14550
|
||||||
connectPort=udp://:14550
|
|
||||||
mysqlHost=140.120.108.238
|
mysqlHost=140.120.108.238
|
||||||
mysqlPort=1880
|
mysqlPort=1880
|
||||||
mysqlUser=root
|
mysqlUser=root
|
||||||
mysqlPW=wp21qpck57
|
mysqlPW=wp21qpck57
|
||||||
mysqlDatabase=Mav_one
|
mysqlDatabase=Mav_one
|
||||||
|
C=3.14
|
||||||
EOC
|
EOC
|
||||||
|
|
||||||
EOC 就是結尾了 所以這邊可以打註解
|
EOC 就是結尾了 所以這邊可以打註解
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
extern std::map<int, std::map<std::string, std::string>> gTelemetryInfo;
|
||||||
|
extern std::map<int, std::map<std::string, double>> gVehicleCommand;
|
||||||
|
extern std::mutex gTeleMtx;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// globals.h
|
||||||
|
#ifndef GLOBALS_H
|
||||||
|
#define GLOBALS_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
extern std::map<int, std::map<std::string, std::string>> gTelemetryInfo;
|
||||||
|
extern std::map<int, std::map<std::string, double>> gVehicleCommand;
|
||||||
|
extern std::mutex gTeleMtx;
|
||||||
|
|
||||||
|
#endif
|
||||||
+4
-66
@@ -1,73 +1,11 @@
|
|||||||
//
|
|
||||||
// Simple example to demonstrate how takeoff and land using MAVSDK.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <mavsdk/mavsdk.h>
|
|
||||||
#include <mavsdk/plugins/action/action.h>
|
|
||||||
#include <mavsdk/plugins/telemetry/telemetry.h>
|
|
||||||
#include <mavsdk/plugins/mavlink_passthrough/mavlink_passthrough.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <future>
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
#include <vector>
|
|
||||||
#include <mutex>
|
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <mysql_driver.h>
|
|
||||||
#include <mysql_connection.h>
|
|
||||||
#include <cppconn/resultset.h>
|
|
||||||
#include <cppconn/statement.h>
|
|
||||||
|
|
||||||
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 變數生命週期問題
|
||||||
// 用最智障的全域變數 (砍掉 promise 結構簡單好多)
|
// 用最智障的全域變數 (砍掉 promise 結構簡單好多)
|
||||||
std::map<int,std::map<std::string,std::string>> gTelemetryInfo;
|
#include "globals.h"
|
||||||
std::map<int,std::map<std::string,double>> gVehicleCommand;
|
|
||||||
std::mutex gTeleMtx;
|
|
||||||
|
|
||||||
|
|
||||||
bool reset;
|
|
||||||
|
|
||||||
|
|
||||||
int initializeParameters(const std::string& filePath, MavInitParameter& initSetting) {
|
int initializeParameters(const std::string& filePath, MavInitParameter& initSetting) {
|
||||||
std::ifstream configFile(filePath);
|
std::ifstream configFile(filePath);
|
||||||
@@ -399,7 +337,7 @@ int main(int argc, char** argv)
|
|||||||
stmt->execute(sqlString);
|
stmt->execute(sqlString);
|
||||||
|
|
||||||
case systemHandlerState::Ready :
|
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){
|
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
|
std::cout << "SystemHandler:" << std::to_string(handlerInfo.systemID) << " at Disconnected " << std::endl; //debug
|
||||||
|
|
||||||
|
|
||||||
// reset = true; //debug
|
reset = true; //debug
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#ifndef MAVONE_H
|
||||||
|
#define MAVONE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <mavsdk/mavsdk.h>
|
||||||
|
#include <mavsdk/plugins/action/action.h>
|
||||||
|
#include <mavsdk/plugins/telemetry/telemetry.h>
|
||||||
|
#include <mavsdk/plugins/mavlink_passthrough/mavlink_passthrough.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <future>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
#include <vector>
|
||||||
|
#include <mutex>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <mysql_driver.h>
|
||||||
|
#include <mysql_connection.h>
|
||||||
|
#include <cppconn/resultset.h>
|
||||||
|
#include <cppconn/statement.h>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user