Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="serialNumber"><see cref="null"/> if not provided</param>
        /// <param name="status"></param>
        public DeviceStatusInfo(RUSDeviceId deviceId, ushort?serialNumber, StatusInfo status)
        {
            SerialNumber = serialNumber;
            Status       = status;

            var deviceFlagsDescriptors = DESCRIPTORS
                                         .Where(s => s.DeviceId == deviceId || s.DeviceId == null)
                                         .OrderBy(d => d.DeviceId == null)
                                         .ToArray();

            CurrentStatuses = ArrayUtils
                              .Range(0, 1, Status.NumOfBits)
                              .Select(v => 2L.Pow(v))
                              .Select(mask => (Status.Bits & mask) > 0)
                              .Select((set, i) =>
            {
                var descriptor = deviceFlagsDescriptors.Find(d => d.BitIndex == i);
                return(set
                        ? descriptor.ValueOrDefault?.Description
                        : null);
            })
                              .SkipNulls();

            var modes = EnumUtils
                        .GetValues <InclinometrMode>()
                        .Where(m => m.GetInfo().IsThisStatus((ushort)Status.Bits))
                        .ToArray();

            if (modes.Length == 1)
            {
                InclinometrMode = modes.Single();
            }
        }
Example #2
0
 internal RequestInfo(RUSDeviceId deviceId, Command address, EntityDescriptor[] descriptors, IEnumerable <int> userCommandDescriptors, Func <RequestInfo, IEnumerable <IDataEntity> > entitiesFactory)
 {
     _entitiesFactory       = entitiesFactory ?? (_ => new IDataEntity[0]);
     DeviceId               = deviceId;
     Address                = address;
     Descriptors            = descriptors ?? throw new ArgumentNullException(nameof(descriptors));
     UserCommandDescriptors = Descriptors.SubArray(userCommandDescriptors).ToArray();
 }
Example #3
0
 public Task SaveAsync(RUSDeviceId deviceId,
                       IDictionary <RUSDeviceId, IEnumerable <IDataEntity> > dataPacketFormats,
                       Stream rawDump,
                       Stream uncompressedParsedData,
                       Stream destination,
                       AsyncOperationInfo operationInfo)
 {
     return(FlashDump.SaveAsync(deviceId, dataPacketFormats, rawDump, uncompressedParsedData, destination, operationInfo));
 }
Example #4
0
        public FileExtension(RUSDeviceId deviceId, FileType fileType)
        {
            var fileTypeString = fileType.ToString(ft => ft.ToString(),
                                                   (FileType.CALIBRATION, "Cal"),
                                                   (FileType.DATA_PACKET_CONFIGURATION, "DPConf"),
                                                   (FileType.FACTORY_SETTINGS, "FSet"),
                                                   (FileType.TEMPERATURE_CALIBRATION, "TCal"),
                                                   (FileType.WORK_MODE, "WMode"));

            Extension           = $".RUS{((byte)deviceId).ToString("D2")}-{fileTypeString}.txt";
            FileExtensionFilter = $"Файл устройства (*{Extension})|*{Extension}";
        }
Example #5
0
        public FlashDumpLoadVM(RUSDeviceId rusDevice, BusyObject isBusy)
        {
            IsBusy = isBusy;

            DataStorageVM = new FlashDataStorageVM(this);
            Load          = new ActionCommand(loadAsync, IsBusy);
            Cancel        = new ActionCommand(cancelAsync, () => _currentOperation != null, IsBusy);

            async Task loadAsync()
            {
                using (IsBusy.BusyMode)
                {
                    var path = IOUtils.RequestFileOpenPath("BIN (*.bin)|*.bin");
                    if (path == null)
                    {
                        return;
                    }

                    try
                    {
                        _currentOperation     = new AsyncOperationInfo().UseInternalCancellationSource();
                        _currentOperationTask = LoadAsync(path, _currentOperation);
                        Cancel.Update();
                        await _currentOperationTask;

                        Logger.LogOKEverywhere("Дамп Flash успешно загружен");
                    }
                    catch (OperationCanceledException)
                    {
                        Logger.LogInfoEverywhere("Чтение дампа Flash отменено");

                        PointsSource = null;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Ошибка загрузки дампа", $"-MSG", ex);

                        PointsSource = null;
                    }
                    finally
                    {
                        _currentOperationTask = null;
                        _currentOperation     = null;
                    }
                }
            }

            async Task cancelAsync()
            {
                _currentOperation?.Cancel();
            }
        }
