Browse Source

add a new project for dianziweilan....

Gogs 4 years ago
parent
commit
bd97cb62af

+ 1 - 0
src/tool/tool_electronic_fence/README.md

@@ -0,0 +1 @@
+本工程基于靶车项目电子栅栏功能而设计

+ 5 - 0
src/tool/tool_electronic_fence/adc_icon.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>gps.png</file>
+    </qresource>
+</RCC>

BIN
src/tool/tool_electronic_fence/gps.png


+ 12 - 0
src/tool/tool_electronic_fence/main.cpp

@@ -0,0 +1,12 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+
+    MainWindow w;
+    w.show();
+
+    return a.exec();
+}

+ 115 - 0
src/tool/tool_electronic_fence/mainwindow.cpp

@@ -0,0 +1,115 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include <QMessageBox>
+#include <iostream>
+#include "gpsimu.pb.h"
+
+static MainWindow::GPS_INS gps_data_set,gps_data_car;
+static double set_R;
+
+void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    iv::gps::gpsimu xgpsimu;
+    if(!xgpsimu.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"Listengpsimu Parse error."<<std::endl;
+    }
+    gps_data_car.gps_lng = xgpsimu.lon();
+    gps_data_car.gps_lat = xgpsimu.lat();
+}
+
+
+
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    //使用正则表达式限制只能输入数字
+    QRegExp rx("[0-9\.]+$");
+    QRegExpValidator *validator = new QRegExpValidator(rx, this);
+    ui->lineEdit->setValidator(validator);
+    ui->lineEdit_2->setValidator(validator);
+    ui->lineEdit_3->setValidator(validator);
+    ui->lineEdit_4->setText("");
+    ui->lineEdit_5->setText("");
+    ui->lineEdit_6->setText("");
+    ui->textEdit->setText("");
+
+    void * paraw = iv::modulecomm::RegisterRecv("hcp2_gpsimu",Listengpsimu);
+
+    setWindowTitle("电子栅栏测试工具");
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+
+double MainWindow::GetDistance(GPS_INS p1, GPS_INS p2)
+{
+    return sqrt((p1.gps_x - p2.gps_x) * (p1.gps_x - p2.gps_x) + (p1.gps_y - p2.gps_y) * (p1.gps_y - p2.gps_y));
+}
+
+
+void MainWindow::on_pushButton_clicked()
+{
+    const double Set_Jingdu = ui->lineEdit->text().toDouble();
+    const double Set_Weidu  = ui->lineEdit_2->text().toDouble();
+    const double Set_R      = ui->lineEdit_3->text().toDouble();
+
+
+    if(Set_Jingdu < 0.0 || Set_Jingdu > 180.0 || ui->lineEdit->text().isEmpty())
+    {
+        QMessageBox message(QMessageBox::NoIcon, "注意", "经度范围0~180且不为空.");
+        message.setIconPixmap(QPixmap(":/gps.png"));
+        message.exec();
+        return;
+    }
+    if(Set_Weidu < 0.0 || Set_Weidu > 90.0 || ui->lineEdit_2->text().isEmpty())
+    {
+        QMessageBox message(QMessageBox::NoIcon, "注意", "纬度范围0~90且不为空.");
+        message.setIconPixmap(QPixmap(":/gps.png"));
+        message.exec();
+        return;
+    }
+    if(Set_R < 0.0 || ui->lineEdit_3->text().isEmpty())
+    {
+        QMessageBox message(QMessageBox::NoIcon, "注意", "R范围>0且不为空.");
+        message.setIconPixmap(QPixmap(":/gps.png"));
+        message.exec();
+        return;
+    }
+
+    gps_data_set.gps_lat = Set_Weidu;
+    gps_data_set.gps_lng = Set_Jingdu;
+    set_R = Set_R;
+
+    QTimer * timer = new QTimer(this);
+    connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    timer->start(100);
+
+}
+
+void MainWindow::onTimer()
+{
+    ui->lineEdit_4->setText(QString::number(gps_data_car.gps_lng, 'g', 12));
+    ui->lineEdit_5->setText(QString::number(gps_data_car.gps_lat, 'g', 12));
+    GaussProjCal(gps_data_set.gps_lng, gps_data_set.gps_lat, &gps_data_set.gps_x, &gps_data_set.gps_y);
+    GaussProjCal(gps_data_car.gps_lng, gps_data_car.gps_lat, &gps_data_car.gps_x, &gps_data_car.gps_y);
+    double distance = GetDistance(gps_data_set,gps_data_car);
+    ui->lineEdit_6->setText(QString::number(distance, 'g', 12));
+
+    std::cout<<set_R<<std::endl;
+    std::cout<<distance<<std::endl;
+
+    if(distance < set_R)
+        ui->textEdit->setPlainText("车辆中心点在电子栅栏以内");
+    if(distance == set_R)
+        ui->textEdit->setPlainText("车辆中心点在电子栅栏之上");
+    if(distance > set_R)
+        ui->textEdit->setPlainText("车辆中心点在电子栅栏以外");
+}

+ 77 - 0
src/tool/tool_electronic_fence/mainwindow.h

