flexstack.facilities Module
The flexstack.facilities package implements ETSI C-ITS Release 2 facilities services.
Cooperative Awareness (CA) Basic Service
Cooperative Awareness Basic Service
This file contains the class for the Cooperative Awareness Basic Service, strictly following ETSI TS 103 900 V2.3.1 (2026-05), the latest version.
- class flexstack.facilities.ca_basic_service.ca_basic_service.CooperativeAwarenessBasicService(btp_router, vehicle_data, ldm=None)[source]
Bases:
objectCooperative Awareness Basic Service — ETSI TS 103 900 V2.3.1.
Call
start()to activate the service andstop()to deactivate it in accordance with §5.3.1 (CA_Activation).- Variables:
btp_router (BTPRouter) – BTP Router.
cam_coder (CAMCoder) – CAM Coder.
cam_transmission_management (CAMTransmissionManagement) – CAM Transmission Management.
cam_reception_management (CAMReceptionManagement) – CAM Reception Management.
- Parameters:
btp_router (BTPRouter) –
vehicle_data (VehicleData) –
ldm (LDMFacility | None) –
- __init__(btp_router, vehicle_data, ldm=None)[source]
Initialise the Cooperative Awareness Basic Service.
- Parameters:
btp_router (BTPRouter) – BTP Router.
vehicle_data (VehicleData) – Vehicle Data.
ldm (LDMFacility or None) – Local Dynamic Map (LDM) Service.
- Return type:
None
- start()[source]
Activate the CA service (§5.3.1 (CA_Activation)).
Starts the T_CheckCamGen timer in the transmission management.
- Return type:
None
- stop()[source]
Deactivate the CA service (§5.3.1 (CA_Activation)).
Stops the T_CheckCamGen timer in the transmission management.
- Return type:
None
CAM Transmission Management
This file implements the CAM Transmission Management required by the CAM Basic Service, strictly following ETSI TS 103 900 V2.3.1 (2026-05), the latest version.
- Key behavioural changes versus the pre-standard implementation:
Timer-based (T_CheckCamGen) instead of GPS-callback-reactive (§6.1.2, Annex B).
T_GenCam is initialised to T_GenCamMax (not T_GenCamMin) as mandated by §6.1.2.
Condition 1 (dynamics: heading/position/speed) and Condition 2 (time) are both evaluated on every T_CheckCamGen tick.
A condition-1 CAM sets T_GenCam to the elapsed time; N_GenCam consecutive condition-2 CAMs reset it to T_GenCamMax; the first CAM keeps T_GenCamMax.
Low-Frequency, Special-Vehicle, Very-Low-Frequency and Two-Wheeler extension containers are included according to §6.1.2.
CAM construction failures are handled per Annex B.2.5 (skip, continue timer).
GN max packet lifetime 950 ms, below 1 s (TS 102 868-2 TP/CAM/MSD/PAR/BV-03; single-hop BTP-B/SHB per §6.1.1 and §5.3.4; V2.2.1 §5.3.4.1 allows at most 1000 ms, V2.3.1 leaves it to the NTL protocol stack).
CA service start/stop correspond to ITS-S activation/deactivation per §5.3.1 (CA_Activation).
- class flexstack.facilities.ca_basic_service.cam_transmission_management.VehicleData(station_id=0, station_type=0, drive_direction='unavailable', vehicle_length=<factory>, vehicle_width=62, vehicle_role=0, exterior_lights=b'\x00', special_vehicle_data=None)[source]
Bases:
objectClass that stores the vehicle data.
- Variables:
station_id (int) – Station Id as specified in ETSI TS 102 894-2 V2.3.1 (2024-08).
station_type (int) – Station Type as specified in ETSI TS 102 894-2 V2.3.1 (2024-08).
drive_direction (str) – Drive Direction as specified in ETSI TS 102 894-2 V2.3.1 (2024-08).
vehicle_length (dict) – Vehicle Length as specified in ETSI TS 102 894-2 V2.3.1 (2024-08).
vehicle_width (int) – Vehicle Width as specified in ETSI TS 102 894-2 V2.3.1 (2024-08).
vehicle_role (int) – VehicleRole (0=default). Used in the Low-Frequency container and to decide whether a Special-Vehicle container is required (§6.1.2).
exterior_lights (bytes) – ExteriorLights BIT STRING (SIZE(8)). One byte; bits ordered MSB→LSB correspond to lowBeam(0)…parkingLights(7). Default = all off.
special_vehicle_data (dict or None) – Special vehicle container data (CHOICE value dict), e.g.
("emergencyContainer", {...}). None if not applicable.
- Parameters:
station_id (int) –
station_type (int) –
drive_direction (str) –
vehicle_length (dict) –
vehicle_width (int) –
vehicle_role (int) –
exterior_lights (bytes) –
special_vehicle_data (dict | None) –
- station_id: int = 0
- station_type: int = 0
- drive_direction: str = 'unavailable'
- vehicle_length: dict
- vehicle_width: int = 62
- vehicle_role: int = 0
- exterior_lights: bytes = b'\x00'
- special_vehicle_data: dict | None = None
- flexstack.facilities.ca_basic_service.cam_transmission_management.bits_to_bytes(names, flags)[source]
Encode named BIT STRING flags (bit 0 = most significant bit of the first octet) into bytes; unknown names raise ValueError.
- Parameters:
names (tuple) –
flags (dict) –
- Return type:
bytes
- class flexstack.facilities.ca_basic_service.cam_transmission_management.InVehicleData(curvature_value=1023, curvature_confidence='unavailable', curvature_calculation_mode='unavailable', yaw_rate_value=32767, yaw_rate_confidence='unavailable', drive_direction=None, acceleration_control=None, exterior_lights=None)[source]
Bases:
objectLatest in-vehicle data provided to the CA basic service (ETSI TS 103 900 V2.3.1 clauses 5.2 and 7.1): the next generated CAM carries these values.
Nonekeeps the static value ofVehicleData(drive direction, exterior lights) or omits the optional field (accelerationControl).- Variables:
curvature_value (int) – CurvatureValue (-1023..1023, 1023 = unavailable).
curvature_confidence (str) – CurvatureConfidence.
curvature_calculation_mode (str) – CurvatureCalculationMode.
yaw_rate_value (int) – YawRateValue in 0,01 degree/s (-32766..32767, 32767 = unavailable).
yaw_rate_confidence (str) – YawRateConfidence.
drive_direction (str or None) – DriveDirection (“forward”, “backward”, “unavailable”).
acceleration_control (dict or None) – AccelerationControl flags by name (see
ACCELERATION_CONTROL_BITS).exterior_lights (dict or None) – ExteriorLights flags by name (see
EXTERIOR_LIGHTS_BITS).
- Parameters:
curvature_value (int) –
curvature_confidence (str) –
curvature_calculation_mode (str) –
yaw_rate_value (int) –
yaw_rate_confidence (str) –
drive_direction (str | None) –
acceleration_control (dict | None) –
exterior_lights (dict | None) –
- curvature_value: int = 1023
- curvature_confidence: str = 'unavailable'
- curvature_calculation_mode: str = 'unavailable'
- yaw_rate_value: int = 32767
- yaw_rate_confidence: str = 'unavailable'
- drive_direction: str | None = None
- acceleration_control: dict | None = None
- exterior_lights: dict | None = None
- class flexstack.facilities.ca_basic_service.cam_transmission_management.GenerationDeltaTime(msec=0)[source]
Bases:
objectGeneration Delta Time class. As specified in ETSI TS 102 894-2 V2.3.1 (2024-08).
The reason this type is implemented as a class is to be able to quickly perform operations.
Express the following way: generationDeltaTime = TimestampIts mod 65536 TimestampIts represents an integer value in milliseconds since 2004-01-01T00:00:00:000Z as defined in ETSI TS 102 894-2
- Variables:
msec (int) – Time in milliseconds.
- Parameters:
msec (int) –
- msec: int = 0
- classmethod from_timestamp(utc_timestamp_in_seconds)[source]
Set the Generation Delta Time in normal UTC timestamp. [Seconds]
- Parameters:
utc_timestamp_in_seconds (float) – Timestamp in seconds.
- Return type:
- as_timestamp_in_certain_point(utc_timestamp_in_millis)[source]
Returns the generation delta time as timestamp as it would be if received at certain point in time.
- Parameters:
utc_timestamp_in_millis (int) – Timestamp in milliseconds
- Returns:
Timestamp of the generation delta time in milliseconds
- Return type:
float
- class flexstack.facilities.ca_basic_service.cam_transmission_management.CooperativeAwarenessMessage(cam=<factory>)[source]
Bases:
objectCooperative Awareness Message class.
- Variables:
cam (dict) – All the CAM message in dict format as decoded by the CAMCoder.
- Parameters:
cam (dict) –
- cam: dict
- fullfill_with_vehicle_data(vehicle_data)[source]
Fullfill the CAM with vehicle data.
- Parameters:
vehicle_data (VehicleData) – Vehicle data.
- Return type:
None
- fullfill_gen_delta_time_with_tpv_data(tpv)[source]
Fullfills the generation delta time with the GPSD TPV data.
- Parameters:
tpv (dict) – GPSD TPV data.
- Return type:
None
- fullfill_basic_container_with_tpv_data(tpv)[source]
Fullfills the basic container with the GPSD TPV data.
- Parameters:
tpv (dict) – GPSD TPV data.
- Return type:
None
- fullfill_high_frequency_container_with_tpv_data(tpv)[source]
Fullfills the high frequency container with the GPSD TPV data.
- Parameters:
tpv (dict) – GPSD TPV data.
- Return type:
None
- fullfill_with_tpv_data(tpv)[source]
Convert a TPV data to a CAM.
- Parameters:
tpv (dict) – GPSD TPV data.
- Return type:
None
- create_position_confidence(epx, epy)[source]
Translates the epx and epy TPV values to the position confidence ellipse value.
- Parameters:
epx (int) – TPV epx value.
epy (int) – TPV epy value.
- Returns:
Position confidence ellipse value.
- Return type:
dict
- class flexstack.facilities.ca_basic_service.cam_transmission_management.CAMTransmissionManagement(btp_router, cam_coder, vehicle_data, ca_basic_service_ldm=None)[source]
Bases:
objectCAM Transmission Management — ETSI TS 103 900 V2.3.1 §6.1.
Protocol operation is timer-based (T_CheckCamGen) rather than GPS-callback-reactive. Call
start()to activate the service andstop()to deactivate it (§5.3.1 (CA_Activation)).The
location_service_callback()only updates the current position cache; the T_CheckCamGen timer evaluates CAM generation conditions on every tick (§6.1.2, Annex B.2.4).- Variables:
btp_router (BTPRouter) – BTP Router.
vehicle_data (VehicleData) – Vehicle Data (static parameters).
cam_coder (CAMCoder) – CAM encoder/decoder.
ca_basic_service_ldm (CABasicServiceLDM or None) – Local Dynamic Map adapter; may be None.
t_gen_cam (int) – Current T_GenCam upper bound [ms]. Starts at T_GenCamMax per §6.1.2.
t_gen_cam_dcc (int) – T_GenCam_DCC [ms] provided by the management layer (DCC), see
set_t_gen_cam_dcc(). Defaults toT_GEN_CAM_DCC.last_cam_generation_delta_time (GenerationDeltaTime or None) – GenerationDeltaTime of the most recently sent CAM (legacy attribute).
- Parameters:
btp_router (BTPRouter) –
cam_coder (CAMCoder) –
vehicle_data (VehicleData) –
ca_basic_service_ldm (Optional[CABasicServiceLDM]) –
- start()[source]
Activate the CA service. Starts the T_CheckCamGen timer (§5.3.1 (CA_Activation)).
- Return type:
None
- stop()[source]
Deactivate the CA service. Cancels the T_CheckCamGen timer (§5.3.1 (CA_Activation)).
- Return type:
None
- set_t_gen_cam_dcc(t_gen_cam_dcc_ms)[source]
Set T_GenCam_DCC (§6.1.2), clamped to [T_GenCamMin, T_GenCamMax].
Intended as a
DccEntitylistener; may be called from the DCC thread while the CA service runs.- Parameters:
t_gen_cam_dcc_ms (int) – Minimum CAM generation interval imposed by DCC [ms].
- Return type:
None
- location_service_callback(tpv)[source]
Cache the latest position data (§6.1.2).
This method no longer triggers CAM generation directly. The T_CheckCamGen timer evaluates generation conditions at each tick.
- Parameters:
tpv (dict) – GPSD TPV message or compatible position dict.
- Return type:
None
- update_in_vehicle_data(**changes)[source]
Update the latest in-vehicle data (§5.2, §7.1): the next CAM carries the new values. Keyword arguments are
InVehicleDatafields; invalid values raiseValueErrorand leave the data unchanged.- Returns:
The in-vehicle data now in use.
- Return type:
- property in_vehicle_data: InVehicleData
The latest in-vehicle data.
Decentralized Environmental Notification (DEN) Service
Decentralized Environmental Notification (DEN) service.
Implements ETSI TS 103 831 V2.3.1 (2025-11) “Decentralized Environmental Notification Service; Release 2” (latest version), the successor of ETSI EN 302 637-3 V1.3.1 (2019-04). DENMs use DENM-PDU-Descriptions v2.3 (Annex A) over the Common Data Dictionary v4.3 (ETSI TS 102 894-2).
DENMTransmissionManagement: originating ITS-S (clause 8.2): AppDENM_trigger / update / termination, DENM repetition.DENMReceptionManagement: receiving ITS-S (clause 8.4).Keep-Alive Forwarding (clause 8.3), optional, enabled with
kaf_enabled.
All three share one DENProtocol (the ITS-S message
tables). A scheduler thread fires the protocol timers (T_O_Validity,
T_Repetition, T_RepetitionDuration, T_R_Validity, T_F_Validity, T_Forwarding)
at their deadlines.
- class flexstack.facilities.decentralized_environmental_notification_service.den_service.DecentralizedEnvironmentalNotificationService(btp_router, vehicle_data, ldm=None, kaf_enabled=False, start_scheduler=True, *, clock=None)[source]
Bases:
objectDecentralized Environmental Notification (DEN) Service.
- Parameters:
btp_router (BTPRouter) – BTP Router.
vehicle_data (VehicleData) – stationId and stationType of this ITS-S.
ldm (LDMFacility, optional) – Local Dynamic Map fed with accepted DENMs.
kaf_enabled (bool) – Activate Keep-Alive Forwarding of received DENMs (clause 6.1.4.2). KAF only forwards while
set_ego_position()has placed the station inside the DENM destination area.start_scheduler (bool) – Start the timer thread (DENM repetition, KAF, table expiry). Tests that drive the protocol timers manually pass False.
clock (callable, optional) – Time source of the service (TimestampIts, ms); the system time when None.
- Variables:
protocol (DENProtocol) – Shared protocol engine.
denm_transmission_management (DENMTransmissionManagement) – Originating ITS-S operation.
denm_reception_management (DENMReceptionManagement) – Receiving ITS-S operation.
- trigger_denm(request)[source]
AppDENM_trigger.
- Parameters:
request (DENMRequest) –
- Return type:
DENResult
- update_denm(action_id, request)[source]
AppDENM_update.
- Parameters:
action_id (ActionId) –
request (DENMRequest) –
- Return type:
DENResult
- terminate_denm(action_id, request)[source]
AppDENM_termination.
- Parameters:
action_id (ActionId) –
request (DENMRequest) –
- Return type:
DENResult
- add_application_callback(callback)[source]
Receive accepted DENMs and their state (ACTIVE / CANCELLED / NEGATED).
- Parameters:
callback (Callable[[ReceivedDENM], None]) –
- Return type:
None
- add_expiry_callback(callback)[source]
Be notified when a received event expires (T_R_Validity).
- Parameters:
callback (Callable[[ActionId], None]) –
- Return type:
None
- update_station_id(station_id)[source]
Pseudonym change: re-label all stored own DENMs (clause 6.1.1.2).
- Parameters:
station_id (int) –
- Return type:
None
VRU Awareness Service
- class flexstack.facilities.vru_awareness_service.vru_awareness_service.VRUAwarenessService(btp_router, device_data_provider, ldm=None, cluster_support=True, own_vru_profile='pedestrian')[source]
Bases:
objectVRU Awareness Basic Service (VBS).
Top-level service object that wires together encoding, transmission, reception, LDM storage, and the optional VBS clustering state machine defined in ETSI TS 103 300-3 V2.3.1 (2025-12), clause 5.4.
- Variables:
btp_router – BTP Router used to send and receive VAMs.
vam_coder – ASN.1 encoder/decoder for VAMs.
device_data_provider – Static device parameters (station ID, station type, etc.).
vam_transmission_management – VAM generation and transmission engine.
vam_reception_management – VAM reception and LDM injection engine.
clustering_manager – VBS clustering state machine (
Nonewhencluster_support=False).
- Parameters:
btp_router (BTPRouter) –
device_data_provider (DeviceDataProvider) –
ldm (LDMFacility | None) –
cluster_support (bool) –
own_vru_profile (str) –
- __init__(btp_router, device_data_provider, ldm=None, cluster_support=True, own_vru_profile='pedestrian')[source]
Initialise the VRU Awareness Basic Service.
- Parameters:
btp_router (Router) – BTP Router.
device_data_provider (DeviceDataProvider) – Static device parameters.
ldm (LDMFacility | None) – Local Dynamic Map Facility. When provided, transmitted and received VAMs are stored for other facilities to query.
cluster_support (bool) – When
True(default), the VBS clustering state machine is instantiated and integrated with transmission and reception management per clause 5.4 of ETSI TS 103 300-3 V2.3.1.own_vru_profile (str) – ASN.1 VRU profile string, e.g.
"pedestrian". Used by the clustering manager to populateclusterProfilesin transmitted cluster VAMs.
- Return type:
None
Local Dynamic Map (LDM)
- class flexstack.facilities.local_dynamic_map.ldm_service.LDMService(ldm_maintenance)[source]
Bases:
objectClass specified in the ETSI ETSI EN 302 895 V1.1.1 (2014-09). Section 5.3. The Local Dynamic Map (LDM) Service component is responsible for providing functionalities to authorized LDM data Providers and Consumers for LDM data manipulation (such as adding new data, modifying existing data, delete existing data), direct access to data (query data) and a publish/subscribe mechanism for data access by LDM Data Consumers
- Variables:
ldm_maintenance (LDMMaintenance) – Backend component that stores, updates and retrieves data containers.
data_provider_its_aid (set[int]) – Thread-safe set with the ITS-AID values of registered data providers.
data_consumer_its_aid (set[int]) – Thread-safe set with the ITS-AID values of registered data consumers.
subscriptions (list[SubscriptionInfo]) – Active subscription records registered by data consumers.
last_checked_subscriptions_time (dict[SubscriptionInfo, TimestampIts]) – Tracks the last notification timestamp per subscription.
_lock (threading.RLock) – Reentrant lock guarding shared mutable state in the service.
- Parameters:
ldm_maintenance (LDMMaintenance) –
- attend_subscriptions()[source]
Method to attend subscriptions as specified in the ETSI EN 302 895 V1.1.1 (2014-09). Section 6.3.4.
- Return type:
None
- search_data(subscription)[source]
Method to search data by using the filter in the subscription.
- Parameters:
subscription (dict) – Subscription information (in dictionary format).
- Returns:
tuple of data objects that match the filter.
- Return type:
tuple[dict, …]
- filter_data_object_type(search_result, allowed_types)[source]
Method to filter data objects by type.
- Parameters:
search_result (tuple[dict, ...]) – tuple of data objects that match the filter.
allowed_types (list[str]) – list of allowed data object types (as specified in the ETSI TS 102 894-2 V2.2.1 (2023-10), i.e. CAM, DENM,…).
- Returns:
tuple of data objects that match the filter and are of the allowed types.
- Return type:
tuple[dict, …]
- process_notifications(subscription, valid_search_result)[source]
Method to process notifications for a subscription. It checks the notification interval and the last time it had been checked. If the notification interval has passed since the last check, it will send a notification to the callback function (listed in the subscription information dictionary database).
- Parameters:
subscription (dict) – Subscription information (in dictionary format).
valid_search_result (tuple[dict]) – tuple of data objects that match the filter and are of the allowed types.
- Return type:
None
- remove_subscription(subscription)[source]
Method that removes (pops) a subscription from the subscriptions list.
- Parameters:
subscription (SubscriptionInfo) –
- Return type:
None
- find_key_paths_in_list(target_key, search_result)[source]
Static method to find the path of a key in a list
- Parameters:
target_key (str) –
search_result (list) –
- Return type:
list[str]
- find_key_path(target_key, dictionary, path=None)[source]
Static method to find the path of a key in a dictionary.
- Parameters:
target_key (str) –
dictionary (dict) –
path (list) –
- Return type:
str
- order_search_results(search_results, orders)[source]
Method to order search results.
- Parameters:
search_results (tuple[dict, ...]) – tuple of data objects that match the filter.
orders (tuple[OrderTuple, ...]) – tuple of OrderTuple objects specifying the ordering.
- Returns:
tuple of ordered tuples of data objects.
- Return type:
tuple[tuple[dict, …], …]
- add_provider_data(data)[source]
Method created in order to add provider data into the data containers.
- Parameters:
data (AddDataProviderReq) –
- Return type:
int | None
- add_data_provider_its_aid(its_aid)[source]
Method created in order to add the providers ITS_AID into the list of data consumers.
- Parameters:
its_aid (int) –
- Return type:
None
- update_provider_data(data_object_id, data_object)[source]
Method used to update provider data.
- Parameters:
data_object_id (int) –
data_object (dict) –
- Return type:
None
- get_data_provider_its_aid()[source]
Method to get all providers ITS_AID values.
- Parameters:
None –
- Return type:
set[int]
- del_provider_data(provider_data_id)[source]
Method to delete all provider data with doc_id.
- Parameters:
provider_data_id (int) –
- Return type:
None
- del_data_provider_its_aid(its_aid)[source]
Method to delete provider ITS_AID from the list of data providers.
- Parameters:
its_aid (int) –
- Return type:
None
- query(data_request)[source]
Method to query the data containers using the RequestDataObjectsReq object.
- Parameters:
data_request (RequestDataObjectsReq) –
- Returns:
list of list of data objects. Each list of data objects is ordered according to the order specified in the data_request object.
- Return type:
list[list[dict]]
- get_object_type_from_data_object(data_object)[source]
Method to get object type from data object.
- Parameters:
data_object (dict) –
- Returns:
data object type.
- Return type:
str
- store_new_subscription_petition(subscription_request, callback)[source]
Method as standarized in ETSI EN 302 895 V1.1.1 (2014-09). Section 6.3.4. Method is used to store a new subscription petition.
- Parameters:
subscription_request (SubscribeDataobjectsReq) – Subscription request object containing subscription details.
callback (Callable[[RequestDataObjectsResp], None]) – callback function to be called when a notification is to be sent.
- Return type:
int
- add_data_consumer_its_aid(its_aid)[source]
Method to add data consumer ITS_AID to the list of data consumers.
- Parameters:
its_aid (int) –
- Return type:
None
- get_data_consumer_its_aid()[source]
Method to get list of data consumer ITS_AID.
- Parameters:
None –
- Return type:
set[int]
- class flexstack.facilities.local_dynamic_map.factory.LDMFactory[source]
Bases:
objectFactory class to create a Local Dynamic Map Facility.
- create_ldm(ldm_location, ldm_maintenance_type='Reactive', ldm_service_type='Reactive', ldm_database_type='Dictionary')[source]
Factory function to create a Local Dynamic Map Facility.
- Parameters:
ldm_location (Location) – Location object to be used by the LDM Facility.
ldm_maintenance_type (str, optional) – Type of LDM Maintenance to be used. Defaults to “Reactive”.
ldm_service_type (str, optional) – Type of LDM Service to be used. Defaults to “Reactive”.
ldm_database_type (str, optional) – Type of LDM Database to be used. Defaults to “Dictionary”.
- Return type:
LDMFacility
- subscribe_to_ldm(own_station_id, area_of_interest, callback_function)[source]
Method to subscribe to the LDM Facility.
- Parameters:
subscription_request (SubscribeDataobjectsReq) – Subscription request object.
callback_function (Callable) – Callback function to be called when new data is available.
own_station_id (int) –
area_of_interest (GeometricArea) –
- Returns:
Subscription ID.
- Return type:
int