Example #6
0
        internal static IEnumerable <EntityDescriptor> GetStatusRequestDescriptors(RUSDeviceId deviceId)
        {
            if (deviceId.IsOneOf(RUSDeviceId.TELEMETRY, RUSDeviceId.RUS_MODULE, RUSDeviceId.RUS_TECHNOLOGICAL_MODULE))
            {
                yield return(new EntityDescriptor("Flags", 0, 4, DataEntityFormat.UINT32));

                yield return(new EntityDescriptor("Serial", 4, 2, DataEntityFormat.UINT16));
            }
            else
            {
                yield return(new EntityDescriptor("Flags", 0, 2, DataEntityFormat.UINT16));

                yield return(new EntityDescriptor("Serial", 2, 2, DataEntityFormat.UINT16));
            }
        }
Example #7
0
        SalachovRequest(RUSDeviceId deviceId, Command address, bool isWriteRequest, ResponseLength responseLength, IEnumerable <IDataEntity> dataEntities, DeviceOperationScope scope)
        {
            DeviceId       = deviceId;
            Address        = address;
            IsWriteRequest = isWriteRequest;
            var addressInfo = Address.GetInfo();

            _responseFullLength = responseLength;
            _hasLengthField     = _responseFullLength.IsUnknown;

            _commandWords = new ushort[]
            {
                (ushort)(((byte)DeviceId << 9) | ((~0x80) & Address.GetInfo().Address) | (IsWriteRequest ? 1 << 7 : 0)),
                0x0000
            };
            _header = wordsToBytes(_commandWords).ToArray();

            Serialized = serialize(dataEntities);

            IEnumerable <byte> serialize(IEnumerable <IDataEntity> entities)
            {
                var dataBytes = entities
                                .Select(e => e.RawValue)
                                .Flatten()
                                .ToArray();
                var zeroTrailShouldBeAdded = dataBytes.Length % 2 == 1;
                var actualLength           = zeroTrailShouldBeAdded
                    ? dataBytes.Length + 1
                    : dataBytes.Length;
                var requestBytes = new Enumerable <byte>()
                {
                    _header,
                    IsWriteRequest     // If there is data - we need to add length of the data
                            ? wordsToBytes(((ushort)actualLength).ToSequence())
                            : new byte[0],
                    dataBytes,
                    zeroTrailShouldBeAdded
                            ? new byte[1]
                            : new byte[0]
                };

                requestBytes.Add(wordsToBytes(_checksum.ComputeChecksum(requestBytes).ToSequence()));

                return(requestBytes);
            }
        }
Example #8
0
 FlashStreamReader(
     DeviceOperationScope flashReadOperationScope,
     RUSDeviceId device,
     IDictionary <RUSDeviceId, IEnumerable <IDataEntity> > rowDescriptors,
     Task <IFlashDumpDataParser> parserFuture,
     StreamPartsProviderSupplier partsProviderSupplier,
     Stream rawDumpStream,
     string rawDumpPath)
 {
     FlashReadOperationScope = flashReadOperationScope ?? throw new ArgumentNullException(nameof(flashReadOperationScope));
     _device                = device;
     _rowDescriptors        = rowDescriptors ?? throw new ArgumentNullException(nameof(rowDescriptors));
     _parserFuture          = parserFuture ?? throw new ArgumentNullException(nameof(parserFuture));
     _partsProviderSupplier = partsProviderSupplier ?? throw new ArgumentNullException(nameof(partsProviderSupplier));
     _rawDumpStream         = rawDumpStream;
     _rawDumpPath           = rawDumpPath ?? throw new ArgumentNullException(nameof(rawDumpPath));
 }
