Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for ETSI CAM-ASN1 to Json Command #179

Open
patrizianeubauer opened this issue Apr 25, 2024 · 1 comment
Open

Example for ETSI CAM-ASN1 to Json Command #179

patrizianeubauer opened this issue Apr 25, 2024 · 1 comment

Comments

@patrizianeubauer
Copy link

Hi,

could you please provide an example, how to run your project to generate json files from the asn-files for example with your cam_pdu_descriptions_1_3_2.asn file?

Thank you!

Kind regards,
Patrizia

@nemesis03
Copy link

@patrizianeubauer
I also had trouble getting this to work. I found the following solution:
Get the current asn-file for CAM: https://forge.etsi.org/rep/ITS/asn1/cam_en302637_2/-/blob/master/CAM-PDU-Descriptions.asn (saved as "CAM-PDU-Descriptions.asn")
Get the ITS-Container in version v1.3.1: https://forge.etsi.org/rep/ITS/asn1/cdd_ts102894_2/-/blob/v1.3.1/ITS-Container.asn (saved as "ITS-Container.asn")

import base64
import asn1tools
files = ['CAM-PDU-Descriptions.asn','ITS-Container.asn']
cam = asn1tools.compile_files(files, 'uper')
s_base64="AgINl1aLXpNAWrOG4g4oO3viNCMMSDOWUFh5cKJYfgKWilc3/un/6iA//5RZgQJeAMyAFdjOAATwOlwGSsZwAVOB2WAyljOACewO/QGbMZwAT+B6eA0FjOACfwOhQGLsgAAS2BzOAwdjOACTwPHwGMsZwAUOB1iAy5jOACewOlQGbsZwAT+B4qAzZjOACqA="
cam.decode('CAM',base64.b64decode(s_base64))

The string s_base64 contains the base64 encoded ITS data (in my case exported from wireshark). It will return a python struct:
{'header': {'protocolVersion': 2, 'messageID': 2, 'stationID': 228021899}, 'cam': {'generationDeltaTime': 24211, 'camParameters': {'basicContainer': {'stationType': 5, 'referencePosition': {'latitude': 536301072, 'longitude': 100141535, 'positionConfidenceEllipse': {'semiMajorConfidence': 282, 'semiMinorConfidence': 280, 'semiMajorOrientation': 1572}, 'altitude': {'altitudeValue': 5650, 'altitudeConfidence': 'alt-005-00'}}}, 'highFrequencyContainer': ('basicVehicleContainerHighFrequency', {'heading': {'headingValue': 1943, 'headingConfidence': 6}, 'speed': {'speedValue': 1200, 'speedConfidence': 127}, 'driveDirection': 'forward', 'vehicleLength': {'vehicleLengthValue': 42, 'vehicleLengthConfidenceIndication': 'trailerPresenceIsUnknown'}, 'vehicleWidth': 18, 'longitudinalAcceleration': {'longitudinalAccelerationValue': -11, 'longitudinalAccelerationConfidence': 102}, 'curvature': {'curvatureValue': 1023, 'curvatureConfidence': 'unavailable'}, 'curvatureCalculationMode': 'unavailable', 'yawRate': {'yawRateValue': -4, 'yawRateConfidence': 'unavailable'}, 'accelerationControl': (b'\x80', 7), 'steeringWheelAngle': {'steeringWheelAngleValue': 0, 'steeringWheelAngleConfidence': 127}, 'lateralAcceleration': {'lateralAccelerationValue': 2, 'lateralAccelerationConfidence': 102}}), 'lowFrequencyContainer': ('basicVehicleContainerLowFrequency', {'vehicleRole': 'default', 'exteriorLights': (b'\x81', 8), 'pathHistory': [{'pathPosition': {'deltaLatitude': 205, 'deltaLongitude': 88, 'deltaAltitude': 0}, 'pathDeltaTime': 20}, {'pathPosition': {'deltaLatitude': 1868, 'deltaLongitude': 806, 'deltaAltitude': 0}, 'pathDeltaTime': 170}, {'pathPosition': {'deltaLatitude': 1894, 'deltaLongitude': 810, 'deltaAltitude': 0}, 'pathDeltaTime': 159}, {'pathPosition': {'deltaLatitude': 1919, 'deltaLongitude': 823, 'deltaAltitude': 0}, 'pathDeltaTime': 160}, {'pathPosition': {'deltaLatitude': 1960, 'deltaLongitude': 834, 'deltaAltitude': 0}, 'pathDeltaTime': 160}, {'pathPosition': {'deltaLatitude': 1859, 'deltaLongitude': 792, 'deltaAltitude': 100}, 'pathDeltaTime': 151}, {'pathPosition': {'deltaLatitude': 1844, 'deltaLongitude': 776, 'deltaAltitude': 0}, 'pathDeltaTime': 148}, {'pathPosition': {'deltaLatitude': 1936, 'deltaLongitude': 794, 'deltaAltitude': 0}, 'pathDeltaTime': 162}, {'pathPosition': {'deltaLatitude': 1881, 'deltaLongitude': 815, 'deltaAltitude': 0}, 'pathDeltaTime': 159}, {'pathPosition': {'deltaLatitude': 1867, 'deltaLongitude': 824, 'deltaAltitude': 0}, 'pathDeltaTime': 160}, {'pathPosition': {'deltaLatitude': 1931, 'deltaLongitude': 823, 'deltaAltitude': 0}, 'pathDeltaTime': 171}]})}}}

