Esempio n. 1
0
        public static Mvt100 parseMvt100(string rawData)
        {
            //$$d140,865734029500608,AAA,35,0.000000,0.000999,000101030330,V,0,31,0,0,0.0,0,0,11003,427|2|008E|53C1,0000,0000|0000|0000|0A51|0393,00000031,*BA
            //$$d140,865734029500608,AAA,35,0.000000,0.000999,000101030330,V,0,31,0,0,(12)0.0,0,0,11003,427|2|008E|53C1,(17)0000,0000|0000|0000|0A51|0393,00000031,*BA
            Mvt100 mvt100 = new Mvt100();

            mvt100.rawData = rawData;

            List<string> listData = mvt100.rawData.Split(',').ToList();

            //Validate
            if (String.IsNullOrEmpty(rawData))
                throw new MeitrackException(1, "rawData is null or empty.");

            if (listData.Count != 21)
                throw new MeitrackException(1, "rawData does not have enough comma.");

            if (!(listData[0].Substring(0, 2) == "@@" || listData[0].Substring(0, 2) == "$$"))
                throw new MeitrackException(1, "rawData has wrong format.");

            //Parse
            if (listData[0].Substring(0, 2) == "@@") {
                mvt100.transmissionDirection = TransmissionDirection.SERVER_TO_DEVICE;
            }
            if (listData[0].Substring(0, 2) == "$$") {
                mvt100.transmissionDirection = TransmissionDirection.DEVICE_TO_SERVER;
            }

            mvt100.dataIdentifier = (int)char.Parse(listData[0].Substring(2, 1));
            mvt100.dataLength = int.Parse(listData[0].Substring(4));
            mvt100.imei = Int64.Parse(listData[1]);
            mvt100.commandType = listData[2];
            mvt100.eventCode = int.Parse(listData[3]);
            mvt100.latitude = double.Parse(listData[4]);
            mvt100.longitude = double.Parse(listData[5]);
            mvt100.dateTimeSent = DateTime.ParseExact(listData[6], "yyMMddhhmmss", System.Globalization.CultureInfo.InvariantCulture);
            mvt100.dateTimeReceived = DateTime.Now;
            mvt100.gpsSignalStatus = listData[7] == "A" ? GpsSignalStatus.POSITIONED : GpsSignalStatus.NOT_POSITIONED;
            mvt100.gpsSatellites = int.Parse(listData[8]);
            mvt100.gsmSignalStrength = int.Parse(listData[9]);
            mvt100.speed = int.Parse(listData[10]);
            mvt100.direction = int.Parse(listData[11]);
            mvt100.horizontalPositioningAccuracy = double.Parse(listData[12]);
            mvt100.altitude = int.Parse(listData[13]);
            mvt100.mileage = int.Parse(listData[14]);
            mvt100.runTime = int.Parse(listData[15]);
            mvt100.baseStation = listData[16];
            mvt100.ioPort = int.Parse(listData[17], System.Globalization.NumberStyles.AllowHexSpecifier);

            mvt100.analogValue = listData[18];

            List<string> analogValues = mvt100.analogValue.Split('|').ToList();
            mvt100.analogValueAd1 = int.Parse(analogValues[0], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd2 = int.Parse(analogValues[1], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd3 = int.Parse(analogValues[2], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd4 = int.Parse(analogValues[3], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd5 = int.Parse(analogValues[4], System.Globalization.NumberStyles.AllowHexSpecifier);

            return mvt100;
        }
Esempio n. 2
0
        public static Mvt100 parseMvt100(string rawData)
        {
            //$$d140,865734029500608,AAA,35,0.000000,0.000999,000101030330,V,0,31,0,0,0.0,0,0,11003,427|2|008E|53C1,0000,0000|0000|0000|0A51|0393,00000031,*BA
            //$$d140,865734029500608,AAA,35,0.000000,0.000999,000101030330,V,0,31,0,0,(12)0.0,0,0,11003,427|2|008E|53C1,(17)0000,0000|0000|0000|0A51|0393,00000031,*BA
            Mvt100 mvt100 = new Mvt100();

            mvt100.rawData = rawData;

            List <string> listData = mvt100.rawData.Split(',').ToList();


            //Validate
            if (String.IsNullOrEmpty(rawData))
            {
                throw new MeitrackException(1, "rawData is null or empty.");
            }

            if (listData.Count != 21)
            {
                throw new MeitrackException(1, "rawData does not have enough comma.");
            }


            if (!(listData[0].Substring(0, 2) == "@@" || listData[0].Substring(0, 2) == "$$"))
            {
                throw new MeitrackException(1, "rawData has wrong format.");
            }



            //Parse
            if (listData[0].Substring(0, 2) == "@@")
            {
                mvt100.transmissionDirection = TransmissionDirection.SERVER_TO_DEVICE;
            }
            if (listData[0].Substring(0, 2) == "$$")
            {
                mvt100.transmissionDirection = TransmissionDirection.DEVICE_TO_SERVER;
            }


            mvt100.dataIdentifier                = (int)char.Parse(listData[0].Substring(2, 1));
            mvt100.dataLength                    = int.Parse(listData[0].Substring(4));
            mvt100.imei                          = Int64.Parse(listData[1]);
            mvt100.commandType                   = listData[2];
            mvt100.eventCode                     = int.Parse(listData[3]);
            mvt100.latitude                      = double.Parse(listData[4]);
            mvt100.longitude                     = double.Parse(listData[5]);
            mvt100.dateTimeSent                  = DateTime.ParseExact(listData[6], "yyMMddhhmmss", System.Globalization.CultureInfo.InvariantCulture);
            mvt100.dateTimeReceived              = DateTime.Now;
            mvt100.gpsSignalStatus               = listData[7] == "A" ? GpsSignalStatus.POSITIONED : GpsSignalStatus.NOT_POSITIONED;
            mvt100.gpsSatellites                 = int.Parse(listData[8]);
            mvt100.gsmSignalStrength             = int.Parse(listData[9]);
            mvt100.speed                         = int.Parse(listData[10]);
            mvt100.direction                     = int.Parse(listData[11]);
            mvt100.horizontalPositioningAccuracy = double.Parse(listData[12]);
            mvt100.altitude                      = int.Parse(listData[13]);
            mvt100.mileage                       = int.Parse(listData[14]);
            mvt100.runTime                       = int.Parse(listData[15]);
            mvt100.baseStation                   = listData[16];
            mvt100.ioPort                        = int.Parse(listData[17], System.Globalization.NumberStyles.AllowHexSpecifier);

            mvt100.analogValue = listData[18];

            List <string> analogValues = mvt100.analogValue.Split('|').ToList();

            mvt100.analogValueAd1 = int.Parse(analogValues[0], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd2 = int.Parse(analogValues[1], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd3 = int.Parse(analogValues[2], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd4 = int.Parse(analogValues[3], System.Globalization.NumberStyles.AllowHexSpecifier);
            mvt100.analogValueAd5 = int.Parse(analogValues[4], System.Globalization.NumberStyles.AllowHexSpecifier);

            return(mvt100);
        }