Skip to content

Commit

Permalink
fix - get sim env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
adev4a committed Oct 18, 2023
1 parent b27a570 commit 7368164
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(self):
self.registered = False
self.subscribers_list = {}
self.exclusion_list = []

# Get is_sim env variable as boolean
self.is_sim = os.getenv("IS_SIM", 'False').lower() in ('true', '1', 't')

self.vehicle_info = {
UnitKeys.UNIT_ID.value: os.getenv("VEHICLE_BRIDGE_UNIT_ID"),
Expand All @@ -75,7 +78,6 @@ def __init__(self):
self.log_rotation = int(os.getenv("VEHICLE_BRIDGE_LOG_ROTATION_SIZE_BYTES"))

self.log_handler_type = os.getenv('VEHICLE_BRIDGE_LOG_HANDLER_TYPE')
self.is_sim = os.getenv('IS_SIM')

# Create ROS2NatsBridge logger
if self.log_handler_type == LogType.ALL.value:
Expand Down Expand Up @@ -277,7 +279,8 @@ async def topic_request(msg):
exec("from " + msg_type[0] + '.' +
msg_type[1] + " import " + msg_type[2])
call_back = self.CallBack(i[1][0], topic, self.nc, self.vehicle_info[UnitKeys.UNIT_ID.value], self.vehicle_info[UnitKeys.UNIT_TYPE.value],
self.vehicle_info[UnitKeys.UNIT_NAME.value], self.vehicle_info[EventKeys.EVENT_NAME.value], self.vehicle_info[EventKeys.TESTING_TYPE.value], self.vehicle_info[EventKeys.LOCATION.value], self.logger)
self.vehicle_info[UnitKeys.UNIT_NAME.value], self.vehicle_info[EventKeys.EVENT_NAME.value], self.vehicle_info[EventKeys.TESTING_TYPE.value], self.vehicle_info[EventKeys.LOCATION.value],
self.is_sim, self.logger)
try:
self.subscribers_list[topic] = self.create_subscription(
eval(msg_type[2]), topic, call_back.listener_callback, 10)
Expand All @@ -299,7 +302,7 @@ async def topic_request(msg):


class CallBack():
def __init__(self, msg_type, topic_name, nc, unit_id, unit_type, unit_name, event_name, testing_type, location, logger):
def __init__(self, msg_type, topic_name, nc, unit_id, unit_type, unit_name, event_name, testing_type, location, is_sim, logger):
"""
initilize CallBack class
declare Nats client
Expand All @@ -317,6 +320,7 @@ def __init__(self, msg_type, topic_name, nc, unit_id, unit_type, unit_name, even
self.logger = logger
self.logger.info("Publishing on topic: "+ self.topic_name)
self.nc = nc
self.is_sim = is_sim

async def listener_callback(self, msg):
"""
Expand All @@ -339,7 +343,7 @@ async def listener_callback(self, msg):
secondToMicro = 1000000 #convert seconds to microseconds

# If simulation environment - use current system time instead of ros header time
if self.is_sim :
if self.is_sim:
ordereddict_msg["timestamp"] = datetime.now(timezone.utc).timestamp()*secondToMicro # microseconds
else:
#Check if the ROS message has a timestamp and use it for the NATS message
Expand Down

0 comments on commit 7368164

Please sign in to comment.