//获取:地表面位置消息(含位置信息) public static ADS_MessageInfo GetEarthLocation(byte[] ADSData, double lon, double lat, uint GPSTime) { ADS_MessageInfo info = new ADS_MessageInfo(); try { info.ICAO = (uint)((ADSData[0] & 0xFF) << 16 | (ADSData[1] & 0xFF) << 8 | (ADSData[2] & 0xFF)); info.Type = (int)(ADSData[3]); #region 经纬度信息 Ads_b_msg msg = new Ads_b_msg(); uint ZY = 0; uint ZX = 0; byte cpr = 0; byte[] zy_c = new byte[4]; byte[] zx_c = new byte[4]; byte[] tmp = new byte[4]; int num = 0; code_msg code_rew = new code_msg(); code_rew.icao = info.ICAO; Array.Copy(ADSData, 9, zy_c, 0, 4); Array.Copy(ADSData, 13, zx_c, 0, 4); ZY = System.BitConverter.ToUInt32(zy_c, 0); ZX = System.BitConverter.ToUInt32(zx_c, 0); cpr = ADSData[8]; code_rew.cpr = cpr; if (cpr == 0) { code_rew.YZ0 = ZY; code_rew.XZ0 = ZX; code_rew.even_time = GPSTime; } else if (cpr == 1) { code_rew.YZ1 = ZY; code_rew.XZ1 = ZX; code_rew.odd_time = GPSTime; } bool even_odd = list_check_msg(code_rew, out num); if (even_odd)//奇偶算法 { msg.msg_out = msg.calc_odd_even_msg(code_list[num].YZ0, code_list[num].XZ0, code_list[num].YZ1, code_list[num].XZ1); //if (CheckRegion(msg.msg_out.latitude, msg.msg_out.longitude, lat, lon))//未超过经纬度界限 { if (info.ICAO != 0 && info.longitude != null && info.latitude != null) { if (msg.msg_out.longitude > -180 && msg.msg_out.longitude < 180 && msg.msg_out.latitude < 90 && msg.msg_out.latitude > -90) { info.longitude = GetLongitude(msg.msg_out.longitude); info.latitude = GetLatitude(msg.msg_out.latitude); //for (int i = 0; i < ADS_Static_Map.Count; i++) //{ // if (info.ICAO == ADS_Static_Map[i].ICAO) // { // info.AirPlaneID = ADS_Static_Map[i].AirPlaneID; // return info; // } //} //态势数据Map赋值 //MapSQL.Add_MapADS(info.ICAO, msg.msg_out.longitude, msg.msg_out.latitude); } else { info.ICAO = 0; } } } } else { info.ICAO = 0; } #endregion } catch (System.Exception ex) { // ErrorRecord.ProcessError(ex.ToString()); } return(info); }
//****************************************ADS_B消息解译函数*****************************************************// //获取:空中位置消息(含位置信息) public static ADS_MessageInfo GetAirLocation(byte[] ADSData, double lon, double lat, uint GPSTime) { ADS_MessageInfo info = new ADS_MessageInfo(); try { info.ICAO = (uint)((ADSData[0] & 0xFF) << 16 | (ADSData[1] & 0xFF) << 8 | (ADSData[2] & 0xFF)); info.Type = (int)(ADSData[3]); #region 高度 int Height = 0; byte[] btheight = ADSData.Skip(6).Take(2).ToArray(); if ((btheight[1] & 0x01) == 0x01) { byte Height_h = (byte)(btheight[1] >> 1); byte Height_l = (byte)(btheight[0] >> 4); int Height_Hd = (int)Height_h * 16; int Height_ld = Height_l; Height = (Height_Hd + Height_l) * 25 - 1025; info.Height = (int)(Height * 0.3048); } else { int CCode = 0; int Gcode = 0; //height[1] = 0x09; //height[0] = 0x04; Gcode = (int)(((btheight[0] & 0x04) << 5) | ((btheight[0] & 0x01) << 6) | ((btheight[1] & 0x40) >> 1) | (btheight[1] & 0x10) | ((btheight[1] & 0x04) << 1) | ((btheight[1] & 0x02) << 1) | ((btheight[0] & 0x08) >> 2) | ((btheight[0] & 0x02) >> 1)); CCode = (int)(((btheight[1] & 0x80) >> 5) | ((btheight[1] & 0x20) >> 4) | ((btheight[1] & 0x08) >> 3)); //Gcode = 0x07; //CCode = 0x04; 对应高度396m Gcode ^= Gcode >> 1; Gcode ^= Gcode >> 2; Gcode ^= Gcode >> 4; Gcode ^= Gcode >> 8; Gcode ^= Gcode >> 16; if (Gcode % 2 == 0) { switch (CCode) { case 0x01: CCode = 0; break; case 0x02: CCode = 2; break; case 0x03: CCode = 1; break; case 0x04: CCode = 4; break; case 0x06: CCode = 3; break; } } else { switch (CCode) { case 0x01: CCode = 4; break; case 0x02: CCode = 2; break; case 0x03: CCode = 3; break; case 0x04: CCode = 0; break; case 0x06: CCode = 1; break; } } info.Height = (int)((Gcode * 5 + CCode - 12) * 100 * 0.3048); } #endregion #region 经纬度信息 Ads_b_msg msg = new Ads_b_msg(); uint ZY = 0; uint ZX = 0; byte cpr = 0; byte[] zy_c = new byte[4]; byte[] zx_c = new byte[4]; byte[] tmp = new byte[4]; int num = 0; code_msg code_rew = new code_msg(); code_rew.icao = info.ICAO; Array.Copy(ADSData, 10, zy_c, 0, 4); Array.Copy(ADSData, 14, zx_c, 0, 4); ZY = System.BitConverter.ToUInt32(zy_c, 0); ZX = System.BitConverter.ToUInt32(zx_c, 0); cpr = ADSData[9]; code_rew.cpr = cpr; if (cpr == 0) { code_rew.YZ0 = ZY; code_rew.XZ0 = ZX; code_rew.even_time = GPSTime; } else if (cpr == 1) { code_rew.YZ1 = ZY; code_rew.XZ1 = ZX; code_rew.odd_time = GPSTime; } bool even_odd = list_check_msg(code_rew, out num); if (even_odd)//奇偶算法 { msg.msg_out = msg.calc_odd_even_msg(code_list[num].YZ0, code_list[num].XZ0, code_list[num].YZ1, code_list[num].XZ1); //if (CheckRegion(msg.msg_out.latitude, msg.msg_out.longitude, lat, lon))//未超过经纬度界限 { if (info.ICAO != 0) { //info.longitude = GetLongitude(msg.msg_out.longitude); //info.latitude = GetLatitude(msg.msg_out.latitude); info.longitude = msg.msg_out.longitude.ToString("f4"); info.latitude = msg.msg_out.latitude.ToString("f4"); //for (int i = 0; i < ADS_Static_Map.Count; i++) //{ // if (info.ICAO == ADS_Static_Map[i].ICAO) // { // info.AirPlaneID = ADS_Static_Map[i].AirPlaneID; // return info; // } //} //态势数据Map赋值 //MapSQL.Add_MapADS(info.ICAO, msg.msg_out.longitude, msg.msg_out.latitude); } else { info.ICAO = 0; } } } else { info.ICAO = 0; } #endregion } catch (System.Exception ex) { // ErrorRecord.ProcessError(ex.ToString()); } return(info); }