예제 #1
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        private static IMessage GetSalida(GPSPoint gpsPoint, DateTime dt, String rfid, int codEv, INode device, ulong msgId)
        {
            MessageIdentifier codigo;

            switch (codEv)             // codigo del Evento generador del reporte
            {
            case Evento.Panico: codigo = MessageIdentifier.PanicButtonOn; break;

            case Evento.DoorOpenned: codigo = MessageIdentifier.DoorOpenned; break;

            case Evento.SemiTrailerUnhook: codigo = MessageIdentifier.TrailerUnHooked; break;

            case Evento.Substitute: codigo = MessageIdentifier.SubstituteViolation; break;

            case Evento.Generic01: codigo = MessageIdentifier.CustomMsg1On; break;

            case Evento.Generic02: codigo = MessageIdentifier.CustomMsg2On; break;

            case Evento.EngineOn: codigo = MessageIdentifier.EngineOn; break;

            case Evento.EngineOff: codigo = MessageIdentifier.EngineOff; break;

            //case Evento.Periodic01: goto default;
            //case Evento.Periodic02: goto default;
            case Evento.DeviceTurnedOn: codigo = MessageIdentifier.DeviceTurnedOn; break;

            default:
                var pos = gpsPoint.ToPosition(device.Id, msgId);
                pos.Tiempo = dt;
                return(pos);
            }

            return(codigo.FactoryEvent(device.Id, msgId, gpsPoint, dt, rfid, null));
        }
예제 #2
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        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);
        }
예제 #3
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        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));
        }
예제 #4
0
        public IMessage ToIMessage(CaesatFrame frame)
        {
            Logger.DebugFormat("ToIMessage : {0}, the frame was {1}", frame.LicensePlate, frame.Raw);

            var deviceId = FindDeviceId(frame.LicensePlate);

            if (deviceId > 0)
            {
                var pos = new GPSPoint()
                {
                    Lat    = frame.Coordinate.Latitude,
                    Lon    = frame.Coordinate.Longitude,
                    Date   = frame.DateTime,
                    Speed  = new Speed(frame.Speed),
                    Course = new Course(frame.Meaning)
                };

                var message = pos.ToPosition(deviceId, 0);
                Logger.DebugFormat("ToIMessage success: {0} for {1}", message.DeviceId, frame.LicensePlate);

                return(message);
            }

            Logger.WarnFormat("ToIMessage : LicensePlate not found {0}, the frame was {1}", frame.LicensePlate, frame.Raw);
            return(null);
        }
예제 #5
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        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);
        }
예제 #6
0
        private IMessage Translate(SitrackFrame frame)
        {
            var deviceId = 0;

            if (frame.HolderDomain != null)
            {
                deviceId = FindDeviceId(frame.HolderDomain);
            }

            if (deviceId != 0 && deviceId != -1)
            {
                var pos = new GPSPoint
                {
                    Lat    = (float)frame.Latitude,
                    Lon    = (float)frame.Longitude,
                    Date   = frame.ReportDate.ToUniversalTime(),
                    Speed  = new Speed(frame.Speed),
                    Course = new Course(frame.Course)
                };
                if (frame.EventDesc != null)
                {
                    var dispositivoDao = new DispositivoDAO();
                    var dispositivo    = dispositivoDao.FindById(deviceId);

                    var codeEvent = frame.EventId + 9000;

                    var msgTraduccionDao   = new MensajeTraducidoDAO();
                    var codeEventTraducido = msgTraduccionDao.GetCodigoFinal(dispositivo.Empresa.Id, codeEvent.ToString());
                    var evento             = new Event(Convert.ToInt16(codeEventTraducido), -1, deviceId, (ulong)frame.EventId, pos, pos.GetDate(), "", null, true);

                    return(evento);
                }

                var message = pos.ToPosition(deviceId, 0);

                return(message);
            }

            return(null);
        }
예제 #7
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        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);
        }
예제 #8
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        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);
        }
예제 #9
0
파일: Parser.cs 프로젝트: jesumarquez/lt
        private static IMessage GetSalidaReal(GPSPoint gpsPoint, String rfid, int codEv, INode device, ulong msgId, byte[] data)
        {
            MessageIdentifier codigo;

            switch (codEv)             // codigo del Evento generador del reporte
            {
            case Evento.MotorOn:             codigo = MessageIdentifier.EngineOnInternal;           break;

            case Evento.MotorOff:            codigo = MessageIdentifier.EngineOffInternal;          break;

            case Evento.GarminOn:            codigo = MessageIdentifier.GarminOn;                           break;

            case Evento.GarminOff:           codigo = MessageIdentifier.GarminOff;                          break;

            case Evento.PanicButtonOn:       codigo = MessageIdentifier.PanicButtonOn;                      break;

            case Evento.PanicButtonOff:      codigo = MessageIdentifier.PanicButtonOff;                     break;

            case Evento.AmbulanciaSirenaOn:  codigo = MessageIdentifier.SirenOn;                            break;

            case Evento.AmbulanciaSirenaOff: codigo = MessageIdentifier.SirenOff;                           break;

            case Evento.AmbulanciaBalizaOn:  codigo = MessageIdentifier.BeaconOn;                           break;

            case Evento.AmbulanciaBalizaOff: codigo = MessageIdentifier.BeaconOff;                          break;

            case Evento.GsmOn:               codigo = MessageIdentifier.GsmSignalOn;                        break;

            case Evento.GsmOff:              codigo = MessageIdentifier.GsmSignalOff;                       break;

            case Evento.GpsSignalOn:         codigo = MessageIdentifier.GpsSignalOn;                        break;

            case Evento.GpsSignalOff:        codigo = MessageIdentifier.GpsSignalOff;                       break;

            case Evento.Gps3DSignalOff:      codigo = MessageIdentifier.GpsSignal3DOff;                     break;

            case Evento.Gps2DSignalOn:       codigo = MessageIdentifier.GpsSignal2DOn;                      break;

            case Evento.PistonOff:           codigo = MessageIdentifier.PistonOff;                          break;

            case Evento.PistonOn:            codigo = MessageIdentifier.PistonOn;                           break;

            case Evento.DistanciaSinChofer:  codigo = MessageIdentifier.NoDriverMovement;           break;

            case Evento.DistanciaMotorOff:   codigo = MessageIdentifier.NoEngineMovement;           break;

            case Evento.ChoferLoggedOn:  return(MessageIdentifierX.FactoryRfid(device.Id, msgId, gpsPoint, gpsPoint.GetDate(), rfid, 0));

            case Evento.ChoferLoggedOff: return(MessageIdentifierX.FactoryRfid(device.Id, msgId, gpsPoint, gpsPoint.GetDate(), rfid, 1));

            case Evento.Infraccion:
                var maxVel       = data[14];
                var maxPermitida = Speed.KmToKnot(80);                         //volvemos al hardcoded ya q no hay qtree
                var posIni       = device.Retrieve <GPSPoint>("IniInfraccion") ?? gpsPoint;
                return(new SpeedingTicket(device.Id, msgId, posIni, gpsPoint, maxVel, maxPermitida, rfid));

            case Evento.InfraccionInicio:
                device.Store("IniInfraccion", gpsPoint);
                goto default;

            default:
                return(gpsPoint.ToPosition(device.Id, msgId));
            }
            return(codigo.FactoryEvent(device.Id, msgId, gpsPoint, gpsPoint.GetDate(), rfid, null));
        }