如何在C中打印ASN.1 UPER消息字段的字段?

问题描述

我有以下消息。这是在 https://asn1.io/asn1playground/ 上创建的基本 ASN.1 Uper 消息。我想使用单个字段进行操作。例如我想打印协议版本。我能怎么做?我可以写 DENM.header.protocol versione 吗?我真的不知道:

value1 DENM ::= {
  header {
    protocolVersion 1,messageID denm,stationID 1234567
  },denm {
    management {
      actionID {
        originatingStationID 20,sequenceNumber 30
      },detectionTime 45000000000,referenceTime oneMillisecAfterUTCStartOf2004,eventPosition {
        latitude 40487111,longitude -79494789,positionConfidenceEllipse {
          semiMajorConfidence 500,semiMinorConfidence 400,semiMajorOrientation 10
        },altitude {
          altitudeValue 2000,altitudeConfidence alt-000-02
        }
      },validityDuration 600,transmissionInterval oneMilliSecond,stationType unkNown
    },situation {
      informationQuality lowest,eventType {
        causeCode roadworks,subCauseCode 0
      }
    },location {
      eventSpeed {
        speedValue standstill,speedConfidence equalOrWithinOneCentimeterPerSec
      },eventPositionheading {
        headingValue wgs84north,headingConfidence equalOrWithinOneDegree
      },traces {
        {
          {
            pathPosition {
              deltaLatitude 20,deltaLongitude 20,deltaAltitude unavailable
            },pathDeltaTime tenMilliSecondsInPast
          },{
            pathPosition {
              deltaLatitude 22,deltaLongitude 22,deltaAltitude unavailable
            }
          }
        }
      },roadType urban-NoStructuralSeparationToOppositeLanes
    },alacarte {
      impactReduction {
        heightLonCarrLeft oneCentimeter,heightLonCarrRight oneCentimeter,poslonCarrLeft oneCentimeter,poslonCarrRight oneCentimeter,positionOfPillars {
          tenCentimeters
        },posCentMass unavailable,wheelBaseVehicle tenCentimeters,turningRadius point4Meters,posFrontAx tenCentimeters,positionOfOccupants '11111110000000100001'B,vehicleMass 20,requestResponseIndication response
      },externalTemperature oneDegreeCelsius,roadWorks {
        lightBarsirenInUse '11'B,closedLanes {
          innerhardShoulderStatus availableForStopping,drivingLanestatus '011'B
        },restriction {
          unkNown
        },speedLimit 20,incidentIndication {
          causeCode reserved,subCauseCode 0
        },recommendedpath {
          {
            latitude 20,longitude 20,positionConfidenceEllipse {
              semiMajorConfidence oneCentimeter,semiMinorConfidence oneCentimeter,semiMajorOrientation wgs84north
            },altitude {
              altitudeValue 200,altitudeConfidence alt-000-02
            }
          }
        }
      },positioningSolution nopositioningSolution,stationaryVehicle {
        stationarySince equalOrGreater15Minutes,stationaryCause {
          causeCode roadworks,numberOfOccupants 30,vehicleIdentification {
          wMInumber "WVW",vDS "ZZZ1JZ"
        },energyStorageType '0000010'B
      }
    }
  }
}

如何在 C 中打印“PROTOCOL VERSION”字段?感谢您的帮助!

解决方法

该网站具有三个基本区域。左侧是您的架构所在的位置。中间区域是您放置问题中包含的 ASN.1 值的位置。右侧是网站输出 ASN.1 可以为该 ASN.1 值创建的各种不同的线路格式(或编码)的地方。十六进制只是呈现为十六进制数字对的二进制输出。

您需要做的是使用您自己的 ASN.1 编译器来编译模式,例如 this one。这将为您提供大量 C 源代码,其中一些是编译器的库代码,还有一些是编译器生成的,用于将您的模式表示为 C 结构的层次结构。那里将有一个例程,用于从包含该 ASN.1 值的 uPER 编码的二进制文件解码 DENM。

一旦你掌握了这一点,编写一个程序来调用那个 DENM uPER 解码器,然后 printf("%i\n",denm.header.protocolVersion);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...