Skip to content

Commit

Permalink
Started remote telemetry system
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Jan 5, 2025
1 parent dbb2036 commit 714daea
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
19 changes: 17 additions & 2 deletions dashcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
debug_message = utils.debug_message
process_timing = utils.process_timing
get_gps_location = utils.get_gps_location
get_gps_location_lazy = utils.get_gps_location_lazy
heartbeat = utils.heartbeat
update_state = utils.update_state
convert_speed = utils.convert_speed
Expand Down Expand Up @@ -517,7 +516,7 @@ def apply_dashcam_stamps(frame, device=""):
gps_stamp = "" # Set the GPS to a blank placeholder. Elements will be added to this in the next steps.
if (config["general"]["gps"]["enabled"] == True): # Check to see if GPS features are enabled before processing the GPS stamp.
if (config["dashcam"]["stamps"]["gps"]["location"]["enabled"] == True or config["dashcam"]["stamps"]["gps"]["altitude"]["enabled"] == True or config["dashcam"]["stamps"]["gps"]["speed"]["enabled"] == True): # Check to see if at least one of the GPS stamps is enabled.
current_location = get_gps_location_lazy() # Get the most recent location.
current_location = utils.get_gps_location_lazy() # Get the most recent location.

if (config["dashcam"]["stamps"]["gps"]["location"]["enabled"] == True): # Check to see if the GPS location stamp is enabled.
gps_stamp = gps_stamp + "(" + str(f'{current_location[0]:.5f}') + ", " + str(f'{current_location[1]:.5f}') + ") " # Add the current coordinates to the GPS stamp.
Expand Down Expand Up @@ -1103,6 +1102,22 @@ def dashcam_normal(device):
output.write(frame)


# ===============
# Send telemetry:
telemetry_data = {}
telemetry_data["image"] = current_frame_data
current_location = utils.get_gps_location_lazy() # Get the most recent location.
telemetry_data["location"] = {
"time": utils.get_time(),
"lat": current_location[0],
"lon": current_location[1],
"alt": current_location[3],
"spd": current_location[2],
"head": current_location[4]
}
send_telemetry(data)


# ===================
# Handle diagnostics:
update_state("dashcam/normal", instant_framerate)
Expand Down
36 changes: 36 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,40 @@ def count_frames(video):
video_frame_count = 0
return video_frame_count

# This function is called for every frame, and uploads dash-cam telemetry information at regular intervals.
last_telementry_sent = 0 # This holds the timestamp of the last time telemetry was sent.
def send_telemetry(data):
# data = {
# "image": {
# "main": [OpenCV image],
# "rear": "[OpenCV image]",
# ...
# },
# "location": {
# "time": 0.0,
# "lat": 0.0,
# "lon": 0.0,
# "alt": 0.0,
# "spd": 0.0,
# "head": 0.0
# }
# }
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
scale_factor = target_height / original_height
new_width = int(original_width * scale_factor)

data["image"][device] = cv2.resize(data["image"][device], (new_width, target_height)) # Resize the frame to the target size.
retval, buffer = cv2.imencode('.jpg', data["image"][device])
data["image"][device] = base64.b64encode(buffer)
last_telemetry_sent = time.time()

submission = json.dumps(data) # Convert the image information into a string.
request = requests.post("http://localhost/portal/ingest.php", data={"identifier": "ebdbaf0781f03d54422b1321", "data": submission}, timeout=8) # TODO: Add configuration options.



# Calling this function will gracefully stop Predator.
def stop_predator():
Expand All @@ -891,3 +925,5 @@ def to_int(value):
except:
value = 0
return value


0 comments on commit 714daea

Please sign in to comment.