如何在 C 中打印 ASN.1 UPER 消息字段的字段?
How to print field of an ASN.1 UPER message field in C?
我收到以下消息。这是在 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,
subCauseCode 0
},
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);
我收到以下消息。这是在 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,
subCauseCode 0
},
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);