.. _python_ca_basic_service:
============================================
Cooperative Awareness (CA) Basic Service
============================================
The CA basic service implements **ETSI TS 103 900 V2.3.1**: generation, transmission and reception of Cooperative Awareness Messages (CAMs), which advertise the position, dynamics and dimensions of an ITS station.
Architecture Diagram
====================
.. mermaid::
flowchart TD
LDM["Local Dynamic Map (LDM)
ETSI EN 302 895"]
LOC["Location Service
Ego position & dynamics"]
CA["CA Basic Service
ETSI TS 103 900"]
BTP["Basic Transport Protocol (BTP)
Port 2001"]
LOC -->|"position updates"| CA
CA -->|"received CAMs"| LDM
CA -->|"BTP-Data.request"| BTP
BTP -->|"BTP-Data.indication"| CA
style LDM fill:#f3e8ff,stroke:#7c3aed,stroke-width:2px,color:#581c87
style LOC fill:#fef3c7,stroke:#d97706,stroke-width:2px,color:#78350f
style CA fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
style BTP fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a8a
Core Components
===============
- ``CooperativeAwarenessBasicService``: the service; it owns the transmission and reception management.
- ``VehicleData``: the station's static data (station ID and type, dimensions, role, lights), a frozen dataclass following the Common Data Dictionary (**ETSI TS 102 894-2**).
- ``CAMTransmissionManagement`` (``ca_service.cam_transmission_management``): the generation rules. A CAM is generated when the heading changes by more than 4°, the position by more than 4 m or the speed by more than 0.5 m/s, and at least every ``T_GenCamMax`` (1 s); never more often than ``T_GenCamMin`` (100 ms) or the DCC interval ``T_GenCam_DCC``. Low-frequency and special-vehicle containers are added as specified.
Instantiating the Service
=========================
.. code-block:: python
from flexstack.facilities.ca_basic_service.ca_basic_service import CooperativeAwarenessBasicService
from flexstack.facilities.ca_basic_service.cam_transmission_management import VehicleData
vehicle_data = VehicleData(
station_id=1001,
station_type=5, # passenger car (ETSI TS 102 894-2)
drive_direction="forward",
vehicle_length={"vehicleLengthValue": 48, "vehicleLengthConfidenceIndication": "unavailable"}, # 0.1 m units
vehicle_width=19, # 0.1 m units
)
ca_service = CooperativeAwarenessBasicService(
btp_router=btp_router,
vehicle_data=vehicle_data,
ldm=ldm,
)
# Every position update is checked against the generation rules
location_service.add_callback(ca_service.cam_transmission_management.location_service_callback)
ca_service.start()
``ca_service.stop()`` stops it. A received CAM (BTP port 2001) is decoded and stored in the LDM, from which applications read it (see :ref:`ldm`).
Congestion Control
==================
When a DCC entity is running (``flexstack.management``), it sets the CAM interval limit through ``ca_service.set_t_gen_cam_dcc(milliseconds)``; without DCC the limit stays at its default, 100 ms.