Example #1
0
        private IMessage ParseLogout(IFrame frame)
        {
            //decode input
            var      rtctime = ParseRtcTime(frame.Payload, DataStart);
            var      privacyFunctionenabledFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 4], 0x01);
            var      dataFlag    = frame.Payload[DataStart + 4];
            var      gpsDataFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 4], 0x02);
            GPSPoint pos         = null;
            var      offset      = DataStart + 5;

            if (!privacyFunctionenabledFlag && gpsDataFlag)
            {
                pos     = ParseGpsData(frame.Payload, offset);
                offset += 19;
            }
            else
            {
                var limit = 19;
                if (frame.Payload.Length - offset < 19)
                {
                    limit = frame.Payload.Length - offset;
                }
                STrace.Debug(GetType().FullName, Id, String.Format("No hay datos de gps, Flag={0:X2} pfeFlag={1} GpsFlag={2} payload={3}", dataFlag, privacyFunctionenabledFlag, gpsDataFlag, StringUtils.ByteArrayToHexString(frame.Payload, offset, limit)));
            }
            var vState = ParseVehicleState(frame.Payload, offset);

            STrace.Debug(GetType().FullName, Id, String.Format("Logout: VState.Length={0} payload={1}", vState.Length, GetData(frame)));

            var res = pos.ToPosition(Id, 0);

            res.Tiempo = rtctime;
            return(res);
        }
Example #2
0
        private IMessage ParseRollCallResponse(IFrame frame)
        {
            //decode input
            var      privacyFunctionenabledFlag = BitHelper.AreBitsSet(frame.Payload[DataStart], 0x01);
            var      dataFlag    = frame.Payload[DataStart];
            var      gpsDataFlag = BitHelper.AreBitsSet(frame.Payload[DataStart], 0x02);
            GPSPoint pos         = null;
            var      offset      = DataStart + 1;

            if (!privacyFunctionenabledFlag && gpsDataFlag)
            {
                pos     = ParseGpsData(frame.Payload, offset);
                offset += 19;
            }
            else
            {
                var limit = 19;
                if (frame.Payload.Length - offset < 19)
                {
                    limit = frame.Payload.Length - offset;
                }
                STrace.Debug(GetType().FullName, Id, String.Format("No hay datos de gps, Flag={0:X2} pfeFlag={1} GpsFlag={2} payload={3}", dataFlag, privacyFunctionenabledFlag, gpsDataFlag, StringUtils.ByteArrayToHexString(frame.Payload, offset, limit)));
            }
            var vState      = ParseVehicleState(frame.Payload, offset);
            var newParaFlag = frame.Payload[offset + 4] == 0x01;             //1 byte

            STrace.Debug(GetType().FullName, Id, String.Format("RollCallResponse: VState.Length={0} NewParaFlag={1} payload={2}", vState.Length, newParaFlag, GetData(frame)));

            return(pos.ToPosition(Id, 0));
        }
