Ejemplo n.º 1
0
        private void ParsePosDataSubrecord(ref byte[] data, int firstByte, ref ServiceDataSubrecord subrecord)
        {
            Data.ServiceLayer.TeledataService.PosDataSubrecord posData = new Data.ServiceLayer.TeledataService.PosDataSubrecord();

            byte flags = data[firstByte + 12];                                                                                                                                      // 12

            posData.NTM       = BitConverter.ToUInt32(data, firstByte + 0);                                                                                                         // 0-3
            posData.Latitude  = (float)BitConverter.ToUInt32(data, firstByte + 4) * 90 / 0xFFFFFFFF * ((((PosDataFlags)flags & PosDataFlags.LAHS) == PosDataFlags.LAHS) ? -1 : 1);  // 4-7
            posData.Longitude = (float)BitConverter.ToUInt32(data, firstByte + 8) * 180 / 0xFFFFFFFF * ((((PosDataFlags)flags & PosDataFlags.LOHS) == PosDataFlags.LOHS) ? -1 : 1); // 8-11

            posData.Valid  = ((PosDataFlags)flags & PosDataFlags.VLD) == PosDataFlags.VLD;
            posData.Actual = ((PosDataFlags)flags & PosDataFlags.BB) != PosDataFlags.BB;
            posData.Moving = ((PosDataFlags)flags & PosDataFlags.MV) == PosDataFlags.MV;

            posData.Speed     = (ushort)(BitConverter.ToUInt16(new byte[] { data[firstByte + 13], (byte)(data[firstByte + 14] & 0x3F) }, 0) / 10);       // 13-14
            posData.Direction = BitConverter.ToUInt16(new byte[] { data[firstByte + 15], (byte)((data[firstByte + 14] & 0x80) >> 7) }, 0);               // 15

            posData.Odometer = (float)BitConverter.ToUInt32(new byte[] { data[firstByte + 16], data[firstByte + 17], data[firstByte + 18], 0 }, 0) / 10; // 16-18

            posData.DigitalInputs = data[firstByte + 19];                                                                                                // 19
            posData.Source        = data[firstByte + 20];                                                                                                // 20

            if (((PosDataFlags)flags & PosDataFlags.ALTE) == PosDataFlags.ALTE)
            {
                posData.Altitude = BitConverter.ToInt32(new byte[] { data[firstByte + 21], data[firstByte + 22], data[firstByte + 23], 0 }, 0) * (((data[firstByte + 14] & 0x40) == 0x40) ? -1 : 1);    //21-23
            }

            subrecord.Data = posData;
        }
Ejemplo n.º 2
0
        private void ParseRecord(ref byte[] data, int firstByte, ref ServiceDataRecord record)
        {
            int bytesRead = 0;

            while (bytesRead != record.RecordLength)
            {
                ServiceDataSubrecord subrecord = new ServiceDataSubrecord
                {
                    Type   = (SubrecordType)data[firstByte + 0],
                    Length = BitConverter.ToUInt16(data, firstByte + 1)
                };

                subrecordParsers.TryGetValue(subrecord.Type, out SubrecordParserDel parser);
                parser?.Invoke(ref data, (firstByte + 3), ref subrecord);

                record.RecordData.Add(subrecord);

                bytesRead  = (bytesRead + subrecord.Length + 3);
                firstByte += (subrecord.Length + 3);
            }
        }
Ejemplo n.º 3
0
        public void BuildFromProcessingResult(ProcessingResult result)
        {
            ResponsePacket response = new ResponsePacket
            {
                ResponseTo = result.PacketId,
                ResultCode = result.Result
            };

            foreach (ProcessingResult.RecordResult recResult in result.RecResults)
            {
                // subrecord data
                SubrecordResponse subrecord = new SubrecordResponse
                {
                    ConfirmedRecord = recResult.Record.RecordNumber,
                    Result          = (byte)recResult.Result
                };

                // record data
                ServiceDataSubrecord recordData = new ServiceDataSubrecord
                {
                    Data   = subrecord,
                    Length = (ushort)subrecord.GetBytes().Length,
                    Type   = SubrecordType.EGTS_SR_RECORD_RESPONSE
                };

                // Record
                ServiceDataRecord record = new ServiceDataRecord
                {
                    EventFieldExists         = false,
                    ObjectFieldExists        = recResult.Record.ObjectFieldExists,
                    ObjectID                 = recResult.Record.ObjectID,
                    ProcessingPriority       = recResult.Record.ProcessingPriority,
                    RecipientService         = recResult.Record.SourceService,
                    RecipientServiceOnDevice = recResult.Record.SourceServiceOnDevice,
                    RecordNumber             = recResult.Record.RecordNumber,
                    SourceService            = recResult.Record.RecipientService,
                    SourceServiceOnDevice    = recResult.Record.RecipientServiceOnDevice,
                    TimeFieldExists          = false,
                    RecordLength             = (ushort)recordData.GetBytes().Length, // only one subrecord ib RecordData
                };
                record.RecordData.Add(recordData);

                response.ServiceDataRecords.Add(record);
            }

            TransportHeader header = new TransportHeader
            {
                Compressed      = false,
                HeaderEncoding  = 0,
                PID             = result.PacketId,
                Prefix          = 0,
                Priority        = Priority.Highest,
                ProtocolVersion = 1,
                Route           = false,
                SecurityKeyId   = 0,
                Type            = PacketType.EGTS_PT_RESPONSE,
                FrameDataLength = (ushort)response.GetBytes().Length,
                HeaderLength    = 11 // TODO: calculate HeaderLength
            };

            header.CRC = Validator.GetCrc8(header.GetBytes(), (ushort)(header.HeaderLength - 1));

            Packet = new EgtsPacket
            {
                Header           = header,
                ServiceFrameData = response,
                CRC = Validator.GetCrc16(response.GetBytes(), 0, header.FrameDataLength)
            };
        }