コード例 #1
0
        public const char OD_CTR_QUERY_MILE = 'd'; //查询里程

        //短信定位信息
        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;
                    }
                }
                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");
                }
                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接收机故障",
                    "超速",        "自定义报警",     "发动机开",      "",
                    "",          "",          "车辆设防",      "车门开",
                    "禁止驶出越界报警",  "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] + " ";
                        }
                    }
                }
                pos.AlarmHandle = (pos.Alarm == "") ? 0 : 1;
                return(pos);
            }
            catch { }
            return(null);
        }
コード例 #2
0
ファイル: Protocol_DaSanTong.cs プロジェクト: yfyf510/GPS
        //gprs/cdma压缩信息
        public static Position GetPosEx(String src)
        {
            Position pos = new Position();

            try
            {
                String ss = Pub.RealHexToHex(src.Substring(1, src.Length - 2));
                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);
                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(ss[1] == '0')
                //pos.La = 0 - pos.La;
                if (ss[2] == '0')
                {
                    pos.Pointed = 0;
                }
                else
                {
                    pos.Pointed = 1;
                }

                pos.Speed     = Pub.KtsToKms(Int32.Parse(ss.Substring(42, 3)));
                pos.Direction = 0;
                double dir = Double.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);
        }