提交 0fe985c3 作者: 崔世豪

合并分支 'shihao' 到 'master'

修改joy驱动

查看合并请求 !2
......@@ -33,6 +33,12 @@ chair_code::~chair_code()
feedback_data::release();//释放车铲反馈数据
logger_module::release();//释放log记录
//if (_refresh_reveal_timer) {
// _refresh_reveal_timer->stop();
// delete _refresh_reveal_timer;
// _refresh_reveal_timer = nullptr;
//}//释放定时器
delete ui;
ui = nullptr;
global_signal::instance()->record_debug_logger("~chair_code()");
......@@ -63,8 +69,9 @@ void chair_code::initialize_main_window()//初始化界面
initialize_car_chair_gui();//车界面
}
_refresh_reveal_timer = new QTimer();//启动刷新界面显示的计时器
connect(_refresh_reveal_timer, &QTimer::timeout, this, &chair_code::refresh_display);
std::unique_ptr<QTimer> _refresh_reveal_timer = std::make_unique<QTimer>();
//_refresh_reveal_timer = new QTimer();//启动刷新界面显示的计时器
connect(_refresh_reveal_timer.get(), &QTimer::timeout, this, &chair_code::refresh_display);
_refresh_reveal_timer->setTimerType(Qt::PreciseTimer);
_refresh_reveal_timer->start(100);
}
......
......@@ -13,6 +13,8 @@
#include "feedback_data.h"
#include "control_module.h"
#ifdef WIN32
#pragma execution_character_set("utf-8")// 该指令仅支持VS环境
#endif
......@@ -45,13 +47,14 @@ private slots:
private:
Ui::chair_codeClass* ui;
QTimer* _refresh_reveal_timer = nullptr;
//QTimer* _refresh_reveal_timer = nullptr;
std::unique_ptr<grpc_module> _grpc_module = nullptr;
std::unique_ptr<network_module> _network_module = nullptr;
std::unique_ptr<remote_module> _remote_module = nullptr;
std::unique_ptr<control_module> _control_module = nullptr;
//单例类
std::shared_ptr<acquire_config> _acquire_config = nullptr;
std::shared_ptr<module_data> _module_data = nullptr;
......
......@@ -45,7 +45,7 @@
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.14.2_msvc2017_64</QtInstall>
<QtInstall>5.14.0_msvc2017_64</QtInstall>
<QtModules>core;network;gui;widgets;serialport;concurrent</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
......@@ -115,6 +115,7 @@
<ClCompile Include="module_data.cpp" />
<ClCompile Include="moza_module.cpp" />
<ClCompile Include="network_module.cpp" />
<ClCompile Include="sdl_module.cpp" />
<ClCompile Include="shovel_chair.grpc.pb.cc" />
<ClCompile Include="shovel_chair.pb.cc" />
<ClCompile Include="tcp_thread.cpp">
......@@ -152,6 +153,7 @@
<QtMoc Include="remote_module.h" />
<QtMoc Include="feishi_module.h" />
<QtMoc Include="control_module.h" />
<QtMoc Include="sdl_module.h" />
<ClInclude Include="shovel_chair.grpc.pb.h" />
<ClInclude Include="shovel_chair.pb.h" />
<ClInclude Include="shovel_server_impl.h" />
......
......@@ -103,6 +103,9 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="sdl_module.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="shovel_server_impl.h">
......@@ -192,5 +195,8 @@
<QtMoc Include="tcp_thread.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="sdl_module.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -2,9 +2,9 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2023-12-19T08:48:42.6569979Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-12-20T01:47:47.9984857Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2023-12-19T08:48:42.7051859Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-12-20T01:49:57.5420612Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -4,7 +4,7 @@ publish_message_type=2;//1云端,2直连
username=boonray;//登录用户名
password=Boonray@123;//登录密码
server_url=http://139.196.75.44:8900;//服务器
server_grpc_host=192.168.1.3;//grpc server ip
server_grpc_host=192.168.9.198;//grpc server ip
mqtt_host=139.196.75.44;//mqtt ip
mqtt_port=28884;//mqtt 端口
hardware_to_chair_way=2;//读取硬件座椅数据的方式1: joystick,2:tcp,3:udp
......@@ -16,7 +16,7 @@ publish_control_frequency=10;//发送车铲控制数据的HZ数
publish_status_frequency=10;//发送车铲状态数据的HZ数
[Shovel]
chair_name=moza;//座椅名称
chair_name=gzy;//座椅名称
chair_sn=shihao_test_01;//本座椅的sn
device_sn=;//默认所控的sn
chair_host=192.168.9.198;//座椅程序IP,不接收0.0.0.0
......@@ -27,7 +27,7 @@ hardware_host=192.168.9.53;//硬件座椅IP 用于接收座椅指令数据 当
hardware_to_chair_port=18855;//硬件座椅端口 用于接收座椅指令数据
[Car]
chair_name=feishi;//gzy:湖州的白色座椅 bulldozer:挖机
chair_name=gzy;//gzy:湖州的白色座椅 bulldozer:挖机
chair_sn=car_chair_shihao;//本座椅的sn
device_sn=;//默认所控的sn
chair_host=0.0.0.0;//座椅程序IP
......
0300eef8bc2000006312000000000000
03001b3c6e3400000300000000000000
......@@ -13,14 +13,13 @@ control_module::control_module(QObject* parent)
_module_data = module_data::instance();//全局数据中转
_feedback_data = feedback_data::instance();//车铲反馈数据
_write_control_timer = new QTimer(this);
_write_status_timer = new QTimer(this);
_write_control_timer = std::make_unique<QTimer>(this);
_write_status_timer = std::make_unique<QTimer>(this);
_udp_thread = std::make_unique<udp_thread>(_module_data->chair_host, _module_data->chair_port, "control_module");
_udp_thread = new udp_thread(_module_data->chair_host, _module_data->chair_port, "control_module");
connect(_write_control_timer, &QTimer::timeout, this, &control_module::on_write_control_timer);
connect(_write_status_timer, &QTimer::timeout, this, &control_module::on_write_statusl_timer);
connect(_udp_thread, &udp_thread::udp_received_data, this, &control_module::no_udp_received_data);
connect(_write_control_timer.get(), &QTimer::timeout, this, &control_module::on_write_control_timer);
connect(_write_status_timer.get(), &QTimer::timeout, this, &control_module::on_write_statusl_timer);
connect(_udp_thread.get(), &udp_thread::udp_received_data, this, &control_module::no_udp_received_data);
control_time_start();//启动下发状态数据的定时器
status_time_start();//启动下发控制的定时器
......@@ -30,6 +29,9 @@ control_module::control_module(QObject* parent)
control_module::~control_module()
{
_write_control_timer.reset();
_write_status_timer.reset();
_udp_thread.reset();
global_signal::instance()->record_debug_logger("~control_module()");
}
......@@ -101,7 +103,7 @@ void control_module::no_udp_received_data(const QByteArray& data, const QHostAdd
this->process_device_data(data);//解析设备端数据/处理切车逻辑
// global_signal::instance()->PublishMsgToWinodw(data);
// global_signal::instance()->PublishMsgToWinodw(data);
}
void control_module::process_device_data(const QByteArray& data)
......
......@@ -38,9 +38,12 @@ private slots:
void on_write_statusl_timer();
private:
udp_thread* _udp_thread = nullptr;
QTimer* _write_control_timer = nullptr;
QTimer* _write_status_timer = nullptr;
//udp_thread* _udp_thread = nullptr;
//QTimer* _write_control_timer = nullptr;
//QTimer* _write_status_timer = nullptr;
std::unique_ptr<udp_thread> _udp_thread = nullptr;
std::unique_ptr<QTimer> _write_control_timer = nullptr;
std::unique_ptr<QTimer> _write_status_timer = nullptr;
std::shared_ptr<module_data> _module_data = nullptr;
std::shared_ptr<feedback_data> _feedback_data = nullptr;
......
......@@ -2,17 +2,17 @@
#include "global_signal.h"
#include <QTimer>
#include <QThread>
feishi_module::feishi_module(const QString& ip, quint16 port, QObject *parent)
feishi_module::feishi_module(const QString& ip, quint16 port, QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
_tcp_thread = std::make_unique<tcp_thread>(ip, port, "feishi_module");
_send_cmd_timer = new QTimer(this);
/*_send_cmd_timer = new QTimer(this);*/
_send_cmd_timer = std::make_unique<QTimer>(this);
connect(_tcp_thread.get(), &tcp_thread::tcp_received_data, this, &feishi_module::no_tcp_received_data);
connect(this, &feishi_module::tcp_write_date, _tcp_thread.get(), &tcp_thread::on_tcp_write_date);
connect(_send_cmd_timer, &QTimer::timeout, this, &feishi_module::on_send_cmd_timer);
connect(_send_cmd_timer.get(), &QTimer::timeout, this, &feishi_module::on_send_cmd_timer);
_send_cmd_timer->setTimerType(Qt::PreciseTimer);
_send_cmd_timer->start(1000 / sending_interval);
......@@ -22,7 +22,7 @@ feishi_module::feishi_module(const QString& ip, quint16 port, QObject *parent)
feishi_module::~feishi_module()
{
_send_cmd_timer->stop();
_send_cmd_timer.reset();
_tcp_thread.reset();
global_signal::instance()->record_debug_logger("~feishi_module()");
}
......@@ -64,7 +64,7 @@ void feishi_module::no_tcp_received_data(const QByteArray& data)//获取座椅
// _last_gear_d = _device_feishi_struct.data.gear_d;
// qDebug() << "D";
//}
if (_device_feishi_struct.data.auto_lock_a_2){//P档
if (_device_feishi_struct.data.auto_lock_a_2) {//P档
_module_data->target_gear = _GEAR_P;
}
else {
......
#pragma once
#pragma once
#include "tcp_thread.h"
#include "module_data.h"
......@@ -19,67 +19,67 @@ private:
int8_t Tab[14];
struct
{
uint8_t version_number : 8;//版本号
uint8_t message_type : 8;//报文类型
uint8_t message_id : 8;//报文ID
uint8_t message_length : 8;//报文长度
uint8_t gear_n : 1;//N
uint8_t gear_r : 1;//R
uint8_t gear_d : 1;//R
uint8_t auto_reset_a_1 : 1;//自复位按钮
uint8_t auto_lock_a_1 : 1;//自锁按钮1
uint8_t auto_lock_a_2 : 1;//自锁按钮2
uint8_t auto_lock_b_1 : 1;//自锁按钮1
uint8_t auto_lock_b_2 : 1;//自锁拨杆2
uint8_t auto_lock_b_3 : 1;//自锁拨杆3
uint8_t auto_lock_b_4 : 1;//自锁拨杆4
uint8_t auto_lock_b_5 : 1;//自锁拨杆5
uint8_t auto_lock_q_1 : 1;//自锁翘板1
uint8_t auto_lock_q_2 : 1;//自锁翘板2
uint8_t auto_lock_q_3 : 1;//自锁翘板3
uint8_t auto_lock_q_4 : 1;//自锁翘板4
uint8_t auto_lock_q_5 : 1;//自锁翘板5
uint8_t auto_lock_q_6 : 1;//自锁翘板6
uint8_t auto_lock_q_7_1 : 1;//自锁翘板7_1
uint8_t auto_lock_q_7_2 : 1;//自锁翘板7_2
uint8_t auto_lock_q_8_1 : 1;//自锁翘板8_1
uint8_t auto_lock_q_8_2 : 1;//自锁翘板8_2
uint8_t scram_switch : 1;//急停开关
uint8_t null1 : 2;//
uint8_t up_trouble : 1;//点火
uint8_t horn : 1;//喇叭
uint8_t width_lamp : 1;//示宽灯
uint8_t low_beam_lamp : 1;//近光灯
uint8_t high_beam_lamp : 1;//远光灯
uint8_t fog_lamp : 1;//雾灯
uint8_t left_turn_lamp : 1;//左转向灯
uint8_t rigth_turn_lamp : 1;//右转向灯
uint8_t wiper_int : 1;//雨刮INT
uint8_t wiper_lo : 1;//雨刮LO
uint8_t wiper_hi : 1;//雨刮HI
uint8_t null2 : 5;//
uint8_t manual_drive : 1;//人工驾驶
uint8_t remote_drive : 1;//远程驾驶
uint8_t auto_drive : 1;//自动驾驶
uint8_t direction_upkey : 1;//方向上键-自复位(可用于选择车辆)
uint8_t direction_downkey : 1;//方向下键-自复位(可用于选择车辆)
uint8_t affirm_but : 1;//确认(可用于确认选择)
uint8_t return_but : 1;//返回(从模式选择界面返回车辆选择界面)
uint8_t null3 : 1;//
int16_t strrting_wheel : 16;//方向盘转角
uint8_t acceleration_pedal : 8;//油门踏板
uint8_t brake_pedal : 8;//刹车踏板
uint8_t version_number : 8;//版本号
uint8_t message_type : 8;//报文类型
uint8_t message_id : 8;//报文ID
uint8_t message_length : 8;//报文长度
uint8_t gear_n : 1;//N
uint8_t gear_r : 1;//R
uint8_t gear_d : 1;//R
uint8_t auto_reset_a_1 : 1;//自复位按钮
uint8_t auto_lock_a_1 : 1;//自锁按钮1
uint8_t auto_lock_a_2 : 1;//自锁按钮2
uint8_t auto_lock_b_1 : 1;//自锁按钮1
uint8_t auto_lock_b_2 : 1;//自锁拨杆2
uint8_t auto_lock_b_3 : 1;//自锁拨杆3
uint8_t auto_lock_b_4 : 1;//自锁拨杆4
uint8_t auto_lock_b_5 : 1;//自锁拨杆5
uint8_t auto_lock_q_1 : 1;//自锁翘板1
uint8_t auto_lock_q_2 : 1;//自锁翘板2
uint8_t auto_lock_q_3 : 1;//自锁翘板3
uint8_t auto_lock_q_4 : 1;//自锁翘板4
uint8_t auto_lock_q_5 : 1;//自锁翘板5
uint8_t auto_lock_q_6 : 1;//自锁翘板6
uint8_t auto_lock_q_7_1 : 1;//自锁翘板7_1
uint8_t auto_lock_q_7_2 : 1;//自锁翘板7_2
uint8_t auto_lock_q_8_1 : 1;//自锁翘板8_1
uint8_t auto_lock_q_8_2 : 1;//自锁翘板8_2
uint8_t scram_switch : 1;//急停开关
uint8_t null1 : 2;//
uint8_t up_trouble : 1;//点火
uint8_t horn : 1;//喇叭
uint8_t width_lamp : 1;//示宽灯
uint8_t low_beam_lamp : 1;//近光灯
uint8_t high_beam_lamp : 1;//远光灯
uint8_t fog_lamp : 1;//雾灯
uint8_t left_turn_lamp : 1;//左转向灯
uint8_t rigth_turn_lamp : 1;//右转向灯
uint8_t wiper_int : 1;//雨刮INT
uint8_t wiper_lo : 1;//雨刮LO
uint8_t wiper_hi : 1;//雨刮HI
uint8_t null2 : 5;//
uint8_t manual_drive : 1;//人工驾驶
uint8_t remote_drive : 1;//远程驾驶
uint8_t auto_drive : 1;//自动驾驶
uint8_t direction_upkey : 1;//方向上键-自复位(可用于选择车辆)
uint8_t direction_downkey : 1;//方向下键-自复位(可用于选择车辆)
uint8_t affirm_but : 1;//确认(可用于确认选择)
uint8_t return_but : 1;//返回(从模式选择界面返回车辆选择界面)
uint8_t null3 : 1;//
int16_t strrting_wheel : 16;//方向盘转角
uint8_t acceleration_pedal : 8;//油门踏板
uint8_t brake_pedal : 8;//刹车踏板
}data;
}device_feishi_struct;
#pragma pack(pop)
device_feishi_struct _device_feishi_struct = {0};
device_feishi_struct _device_feishi_struct = { 0 };
public slots:
void no_tcp_received_data(const QByteArray& data);
......@@ -90,15 +90,17 @@ signals:
void tcp_write_date(const QByteArray& data);
private:
QTimer* _send_cmd_timer = nullptr;
//QTimer* _send_cmd_timer = nullptr;
std::unique_ptr<tcp_thread> _tcp_thread = nullptr;
std::unique_ptr<QTimer> _send_cmd_timer = nullptr;
std::shared_ptr<module_data> _module_data = nullptr;
const int read_data_length = 14;//接收数据长度
const int sending_interval = 10; // 发送数据的时间间隔(以毫秒为单位)
const int read_data_length = 14;//接收数据长度
const int sending_interval = 10; // 发送数据的时间间隔(以毫秒为单位)
// 定义控制指令的值
// 定义控制指令的值
bool _target_emergency_stop;
bool _target_left_light;
bool _target_right_light;
......@@ -107,7 +109,7 @@ private:
bool _target_horn;
int _target_gear;
// 定义座椅指令的值和上次解析时的值
// 定义座椅指令的值和上次解析时的值
bool _last_gear_r;
bool _last_gear_n;
bool _last_gear_d;
......
......@@ -31,12 +31,13 @@ void grpc_module::on_grpc_endthread()
std::ifstream cert_file(client_ca_file);
if (!cert_file.good()) {
std::cerr << "Failed to open cert file: " << client_ca_file << std::endl;
//此处检查不到整数的存在
//此处检查不到证书存在
require_client_cert = false;//关闭ssl
}
}
std::string serverAddress = _module_data->server_grpc_host.toStdString();
if (_module_data->isIpAddressValid(serverAddress)) {//检查IP地址的有效性
serverAddress = _module_data->grpc_server_address.toStdString();
global_signal::instance()->record_debug_logger("gRPC ");
......
......@@ -7,145 +7,41 @@ gzy_module::gzy_module(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
_sdl_module = std::make_unique<sdl_module>();
QTimer* epb_timer = new QTimer(this);
connect(epb_timer, &QTimer::timeout, this, &gzy_module::analyze_seat_epb);
epb_timer->setTimerType(Qt::PreciseTimer);
epb_timer->start(20);
connect(_sdl_module.get(), &sdl_module::buttonStateEvent, this, &gzy_module::analyze_seat_button);
connect(_sdl_module.get(), &sdl_module::axisMotionEvent, this, &gzy_module::analyze_seat_axis);
//QTimer* epb_timer = new QTimer(this);
//connect(epb_timer, &QTimer::timeout, this, &gzy_module::analyze_seat_epb);
//epb_timer->setTimerType(Qt::PreciseTimer);
//epb_timer->start(20);
}
gzy_module::~gzy_module()
{
_sdl_module.reset();
qDebug() << "~gzy_module()";
}
void gzy_module::analyze_seat_axis(int joyIndex, int axis, double value)
void gzy_module::analyze_seat_axis(int joystickIndex, const QString& guid, int axis, double value)
{
if (axis == 0) {
//_module_data->steering = -(value * 100) - _module_data->set_steering_val;
_module_data->target_steering = -(value * 100);
}
else if (axis == 1) {
double is_value = value * 100.0;
if (abs(is_value) > 150) {
is_value = 0;
}
if (is_value >= 10.0)
{
_module_data->target_brake = is_value;
}
else if (is_value <= (-5.0)) {
_module_data->target_throttle = -is_value;
}
else {
_module_data->target_brake = 0.0;
_module_data->target_throttle = 0.0;
}
}
double is_value = 0.0;
is_value = _module_data->map_value(value, -32768.00, 32767.00, 0.0, 100.0);
std::cout << "Axis motion event: JoystickIndex = " << joystickIndex << ", GUID = " << guid.toStdString() << ", Axis = " << axis << ", Value = " << is_value << std::endl;
}
void gzy_module::analyze_seat_button(int joyIndex, int button, bool pressed)
void gzy_module::analyze_seat_button(int joystickIndex, const QString& guid, int button, bool pressed)
{
button += 1;
static bool G_P = false; static bool G_R = false; static bool G_N = false; static bool G_D = false;
if (button == 1) {
if (!pressed) {
global_signal::instance()->record_info_logger("cmd", "下电");
}
else {
global_signal::instance()->record_info_logger("cmd", "上电");
}
}
else if (button == 2) {
if (pressed) {
_module_data->target_left_light = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("左转灯开"));
}
else {
_module_data->target_left_light = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("左转灯关"));
}
}
else if (button == 3) {
if (pressed) {
_module_data->target_right_light = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("右转灯开"));
}
else {
_module_data->target_right_light = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("右转灯关"));
}
}
else if (button == 4) {
if (pressed) {
_module_data->target_low_beam = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("近光灯开"));
}
else {
_module_data->target_low_beam = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("近光灯关"));
}
}
else if (button == 5) {
if (pressed) {
_module_data->target_high_beam = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("远光灯开"));
}
else {
_module_data->target_high_beam = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("远光灯关"));
}
}
else if (button == 6) {
if (pressed) {
global_signal::instance()->record_info_logger("cmd", "安全带开");
}
else {
global_signal::instance()->record_info_logger("cmd", "安全带关");
}
}
else if (button == 7) {
if (pressed) {
global_signal::instance()->record_info_logger("cmd", "示宽开");
}
else {
global_signal::instance()->record_info_logger("cmd", "示宽关");
}
}
else if (button == 8) {}
else if (((button == 9) || (button == 10) || (button == 11) || (button == 12)) && (!handbrake)) {
if (button == 9) {
_module_data->target_gear = 2; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 N 档"));
}
if (button == 10) {
G_N = pressed;
}
if (button == 11) {
G_R = pressed;
_module_data->target_gear = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 R 档"));
}
if (button == 12) {
G_D = pressed; _module_data->target_gear = 3; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 D 档"));
}
if (!G_P && !G_R && !G_D) {
_module_data->target_gear = 2; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 N 档"));
}
}
else if (button == 15) {
handbrake = pressed;
handbrakesta = true;
}
else if (button == 16) {
if (pressed) {
_module_data->target_emergency_stop = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("急停关"));
}
else {
_module_data->target_emergency_stop = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("急停开"));
}
}
else if (button == 17) {
if (pressed) {
_module_data->target_horn = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("喇叭开"));
}
else {
_module_data->target_horn = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("喇叭关"));
std::cout << "Button down event: JoystickIndex = " << joystickIndex << ", GUID = " << guid.toStdString() << ", Button = " << button << std::endl;
if (pressed == 1)
{
std::cout << "Button is pressed" << std::endl;
}
else
{
std::cout << "Button is released" << std::endl;
}
}
......
......@@ -2,6 +2,8 @@
#include <QObject>
#include "module_data.h"
#include "sdl_module.h"
class gzy_module : public QObject
{
......@@ -12,12 +14,14 @@ public:
~gzy_module();
public slots:
void analyze_seat_axis(int joyIndex, int axis, double value);
void analyze_seat_button(int joyIndex, int button, bool pressed);
void analyze_seat_axis(int joystickIndex, const QString& guid, int axis, double value);
void analyze_seat_button(int joystickIndex, const QString& guid, int button, bool state);
private slots:
void analyze_seat_epb();
private:
std::unique_ptr<sdl_module> _sdl_module = nullptr;
//单例类
std::shared_ptr<module_data> _module_data = nullptr;
......
#pragma once
#include "module_data.h"
#include <QtCore>
#include <SFML/Window.hpp>
#include <iostream>
#include <QObject>
#include "module_data.h"
class joy_thread : public QObject
......
#include "chair_code.h"
#define SDL_MAIN_HANDLED
#include "chair_code.h"
#include <QtWidgets/QApplication>
#include <QTextCodec>
......
#include "module_data.h"
#include "global_signal.h"
#include <QHostAddress>
#include <QAbstractSocket>
std::shared_ptr<module_data> module_data::m_instance = nullptr;
std::mutex module_data::m_mutex;
......@@ -121,3 +121,19 @@ bool module_data::isIpAddressValid(const std::string& ipAddress)
QHostAddress address(QString::fromStdString(ipAddress));
return address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol;
}
double module_data::map_value(double input_value, double min_value, double max_value, double target_min_value, double target_max_value)
{
// 计算相对位置
double relative_position = (input_value - min_value) / (max_value - min_value);
// 映射到目标范围
double mapped_value = relative_position * (target_max_value - target_min_value);
// 添加目标范围的最小值
double final_value = mapped_value + target_min_value;
return final_value;
}
\ No newline at end of file
......@@ -33,6 +33,7 @@ public:
QString acquire_device_ip(QString _target_device_sn);
bool isIpAddressValid(const std::string& ipAddress);//检查IP地址的有效性
double map_value(double input_value, double min_value, double max_value, double target_min_value, double target_max_value);
public:
QString chair_name = "";
QString chair_sn = "";
......
......@@ -4,14 +4,16 @@ moza_module::moza_module(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
_joy_thread = new joy_thread();//实例读座椅数据 解析类
connect(_joy_thread, &joy_thread::joy_received_button, this, &moza_module::analyze_seat_button);
connect(_joy_thread, &joy_thread::joy_received_axis, this, &moza_module::analyze_seat_axis);
//_joy_thread = new joy_thread();//实例读座椅数据 解析类
_joy_thread = std::make_unique<joy_thread>(this);
connect(_joy_thread.get(), &joy_thread::joy_received_button, this, &moza_module::analyze_seat_button);
connect(_joy_thread.get(), &joy_thread::joy_received_axis, this, &moza_module::analyze_seat_axis);
}
moza_module::~moza_module()
{
_joy_thread.reset();
qDebug() << "~moza_module()";
}
......
......@@ -18,6 +18,6 @@ public slots:
private:
//单例类
std::shared_ptr<module_data> _module_data = nullptr;
joy_thread* _joy_thread = nullptr;
std::unique_ptr<joy_thread> _joy_thread = nullptr;
//joy_thread* _joy_thread = nullptr;
};
......@@ -30,6 +30,17 @@ remote_module::remote_module(QObject* parent)
remote_module::~remote_module()
{
if (_module_data->chair_name == "moza") {
_moza_module.reset();
}
else if (_module_data->chair_name == "feishi") {
_feishi_module.reset();
}
else if (_module_data->chair_name == "gzy") {//湖州的白色座椅
_gzy_module.reset();
}
else if (_module_data->chair_name == "bulldozer") {//临时兼容推土机ID3
_bulldozer_module.reset();
}
global_signal::instance()->record_debug_logger("~remote_module()");
}
[2023-12-20 09:58:54.569] [logger4] [debug] tcp_thread connect_server:[feishi_module]:192.168.1.3 44444
[2023-12-20 09:58:54.580] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-20 09:59:03.149] [logger4] [debug] ~tcp_thread()
[2023-12-20 09:59:03.149] [logger4] [debug] ~feishi_module()
[2023-12-20 09:59:03.149] [logger4] [debug] ~remote_module()
[2023-12-20 09:59:03.149] [logger4] [debug] ~network_module()
[2023-12-20 09:59:03.149] [logger4] [debug] ~control_module()
[2023-12-20 16:04:20.646] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-20 16:04:20.818] [logger4] [debug] gRPC
[2023-12-20 16:04:20.818] [logger4] [debug] gRPC server listening on 192.168.9.198:50052
[2023-12-20 16:05:18.090] [logger4] [debug] ~grpc_module()
[2023-12-20 16:05:18.091] [logger4] [debug] ~remote_module()
[2023-12-20 16:05:18.091] [logger4] [debug] ~network_module()
[2023-12-20 16:05:18.091] [logger4] [debug] ~control_module()
[2023-12-20 18:22:25.937] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-20 18:22:26.118] [logger4] [debug] gRPC
[2023-12-20 18:22:26.118] [logger4] [debug] gRPC server listening on 192.168.9.198:50052
[2023-12-20 18:22:45.253] [logger4] [debug] ~grpc_module()
[2023-12-20 18:22:45.254] [logger4] [debug] ~remote_module()
[2023-12-20 18:22:45.255] [logger4] [debug] ~network_module()
[2023-12-20 18:22:45.255] [logger4] [debug] ~udp_thread()
[2023-12-20 18:22:45.255] [logger4] [debug] ~control_module()
[2023-12-20 18:26:55.208] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-20 18:26:55.380] [logger4] [debug] gRPC
[2023-12-20 18:26:55.380] [logger4] [debug] gRPC server listening on 192.168.9.198:50052
[2023-12-20 18:27:18.277] [logger4] [debug] ~grpc_module()
[2023-12-20 18:27:18.279] [logger4] [debug] ~remote_module()
[2023-12-20 18:27:18.279] [logger4] [debug] ~network_module()
[2023-12-20 18:27:18.280] [logger4] [debug] ~udp_thread()
[2023-12-20 18:27:18.280] [logger4] [debug] ~control_module()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论