Example #3
0
        private IMessage ParseFixedUpload(IFrame frame)
        {
            //decoding
            var tripid = BitConverter.ToInt32(frame.Payload, DataStart);
            var fixedPackageSequenceNumber = BitConverter.ToUInt32(frame.Payload, DataStart + 4);
            var rtctime = ParseRtcTime(frame.Payload, DataStart + 8);
            //var TripMileage = BitConverter.ToInt32(Frame.Payload, dataStart + 12); //en millas
            var conditionflag = frame.Payload[DataStart + 16] == 0x01;
            var dataFlag      = frame.Payload[DataStart + 17];
            var privacyFunctionenabledFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 17], 0x01);
            var gpsDataFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 17], 0x02);
            var gSensorFlag = frame.Payload[DataStart + 18] == 0x01;
            var pidTypes    = ParsePidTypes(frame.Payload, DataStart + 19);
            var offset      = DataStart + 20 + pidTypes.Length * 2;
            var cdpLen      = frame.Payload[offset];        //length of each group of condition data package every 2 seconds
            var gcgmpLen    = frame.Payload[offset + 1];    //the number of GCG mixed package

            offset += 2;
            var pos           = new GPSPoint[gcgmpLen];
            var conditionData = !conditionflag? null : new byte[gcgmpLen][][];
            var gSensorData   = !gSensorFlag ? null : new byte[gcgmpLen][][];

            for (var i = 0; i < gcgmpLen; i++)
            {
                if (!privacyFunctionenabledFlag && gpsDataFlag)
                {
                    pos[i]  = ParseGpsData(frame.Payload, offset);
                    offset += 19;
                }
                else
                {
                    var limit = 19;
                    if (frame.Payload.Length - offset < 19)
                    {
                        limit = frame.Payload.Length - offset;
                    }
                    STrace.Debug(GetType().FullName, Id, String.Format("No hay datos de gps, Flag={0:X2} pfeFlag={1} GpsFlag={2} payload={3}", dataFlag, privacyFunctionenabledFlag, gpsDataFlag, StringUtils.ByteArrayToHexString(frame.Payload, offset, limit)));
                }
                if (conditionflag)
                {
                    conditionData[i] = ParseConditionData(frame.Payload, offset, cdpLen);
                    offset          += 5 * cdpLen;
                }
                if (gSensorFlag)
                {
                    gSensorData[i] = ParseGSensorData(frame.Payload, offset);
                    offset        += 15;
                }
            }
            var vState = ParseVehicleState(frame.Payload, offset);

            STrace.Debug(GetType().FullName, Id, String.Format("FixedUpload: tripid={0} VState.Length={1}", tripid, vState.Length));

            var res = pos.ToPosition(Id, fixedPackageSequenceNumber);

            res.Tiempo = rtctime;
            return(res);
        }
Example #4
0
        //TODO: tripid, VState, NewParaFlag, conditionData, gSensorData, totalTripMileage, totalTripFuelConsumption

        private IMessage ParseLogin(IFrame frame)
        {
            //decode input
            var      tripid  = BitConverter.ToInt32(frame.Payload, DataStart);
            var      rtctime = ParseRtcTime(frame.Payload, DataStart + 4);
            var      privacyFunctionenabledFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 8], 0x01);
            var      dataFlag    = frame.Payload[DataStart + 8];
            var      gpsDataFlag = BitHelper.AreBitsSet(dataFlag, 0x02);
            GPSPoint pos         = null;
            var      offset      = DataStart + 9;

            if (!privacyFunctionenabledFlag && gpsDataFlag)
            {
                pos     = ParseGpsData(frame.Payload, offset);
                offset += 19;
            }
            else
            {
                var limit = 19;
                if (frame.Payload.Length - offset < 19)
                {
                    limit = frame.Payload.Length - offset;
                }
                STrace.Debug(GetType().FullName, Id, String.Format("No hay datos de gps, Flag={0:X2} pfeFlag={1} GpsFlag={2} payload={3}", dataFlag, privacyFunctionenabledFlag, gpsDataFlag, StringUtils.ByteArrayToHexString(frame.Payload, offset, limit)));
            }
            var vState      = ParseVehicleState(frame.Payload, offset);
            var newParaFlag = frame.Payload[offset + 4] == 0x01;             //1 byte

            STrace.Debug(GetType().FullName, Id, String.Format("Login: tripid={0} VState.Length={1} NewParaFlag={2} payload={3}", tripid, vState.Length, newParaFlag, GetData(frame)));

            //encode Response
            var reply = FactoryPacket(
                PacketType.GsmLoginResponse,
                new byte[]
            {
                0x17, 0x00, 0x00, 0x00,                     //Fixed package sequence number
                0xFF, 0xFF, 0xFF, 0xFF,                     //IP address ("0xFFFFFFFF" represents invalid IP address.)
                0xFF, 0xFF,                                 //port
                0x00, 0x00                                  //Reserved
            },
                frame.Payload);

            return(new ConfigRequest(Id, 0)
            {
                Tiempo = rtctime,
                GeoPoint = pos,
                Response = reply,
            });
        }
