瀏覽代碼

1.增加数据预处理;
2.增加ASCII码还原功能;
3.增加远程升级文件MD5验证码追加功能;

libo 2 年之前
父節點
當前提交
310e758d4d
共有 10 個文件被更改,包括 517 次插入261 次删除
  1. 27 2
      Line.cpp
  2. 2 0
      Line.h
  3. 301 247
      Line.ui
  4. 2 0
      Tools.pro
  5. 3 3
      Tools.pro.user
  6. 0 0
      cj_frame.cpp
  7. 4 0
      cj_frame.h
  8. 167 6
      data_frame.cpp
  9. 1 0
      data_frame.h
  10. 10 3
      file_md5.cpp

+ 27 - 2
Line.cpp

@@ -3436,9 +3436,34 @@ void Line::on_pushButton_decode_clicked()
 {
     QString in_frame = ui.textEdit_frame->toPlainText();
     QString out_frame;
-    //in_frame.trimmed();
+    //in_frame.trimmed();    
+    in_frame.replace("0X", "");
+    in_frame.replace("0x", "");
+    in_frame.replace("\t", "");
+    in_frame.replace("\n", "");
     in_frame.replace(" ", "");
-    //frame_decode_jtt808(in_frame,&out_frame);
+
+    out_frame.append("\r\n转换原始数据:\r\n");
+    out_frame.append(in_frame);
     frame_decode_recognize(in_frame,&out_frame);
     textEdit_append(out_frame);
 }
+
+void Line::on_pushButton_A2HEX_clicked()
+{
+    QString in_frame = ui.textEdit_frame->toPlainText();
+    QString out_frame;
+
+    in_frame.replace("0X", "");
+    in_frame.replace("0x", "");
+    in_frame.replace("\t", "");
+    in_frame.replace("\n", "");
+    in_frame.replace(" ", "");
+
+    out_frame.append("\r\n转换原始数据:\r\n");
+    out_frame.append(in_frame);
+
+    frame_to_ascii(in_frame,&out_frame);
+    textEdit_append(out_frame);
+
+}

+ 2 - 0
Line.h

@@ -110,6 +110,8 @@ private slots:
 
     void on_pushButton_decode_clicked();
 
+    void on_pushButton_A2HEX_clicked();
+
 public:
 	QMenu * portmenu;
 	QDialog *portdialog;

+ 301 - 247
Line.ui

@@ -87,7 +87,7 @@
          <bool>true</bool>
         </property>
         <property name="currentIndex">
-         <number>4</number>
+         <number>1</number>
         </property>
         <widget class="QWidget" name="control">
          <attribute name="title">
@@ -173,10 +173,10 @@
          <widget class="QWidget" name="layoutWidget">
           <property name="geometry">
            <rect>
-            <x>360</x>
+            <x>390</x>
             <y>390</y>
-            <width>541</width>
-            <height>30</height>
+            <width>511</width>
+            <height>41</height>
            </rect>
           </property>
           <layout class="QHBoxLayout" name="horizontalLayout_3">
@@ -200,7 +200,7 @@
            <item>
             <widget class="QPushButton" name="UpgradeButton">
              <property name="text">
-              <string> 开始升级</string>
+              <string>开始升级</string>
              </property>
             </widget>
            </item>
@@ -267,103 +267,9 @@
          <widget class="QWidget" name="layoutWidget">
           <property name="geometry">
            <rect>
-            <x>30</x>
+            <x>390</x>
             <y>180</y>
