How fzi-forschungszentrum-informatik/cohda_v2x_driver works
Project type and its purpose
• This is a Python “driver” library for interacting with COHDA MK6 devices over the BTP (Binary Transport Protocol).
• It provides message-encoding/decoding for ETSI V2X PDUs (CAM, CPM, MAPEM, SPATEM) based on ASN.1 specs.
• Example scripts demonstrate how to send/receive these messages.
Main components
a. Examples Layer
– cam_handler_mk6.py, cpm_handler_mk6.py, mapem_handler_mk6.py
– Configuration files under examples/conf (e.g., rsu.conf)
b. Driver Library (package: cohda_driver)
– Entry point: driver.py (initializes BTP connection, loads config)
– btp_request.py (wraps outgoing PDUs into BTP requests)
– btp_indication.py (parses incoming BTP indications)
– common_header.py (shared ASN.1 header logic)
– etsi_message_type.py (enumerates ETSI message types)
– logger.py (colorlog-based logging)
– etsi_messages/*.py (CAM, CPM, MAPEM, SPATEM message classes)
c. ASN.1 Repository
– asn1/… (multiple .asn files for CAM, CPM, MAPEM, SPATEM under their respective folders)
d. ASN.1 Parser
– asn1tools library (runtime dependency)
– dataclasses-struct (for C-struct-like dataclasses)
e. COHDA MK6 Device
– Physical or simulated device reachable over network/serial port
f. External Dependencies
– Python packages (asn1tools, colorlog, dataclasses-struct)
– ETSI ASN.1 specifications
Relationships and data flows
1. Examples → Driver Library
• The user runs an example script; it loads a config file and instantiates driver.py
2. Driver Library ↔ COHDA MK6 Device
• driver.py uses BTP connection to send/receive raw bytes
3. Driver Library → ASN.1 Parser
• Outgoing: btp_request.py hands off an ETSI PDU (Python dataclass) to asn1tools for encoding
• Incoming: btp_indication.py receives raw bytes, calls asn1tools to decode into Python objects
4. Driver Library → Application Layer
• Parsed messages are exposed back to the example script via callbacks or return values
Architectural patterns and principles
• Layered architecture:
– Presentation (Examples)
– Application (Driver API)
– Integration (ASN.1 parser, BTP transport)
• Facade pattern: driver.py presents a simple interface over low-level BTP + ASN.1 complexity
• Separation of concerns: encoding/decoding logic lives in etsi_messages + asn1tools, transport logic in btp_*.py
Must-have elements
• Config files (.conf) feeding into driver initialization
[Examples Layer]
┌────────────────────────┐
│ cam_handler_mk6.py │
│ cpm_handler_mk6.py │
│ mapem_handler_mk6.py │
└───▲────────────────────┘
│ loads config rsu.conf
│ calls API
┌───┴────────────────────┐
│ Driver Library │
│ ┌───────────────┐ │
│ │ driver.py │ │
│ ├───────────────┤ │
│ │ btp_request │ │
│ │ btp_indication│ │
│ │ logger │ │
│ │ etsi_messages │ │
│ └──▲────────────┘ │
│ │ uses │
└───┴────────────────────┘
│ calls encode/decode
┌───▼────────────────────┐
│ ASN.1 Parser (asn1tools) │
└───▲────────────────────┘
│ reads .asn files from asn1/ tree
┌───┴────────────────────┐
│ ASN.1 Specs (.asn files)│
└─────────────────────────┘
┌────────────────────────┐
│ COHDA MK6 Device │
└────────────────────────┘
▲ send/receive BTP bytes
└────────────────────┘