diff --git a/src/constant_config.hpp b/src/constant_config.hpp deleted file mode 100644 index 5b9300e..0000000 --- a/src/constant_config.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by pengx on 2025/4/10. -// - -#ifndef CONSTANT_CONFIG_HPP -#define CONSTANT_CONFIG_HPP - -namespace ConstantConfig { - constexpr int TCP_REMOTE_PORT = 9001; - // constexpr int TCP_REMOTE_PORT = 30029; - - constexpr const char *SERVICE_ADDRESS = "192.168.123.18"; - // constexpr const char *SERVICE_ADDRESS = "111.198.10.15"; - constexpr int TCP_LOCALE_PORT = 8888; - - - constexpr const char *GAS_PORT = "/dev/ttyUSB0"; - constexpr int BAUD_RATE = 115200; - - constexpr const char *API_RECEIVE_DATA = "/device/receiveData"; - constexpr const char *API_UPLOAD_PCD_FILE = "/device/receiveFile"; - constexpr const char *HTTP_PORT = "30028"; - constexpr const char *DOG_CODE = "B42D4000OCAD3N82"; - - constexpr const char *SLAM_NET_PORT = "eth0"; - - constexpr const char *ROBOTIC_ARM_PORT = "/dev/ttyACM0"; - - constexpr const char *ROBOTIC_ARM_COMMAND_CONFIG = "/home/unitree/Desktop/robotic_arm_commands.conf"; - constexpr const char *SLAM_PCD_FILE = - "/unitree/module/graph_pid_ws/config_files/lio_sam_config/maps/pcd/default/GlobalMap.pcd"; -} - -#endif //CONSTANT_CONFIG_HPP diff --git a/src/constant_config.hpp b/src/constant_config.hpp deleted file mode 100644 index 5b9300e..0000000 --- a/src/constant_config.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by pengx on 2025/4/10. -// - -#ifndef CONSTANT_CONFIG_HPP -#define CONSTANT_CONFIG_HPP - -namespace ConstantConfig { - constexpr int TCP_REMOTE_PORT = 9001; - // constexpr int TCP_REMOTE_PORT = 30029; - - constexpr const char *SERVICE_ADDRESS = "192.168.123.18"; - // constexpr const char *SERVICE_ADDRESS = "111.198.10.15"; - constexpr int TCP_LOCALE_PORT = 8888; - - - constexpr const char *GAS_PORT = "/dev/ttyUSB0"; - constexpr int BAUD_RATE = 115200; - - constexpr const char *API_RECEIVE_DATA = "/device/receiveData"; - constexpr const char *API_UPLOAD_PCD_FILE = "/device/receiveFile"; - constexpr const char *HTTP_PORT = "30028"; - constexpr const char *DOG_CODE = "B42D4000OCAD3N82"; - - constexpr const char *SLAM_NET_PORT = "eth0"; - - constexpr const char *ROBOTIC_ARM_PORT = "/dev/ttyACM0"; - - constexpr const char *ROBOTIC_ARM_COMMAND_CONFIG = "/home/unitree/Desktop/robotic_arm_commands.conf"; - constexpr const char *SLAM_PCD_FILE = - "/unitree/module/graph_pid_ws/config_files/lio_sam_config/maps/pcd/default/GlobalMap.pcd"; -} - -#endif //CONSTANT_CONFIG_HPP diff --git a/src/message_handler.cpp b/src/message_handler.cpp index ec3d7d8..21c8099 100644 --- a/src/message_handler.cpp +++ b/src/message_handler.cpp @@ -5,13 +5,13 @@ #include "tcp_service.hpp" #include "tcp_client.hpp" #include "methane_serial_port.hpp" -#include "constant_config.hpp" +#include "config.hpp" int main() { //启动TCP服务端 std::thread service_thread([] { boost::asio::io_service io; - TcpService::getInstance().start(ConstantConfig::TCP_LOCALE_PORT); + TcpService::getInstance().start(Config::TCP_SERVICE_LOCALE_PORT); io.run(); }); @@ -19,7 +19,7 @@ std::thread client_thread([] { boost::asio::io_service io; TcpClient client; - client.connect(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::TCP_REMOTE_PORT); + client.connect(Config::REMOTE_SERVICE_IP, Config::TCP_SERVICE_REMOTE_PORT); io.run(); }); @@ -28,7 +28,7 @@ try { boost::asio::io_service io; //打开串口 - MethaneSerialPort sp(io, ConstantConfig::GAS_PORT, ConstantConfig::BAUD_RATE); //甲烷串口 + MethaneSerialPort sp(io, Config::GAS_PORT, Config::BAUD_RATE); //甲烷串口 sp.read_from_port(); io.run(); } catch (std::exception &e) { diff --git a/src/constant_config.hpp b/src/constant_config.hpp deleted file mode 100644 index 5b9300e..0000000 --- a/src/constant_config.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by pengx on 2025/4/10. -// - -#ifndef CONSTANT_CONFIG_HPP -#define CONSTANT_CONFIG_HPP - -namespace ConstantConfig { - constexpr int TCP_REMOTE_PORT = 9001; - // constexpr int TCP_REMOTE_PORT = 30029; - - constexpr const char *SERVICE_ADDRESS = "192.168.123.18"; - // constexpr const char *SERVICE_ADDRESS = "111.198.10.15"; - constexpr int TCP_LOCALE_PORT = 8888; - - - constexpr const char *GAS_PORT = "/dev/ttyUSB0"; - constexpr int BAUD_RATE = 115200; - - constexpr const char *API_RECEIVE_DATA = "/device/receiveData"; - constexpr const char *API_UPLOAD_PCD_FILE = "/device/receiveFile"; - constexpr const char *HTTP_PORT = "30028"; - constexpr const char *DOG_CODE = "B42D4000OCAD3N82"; - - constexpr const char *SLAM_NET_PORT = "eth0"; - - constexpr const char *ROBOTIC_ARM_PORT = "/dev/ttyACM0"; - - constexpr const char *ROBOTIC_ARM_COMMAND_CONFIG = "/home/unitree/Desktop/robotic_arm_commands.conf"; - constexpr const char *SLAM_PCD_FILE = - "/unitree/module/graph_pid_ws/config_files/lio_sam_config/maps/pcd/default/GlobalMap.pcd"; -} - -#endif //CONSTANT_CONFIG_HPP diff --git a/src/message_handler.cpp b/src/message_handler.cpp index ec3d7d8..21c8099 100644 --- a/src/message_handler.cpp +++ b/src/message_handler.cpp @@ -5,13 +5,13 @@ #include "tcp_service.hpp" #include "tcp_client.hpp" #include "methane_serial_port.hpp" -#include "constant_config.hpp" +#include "config.hpp" int main() { //启动TCP服务端 std::thread service_thread([] { boost::asio::io_service io; - TcpService::getInstance().start(ConstantConfig::TCP_LOCALE_PORT); + TcpService::getInstance().start(Config::TCP_SERVICE_LOCALE_PORT); io.run(); }); @@ -19,7 +19,7 @@ std::thread client_thread([] { boost::asio::io_service io; TcpClient client; - client.connect(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::TCP_REMOTE_PORT); + client.connect(Config::REMOTE_SERVICE_IP, Config::TCP_SERVICE_REMOTE_PORT); io.run(); }); @@ -28,7 +28,7 @@ try { boost::asio::io_service io; //打开串口 - MethaneSerialPort sp(io, ConstantConfig::GAS_PORT, ConstantConfig::BAUD_RATE); //甲烷串口 + MethaneSerialPort sp(io, Config::GAS_PORT, Config::BAUD_RATE); //甲烷串口 sp.read_from_port(); io.run(); } catch (std::exception &e) { diff --git a/src/methane_serial_port.cpp b/src/methane_serial_port.cpp index c7e2b70..a97193c 100644 --- a/src/methane_serial_port.cpp +++ b/src/methane_serial_port.cpp @@ -4,7 +4,7 @@ #include "methane_serial_port.hpp" #include "tcp_service.hpp" -#include "constant_config.hpp" +#include "config.hpp" #include "utils.hpp" #include @@ -23,20 +23,20 @@ void upload_to_server(const int value) { net::io_context ioc; tcp::resolver resolver{ioc}; - auto const results = resolver.resolve(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT); + auto const results = resolver.resolve(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT); tcp::socket socket{ioc}; try { net::connect(socket, results.begin(), results.end()); // 构建HTTP请求 - http::request req{http::verb::post, ConstantConfig::API_RECEIVE_DATA, 11}; - req.set(http::field::host, ConstantConfig::SERVICE_ADDRESS); + http::request req{http::verb::post, Config::API_RECEIVE_DATA, 11}; + req.set(http::field::host, Config::REMOTE_SERVICE_IP); req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); req.set(http::field::content_type, "application/json"); req.set(http::field::connection, "keep-alive"); //{"type":6,"devcode":"1212","data":{"gas":"20"}} std::ostringstream oss; oss << R"({"type":6,"devcode":")" - << ConstantConfig::DOG_CODE + << Config::DOG_CODE << R"(","data":{"gas":")" << value << R"("}})"; @@ -69,7 +69,7 @@ const auto result = x * (1 << 24) + y * (1 << 16) + z * (1 << 8) + w; TcpService::getInstance().update_gas_value(result); // 上传服务器 - if (Utils::is_network_reachable(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT)) { + if (Utils::is_network_reachable(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT)) { upload_to_server_async(result); } } diff --git a/src/constant_config.hpp b/src/constant_config.hpp deleted file mode 100644 index 5b9300e..0000000 --- a/src/constant_config.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by pengx on 2025/4/10. -// - -#ifndef CONSTANT_CONFIG_HPP -#define CONSTANT_CONFIG_HPP - -namespace ConstantConfig { - constexpr int TCP_REMOTE_PORT = 9001; - // constexpr int TCP_REMOTE_PORT = 30029; - - constexpr const char *SERVICE_ADDRESS = "192.168.123.18"; - // constexpr const char *SERVICE_ADDRESS = "111.198.10.15"; - constexpr int TCP_LOCALE_PORT = 8888; - - - constexpr const char *GAS_PORT = "/dev/ttyUSB0"; - constexpr int BAUD_RATE = 115200; - - constexpr const char *API_RECEIVE_DATA = "/device/receiveData"; - constexpr const char *API_UPLOAD_PCD_FILE = "/device/receiveFile"; - constexpr const char *HTTP_PORT = "30028"; - constexpr const char *DOG_CODE = "B42D4000OCAD3N82"; - - constexpr const char *SLAM_NET_PORT = "eth0"; - - constexpr const char *ROBOTIC_ARM_PORT = "/dev/ttyACM0"; - - constexpr const char *ROBOTIC_ARM_COMMAND_CONFIG = "/home/unitree/Desktop/robotic_arm_commands.conf"; - constexpr const char *SLAM_PCD_FILE = - "/unitree/module/graph_pid_ws/config_files/lio_sam_config/maps/pcd/default/GlobalMap.pcd"; -} - -#endif //CONSTANT_CONFIG_HPP diff --git a/src/message_handler.cpp b/src/message_handler.cpp index ec3d7d8..21c8099 100644 --- a/src/message_handler.cpp +++ b/src/message_handler.cpp @@ -5,13 +5,13 @@ #include "tcp_service.hpp" #include "tcp_client.hpp" #include "methane_serial_port.hpp" -#include "constant_config.hpp" +#include "config.hpp" int main() { //启动TCP服务端 std::thread service_thread([] { boost::asio::io_service io; - TcpService::getInstance().start(ConstantConfig::TCP_LOCALE_PORT); + TcpService::getInstance().start(Config::TCP_SERVICE_LOCALE_PORT); io.run(); }); @@ -19,7 +19,7 @@ std::thread client_thread([] { boost::asio::io_service io; TcpClient client; - client.connect(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::TCP_REMOTE_PORT); + client.connect(Config::REMOTE_SERVICE_IP, Config::TCP_SERVICE_REMOTE_PORT); io.run(); }); @@ -28,7 +28,7 @@ try { boost::asio::io_service io; //打开串口 - MethaneSerialPort sp(io, ConstantConfig::GAS_PORT, ConstantConfig::BAUD_RATE); //甲烷串口 + MethaneSerialPort sp(io, Config::GAS_PORT, Config::BAUD_RATE); //甲烷串口 sp.read_from_port(); io.run(); } catch (std::exception &e) { diff --git a/src/methane_serial_port.cpp b/src/methane_serial_port.cpp index c7e2b70..a97193c 100644 --- a/src/methane_serial_port.cpp +++ b/src/methane_serial_port.cpp @@ -4,7 +4,7 @@ #include "methane_serial_port.hpp" #include "tcp_service.hpp" -#include "constant_config.hpp" +#include "config.hpp" #include "utils.hpp" #include @@ -23,20 +23,20 @@ void upload_to_server(const int value) { net::io_context ioc; tcp::resolver resolver{ioc}; - auto const results = resolver.resolve(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT); + auto const results = resolver.resolve(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT); tcp::socket socket{ioc}; try { net::connect(socket, results.begin(), results.end()); // 构建HTTP请求 - http::request req{http::verb::post, ConstantConfig::API_RECEIVE_DATA, 11}; - req.set(http::field::host, ConstantConfig::SERVICE_ADDRESS); + http::request req{http::verb::post, Config::API_RECEIVE_DATA, 11}; + req.set(http::field::host, Config::REMOTE_SERVICE_IP); req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); req.set(http::field::content_type, "application/json"); req.set(http::field::connection, "keep-alive"); //{"type":6,"devcode":"1212","data":{"gas":"20"}} std::ostringstream oss; oss << R"({"type":6,"devcode":")" - << ConstantConfig::DOG_CODE + << Config::DOG_CODE << R"(","data":{"gas":")" << value << R"("}})"; @@ -69,7 +69,7 @@ const auto result = x * (1 << 24) + y * (1 << 16) + z * (1 << 8) + w; TcpService::getInstance().update_gas_value(result); // 上传服务器 - if (Utils::is_network_reachable(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT)) { + if (Utils::is_network_reachable(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT)) { upload_to_server_async(result); } } diff --git a/src/slam_wrapper.cpp b/src/slam_wrapper.cpp index b02899f..249e83b 100644 --- a/src/slam_wrapper.cpp +++ b/src/slam_wrapper.cpp @@ -4,7 +4,7 @@ #include "slam_wrapper.hpp" #include "tcp_service.hpp" -#include "constant_config.hpp" +#include "config.hpp" #include "utils.hpp" #include @@ -69,18 +69,18 @@ tcp::socket socket(ioc); // 解析并连接服务器 - auto const results = resolver.resolve(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT); + auto const results = resolver.resolve(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT); boost::asio::connect(socket, results.begin(), results.end()); // 构建 HTTP 请求 - http::request req{http::verb::post, ConstantConfig::API_UPLOAD_PCD_FILE, 11}; - req.set(http::field::host, ConstantConfig::SERVICE_ADDRESS); + http::request req{http::verb::post, Config::API_UPLOAD_PCD_FILE, 11}; + req.set(http::field::host, Config::REMOTE_SERVICE_IP); req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); // 构建 multipart/form-data 数据 std::string boundary = "---------------------------boundary_example_" + std::to_string(std::time(nullptr)); std::string contentType; - std::string body = generate_multipart_form(ConstantConfig::SLAM_PCD_FILE, boundary, contentType); + std::string body = generate_multipart_form(Config::SLAM_PCD_FILE, boundary, contentType); if (body.empty()) { throw std::runtime_error("Failed to generate multipart form data"); } @@ -111,12 +111,12 @@ } SlamWrapper::SlamWrapper() { - ChannelFactory::Instance()->Init(0, ConstantConfig::SLAM_NET_PORT); + ChannelFactory::Instance()->Init(0, Config::SLAM_NET_PORT); std::thread serial_port_thread([this] { //初始化机械臂串口 boost::asio::io_service io; - _serialPortPtr = new RoboticArmSerialPort(io, ConstantConfig::ROBOTIC_ARM_PORT, ConstantConfig::BAUD_RATE); + _serialPortPtr = new RoboticArmSerialPort(io, Config::ROBOTIC_ARM_PORT, Config::BAUD_RATE); io.run(); }); serial_port_thread.detach(); @@ -131,7 +131,7 @@ subOdometer->InitChannel(std::bind(&SlamWrapper::odometer_handler, this, std::placeholders::_1), 1); // 读取本地指令配置 - std::ifstream config_file(ConstantConfig::ROBOTIC_ARM_COMMAND_CONFIG); + std::ifstream config_file(Config::ROBOTIC_ARM_COMMAND_CONFIG); if (!config_file.is_open()) { std::cerr << "Failed to open config file" << std::endl; return; @@ -304,7 +304,7 @@ void SlamWrapper::save_command() const { if (!_commandCaches.empty()) { //覆盖保存/home/unitree/Desktop/robotic_arm_commands.conf - const std::string filepath = ConstantConfig::ROBOTIC_ARM_COMMAND_CONFIG; + const std::string filepath = Config::ROBOTIC_ARM_COMMAND_CONFIG; std::ofstream file(filepath); if (!file.is_open()) { std::cerr << "Failed to open config file for writing: " << filepath << std::endl; @@ -362,8 +362,9 @@ } void SlamWrapper::arm_turn_let_bottom() const { + //FE FE 0E 3D 04 67 06 55 08 A6 08 01 0A C7 08 A9 FA _serialPortPtr->write({ - 0xFE, 0xFE, 0x0F, 0x3C, 0x04, 0x1a, 0x07, 0x65, 0x08, 0x99, 0x07, 0xb8, 0x0a, 0x8d, 0x07, 0xdb, 0x14, 0xFA + 0xFE, 0xFE, 0x0F, 0x3C, 0x04, 0x67, 0x06, 0x55, 0x08, 0xA6, 0x08, 0x01, 0x0A, 0xC7, 0x08, 0xA9, 0x14, 0xFA }); } @@ -459,10 +460,10 @@ send_msg.pcdmap_index_().push_back(0); // PCD Map number,just give a fixed value of 0. pubQtCommand->Write(send_msg); //上传服务器 - if (Utils::is_network_reachable(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT)) { + if (Utils::is_network_reachable(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT)) { upload_pcd_file(); } else { - std::cout << "网络异常,上传PCD文件到" << ConstantConfig::SERVICE_ADDRESS << "失败" << std::endl; + std::cout << "网络异常,上传PCD文件到" << Config::REMOTE_SERVICE_IP << "失败" << std::endl; } } diff --git a/src/constant_config.hpp b/src/constant_config.hpp deleted file mode 100644 index 5b9300e..0000000 --- a/src/constant_config.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by pengx on 2025/4/10. -// - -#ifndef CONSTANT_CONFIG_HPP -#define CONSTANT_CONFIG_HPP - -namespace ConstantConfig { - constexpr int TCP_REMOTE_PORT = 9001; - // constexpr int TCP_REMOTE_PORT = 30029; - - constexpr const char *SERVICE_ADDRESS = "192.168.123.18"; - // constexpr const char *SERVICE_ADDRESS = "111.198.10.15"; - constexpr int TCP_LOCALE_PORT = 8888; - - - constexpr const char *GAS_PORT = "/dev/ttyUSB0"; - constexpr int BAUD_RATE = 115200; - - constexpr const char *API_RECEIVE_DATA = "/device/receiveData"; - constexpr const char *API_UPLOAD_PCD_FILE = "/device/receiveFile"; - constexpr const char *HTTP_PORT = "30028"; - constexpr const char *DOG_CODE = "B42D4000OCAD3N82"; - - constexpr const char *SLAM_NET_PORT = "eth0"; - - constexpr const char *ROBOTIC_ARM_PORT = "/dev/ttyACM0"; - - constexpr const char *ROBOTIC_ARM_COMMAND_CONFIG = "/home/unitree/Desktop/robotic_arm_commands.conf"; - constexpr const char *SLAM_PCD_FILE = - "/unitree/module/graph_pid_ws/config_files/lio_sam_config/maps/pcd/default/GlobalMap.pcd"; -} - -#endif //CONSTANT_CONFIG_HPP diff --git a/src/message_handler.cpp b/src/message_handler.cpp index ec3d7d8..21c8099 100644 --- a/src/message_handler.cpp +++ b/src/message_handler.cpp @@ -5,13 +5,13 @@ #include "tcp_service.hpp" #include "tcp_client.hpp" #include "methane_serial_port.hpp" -#include "constant_config.hpp" +#include "config.hpp" int main() { //启动TCP服务端 std::thread service_thread([] { boost::asio::io_service io; - TcpService::getInstance().start(ConstantConfig::TCP_LOCALE_PORT); + TcpService::getInstance().start(Config::TCP_SERVICE_LOCALE_PORT); io.run(); }); @@ -19,7 +19,7 @@ std::thread client_thread([] { boost::asio::io_service io; TcpClient client; - client.connect(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::TCP_REMOTE_PORT); + client.connect(Config::REMOTE_SERVICE_IP, Config::TCP_SERVICE_REMOTE_PORT); io.run(); }); @@ -28,7 +28,7 @@ try { boost::asio::io_service io; //打开串口 - MethaneSerialPort sp(io, ConstantConfig::GAS_PORT, ConstantConfig::BAUD_RATE); //甲烷串口 + MethaneSerialPort sp(io, Config::GAS_PORT, Config::BAUD_RATE); //甲烷串口 sp.read_from_port(); io.run(); } catch (std::exception &e) { diff --git a/src/methane_serial_port.cpp b/src/methane_serial_port.cpp index c7e2b70..a97193c 100644 --- a/src/methane_serial_port.cpp +++ b/src/methane_serial_port.cpp @@ -4,7 +4,7 @@ #include "methane_serial_port.hpp" #include "tcp_service.hpp" -#include "constant_config.hpp" +#include "config.hpp" #include "utils.hpp" #include @@ -23,20 +23,20 @@ void upload_to_server(const int value) { net::io_context ioc; tcp::resolver resolver{ioc}; - auto const results = resolver.resolve(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT); + auto const results = resolver.resolve(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT); tcp::socket socket{ioc}; try { net::connect(socket, results.begin(), results.end()); // 构建HTTP请求 - http::request req{http::verb::post, ConstantConfig::API_RECEIVE_DATA, 11}; - req.set(http::field::host, ConstantConfig::SERVICE_ADDRESS); + http::request req{http::verb::post, Config::API_RECEIVE_DATA, 11}; + req.set(http::field::host, Config::REMOTE_SERVICE_IP); req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); req.set(http::field::content_type, "application/json"); req.set(http::field::connection, "keep-alive"); //{"type":6,"devcode":"1212","data":{"gas":"20"}} std::ostringstream oss; oss << R"({"type":6,"devcode":")" - << ConstantConfig::DOG_CODE + << Config::DOG_CODE << R"(","data":{"gas":")" << value << R"("}})"; @@ -69,7 +69,7 @@ const auto result = x * (1 << 24) + y * (1 << 16) + z * (1 << 8) + w; TcpService::getInstance().update_gas_value(result); // 上传服务器 - if (Utils::is_network_reachable(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT)) { + if (Utils::is_network_reachable(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT)) { upload_to_server_async(result); } } diff --git a/src/slam_wrapper.cpp b/src/slam_wrapper.cpp index b02899f..249e83b 100644 --- a/src/slam_wrapper.cpp +++ b/src/slam_wrapper.cpp @@ -4,7 +4,7 @@ #include "slam_wrapper.hpp" #include "tcp_service.hpp" -#include "constant_config.hpp" +#include "config.hpp" #include "utils.hpp" #include @@ -69,18 +69,18 @@ tcp::socket socket(ioc); // 解析并连接服务器 - auto const results = resolver.resolve(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT); + auto const results = resolver.resolve(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT); boost::asio::connect(socket, results.begin(), results.end()); // 构建 HTTP 请求 - http::request req{http::verb::post, ConstantConfig::API_UPLOAD_PCD_FILE, 11}; - req.set(http::field::host, ConstantConfig::SERVICE_ADDRESS); + http::request req{http::verb::post, Config::API_UPLOAD_PCD_FILE, 11}; + req.set(http::field::host, Config::REMOTE_SERVICE_IP); req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); // 构建 multipart/form-data 数据 std::string boundary = "---------------------------boundary_example_" + std::to_string(std::time(nullptr)); std::string contentType; - std::string body = generate_multipart_form(ConstantConfig::SLAM_PCD_FILE, boundary, contentType); + std::string body = generate_multipart_form(Config::SLAM_PCD_FILE, boundary, contentType); if (body.empty()) { throw std::runtime_error("Failed to generate multipart form data"); } @@ -111,12 +111,12 @@ } SlamWrapper::SlamWrapper() { - ChannelFactory::Instance()->Init(0, ConstantConfig::SLAM_NET_PORT); + ChannelFactory::Instance()->Init(0, Config::SLAM_NET_PORT); std::thread serial_port_thread([this] { //初始化机械臂串口 boost::asio::io_service io; - _serialPortPtr = new RoboticArmSerialPort(io, ConstantConfig::ROBOTIC_ARM_PORT, ConstantConfig::BAUD_RATE); + _serialPortPtr = new RoboticArmSerialPort(io, Config::ROBOTIC_ARM_PORT, Config::BAUD_RATE); io.run(); }); serial_port_thread.detach(); @@ -131,7 +131,7 @@ subOdometer->InitChannel(std::bind(&SlamWrapper::odometer_handler, this, std::placeholders::_1), 1); // 读取本地指令配置 - std::ifstream config_file(ConstantConfig::ROBOTIC_ARM_COMMAND_CONFIG); + std::ifstream config_file(Config::ROBOTIC_ARM_COMMAND_CONFIG); if (!config_file.is_open()) { std::cerr << "Failed to open config file" << std::endl; return; @@ -304,7 +304,7 @@ void SlamWrapper::save_command() const { if (!_commandCaches.empty()) { //覆盖保存/home/unitree/Desktop/robotic_arm_commands.conf - const std::string filepath = ConstantConfig::ROBOTIC_ARM_COMMAND_CONFIG; + const std::string filepath = Config::ROBOTIC_ARM_COMMAND_CONFIG; std::ofstream file(filepath); if (!file.is_open()) { std::cerr << "Failed to open config file for writing: " << filepath << std::endl; @@ -362,8 +362,9 @@ } void SlamWrapper::arm_turn_let_bottom() const { + //FE FE 0E 3D 04 67 06 55 08 A6 08 01 0A C7 08 A9 FA _serialPortPtr->write({ - 0xFE, 0xFE, 0x0F, 0x3C, 0x04, 0x1a, 0x07, 0x65, 0x08, 0x99, 0x07, 0xb8, 0x0a, 0x8d, 0x07, 0xdb, 0x14, 0xFA + 0xFE, 0xFE, 0x0F, 0x3C, 0x04, 0x67, 0x06, 0x55, 0x08, 0xA6, 0x08, 0x01, 0x0A, 0xC7, 0x08, 0xA9, 0x14, 0xFA }); } @@ -459,10 +460,10 @@ send_msg.pcdmap_index_().push_back(0); // PCD Map number,just give a fixed value of 0. pubQtCommand->Write(send_msg); //上传服务器 - if (Utils::is_network_reachable(ConstantConfig::SERVICE_ADDRESS, ConstantConfig::HTTP_PORT)) { + if (Utils::is_network_reachable(Config::REMOTE_SERVICE_IP, Config::HTTP_PORT)) { upload_pcd_file(); } else { - std::cout << "网络异常,上传PCD文件到" << ConstantConfig::SERVICE_ADDRESS << "失败" << std::endl; + std::cout << "网络异常,上传PCD文件到" << Config::REMOTE_SERVICE_IP << "失败" << std::endl; } } diff --git a/src/tcp_client.cpp b/src/tcp_client.cpp index a4f508e..c712f81 100644 --- a/src/tcp_client.cpp +++ b/src/tcp_client.cpp @@ -5,7 +5,7 @@ #include "tcp_client.hpp" #include "tcp_service.hpp" #include "slam_wrapper.hpp" -#include "constant_config.hpp" +#include "config.hpp" #include #include @@ -173,7 +173,7 @@ << ", waiting for command ..." << std::endl; //连接成功后把自己的编号发送给Tcp Service - const std::string dog_code = std::string("devCode:") + ConstantConfig::DOG_CODE; + const std::string dog_code = std::string("devCode:") + Config::DOG_CODE; send(_client_socket, dog_code.c_str(), dog_code.size(), 0); // 启动接收数据的线程