Exemplo n.º 1
0
        /// <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();
            }
        }