/// <summary> /// 处理收到的数据包(IP地址设置) /// </summary> /// <param name="dataPack"></param> void processorData_GetIPAddress(PowerDataPack_Receive_GetIPAddress dataPack) { string vMAC = NetHelper.BytesToString_MAC(new byte[] { dataPack.MAC_1, dataPack.MAC_2, dataPack.MAC_3, dataPack.MAC_4, dataPack.MAC_5, dataPack.MAC_6 }); PowerNetConfigEFModel vPowerNetConfigEFModel = new PowerNetConfigEFModel() { MAC = vMAC, DHCP = dataPack.DHCP == 0x01 ? true : false, Gateway = NetHelper.BytesToString_IP(new byte[] { dataPack.gateway1, dataPack.gateway2, dataPack.gateway3, dataPack.gateway4 }), IPAddress = NetHelper.BytesToString_IP(new byte[] { dataPack.IPAddress1, dataPack.IPAddress2, dataPack.IPAddress3, dataPack.IPAddress4 }), ServerIPAddress = NetHelper.BytesToString_IP(new byte[] { dataPack.ServerIPAddress1, dataPack.ServerIPAddress2, dataPack.ServerIPAddress3, dataPack.ServerIPAddress4 }), SubMask = NetHelper.BytesToString_IP(new byte[] { dataPack.SubnetMask1, dataPack.SubnetMask2, dataPack.SubnetMask3, dataPack.SubnetMask4 }), Port = BitConverter.ToInt16(new byte[] { dataPack.Port2, dataPack.Port1 }, 0), ServerPort = BitConverter.ToInt16(new byte[] { dataPack.ServerPort2, dataPack.ServerPort1 }, 0) }; try { m_BasicDBClass_Receive.TransactionBegin(); m_BasicDBClass_Receive.DeleteRecordCustom <PowerNetConfigEFModel>(string.Format("MAC='{0}'", vMAC)); m_BasicDBClass_Receive.InsertRecord(vPowerNetConfigEFModel); PowerSendCMDEFModel vPowerSendCMDEFModel = new PowerSendCMDEFModel() { IsReply = true, State = true }; string vSql = string.Format("DianYuanID='{0}' and CMD={1:D} and SN={2}", vMAC, (byte)PowerDataPack_Send_CommandEnum.Send_GetIPAddress, dataPack.SN); m_BasicDBClass_Receive.UpdateRecord(vPowerSendCMDEFModel, vSql); m_BasicDBClass_Receive.TransactionCommit(); } catch (Exception ex) { string vOutInfo = string.Format("电源获取电源IP地址错误:{0}", ex.Message); Console.WriteLine(vOutInfo); LogHelper.WriteLog_Debug(typeof(PowerControl), vOutInfo); m_BasicDBClass_Receive.TransactionRollback(); } }
private Task processorReceiveData() { return(Task.Run(() => { while (m_IsRun) { try { if (ReceiveQueue.Count > 0) { WHQueueModel vReceiveData = ReceiveQueue.Dequeue(); switch (vReceiveData.Data[11]) { //处理接收到的电源状态数据 case (byte)PowerDataPack_Receive_CommandEnum.RunningStatus: PowerDataPack_Receive_RunningStatus vDataPack1 = NetHelper.ByteToStructure <PowerDataPack_Receive_RunningStatus>(vReceiveData.Data); processorData_RunningStatus(vDataPack1, vReceiveData.IPAddress); break; case (byte)PowerDataPack_Receive_CommandEnum.SwitchStatus: //处理接收到回复电源开关状态数据 case (byte)PowerDataPack_Receive_CommandEnum.SetTime: //设置时间 case (byte)PowerDataPack_Receive_CommandEnum.SetSwitchParam: //开关参数设置 case (byte)PowerDataPack_Receive_CommandEnum.Timing: //定时设置 case (byte)PowerDataPack_Receive_CommandEnum.SetIPAddress: //设置IP地址 PowerDataPack_Receive_ReplyCMD vDataPack2 = NetHelper.ByteToStructure <PowerDataPack_Receive_ReplyCMD>(vReceiveData.Data); processorData_ReplyCMD(vReceiveData.Data[11], vDataPack2); break; //电源上报事件 case (byte)PowerDataPack_Receive_CommandEnum.Event: PowerDataPack_Receive_Event vDataPack3 = NetHelper.ByteToStructure <PowerDataPack_Receive_Event>(vReceiveData.Data); processorData_Event(vDataPack3, vReceiveData.IPAddress); break; //获取IP地址 case (byte)PowerDataPack_Receive_CommandEnum.GetIPAddress: PowerDataPack_Receive_GetIPAddress vDataPack4 = NetHelper.ByteToStructure <PowerDataPack_Receive_GetIPAddress>(vReceiveData.Data); processorData_GetIPAddress(vDataPack4); break; //获取开关参数设置 case (byte)PowerDataPack_Receive_CommandEnum.GetSwitchParam: PowerDataPack_Receive_GetSwitchParam vDataPack5 = NetHelper.ByteToStructure <PowerDataPack_Receive_GetSwitchParam>(vReceiveData.Data); processorData_GetSwitchParam(vDataPack5); break; //获取电源时间 case (byte)PowerDataPack_Receive_CommandEnum.GetTime: PowerDataPack_Receive_GetTime vDataPack6 = NetHelper.ByteToStructure <PowerDataPack_Receive_GetTime>(vReceiveData.Data); processorData_GetTime(vDataPack6); break; //获取设备信息 case (byte)PowerDataPack_Receive_CommandEnum.GetControlInfo: PowerDataPack_Receive_GetControlInfo vDataPack7 = NetHelper.ByteToStructure <PowerDataPack_Receive_GetControlInfo>(vReceiveData.Data); processorData_GetControlInfo(vDataPack7); break; } } Thread.Sleep(100); } catch (Exception ex) { string vOutInfo = string.Format("电源处理数据报文发生异常,错误信息{0}", ex.Message); Console.WriteLine(vOutInfo); LogHelper.WriteLog_Error(typeof(PowerControl), vOutInfo); } } })); }