コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Protocol_VicZone.cs プロジェクト: yfyf510/GPS
        public const char OD_CTR_QUERY_MILE    = 'e'; //查询里程


        public static Position GetSMSPos(String src)
        {
            Position pos = new Position();



            //   MessageBox.Show(src);

            pos.MNO = src.Substring(16, 15);

            //   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 );
            pos.GpsTime = "20" + src.Substring(0, 2) + "-" + src.Substring(2, 2) + "-" + src.Substring(4, 2) + " " + src.Substring(6, 2) + ":" + src.Substring(8, 2) + ":" + src.Substring(10, 2);
            if (src.IndexOf('A') >= 0)
            {
                String[] ss = src.Split('A');
                src         = ss[1];
                pos.Pointed = 1;
                pos.La      = Double.Parse(src.Substring(0, 2)) + (Double.Parse(src.Substring(2, 2)) / 60 + ((Double.Parse(src.Substring(5, 4))) / 10000) / 60);
                pos.Lo      = Double.Parse(src.Substring(10, 3)) + (Double.Parse(src.Substring(13, 2)) / 60 + ((Double.Parse(src.Substring(16, 4))) / 10000) / 60); //精度
                pos.Speed   = Pub.KtsToKms((int)(Double.Parse(src.Substring(21, 3)) + 0.1 * Double.Parse(src.Substring(25, 1))));
                double dir = Double.Parse(src.Substring(32, 3)) + 0.01 * Double.Parse(src.Substring(36, 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;
                }
                pos.Mileage     = (int)(Double.Parse(src.Substring(47, 6)) / 1000);
                pos.AlarmHandle = 0;
            }
            else
            {
                String[] ss = src.Split('V');
                src         = ss[1];
                pos.Pointed = 0;
                pos.La      = Double.Parse(src.Substring(0, 2)) + (Double.Parse(src.Substring(2, 2)) / 60 + ((Double.Parse(src.Substring(5, 4))) / 10000) / 60);
                pos.Lo      = Double.Parse(src.Substring(10, 3)) + (Double.Parse(src.Substring(13, 2)) / 60 + ((Double.Parse(src.Substring(16, 4))) / 10000) / 60); //精度
                pos.Speed   = Pub.KtsToKms((int)(Double.Parse(src.Substring(21, 3)) + 0.1 * Double.Parse(src.Substring(25, 1))));
                double dir = Double.Parse(src.Substring(32, 3)) + 0.01 * Double.Parse(src.Substring(36, 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;
                }
                pos.Mileage     = (int)(Double.Parse(src.Substring(47, 6)) / 1000);
                pos.AlarmHandle = 0;
            }



            /*
             *          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);
        }