void ParseMain(MainItemTag tag, uint value)
        {
            LocalIndexes indexes = null;

            switch (tag)
            {
            case MainItemTag.Collection:
                ReportCollection collection = new ReportCollection();
                collection.Parent = CurrentCollection;
                collection.Type   = (CollectionType)value;
                CurrentCollection = collection;
                indexes           = collection.Indexes;
                break;

            case MainItemTag.EndCollection:
                CurrentCollection = CurrentCollection.Parent;
                break;

            case MainItemTag.Input:
            case MainItemTag.Output:
            case MainItemTag.Feature:
                ParseDataMain(tag, value, out indexes);
                break;
            }

            if (indexes != null)
            {
                ParseMainIndexes(indexes);
            }
        }
        void ParseDataMain(MainItemTag tag, uint value, out LocalIndexes indexes)
        {
            ReportSegment segment = new ReportSegment();

            segment.Flags        = (DataMainItemFlags)value;
            segment.Parent       = CurrentCollection;
            segment.ElementCount = (int)GetGlobalItemValue(GlobalItemTag.ReportCount);
            segment.ElementSize  = (int)GetGlobalItemValue(GlobalItemTag.ReportSize);
            segment.Unit         = new Units.Unit(GetGlobalItemValue(GlobalItemTag.Unit));
            segment.UnitExponent = Units.Unit.DecodeExponent(GetGlobalItemValue(GlobalItemTag.UnitExponent));
            indexes = segment.Indexes;

            EncodedItem logicalMinItem = GetGlobalItem(GlobalItemTag.LogicalMinimum);
            EncodedItem logicalMaxItem = GetGlobalItem(GlobalItemTag.LogicalMaximum);

            segment.LogicalIsSigned =
                (logicalMinItem != null && logicalMinItem.DataValueMayBeNegative) ||
                (logicalMaxItem != null && logicalMaxItem.DataValueMayBeNegative);
            int logicalMinimum  = logicalMinItem == null ? 0 : segment.LogicalIsSigned ? logicalMinItem.DataValueSigned : (int)logicalMinItem.DataValue;
            int logicalMaximum  = logicalMaxItem == null ? 0 : segment.LogicalIsSigned ? logicalMaxItem.DataValueSigned : (int)logicalMaxItem.DataValue;
            int physicalMinimum = (int)GetGlobalItemValue(GlobalItemTag.PhysicalMinimum);
            int physicalMaximum = (int)GetGlobalItemValue(GlobalItemTag.PhysicalMaximum);

            if (!IsGlobalItemSet(GlobalItemTag.PhysicalMinimum) ||
                !IsGlobalItemSet(GlobalItemTag.PhysicalMaximum) ||
                (physicalMinimum == 0 && physicalMaximum == 0))
            {
                physicalMinimum = logicalMinimum;
                physicalMaximum = logicalMaximum;
            }

            segment.LogicalMinimum  = logicalMinimum;
            segment.LogicalMaximum  = logicalMaximum;
            segment.PhysicalMinimum = physicalMinimum;
            segment.PhysicalMaximum = physicalMaximum;

            Report     report;
            ReportType reportType
                = tag == MainItemTag.Output ? ReportType.Output
                : tag == MainItemTag.Feature ? ReportType.Feature
                : ReportType.Input;
            uint reportID = GetGlobalItemValue(GlobalItemTag.ReportID);

            if (!TryGetReport(reportType, (byte)reportID, out report))
            {
                report = new Report()
                {
                    ID   = (byte)reportID,
                    Type = reportType
                };
                Reports.Add(report);
            }
            segment.Report = report;
        }