to export as JSON i issued the following commands

jer = asn1tools.compile_files(files, 'jer')
jer.encode('CAM', cam.decode('CAM',base64.b64decode(s_base64)))

Unfortunately there is an issue with the conversin of "accelerationControl" and "exteriorLights". The hex value from the struct ("\x80") is converted to a decimal value "80". So you have to be careful to treat this value as a hex value.

It is also possible to decode MAPEM and SPATEM messages. You only need the corresponding files:
https://forge.etsi.org/rep/ITS/asn1/is_ts103301/-/blob/release2/MAPEM-PDU-Descriptions.asn
https://forge.etsi.org/rep/ITS/asn1/is_ts103301/-/blob/release2/SPATEM-PDU-Descriptions.asn
https://forge.etsi.org/rep/ITS/asn1/is_ts103301/-/blob/release2/DSRC.asn
https://forge.etsi.org/rep/ITS/asn1/cdd_ts102894_2/-/blob/release2/ETSI-ITS-CDD.asn

import base64
import asn1tools
files = ['MAPEM-PDU-Descriptions.asn','DSRC.asn','ETSI-ITS-CDD.asn']
mapem = asn1tools.compile_files(files, 'uper')
s_base64="AgUA/6/iCAADCM2DQvyalO+wc33LJvfZrmMAAwOfAirOApE4oNpVAUUTJAEUIgAAOZtwWiKIAvOD7pCFixFQLbSPIXWUlwtMI3BZdxhjxyxQiZ1MVuPzxHrDo+KwdyRFD3GE4dywyDnWJBPeSPERYNAAAgKwggACAlhhAAEBrBEAAMEWFIAAYKIAxkRAAACvSn4XBHOABdXgE6mRAIQiAAAAmZHGYCCPiCGsBBKOvAljYBAMQgIQAAATMyDLrBFbBC92gk3SQSvrogCERAAAAK+vl7YEfYDTAoBpwXEAoiAhAAAAr5LX4gRWwNMCgGnBckAyQgAAAhfvq6AiAL7AYcFQMgJwmlyWxMDApjayFrRtwDig26JrQTOxFAmRg+iWEQABAMsCIABAlYMgAEhRIEkgEIAAAlmCzOmIgCrYGhQADMGKBfRaEz4S6JgUFAbWUtcNuCcXG3RNZCZ2InEyOH4KwyAAIB1gRAAIECAEJEQAAAs2369cEecH3SED35AJAU0IgAAiXnQ5/IgC2oAtqUJzpkkLip0kIL62gR6SQKLHwFgiADBwMBYn4AkDpiNRZdApbtAQuHQLvKAGIoYDF3mFeWyBs+8OYVu7RAwfZBa5qMLZ9sBcPqYLs9JhehsIMAuXhif/AEmfUGQOZgybxCGnfvAzRyEKenSMVFOvw6JetVFhRAAUFrBCAAoMWBQAAoasMQADQ5YQgAGh5IFogEIAAAtl9JmNogCrYJ35AEvZYCVNbFPN8oKdL1AVCX/45bW38cirC2OSFj3HJ2zfDkn5KBTpetCsKgACxBYMQAHCJIDohAAABTMOfNzRAF8QTh7oJn6kU83yQp0vTxUJf/jltbfxyKsLI5IePkcnbN6OSfkoFOl64SwYgAOElgSAAMJrBIAAsUBA1gQIAAADMzPEmQAEExPaCg4QFQQOYECAAAAy7Xx/kABAz0JgoNEBYED2BAgAAAL5K5ZkABAz8MAoQDBcEEGBAgAAAMxAKEdAAQTC9AKDwwYBBFgQIAAAC+IXk9AAQQxMIKEg8ZBBJgQIAAAC9z+7RAAQPQz4KEQ8aBBNgQIAAADNAa5QQAEELzCChQHGwQUYECAAAAzMoqm0ABA9LPgoTBxw"
mapem.decode('MAPEM',base64.b64decode(s_base64))
import base64
import asn1tools
files = ['SPATEM-PDU-Descriptions.asn','DSRC.asn','ETSI-ITS-CDD.asn']
spatem = asn1tools.compile_files(files, 'uper')
s_base64="AgQA/6/iRryZAYgAGBz4ECAGvJkU3A8gFkNxT/FSwVGGojioIKmIqOtRnFTsVbRVZakOKpQq+CrQ1DcWYhaUFoByI4szi0yLQrkZxajFtUWwXAAAkBMhuKf4qWCow1EcVBBUxFR1qK4qdiraKrLUd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uFq1qG4uQC7+LnzhAGwBwA=="
spatem.decode('SPATEM',base64.b64decode(s_base64))

You have to figure out whether your data is CAM or MAPEM or SPATEM.

An alternative might be to use tshark (e.g. "tshark -r dump.pcap -T json"). The advantage is that some values are split into their meaning:

                  "cam.accelerationControl": "40",
                  "cam.accelerationControl_tree": {
                    "its.AccelerationControl.brakePedalEngaged": "0",
                    "its.AccelerationControl.gasPedalEngaged": "1",
                    "its.AccelerationControl.emergencyBrakeEngaged": "0",
                    "its.AccelerationControl.collisionWarningEngaged": "0",
                    "its.AccelerationControl.accEngaged": "0",
                    "its.AccelerationControl.cruiseControlEngaged": "0",
                    "its.AccelerationControl.speedLimiterEngaged": "0"
                  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants