学习笔记(工作时写的测试工具,20220228,IMDS250数据落地(自用))

GUI部分,IMDS250_gui

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled-IMDS250GUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore,QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(928, 449)
        MainWindow.setMinimumSize(QtCore.QSize(450, 300))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setStyleSheet("background-color: rgb(255, 255, 255);\n"
"border-color: rgb(55, 145, 241);")
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label_zbdz = QtWidgets.QLabel(self.centralwidget)
        self.label_zbdz.setObjectName("label_zbdz")
        self.horizontalLayout.addWidget(self.label_zbdz)
        self.lineEdit_zbdz = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_zbdz.setMinimumSize(QtCore.QSize(100, 20))
        self.lineEdit_zbdz.setMaximumSize(QtCore.QSize(100, 20))
        self.lineEdit_zbdz.setObjectName("lineEdit_zbdz")
        self.horizontalLayout.addWidget(self.lineEdit_zbdz)
        self.label_fsIP = QtWidgets.QLabel(self.centralwidget)
        self.label_fsIP.setObjectName("label_fsIP")
        self.horizontalLayout.addWidget(self.label_fsIP)
        self.lineEdit_IP = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_IP.setMinimumSize(QtCore.QSize(100, 20))
        self.lineEdit_IP.setMaximumSize(QtCore.QSize(100, 20))
        self.lineEdit_IP.setObjectName("lineEdit_IP")
        self.horizontalLayout.addWidget(self.lineEdit_IP)
        self.pushButton_kais = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_kais.setMinimumSize(QtCore.QSize(50, 20))
        self.pushButton_kais.setMaximumSize(QtCore.QSize(50, 20))
        self.pushButton_kais.setObjectName("pushButton_kais")
        self.horizontalLayout.addWidget(self.pushButton_kais)
        self.pushButton_qinchu = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_qinchu.setMinimumSize(QtCore.QSize(50, 20))
        self.pushButton_qinchu.setMaximumSize(QtCore.QSize(50, 20))
        self.pushButton_qinchu.setObjectName("pushButton_qinchu")
        self.horizontalLayout.addWidget(self.pushButton_qinchu)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget.setObjectName("tabWidget")
        self.tab_tz = QtWidgets.QWidget()
        self.tab_tz.setObjectName("tab_tz")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.tab_tz)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.tableView_BIDS_tz = QtWidgets.QTableView(self.tab_tz)
        self.tableView_BIDS_tz.setObjectName("tableView_BIDS_tz")
        self.gridLayout_2.addWidget(self.tableView_BIDS_tz, 0, 0, 1, 1)
        self.tableView_WNDS_tz = QtWidgets.QTableView(self.tab_tz)
        self.tableView_WNDS_tz.setObjectName("tableView_WNDS_tz")
        self.gridLayout_2.addWidget(self.tableView_WNDS_tz, 1, 0, 1, 1)
        self.tabWidget.addTab(self.tab_tz, "")
        self.tab_bj = QtWidgets.QWidget()
        self.tab_bj.setObjectName("tab_bj")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.tab_bj)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.tableView_BIDS_bj = QtWidgets.QTableView(self.tab_bj)
        self.tableView_BIDS_bj.setObjectName("tableView_BIDS_bj")
        self.gridLayout_3.addWidget(self.tableView_BIDS_bj, 0, 0, 1, 1)
        self.tableView_WNDS_bj = QtWidgets.QTableView(self.tab_bj)
        self.tableView_WNDS_bj.setObjectName("tableView_WNDS_bj")
        self.gridLayout_3.addWidget(self.tableView_WNDS_bj, 1, 0, 1, 1)
        self.tabWidget.addTab(self.tab_bj, "")
        self.tab_huitu = QtWidgets.QWidget()
        self.tab_huitu.setObjectName("tab_huitu")
        self.gridLayout_4 = QtWidgets.QGridLayout(self.tab_huitu)
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.groupBox_swbj = QtWidgets.QGroupBox(self.tab_huitu)
        self.groupBox_swbj.setObjectName("groupBox_swbj")
        self.gridLayout_4.addWidget(self.groupBox_swbj, 0, 0, 1, 1)
        self.groupBox_pwbj = QtWidgets.QGroupBox(self.tab_huitu)
        self.groupBox_pwbj.setObjectName("groupBox_pwbj")
        self.gridLayout_4.addWidget(self.groupBox_pwbj, 0, 1, 1, 1)
        self.tabWidget.addTab(self.tab_huitu, "")
        self.verticalLayout.addWidget(self.tabWidget)
        self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(1)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "IMDS250_数据落地"))
        self.label_zbdz.setText(_translate("MainWindow", "接收组播"))
        self.lineEdit_zbdz.setText(_translate("MainWindow", "239.255.17.1"))
        self.label_fsIP.setText(_translate("MainWindow", "IP"))
        self.lineEdit_IP.setText(_translate("MainWindow", "10.0.1.170"))
        self.pushButton_kais.setText(_translate("MainWindow", "开始"))
        self.pushButton_qinchu.setText(_translate("MainWindow", "清除"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_tz), _translate("MainWindow", "特征数据"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_bj), _translate("MainWindow", "报警数据"))
        self.groupBox_swbj.setTitle(_translate("MainWindow", "失稳报警数据图"))
        self.groupBox_pwbj.setTitle(_translate("MainWindow", "平稳报警数据图"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_huitu), _translate("MainWindow", "实时绘图"))

 逻辑实现部分,IMDS250_main.py

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled_1.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtGui import *
import socket
import sys
from IMDS250_gui import Ui_MainWindow
from PyQt5.QtWidgets import QApplication, QGridLayout, QMainWindow
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import threading
import queue
#定义画布
class Mydemo(FigureCanvas):
    def __init__(self, parent=None, width=5, height=4, dpi=10):
        plt.rcParams['font.family'] = ['SimHei']
        plt.rcParams['axes.unicode_minus'] = False
        self.fig = Figure(figsize=(width, height), dpi=dpi)
        FigureCanvas.__init__(self, self.fig)
        self.setParent(parent)
        # 设置画布分格子xyz = x*y  第z个分区
        self.axes = self.fig.add_subplot(1, 1, 1)
        # 设置横坐标轴
        # self.axes.set_xlim(0, 5)
        # self.axes.set_ylim(-5, 5)
        # self.axes.set_ylabel('纵坐标标题')
        # self.axes.set_title('标题')