Example #5
0
        private MessageIdentifier[] ParseVehicleState(byte[] ba, int offset)
        {
            var mis = new List <MessageIdentifier>();

            if (BitHelper.AreBitsSet(ba[offset], 0x01))
            {
                mis.Add(MessageIdentifier.BateryLow);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x02))
            {
                mis.Add(MessageIdentifier.SensorLowerLimitExceeded);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x04))
            {
                mis.Add(MessageIdentifier.SpeedingTicketEnd);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x08))
            {
                mis.Add(MessageIdentifier.SensorUpperLimitExceeded);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x10))
            {
                mis.Add(MessageIdentifier.AccelerationEvent);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x20))
            {
                mis.Add(MessageIdentifier.DesaccelerationEvent);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x40))
            {
                mis.Add(MessageIdentifier.StoppedEvent);
            }
            if (BitHelper.AreBitsSet(ba[offset], 0x80))
            {
                mis.Add(MessageIdentifier.ExcessiveExhaustAlarm);
            }

            if (BitHelper.AreBitsSet(ba[offset + 1], 0x01))
            {
                mis.Add(MessageIdentifier.RpmTicketEnd);
            }
            if (BitHelper.AreBitsSet(ba[offset + 1], 0x02))
            {
                mis.Add(MessageIdentifier.DeviceTurnedOn);
            }

            return(mis.ToArray());
        }
Example #6
0
        private IMessage ParseUploadAlarm(IFrame frame, PacketType packettype)
        {
            //decoding
            var tripid = BitConverter.ToInt32(frame.Payload, DataStart);
            var fixedPackageSequenceNumber = BitConverter.ToUInt32(frame.Payload, DataStart + 4);
            var rtctime = ParseRtcTime(frame.Payload, DataStart + 8);
            //var TripMileage = BitConverter.ToInt32(Frame.Payload, dataStart + 12); //en millas
            var      dataFlag = frame.Payload[DataStart + 16];
            var      privacyFunctionenabledFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 16], 0x01);
            var      gpsDataFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 16], 0x02);
            var      offset      = DataStart + 17;
            GPSPoint pos         = null;

            if (!privacyFunctionenabledFlag && gpsDataFlag)
            {
                pos     = ParseGpsData(frame.Payload, offset);
                offset += 19;
            }
            else
            {
                var limit = 19;
                if (frame.Payload.Length - offset < 19)
                {
                    limit = frame.Payload.Length - offset;
                }
                STrace.Debug(GetType().FullName, Id, String.Format("No hay datos de gps, Flag={0:X2} pfeFlag={1} GpsFlag={2} payload={3}", dataFlag, privacyFunctionenabledFlag, gpsDataFlag, StringUtils.ByteArrayToHexString(frame.Payload, offset, limit)));
            }
            var vState          = ParseVehicleState(frame.Payload, offset);
            var alarmIdentifier = BitConverter.ToInt32(frame.Payload, offset + 4);
            var alarmDetailedDescriptionField = BitConverter.ToInt32(frame.Payload, offset + 8);

            STrace.Debug(GetType().FullName, Id, String.Format("{0}: tripid={1} VState.Length={2} AlarmIdentifier={3:X} AlarmDetailedDescriptionField={4:X} payload={5}", packettype, tripid, vState.Length, alarmIdentifier, alarmDetailedDescriptionField, GetData(frame)));

            var res = pos.ToPosition(Id, fixedPackageSequenceNumber);

            res.Tiempo = rtctime;
            return(res);
        }
Example #7
0
        private GPSPoint ParseGpsData(byte[] ba, int offset)
        {
            var mark           = ba[offset + 17];
            var invalidQuality = (mark & 0x0C) == 0x00;

            if (invalidQuality)
            {
                return(null);
            }

            var dt  = new DateTime((DateTime.UtcNow.Year / 100) * 100 + ba[offset + 2], ba[offset + 1], ba[offset], ba[offset + 3], ba[offset + 4], ba[offset + 5], DateTimeKind.Utc);
            var lat = (float)(BitConverter.ToInt32(ba, offset + 6) / 3600000.0) * (!BitHelper.AreBitsSet(mark, 0x02) ? -1 : 1);
            var lon = (float)(BitConverter.ToInt32(ba, offset + 10) / 3600000.0) * (!BitHelper.AreBitsSet(mark, 0x01) ? -1 : 1);
            var vel = (BitConverter.ToInt16(ba, offset + 14) * 36) / 1000;     // reporta centimetros por segundo, multiplico por 0.036 para pasar a kilometros por segundo
            var dir = BitConverter.ToInt16(ba, offset + 16);

            //var cantsat = (flags & 0xF0) >> 4;

            var res = GPSPoint.Factory(dt, lat, lon, vel, dir, 0, 0);

            STrace.Debug(typeof(Parser).FullName, Id, String.Format("GPS: {0}", res));
            return(res);
        }