Example #9
0
        public async static Task <FlashStreamReader> CreateAsync(RUSDeviceId device,
                                                                 IDictionary <RUSDeviceId, IEnumerable <IDataEntity> > formats,
                                                                 IFlashDumpDataParserFactory parserFactory,
                                                                 AsyncOperationInfo operationInfo)
        {
            var flashDumpPath         = Storaging.GetTempFilePath();
            var baseStream            = new FileStream(flashDumpPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
            var flashDumpWriteStream  = new FillNotifiableWriteOnlyStreamDecorator(CHUNK_SIZE, baseStream);
            var partsProvider         = new DumpParserPartsProvider(flashDumpPath);
            var partsProviderSupplier = new StreamPartsProviderSupplier(flashDumpWriteStream, partsProvider);
            var scope    = new DeviceOperationScope(new FlashDumpStreamParameter(flashDumpWriteStream));
            var sections = formats.Select(f =>
                                          new SectionedDataPacketParser.Section(
                                              f.Key,
                                              new DataPacketParser(EntitiesDeserializer.ExtractDataPacketDescriptors(f.Value))))
                           .ToArray();
            var dataParser   = new SectionedDataPacketParser(sections);
            var parserFuture = parserFactory.CreateFromRawPartsAsync(partsProvider.RawDumpParts(), dataParser, operationInfo);

            return(new FlashStreamReader(scope, device, formats, parserFuture, partsProviderSupplier, flashDumpWriteStream, flashDumpPath));
        }
Example #10
0
        public static RequestInfo GetRequestDescription(RUSDeviceId deviceId, Command request)
        {
            var info = (deviceId, request);

            if (info.request.IsOneOf(Command.KEEP_MTF, Command.ROTATE_WITH_CONSTANT_SPEED, Command.DRILL_DIRECTLY, Command.TURN_ON_AZIMUTH))
            {
                var i = new SmartInt();
                return(new RequestInfo(deviceId, request, new EntityDescriptor[]
                {
                    new EntityDescriptor("Inc", i, i.Add(2).DValue, DataEntityFormat.INT16),
                    new EntityDescriptor("Azi", i, i.Add(2).DValue, DataEntityFormat.INT16),
                    new EntityDescriptor("MTF", i, i.Add(2).DValue, DataEntityFormat.INT16),
                }));
            }
            else if (info == (RUSDeviceId.LWD_LINK, Command.PBP_SETTINGS))
            {
                return(new RequestInfo(deviceId, request, new EntityDescriptor[]
                {
                    new EntityDescriptor("Количество секторов", 0, 1, DataEntityFormat.UINT8),
                    new EntityDescriptor("Время молчания", 1, 1, DataEntityFormat.UINT8)
                }));
            }
Example #11
0
 internal static SalachovRequest CreateWriteRequest(RUSDeviceId deviceId, Command address, IEnumerable <IDataEntity> data, DeviceOperationScope scope)
 {
     return(new SalachovRequest(deviceId, address, true,
                                address.GetInfo().WriteResponse.GetInfo().FullResponseLength, data, scope));
 }
Example #12
0
 internal static SalachovRequest CreateReadRequest(RUSDeviceId deviceId, Command address, DeviceOperationScope scope)
 {
     return(new SalachovRequest(deviceId, address, false,
                                address.GetInfo().ReadResponse.GetInfo().FullResponseLength, new DataEntity[0], scope));
 }
Example #13
0
 public FileSaver(RUSDeviceId deviceId, IFileExtensionFactory extensionFactory)
 {
     _deviceId         = deviceId;
     _extensionFactory = extensionFactory;
 }
Example #14
0
 SalachovRequest(RUSDeviceId deviceId, Command address, bool isWriteRequest, ResponseLength responseLength, DeviceOperationScope scope)
     : this(deviceId, address, isWriteRequest, responseLength, new IDataEntity[0], scope)
 {
 }
Example #15
0
        static Files()
        {
            var         pos     = new SmartInt();
            var         dpedPos = new SmartInt();
            RUSDeviceId id      = 0;
            string      name    = null;

            var descriptors = new Dictionary <FileDescriptorsTarget, FileStructure>();

            BaseFileTemplate = new FBED[]
            {
                new FBED("Краткое название прибора", pos, pos.Add(8).DValue, DataEntityFormat.ASCII_STRING, FileEntityType.ANOTHER),
                new FBED("Модификация", pos, pos.Add(2), DataEntityFormat.ASCII_STRING, FileEntityType.MODIFICATION),
                new FBED("Версия ПО или пакета данных", pos, pos.Add(2).DValue, DataEntityFormat.ASCII_STRING, FileEntityType.FORMAT_VERSION),
                new FBED("Дата составления файла", pos, pos.Add(2).DValue, DataEntityFormat.ASCII_STRING, FileEntityType.BURN_DAY),
                new FBED("Месяц составления файла", pos, pos.Add(2).DValue, DataEntityFormat.ASCII_STRING, FileEntityType.BURN_MONTH),
                new FBED("Год составления файла", pos, pos.Add(2).DValue, DataEntityFormat.ASCII_STRING, FileEntityType.BURN_YEAR),
                new FBED("Указатель типа файла", pos, pos.Add(2).DValue, DataEntityFormat.ASCII_STRING, FileEntityType.FILE_TYPE_POINTER),
                new FBED("Серийный номер прибора", pos, pos.Add(2).DValue, DataEntityFormat.UINT16, FileEntityType.SERIAL_NUMBER),
            };

            #region Telemetry 0b00000001

            name      = "________";
            id        = RUSDeviceId.TELEMETRY;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);
            registerStandard(FileType.CALIBRATION);
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            #endregion

            #region RUSModule 0b00000010

            name      = "________";
            id        = RUSDeviceId.RUS_MODULE;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);
            registerStandard(FileType.CALIBRATION);
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            #endregion

            #region DriveControll 0b00000110

            name      = "________";
            id        = RUSDeviceId.DRIVE_CONTROL;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);
            registerStandard(FileType.CALIBRATION);
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            #endregion

            #region Telesystem 0b00001000

            name      = "________";
            id        = RUSDeviceId.TELESYSTEM;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);
            registerStandard(FileType.CALIBRATION);
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            #endregion

            #region RUSEMCModule 0b01010000

            name      = "EMC_Mdl_";
            id        = RUSDeviceId.EMC_MODULE;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);
            registerStandard(FileType.CALIBRATION);
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            #endregion

            #region TechnologicalModule 0b00001000

            name      = "TexModul";
            id        = RUSDeviceId.RUS_TECHNOLOGICAL_MODULE;
            pos.Value = 0;

            {
                pos.Value = 0;
                var v01Target = new FileDescriptorsTarget(FileType.FACTORY_SETTINGS, "01", id);
                var v01       = new Enumerable <FED>
                {
                    createHeader(name, FileType.FACTORY_SETTINGS.GetInfo().FileTypePointerName),
                    new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue]),
                    new FED("Массив UInt8[36]", pos, pos.Add(36).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue]),
                }.ToArray();

                descriptors.Add(v01Target, new FileStructure(v01));
            }
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            {
                pos.Value = 0;
                var v01CalibrationTarget
                    = new FileDescriptorsTarget(FileType.CALIBRATION, "01", id);
                var v01Calibration = new Enumerable <FED>
                {
                    createHeader(name, FileType.CALIBRATION.GetInfo().FileTypePointerName),
                    new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue]),
                    new FED("Калибровки", pos, pos.Add(36).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue]),
                }.ToArray();

                descriptors.Add(v01CalibrationTarget, new FileStructure(v01Calibration));
            }

            {
                pos.Value = 0;
                var v01TemperatureCalibrationTarget
                    = new FileDescriptorsTarget(FileType.TEMPERATURE_CALIBRATION, "01", id);
                var v01TemperatureCalibration = new Enumerable <FED>
                {
                    createHeader(name, FileType.TEMPERATURE_CALIBRATION.GetInfo().FileTypePointerName),
                    new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue]),
                    new FED("Калибровки", pos, pos.Add(36).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue]),
                }.ToArray();

                descriptors.Add(v01TemperatureCalibrationTarget, new FileStructure(v01TemperatureCalibration));
            }

            pos.Value = 0;
            var v01CalibrationFileForTechnologicalModuleTarget
                = new FileDescriptorsTarget(FileType.WORK_MODE, "01", id);
            var v01CalibrationFileForTechnologicalModule = new Enumerable <FED>
            {
                createHeader(name, FileType.WORK_MODE.GetInfo().FileTypePointerName),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Режим работы", pos, pos.Add(36).DValue, DataEntityFormat.BYTE_ARRAY, new byte[pos.DValue])
            }.ToArray();

            descriptors.Add(v01CalibrationFileForTechnologicalModuleTarget, new FileStructure(v01CalibrationFileForTechnologicalModule));

            #endregion

            #region RUSLWDLink 0b00001001

            name      = "SNAPUNIT";
            id        = RUSDeviceId.LWD_LINK;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);
            registerStandard(FileType.CALIBRATION);
            registerStandard(FileType.DATA_PACKET_CONFIGURATION);
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            #endregion

            #region ShockSensor 0b00000101

            name = "SHOCK___";
            id   = RUSDeviceId.SHOCK_SENSOR;

            registerStandard(FileType.FACTORY_SETTINGS);

            pos.Value = 0;
            var v01DataPacketConfigurationFileForShockSensorTarget
                = new FileDescriptorsTarget(FileType.DATA_PACKET_CONFIGURATION, "01", id);
            var v01DataPacketConfigurationFileForShockSensor = new Enumerable <FED>
            {
                createHeader(name, "F_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Массив описаний пакета данных", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.DATA_PACKET_ENTITIES_ARRAY,
                        new DataPacketEntityDescriptor[]
                {
                    new DataPacketEntityDescriptor("SH5O", 2, 1, false),
                    new DataPacketEntityDescriptor("SH1O", 2, 3, false),
                    new DataPacketEntityDescriptor("SH2O", 2, 5, false),
                    new DataPacketEntityDescriptor("SH3O", 2, 7, false),
                    new DataPacketEntityDescriptor("SH5R", 2, 9, false),
                    new DataPacketEntityDescriptor("SH1R", 2, 11, false),
                    new DataPacketEntityDescriptor("SH2R", 2, 13, false),
                    new DataPacketEntityDescriptor("SH3R", 2, 15, false),
                    new DataPacketEntityDescriptor("ARAD", 2, 17, false),
                    new DataPacketEntityDescriptor("AOSV", 2, 19, false),
                }),
            }.ToArray();
            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            pos.Value = 0;
            var v01CalibrationFileForShockSensorTarget
                = new FileDescriptorsTarget(FileType.CALIBRATION, "01", id);
            var v01CalibrationFileForShockSensor = new Enumerable <FED>
            {
                createHeader(name, "K_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Калибровки", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.CALIBRATION_PACKET_ENTITIES_ARRAY,
                        new CalibrationFileEntity[]
                {
                    CalibrationFileEntity.CreateConstantsTable("G0_", DataTypes.UINT16, new ushort[] { 517, 517, 517 }),
                    CalibrationFileEntity.CreateConstantsTable("POR_", DataTypes.UINT16, new ushort[] { 41, 82, 164, 246 }),
                    CalibrationFileEntity.CreateConstantsTable("TMR", DataTypes.UINT16, new ushort[] { 2 }),
                }),
            }.ToArray();


            descriptors.Add(v01CalibrationFileForShockSensorTarget, new FileStructure(v01CalibrationFileForShockSensor));
            descriptors.Add(v01DataPacketConfigurationFileForShockSensorTarget, new FileStructure(v01DataPacketConfigurationFileForShockSensor));

            #endregion

            #region RotationSensor 0b00000111

            name          = "Bl_Gyro_";
            id            = RUSDeviceId.ROTATIONS_SENSOR;
            pos.Value     = 0;
            dpedPos.Value = 1;

            registerStandard(FileType.FACTORY_SETTINGS);

            pos.Value = 0;
            var v01DataPacketConfigurationFileForRotationSensorTarget
                = new FileDescriptorsTarget(FileType.DATA_PACKET_CONFIGURATION, "01", id);
            var v01DataPacketConfigurationFileForRotationSensor = new Enumerable <FED>
            {
                createHeader(name, "F_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Массив описаний пакета данных", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.DATA_PACKET_ENTITIES_ARRAY,
                        new DataPacketEntityDescriptor[]
                {
                    new DataPacketEntityDescriptor("STAT", dpedPos.Add(2).DValue, dpedPos.PreviousValue, false),
                    new DataPacketEntityDescriptor("SGY1", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                    new DataPacketEntityDescriptor("SRO1", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                    new DataPacketEntityDescriptor("ANG1", dpedPos.Add(2).DValue, dpedPos.PreviousValue, false),
                    new DataPacketEntityDescriptor("TEM1", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                    new DataPacketEntityDescriptor("SGY2", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                    new DataPacketEntityDescriptor("SRO2", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                    new DataPacketEntityDescriptor("ANG2", dpedPos.Add(2).DValue, dpedPos.PreviousValue, false),
                    new DataPacketEntityDescriptor("TEM2", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                    new DataPacketEntityDescriptor("ADSG", dpedPos.Add(2).DValue, dpedPos.PreviousValue, false),
                    new DataPacketEntityDescriptor("ADH1", dpedPos.Add(2).DValue, dpedPos.PreviousValue, false),
                    new DataPacketEntityDescriptor("ADH2", dpedPos.Add(2).DValue, dpedPos.PreviousValue, false),
                    new DataPacketEntityDescriptor("ADTM", dpedPos.Add(2).DValue, dpedPos.PreviousValue, true),
                }),
            }.ToArray();

            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            registerStandardCalibrationFile(CalibrationFileEntity.CreateConstantsTable("dTe", DataTypes.INT16, new short[] { 0 }));

            pos.Value = 0;
            var v01TemperatureCalibrationFileForRotationSensorTarget
                = new FileDescriptorsTarget(FileType.TEMPERATURE_CALIBRATION, "01", id);
            var v01TemperatureCalibrationFileForRotationSensor = new Enumerable <FED>
            {
                createHeader(name, "T_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Калибровки", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.CALIBRATION_PACKET_ENTITIES_ARRAY,
                        new CalibrationFileEntity[]
                {
                    CalibrationFileEntity.CreateArray("AH1", DataTypes.UINT16, Enumerable.Repeat((ushort)32498, 156).ToArray()),
                    CalibrationFileEntity.CreateArray("AH2", DataTypes.UINT16, Enumerable.Repeat((ushort)32715, 156).ToArray()),
                    CalibrationFileEntity.CreateArray("ASG", DataTypes.UINT16, Enumerable.Repeat((ushort)32809, 156).ToArray()),
                    CalibrationFileEntity.CreateArray("Kgy", DataTypes.FLOAT, Enumerable.Repeat((float)0.12947888, 156).ToArray())
                }),
            }.ToArray();

            descriptors.Add(v01DataPacketConfigurationFileForRotationSensorTarget, new FileStructure(v01DataPacketConfigurationFileForRotationSensor));
            descriptors.Add(v01TemperatureCalibrationFileForRotationSensorTarget, new FileStructure(v01TemperatureCalibrationFileForRotationSensor));

            #endregion

            #region Izmeritel 0b00000100

            name      = "Izmeritl";
            id        = RUSDeviceId.IZMERITEL;
            pos.Value = 0;

            registerStandard(FileType.FACTORY_SETTINGS);

            pos.Value = 0;
            var v01DataPacketConfigurationFileForIzmeritelTarget
                = new FileDescriptorsTarget(FileType.DATA_PACKET_CONFIGURATION, "01", id);
            var v01DataPacketConfigurationFileForIzmeritel = new Enumerable <FED>
            {
                createHeader(name, "F_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Массив описаний пакета данных", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.DATA_PACKET_ENTITIES_ARRAY,
                        new DataPacketEntityDescriptor[]
                {
                    new DataPacketEntityDescriptor("TimP", 2, 0x07, false),
                    new DataPacketEntityDescriptor("DD1_", 2, 0x09, false),
                    new DataPacketEntityDescriptor("DD2_", 2, 0x0B, false),
                    new DataPacketEntityDescriptor("TDD1", 2, 0x0D, false),
                    new DataPacketEntityDescriptor("TDD2", 2, 0x0F, false),
                    new DataPacketEntityDescriptor("TACD", 2, 0x11, false),
                    new DataPacketEntityDescriptor("+INC", 2, 0x13, false),
                    new DataPacketEntityDescriptor("-INC", 2, 0x14, false),
                    new DataPacketEntityDescriptor("GK__", 2, 0x15, false),
                    new DataPacketEntityDescriptor("TIME", 2, 0x17, false),
                    new DataPacketEntityDescriptor("URTC", 2, 0x19, false),
                    new DataPacketEntityDescriptor("REZ_", 2, 0x1B, false),
                    new DataPacketEntityDescriptor("SerN", 2, 0x23, false),
                }),
            }.ToArray();

            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            registerStandard(FileType.CALIBRATION);

            descriptors.Add(v01DataPacketConfigurationFileForIzmeritelTarget, new FileStructure(v01DataPacketConfigurationFileForIzmeritel));

            #endregion

            #region Inclinometr 0b00000011

            name          = "INCL____";
            id            = RUSDeviceId.INCLINOMETR;
            pos.Value     = 0;
            dpedPos.Value = 1;

            registerStandard(FileType.FACTORY_SETTINGS);

            pos.Value = 0;
            var v01DataPacketConfigurationFileForInclinometrTarget
                = new FileDescriptorsTarget(FileType.DATA_PACKET_CONFIGURATION, "01", id);
            var v01DataPacketConfigurationFileForInclinometr = new Enumerable <FED>
            {
                createHeader("INCL____", "F_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Массив описаний пакета данных", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.DATA_PACKET_ENTITIES_ARRAY,
                        new DataPacketEntityDescriptor[]
                {
                    new DataPacketEntityDescriptor("STAT", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("INC_", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("GTF_", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("MTF_", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("AZI_", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("DIP_", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("GTOT", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("BTOT", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("GCNT", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("Taks", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("Tmag", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("XGrp", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("YGrp", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("ZGrp", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("XMrp", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("YMrp", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("ZMrp", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("XGad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("YGad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("ZGad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("XMad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("YMad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("ZMad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x8F),
                    new DataPacketEntityDescriptor("TGad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("Tmad", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("UHV_", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("UHAL", dpedPos.Add(2).DValue, dpedPos.PreviousValue, 0x10),
                    new DataPacketEntityDescriptor("RSRV", dpedPos.Add(2).DValue, 59, 0x10),
                }),
            }.ToArray();

            registerStandard(FileType.FLASH_DATA_PACKET_CONFIGURATION);

            registerStandard(FileType.CALIBRATION);

            pos.Value = 0;
            var v01TemperatureCalibrationFileForInclinometrTarget
                = new FileDescriptorsTarget(FileType.TEMPERATURE_CALIBRATION, "01", id);
            var v01TemperatureCalibrationFileForInclinometr = new Enumerable <FED>
            {
                createHeader(name, "T_"),
                new FED("Резерв", pos, pos.Add(14).DValue, DataEntityFormat.BYTE_ARRAY, new byte[14]),
                new FED("Калибровки", pos, EntityLength.TILL_THE_END_OF_A_PACKET, DataEntityFormat.CALIBRATION_PACKET_ENTITIES_ARRAY, new CalibrationFileEntity[]
                {
                    CalibrationFileEntity.CreateLinearInterpolationTable("G1x", DataTypes.FLOAT, 140.Range().Select(_ => (0F, 1F)).ToArray()),
                    CalibrationFileEntity.CreateLinearInterpolationTable("G1y", DataTypes.FLOAT, 140.Range().Select(_ => (0F, 1F)).ToArray()),
                    CalibrationFileEntity.CreateLinearInterpolationTable("G1z", DataTypes.FLOAT, 140.Range().Select(_ => (0F, 1F)).ToArray()),
                    CalibrationFileEntity.CreateLinearInterpolationTable("M1x", DataTypes.FLOAT, 140.Range().Select(_ => (0F, 1F)).ToArray()),
                    CalibrationFileEntity.CreateLinearInterpolationTable("M1y", DataTypes.FLOAT, 140.Range().Select(_ => (0F, 1F)).ToArray()),
                    CalibrationFileEntity.CreateLinearInterpolationTable("M1z", DataTypes.FLOAT, 140.Range().Select(_ => (0F, 1F)).ToArray()),
                }),
Example #16
0
 public FileDescriptorsTarget(FileType fileType, string fileFormatVersion, RUSDeviceId targetDeviceId)
 {
     FileType          = fileType;
     FileFormatVersion = fileFormatVersion;
     TargetDeviceId    = targetDeviceId;
 }
 public RetranslatingMiddleware(RUSDeviceId parrentId)
 {
     _parrentId = parrentId;
 }
 public bool IsSupportedForDevice(RUSDeviceId deviceId)
 {
     return(_supportedDevices == null
         ? true
         : _supportedDevices.Contains(deviceId));
 }
Example #19
0
 internal RequestInfo(RUSDeviceId deviceId, Command address, EntityDescriptor[] descriptors)
     : this(deviceId, address, descriptors, descriptors.Length.Range(), _ => new IDataEntity[0])
 {
 }
Example #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileData"></param>
        /// <param name="fileType"></param>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        /// <exception cref="SerializationException"></exception>
        /// <exception cref="Exception"></exception>
        public IEnumerable <IDataEntity> Deserialize(string fileData, FileType fileType, RUSDeviceId deviceId)
        {
            var entries = parse().ToArray();

            validateFileTypePointer();
            var target      = getTarget();
            var descriptors = Files.Descriptors.Find(kvp => kvp.Key.Equals(target));

            if (!descriptors.Found)
            {
                throw new SerializationException("There were no appropriate descriptors found");
            }
            else
            {
                foreach (var descriptor in descriptors.Value.Value.Descriptors)
                {
                    var entry = entries.Find(e => e.Name == descriptor.Name);
                    if (!entry.Found)
                    {
                        throw new SerializationException($"The file isn't full. It lacks \"{descriptor.Name}\" entity.");
                    }
                    else
                    {
#warning doesn't work for all types..., bad code
                        if (descriptor.Length.IsTillTheEndOfAPacket &&
                            descriptor.ValueFormat == DataEntityFormat.ASCII_STRING)
                        {
                            var startOfEntityIndex = fileData.Find(descriptor.Name).Index;
                            var startIndex         = fileData
                                                     .Skip(startOfEntityIndex)
                                                     .Find(KVP_SEPARATOR)
                                                     .Index + startOfEntityIndex + KVP_SEPARATOR.Length;
                            var multilineValue = fileData.Skip(startIndex).Aggregate();
                            if (multilineValue.Length % 2 == 1)
                            {
                                multilineValue += (char)0;
                            }

                            var value = (string)descriptor.DeserializeFromString(multilineValue);
                            if (value != descriptor.SerializeToString(value))
                            {
                                throw new SerializationException();
                            }

                            yield return(new DataEntity(value, descriptor.Serialize(value), descriptor));
                        }
                        else
                        {
                            var value    = descriptor.DeserializeFromString(entry.Value.SerializedValue);
                            var rawValue = descriptor.Serialize(value).ToArray();

                            if (!descriptor.Length.IsTillTheEndOfAPacket &&
                                rawValue.Length != descriptor.Length.Length)
                            {
                                throw new SerializationException($"Length for field \"{descriptor.Name}\" is not valid. Expected:{descriptor.Length.Length}, actual:{rawValue.Length}");
                            }

                            yield return(new DataEntity(value, rawValue, descriptor));
                        }
                    }
                }
            }

            /////////////////////////////////////////////////////

            FileDescriptorsTarget getTarget()
            {
                var version = getEntityValue(FileEntityType.FORMAT_VERSION);

                return(new FileDescriptorsTarget(fileType, version, deviceId));
            }

            void validateFileTypePointer()
            {
                var fileTypePtr = getEntityValue(FileEntityType.FILE_TYPE_POINTER);
                var expected    = fileType.GetInfo().FileTypePointerName;

                if (fileTypePtr != expected)
                {
                    throw new SerializationException($"FileTypePointer is not valid. Expected \"{expected}\", but was \"{fileTypePtr}\"");
                }
            }

            string getEntityValue(FileEntityType entityType)
            {
                var entry       = Files.BaseFileTemplate.Single(d => d.EntityType == entityType);
                var entityValue = entries.SingleOrDefault(e => e.Name == entry.Name).SerializedValue;

                if (entityValue == null)
                {
                    throw new SerializationException($"There was no \"{entityType}\" entity present.");
                }

                return(entityValue);
            }

            IEnumerable <(string Name, string SerializedValue)> parse()
            {
                var parsedLines = fileData
                                  .Split(Global.NL)
                                  .Select(tryParseLine)
                                  .SkipNulls()
                                  .Select(v => v.Value)
                                  .GroupBy(v => v.Name, v => v.SerializedValue);

                foreach (var entity in parsedLines)
                {
                    var isMultiline = entity.Key.EndsWith("[]");
                    var lines       = entity.ToArray();
                    if (!isMultiline && lines.Length > 1)
                    {
                        throw new SerializationException($"Не допускается наличие повторяющихся полей. Имя поля: \"{entity.Key}\"");
                    }
                    else
                    {
                        var name = isMultiline
                            ? entity.Key.SkipFromEnd(2).Aggregate()
                            : entity.Key;
                        var value = lines
                                    .Aggregate(Global.NL)
                                    .Aggregate();

                        yield return(name, value);
                    }
                }

                (string Name, string SerializedValue)? tryParseLine(string line)
                {
                    var values = line.Split(KVP_SEPARATOR, false);

                    if (values.Length >= 2)
                    {
                        var name  = values[0];
                        var value = values.Skip(1).Aggregate(KVP_SEPARATOR);

                        return(name, value);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Example #21
0
 public Section(RUSDeviceId deviceId, IDataPacketParser parser)
 {
     DeviceId = (byte)deviceId;
     Parser   = parser ?? throw new ArgumentNullException(nameof(parser));
 }
Example #22
0
 public static IRUSDevice InstantiateSpecificDevice(RUSDeviceId rusDevice, IRUSConnectionInterface connectionInterface)
 {
     return(InstantiateSupported(connectionInterface).Single(d => d.Id == rusDevice));
 }
Example #23
0
 public IFileExtension GetExtension(RUSDeviceId deviceId, FileType fileType)
 {
     return(new FileExtension(deviceId, fileType));
 }