@@ -0,0 +1,77 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <math.h>
+#include "modulecomm.h"
+#include <QTimer>
+
+#define M_PI (3.1415926535897932384626433832795)
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+    struct GPS_INS
+    {
+        double gps_lat = 0;//纬度
+        double gps_lng = 0;//经度
+        double gps_x = 0;
+        double gps_y = 0;
+    };
+
+    double GetDistance(GPS_INS p1, GPS_INS p2);
+
+    //高斯投影由经纬度(Unit:DD)反算大地坐标(含带号,Unit:Metres)
+    void GaussProjCal(double longitude, double latitude, double *X, double *Y)
+    {
+        int ProjNo = 0; int ZoneWide; ////带宽
+        double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
+        double a, f, e2, ee, NN, T, C, A, M, iPI;
+        iPI = 0.0174532925199433; ////3.1415926535898/180.0;
+        ZoneWide = 6; ////6度带宽
+        a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
+                                        ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
+        ProjNo = (int)(longitude / ZoneWide);
+        longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
+        longitude0 = longitude0 * iPI;
+        latitude0 = 0;
+        longitude1 = longitude * iPI; //经度转换为弧度
+        latitude1 = latitude * iPI; //纬度转换为弧度
+        e2 = 2 * f - f * f;
+        ee = e2 * (1.0 - e2);
+        NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
+        T = tan(latitude1)*tan(latitude1);
+        C = ee * cos(latitude1)*cos(latitude1);
+        A = (longitude1 - longitude0)*cos(latitude1);
+        M = a * ((1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256)*latitude1 - (3 * e2 / 8 + 3 * e2*e2 / 32 + 45 * e2*e2
+            *e2 / 1024)*sin(2 * latitude1)
+            + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) - (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
+        xval = NN * (A + (1 - T + C)*A*A*A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * ee)*A*A*A*A*A / 120);
+        yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
+            + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
+        X0 = 1000000L * (ProjNo + 1) + 500000L;
+        Y0 = 0;
+        xval = xval + X0; yval = yval + Y0;
+        *X = xval;
+        *Y = yval;
+    }
+
+private slots:
+    void on_pushButton_clicked();
+    void onTimer();
+
+private:
+    Ui::MainWindow *ui;
+
+};
+
+#endif // MAINWINDOW_H

+ 241 - 0
src/tool/tool_electronic_fence/mainwindow.ui

@@ -0,0 +1,241 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>757</width>
+    <height>330</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>40</y>
+      <width>241</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>请输入设定的圆心经纬度及R:</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>80</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>圆心经度</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_3">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>110</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>圆心纬度</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit">
+    <property name="geometry">
+     <rect>
+      <x>110</x>
+      <y>80</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_2">
+    <property name="geometry">
+     <rect>
+      <x>110</x>
+      <y>110</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_4">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>140</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>R(m)</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_3">
+    <property name="geometry">
+     <rect>
+      <x>110</x>
+      <y>140</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_5">
+    <property name="geometry">
+     <rect>
+      <x>460</x>
+      <y>40</y>
+      <width>201</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>车辆中心点当前经纬度位置:</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="pushButton">
+    <property name="geometry">
+     <rect>
+      <x>110</x>
+      <y>180</y>
+      <width>89</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Set</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_6">
+    <property name="geometry">
+     <rect>
+      <x>460</x>
+      <y>80</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>车辆经度</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_4">
+    <property name="geometry">
+     <rect>
+      <x>550</x>
+      <y>80</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_7">
+    <property name="geometry">
+     <rect>
+      <x>460</x>
+      <y>110</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>车辆纬度</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_5">
+    <property name="geometry">
+     <rect>
+      <x>550</x>
+      <y>110</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_8">
+    <property name="geometry">
+     <rect>
+      <x>460</x>
+      <y>140</y>
+      <width>81</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>到边界距离</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_6">
+    <property name="geometry">
+     <rect>
+      <x>550</x>
+      <y>140</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_9">
+    <property name="geometry">
+     <rect>
+      <x>350</x>
+      <y>210</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>车辆状态</string>
+    </property>
+   </widget>
+   <widget class="QTextEdit" name="textEdit">
+    <property name="geometry">
+     <rect>
+      <x>440</x>
+      <y>200</y>
+      <width>241</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>757</width>
+     <height>22</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

+ 50 - 0
src/tool/tool_electronic_fence/tool_electronic_fence.pro

@@ -0,0 +1,50 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2021-03-08T13:37:16
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = tool_electronic_fence
+TEMPLATE = app
+QMAKE_CXXFLAGS +=  -g
+CONFIG += c++11
+QMAKE_LFLAGS += -no-pie
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+INCLUDEPATH += $$PWD/../../../include/
+INCLUDEPATH += $$PWD/../../include/msgtype/
+LIBS += -L$$PWD/../../../bin/ -lxmlparam -lmodulecomm  -livlog -livfault -livexit -livbacktrace
+LIBS += -lboost_system  -lbacktrace -ldl -lprotobuf
+
+
+SOURCES += \
+        main.cpp \
+        mainwindow.cpp \
+        ../../include/msgtype/gpsimu.pb.cc
+
+HEADERS += \
+        mainwindow.h \
+        ../../include/msgtype/gpsimu.pb.h
+
+FORMS += \
+        mainwindow.ui
+
+DISTFILES += \
+    README.md
+
+RESOURCES += \
+    adc_icon.qrc