Example #8
0
        private IMessage ParseTripEnd(IFrame frame)
        {
            //decoding
            var tripid = BitConverter.ToInt32(frame.Payload, DataStart);
            var fixedPackageSequenceNumber = BitConverter.ToUInt32(frame.Payload, DataStart + 4);
            var rtctime = ParseRtcTime(frame.Payload, DataStart + 8);
            //var totalTripMileage = BitConverter.ToInt32(Frame.Payload, dataStart + 12); //en millas
            //var totalTripFuelConsumption = BitConverter.ToInt32(Frame.Payload, dataStart + 16);
            var      dataFlag = frame.Payload[DataStart + 20];
            var      privacyFunctionenabledFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 20], 0x01);
            var      gpsDataFlag = BitHelper.AreBitsSet(frame.Payload[DataStart + 20], 0x02);
            var      offset      = DataStart + 18;
            GPSPoint pos         = null;

            if (!privacyFunctionenabledFlag && gpsDataFlag)
            {
                pos     = ParseGpsData(frame.Payload, offset);
                offset += 19;
            }
            else
            {
                var limit = 19;
                if (frame.Payload.Length - offset < 19)
                {
                    limit = frame.Payload.Length - offset;
                }
                STrace.Debug(GetType().FullName, Id, String.Format("No hay datos de gps, Flag={0:X2} pfeFlag={1} GpsFlag={2} payload={3}", dataFlag, privacyFunctionenabledFlag, gpsDataFlag, StringUtils.ByteArrayToHexString(frame.Payload, offset, limit)));
            }
            var vState = ParseVehicleState(frame.Payload, offset);

            STrace.Debug(GetType().FullName, Id, String.Format("TripEnd: tripid={0} VState.Length={1} payload={2}", tripid, vState.Length, GetData(frame)));

            var res = pos.ToPosition(Id, fixedPackageSequenceNumber);

            res.Tiempo = rtctime;
            return(res);
        }
