Skip to content

Commit d06912e

Browse files
VERSION 0.9.20
1 parent 5de54ae commit d06912e

File tree

14 files changed

+123
-62
lines changed

14 files changed

+123
-62
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "v2xflexstack"
7-
version = "0.9.19"
7+
version = "0.9.20"
88
authors = [
99
{ name = "Jordi Marias-i-Parella", email = "[email protected]" },
1010
{ name = "Daniel Ulied Guevara", email = "[email protected]" },

src/flexstack/applications/road_hazard_signalling_service/emergency_vehicle_approaching_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
self.denm_interval = 100
6060
self.priority_level = PriorityLevel.WARNING
6161
# Get DENM data to simulate the hazard detection
62-
self.detection_time = int((TimeService.time() - 1072915200 + 5) * 1000)
62+
self.detection_time = TimeService.timestamp_its()
6363
self.event_position = {
6464
"latitude": 900000001,
6565
"longitude": 1800000001,

src/flexstack/facilities/ca_basic_service/cam_ldm_adaptation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def add_provider_data_to_ldm(self, cam: dict) -> None:
5252
timestamp = TimestampIts()
5353
data = AddDataProviderReq(
5454
application_id=CAM,
55-
time_stamp=timestamp,
55+
timestamp=timestamp,
5656
location=Location.location_builder_circle(
5757
latitude=cam["cam"]["camParameters"]["basicContainer"][
5858
"referencePosition"

src/flexstack/facilities/ca_basic_service/cam_transmission_management.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CommunicationProfile,
1717
TrafficClass,
1818
)
19+
from ...utils.time_service import ITS_EPOCH_MS, ELAPSED_MILLISECONDS
1920
from .cam_ldm_adaptation import CABasicServiceLDM
2021

2122
T_GEN_CAM_MIN = 100 # T_GenCamMin [in ms]
@@ -111,25 +112,27 @@ class GenerationDeltaTime:
111112
def __init__(self) -> None:
112113
self.msec = 0
113114

114-
def set_in_normal_timestamp(self, timestamp_seconds: float) -> None:
115+
def set_in_normal_timestamp(self, utc_timestamp_in_seconds: float) -> None:
115116
"""
116-
Set the Generation Delta Time in normal timestamp. [Seconds]
117+
Set the Generation Delta Time in normal UTC timestamp. [Seconds]
117118
118119
Parameters
119120
----------
120121
timestamp : int
121122
Timestamp in milliseconds.
122123
"""
123-
self.msec = (timestamp_seconds*1000 - 1072915200000 + 5000) % 65536
124+
self.msec = (
125+
utc_timestamp_in_seconds * 1000 - ITS_EPOCH_MS + ELAPSED_MILLISECONDS
126+
) % 65536
124127

125-
def as_timestamp_in_certain_point(self, point_in_time_millis: int) -> float:
128+
def as_timestamp_in_certain_point(self, utc_timestamp_in_millis: int) -> float:
126129
"""
127130
Returns the generation delta time as timestamp as it would be if received at
128131
certain point in time.
129132
130133
Parameters
131134
----------
132-
point_in_time : int
135+
utc_timestamp_in_millis : int
133136
Timestamp in milliseconds
134137
135138
Returns
@@ -138,12 +141,12 @@ def as_timestamp_in_certain_point(self, point_in_time_millis: int) -> float:
138141
Timestamp of the generation delta time in milliseconds
139142
"""
140143
number_of_cycles = trunc(
141-
(point_in_time_millis - 1072915200000 + 5000) / 65536)
144+
(utc_timestamp_in_millis - ITS_EPOCH_MS + ELAPSED_MILLISECONDS) / 65536)
142145
transformed_timestamp = self.msec + 65536 * \
143-
number_of_cycles + 1072915200000 - 5000
144-
if transformed_timestamp <= point_in_time_millis:
146+
number_of_cycles + ITS_EPOCH_MS - ELAPSED_MILLISECONDS
147+
if transformed_timestamp <= utc_timestamp_in_millis:
145148
return transformed_timestamp
146-
return self.msec + 65536 * (number_of_cycles - 1) + 1072915200000 - 5000
149+
return self.msec + 65536 * (number_of_cycles - 1) + ITS_EPOCH_MS - ELAPSED_MILLISECONDS
147150

148151
def __gt__(self, other: object) -> bool:
149152
"""

src/flexstack/facilities/decentralized_environmental_notification_service/denm_reception_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def feed_ldm(self, denm: dict) -> None:
6868
if self.ldm_facility is not None:
6969
data = AddDataProviderReq(
7070
application_id=DENM,
71-
time_stamp=TimestampIts.initialize_with_timestamp_its(denm["denm"]["management"]["detectionTime"]),
71+
timestamp=TimestampIts.initialize_with_timestamp_its(denm["denm"]["management"]["detectionTime"]),
7272
location=Location.location_builder_circle(
7373
latitude=denm["denm"]["management"]["eventPosition"]["latitude"],
7474
longitude=denm["denm"]["management"]["eventPosition"]["longitude"],

src/flexstack/facilities/decentralized_environmental_notification_service/denm_transmission_management.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def fullfill_with_denrequest(self, request: DENRequest) -> None:
8989
# Add Management Container
9090
self.denm["denm"]["management"]["detectionTime"] = request.detection_time
9191
self.denm["denm"]["management"]["referenceTime"] = int(
92-
(TimeService.time() - 1072915200 + 5) * 1000
92+
TimeService.timestamp_its()
9393
)
9494
self.denm["denm"]["management"]["TransmissionInterval"] = request.denm_interval
9595

@@ -147,7 +147,7 @@ def fullfill_with_collision_risk_warning(self, request: DENRequest) -> None:
147147
# Add Management Container
148148
self.denm["denm"]["management"]["detectionTime"] = request.detection_time
149149
self.denm["denm"]["management"]["referenceTime"] = int(
150-
(TimeService.time() - 1072915200 + 5) % 65536
150+
TimeService.timestamp_its()
151151
)
152152
self.denm["denm"]["management"]["TransmissionInterval"] = request.denm_interval
153153

src/flexstack/facilities/local_dynamic_map/ldm_classes.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
"""
1818

1919
from __future__ import annotations
20-
from ...utils.time_service import TimeService
20+
from ...utils.time_service import TimeService, ITS_EPOCH, ELAPSED_SECONDS
2121
import math
2222

2323
from .ldm_constants import (
2424
EATH_RADIUS,
25-
REFERENCE_ITS_TIMESTAMP,
2625
DATA_OBJECT_TYPE_ID,
2726
DENM,
2827
CAM,
@@ -53,23 +52,25 @@ class TimestampIts:
5352
TimestamptITS class to handle timestamps. Timestamps are expressed in ETSI Timestamp format.
5453
"""
5554

56-
def __init__(self, timestamp: int = None) -> None:
55+
def __init__(self, utc_timestamp_seconds: int = None) -> None:
5756
"""
5857
Initializes the TimestampIts class.
5958
6059
Parameters
6160
----------
62-
timestamp : int
63-
The timestamp in seconds since the epoch (UTC). If None, it will be set to the current time.
61+
utc_timestamp_seconds : int
62+
The UTC timestamp in seconds since the epoch (UTC).
63+
If None, it will be set to the current UTC timestamp.
6464
"""
65-
self.timestamp = None
66-
if timestamp:
65+
self.timestamp = 0
66+
if utc_timestamp_seconds:
6767
self.timestamp = self.__transform_utc_seconds_timestamp_to_timestamp_its(
68-
timestamp)
68+
utc_timestamp_seconds)
6969
else:
7070
self.timestamp = self.__transform_utc_seconds_timestamp_to_timestamp_its(
7171
int(TimeService.time()))
7272

73+
@staticmethod
7374
def initialize_with_timestamp_its(timestamp_its: int) -> TimestampIts:
7475
"""
7576
Initializes the TimestampIts class with a given ETSI ITS timestamp.
@@ -84,25 +85,25 @@ def initialize_with_timestamp_its(timestamp_its: int) -> TimestampIts:
8485
TimestampIts
8586
An instance of the TimestampIts class.
8687
"""
87-
to_return: TimestampIts = TimestampIts(REFERENCE_ITS_TIMESTAMP+5)
88+
to_return: TimestampIts = TimestampIts(ITS_EPOCH + ELAPSED_SECONDS)
8889
to_return.timestamp = timestamp_its
8990
return to_return
9091

91-
def __transform_utc_seconds_timestamp_to_timestamp_its(self, timestamp: int) -> int:
92+
def __transform_utc_seconds_timestamp_to_timestamp_its(self, utc_timestamp_seconds: int) -> int:
9293
"""
9394
Method to transform a UTC timestamp to a ETSI ITS timestamp.
9495
9596
Parameters
9697
----------
97-
timestamp : int
98-
UTC timestamp to be converted.
98+
utc_timestamp_seconds : int
99+
UTC timestamp in seconds to be converted.
99100
100101
Returns
101102
-------
102103
int
103104
Converted ITS timestamp.
104105
"""
105-
return (timestamp - REFERENCE_ITS_TIMESTAMP + 5) * 1000 # The 5 correspond to leap seconds
106+
return int((utc_timestamp_seconds - ITS_EPOCH + ELAPSED_SECONDS) * 1000)
106107

107108
def __add__(self, other: TimestampIts) -> TimestampIts:
108109
"""
@@ -248,7 +249,7 @@ def to_etsi_its(self) -> int:
248249
int
249250
Converted timestamp in ETSI ITS format.
250251
"""
251-
return ((self.time - REFERENCE_ITS_TIMESTAMP)) * 1000
252+
return int(((self.time - ITS_EPOCH)) * 1000)
252253

253254

254255
class DataContainer:
@@ -977,21 +978,21 @@ class AddDataProviderReq:
977978
def __init__(
978979
self,
979980
application_id: int,
980-
time_stamp: TimestampIts,
981+
timestamp: TimestampIts,
981982
location: Location,
982983
data_object: dict,
983984
time_validity: TimeValidity,
984985
) -> None:
985986
self.application_id = application_id
986-
self.time_stamp = time_stamp
987+
self.timestamp = timestamp
987988
self.location = location
988989
self.data_object = data_object
989990
self.time_validity = time_validity
990991

991992
def __iter__(self):
992993
# pylint: disable=line-too-long
993994
yield "application_id", self.application_id
994-
yield "timestamp", self.time_stamp.timestamp
995+
yield "timestamp", self.timestamp.timestamp
995996
yield "location", {
996997
"referencePosition": {
997998
"latitude": self.location.reference_position.latitude,
@@ -1058,7 +1059,7 @@ def to_dict(self) -> dict:
10581059
# pylint: disable=line-too-long
10591060
data = {
10601061
"application_id": self.application_id,
1061-
"timestamp": self.time_stamp.timestamp,
1062+
"timestamp": self.timestamp.timestamp,
10621063
"location": {
10631064
"referencePosition": {
10641065
"latitude": self.location.reference_position.latitude,
@@ -1127,7 +1128,8 @@ def from_dict(data: dict) -> "AddDataProviderReq":
11271128
An instance of the AddDataProviderReq class.
11281129
"""
11291130
application_id = data.get("application_id")
1130-
time_stamp = TimestampIts.initialize_with_timestamp_its(data.get("timestamp"))
1131+
time_stamp = TimestampIts.initialize_with_timestamp_its(
1132+
data.get("timestamp"))
11311133
location_data = data.get("location")
11321134
data_object = data.get("dataObject")
11331135
time_validity = TimeValidity(data.get("timeValidity"))
@@ -1193,7 +1195,7 @@ def from_dict(data: dict) -> "AddDataProviderReq":
11931195

11941196
return AddDataProviderReq(
11951197
application_id=application_id,
1196-
time_stamp=time_stamp,
1198+
timestamp=time_stamp,
11971199
location=location,
11981200
data_object=data_object,
11991201
time_validity=time_validity,

src/flexstack/facilities/local_dynamic_map/ldm_constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
library_folder = os.path.dirname(os.path.abspath(__file__))
66
file_path = os.path.join(library_folder, "data_containers.json")
77
LDM_STORAGE_PATH = file_path
8-
REFERENCE_ITS_TIMESTAMP = 1072911600
98
MAINTENANCE_AREA_MAX_ALTITUDE_DIFFERENCE = 15
109
EATH_RADIUS = 6371000.0
1110

src/flexstack/facilities/vru_awareness_service/vam_ldm_adaptation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def add_provider_data_to_ldm(self, vam: dict) -> None:
5757
timestamp = TimestampIts()
5858
data = AddDataProviderReq(
5959
application_id=VAM,
60-
time_stamp=timestamp,
60+
timestamp=timestamp,
6161
location=Location.location_builder_circle(
6262
latitude=vam["vam"]["vamParameters"]["basicContainer"]["referencePosition"]["latitude"],
6363
longitude=vam["vam"]["vamParameters"]["basicContainer"]["referencePosition"]["longitude"],

src/flexstack/geonet/position_vector.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dateutil import parser
2-
2+
from ..utils.time_service import ITS_EPOCH, ITS_EPOCH_MS, ELAPSED_SECONDS, ELAPSED_MILLISECONDS
33
from .exceptions import DecodeError
44
from .gn_address import GNAddress
55

@@ -26,27 +26,27 @@ class TST:
2626
def __init__(self) -> None:
2727
self.msec = 0
2828

29-
def set_in_normal_timestamp_seconds(self, timestamp: int) -> None:
29+
def set_in_normal_timestamp_seconds(self, utc_timestamp_seconds: int) -> None:
3030
"""
3131
Set the timestamp in normal timestamp format.
3232
3333
Parameters
3434
----------
35-
timestamp : int
36-
Timestamp in normal timestamp format.
35+
utc_timestamp_seconds : int
36+
Timestamp in normal UTC timestamp format.
3737
"""
38-
self.msec = ((timestamp-1072911600+5)*1000) % 2**32
38+
self.msec = ((utc_timestamp_seconds-ITS_EPOCH+ELAPSED_SECONDS)*1000) % 2**32
3939

40-
def set_in_normal_timestamp_milliseconds(self, timestamp: int) -> None:
40+
def set_in_normal_timestamp_milliseconds(self, utc_timestamp_milliseconds: int) -> None:
4141
"""
4242
Set the timestamp in normal timestamp format.
4343
4444
Parameters
4545
----------
46-
timestamp : int
47-
Timestamp in normal timestamp format.
46+
utc_timestamp_milliseconds : int
47+
Timestamp in normal UTC timestamp format.
4848
"""
49-
self.msec = (timestamp-1072911600000 + 5000) % 2**32
49+
self.msec = (utc_timestamp_milliseconds-ITS_EPOCH_MS+ELAPSED_MILLISECONDS) % 2**32
5050

5151
def encode(self) -> int:
5252
"""

0 commit comments

Comments
 (0)