Пример #1
0
        public static AstDescriptionBlock ReadAsAstDescriptionBlock(this AstFile astFile, string groupName)
        {
            var astDeviceParams =
                astFile.DescriptionBlocks.Items.OfType <AstDescriptionBlock>()
                .SingleOrDefault(x => x.GroupName.Equals(groupName, StringComparison.OrdinalIgnoreCase));

            if (astDeviceParams == null)
            {
                throw new ParserContextErrorException(
                          $"Could not find Description Block with group name of \"{groupName}\"");
            }

            return(astDeviceParams);
        }
Пример #2
0
        private static RobConstants ReadRobConstants(AstFile astFile)
        {
            var astConstants = astFile.ReadAsAstDescriptionBlock("PROCONST2");
            var variables    = astConstants.Variables;

            var robConstants = new RobConstants()
            {
                Header = new RobConstantsHeader()
                {
                    Reserved0             = astConstants.Headers.ReadAsInt(0),
                    RamBlockAddressOffset = astConstants.Headers.ReadAsInt(1),
                },
                Parameters = ReadRobParameters(variables),
            };

            return(robConstants);
        }
Пример #3
0
        private static List <RobRomText> ReadRomTexts(AstFile astFile)
        {
            var result        = new List <RobRomText>();
            var romTextBlocks =
                astFile.DescriptionBlocks.Items.Cast <AstDescriptionBlock>()
                .Where(x => x.GroupName.Equals("ROMTEXT", StringComparison.OrdinalIgnoreCase));

            foreach (var source in romTextBlocks)
            {
                var headers = source.Headers;
                result.Add(new RobRomText()
                {
                    Description = headers.ReadAsText(0),
                    Label       = headers.ReadAsText(1),
                    Address     = headers.ReadAsInt(2),
                    TextType    = headers.ReadAsInt(3),
                    MaxLength   = headers.ReadAsInt(4),
                });
            }

            return(result);
        }
Пример #4
0
        private static RobDeviceParams ReadRobDeviceParams(AstFile astFile, RobControlUnitType controlUnitType)
        {
            var astDeviceParams = astFile.ReadAsAstDescriptionBlock("DEVPARAM");

            RobDeviceParams robDeviceParams;
            var             headers = astDeviceParams.Headers;

            if (controlUnitType.HasFlag(RobControlUnitType.CAN))
            {
                // DEVPARAM layout seems to depend on the control unit type
                robDeviceParams = new RobCanDeviceParams()
                {
                    BaseAddressBinaryImage     = headers.ReadAsUInt(0),
                    BaseAddressMeasurementData = headers.ReadAsUInt(1),
                    CanCcpIdentifierDto        = headers.ReadAsInt(2),
                    CanCcpIdentifierCro        = headers.ReadAsInt(3),
                    AnalogOutput1Control       = headers.ReadAsInt(4),
                    AnalogOutput2Control       = headers.ReadAsInt(5),
                    AnalogOutput3Control       = headers.ReadAsInt(6),
                    AnalogOutput4Control       = headers.ReadAsInt(7),
                };
            }
            else if (controlUnitType.HasFlag(RobControlUnitType.ABUS))
            {
                throw new ParserContextErrorException(
                          "DEVPARAM not implemented for ABUS, need an example file to implement more.", astDeviceParams);
            }
            else
            {
                // ROM
                robDeviceParams = new RobRomDeviceParams()
                {
                    OffsetRomImage       = headers.ReadAsSeq(0).ReadAsInt(0),
                    OffsetProvariAddress = headers.ReadAsSeq(0).ReadAsInt(1),
                };
            }
            return(robDeviceParams);
        }
Пример #5
0
        private static List <RobCharacteristicMap> ReadCharacteristicMaps(AstFile astFile)
        {
            var results = new List <RobCharacteristicMap>();

            var astCharline = astFile.DescriptionBlocks.Items.OfType <AstCharacteristicMapBlock>();

            foreach (var descriptionBlock in astCharline)
            {
                var header = new RobCharacteristicMapHeader()
                {
                    Description  = descriptionBlock.Headers.ReadAsText(0),
                    Label        = descriptionBlock.Headers.ReadAsText(1),
                    AddressOfMap = descriptionBlock.Headers.ReadAsUInt(2),
                    Reserve3     = descriptionBlock.Headers.ReadAsInt(3),
                    Reserve4     = descriptionBlock.Headers.ReadAsInt(4),
                };

                var independantAxis = ReadRobIndependantAxis(descriptionBlock.IndependantAxis).ToList();
                var dependantAxis   = ReadRobDependantAxis(descriptionBlock.DependantAxis);

                RobCharacteristicMap robCharacteristicMap;
                switch (descriptionBlock.GroupName.ToUpperInvariant())
                {
                case "CHARLINE2":
                    robCharacteristicMap = new RobCharLine2()
                    {
                        Header = header,
                        UAxis  = independantAxis[0],
                        QAxis  = dependantAxis,
                    };
                    break;

                case "CHARMAP2":
                    robCharacteristicMap = new RobCharMap2()
                    {
                        Header = header,
                        UAxis  = independantAxis[0],
                        VAxis  = independantAxis[1],
                        QAxis  = dependantAxis,
                    };
                    break;

                case "CHARSPACE":
                    robCharacteristicMap = new RobCharSpace()
                    {
                        Header = header,
                        UAxis  = independantAxis[0],
                        VAxis  = independantAxis[1],
                        WAxis  = independantAxis[2],
                        QAxis  = dependantAxis,
                    };
                    break;

                default:
                    throw new ParserContextErrorException($"Unknown characteristic map type {descriptionBlock.GroupName}", descriptionBlock);
                }

                results.Add(robCharacteristicMap);
            }

            return(results);
        }