-            <width>121</width>
-            <height>211</height>
-           </rect>
-          </property>
-          <layout class="QVBoxLayout" name="verticalLayout_5">
-           <item>
-            <widget class="QCheckBox" name="Level">
-             <property name="text">
-              <string> 开启液位</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="Pressure">
-             <property name="text">
-              <string> 开启压力</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="PoweroffSave">
-             <property name="text">
-              <string> 断电保存</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="DoubleOil">
-             <property name="text">
-              <string> 两边均有油</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="ReSeal">
-             <property name="text">
-              <string> 重复施封</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="lcd5">
-             <property name="text">
-              <string> 5寸液晶</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="Reserved">
-             <property name="text">
-              <string> 保留位</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QCheckBox" name="AutoSeal">
-             <property name="text">
-              <string> 自动施封</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </widget>
-         <widget class="QWidget" name="layoutWidget">
-          <property name="geometry">
-           <rect>
-            <x>220</x>
-            <y>390</y>
-            <width>158</width>
-            <height>31</height>
-           </rect>
-          </property>
-          <layout class="QHBoxLayout" name="horizontalLayout_8">
-           <item>
-            <widget class="QPushButton" name="ReadCoefExp">
-             <property name="text">
-              <string>读取</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QPushButton" name="SetCoefExp">
-             <property name="text">
-              <string>标定</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </widget>
-         <widget class="QWidget" name="layoutWidget">
-          <property name="geometry">
-           <rect>
-            <x>360</x>
-            <y>180</y>
-            <width>541</width>
+            <width>511</width>
             <height>161</height>
            </rect>
           </property>
@@ -533,7 +439,7 @@
          <widget class="QLabel" name="label_88">
           <property name="geometry">
            <rect>
-            <x>170</x>
+            <x>200</x>
             <y>160</y>
             <width>54</width>
             <height>12</height>
@@ -543,142 +449,6 @@
            <string>膨胀系数:</string>
           </property>
          </widget>
-         <widget class="QWidget" name="layoutWidget">
-          <property name="geometry">
-           <rect>
-            <x>220</x>
-            <y>180</y>
-            <width>111</width>
-            <height>211</height>
-           </rect>
-          </property>
-          <layout class="QVBoxLayout" name="verticalLayout_7">
-           <item>
-            <widget class="QLineEdit" name="CoefExp1"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp2"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp3"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp4"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp5"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp6"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp7"/>
-           </item>
-           <item>
-            <widget class="QLineEdit" name="CoefExp8"/>
-           </item>
-          </layout>
-         </widget>
-         <widget class="QWidget" name="layoutWidget">
-          <property name="geometry">
-           <rect>
-            <x>170</x>
-            <y>180</y>
-            <width>41</width>
-            <height>211</height>
-           </rect>
-          </property>
-          <layout class="QVBoxLayout" name="verticalLayout_6">
-           <item>
-            <widget class="QLabel" name="label_17">
-             <property name="text">
-              <string> 1仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_16">
-             <property name="text">
-              <string> 2仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_15">
-             <property name="text">
-              <string> 3仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_14">
-             <property name="text">
-              <string> 4仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_10">
-             <property name="text">
-              <string> 5仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_11">
-             <property name="text">
-              <string> 6仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_12">
-             <property name="text">
-              <string> 7仓:</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="label_13">
-             <property name="text">
-              <string> 8仓:</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </widget>
-         <widget class="QWidget" name="layoutWidget">
-          <property name="geometry">
-           <rect>
-            <x>30</x>
-            <y>390</y>
-            <width>154</width>
-            <height>31</height>
-           </rect>
-          </property>
-          <layout class="QHBoxLayout" name="horizontalLayout_6">
-           <property name="spacing">
-            <number>2</number>
-           </property>
-           <property name="sizeConstraint">
-            <enum>QLayout::SetDefaultConstraint</enum>
-           </property>
-           <item>
-            <widget class="QPushButton" name="ReadConfig">
-             <property name="text">
-              <string>读取</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QPushButton" name="SetConfig">
-             <property name="text">
-              <string>标定</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </widget>
          <widget class="QLabel" name="label_177">
           <property name="geometry">
            <rect>
@@ -797,6 +567,277 @@
            </item>
           </layout>
          </widget>