Example #9
0
        public DeviceStatus ParsePosition()
        {
            if (!(new[] { "RPH", "RPI" }.Any(d => _command.StartsWith(d))))
            {
                return(null);
            }
            // RPI 190814161155 -3468748 -05847549 125 000 1 12 0000 1 008 1 1 16 0008042322 EF 27;ID=4629;#LOG:9C78;*72<
            // RPH 141014140025 -3460429 -05837906 145 000 1 03 0000 0 256 1 1 16 0000114489 0F 67;ID=5182;#LOG:506F;*0A<

            #region parse line

            var datetimeStr             = _command.Substring(3, 12);
            var latStr                  = _command.Substring(15, 8);
            var lonStr                  = _command.Substring(23, 9);
            var curseStr                = _command.Substring(32, 3); // Norte = 0, Este = 90, Sur = 180, Oeste = 270
            var speedStr                = _command.Substring(35, 3);
            var gpsOnOffStr             = _command.Substring(38, 1);
            var qSatStr                 = _command.Substring(39, 2);
            var posAgeStr               = _command.Substring(41, 4);
            var oneStr                  = _command.Substring(45, 1);
            var hdopStr                 = _command.Substring(46, 3);
            var gprsWithValidIPOnOffStr = _command.Substring(49, 1);
            var gsmStatusStr            = _command.Substring(50, 1);

            /*
             *  Estado de registro GSM
             *      0 not registered, ME is not currently searching a new operator to register to
             *      1 registered, home network
             *      2 not registered, but ME is currently searching a new operator to register to
             *      3 registration denied
             *      4 unknown
             *      5 registered, roaming
             */
            var gsmSignalStr = _command.Substring(51, 2);

            /*
             *  Nivel de señal GSM
             *      0 -113 dBm o menor
             *      1 -111 dBm
             *      2...30 -109... -53 dBm
             *      31 -51 dBm o mayor
             *      99 no detectado
             */
            var odometerStr = _command.Substring(53, 10);
            var inputsStr   = _command.Substring(63, 2);

            /*
             *  Estado de las entradas digitales en hexadecimal
             *      0x80 Estado de Contacto o Ignición
             *      0x40 Estado de Alimentación Principal
             *      0x20 Entrada digital 5
             *      0x10 Entrada digital 4
             *      0x08 Entrada digital 3
             *      0x04 Entrada digital 2
             *      0x02 Entrada digital 1
             *      0x01 Entrada digital 0
             */
            var eventStr = _command.Substring(65, 2);

            #endregion parse line
            // -----------------------

            var time     = DateTimeUtils.SafeParseFormat(datetimeStr, "ddMMyyHHmmss");
            var lat      = Convert.ToSingle(latStr) * (float)0.00001;
            var lon      = Convert.ToSingle(lonStr) * (float)0.00001;
            var vel      = Convert.ToSingle(speedStr);
            var dir      = Convert.ToSingle(curseStr); // (0 ..359), Norte = 0, Este = 90, Sur = 180, Oeste = 270
            var hdop     = Convert.ToSingle(hdopStr) / 10;
            var entradas = Convert.ToByte(inputsStr, 16);
            var evento   = Convert.ToByte(eventStr);
            var posEdad  = Convert.ToInt32(posAgeStr);

            var devId = (Int32?)null;

            if (_node != null)
            {
                devId = _node.Id;
            }

            GPSPoint gpoint = null;
            try
            {
                gpoint = new GPSPoint(time, lat, lon, vel, GPSPoint.SourceProviders.Unespecified, 0)
                {
                    Age            = posEdad,
                    Course         = new Course(dir),
                    HDOP           = hdop,
                    IgnitionStatus = BitHelper.AreBitsSet(entradas, 0x80) ? IgnitionStatus.On : IgnitionStatus.Off
                };
                if (devId != null)
                {
                    gpoint.DeviceId = devId.Value;
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                STrace.Exception(typeof(VirlocDeviceCommand).FullName, e, IdNum ?? 0, String.Format("Posición inválida {0}", getCommand()));
                gpoint = null;
            }

            var result = new DeviceStatus(devId, gpoint, evento, entradas);
            return(result);
        }
Example #10
0
        public DeviceStatus ParsePosition()
        {
            if (!(new[] { "RGP", "RGL" }.Any(d => _command.StartsWith(d))))
            {
                return(null);
            }



            #region command dependent lengths attributes (RGP=47|48/RGL=45|46)
            var eventoLength = (_command.Length == 48 || _command.Length == 46 ? 3 : 2);
            var evento       = Convert.ToByte(_command.Substring(43, eventoLength));
            var hdop         = _command.Length < 47 ? 0 : Convert.ToByte(_command.Substring(43 + eventoLength, 2));
            #endregion command dependent lengths attributes

            var entradas = Convert.ToByte(_command.Substring(41, 2), 16);
            //var tipoDePos = Convert.ToSingle(_command.Substring(38, 1));
            //var edad = Convert.ToByte(_command.Substring(39, 2), 16);

            //if (edad > 300)
            //    return null;

            var time = DateTimeUtils.SafeParseFormat(_command.Substring(3, 12), "ddMMyyHHmmss");
            var lat  = Convert.ToSingle(_command.Substring(15, 8)) * (float)0.00001;
            var lon  = Convert.ToSingle(_command.Substring(23, 9)) * (float)0.00001;
            var vel  = Convert.ToSingle(_command.Substring(32, 3));
            var dir  = Convert.ToSingle(_command.Substring(35, 3)); // (0 ..359), Norte = 0, Este = 90, Sur = 180, Oeste = 270

            /*
             * Estado del posicionamiento del GPS  de la ultima posición valida
             *
             * 0 = Posicionando con solo 1 satélite.
             *
             * 1 = Posicionando con 2 satélites
             *
             * 2 = Posicionando con 3 satélites (2D).
             *
             * 3 = Posicionando con 4 o más satélites (3D).
             *
             * 4 = Posición en 2D calculada por aproximación de cuadrados mínimos.
             *
             * 5 = Posición en 3D calculada por aproximación de cuadrados mínimos.
             *
             * 6 = Posición calculada sin satélites, por velocidad, sentido y tiempo.
             *
             * 8 = Antena en corto circuito
             *
             * 9 = Antena no conectada
             *
             */


            /*
             *
             * bit 7 Ignición.
             *
             * bit 6 Fuente de poder principal.
             *
             * bit 5 Entrada digital 5
             *
             * bit 4 Entrada digital 4
             *
             * bit 3 Entrada digital 3.
             *
             * bit 2 Entrada digital 2.
             *
             * bit 1 Entrada digital 1.
             *
             * bit 0 Entrada digital 0.
             */

            var devId = (Int32?)null;

            if (_node != null)
            {
                devId = _node.Id;
            }


            GPSPoint gpoint = null;
            try
            {
                gpoint = new GPSPoint(time, lat, lon, vel, GPSPoint.SourceProviders.Unespecified, 0)
                {
                    Course         = new Course(dir),
                    HDOP           = hdop,
                    IgnitionStatus = BitHelper.AreBitsSet(entradas, 7) ? IgnitionStatus.On : IgnitionStatus.Off
                };
                if (devId != null)
                {
                    gpoint.DeviceId = devId.Value;
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                STrace.Exception(typeof(VirlocDeviceCommand).FullName, e, IdNum ?? 0, String.Format("Posición inválida {0}", getCommand()));
                gpoint = null;
            }

            var result = new DeviceStatus(devId, gpoint, evento, entradas);
            return(result);
        }
Example #11
0
        public DeviceStatus ParsePosition()
        {
            var eventoLength = (_command.Length == 48 || _command.Length == 46 ? 3 : 2);
            var evento       = (byte)0; // Convert.ToByte(_command.Substring(43, eventoLength));
            var hdop         = (byte)0; // _command.Length < 47 ? 0 : Convert.ToByte(_command.Substring(43 + eventoLength, 2));

            string[] parse    = _command.Split(new[] { "<", ">" }, StringSplitOptions.RemoveEmptyEntries);
            var      entradas = Convert.ToByte("0", 16);
            var      time     = DateTimeUtils.SafeParseFormat(parse[10] + parse[2].Split('.')[0], "ddMMyyHHmmss");

            /*
             *  Latitude: DD MM.MMMM
             *  Longitude: DDD MM.MMMM
             * 3259.816776,N
             * 09642.858868,W
             * latitud max -90 +90
             * 32*59.816776
             * longitud max -180 + 180
             * 096*42.858868
             */

            /*
             * If latitude direction is South, then:
             * Latitude = Latitude * -1
             */
            int latitudSignal = 1;

            if (parse[5].Equals("S"))
            {
                latitudSignal = -1;
            }

            /*
             *  If longitude direction is West, then:
             *  Longitude = Longitude * -1
             */
            int longitudSignal = 1;

            if (parse[7].Equals("W"))
            {
                longitudSignal = -1;
            }

            parse[4] = parse[4].Insert(2, ",").Replace(".", "").Replace(",", "."); //(double.Parse(parse[4].Replace('.', ',')) * latitudSignal) / 100).ToString("0.00001").Replace('.', ',');
            parse[6] = parse[6].Insert(3, ",").Replace(".", "").Replace(",", "."); // ((double.Parse(parse[6].Replace('.', ',')) * longitudSignal) / 100).ToString("0.00001").Replace('.', ',');

            var lat = Convert.ToSingle(parse[4].Split('.')[0]) * latitudSignal;
            var lon = Convert.ToSingle(parse[6].Split('.')[0]) * longitudSignal;
            var vel = Convert.ToSingle(parse[8]);
            var dir = Convert.ToSingle(parse[9]); // (0 ..359), Norte = 0, Este = 90, Sur = 180, Oeste = 270

            var devId = (Int32?)null;

            if (_node != null)
            {
                devId = _node.Id;
            }


            GPSPoint gpoint = null;

            try
            {
                gpoint = new GPSPoint(time, lat, lon, vel, GPSPoint.SourceProviders.Unespecified, 0)
                {
                    Course         = new Course(dir),
                    HDOP           = hdop,
                    IgnitionStatus = BitHelper.AreBitsSet(entradas, 7) ? IgnitionStatus.On : IgnitionStatus.Off
                };
                if (devId != null)
                {
                    gpoint.DeviceId = devId.Value;
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                STrace.Exception(typeof(NovatelDeviceCommand).FullName, e, IdNum ?? 0, String.Format("Posición inválida {0}", getCommand()));
                gpoint = null;
            }

            var result = new DeviceStatus(devId, gpoint, evento, entradas);

            return(result);
        }
Example #12
0
        public DeviceStatus ParsePosition()
        {
            // orden del array

            //0   Encabezado del paquete
            //1   IMEI del equipo
            //2   Número de paquete            string[] parse = _command.Split(new[] { "<", ">" }, StringSplitOptions.RemoveEmptyEntries);
            //3   Evento que generó el paquete            var eventoLength = (_command.Length == 48 || _command.Length == 46 ? 3 : 2);
            //4   Nivel de señal GSM. (Entre 0 y 31)            var evento = (byte)0;
            //5   U1 en voltios            var hdop = (byte)0;
            //6   I1 en Ampere por 10. (10 equivale a 1.0 Amp)            var entradas = Convert.ToByte("0", 16);
            //7   U2 en voltios            var time = DateTimeUtils.SafeParseFormat(parse[10] + parse[2].Split('.')[0], "ddMMyyHHmmss");
            //8   I2 en Ampere por 10. (27 equivale a 2.7 Amp)
            //9   D1 Entrada DIN1 inactiva            /*
            //10  D2 Entrada D2 activa                Latitude: DD MM.MMMM
            //11  T1 Temperatura 25ºC                Longitude: DDD MM.MMMM   T1:valor,T2:valor
            //12  T2 Temperatura 23ºC             3259.816776,N
            //13  T3 Sensor NTC3 abierto             09642.858868,W
            //14  T4 Sensor NTC4 en cortocircuito             latitud max -90 +90
            //15  Latitud             32*59.816776
            //16  Longitud             longitud max -180 + 180
            //17  Modelo y versión de firmware del equipo             096*42.858868
            //18  Fecha y hora de la generación del evento GMT0             */
            //19  Fin de paquete


            string[] parse    = _command.Split(new[] { "<", ">" }, StringSplitOptions.RemoveEmptyEntries);
            var      entradas = Convert.ToByte("0", 16);
            var      time     = DateTimeUtils.SafeParseFormat(parse[17], "yyyy-MM-dd HH:mm:ss");

            //-34.603718 Latitud
            //-58.38158 Longitud
            var lat    = Convert.ToSingle(parse[14].Split('.')[0]);
            var lon    = Convert.ToSingle(parse[15].Split('.')[0]);
            var hdop   = Convert.ToByte(parse[3]);
            var evento = Convert.ToByte(parse[3]);
            var vel    = Convert.ToSingle(0);
            var dir    = Convert.ToSingle(1); // (0 ..359), Norte = 0, Este = 90, Sur = 180, Oeste = 270

            _node.Imei = parse[3];

            var devId = (Int32?)null;

            if (_node != null)
            {
                devId = _node.Id;
            }


            GPSPoint gpoint = null;

            try
            {
                gpoint = new GPSPoint(time, lat, lon, vel, GPSPoint.SourceProviders.Unespecified, 0)
                {
                    Course         = new Course(dir),
                    HDOP           = hdop,
                    IgnitionStatus = BitHelper.AreBitsSet(entradas, 7) ? IgnitionStatus.On : IgnitionStatus.Off
                };
                if (devId != null)
                {
                    gpoint.DeviceId = devId.Value;
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                STrace.Exception(typeof(AbsolutDeviceCommand).FullName, e, IdNum ?? 0, String.Format("Posición inválida {0}", getCommand()));
                gpoint = null;
            }

            var result = new DeviceStatus(devId, gpoint, evento, entradas);

            return(result);
        }