public const char OD_CTR_QUERY_MILE = 'e'; //查询里程 public static Position GetSMSPos(String src) { Position pos = new Position(); String[] ss = src.Split(','); src = ss[1]; // MessageBox.Show(src); pos.MNO = src.Substring(0, 8); pos.MNO = pos.MNO.Substring(6, 2) + pos.MNO.Substring(4, 2) + pos.MNO.Substring(2, 2) + pos.MNO.Substring(0, 2); // MessageBox.Show(pos.MNO); // var id = Int32.Parse("c0801081", System.Clobalization.NumberStyles.HexNumber); // var newid = IPAddress.HostToNetworkOrder( id ); if ((src.Substring(20, 6) == "020301") || (src.Substring(20, 6) == "020302") || (src.Substring(20, 6) == "020307") || (src.Substring(20, 6) == "020308") || (src.Substring(20, 6) == "020304") || (src.Substring(20, 6) == "02030B")) { try { pos.GpsTime = "20" + src.Substring(54, 2) + "-" + src.Substring(56, 2) + "-" + src.Substring(58, 2) + " " + src.Substring(60, 2) + ":" + src.Substring(62, 2) + ":" + src.Substring(64, 2); // MessageBox.Show(pos.GpsTime); DateTime dt = DateTime.Parse(pos.GpsTime); dt = dt.AddHours(8); pos.GpsTime = dt.ToString("yyyy-MM-dd HH:mm:ss"); } catch { pos.GpsTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } pos.Pointed = 1; // pos.Mileage = (int)(((Double.Parse(src.Substring(46, 3)) + 0.1 * Double.Parse(src.Substring(49, 1))) * 0.51444 / 1000)); // pos.Mileage = 200;//(每移动200米报位一次.来计算 pos.La = Double.Parse(src.Substring(28, 2)) + (Double.Parse(src.Substring(30, 2)) / 60 + ((Double.Parse(src.Substring(32, 4))) / 10000) / 60); // 维度 pos.Lo = Double.Parse(src.Substring(37, 3)) + (Double.Parse(src.Substring(40, 2)) / 60 + ((Double.Parse(src.Substring(42, 4))) / 10000) / 60); //精度 pos.Speed = Pub.KtsToKms((int)(Double.Parse(src.Substring(46, 3)) + 0.1 * Double.Parse(src.Substring(49, 1)))); double dir = Double.Parse(src.Substring(50, 2)) + 0.1 * Double.Parse(src.Substring(52, 2)); if (dir < 90) { pos.Direction = 1; } else if (dir == 90) { pos.Direction = 2; } else if (dir < 180) { pos.Direction = 3; } else if (dir == 180) { pos.Direction = 4; } else if (dir < 270) { pos.Direction = 5; } else if (dir == 270) { pos.Direction = 6; } else if (dir > 270) { pos.Direction = 7; } if (src.Substring(20, 6) == "020302") { pos.Alarm = "紧急报警" + ""; pos.Status = pos.Status + "ACC开"; } if (src.Substring(20, 6) == "020307") { pos.Alarm = "断电报警" + ""; pos.Status = pos.Status + "ACC开"; } if (src.Substring(20, 6) == "02030B") { pos.Alarm = "超速报警" + ""; pos.Status = pos.Status + "ACC开"; } if (src.Substring(20, 6) == "020304") { pos.Alarm = "区域报警" + ""; pos.Status = pos.Status + "ACC开"; } pos.AlarmHandle = (pos.Alarm == "") ? 0 : 1; // pos.IsGetSetMsg = true; // pos.SettingStr = src;//硬件目前无独立获得设置命令 } return(pos); }
public const char OD_CTR_QUERY_MILE = 'e'; //查询里程 //短信定位信息 //*RS,123456789,V1,181003,A,2233.1055,N,11358.1257,E,51.00,000,070925,FFFFFBFD# public static Position GetSMSPos(String src) { Position pos = new Position(); try { //Console.WriteLine(src); String[] ss = src.Split(','); pos.MNO = ss[0]; int add = 0; if (ss[1] == "V4") { if (ss[2] == "S32") { add = 3; pos.Mileage = (int)(Double.Parse(ss[4]) * 0.51444 / 1000); }/* * else if(ss[2] == "S5") * { * add = 5; * pos.IsPointMsg = true; * }/*/ else if (ss[2] == "S26") { pos.IsGetSetMsg = true; pos.SettingStr = src.Substring(src.IndexOf(ss[5])); return(pos); } else { add = 2; } } else { pos.IsPointMsg = true; //此协议无单独定位指令,只好用v1代替 } try {/* * pos.GpsTime = "20" + ss[add + 10].Substring(4) + "-" + ss[add + 10].Substring(2, 2) + "-" + ss[add + 10].Substring(0, 2) + " " + ss[add + 2].Substring(0, 2) + ":" + ss[add + 2].Substring(2, 2) + ":" + ss[add + 2].Substring(4); + DateTime dt = DateTime.Parse(pos.GpsTime); + dt = dt.AddHours(8); + pos.GpsTime = dt.ToString("yyyy-MM-dd HH:mm:ss");*/ pos.GpsTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } catch { pos.GpsTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } pos.Pointed = (ss[add + 3] == "A") ? 1 : 0; pos.La = Double.Parse(ss[add + 4].Substring(0, 2)) + Double.Parse(ss[add + 4].Substring(2)) / 60; if (ss[add + 5] == "S") { pos.La = 0 - pos.La; } pos.Lo = Double.Parse(ss[add + 6].Substring(0, 3)) + Double.Parse(ss[add + 6].Substring(3)) / 60; if (ss[add + 7] == "W") { pos.Lo = 0 - pos.Lo; } pos.Speed = Pub.KtsToKms((int)Double.Parse(ss[add + 8])); if (ss[add + 9] == "") { pos.Direction = 0; } else { pos.Direction = 0; double dir = Double.Parse(ss[add + 9]); if (dir < 90) { pos.Direction = 1; } else if (dir == 90) { pos.Direction = 2; } else if (dir < 180) { pos.Direction = 3; } else if (dir == 180) { pos.Direction = 4; } else if (dir < 270) { pos.Direction = 5; } else if (dir == 270) { pos.Direction = 6; } else if (dir > 270) { pos.Direction = 7; } } if (ss[add + 11].Length > 8) { ss[add + 11] = ss[add + 11].Substring(0, 8); } String hex = Pub.HexToBin(ss[add + 11]); String[] status = { "低电传感器1搭铁", "高电传感器2为高", "高电传感器1为高", "电瓶拆除报警", "车辆断油电", "GPRS阻塞报警", "三次密码错误报警", "温度报警", "低电传感器2搭铁", "GPS天线短路", "GPS天线开路", "电瓶被拆除", "主机由后备电池供电", "", "", "GPS天线故障报警", "超速", "自定义报警", "发动机开", "", "", "ACC关", "车辆设防", "车门开", "禁止驶出越界报警", "GPS天线短路报警", "GPS天线开路报警", "禁止驶入越界报警", "非法点火报警", "超速报警", "劫警", "盗警" }; for (int i = 0; i < 32; i++) { if (hex[i] == '0' && status[i] != "") { if (status[i].IndexOf("警") > 0) { pos.Alarm = pos.Alarm + status[i] + " "; } else { pos.Status = pos.Status + status[i] + " "; } } } if (pos.Status.IndexOf("ACC关") < 0) { pos.Status = pos.Status + "ACC开"; } pos.AlarmHandle = (pos.Alarm == "") ? 0 : 1; return(pos); } catch { } return(null); }
public static String CreateGPRSOrder(String mNO, char type, String content, out String remark) { string flash; flash = mNO.Substring(6, 2) + mNO.Substring(4, 2) + mNO.Substring(2, 2) + mNO.Substring(0, 2); try { StringBuilder stb = new StringBuilder("@SJHX,").Append(flash); String time = DateTime.Now.ToString(",HHmmss"); switch (type) { case OD_SET_SMS_NUM_M: //中心短信号码 stb.Append("S2").Append(time).Append(",").Append(content); remark = "设置中心短信号码:"; // +content; break; case OD_SET_SMS_NUM_S: //中心辅助短信号码 stb.Append("S28").Append(time).Append(",").Append(content); remark = "设置中心辅助短信号码:"; // + content; break; case OD_SET_ALARM_SPEED: //设置超速报警速度 String[] ss = content.Split(Constant.SPLIT2); stb.Append("S14").Append(time).Append(",").Append(Pub.KmsToKts(Int32.Parse(ss[0]))); stb.Append(",").Append(Pub.KmsToKts(Int32.Parse(ss[1]))).Append(",1,").Append(ss[2]); remark = "设置超速报警"; break; case OD_SET_NOTIFY_SPEED: //设置超速提示速度 stb.Append("S33").Append(time).Append(",").Append(Pub.KmsToKts(Int32.Parse(content))); remark = "设置超速提示"; break; case OD_SET_ENCLOSURE: //设置电子围栏 String[] str1 = content.Split(','); if (str1[0] == "1") { stb.Append("7E7E00007E7E030003").Append(str1[1]).Append("\r\n"); } else { stb.Append("7E7E00007E7E030003951234560116123456951234560116123456").Append("\r\n"); } remark = "设置电子围栏"; break; case OD_SET_CALL_LIMIT: //设置呼叫限制 stb.Append("S5").Append(time).Append(",").Append(content); remark = "设置呼叫限制"; break; case OD_SET_AUTO_UPLOAD2: //顶事回传 string str = ""; int a = IPAddress.NetworkToHostOrder(int.Parse(content)); byte[] btValue = BitConverter.GetBytes(a); str = Convert.ToString(btValue[2], 16) + Convert.ToString(btValue[3], 16) + Convert.ToString(btValue[0], 16) + Convert.ToString(btValue[1], 16); //低字节在前 str = str.ToUpper(); // str = str.Substring(2, 2) + str.Substring(0, 2); //http://blog.csdn.net/lcj8/archive/2008/04/24/2323451.aspx 参考文件 stb.Append("7E7E00007E7E030103").Append(str).Append("\r\n"); remark = "设置定时自动回传数据时间"; break; case OD_SET_CUTDOWN: //断油断电 String[] ss2 = content.Split(Constant.SPLIT2); stb.Append("S20").Append(time).Append(",").Append(content); if (ss2[1] == "0") { remark = "恢复油电"; } else { remark = "断油断电"; } break; case OD_SET_CUSTOM_ALARM: //自定义报警 stb.Append("S19").Append(time).Append(",").Append(content); remark = "设置自定义报警"; break; case OD_SET_PARAM: //设置终端参数 stb.Append("S12").Append(time).Append(",").Append(content); remark = "设置终端参数"; break; case OD_CTR_FREE_ALARM: //解除报警 stb.Append("7E7E00007E7E03020100\r\n"); remark = "解除报警"; break; case OD_CTR_REBOOT: //重启终端 stb.Append("R1").Append(time); remark = "重启终端"; break; case OD_SET_WATCHING: //监听 stb.Append("R8").Append(time).Append(",").Append(content); remark = "监听:" + content; break; case OD_CTR_RESET: //回复出厂设置 stb.Append("S25").Append(time); remark = "回复出厂设置"; break; case OD_SET_APN: // 设置距离回传时间 50 米倍数 string strf = ""; int b = IPAddress.NetworkToHostOrder(int.Parse(content)); byte[] btValue_1 = BitConverter.GetBytes(b); strf = Convert.ToString(btValue_1[2], 16) + Convert.ToString(btValue_1[3], 16); strf = strf.ToUpper(); stb.Append("7E7E00007E7E030105").Append(strf).Append("\r\n"); remark = "设置距离倍数"; break; case OD_CTR_QUERY_MILE: //查询里程 stb.Append("S32").Append(time).Append(",1"); remark = "查询里程"; break; default: remark = ""; break; } stb.Append(FOOT); return(stb.ToString()); } catch { remark = ""; return(""); } }
//gprs/cdma压缩信息 //24 75 50 13 90 79 16 04 33 14 08 08 22 31 46 01 00 11 40 19 44 3C 00 01 92 FF FF FB FF FF 00 03 //24 75 50 13 90 79 16 04 33 14 08 08 22 31 46 01 00 11 40 19 44 3C 00 01 92 FF FF FB FF FF 00 03 //24 30 80 72 25 23 04 20 38 15 08 08 24 54 60 96 00 11 83 64 28 5C 00 02 67 FF FF FB FF FF 00 5D //char c = 1100 public static Position GetPosEx(String src) { Position pos = new Position(); try { String ss = Pub.RealHexToHex(src.Substring(1, src.Length - 3)); Console.WriteLine(ss.Length.ToString()); if (src[0] == HEAD_HEX_2) { pos.Mileage = (int)(Int32.Parse(ss.Substring(0, 10)) * 0.51444 / 1000); } StringBuilder stb = new StringBuilder(); pos.MNO = ss.Substring(0, 10); /* * GPRS协议2协议停车上传数据时,gps时间不变,所以取服务器时间 */ try {/* * stb.Append("20").Append(ss.Substring(20, 2)).Append("-"); * stb.Append(ss.Substring(18, 2)).Append("-").Append(ss.Substring(16, 2)).Append(" "); * stb.Append(ss.Substring(10, 2)).Append(":").Append(ss.Substring(12, 2)).Append(":"); * stb.Append(ss.Substring(14, 2)); * DateTime dt = DateTime.Parse(stb.ToString()); * dt = dt.AddHours(8); * pos.GpsTime = dt.ToString("yyyy-MM-dd HH:mm:ss");*/ pos.GpsTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } catch { pos.GpsTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } pos.La = Double.Parse(ss.Substring(22, 2)) + Double.Parse(ss.Substring(24, 6).Insert(2, ".")) / 60; pos.Lo = Double.Parse(ss.Substring(32, 3)) + Double.Parse(ss.Substring(35, 6).Insert(2, ".")) / 60; String temp = Pub.HexToBin(ss.Substring(41, 1)); if (temp[0] == '0') { pos.Lo = 0 - pos.Lo; } if (temp[1] == '0') { pos.La = 0 - pos.La; } if (temp[2] == '0') { pos.Pointed = 0; } else { pos.Pointed = 1; } pos.Speed = Pub.KtsToKms(Int32.Parse(ss.Substring(42, 3))); pos.Direction = 0; int dir = Int32.Parse(ss.Substring(45, 3)); if (dir < 90) { pos.Direction = 1; } else if (dir == 90) { pos.Direction = 2; } else if (dir < 180) { pos.Direction = 3; } else if (dir == 180) { pos.Direction = 4; } else if (dir < 270) { pos.Direction = 5; } else if (dir == 270) { pos.Direction = 6; } else if (dir > 270) { pos.Direction = 7; } String hex = Pub.HexToBin(ss.Substring(48, 8)); String[] status = { "低电传感器1搭铁", "高电传感器2为高", "高电传感器1为高", "电瓶拆除报警", "车辆断油电", "GPRS阻塞报警", "三次密码错误报警", "温度报警", "低电传感器2搭铁", "GPS天线短路", "GPS天线开路", "电瓶被拆除", "主机由后备电池供电", "", "", "GPS天线故障报警", "超速", "自定义报警", "发动机开", "", "", "ACC关", "车辆设防", "车门开", "禁止驶出越界报警", "GPS天线短路报警", "GPS天线开路报警", "禁止驶入越界报警", "非法点火报警", "超速报警", "劫警", "盗警" }; for (int i = 0; i < 32; i++) { if (hex[i] == '0' && status[i] != "") { if (status[i].IndexOf("警") > 0) { pos.Alarm = pos.Alarm + status[i] + " "; } else { pos.Status = pos.Status + status[i] + " "; } } } if (pos.Status.IndexOf("ACC关") < 0) { pos.Status = pos.Status + "ACC开"; } pos.AlarmHandle = (pos.Alarm == "") ? 0 : 1; return(pos); } catch { } return(null); }