+         <widget class="QWidget" name="gridLayoutWidget_3">
+          <property name="geometry">
+           <rect>
+            <x>200</x>
+            <y>180</y>
+            <width>151</width>
+            <height>251</height>
+           </rect>
+          </property>
+          <layout class="QGridLayout" name="gridLayout_3">
+           <item row="0" column="1">
+            <layout class="QVBoxLayout" name="verticalLayout_7">
+             <property name="spacing">
+              <number>7</number>
+             </property>
+             <item>
+              <widget class="QLineEdit" name="CoefExp1"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp2"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp3"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp4"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp5"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp6"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp7"/>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="CoefExp8"/>
+             </item>
+            </layout>
+           </item>
+           <item row="0" column="0">
+            <layout class="QVBoxLayout" name="verticalLayout_6">
+             <item>
+              <widget class="QLabel" name="label_17">
+               <property name="text">
+                <string> 1仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_16">
+               <property name="text">
+                <string> 2仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_15">
+               <property name="text">
+                <string> 3仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_14">
+               <property name="text">
+                <string> 4仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_10">
+               <property name="text">
+                <string> 5仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_11">
+               <property name="text">
+                <string> 6仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_12">
+               <property name="text">
+                <string> 7仓:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="label_13">
+               <property name="text">
+                <string> 8仓:</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </item>
+           <item row="1" column="0" colspan="2">
+            <layout class="QHBoxLayout" name="horizontalLayout_8">
+             <property name="spacing">
+              <number>5</number>
+             </property>
+             <item>
+              <widget class="QPushButton" name="ReadCoefExp">
+               <property name="text">
+                <string>读取</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QPushButton" name="SetCoefExp">
+               <property name="text">
+                <string>标定</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </item>
+          </layout>
+         </widget>
+         <widget class="QWidget" name="">
+          <property name="geometry">
+           <rect>
+            <x>30</x>
+            <y>180</y>
+            <width>141</width>
+            <height>249</height>
+           </rect>
+          </property>
+          <layout class="QVBoxLayout" name="verticalLayout_5">
+           <property name="spacing">
+            <number>11</number>
+           </property>
+           <item>
+            <widget class="QCheckBox" name="Level">
+             <property name="text">
+              <string> 开启液位</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="Pressure">
+             <property name="text">
+              <string> 开启压力</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="PoweroffSave">
+             <property name="text">
+              <string> 断电保存</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="DoubleOil">
+             <property name="text">
+              <string> 两边均有油</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="ReSeal">
+             <property name="text">
+              <string> 重复施封</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="lcd5">
+             <property name="text">
+              <string> 5寸液晶</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="Reserved">
+             <property name="text">
+              <string> 保留位</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QCheckBox" name="AutoSeal">
+             <property name="text">
+              <string> 自动施封</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <layout class="QHBoxLayout" name="horizontalLayout_6">
+             <property name="spacing">
+              <number>1</number>
+             </property>
+             <property name="sizeConstraint">
+              <enum>QLayout::SetMinimumSize</enum>
+             </property>
+             <item>
+              <spacer name="horizontalSpacer_12">
+               <property name="orientation">
+                <enum>Qt::Horizontal</enum>
+               </property>
+               <property name="sizeHint" stdset="0">
+                <size>
+                 <width>40</width>
+                 <height>20</height>
+                </size>
+               </property>
+              </spacer>
+             </item>
+             <item>
+              <spacer name="horizontalSpacer_13">
+               <property name="orientation">
+                <enum>Qt::Horizontal</enum>
+               </property>
+               <property name="sizeHint" stdset="0">
+                <size>
+                 <width>40</width>
+                 <height>20</height>
+                </size>
+               </property>
+              </spacer>
+             </item>
+             <item>
+              <widget class="QPushButton" name="ReadConfig">
+               <property name="text">
+                <string>读取</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QPushButton" name="SetConfig">
+               <property name="text">
+                <string>标定</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <spacer name="horizontalSpacer_14">
+               <property name="orientation">
+                <enum>Qt::Horizontal</enum>
+               </property>
+               <property name="sizeHint" stdset="0">
+                <size>
+                 <width>40</width>
+                 <height>20</height>
+                </size>
+               </property>
+              </spacer>
+             </item>
+             <item>
+              <spacer name="verticalSpacer_2">
+               <property name="orientation">
+                <enum>Qt::Vertical</enum>
+               </property>
+               <property name="sizeHint" stdset="0">
+                <size>
+                 <width>20</width>
+                 <height>40</height>
+                </size>
+               </property>
+              </spacer>
+             </item>
+            </layout>
+           </item>
+          </layout>
+         </widget>
         </widget>
         <widget class="QWidget" name="collect">
          <attribute name="title">
@@ -807,7 +848,7 @@
            <rect>
             <x>30</x>
             <y>30</y>
-            <width>839</width>
+            <width>801</width>
             <height>31</height>
            </rect>
           </property>
