-
Notifications
You must be signed in to change notification settings - Fork 2
Adding GN Beacons #14
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| This file implements the CAM Transmission Management required by the CAM Basic Service. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
| from math import trunc | ||
| import logging | ||
|
|
@@ -17,7 +18,7 @@ | |
| CommunicationProfile, | ||
| TrafficClass, | ||
| ) | ||
| from ...utils.time_service import TimeService, ITS_EPOCH_MS, ELAPSED_MILLISECONDS | ||
| from ...utils.time_service import ITS_EPOCH_MS, ELAPSED_MILLISECONDS | ||
| from .cam_ldm_adaptation import CABasicServiceLDM | ||
|
|
||
| T_GEN_CAM_MIN = 100 # T_GenCamMin [in ms] | ||
|
|
@@ -50,13 +51,16 @@ class VehicleData: | |
| vehicle_width : int | ||
| Vehicle Width as specified in ETSI TS 102 894-2 V2.3.1 (2024-08). | ||
| """ | ||
|
|
||
| station_id: int = 0 | ||
| station_type: int = 0 | ||
| drive_direction: str = "unavailable" | ||
| vehicle_length: dict = field(default_factory=lambda: { | ||
| "vehicleLengthValue": 1023, | ||
| "vehicleLengthConfidenceIndication": "unavailable", | ||
| }) | ||
| vehicle_length: dict = field( | ||
| default_factory=lambda: { | ||
| "vehicleLengthValue": 1023, | ||
| "vehicleLengthConfidenceIndication": "unavailable", | ||
| } | ||
| ) | ||
| vehicle_width: int = 62 | ||
|
|
||
| def __check_valid_station_id(self) -> None: | ||
|
|
@@ -69,11 +73,13 @@ def __check_valid_station_type(self) -> None: | |
|
|
||
| def __check_valid_drive_direction(self) -> None: | ||
| if self.drive_direction not in ["forward", "backward", "unavailable"]: | ||
| raise ValueError( | ||
| "Drive Direction must be forward, backward or unavailable") | ||
| raise ValueError("Drive Direction must be forward, backward or unavailable") | ||
|
|
||
| def __check_valid_vehicle_length(self) -> None: | ||
| if self.vehicle_length["vehicleLengthValue"] < 0 or self.vehicle_length["vehicleLengthValue"] > 1023: | ||
| if ( | ||
| self.vehicle_length["vehicleLengthValue"] < 0 | ||
| or self.vehicle_length["vehicleLengthValue"] > 1023 | ||
| ): | ||
| raise ValueError("Vehicle length must be between 0 and 1023") | ||
|
|
||
| def __check_valid_vehicle_width(self) -> None: | ||
|
|
@@ -105,6 +111,7 @@ class GenerationDeltaTime: | |
| msec : int | ||
| Time in milliseconds. | ||
| """ | ||
|
|
||
| msec: int = 0 | ||
|
|
||
| @classmethod | ||
|
|
@@ -138,12 +145,19 @@ def as_timestamp_in_certain_point(self, utc_timestamp_in_millis: int) -> float: | |
| Timestamp of the generation delta time in milliseconds | ||
| """ | ||
| number_of_cycles = trunc( | ||
| (utc_timestamp_in_millis - ITS_EPOCH_MS + ELAPSED_MILLISECONDS) / 65536) | ||
| transformed_timestamp = self.msec + 65536 * \ | ||
| number_of_cycles + ITS_EPOCH_MS - ELAPSED_MILLISECONDS | ||
| (utc_timestamp_in_millis - ITS_EPOCH_MS + ELAPSED_MILLISECONDS) / 65536 | ||
| ) | ||
| transformed_timestamp = ( | ||
| self.msec + 65536 * number_of_cycles + ITS_EPOCH_MS - ELAPSED_MILLISECONDS | ||
| ) | ||
| if transformed_timestamp <= utc_timestamp_in_millis: | ||
| return transformed_timestamp | ||
| return self.msec + 65536 * (number_of_cycles - 1) + ITS_EPOCH_MS - ELAPSED_MILLISECONDS | ||
| return ( | ||
| self.msec | ||
| + 65536 * (number_of_cycles - 1) | ||
| + ITS_EPOCH_MS | ||
| - ELAPSED_MILLISECONDS | ||
| ) | ||
|
|
||
| def __gt__(self, other: object) -> bool: | ||
| """ | ||
|
|
@@ -208,8 +222,10 @@ class CooperativeAwarenessMessage: | |
| All the CAM message in dict format as decoded by the CAMCoder. | ||
|
|
||
| """ | ||
|
|
||
| cam: dict = field( | ||
| default_factory=lambda: CooperativeAwarenessMessage.generate_white_cam_static()) | ||
| default_factory=lambda: CooperativeAwarenessMessage.generate_white_cam_static() | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def generate_white_cam_static() -> dict: | ||
|
|
@@ -307,7 +323,8 @@ def fullfill_gen_delta_time_with_tpv_data(self, tpv: dict) -> None: | |
| """ | ||
| if "time" in tpv: | ||
| gen_delta_time = GenerationDeltaTime.from_timestamp( | ||
| parser.parse(tpv["time"]).timestamp()) | ||
| parser.parse(tpv["time"]).timestamp() | ||
| ) | ||
| self.cam["cam"]["generationDeltaTime"] = int(gen_delta_time.msec) | ||
|
|
||
| def fullfill_basic_container_with_tpv_data(self, tpv: dict) -> None: | ||
|
|
@@ -362,7 +379,7 @@ def fullfill_high_frequency_container_with_tpv_data(self, tpv: dict) -> None: | |
| if "track" in tpv.keys(): | ||
| self.cam["cam"]["camParameters"]["highFrequencyContainer"][1]["heading"][ | ||
| "headingValue" | ||
| ] = int(tpv["track"]*10) | ||
| ] = int(tpv["track"] * 10) | ||
| if "epd" in tpv.keys(): | ||
| self.cam["cam"]["camParameters"]["highFrequencyContainer"][1]["heading"][ | ||
| "headingConfidence" | ||
|
|
@@ -622,11 +639,7 @@ def _send_cam(self, cam: CooperativeAwarenessMessage) -> None: | |
| Send the next CAM. | ||
| """ | ||
| if self.ca_basic_service_ldm is not None: | ||
| cam_ldm = cam.cam.copy() | ||
| cam_ldm["utc_timestamp"] = TimeService.time() | ||
| self.ca_basic_service_ldm.add_provider_data_to_ldm( | ||
| cam.cam | ||
| ) | ||
| self.ca_basic_service_ldm.add_provider_data_to_ldm(cam.cam) | ||
| data = self.cam_coder.encode(cam.cam) | ||
| request = BTPDataRequest( | ||
| btp_type=CommonNH.BTP_B, | ||
|
|
@@ -639,7 +652,7 @@ def _send_cam(self, cam: CooperativeAwarenessMessage) -> None: | |
| ) | ||
|
|
||
| self.btp_router.btp_data_request(request) | ||
| self.logging.debug( | ||
| self.logging.info( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before |
||
| "Sent CAM message with timestamp: %d, station_id: %d", | ||
| cam.cam["cam"]["generationDeltaTime"], | ||
| cam.cam["header"]["stationId"], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ def reception_callback(self, btp_indication: BTPDataIndication) -> None: | |
| """ | ||
| denm = self.denm_coder.decode(btp_indication.data) | ||
| self.feed_ldm(denm) | ||
| self.logging.debug( | ||
| self.logging.info( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| "Received DENM with timestamp: %s, station_id: %s", | ||
| denm["denm"]["management"]["referenceTime"], | ||
| denm["header"]["stationId"], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,7 +267,7 @@ def transmit_denm( | |
| length=len(data), | ||
| ) | ||
| self.btp_router.btp_data_request(request) | ||
| self.logging.debug( | ||
| self.logging.info( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| "Sent DENM with timestamp: %s, station_id: %s", | ||
| denm_to_send.denm["denm"]["management"]["referenceTime"], | ||
| denm_to_send.denm["header"]["stationId"], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be kept as debug logging. Technically, if you run the whole stack you don't expect to get an INFO print every time you receive a CAM message. This should be on a debug level.