Пример #1
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)
            };
        }