@@ -828,7 +869,7 @@
            <item>
             <widget class="QLabel" name="label_20">
              <property name="text">
-              <string>每仓人孔盖数量:</string>
+              <string>每仓人孔盖数:</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -841,7 +882,7 @@
            <item>
             <widget class="QLabel" name="label_23">
              <property name="text">
-              <string>每仓人孔小盖数量:</string>
+              <string>每仓人孔小盖数:</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -854,7 +895,7 @@
            <item>
             <widget class="QLabel" name="label_21">
              <property name="text">
-              <string> 每仓卸油阀数:</string>
+              <string> 每仓卸油阀数:</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -867,7 +908,7 @@
            <item>
             <widget class="QLabel" name="label_22">
              <property name="text">
-              <string>每仓底阀数量:</string>
+              <string>每仓底阀数:</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -1228,7 +1269,7 @@
              <item>
               <widget class="QLabel" name="label_43">
                <property name="text">
-                <string>     卸油阀标零:</string>
+                <string>    卸油阀标零: </string>
                </property>
                <property name="alignment">
                 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -1309,7 +1350,7 @@
              <item>
               <widget class="QLabel" name="label_44">
                <property name="text">
-                <string>     人孔盖标零:</string>
+                <string>    人孔盖标零: </string>
                </property>
                <property name="alignment">
                 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -1492,9 +1533,9 @@
           <property name="geometry">
            <rect>
             <x>30</x>
-            <y>70</y>
+            <y>80</y>
             <width>801</width>
-            <height>201</height>
+            <height>191</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout">
@@ -2480,6 +2521,19 @@
            <string> 协议解析</string>
           </property>
          </widget>
+         <widget class="QPushButton" name="pushButton_A2HEX">
+          <property name="geometry">
+           <rect>
+            <x>810</x>
+            <y>240</y>
+            <width>141</width>
+            <height>31</height>
+           </rect>
+          </property>
+          <property name="text">
+           <string>ASCII转HEX</string>
+          </property>
+         </widget>
         </widget>
        </widget>
       </item>

+ 2 - 0
Tools.pro

@@ -15,10 +15,12 @@ TEMPLATE = app
 
 SOURCES += main.cpp\
         Line.cpp \
+        cj_frame.cpp \
         data_frame.cpp \
         file_md5.cpp
 
 HEADERS  += Line.h \
+    cj_frame.h \
     data_frame.h \
     file_md5.h
 

+ 3 - 3
Tools.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.12.2, 2022-09-21T20:01:42. -->
+<!-- Written by QtCreator 4.12.2, 2022-10-24T10:39:32. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -77,7 +77,7 @@
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.9 MinGW 32-bit</value>
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.9 MinGW 32-bit</value>
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5129.win32_mingw73_kit</value>
-   <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
+   <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
    <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
    <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@@ -320,7 +320,7 @@
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
     <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
-    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/libo_20220905/product/Linetool/build-Tools-Desktop_Qt_5_12_9_MinGW_32_bit-Debug</value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/libo_20220905/product/Linetool/build-Tools-Desktop_Qt_5_12_9_MinGW_32_bit-Release</value>
    </valuemap>
    <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

+ 0 - 0
cj_frame.cpp


+ 4 - 0
cj_frame.h

@@ -0,0 +1,4 @@
+#ifndef CJ_FRAME_H
+#define CJ_FRAME_H
+
+#endif // CJ_FRAME_H

+ 167 - 6
data_frame.cpp

@@ -6,9 +6,25 @@
 #include <QCryptographicHash>
 #include "data_frame.h"
 