class mainWindow (QMainWindow, Ui_MainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        global MYGROUP
        global fasong
        self.setupUi(self)
        self.tableView_biaotou()
        self.UDP_jies = UDP_jies()
        # 保持滚动条在顶部(默认)scrollToTop();// 保持滚动条在底部scrollToBottom();
        self.tableView_WNDS_tz.scrollToBottom()
        self.tableView_BIDS_bj.scrollToBottom()
        self.tableView_WNDS_bj.scrollToBottom()
        # 根据表头自动适应列宽
        self.tableView_WNDS_tz.resizeColumnsToContents()
        self.tableView_BIDS_tz.resizeColumnsToContents()
        self.tableView_WNDS_bj.resizeColumnsToContents()
        self.tableView_BIDS_bj.resizeColumnsToContents()
        # 按钮按键信号
        self.pushButton_kais.clicked.connect(self.slotAdd)
        self.pushButton_qinchu.clicked.connect(self.qingchu)
        # 赋值全局变量
        MYGROUP = str(self.lineEdit_zbdz.text())
        fasong = str(self.lineEdit_IP.text())
        self.huatu()
    ##-----------------------------------------------------------打印输出事件----------------------------------------------------------
    def call_backlog(self, mgr):
        global BIDS_baoxvhao_jy
        global WNDS_baoxvhao_jy
        if (len(mgr) == 1440):
            mgr = mgr[40:1441]
            # -------------------------------------失稳落地----------------------------------
            if(mgr[0] == 170):
                data_BIDS_tz = []
                BIDS_tz = (self.shujv_toubu_BIDS(mgr[0:22]) + self.shujv_BIDS_tz(mgr[22:50]) + self.shujv_BIDS_tz(mgr[50:78]) +
                     self.shujv_BIDS_tz(mgr[78:106]) + self.shujv_BIDS_tz(mgr[106:134]) + self.shujv_BIDS_tz(mgr[134:162]) +
                     self.shujv_BIDS_tz(mgr[162:190]) + self.shujv_BIDS_tz(mgr[190:218]) + self.shujv_BIDS_tz(mgr[218:246]) +
                     self.shujv_BIDS_tz(mgr[246:274]) + self.shujv_BIDS_tz(mgr[274:302]))  # 数据整合,输出str类型数据
                for a in BIDS_tz:
                    data_BIDS_tz.append(QStandardItem(str(a)))
                self.model_BIDS_tz.appendRow(data_BIDS_tz)
                # 保持滚动条在顶部(默认)scrollToTop();// 保持滚动条在底部scrollToBottom();
                self.tableView_BIDS_tz.scrollToBottom()
                # 根据表头自动适应列宽
                self.tableView_BIDS_tz.resizeColumnsToContents()
                if self.model_BIDS_tz.rowCount() == 50:
                    self.qingchu()
                # ------------------------------------------报警数据------------------------------
                data_BIDS_bj = []
                BIDS_bj = (self.shujv_toubu_bj(mgr[400:424], mgr[1398:1400]))  # 数据整合,输出str类型数据
                for b in BIDS_bj:
                    data_BIDS_bj.append(QStandardItem(str(b)))
                self.model_BIDS_bj.appendRow(data_BIDS_bj)
                self.tableView_BIDS_bj.resizeColumnsToContents()  # 根据表头自动适应列宽
                self.tableView_BIDS_bj.scrollToBottom()
                if self.model_BIDS_bj.rowCount() == 50:  # 自动清除表格
                    self.qingchu()
                #---------------------------------数据存储——————————————————————————————————————————————
                if int(bin(mgr[404])[9:10]) == 1:  # 数据有效位
                    jiaoyan_xvhao = (int((("0x%02x" % (mgr[405]))[2:] + ("0x%02x" % (mgr[406]))[2:]), 16))  # 包序号判断
                    if BIDS_baoxvhao_jy != jiaoyan_xvhao:
                        BIDS_baoxvhao_jy = jiaoyan_xvhao
                        t1 = threading.Thread(target=self.BIDS_bjsv_cchunchu, args=(mgr[404:405],mgr[424:1397],))
                        t1.setDaemon(True)  # 线程守护
                        t1.start()
                if duilie_BIDS.empty() == False:
                    #清空画布
                    self.figure_sw.axes.cla()
                    # 添加标题
                    self.figure_sw.axes.set_ylabel('加速度/g')
                    self.figure_sw.axes.set_title('失稳报警')
                    #添加数据,y轴
                    self.figure_sw.axes.plot(duilie_BIDS.get())
                    #实时渲染画布
                    self.figure_sw.draw()
            #-------------------------------------平稳落地----------------------------------
            elif mgr[0] == 165:
                data_WNDS_tz = []
                WNDS_tz = (self.shujv_toubu_WDNS(mgr[0:22])+ self.shujv_WNDS_tz(mgr[22:54]) + self.shujv_WNDS_tz(mgr[54:86]) +
                     self.shujv_WNDS_tz(mgr[86:118]) + self.shujv_WNDS_tz(mgr[118:150]) + self.shujv_WNDS_tz(mgr[150:182]) +
                     self.shujv_WNDS_tz(mgr[182:214]) + self.shujv_WNDS_tz(mgr[214:246]) + self.shujv_WNDS_tz(mgr[246:278]) +
                     self.shujv_WNDS_tz(mgr[278:310]) + self.shujv_WNDS_tz(mgr[310:342]))

                for x in WNDS_tz:
                    data_WNDS_tz.append(QStandardItem(str(x)))
                self.model_WNDS_tz.appendRow(data_WNDS_tz)
                self.tableView_WNDS_tz.scrollToBottom()
                self.tableView_WNDS_tz.resizeColumnsToContents()
                if self.model_WNDS_tz.rowCount() == 50:
                    self.qingchu()

                # ------------------------------------------报警数据------------------------------
                data_WNDS_bj = []
                WNDS_bj = (self.shujv_toubu_bj(mgr[400:424], mgr[1398:1400]))  # 数据整合,输出str类型数据
                for y in WNDS_bj:
                    data_WNDS_bj.append(QStandardItem(str(y)))
                self.model_WNDS_bj.appendRow(data_WNDS_bj)
                self.tableView_WNDS_bj.resizeColumnsToContents()  # 根据表头自动适应列宽
                self.tableView_WNDS_bj.scrollToBottom()
                if self.model_WNDS_bj.rowCount() == 50:  # 自动清除表格
                    self.qingchu()
                # ---------------------------------数据存储——————————————————————————————————————————————
                if int(bin(mgr[404])[9:10]) == 1:  # 数据有效位
                    jiaoyan_xvhao = (int((("0x%02x" % (mgr[405]))[2:] + ("0x%02x" % (mgr[406]))[2:]), 16))  # 包序号判断
                    if WNDS_baoxvhao_jy != jiaoyan_xvhao:
                        WNDS_baoxvhao_jy = jiaoyan_xvhao
                        t1 = threading.Thread(target=self.WNDS_bjsv_cchunchu, args=(mgr[404:405],mgr[424:1397],))
                        t1.setDaemon(True)  # 线程守护
                        t1.start()
                if duilie_WNDS.empty() == False:
                    # 清空画布
                    self.figure_pw.axes.cla()
                    # 添加标题
                    self.figure_pw.axes.set_ylabel('加速度/g')
                    self.figure_pw.axes.set_title('平稳报警')
                    # 添加数据,y轴
                    self.figure_pw.axes.plot(duilie_WNDS.get())
                    # 实时渲染画布
                    self.figure_pw.draw()


    def Message_type_BIDS(self, data):
        Message_BIDS = {0: "BIDSB_bj_1.txt", 11: "BIDSB_bj_2.txt"}
        return Message_BIDS[data]
    def Message_type_WNDS(self, data):
        Message_WNDS = {0: "WNDS_bj_1横.txt", 1: "WNDS_bj_1垂.txt",10: "WNDS_bj_2横.txt", 11: "WNDS_bj_2垂.txt"}
        return Message_WNDS[data]

    ##-----------------------------------------------------------创建画布----------------------------------------------------------
    def huatu(self):
        # 然后在相应的QGroupBox中添加一个栅格布局
        self.LineFigureLayout_sw = QGridLayout(self.groupBox_swbj)
        self.LineFigureLayout_pw = QGridLayout(self.groupBox_pwbj)
        # 创建画布
        self.figure_sw = Mydemo(width=5, height=4, dpi=100)
        self.figure_pw = Mydemo(width=5, height=4, dpi=100)
        # self.figure_sw.axes.set_xlabel('横坐标标题')
        # self.figure_sw.axes.set_xlabel('横坐标标题')
        self.figure_sw.axes.set_ylabel('加速度/g')
        self.figure_pw.axes.set_ylabel('加速度/g')
        self.figure_sw.axes.set_title('失稳报警')
        self.figure_pw.axes.set_title('平稳报警')
        #添加画板工具框
        self.toobar = NavigationToolbar(self.figure_sw, self)
        self.toobar1 = NavigationToolbar(self.figure_pw, self)
        #链接画板及工具框
        self.LineFigureLayout_sw.addWidget(self.figure_sw)
        self.LineFigureLayout_sw.addWidget(self.toobar)
        self.LineFigureLayout_pw.addWidget(self.figure_pw)
        self.LineFigureLayout_pw.addWidget(self.toobar1)

        # gridlayout.addWidget(self.figure_sw)
        # gridlayout.addWidget(toobar)
        # 然后,将画板添加到布局中
        # self.figure_pw.axes.plot(self.data)


    #————————————————————————————————————————————————抓包控制——————————————————————————————————————
    def kongzhi(self):
        if self.pushButton_kais.text() == "开始":
            return 0
        else:
            return 1
    ##-----------------------------------------------------------按键开始事件----------------------------------------------------------
    def slotAdd(self):
        global kongz
        if self.pushButton_kais.text() == "开始":
            self.pushButton_kais.setText("停止")
            kongz = 1
            # 连接信号
            self.UDP_jies.breakSignal.connect(self.call_backlog)  # 进程连接回传到GUI的事件
            self.UDP_jies.start()
        elif self.pushButton_kais.text() == "停止":
            self.pushButton_kais.setText("开始")
            kongz = 0
            self.UDP_jies.breakSignal.disconnect()  # 解除信号与槽绑定
    # -----------------------------------------------------------表格清除------------------------------------------------------------------
    def qingchu(self):
        # self.zbjs.sleep(2)
        self.model_BIDS_tz.clear()
        self.model_WNDS_tz.clear()
        self.model_BIDS_bj.clear()
        self.model_WNDS_bj.clear()
        self.model_BIDS_tz.setHorizontalHeaderLabels(self.biaotou_BIDS_tz)  # 表头
        self.model_WNDS_tz.setHorizontalHeaderLabels(self.biaotou_WNDS_tz)  # 表头
        self.model_BIDS_bj.setHorizontalHeaderLabels(self.biaotou_BIDS_bj)  # 表头
        self.model_WNDS_bj.setHorizontalHeaderLabels(self.biaotou_WNDS_bj)  # 表头
    # -----------------------------------------------------------表格标题及数据绑定------------------------------------------------------------------
    def tableView_biaotou(self):
        self.model_BIDS_tz = QStandardItemModel(0, 0)
        self.biaotou_BIDS_tz = [" 帧头 ", "报文长度", "包序号", "包总数", "       时    间       ", "编组", "车号", "公里标",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_1-1小", "特征_1-4小", "特征_1-5小", "特征_1-8小", "特征_1-1均", "特征_1-4均", "特征_1-5均", "特征_1-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_2-1小", "特征_2-4小", "特征_2-5小", "特征_2-8小", "特征_2-1均", "特征_2-4均", "特征_2-5均", "特征_2-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_3-1小", "特征_3-4小", "特征_3-5小", "特征_3-8小", "特征_3-1均", "特征_3-4均", "特征_3-5均", "特征_3-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_4-1小", "特征_4-4小", "特征_4-5小", "特征_4-8小", "特征_4-1均", "特征_4-4均", "特征_4-5均", "特征_4-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_5-1小", "特征_5-4小", "特征_5-5小", "特征_5-8小", "特征_5-1均", "特征_5-4均", "特征_5-5均", "特征_5-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_6-1小", "特征_6-4小", "特征_6-5小", "特征_6-8小", "特征_6-1均", "特征_6-4均", "特征_6-5均", "特征_6-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_7-1小", "特征_7-4小", "特征_7-5小", "特征_7-8小", "特征_7-1均", "特征_7-4均", "特征_7-5均", "特征_7-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_8-1小", "特征_8-4小", "特征_8-5小", "特征_8-8小", "特征_8-1均", "特征_8-4均", "特征_8-5均", "特征_8-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_9-1小", "特征_9-4小", "特征_9-5小", "特征_9-8小", "特征_9-1均", "特征_9-4均", "特征_9-5均", "特征_9-8均",
                   " 车速 ", " 经  度 ", " 纬  度 ","特征_10-1小", "特征_10-4小", "特征_10-5小", "特征_10-8小", "特征_10-1均", "特征_10-4均", "特征_10-5均", "特征_10-8均", ]
        self.model_BIDS_tz.setHorizontalHeaderLabels(self.biaotou_BIDS_tz)    #表头
        self.tableView_BIDS_tz.setModel(self.model_BIDS_tz)  #绑定数据

        self.model_WNDS_tz = QStandardItemModel(0, 0)
        self.biaotou_WNDS_tz = [" 帧头 ", "报文长度", "包序号", "包总数", "       时    间       ", "编组", "车号", "公里标",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_1-横向平稳1", "特征_1-横向平稳2", "特征_1-垂向平稳1", "特征_1-垂向平稳2", "特征_1-晃车峰值1", "特征_1-晃车峰值2", "特征_1-横向均方根1", "特征_1-横向均方根2", "特征_1-垂向均方根1", "特征_1-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_2-横向平稳1", "特征_2-横向平稳2", "特征_2-垂向平稳1", "特征_2-垂向平稳2", "特征_2-晃车峰值1", "特征_2-晃车峰值2", "特征_2-横向均方根1", "特征_2-横向均方根2", "特征_2-垂向均方根1", "特征_2-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_3-横向平稳1", "特征_3-横向平稳2", "特征_3-垂向平稳1", "特征_3-垂向平稳2", "特征_3-晃车峰值1", "特征_3-晃车峰值2", "特征_3-横向均方根1", "特征_3-横向均方根2", "特征_3-垂向均方根1", "特征_3-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_5-横向平稳1", "特征_4-横向平稳2", "特征_4-垂向平稳1", "特征_4-垂向平稳2", "特征_4-晃车峰值1", "特征_4-晃车峰值2", "特征_4-横向均方根1", "特征_4-横向均方根2", "特征_4-垂向均方根1", "特征_4-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_5-横向平稳1", "特征_5-横向平稳2", "特征_5-垂向平稳1", "特征_5-垂向平稳2", "特征_5-晃车峰值1", "特征_5-晃车峰值2", "特征_5-横向均方根1", "特征_5-横向均方根2", "特征_5-垂向均方根1", "特征_5-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_6-横向平稳1", "特征_6-横向平稳2", "特征_6-垂向平稳1", "特征_6-垂向平稳2", "特征_6-晃车峰值1", "特征_6-晃车峰值2", "特征_6-横向均方根1", "特征_6-横向均方根2", "特征_6-垂向均方根1", "特征_6-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_7-横向平稳1", "特征_7-横向平稳2", "特征_7-垂向平稳1", "特征_7-垂向平稳2", "特征_7-晃车峰值1", "特征_7-晃车峰值2", "特征_7-横向均方根1", "特征_7-横向均方根2", "特征_7-垂向均方根1", "特征_7-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_8-横向平稳1", "特征_8-横向平稳2", "特征_8-垂向平稳1", "特征_8-垂向平稳2", "特征_8-晃车峰值1", "特征_8-晃车峰值2", "特征_8-横向均方根1", "特征_8-横向均方根2", "特征_8-垂向均方根1", "特征_8-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_9-横向平稳1", "特征_9-横向平稳2", "特征_9-垂向平稳1", "特征_9-垂向平稳2", "特征_9-晃车峰值1", "特征_9-晃车峰值2", "特征_9-横向均方根1", "特征_9-横向均方根2", "特征_9-垂向均方根1", "特征_9-垂向均方根2",
                        " 车速 ", " 经  度 ", " 纬  度 ", "特征_10-横向平稳1", "特征_10-横向平稳2", "特征_10-垂向平稳1", "特征_10-垂向平稳2", "特征_10-晃车峰值1", "特征_10-晃车峰值2", "特征_10-横向均方根1", "特征_10-横向均方根2", "特征_10-垂向均方根1", "特征_10-垂向均方根2",
                                ]
        self.model_WNDS_tz.setHorizontalHeaderLabels(self.biaotou_WNDS_tz)  # 表头
        self.tableView_WNDS_tz.setModel(self.model_WNDS_tz)  # 绑定数据

        self.model_BIDS_bj = QStandardItemModel(0, 0)
        self.biaotou_BIDS_bj =  ["帧头", "报文长度", "数据有效位", "传感器报警位", "包序号", "包总数", "时间", "编组", "车号", "公里标", "速度", "校验和"]
        self.model_BIDS_bj.setHorizontalHeaderLabels(self.biaotou_BIDS_bj)    #表头
        self.tableView_BIDS_bj.setModel(self.model_BIDS_bj)  #绑定数据

        self.model_WNDS_bj = QStandardItemModel(0, 0)
        self.biaotou_WNDS_bj = ["帧头", "报文长度", "数据有效位", "传感器报警位", "包序号", "包总数", "时间", "编组", "车号", "公里标", "速度", "校验和"]
        self.model_WNDS_bj.setHorizontalHeaderLabels(self.biaotou_WNDS_bj)  # 表头
        self.tableView_WNDS_bj.setModel(self.model_WNDS_bj)  # 绑定数据
    ##-----------------------------------------------------------数据转换事件----------------------------------------------------------
    def shujv_toubu_BIDS(self, data):
        schu = [(("0x%02x" % (data[0]))[2:] + ("0x%02x" % (data[1]))[2:])]  # 帧头
        schu.append((int((("0x%02x" % (data[2]))[2:] + ("0x%02x" % (data[3]))[2:]), 16)))  # 报文长度
        schu.append((int((("0x%02x" % (data[5]))[2:] + ("0x%02x" % (data[6]))[2:]), 16)))  # 包序号
        schu.append((int((("0x%02x" % (data[7]))[2:] + ("0x%02x" % (data[8]))[2:]), 16)))  # 包总数
        schu.append(str(data[9]) + "-" + str(data[10]) + "-" +str(data[11]) + "-" + str(data[12]) + ":" +str(data[13]) + ":" + str(data[14]))  # 时间:年月日时分秒
        schu.append(("0x%02x" % (data[15]))[2:3] + ("0x%02x" % (data[15]))[3:4] + ("0x%02x" % (data[16]))[2:3] + ("0x%02x" % (data[16]))[3:4])  # 编组编号
        schu.append(str(data[17]))  # 车号
        schu.append(data[18] + data[19] + data[20] + data[21])  # 公里标
        return schu
    def shujv_toubu_WDNS(self, data):
        schu = [(("0x%02x" % (data[0]))[2:] + ("0x%02x" % (data[1]))[2:])]  # 帧头
        schu.append((int((("0x%02x" % (data[2]))[2:] + ("0x%02x" % (data[3]))[2:]), 16)))  # 报文长度
        schu.append((int((("0x%02x" % (data[5]))[2:] + ("0x%02x" % (data[6]))[2:]), 16)))  # 包序号
        schu.append((int((("0x%02x" % (data[7]))[2:] + ("0x%02x" % (data[8]))[2:]), 16)))  # 包总数
        schu.append(str(data[9]) + "-" + str(data[10]) + "-" +str(data[11]) + "-" + str(data[12]) + ":" +str(data[13]) + ":" + str(data[14]))  # 时间:年月日时分秒
        schu.append(("0x%02x" % (data[15]))[2:3] + ("0x%02x" % (data[15]))[3:4] + ("0x%02x" % (data[16]))[2:3] + ("0x%02x" % (data[16]))[3:4])  # 编组编号
        schu.append(str(data[17]))  # 车号
        schu.append(data[18] + data[19] + data[20] + data[21])  # 公里标
        return schu
    def shujv_BIDS_tz(self, data_BIDS):
        schu = [((int((("0x%02x" % (data_BIDS[0]))[2:] + ("0x%02x" % (data_BIDS[1]))[2:]), 16)) / 100)]  # 车度
        schu.append(chr(data_BIDS[7]) + str(data_BIDS[5]) + str(data_BIDS[4]) + str(data_BIDS[3]) + str(data_BIDS[2]))  # 经度方向+经度
        schu.append(chr(data_BIDS[6]) + str(data_BIDS[11]) + str(data_BIDS[10]) + str(data_BIDS[9]) + str(data_BIDS[8]))  # 纬度方向+纬度
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[12]))[2:] + ("0x%02x" % (data_BIDS[13]))[2:]), 16)) * 0.001))  # tz_1-小
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[14]))[2:] + ("0x%02x" % (data_BIDS[15]))[2:]), 16)) * 0.001))  # tz_4-小
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[16]))[2:] + ("0x%02x" % (data_BIDS[17]))[2:]), 16)) * 0.001))  # tz_5-小
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[18]))[2:] + ("0x%02x" % (data_BIDS[19]))[2:]), 16)) * 0.001))  # tz_8-小
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[20]))[2:] + ("0x%02x" % (data_BIDS[21]))[2:]), 16)) * 0.001))  # tz_1-均
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[22]))[2:] + ("0x%02x" % (data_BIDS[23]))[2:]), 16)) * 0.001))  # tz_4-均
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[24]))[2:] + ("0x%02x" % (data_BIDS[25]))[2:]), 16)) * 0.001))  # tz_5-均
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_BIDS[26]))[2:] + ("0x%02x" % (data_BIDS[27]))[2:]), 16)) * 0.001))  # tz_8-均
        return schu
    def shujv_WNDS_tz(self, data_WNDS):
        schu = [((int((("0x%02x" % (data_WNDS[0]))[2:] + ("0x%02x" % (data_WNDS[1]))[2:]), 16)) / 100)]  # 车度
        schu.append(chr(data_WNDS[7]) + str(data_WNDS[5]) + str(data_WNDS[4]) + str(data_WNDS[3]) + str(data_WNDS[2]))  # 经度方向+经度
        schu.append(chr(data_WNDS[6]) + str(data_WNDS[11]) + str(data_WNDS[10]) + str(data_WNDS[9]) + str(data_WNDS[8]))  # 纬度方向+纬度
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[12]))[2:] + ("0x%02x" % (data_WNDS[13]))[2:]), 16)) * 0.001))  # 特征_1-横向平稳1
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[14]))[2:] + ("0x%02x" % (data_WNDS[15]))[2:]), 16)) * 0.001))  # 特征_1-横向平稳2
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[16]))[2:] + ("0x%02x" % (data_WNDS[17]))[2:]), 16)) * 0.001))  # 特征_1-垂向平稳1
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[18]))[2:] + ("0x%02x" % (data_WNDS[19]))[2:]), 16)) * 0.001))  # 特征_1-垂向平稳2
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[20]))[2:] + ("0x%02x" % (data_WNDS[21]))[2:]), 16)) * 0.001))  # 特征_1-晃车峰值1
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[22]))[2:] + ("0x%02x" % (data_WNDS[23]))[2:]), 16)) * 0.001))  # 特征_1-晃车峰值2
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[24]))[2:] + ("0x%02x" % (data_WNDS[25]))[2:]), 16)) * 0.001))  # 特征_1-横向均方根1
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[26]))[2:] + ("0x%02x" % (data_WNDS[27]))[2:]), 16)) * 0.001))  # 特征_1-横向均方根2
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[28]))[2:] + ("0x%02x" % (data_WNDS[29]))[2:]), 16)) * 0.001))  # 特征_1-垂向均方根1
        schu.append('{:.3f}'.format((int((("0x%02x" % (data_WNDS[30]))[2:] + ("0x%02x" % (data_WNDS[31]))[2:]), 16)) * 0.001))  # 特征_1-垂向均方根2
        return schu
    def shujv_toubu_bj(self, data, jiaoyanhe):
        schu = [(("0x%02x" % (data[0]))[2:] + ("0x%02x" % (data[1]))[2:])]  # 帧头
        schu.append((int((("0x%02x" % (data[2]))[2:] + ("0x%02x" % (data[3]))[2:]), 16)))  # 报文长度
        schu.append(int(bin(data[4])[9:10]))  # 数据有效位
        schu.append(int(bin(data[4])[7:9]))  # 传感器报警位
        schu.append((int((("0x%02x" % (data[5]))[2:] + ("0x%02x" % (data[6]))[2:]), 16)))  # 包序号
        schu.append((int((("0x%02x" % (data[7]))[2:] + ("0x%02x" % (data[8]))[2:]), 16)))  # 包总数
        schu.append(str(data[9]) + "-" + str(data[10]) + "-" +str(data[11]) + "-" + str(data[12]) + ":" +str(data[13]) + ":" + str(data[14]))  # 时间:年月日时分秒
        schu.append(("0x%02x" % (data[15]))[2:3] + ("0x%02x" % (data[15]))[3:4] + ("0x%02x" % (data[16]))[2:3] + ("0x%02x" % (data[16]))[3:4])  # 编组编号
        schu.append(str(data[17]))  # 车号
        schu.append(data[18] + data[19] + data[20] + data[21])  # 公里标
        schu.append(((int((("0x%02x" % (data[22]))[2:] + ("0x%02x" % (data[23]))[2:]), 16)) / 100))  # 速度
        schu.append(jiaoyanhe[0] + jiaoyanhe[1])  # 校验和
        return schu
        # ["帧头", "报文长度", "数据有效位", "传感器报警位", "包序号", "包总数", "时间", "编组", "车号", "公里标", "速度", "校验和"]
    #——————————————————————————————————————————————————————————数据存储————————————————————————————————————————————————————————————————
    def BIDS_bjsv_cchunchu(self, data_type, data):
        a = 0
        schu = []
        huatu = []
        for cnt in range(486):
            schu.append((int((("0x%02x" % (data[a]))[2:] + ("0x%02x" % (data[a + 1]))[2:]), 16)))
            a += 2
        for t in schu:
            if (t - 30000) > 0:
                t = (t - 65535)
            huatu.append(t/1000)
            f = open(self.Message_type_BIDS(int(bin(data_type[0])[7:9])), "a+")
            f.write(str(t/1000) + '\n')
            f.close()  # 关闭这个文件
        duilie_BIDS.put(huatu)
    def WNDS_bjsv_cchunchu(self, data_type, data):
        a = 0
        schu = []
        huatu = []
        for cnt in range(486):
            schu.append((int((("0x%02x" % (data[a]))[2:] + ("0x%02x" % (data[a + 1]))[2:]), 16)))
            a += 2
        for t in schu:
            if (t - 30000) > 0:
                t = (t - 65535)
            huatu.append(t / 1000)
            f = open(self.Message_type_WNDS(int(bin(data_type[0])[7:9])), "a+")
            f.write(str(t / 1000) + '\n')
            f.close()  # 关闭这个文件
        duilie_WNDS.put(huatu)

##-----------------------------------------------------------接收事件----------------------------------------------------------
class UDP_jies(QThread):
    global kongz
    global MYGROUP
    global fasong
    breakSignal = pyqtSignal(list)  # 定义一个信号及数据类型
    def run(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(("10.0.1.5", 17224))
        status = sock.setsockopt(socket.IPPROTO_IP,
                                 socket.IP_ADD_MEMBERSHIP,
                                 socket.inet_aton(MYGROUP) + socket.inet_aton("10.0.1.5"));
        sock.setblocking(0)
        while (kongz):
            try:
                data, addr = sock.recvfrom(1440)  # 判断列表长度 = 1440
            except (socket.error) as e:
                pass
            else:
                if addr[0] == fasong:
                    self.breakSignal.emit(list(data))

# --------------------------------------------------main事件---------------------------------------------------------------
if __name__ == '__main__':
    BIDS_baoxvhao_jy = 999
    WNDS_baoxvhao_jy = 999
    #新建队列
    duilie_BIDS = queue.Queue(1)
    duilie_WNDS = queue.Queue(1)
    app = QApplication(sys.argv)
    mainwindow = mainWindow()
    mainwindow.show()
    sys.exit(app.exec_())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hi-那个谁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值