//身份验证解析入口
 private static void AuthenticationDispose(byte[] b, int c, TcpSocketClient client)
 {
     try
     {
         if (b[8] == 0x00 && b[13] == 0x00)//身份验证
         {
             byte[] rb = OnResolveAuthentication(b, 0, 1);
             if (rb != null)
             {
                 client.SendBuffer(rb);
             }
         }
         else if (b[8] == 0x01)//上下班状态
         {
             byte[] rb = OnResolveAuthentication(b, 1, 1);
             if (rb != null)
             {
                 client.SendBuffer(rb);
             }
         }
         else if (b[8] == 0x02)
         {
             byte[] rb = OnResolveAuthentication(b, 2, 1);
             if (rb != null)
             {
                 client.SendBuffer(rb);
             }
         }
     }
     catch (Exception ex)
     { }
 }
Ejemplo n.º 2
0
        //心跳
        //7A 7A 01 00 02 00 0E 00 31 32 33 34 35 36 37 38 17 10 31 17 34 00 C9 6A 7B 7B
        //7a 7a 01 00 02 00 07 00 01 17 10 31 17 38 29 27 cb 7b 7b
        static public void ReceiveDispose_Heartbeat(byte[] data, TcpSocketClient client)
        {
            try
            {
                //设备编号
                byte[] sn = new byte[8];   //设备编号
                for (int i = 0; i < 8; i++)
                {
                    sn[i] = data[i];
                }
                string   DeviceNo = Encoding.ASCII.GetString(sn); //获取设备编号ASCII
                DateTime dateTime = DateTime.Now;
                //RTC
                string tStr = ConvertData.ToHexString(data, 8, 6);
                try
                {
                    dateTime = DateTime.ParseExact(tStr, "yyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception)
                {
                    dateTime = DateTime.Now;
                }
                //拼接应答
                byte[] result = SendJoint_Heartbeat();
                if (result != null)
                {
                    client.SendBuffer(result);
                }

                //更新redis
                DPC.Discharge_operation.Update_equminet_last_online_time(DeviceNo, DPC_Tool.GetTimeStamp(dateTime));
            }
            catch (Exception)
            { }
        }
 public static string OnResolveRecvMessage(byte[] b, int c, TcpSocketClient client)
 {
     try
     {
         uint Command = Convert.ToUInt32(("0x" + ConvertData.ToHexString(b, 4, 4)), 16);
         //传送的各个环境信息
         if (Command == 0x02)
         {
             byte[] rb = OnResolveRealData(b, c);
             if (rb != null)
             {
                 client.SendBuffer(rb);
             }
         }
         return("");
     }
     catch (Exception ex)
     {
         ToolAPI.XMLOperation.WriteLogXmlNoTail(System.Windows.Forms.Application.StartupPath + @"\CT", "创塔设备数据解析异常", ex.Message);
     }
     //图片的封包信息(拍照和取图片一致的)
     //else if (Command == 0x8004)
     //{
     //    OnResolveBitmap(b, c, client);
     //}
     return("");
 }
Ejemplo n.º 4
0
 //时间校准
 //7A 7A 01 00 02 08 0e 00 31 32 33 34 35 36 37 38 17 11 01 09 58 00 54 FA 7b 7b
 //7a 7a 01 00 02 08 07 00 01 17 11 01 10 09 02 a2 6b 7b 7b
 static public void ReceiveDispose_TimeCalibration(byte[] data, TcpSocketClient client)
 {
     try
     {
         Frame_TimeCalibration dataFrame = new Frame_TimeCalibration();
         //设备编号
         byte[] sn = new byte[8];   //设备编号
         for (int i = 0; i < 8; i++)
         {
             sn[i] = data[i];
         }
         dataFrame.DeviceNo = Encoding.ASCII.GetString(sn);  //获取设备编号ASCII
         //RTC
         string tStr = ConvertData.ToHexString(data, 8, 6);
         try
         {
             dataFrame.RTC = DateTime.ParseExact(tStr, "yyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
         }
         catch (Exception)
         {
             dataFrame.RTC = null;
         }
         //拼接应答
         byte[] result = SendJoint_TimeCalibration(dataFrame);
         if (result != null)
         {
             client.SendBuffer(result);
         }
     }
     catch (Exception)
     { }
 }
        public static string OnResolveRecvMessage(byte[] b, int c, TcpSocketClient client)
        {
            try
            {
                byte typ = b[5];
                //心跳
                if (typ == 0x00)
                {
                    byte[] rb = OnResolveHeabert(b, c, client);
                    if (rb != null)
                    {
                        client.SendBuffer(rb);
                    }
                }
                //实时数据
                if (typ == 0x01)
                {
                    OnResolveCurrent(b, c, client);
                }

                //参数上传
                if (typ == 0x04)
                {
                    byte[] rb = OnResolveParm(b, c, client);
                    if (rb != null)
                    {
                        client.SendBuffer(rb);
                    }
                }

                //时间校准
                if (typ == 0x08)
                {
                    byte[] rb = OnResolveTime(b, c);
                    if (rb != null)
                    {
                        client.SendBuffer(rb);
                    }
                }

                return("");
            }
            catch (Exception ex)
            {
                return("");
            }
        }
 /// <summary>
 /// 解析、存储、显示数据
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public static string OnResolveRecvMessage(byte[] b, int c, TcpSocketClient client)
 {
     try
     {
         if (b.Length < 3)
         {
             return("");
         }
         byte typ = b[3];
         if (typ == 0x00)//心跳
         {
             byte[] rb = OnResolveHeabert(b, c);
             if (rb != null)
             {
                 client.SendBuffer(rb);
             }
         }
         else if (typ == 0x01)//实时数据
         {
             OnResolveRealData(b, c, client);
         }
         else if (typ == 0x03)//离线数据
         {
             client.SendBuffer(new byte[] { 0x7E, 0x7E, 0x0E, 0x03, 0x00, 0x00, 0x7D, 0x7D });
         }
         else if (typ == 0x02)//身份验证    考虑考虑怎么处理,是不是给个直通车啥的。
         {
             AuthenticationDispose(b, c, client);
         }
         else if (typ == 0x04)//召唤信息
         {
             byte[] rb = OnResolveParamDataUpload(b, c);
             if (rb != null)
             {
                 client.SendBuffer(rb);
             }
         }
         return("");
     }
     catch (Exception ex)
     {
         return("");
     }
 }
Ejemplo n.º 7
0
        //运行时间帧
        //7A 7A 01 00 02 07 1c 00 31 32 33 34 35 36 37 38 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2F D2 7b 7b
        //7a 7a 01 00 02 07 00 00 00 00 7b 7b
        static public void ReceiveDispose_RunTime(byte[] data, TcpSocketClient client)
        {
            try
            {
                Frame_RunTime dataFrame = new Frame_RunTime();
                //设备编号
                byte[] sn = new byte[8];   //设备编号
                for (int i = 0; i < 8; i++)
                {
                    sn[i] = data[i];
                }
                dataFrame.DeviceNo = Encoding.ASCII.GetString(sn);  //获取设备编号ASCII

                //总运行时间
                UIntValue ui = new UIntValue();
                ui.bValue1             = data[8];
                ui.bValue2             = data[9];
                ui.bValue1             = data[10];
                ui.bValue2             = data[11];
                dataFrame.TotalRunTime = ui.iValue / 3600;
                //开机运行时间
                ui.bValue1            = data[12];
                ui.bValue2            = data[13];
                ui.bValue1            = data[14];
                ui.bValue2            = data[15];
                dataFrame.PowerOnTime = ui.iValue / 3600;
                //应答
                byte[] result = SendJoint_RunTime();
                if (result != null)
                {
                    client.SendBuffer(result);
                }
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 8
0
 public static byte[] OnViolation(byte[] b, int bCount, TcpSocketClient client)
 {
     #region 应答
     List <byte> rb       = new List <byte>();
     byte[]      byteTemp = new byte[6];
     Array.Copy(b, byteTemp, 6);
     rb.AddRange(byteTemp);
     //长度
     rb.Add(1); rb.Add(0);
     rb.Add(1);
     byte[] byteT = new byte[rb.Count];
     rb.CopyTo(byteT);
     byte[] crc16 = BitConverter.GetBytes(ConvertData.CRC16(byteT, 8, rb.Count - 8));
     rb.Add(crc16[0]);
     rb.Add(crc16[1]);
     //结束符
     rb.Add(0x7B);
     rb.Add(0x7B);
     byteT = new byte[rb.Count];
     rb.CopyTo(byteT);
     client.SendBuffer(byteT);
     #endregion
     return(null);
 }
Ejemplo n.º 9
0
 //参数配置
 //7A 7A 01 00 02 04 32 00 31 32 33 34 35 36 37 38 17 10 31 17 34 00 17 10 31 01 00 01 01 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0a 00 0b 00 0c 00 0d 00 31 32 33 D4 18 7b 7b
 //7a 7a 01 00 02 04 00 00 00 00 7b 7b
 static public void ReceiveDispose_ParameterConfig(byte[] data, TcpSocketClient client)
 {
     try
     {
         Frame_ParameterConfig dataFrame = new Frame_ParameterConfig();
         //设备编号
         byte[] sn = new byte[8];   //设备编号
         for (int i = 0; i < 8; i++)
         {
             sn[i] = data[i];
         }
         dataFrame.DeviceNo = Encoding.ASCII.GetString(sn);  //获取设备编号ASCII
         //参数修改时间
         string tStr = ConvertData.ToHexString(data, 8, 6);
         try
         {
             dataFrame.ParameterUpdateTime = DateTime.ParseExact(tStr, "yyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
         }
         catch (Exception)
         {
             dataFrame.ParameterUpdateTime = DateTime.Now;
         }
         //安装时间
         tStr = ConvertData.ToHexString(data, 14, 3);
         try
         {
             dataFrame.InstallDate = DateTime.ParseExact(tStr, "yyMMdd", System.Globalization.CultureInfo.InvariantCulture);
         }
         catch (Exception)
         {
             dataFrame.InstallDate = DateTime.Now;
         }
         //额定载荷
         UShortValue us = new UShortValue();
         us.bValue1           = data[17];
         us.bValue2           = data[18];
         dataFrame.LoadRating = us.sValue;
         //预警系数
         dataFrame.EarlyAlarmCoefficient = data[19];
         //报警系数
         dataFrame.AlarmCoefficient = data[20];
         //空载AD1
         ShortValue s = new ShortValue();
         s.bValue1          = data[21];
         s.bValue2          = data[22];
         dataFrame.EmptyAD1 = s.sValue;
         //空载AD2
         s.bValue1          = data[23];
         s.bValue2          = data[24];
         dataFrame.EmptyAD2 = s.sValue;
         //空载AD3
         s.bValue1          = data[25];
         s.bValue2          = data[26];
         dataFrame.EmptyAD3 = s.sValue;
         //空载AD4
         s.bValue1          = data[27];
         s.bValue2          = data[28];
         dataFrame.EmptyAD4 = s.sValue;
         //空载AD
         s.bValue1         = data[29];
         s.bValue2         = data[30];
         dataFrame.EmptyAD = s.sValue;
         //标准重物AD1
         s.bValue1 = data[31];
         s.bValue2 = data[32];
         dataFrame.StandardLoadAD1 = s.sValue;
         //标准重物AD2
         s.bValue1 = data[33];
         s.bValue2 = data[34];
         dataFrame.StandardLoadAD2 = s.sValue;
         //标准重物AD3
         s.bValue1 = data[35];
         s.bValue2 = data[36];
         dataFrame.StandardLoadAD3 = s.sValue;
         //标准重物AD4
         s.bValue1 = data[37];
         s.bValue2 = data[38];
         dataFrame.StandardLoadAD1 = s.sValue;
         //标准重物AD
         s.bValue1 = data[39];
         s.bValue2 = data[40];
         dataFrame.StandardLoadAD = s.sValue;
         //标准重物
         s.bValue1 = data[41];
         s.bValue2 = data[42];
         dataFrame.StandardLoad = s.sValue;
         //倾角预警值
         s.bValue1 = data[43];
         s.bValue2 = data[44];
         dataFrame.AngleEarlyAlarm = s.sValue;
         //倾角报警值
         s.bValue1            = data[45];
         s.bValue2            = data[46];
         dataFrame.AngleAlarm = s.sValue;
         //软件版本号 ASCII
         byte[] SoftVersion = new byte[data.Length - 47];
         for (int i = 47, j = 0; i < data.Length; i++, j++)
         {
             SoftVersion[j] = data[i];
         }
         dataFrame.SoftVersion = Encoding.ASCII.GetString(SoftVersion);
         //拼接应答
         byte[] result = SendJoint_ParameterConfig(dataFrame);
         if (result != null)
         {
             client.SendBuffer(result);
         }
     }
     catch (Exception)
     { }
 }
Ejemplo n.º 10
0
        //实时数据
        //7A 7A 01 00 02 01 15 00 31 32 33 34 35 36 37 38 17 10 31 17 34 00 01 00 02 00 03 00 01 15 03 7B 7B
        //有报警7A 7A 01 00 02 01 15 00 31 32 33 34 35 36 37 38 17 10 31 17 34 00 01 00 02 00 03 00 0f DB E2 7B 7B
        static public void ReceiveDispose_Current(byte[] data, TcpSocketClient client, bool isCurrent)
        {
            try
            {
                Zhgd_iot_discharge_current dataFrame = new Zhgd_iot_discharge_current();
                //设备编号
                byte[] sn = new byte[8];   //设备编号
                for (int i = 0; i < 8; i++)
                {
                    sn[i] = data[i];
                }
                dataFrame.sn = Encoding.ASCII.GetString(sn);  //获取设备编号ASCII
                //RTC
                string tStr = ConvertData.ToHexString(data, 8, 6);
                try
                {
                    dataFrame.timestamp = DPC_Tool.GetTimeStamp(DateTime.ParseExact(tStr, "yyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture));
                }
                catch (Exception)
                {
                    dataFrame.timestamp = DPC_Tool.GetTimeStamp(DateTime.Now);
                }
                //当前载重
                UShortValue us = new UShortValue();
                us.bValue1       = data[14];
                us.bValue2       = data[15];
                dataFrame.weight = us.sValue;
                //倾角X
                ShortValue s = new ShortValue();
                s.bValue1       = data[16];
                s.bValue2       = data[17];
                dataFrame.dip_x = (double)((double)(s.sValue) / 100d);
                //倾角Y
                s.bValue1       = data[18];
                s.bValue2       = data[19];
                dataFrame.dip_y = (double)((double)(s.sValue) / 100d);
                //报警状态
                string        state = Convert.ToString(data[20], 2).PadLeft(8, '0');
                List <string> vs    = new List <string>();
                dataFrame.is_warning = "N";
                //  dataFrame.WeightWarning = (byte)(state[7] - 48);
                if ((byte)(state[6] - 48) == 1)
                {
                    vs.Add(Warning_type.重量告警); dataFrame.is_warning = "Y";
                }
                //dataFrame.WeightAlarm = (byte)(state[6] - 48);
                // dataFrame.AngleWarning = (byte)(state[5] - 48);
                if ((byte)(state[4] - 48) == 1)
                {
                    vs.Add(Warning_type.重量告警); dataFrame.is_warning = "Y";
                }
                //dataFrame.AngleAlarm = (byte)(state[4] - 48);
                //离线数据应答
                if (!isCurrent)
                {
                    byte[] result = SendJoint_OffLine();
                    if (result != null)
                    {
                        client.SendBuffer(result);
                    }
                }

                //进行数据put
                Discharge_operation.Send_discharge_Current(dataFrame);
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 身份验证
        /// </summary>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <param name="client"></param>
        private static void AuthenticationDispose(byte[] b, int c, TcpSocketClient client)
        {
            List <byte> rb = new List <byte>();

            try
            {
                switch (b[17])
                {
                case 1:
                    byte[] byteTemp = new byte[26];
                    Array.Copy(b, byteTemp, 26);
                    rb.AddRange(byteTemp);
                    rb.Add(1);
                    //长度
                    rb[6] = 19; rb[7] = 0;
                    break;

                case 2:
                    byte[] byteTemp2 = new byte[20];
                    Array.Copy(b, byteTemp2, 20);
                    rb.AddRange(byteTemp2);
                    rb.Add(1);
                    //长度
                    rb[6] = 13; rb[7] = 0;
                    break;

                case 6:    //ZT 20170322
                    byte[] byteTemp6 = new byte[18];
                    Array.Copy(b, byteTemp6, 18);
                    rb.AddRange(byteTemp6);
                    //长度
                    rb[6] = 10; rb[7] = 0;
                    break;

                default: break;
                }
                byte[] byteT = new byte[rb.Count];
                rb.CopyTo(byteT);
                byte[] crc16 = BitConverter.GetBytes(ConvertData.CRC16(byteT, 8, rb.Count - 8));
                rb.Add(crc16[0]);
                rb.Add(crc16[1]);
                //结束符
                rb.Add(0x7B);
                rb.Add(0x7B);
                byteT = new byte[rb.Count];
                rb.CopyTo(byteT);
                client.SendBuffer(byteT);

                if (b[17] == 2)
                {
                    rb.Clear();
                    byte[] byteTemp2 = new byte[18];
                    Array.Copy(b, byteTemp2, 18);
                    rb.AddRange(byteTemp2);
                    rb.Add(1);  //验证结果
                    //子命令字
                    rb[17] = 3; //验证结果下发
                    //长度
                    rb[6] = 81; rb[7] = 0;


                    byte[] sn = new byte[8];   //司机卡号
                    for (int l = 20, j = 0; l < 28; l++, j++)
                    {
                        sn[j] = b[l];
                    }
                    //工号
                    rb.AddRange(sn);
                    //卡号
                    rb.AddRange(sn);

                    for (int i = 0; i < 54; i++)
                    {
                        rb.Add(0xff);
                    }

                    byteT = new byte[rb.Count];
                    rb.CopyTo(byteT);
                    crc16 = BitConverter.GetBytes(ConvertData.CRC16(byteT, 8, rb.Count - 8));
                    rb.Add(crc16[0]);
                    rb.Add(crc16[1]);
                    //结束符
                    rb.Add(0x7B);
                    rb.Add(0x7B);
                    byteT = new byte[rb.Count];
                    rb.CopyTo(byteT);
                    client.SendBuffer(byteT);
                }
            }
            catch (Exception) { }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 解析、存储、显示数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static string OnResolveRecvMessage(byte[] b, int c, TcpSocketClient client)
        {
            if (b.Length < 6)
            {
                return("");
            }

            byte typ = b[5];

            //心跳
            if (typ == 0x00)
            {
                byte[] rb = OnResolveHeabert(b, c, client);
                if (rb != null)
                {
                    client.SendBuffer(rb);
                }
            }
            //实时数据
            if (typ == 0x01)
            {
                OnResolveRealData(b, c);
            }
            //身份验证
            if (typ == 0x02)
            {
                AuthenticationDispose(b, c, client);
            }
            //离线数据
            if (typ == 0x03)
            {
                OnResolveRealData(b, c);
                //离线数据应答
                byte[] rb = new byte[12];
                //针头
                rb[0] = 0x7A;
                rb[1] = 0x7A;
                //协议版本号
                rb[2] = 0x01;
                rb[3] = 0x04;
                rb[4] = 0x00;
                //命令字
                rb[5] = 0x03;
                //数据长度
                rb[6] = 0x00;
                rb[7] = 0x00;
                //数据区
                rb[8] = 0x00;
                //校验和
                rb[9]  = 0x00;
                rb[10] = 0x00;
                //结束
                rb[11] = 0x7B;
                rb[12] = 0x7B;
                client.SendBuffer(rb);
            }
            //参数上传(一样)
            if (typ == 0x04)
            {
                byte[] rb = OnResolveParamDataUpload(b, c);
                if (rb != null)
                {
                    client.SendBuffer(rb);
                }
            }
            /*重新整理*/
            if (typ == 0x07) // 设备运行时间
            {
                byte[] rb = OnResolveRunTime(b, c);
                if (rb != null)
                {
                    client.SendBuffer(rb);
                }
            }
            /*再检查一下*/
            if (typ == 0x08) //时间校准
            {
                byte[] rb = OnResolveTime(b, c);
                if (rb != null)
                {
                    client.SendBuffer(rb);
                }
            }
            if (typ == 0x09) //违规运行通知
            {
                OnViolation(b, c, client);
            }
            return(null);
        }