+char ConvertHexChar(char c)
+{
+    if((c >= '0') && (c <= '9'))
+        return c - 0x30;
+    else if((c >= 'A') && (c <= 'F'))
+        return c - 'A' + 10;//'A' = 65;
+    else if((c >= 'a') && (c <= 'f'))
+        return c - 'a' + 10;
+    else
+        return -1;
+}
+void frame_decode_jtt808_msg(QString in,QString *out)
+{
+    QString f3_in = in.mid(2,in.length()-4);
+    frame_decode_jtt808(f3_in,out);
+}
 void frame_decode_jtt808(QString in,QString *out)
 {
-    in.toLower();
+    //in.toLower();
 
     QByteArray bytes = in.toLatin1();
     MsgHead_txt_2013 head;
@@ -36,18 +52,40 @@ void frame_decode_jtt808(QString in,QString *out)
     out->append(tmp.mid(0,sizeof(head.sn)));
     out->append("\r\n");
 
+
+    QByteArray msg_data;
+    QByteArray msg_crc;
+
+    msg_crc  = bytes.right(2);
+    uint32_t head_len = sizeof(head);
+    if(1)
+    {
+       head_len  = head_len - 8;
+    }
+
+    msg_data = bytes.mid(head_len,bytes.length() - head_len - 2);
+
+    out->append("消息体:");
+    tmp = QString(msg_data);
+    out->append(tmp);
+    out->append("\r\n");
+
+    out->append("校验值:");
+    tmp = QString(msg_crc);
+    out->append(tmp);
+    out->append("\r\n");
 }
 
 void frame_decode_T2C(QString in,QString *out)
 {
-    in.toLower();
 
     QByteArray bytes = in.toLatin1();
     T2C_Header_txt head;
 
+
     memcpy( &head, bytes.data(),  sizeof(head) );
     QString tmp ;
-    out->append("\r\n远程标定--数据帧头:\r\n");
+    out->append("\r\n远程标定数据帧\r\n数据帧头:\r\n");
     out->append("帧头:");
     tmp = QString(QLatin1String((char *)head.frameflag));
     out->append(tmp.mid(0,sizeof(head.frameflag)));
@@ -63,7 +101,7 @@ void frame_decode_T2C(QString in,QString *out)
     out->append(tmp.mid(0,sizeof(head.functioncode)));
     out->append("\r\n");
 
-    out->append("命令码:");
+    out->append("命令码(寄存器地址):");
     tmp = QString(QLatin1String((char *)head.cmdcode));
     out->append(tmp.mid(0,sizeof(head.cmdcode)));
     out->append("\r\n");
@@ -78,18 +116,141 @@ void frame_decode_T2C(QString in,QString *out)
     out->append(tmp.mid(0,sizeof(head.reserved)));
     out->append("\r\n");
 
+    QByteArray msg_data;
+    QByteArray msg_crc;
+
+    msg_crc = bytes.right(4);
+    msg_data = bytes.mid(sizeof(head),bytes.length() - sizeof(head) - msg_crc.length());
+
+    out->append("消息体:");
+    tmp = QString(msg_data);
+    out->append(tmp);
+    out->append("\r\n");
+
+    out->append("校验值:");
+    tmp = QString(msg_crc);
+    out->append(tmp);
+    out->append("\r\n");
 }
 
