提交 d77937aa 作者: 崔世豪

.

上级 10473ed8
......@@ -136,8 +136,8 @@ void acquire_config::get_configuration_file()
qDebug() << "http_enable_cert:" << http_enable_cert;
qDebug() << "publish_control_frequency:" << publish_control_frequency;
qDebug() << "publish_status_frequency:" << publish_status_frequency;
qDebug() << "chair_sn:" << chair_sn;
qDebug() << "chair_name:" << chair_name;
qDebug() << "device_sn:" << device_sn;
qDebug() << "chair_host:" << chair_host;
qDebug() << "chair_to_device_port:" << chair_to_device_port;
......
#pragma once
#include <QObject>
#include "udp_thread.h"
#include "module_data.h"
#include "joy_thread.h"
//#include "udp_thread.h"
class bulldozer_module : public QObject
{
......@@ -11,10 +13,18 @@ public:
explicit bulldozer_module(const QString& ip, quint16 port, QObject* parent = nullptr);
~bulldozer_module();
int mapRange(double value, double fromMin, double fromMax, double toMin, double toMax);
public slots:
void no_udp_received_data(const QByteArray& data);
private:
void parseData(const QString& data);
void analyze_seat_axis(int joyIndex, int axis, double value);
void analyze_seat_button(int joyIndex, int button, bool pressed);
//public slots:
// void no_udp_received_data(const QByteArray& data);
//private:
// void parseData(const QString& data);
// int handleControlData(const int currentLeftValue);
private:
udp_thread* _udp_thread = nullptr;
//udp_thread* _udp_thread = nullptr;
joy_thread* _joy_thread = nullptr;
std::shared_ptr<module_data> _module_data = nullptr;
};
......@@ -15,13 +15,16 @@ chair_code::chair_code(QWidget* parent)
_network_module = new network_module();//开启网联模块
_control_module = new control_module();//读取座椅指令
_remote_module = new remote_module();//读取座椅指令
_control_module = new control_module();//开启下发控制
qDebug() << "chair_code thread ID: " << QThread::currentThreadId();
}
chair_code::~chair_code()
{
_module_data->joy_enable = false;//关闭jou使能
logger_module::release();//释放log记录
acquire_config::release();//释放获取配置
feedback_data::release();//释放车铲反馈数据
......@@ -51,6 +54,8 @@ void chair_code::initialize_main_window()//初始化界面
connect(global_signal::instance(), &global_signal::error_logger, this, &chair_code::record_error_logger_clicked);
connect(global_signal::instance(), &global_signal::info_logger, this, &chair_code::record_info_logger_clicked);
//
if (_module_data->chair_type == _SHOVEL) {
}
......
#pragma once
#pragma once
#include <QtWidgets/QMainWindow>
#include <QTimer>
......@@ -7,30 +7,31 @@
#include "acquire_config.h"
#include "logger_module.h"
#include "network_module.h"
#include "control_module.h"
#include "remote_module.h"
#include "grpc_module.h"
#include "module_data.h"
#include "feedback_data.h"
#include "control_module.h"
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")// 该指令仅支持VS环境
#pragma execution_character_set("utf-8")// 该指令仅支持VS环境
#endif
class chair_code : public QMainWindow
{
Q_OBJECT
Q_OBJECT
public:
explicit chair_code(QWidget *parent = nullptr);
~chair_code();
explicit chair_code(QWidget* parent = nullptr);
~chair_code();
private:
void initialize_main_window();//始化界面
void initialize_car_chair_gui();//初始化车座椅界面。
void refresh_car_status_gui();//刷新车界面的显示状态。
void show_car_chair_status_list();//显示车座椅状态列表。
void initialize_main_window();//初始化界面
void initialize_car_chair_gui();//初始化车座椅界面。
void refresh_car_status_gui();//刷新车界面的显示状态。
void show_car_chair_status_list();//显示车座椅状态列表。
private slots:
......@@ -43,18 +44,19 @@ private slots:
private:
Ui::chair_codeClass* ui;
Ui::chair_codeClass* ui;
QTimer* _refresh_reveal_timer = nullptr;
//QTimer* _refresh_reveal_timer;//刷新界面显示定时器
//QTimer* _refresh_reveal_timer;//刷新界面显示定时器
grpc_module* _grpc_module = nullptr;
network_module* _network_module = nullptr;
remote_module* _remote_module = nullptr;
control_module* _control_module = nullptr;
//std::unique_ptr<QTimer> _refresh_reveal_timer;
//std::unique_ptr<grpc_module> _grpc_module;
//std::unique_ptr<network_module> _network_module;
//std::unique_ptr<control_module> _control_module;
//单例类
//单例类
std::shared_ptr<acquire_config> _acquire_config = nullptr;
std::shared_ptr<module_data> _module_data = nullptr;
std::shared_ptr<feedback_data> _feedback_data = nullptr;
......
......@@ -102,6 +102,7 @@
<ClCompile Include="car_chair.grpc.pb.cc" />
<ClCompile Include="car_chair.pb.cc" />
<ClCompile Include="control_module.cpp" />
<ClCompile Include="remote_module.cpp" />
<ClCompile Include="feedback_data.cpp" />
<ClCompile Include="feishi_module.cpp" />
<ClCompile Include="grpc_module.cpp" />
......@@ -141,8 +142,9 @@
<QtMoc Include="joy_thread.h" />
<QtMoc Include="moza_module.h" />
<QtMoc Include="gzy_module.h" />
<QtMoc Include="control_module.h" />
<QtMoc Include="remote_module.h" />
<QtMoc Include="feishi_module.h" />
<QtMoc Include="control_module.h" />
<ClInclude Include="shovel_chair.grpc.pb.h" />
<ClInclude Include="shovel_chair.pb.h" />
<ClInclude Include="shovel_server_impl.h" />
......
......@@ -91,7 +91,7 @@
<ClCompile Include="gzy_module.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="control_module.cpp">
<ClCompile Include="remote_module.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="feishi_module.cpp">
......@@ -100,6 +100,9 @@
<ClCompile Include="bulldozer_module.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="control_module.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="shovel_server_impl.h">
......@@ -176,7 +179,7 @@
<QtMoc Include="gzy_module.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="control_module.h">
<QtMoc Include="remote_module.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="feishi_module.h">
......@@ -185,5 +188,8 @@
<QtMoc Include="bulldozer_module.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="control_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-04T03:03:49.9005770Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-12-05T01:42:00.7679855Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2023-12-04T08:03:26.9085734Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-12-05T01:42:00.9065592Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -27,14 +27,14 @@ hardware_host=192.168.9.53;//蝖砌辣摨扳P 鈭摨扳誘 敶
hardware_to_chair_port=18855;//硬件座椅端口 用于接收座椅指令数据
[Car]
chair_name=bulldozer;//gzy:湖州的白色座椅 bulldozer:挖机
chair_name=moza;//gzy:湖州的白色座椅 bulldozer:挖机
chair_sn=car_chair_shihao;//本座椅的sn
device_sn=;//默认所控的sn
chair_host=192.168.9.198;//座椅程序IP
chair_port=8801;//座椅程序端口
chair_port=8805;//座椅程序端口
chair_to_device_port=8801;//座椅程序下发控制指令的端口
grpc_to_chair_port=50052;//pad到座椅的指令端口,grpc server ip
hardware_host=192.168.9.53;//硬件座椅IP 用于接收座椅指令数据 当与座椅进行tcp 通信时需要
hardware_to_chair_port=18855;//硬件座椅端口 用于接收座椅指令数据
hardware_host=192.168.9.120;//硬件座椅IP 用于接收座椅指令数据 当与座椅进行tcp 通信时需要
hardware_to_chair_port=11888;//硬件座椅端口 用于接收座椅指令数据
brake_ignore=20.0;//刹车忽略值
steering_ignore=1.0;//方向盘忽略值
\ No newline at end of file
#include "control_module.h"
#include "global_signal.h"
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QDateTime>
#include <QTimer>
control_module::control_module(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
QTimer* _send_cmd_timer = new QTimer(this);
_udp_thread = new udp_thread(_module_data->chair_host, _module_data->chair_port, "control_module");
connect(_send_cmd_timer, &QTimer::timeout, this, &control_module::on_send_cmd_timer);
connect(_udp_thread, &udp_thread::udp_received_data, this, &control_module::no_udp_received_data);
_send_cmd_timer->setTimerType(Qt::PreciseTimer);
_send_cmd_timer->start(100);
if (_module_data->chair_name == "moza") {
_moza_module = new moza_module();//实例moza 解析类
}
else if (_module_data->chair_name == "feishi") {
_feishi_module = new feishi_module(_module_data->hardware_host, _module_data->hardware_to_chair_port);
}
else if (_module_data->chair_name == "gzy") {//湖州的白色座椅
_gzy_module = new gzy_module();//实例moza 解析类
//_joy_thread = new joy_thread();//实例读座椅数据 解析类
//connect(_joy_thread, &joy_thread::joy_received_button, _gzy_module, &gzy_module::analyze_seat_button);
//connect(_joy_thread, &joy_thread::joy_received_axis, _gzy_module, &gzy_module::analyze_seat_axis);
}
else if (_module_data->chair_name == "bulldozer") {//临时兼容推土机ID3
_bulldozer_module = new bulldozer_module("", _module_data->hardware_to_chair_port);
}
//_udp_thread = new udp_thread(_module_data->chair_host, _module_data->chair_to_device_port, "car");
//_udp_thread->udp_write_date("qwertyuiop", "192.168.1.3", 23456);
//_joy_thread = new joy_thread();
qDebug() << "control_module thread ID: " << QThread::currentThreadId();
}
control_module::~control_module()
{
}
void control_module::on_send_cmd_timer()
{
QByteArray dataarray = bulldozer_generate_realtime_control_message();
_udp_thread->udp_write_date(dataarray, _module_data->hardware_host, _module_data->hardware_to_chair_port);
}
void control_module::no_udp_received_data(const QByteArray& data)
{
global_signal::instance()->PublishMsgToWinodw(data);
}
QByteArray control_module::bulldozer_generate_realtime_control_message()
{
QJsonObject JparamsObject;
JparamsObject.insert("sn", _module_data->chair_sn);
JparamsObject.insert("unlock", _module_data->target_bulldozer_unlock);
JparamsObject.insert("drive_mode", _module_data->target_bulldozer_mode_switch);
JparamsObject.insert("horn", _module_data->target_bulldozer_horn);
JparamsObject.insert("light", _module_data->target_bulldozer_light);
JparamsObject.insert("forward_backward", _module_data->target_bulldozer_forward_backward);
/*JparamsObject.insert("forward", _module_data->target_bulldozer_forward);
JparamsObject.insert("backward", _module_data->target_bulldozer_backward);*/
JparamsObject.insert("left_right", _module_data->target_bulldozer_left_right);
/*JparamsObject.insert("left", _module_data->target_bulldozer_left);
JparamsObject.insert("right", _module_data->target_bulldozer_right);*/
JparamsObject.insert("throttle", _module_data->target_bulldozer_throttle);
JparamsObject.insert("rise_gear", _module_data->target_bulldozer_rise_gear);
JparamsObject.insert("fall_gear", _module_data->target_bulldozer_fall_gear);
JparamsObject.insert("lift_lower", _module_data->target_bulldozer_lift_lower);
/*JparamsObject.insert("lift", _module_data->target_bulldozer_lift);
JparamsObject.insert("lower", _module_data->target_bulldozer_lower);*/
JparamsObject.insert("tilt_left_right", _module_data->target_bulldozer_tilt_left_right);
/*JparamsObject.insert("tilt_left", _module_data->target_bulldozer_tilt_left);
JparamsObject.insert("tilt_right", _module_data->target_bulldozer_tilt_right);*/
JparamsObject.insert("engine_speed", _module_data->target_bulldozer_engine_speed);
JparamsObject.insert("timestamp", QString::number(QDateTime::currentMSecsSinceEpoch() / 1000));
QJsonDocument document;
document.setObject(JparamsObject);
QByteArray JparamsObjectarray = document.toJson(QJsonDocument::Compact);
QJsonObject JdataObject;
JdataObject.insert("method", _module_data->remote_chair_control_message + _module_data->chair_sn);
JdataObject.insert("params", JparamsObjectarray.data());
document.setObject(JdataObject);
QByteArray dataarray = "1@" + document.toJson(QJsonDocument::Compact);
return dataarray;
}
#pragma once
#include <QObject>
#include "udp_thread.h"
#include "module_data.h"
#include "gzy_module.h"
#include "moza_module.h"
#include "feishi_module.h"
#include "bulldozer_module.h"
class control_module : public QObject
{
......@@ -18,15 +12,14 @@ public:
explicit control_module(QObject* parent = nullptr);
~control_module();
private:
//单例类
std::shared_ptr<module_data> _module_data = nullptr;
QByteArray bulldozer_generate_realtime_control_message();
moza_module* _moza_module = nullptr;
gzy_module* _gzy_module = nullptr;
feishi_module* _feishi_module = nullptr;
bulldozer_module* _bulldozer_module = nullptr;
public slots:
void no_udp_received_data(const QByteArray& data);
private slots:
void on_send_cmd_timer();
private:
udp_thread* _udp_thread = nullptr;
joy_thread* _joy_thread = nullptr;
std::shared_ptr<module_data> _module_data = nullptr;
};
#include "gzy_module.h"
#include "gzy_module.h"
#include "global_signal.h"
#include <QTimer>
#include <QTime>
gzy_module::gzy_module(QObject *parent)
gzy_module::gzy_module(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
_module_data = module_data::instance();//全局数据中转
QTimer* epb_timer = new QTimer(this);
connect(epb_timer, &QTimer::timeout, this, &gzy_module::analyze_seat_epb);
......@@ -19,7 +19,7 @@ gzy_module::~gzy_module()
}
void gzy_module::analyze_seat_axis(int axis, double value)
void gzy_module::analyze_seat_axis(int joyIndex, int axis, double value)
{
if (axis == 0) {
//_module_data->steering = -(value * 100) - _module_data->set_steering_val;
......@@ -46,84 +46,84 @@ void gzy_module::analyze_seat_axis(int axis, double value)
}
void gzy_module::analyze_seat_button(int button, bool pressed)
void gzy_module::analyze_seat_button(int joyIndex, 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", "电");
global_signal::instance()->record_info_logger("cmd", "下电");
}
else {
global_signal::instance()->record_info_logger("cmd", "电");
global_signal::instance()->record_info_logger("cmd", "上电");
}
}
else if (button == 2) {
if (pressed) {
_module_data->target_left_light = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("左转灯开"));
_module_data->target_left_light = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("左转灯开"));
}
else {
_module_data->target_left_light = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("左转灯关"));
_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("右转灯开"));
_module_data->target_right_light = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("右转灯开"));
}
else {
_module_data->target_right_light = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("右转灯关"));
_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("光灯开"));
_module_data->target_low_beam = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("近光灯开"));
}
else {
_module_data->target_low_beam = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("光灯关"));
_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("远光灯开"));
_module_data->target_high_beam = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("远光灯开"));
}
else {
_module_data->target_high_beam = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("远光灯关"));
_module_data->target_high_beam = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("远光灯关"));
}
}
else if (button == 6) {
if (pressed) {
global_signal::instance()->record_info_logger("cmd", "全带开");
global_signal::instance()->record_info_logger("cmd", "安全带开");
}
else {
global_signal::instance()->record_info_logger("cmd", "全带关");
global_signal::instance()->record_info_logger("cmd", "安全带关");
}
}
else if (button == 7) {
if (pressed) {
global_signal::instance()->record_info_logger("cmd", "宽开");
global_signal::instance()->record_info_logger("cmd", "示宽开");
}
else {
global_signal::instance()->record_info_logger("cmd", "宽关");
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 档"));
_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 档"));
_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 档"));
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 档"));
_module_data->target_gear = 2; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 N 档"));
}
}
......@@ -133,18 +133,18 @@ void gzy_module::analyze_seat_button(int button, bool pressed)
}
else if (button == 16) {
if (pressed) {
_module_data->target_emergency_stop = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("停关"));
_module_data->target_emergency_stop = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("急停关"));
}
else {
_module_data->target_emergency_stop = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("停开"));
_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("叭开"));
_module_data->target_horn = 1; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("喇叭开"));
}
else {
_module_data->target_horn = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("叭关"));
_module_data->target_horn = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("喇叭关"));
}
}
}
......@@ -165,10 +165,10 @@ void gzy_module::analyze_seat_epb()
{
if (handbrake)
{
_module_data->target_gear = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 P 档"));
_module_data->target_gear = 0; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 P 档"));
}
else {
_module_data->target_gear = 2; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 N 档"));
_module_data->target_gear = 2; global_signal::instance()->PublishMsgToWinodw(QStringLiteral("档位切换到 N 档"));
}
time = 0;
handbraketim = 0;
......
#pragma once
#pragma once
#include <QObject>
#include "module_data.h"
class gzy_module : public QObject
class gzy_module : public QObject
{
Q_OBJECT
......@@ -12,13 +12,13 @@ public:
~gzy_module();
public slots:
void analyze_seat_axis(int axis, double value);
void analyze_seat_button(int button, bool pressed);
void analyze_seat_axis(int joyIndex, int axis, double value);
void analyze_seat_button(int joyIndex, int button, bool pressed);
private slots:
void analyze_seat_epb();
private:
//
//单例类
std::shared_ptr<module_data> _module_data = nullptr;
bool handbrakesta = false;
......
......@@ -4,6 +4,7 @@
joy_thread::joy_thread(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
QFuture<void> future = QtConcurrent::run(this, &joy_thread::call_hardware_data);
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("开启 joy_thread ."));
}
......@@ -33,13 +34,101 @@ void joy_thread::call_hardware_data()
}
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("已经连接到座椅 %1.").arg(joyIndex));
detection[joyIndex] = true;
}
else {
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("没有检测到座椅 %1.").arg(joyIndex));
}
}
_module_data->joy_enable = true;
while (_module_data->joy_enable) {
for (int joyIndex = 0; joyIndex < joyCount; ++joyIndex) {
if (!detection[joyIndex]) {
continue;
}
while (true) {
sf::Joystick::update();
int buttonCount = sf::Joystick::getButtonCount(joyIndex);
if (buttonCount != previousButtonCount[joyIndex]) {
previousButtonCount[joyIndex] = buttonCount;
}
if (axisCount[joyIndex] != previousAxisCount[joyIndex]) {
previousAxisCount[joyIndex] = axisCount[joyIndex];
}
for (int button = 0; button < buttonCount; ++button) {
if (button < sf::Joystick::getButtonCount(joyIndex)) {
bool state = sf::Joystick::isButtonPressed(joyIndex, button);
if (state != previousButtonStates[joyIndex][button]) {
previousButtonStates[joyIndex][button] = state;
emit joy_received_button(joyIndex, button, state);
global_signal::instance()->record_debug_logger("joyIndex: " + QString::number(joyIndex) + " button: " + QString::number(button, 10) + " " + QString::number(state, 10));
}
}
}
for (int axis = 0; axis < axisCount[joyIndex]; ++axis) {
if (sf::Joystick::hasAxis(joyIndex, static_cast<sf::Joystick::Axis>(axis))) {
double position = sf::Joystick::getAxisPosition(joyIndex, static_cast<sf::Joystick::Axis>(axis));
emit joy_received_axis(joyIndex, axis, position);
global_signal::instance()->PublishMsgToWinodw("joyIndex: " + QString::number(joyIndex) + " axis: " + QString::number(axis, 10) + " " + QString::number(position, 'f'));
}
}
}
QThread::msleep(20);
}
}
/*#include "joy_thread.h" 可以获取唯一标识符
#include "global_signal.h"
joy_thread::joy_thread(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
QFuture<void> future = QtConcurrent::run(this, &joy_thread::call_hardware_data);
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("开启 joy_thread ."));
}
joy_thread::~joy_thread()
{
}
void joy_thread::call_hardware_data()
{
const int joyCount = sf::Joystick::Count;
bool detection[joyCount] = { false };
int axisCount[joyCount] = { 0 };
int previousButtonCount[joyCount] = { 0 };
int previousAxisCount[joyCount] = { 0 };
bool previousButtonStates[joyCount][sf::Joystick::ButtonCount] = { false };
std::string joystickGuids[joyCount];
for (int joyIndex = 0; joyIndex < joyCount; ++joyIndex) {
sf::Joystick::update();
if (sf::Joystick::isConnected(joyIndex)) {
sf::Joystick::getButtonCount(joyIndex);
axisCount[joyIndex] = 0;
while (sf::Joystick::hasAxis(joyIndex, static_cast<sf::Joystick::Axis>(axisCount[joyIndex]))) {
axisCount[joyIndex]++;
}
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("已经连接到座椅 %1.").arg(joyIndex));
detection[joyIndex] = true;
// 获取手柄的唯一标识符(GUID)
joystickGuids[joyIndex] = sf::Joystick::getGuid(joyIndex);
}
else {
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("没有检测到座椅 %1.").arg(joyIndex));
}
}
_module_data->joy_enable = true;
while (_module_data->joy_enable) {
for (int joyIndex = 0; joyIndex < joyCount; ++joyIndex) {
if (!detection[joyIndex]) {
continue;
......@@ -62,8 +151,8 @@ void joy_thread::call_hardware_data()
bool state = sf::Joystick::isButtonPressed(joyIndex, button);
if (state != previousButtonStates[joyIndex][button]) {
previousButtonStates[joyIndex][button] = state;
emit joy_received_button(button, state);
//global_signal::instance()->record_debug_logger("joyIndex: " + QString::number(joyIndex) + " button: " + QString::number(button, 10) + " " + QString::number(state, 10));
emit joy_received_button(joyIndex, button, state);
global_signal::instance()->record_debug_logger("joyIndex: " + QString::number(joyIndex) + " button: " + QString::number(button, 10) + " " + QString::number(state, 10));
}
}
}
......@@ -71,14 +160,102 @@ void joy_thread::call_hardware_data()
for (int axis = 0; axis < axisCount[joyIndex]; ++axis) {
if (sf::Joystick::hasAxis(joyIndex, static_cast<sf::Joystick::Axis>(axis))) {
double position = sf::Joystick::getAxisPosition(joyIndex, static_cast<sf::Joystick::Axis>(axis));
emit joy_received_axis(axis, position);
//global_signal::instance()->PublishMsgToWinodw("joyIndex: " + QString::number(joyIndex) + " axis: " + QString::number(axis, 10) + " " + QString::number(position, 'f'));
emit joy_received_axis(joyIndex, axis, position);
global_signal::instance()->PublishMsgToWinodw("joyIndex: " + QString::number(joyIndex) + " axis: " + QString::number(axis, 10) + " " + QString::number(position, 'f'));
}
}
// 打印手柄的唯一标识符(GUID)
global_signal::instance()->PublishMsgToWinodw("joyIndex: " + QString::number(joyIndex) + " GUID: " + QString::fromStdString(joystickGuids[joyIndex]));
}
QThread::msleep(20);
}
}
*/
/*#include "joy_thread.h"
#include "global_signal.h"
joy_thread::joy_thread(QObject* parent)
: QObject(parent)
{
QFuture<void> future = QtConcurrent::run(this, &joy_thread::call_hardware_data);
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("开启 joy_thread ."));
}
joy_thread::~joy_thread()
{
}
void joy_thread::call_hardware_data()
{
const int joyCount = sf::Joystick::Count;
bool detection[joyCount] = { false };
int axisCount[joyCount] = { 0 };
int previousButtonCount[joyCount] = { 0 };
int previousAxisCount[joyCount] = { 0 };
bool previousButtonStates[joyCount][sf::Joystick::ButtonCount] = { false };
while (true) {
for (int joyIndex = 0; joyIndex < joyCount; ++joyIndex) {
sf::Joystick::update();
if (sf::Joystick::isConnected(joyIndex)) {
if (!detection[joyIndex]) {
sf::Joystick::getButtonCount(joyIndex);
axisCount[joyIndex] = 0;
while (sf::Joystick::hasAxis(joyIndex, static_cast<sf::Joystick::Axis>(axisCount[joyIndex]))) {
axisCount[joyIndex]++;
}
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("已经连接到座椅 %1.").arg(joyIndex));
detection[joyIndex] = true;
}
int buttonCount = sf::Joystick::getButtonCount(joyIndex);
if (buttonCount != previousButtonCount[joyIndex]) {
previousButtonCount[joyIndex] = buttonCount;
}
if (axisCount[joyIndex] != previousAxisCount[joyIndex]) {
previousAxisCount[joyIndex] = axisCount[joyIndex];
}
for (int button = 0; button < buttonCount; ++button) {
if (button < sf::Joystick::getButtonCount(joyIndex)) {
bool state = sf::Joystick::isButtonPressed(joyIndex, button);
if (state != previousButtonStates[joyIndex][button]) {
previousButtonStates[joyIndex][button] = state;
emit joy_received_button(button, state);
global_signal::instance()->record_debug_logger("joyIndex: " + QString::number(joyIndex) + " button: " + QString::number(button, 10) + " " + QString::number(state, 10));
}
}
}
for (int axis = 0; axis < axisCount[joyIndex]; ++axis) {
if (sf::Joystick::hasAxis(joyIndex, static_cast<sf::Joystick::Axis>(axis))) {
double position = sf::Joystick::getAxisPosition(joyIndex, static_cast<sf::Joystick::Axis>(axis));
emit joy_received_axis(axis, position);
global_signal::instance()->PublishMsgToWinodw("joyIndex: " + QString::number(joyIndex) + " axis: " + QString::number(axis, 10) + " " + QString::number(position, 'f'));
}
}
}
else {
if (detection[joyIndex]) {
global_signal::instance()->PublishMsgToWinodw(QStringLiteral("座椅 %1 已断开连接.").arg(joyIndex));
detection[joyIndex] = false;
// 处理设备断开连接的情况,例如重置相关变量或发出信号通知其他模块
// 例如:
// emit joy_disconnected(joyIndex);
// reset_variables(joyIndex);
}
}
}
QThread::msleep(20);
}
}
*/
/*
#include "joy_thread.h"
......
#pragma once
#pragma once
#include <QtCore>
#include <SFML/Window.hpp>
......@@ -6,6 +6,7 @@
#include <QObject>
#include <QFuture>
#include <QtConcurrent>
#include "module_data.h"
class joy_thread : public QObject
{
......@@ -18,10 +19,10 @@ protected:
void call_hardware_data();
signals:
void joy_received_button(int button, bool pressed);
void joy_received_axis(int axis, double value);
void joy_received_button(int joyIndex, int button, bool pressed);
void joy_received_axis(int joyIndex, int axis, double value);
private:
std::shared_ptr<module_data> _module_data = nullptr;
};
\ No newline at end of file
......@@ -2,11 +2,9 @@
#include <QtWidgets/QApplication>
#include <QTextCodec>
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
chair_code w;
w.show();
return a.exec();
......
......@@ -56,6 +56,7 @@ public:
QString current_chair_device_sn = "";//当前座椅的sn
QString current_chair_device_name = "";//当前座椅的name
qint64 current_chair_device_id = 0;//当前座椅的id
//铲控制数据
int work_state = 0;//工作状态: 0其他 1装载中 2空闲
int emrg_stop = 0;//急停:0关闭 1开启
......@@ -129,6 +130,27 @@ public:
//double network_latency = 0.0;//数据延迟
int target_drywetroad_state = 0;//增加干湿路 0默认常态干路,1湿路
// 推土机控制指令
int target_bulldozer_forward_backward = 0; // 前进后退
int target_bulldozer_forward = 0; // 推土机前进指令
int target_bulldozer_backward = 0; // 推土机后退指令
int target_bulldozer_left_right = 0; //左转右转
int target_bulldozer_left = 0; // 推土机左转指令
int target_bulldozer_right = 0; // 推土机右转指令
int target_bulldozer_rise_gear = 0; // 推土机升档位指令
int target_bulldozer_fall_gear = 0; // 推土机降档位指令
int target_bulldozer_throttle = 0; // 推土机油门指令
int target_bulldozer_lift_lower = 0;//升降铲
int target_bulldozer_lift = 0; // 推土机提铲指令
int target_bulldozer_lower = 0; // 推土机降铲指令
int target_bulldozer_tilt_left_right = 0; //左右倾斜
int target_bulldozer_tilt_left = 0; // 推土机左倾斜指令
int target_bulldozer_tilt_right = 0; // 推土机右倾斜指令
int target_bulldozer_engine_speed = 0; // 推土机发动机调速指令
int target_bulldozer_unlock = 0; // 推土机解锁指令
int target_bulldozer_mode_switch = 0; // 推土机模式切换指令
int target_bulldozer_horn = 0; // 推土机喇叭指令
int target_bulldozer_light = 0; // 推土机灯光指令
//程序中转数据 QString all_canbind_device_json = "";
......@@ -178,7 +200,7 @@ public:
bool mqtt_enable_cert = false;//使能 mqtt ssl
bool grpc_enable_cert = false;//使能 grpc ssl
bool publish_control_sign = false;//使能下发控制数据
bool joy_enable = false;//开启joy使能
private:
......
......@@ -15,7 +15,7 @@ moza_module::~moza_module()
}
void moza_module::analyze_seat_axis(int axis, double value)
void moza_module::analyze_seat_axis(int joyIndex, int axis, double value)
{
double is_value = 0;
if (axis == 0) {
......@@ -44,7 +44,7 @@ void moza_module::analyze_seat_axis(int axis, double value)
}
}
void moza_module::analyze_seat_button(int button, bool pressed)
void moza_module::analyze_seat_button(int joyIndex, int button, bool pressed)
{
switch (button)
{
......
......@@ -12,8 +12,8 @@ public:
~moza_module();
public slots:
void analyze_seat_axis(int axis, double value);
void analyze_seat_button(int button, bool pressed);
void analyze_seat_axis(int joyIndex, int axis, double value);
void analyze_seat_button(int joyIndex, int button, bool pressed);
private:
//单例类
......
......@@ -48,3 +48,4 @@ network_module::~network_module()
{
}
#include "remote_module.h"
remote_module::remote_module(QObject* parent)
: QObject(parent)
{
_module_data = module_data::instance();//全局数据中转
if (_module_data->chair_name == "moza") {
_moza_module = new moza_module();//实例moza 解析类
}
else if (_module_data->chair_name == "feishi") {
_feishi_module = new feishi_module(_module_data->hardware_host, _module_data->hardware_to_chair_port);
}
else if (_module_data->chair_name == "gzy") {//湖州的白色座椅
_gzy_module = new gzy_module();//实例moza 解析类
//_joy_thread = new joy_thread();//实例读座椅数据 解析类
//connect(_joy_thread, &joy_thread::joy_received_button, _gzy_module, &gzy_module::analyze_seat_button);
//connect(_joy_thread, &joy_thread::joy_received_axis, _gzy_module, &gzy_module::analyze_seat_axis);
}
else if (_module_data->chair_name == "bulldozer") {//临时兼容推土机ID3
_bulldozer_module = new bulldozer_module("", _module_data->hardware_to_chair_port);
}
//_udp_thread = new udp_thread(_module_data->chair_host, _module_data->chair_to_device_port, "car");
//_udp_thread->udp_write_date("qwertyuiop", "192.168.1.3", 23456);
//_joy_thread = new joy_thread();
}
remote_module::~remote_module()
{
}
#pragma once
#include <QObject>
#include "module_data.h"
#include "gzy_module.h"
#include "moza_module.h"
#include "feishi_module.h"
#include "bulldozer_module.h"
class remote_module : public QObject
{
Q_OBJECT
public:
explicit remote_module(QObject* parent = nullptr);
~remote_module();
private:
//单例类
std::shared_ptr<module_data> _module_data = nullptr;
moza_module* _moza_module = nullptr;
gzy_module* _gzy_module = nullptr;
feishi_module* _feishi_module = nullptr;
bulldozer_module* _bulldozer_module = nullptr;
};
[2023-12-05 09:50:56.148] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 09:50:56.423] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 09:56:59.869] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 09:57:00.138] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 10:19:37.927] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 10:19:38.309] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 10:43:45.061] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 10:43:45.377] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 10:45:35.013] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 10:45:35.321] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 10:49:25.799] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 10:49:26.084] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 11:09:53.178] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 11:09:53.529] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 11:28:22.955] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 11:28:23.244] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 11:31:17.616] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 11:31:17.901] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 12:09:44.357] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 12:09:44.649] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 12:11:31.603] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 12:11:31.915] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 12:54:44.315] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 12:54:44.608] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 12:58:59.253] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 12:58:59.541] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 13:01:01.368] [logger4] [debug] [bulldozer]:_udp_socket port:18855
[2023-12-05 13:01:01.648] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:00:47.073] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:08:44.662] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:12:21.124] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:13:53.030] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:16:00.430] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:17:06.596] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-05 14:20:20.202] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 09:55:50.197] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 09:57:09.388] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:37:01.358] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:38:05.831] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:50:25.255] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:51:01.739] [logger4] [debug] [control_module]:_udp_socket port:8805
[2023-12-06 16:51:02.030] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:51:56.460] [logger4] [debug] [control_module]:_udp_socket port:8805
[2023-12-06 16:51:56.753] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:52:58.505] [logger4] [debug] [control_module]:_udp_socket port:8805
[2023-12-06 16:52:58.794] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-06 16:55:54.734] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-06 16:55:55.032] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-07 13:48:24.992] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-07 13:48:25.242] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-07 17:38:24.877] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-07 17:38:25.694] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 10:13:33.374] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-08 10:13:33.792] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 15:29:31.178] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-08 15:29:32.134] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 15:33:43.237] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-08 15:33:44.096] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 15:40:58.568] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-08 15:40:58.984] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 15:46:20.449] [logger4] [debug] [control_module]:_udp_socket port:8801
[2023-12-08 15:46:20.787] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 17:39:28.805] [logger4] [debug] [control_module]:_udp_socket port:8805
[2023-12-08 17:39:29.150] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
[2023-12-08 17:57:03.573] [logger4] [debug] [control_module]:_udp_socket port:8805
[2023-12-08 17:57:03.913] [logger4] [debug] Invalid IP address: 192.168.9.111:50052
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论