public void PacketArrived(TcpServer TS) { string ServiceId = TS.ServiceID; ConcurrentQueue <TcpReceivedData> Qtrd = TS.TQ.Qtrd; List <TcpSocket> Ts = TS.Ts; ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd; while (Qtrd.Count > 0) { TcpReceivedData trd = null; Qtrd.TryDequeue(out trd); if (trd != null) { try { //注册&透传 Service.ServiceBussiness.RemoteCommand(trd.Data); //Service.ServiceBussiness.Registered30(urd.Data); //ASCII To String string data = EnCoder.ByteArrayToHexStr(trd.Data); //Encoding.ASCII.GetString(trd.Data); if (pd.GetDataState(data) == "01") { string STCD = pd.GetCode(data); InsertNewSTCD(STCD, Service.ServiceEnum.NFOINDEX.TCP, TS); bool B = false; //更新socket列表的stcd、socket TcpBussiness.UpdSocket(TS, trd.SOCKET, STCD, out B); if (!B) { //上线 TcpBussiness.TcpConnected(TS, STCD); } //通知界面 ServiceBussiness.WriteQUIM("TCP", ServiceId, STCD, "接收数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); PacketArrived(data, ServiceEnum.NFOINDEX.TCP, TS); } else { ServiceBussiness.WriteQUIM("TCP", ServiceId, "", "接收异常数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } } catch (Exception ex) { //通知界面 ServiceBussiness.WriteQUIM("TCP", ServiceId, "", "接收异常数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); log.Error(DateTime.Now + "包处理操作异常" + ex.ToString()); } } } }
/// <summary> /// 将收到数据放入数据队列 /// </summary> /// <param name="CS">COM服务</param> /// <param name="senddatetime">发送时间</param> /// <param name="bt">数据</param> public static void WriteCrdQ(ComServer CS, string Satellite, byte[] bt) { ConcurrentQueue <ComReceivedData> Qcrd = CS.CQ.Qcrd; ComReceivedData crd = new ComReceivedData(); crd.SATELLITE = Satellite; crd.Data = bt; /////////////////////////测试输出 Console.Write(EnCoder.ByteArrayToHexStr(bt)); if (bt.Length > 0) { lock (Qcrd) { Qcrd.Enqueue(crd); } } }
public static List <ComReceivedData> SubpackageFor4(ComServer CS, byte[] data) { List <ComReceivedData> Lcrd = new List <ComReceivedData>(); string str = EnCoder.ByteArrayToHexStr(data); if (str.Length >= 10) { string temp = str.Substring(0, 10); if (temp == "2454585858") //$TXXX 通讯信息 { //报文内容长度 long l = Convert.ToInt64(str.Substring(32, 4), 16); //用户地址 string RevSatellite = Convert.ToInt64(str.Substring(14, 6), 16).ToString(); //发信方地址 string SendSatellite = Convert.ToInt64(str.Substring(22, 6), 16).ToString(); //时间 string Time = Convert.ToInt64(str.Substring(28, 2), 16).ToString() + "时" + Convert.ToInt64(str.Substring(30, 2), 16).ToString() + "分"; ComReceivedData crd = new ComReceivedData(); crd.SATELLITE = SendSatellite; //从原始数据报里copy报文 byte[] vBuffer1 = new byte[l / 8]; Array.Copy(data, 18, vBuffer1, 0, l / 8); crd.Data = vBuffer1; Lcrd.Add(crd); //IsCOUT = true; //反馈给界面信息 ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据,用户地址:" + RevSatellite + ",发信方地址:" + SendSatellite + ",时间" + Time + ",数据报长度:" + l, new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text); } else if (temp == "245A4A5858") //$ZJXX 自检信息 { string Explain = ""; //用户地址 string RevSatellite = Convert.ToInt64(str.Substring(14, 6), 16).ToString(); //IC卡状态 string ICState = str.Substring(20, 2); if (ICState == "00")//正常 { Explain += "IC卡状态:正常\n"; } else //异常 { Explain += "IC卡状态:异常\n"; } CS.CStateFor4.ICState = ICState; //硬件状态 string HardwareState = str.Substring(22, 2); if (HardwareState == "00")//正常 { Explain += " 硬件状态:正常\n"; } else //异常 { Explain += " 硬件状态:异常\n"; } CS.CStateFor4.HardwareState = HardwareState; //电量百分比 string Electricity = str.Substring(24, 2); Electricity = Convert.ToInt64(Electricity, 16).ToString(); Explain += " 电量:" + Electricity + "%\n"; CS.CStateFor4.Electricity = Electricity; //入站状态 string Inbound = str.Substring(26, 2); if (Inbound == "00")//正常 { } else //异常 { } string Power = str.Substring(28, 12); CS.CStateFor4.Power = Power; string[] bs = new string[] { "<-158dBW", "-156~-157dBW", "-154~-155dBW", "-152~-153dBW", ">-152dBW" }; for (int i = 0; i < 6; i++) { string s = Power.Substring(2 * i, 2); if (s == "00") { Explain += " 波束" + (i + 1) + "#功率:" + bs[0] + "\n"; } else if (s == "01") { Explain += " 波束" + (i + 1) + "#功率:" + bs[1] + "\n"; } else if (s == "02") { Explain += " 波束" + (i + 1) + "#功率:" + bs[2] + "\n"; } else if (s == "03") { Explain += " 波束" + (i + 1) + "#功率:" + bs[3] + "\n"; } else if (s == "04") { Explain += " 波束" + (i + 1) + "#功率:" + bs[4] + "\n"; } } CS.CStateFor4.DATATIME = DateTime.Now; //将以上解析信息反馈到界面时注销下行 //Explain = " 服务器与卫星接收设备通讯正常"; //反馈给界面信息 ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, RevSatellite, "接收到状态信息\n" + Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } else if (temp == "24544A5858") //$SJXX 时间信息 { //用户地址 string RevSatellite = Convert.ToInt64(str.Substring(14, 6), 16).ToString(); //日期时间 string Date = Convert.ToInt64(str.Substring(20, 4), 16).ToString() + "年" + Convert.ToInt64(str.Substring(24, 2), 16).ToString() + "月" + Convert.ToInt64(str.Substring(26, 2), 16).ToString() + "日"; string Time = Convert.ToInt64(str.Substring(28, 2), 16).ToString() + "时" + Convert.ToInt64(str.Substring(30, 2), 16).ToString() + "分" + Convert.ToInt64(str.Substring(32, 2), 16).ToString() + "秒"; //反馈给界面信息 string Explain = "用户地址" + RevSatellite + ",接收时间信息" + "[" + Date + " " + Time + "]"; //ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据" + item, new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text); ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "", Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } } return(Lcrd); }