+//输入ASCII码,转换为数值
+void frame_decode_ascii(QString in,QString *out)
+{
+    out->append("\r\nASCII码数据帧\r\n终端《========》控制器\r\n");
+    in = in.mid(2,in.length() - 4 - 2);
+
+    QByteArray bytes = in.toLatin1();
+    bytes =bytes.fromHex(bytes);
+    //QByteArray bytes_out;
+
+    out->append(bytes);
+}
+
+void frame_decode_ascii_old(QString in,QString *out)
+{
+    out->append("\r\nASCII码数据帧\r\n终端《========》控制器\r\n");
+    in = in.mid(2,in.length() - 4 - 2);
+
+    QByteArray bytes = in.toLatin1();
+    QByteArray bytes_out ;
+
+    QString data;
+    int i = 0;
+    for(i = 0; i < in.length() ; i++)
+    {
+       bytes_out.append( ConvertHexChar(bytes.at(i)));
+    }
+
+    uint8_t hex_h = 0;
+    uint8_t hex_l = 0;
+    char hex[512] = {0};
+    QString tmp ;
+    for(i = 0; i < in.length()/2; i++)
+    {
+        hex_h  = bytes_out[2*i];
+        hex_l  = bytes_out[2*i+1];
+        hex[i] = (hex_h&0x0f)*16 + (hex_l&0x0f);
+    }
+
+    out->append(hex);
+
+    //out->append(bytes_out);
+}
+
+void frame_to_ascii(QString in,QString *out)
+{
+    out->append("\r\nASCII转换为HEX\r\n");
+
+    QByteArray bytes = in.toLatin1();
+    //QByteArray bytes_out ;
+    QByteArray bytes_hex ;
+
+   // bytes_hex = bytes.toHex();
+    //toHex转换为字符串输出
+    //out->append(bytes_hex);
+
+    bytes_hex = bytes.fromHex(bytes);
+
+    //bytes_out = bytes_hex.fromHex(bytes_hex);
+
+    out->append(bytes_hex);
+}
+
+void frame_to_ascii_old(QString in,QString *out)
+{
+    out->append("\r\nASCII转换为HEX\r\n");
+
+    QByteArray bytes = in.toLatin1();
+    QByteArray bytes_out ;
+
+    QString data;
+    int i = 0;
+    for(i = 0; i < in.length() ; i++)
+    {
+       bytes_out.append( ConvertHexChar(bytes.at(i)));
+    }
+
+    uint8_t hex_h = 0;
+    uint8_t hex_l = 0;
+    char hex[512] = {0};
+    QString tmp ;
+    for(i = 0; i < in.length()/2; i++)
+    {
+        hex_h  = bytes_out[2*i];
+        hex_l  = bytes_out[2*i+1];
+        hex[i] = (hex_h&0x0f)*16 + (hex_l&0x0f);
+    }
+
+    out->append(hex);
+
+    //out->append(bytes_out);
+}
 
 void frame_decode_recognize(QString in,QString *out)
 {
-    if(in.indexOf("3901") == 0)
+    in = in.toLower();
+
+    if((in.indexOf("3901") == 0)||
+       (in.indexOf("3801") == 0)||
+       (in.indexOf("4701") == 0))
     {
         frame_decode_T2C(in,out);
     }
+    else if( (in.indexOf("3a")   == 0) &&
+             (in.indexOf("0d0a") == (in.length() - 4))
+           )
+    {
+       frame_decode_ascii(in,out);
+    }
+    else if( (in.indexOf("7e")   == 0) &&
+                 (in.lastIndexOf("7e") == (in.length() - 2))
+               )
+    {
+       frame_decode_jtt808_msg(in,out);
+    }
     else
     {
-        frame_decode_jtt808(in,out);
+        //frame_decode_jtt808(in,out);
     }
 }
 

+ 1 - 0
data_frame.h

@@ -83,6 +83,7 @@ typedef struct
     uint8_t   reserved[8];            //保留字4字节 12--15
 }T2C_Header_txt;
 
+void frame_to_ascii(QString in,QString *out);
 void frame_decode_jtt808(QString in,QString *out);
 void frame_decode_recognize(QString in,QString *out);
 #endif // DATA_FRAME_H

+ 10 - 3
file_md5.cpp

@@ -17,7 +17,7 @@ void file_md5(QString fileName)
     QByteArray byte_md;
     QFile qfile_in(fileName);
 
-
+    //读到文件数据
     qfile_in.setFileName(fileName);
     if (!qfile_in.open(QIODevice::ReadOnly))
     {
@@ -27,8 +27,8 @@ void file_md5(QString fileName)
     bytes=qfile_in.readAll();
     qDebug("read size=%d\n",bytes.size());
     qfile_in.close();
-
-    QString out_fileName = fileName.replace(".bin", "_out.bin");
+    //生成输出文件名
+    QString out_fileName = fileName.replace(".bin", "_IAP.bin");
 
     QFile qfile_out(out_fileName);
     qfile_out.setFileName(out_fileName);
@@ -36,16 +36,23 @@ void file_md5(QString fileName)
 
 
     //qDebug("%s", fileName.toUtf8());
+
+    //打开输出文件
     if (!qfile_out.open(QIODevice::WriteOnly))
     {
         return;
     }
     qDebug("write size=%d\n",bytes.size());
+    //将原始文件写入到输出文件
     qfile_out.write(bytes);
+    //清空校验值
     byte_md.clear();
+    //生成校验值
     byte_md = QCryptographicHash::hash(bytes, QCryptographicHash::Md5);
     qDebug("md5 size=%d\n",byte_md.size());
+    //将校验值追加文件尾部
     qfile_out.write(byte_md);
+    //关闭文件
     qfile_out.close();