Exemplo n.º 3
0
        void ParseMainIndexes(LocalIndexes indexes)
        {
            int         delimiter = 0;
            List <uint> designatorValues = new List <uint>(); IndexBase designator = IndexBase.Unset;
            List <uint> stringValues = new List <uint>(); IndexBase @string = IndexBase.Unset;
            List <uint> usageValues = new List <uint>(); IndexBase usage = IndexBase.Unset;

            foreach (KeyValuePair <LocalItemTag, uint> kvp in LocalItemState)
            {
                switch (kvp.Key)
                {
                case LocalItemTag.DesignatorMinimum: UpdateIndexMinimum(ref designator, kvp.Value); break;

                case LocalItemTag.StringMinimum: UpdateIndexMinimum(ref @string, kvp.Value); break;

                case LocalItemTag.UsageMinimum: UpdateIndexMinimum(ref usage, kvp.Value); break;

                case LocalItemTag.DesignatorMaximum: UpdateIndexMaximum(ref designator, kvp.Value); break;

                case LocalItemTag.StringMaximum: UpdateIndexMaximum(ref @string, kvp.Value); break;

                case LocalItemTag.UsageMaximum: UpdateIndexMaximum(ref usage, kvp.Value); break;

                case LocalItemTag.DesignatorIndex: UpdateIndexList(designatorValues, delimiter, ref designator, kvp.Value); break;

                case LocalItemTag.StringIndex: UpdateIndexList(stringValues, delimiter, ref @string, kvp.Value); break;

                case LocalItemTag.Usage: UpdateIndexList(usageValues, delimiter, ref usage, kvp.Value); break;

                case LocalItemTag.Delimiter:
                    if (kvp.Value == 1)
                    {
                        if (delimiter++ == 0)
                        {
                            designatorValues.Clear();
                            stringValues.Clear();
                            usageValues.Clear();
                        }
                    }
                    else if (kvp.Value == 0)
                    {
                        delimiter--;
                        UpdateIndexListCommit(designatorValues, delimiter, ref designator);
                        UpdateIndexListCommit(stringValues, delimiter, ref @string);
                        UpdateIndexListCommit(usageValues, delimiter, ref usage);
                    }
                    break;
                }
            }

            indexes.Designator = designator;
            indexes.String     = @string;
            indexes.Usage      = usage;
        }
        void ParseDataMain(MainItemTag tag, uint value, out LocalIndexes indexes)
        {
            ReportSegment segment = new ReportSegment();
            segment.Flags = (DataMainItemFlags)value;
            segment.Parent = CurrentCollection;
            segment.ElementCount = (int)GetGlobalItemValue(GlobalItemTag.ReportCount);
            segment.ElementSize = (int)GetGlobalItemValue(GlobalItemTag.ReportSize);
            segment.Unit = new Units.Unit(GetGlobalItemValue(GlobalItemTag.Unit));
            segment.UnitExponent = Units.Unit.DecodeExponent(GetGlobalItemValue(GlobalItemTag.UnitExponent));
            indexes = segment.Indexes;

            EncodedItem logicalMinItem = GetGlobalItem(GlobalItemTag.LogicalMinimum);
            EncodedItem logicalMaxItem = GetGlobalItem(GlobalItemTag.LogicalMaximum);
            segment.LogicalIsSigned =
                (logicalMinItem != null && logicalMinItem.DataValueMayBeNegative) ||
                (logicalMaxItem != null && logicalMaxItem.DataValueMayBeNegative);
            int logicalMinimum = logicalMinItem == null ? 0 : segment.LogicalIsSigned ? logicalMinItem.DataValueSigned : (int)logicalMinItem.DataValue;
            int logicalMaximum = logicalMaxItem == null ? 0 : segment.LogicalIsSigned ? logicalMaxItem.DataValueSigned : (int)logicalMaxItem.DataValue;
            int physicalMinimum = (int)GetGlobalItemValue(GlobalItemTag.PhysicalMinimum);
            int physicalMaximum = (int)GetGlobalItemValue(GlobalItemTag.PhysicalMaximum);
            if (!IsGlobalItemSet(GlobalItemTag.PhysicalMinimum) ||
                !IsGlobalItemSet(GlobalItemTag.PhysicalMaximum) ||
                (physicalMinimum == 0 && physicalMaximum == 0))
            {
                physicalMinimum = logicalMinimum; physicalMaximum = logicalMaximum;
            }

            segment.LogicalMinimum = logicalMinimum; segment.LogicalMaximum = logicalMaximum;
            segment.PhysicalMinimum = physicalMinimum; segment.PhysicalMaximum = physicalMaximum;

            Report report;
            ReportType reportType
                = tag == MainItemTag.Output ? ReportType.Output
                : tag == MainItemTag.Feature ? ReportType.Feature
                : ReportType.Input;
            uint reportID = GetGlobalItemValue(GlobalItemTag.ReportID);
            if (!TryGetReport(reportType, (byte)reportID, out report))
            {
                report = new Report() { ID = (byte)reportID, Type = reportType };
                Reports.Add(report);
            }
            segment.Report = report;
        }
        void ParseMainIndexes(LocalIndexes indexes)
        {
            int delimiter = 0;
            List<uint> designatorValues = new List<uint>(); IndexBase designator = IndexBase.Unset;
            List<uint> stringValues = new List<uint>(); IndexBase @string = IndexBase.Unset;
            List<uint> usageValues = new List<uint>(); IndexBase usage = IndexBase.Unset;

            foreach (KeyValuePair<LocalItemTag, uint> kvp in LocalItemState)
            {
                switch (kvp.Key)
                {
                    case LocalItemTag.DesignatorMinimum: UpdateIndexMinimum(ref designator, kvp.Value); break;
                    case LocalItemTag.StringMinimum: UpdateIndexMinimum(ref @string, kvp.Value); break;
                    case LocalItemTag.UsageMinimum: UpdateIndexMinimum(ref usage, kvp.Value); break;

                    case LocalItemTag.DesignatorMaximum: UpdateIndexMaximum(ref designator, kvp.Value); break;
                    case LocalItemTag.StringMaximum: UpdateIndexMaximum(ref @string, kvp.Value); break;
                    case LocalItemTag.UsageMaximum: UpdateIndexMaximum(ref usage, kvp.Value); break;

                    case LocalItemTag.DesignatorIndex: UpdateIndexList(designatorValues, delimiter, ref designator, kvp.Value); break;
                    case LocalItemTag.StringIndex: UpdateIndexList(stringValues, delimiter, ref @string, kvp.Value); break;
                    case LocalItemTag.Usage: UpdateIndexList(usageValues, delimiter, ref usage, kvp.Value); break;

                    case LocalItemTag.Delimiter:
                        if (kvp.Value == 1)
                        {
                            if (delimiter++ == 0)
                            {
                                designatorValues.Clear();
                                stringValues.Clear();
                                usageValues.Clear();
                            }
                        }
                        else if (kvp.Value == 0)
                        {
                            delimiter--;
                            UpdateIndexListCommit(designatorValues, delimiter, ref designator);
                            UpdateIndexListCommit(stringValues, delimiter, ref @string);
                            UpdateIndexListCommit(usageValues, delimiter, ref usage);
                        }
                        break;
                }
            }

            indexes.Designator = designator;
            indexes.String = @string;
            indexes.Usage = usage;
        }
Exemplo n.º 6
0
 public ReportMainItem()
 {
     Indexes = new LocalIndexes();
 }
Exemplo n.º 7
0
 public ReportMainItem()
 {
     Indexes = new LocalIndexes();
 }