Skip to content

Commit

Permalink
Added timezone to remote telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Jan 6, 2025
1 parent 20b7a73 commit 215680e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ class style:
daylight_savings = True
else:
daylight_savings = False
timezone_offset = -(time.altzone if daylight_savings else time.timezone) # This is the local timezone's offset from UTC in seconds.
if daylight_savings:
timezone_offset = time.altzone
else:
timezone_offset = time.timezone

# Get the timezone offset as a text stamp.
hours = offset // 3600
minutes = (offset // 60) % 60
if hours < 0: # Check to see if the hours offset is negative.
sign = "-"
else:
sign = "+"
hours = abs(hours) # Make the hours field positive, now that we've specified the sign.
timezone_offset_stamp = "UTC" + sign + "{:02d}:{:02d}".format(hours, minutes)


global_time_offset = 0
def get_time():
Expand Down Expand Up @@ -688,7 +702,7 @@ def get_gps_location():
current_state["gps"] = gps_data_packet.mode
if (gps_data_packet.mode >= 2): # Check to see if the GPS has a 2D fix yet.
try:
gps_time = datetime.datetime.strptime(str(gps_data_packet.time)[:-1]+"000" , '%Y-%m-%dT%H:%M:%S.%f').astimezone().timestamp() + timezone_offset # Determine the local Unix timestamp from the GPS timestamp.
gps_time = datetime.datetime.strptime(str(gps_data_packet.time)[:-1]+"000" , '%Y-%m-%dT%H:%M:%S.%f').astimezone().timestamp() - timezone_offset # Determine the local Unix timestamp from the GPS timestamp.
except:
gps_time = 0
position = gps_data_packet.position()
Expand Down Expand Up @@ -884,7 +898,11 @@ def count_frames(video):
last_telemetry_sent = 0 # This holds the timestamp of the last time telemetry was sent.
def send_telemetry(data):
global last_telemetry_sent
data["system"]["timezone"] = timezone_offset_stamp # Add the system timezone to the data.
# data = {
# "system": {
# "timezone": "UTC+00:00"
# },
# "image": {
# "main": [OpenCV image],
# "rear": "[OpenCV image]",
Expand All @@ -900,6 +918,7 @@ def send_telemetry(data):
# }
# }
if (time.time() - last_telemetry_sent >= 10): # Check to see if it has been at least 10 seconds since the last telemetry update.

for device in data["image"]:
original_height, original_width = data["image"][device].shape[:2]
target_height = 720
Expand Down

0 comments on commit 215680e

Please sign in to comment.