Browse Source

修复阀控表上报阀门状态问题

yinyujing 3 years ago
parent
commit
a3cce71fdd
1 changed files with 21 additions and 13 deletions
  1. 21 13
      NB_IOT_TCP_HP_SOCKET/MainForm_TCP.cs

+ 21 - 13
NB_IOT_TCP_HP_SOCKET/MainForm_TCP.cs

@@ -413,7 +413,7 @@ namespace NB_IOT_TCP_HP_SOCKET
                     // 接外包操作
                     // 接外包操作
                     ResMsg msg = ProtocolAnalysisTools.UnOuterPack(bytes, psp);
                     ResMsg msg = ProtocolAnalysisTools.UnOuterPack(bytes, psp);
 
 
-                    if (!msg.Result)
+                    if (!msg.Result || psp.Data.Length == 0)
                     {
                     {
                         AddMsg($" > [{clientInfo.ConnId},OnReceive] -> {clientInfo.IpAddress}:{clientInfo.Port}-{clientInfo.SourceNumber} {psp.SourceNumber} ({bytes.Length} bytes) 外包解包失败 \n {msg.Message}", lbErrorData);
                         AddMsg($" > [{clientInfo.ConnId},OnReceive] -> {clientInfo.IpAddress}:{clientInfo.Port}-{clientInfo.SourceNumber} {psp.SourceNumber} ({bytes.Length} bytes) 外包解包失败 \n {msg.Message}", lbErrorData);
 
 
@@ -476,18 +476,21 @@ namespace NB_IOT_TCP_HP_SOCKET
                                 protocol2.Type = psp.Type;
                                 protocol2.Type = psp.Type;
                                 protocol2.PackNum = psp.PackNum;
                                 protocol2.PackNum = psp.PackNum;
 
 
-                                // 封装回包信息,并发送
-                                if (!ProtocolAnalysisTools.OuterPack(protocol2, out buffer3).Result)
-                                {
+                                if (psp.Type != FrameType.Battery_Param) {
 
 
-                                    AddMsg($" > [{clientInfo.ConnId},OnReceive] -> {clientInfo.IpAddress}:{clientInfo.Port}-{clientInfo.SourceNumber} {psp.SourceNumber} ({bytes.Length} bytes) 历史记录回应打包失败 ", lbErrorData);
+                                    // 封装回包信息,并发送
+                                    if (!ProtocolAnalysisTools.OuterPack(protocol2, out buffer3).Result)
+                                    {
 
 
-                                }
-                                else
-                                {
+                                        AddMsg($" > [{clientInfo.ConnId},OnReceive] -> {clientInfo.IpAddress}:{clientInfo.Port}-{clientInfo.SourceNumber} {psp.SourceNumber} ({bytes.Length} bytes) 历史记录回应打包失败 ", lbErrorData);
 
 
-                                    AddMsg($" > [{clientInfo.ConnId},OnSend] -> {clientInfo.IpAddress}:{clientInfo.Port}-{clientInfo.SourceNumber} {psp.SourceNumber} ({bytes.Length} bytes) 历史记录回应成功 \n {BitConverter.ToString(buffer3, 0, buffer3.Length).Replace("-", " ")} ", lbReceiveData);
-                                    server.Send(clientInfo.ConnId, buffer3, buffer3.Length);// 发送数据
+                                    }
+                                    else
+                                    {
+
+                                        AddMsg($" > [{clientInfo.ConnId},OnSend] -> {clientInfo.IpAddress}:{clientInfo.Port}-{clientInfo.SourceNumber} {psp.SourceNumber} ({bytes.Length} bytes) 历史记录回应成功 \n {BitConverter.ToString(buffer3, 0, buffer3.Length).Replace("-", " ")} ", lbReceiveData);
+                                        server.Send(clientInfo.ConnId, buffer3, buffer3.Length);// 发送数据
+                                    }
                                 }
                                 }
 
 
                                 StartOrResumeSendThread();
                                 StartOrResumeSendThread();
@@ -958,7 +961,7 @@ namespace NB_IOT_TCP_HP_SOCKET
                                             if (rs)
                                             if (rs)
                                             {
                                             {
                                                 PSProtocol protocol2 = new PSProtocol(psp.DestNumber, psp.SourceNumber, backParamSendCode);
                                                 PSProtocol protocol2 = new PSProtocol(psp.DestNumber, psp.SourceNumber, backParamSendCode);
-                                                protocol2.Type = FrameType.Battery_EndComm;
+                                                protocol2.Type = psp.Type;
 
 
                                                 if (ProtocolAnalysisTools.OuterPack(protocol2, out byte[] buffer3).Result)
                                                 if (ProtocolAnalysisTools.OuterPack(protocol2, out byte[] buffer3).Result)
                                                 {
                                                 {
@@ -989,7 +992,7 @@ namespace NB_IOT_TCP_HP_SOCKET
                                                 if (result)
                                                 if (result)
                                                 {
                                                 {
                                                     PSProtocol protocol2 = new PSProtocol(psp.DestNumber, psp.SourceNumber, backParamSendCode);
                                                     PSProtocol protocol2 = new PSProtocol(psp.DestNumber, psp.SourceNumber, backParamSendCode);
-                                                    protocol2.Type = FrameType.Battery_EndComm;
+                                                    protocol2.Type = psp.Type;
 
 
                                                     if (ProtocolAnalysisTools.OuterPack(protocol2, out byte[] buffer3).Result)
                                                     if (ProtocolAnalysisTools.OuterPack(protocol2, out byte[] buffer3).Result)
                                                     {
                                                     {
@@ -1217,7 +1220,12 @@ namespace NB_IOT_TCP_HP_SOCKET
                                                 backValveSate = "ERROR";
                                                 backValveSate = "ERROR";
                                                 break;
                                                 break;
                                         }
                                         }
-                                        sql = "select Top 1 ID,isnull(阀门设置状态,'') as valveSetState,isnull(阀门状态,'') as valveState,isnull(考核表编码,'') as devCode from 设备信息 where 通讯设备ID=" + dt.Rows[0]["transId"].ToString();
+
+                                        sql = "declare @sql varchar(200) if col_length('设备信息','阀门状态') is null begin set @sql = 'alter table 设备信息 add 阀门状态 varchar(20)' EXEC(@sql) end";
+                                        sql += " if col_length('设备信息', '阀门状态更新时间') is null begin set @sql = 'alter table 设备信息 add 阀门状态更新时间 datetime' EXEC(@sql) end ";
+                                        DBHelper.Query(sql);
+
+                                        sql = "select Top 1 ID,isnull(阀门状态,'') as valveState,isnull(考核表编码,'') as devCode from 设备信息 where 通讯设备ID=" + dt.Rows[0]["transId"].ToString();
                                         DataTable dataTable = DBHelper.ExecuteDataTable(sql, CommandType.Text, null);
                                         DataTable dataTable = DBHelper.ExecuteDataTable(sql, CommandType.Text, null);
                                         int num = dataTable.Rows.Count;
                                         int num = dataTable.Rows.Count;
                                         if (num > 0)//存在一条记录
                                         if (num > 0)//存在一条记录