wip
This commit is contained in:
@@ -4,6 +4,7 @@ import uuid
|
|||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
from openpilot.common.params import Params
|
from openpilot.common.params import Params
|
||||||
from openpilot.system.hardware.hw import Paths
|
from openpilot.system.hardware.hw import Paths
|
||||||
|
|
||||||
|
|||||||
33
common/watcher.py
Normal file
33
common/watcher.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Initialize the socket without connecting
|
||||||
|
watcher_sock = None
|
||||||
|
|
||||||
|
class Watcher:
|
||||||
|
def ensure_socket_connected():
|
||||||
|
global watcher_sock
|
||||||
|
if watcher_sock is None or watcher_sock.fileno() == -1: # Checks if socket is not initialized or closed
|
||||||
|
try:
|
||||||
|
# Attempt to initialize and connect the socket
|
||||||
|
watcher_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
watcher_sock.connect("/tmp/oscar_watcher.sock")
|
||||||
|
except socket.error:
|
||||||
|
# If connection fails, set sock to None and do nothing
|
||||||
|
watcher_sock = None
|
||||||
|
|
||||||
|
def log_watch(var_name, message):
|
||||||
|
global watcher_sock
|
||||||
|
ensure_socket_connected() # Ensure the socket is connected before attempting to log
|
||||||
|
if watcher_sock: # Proceed only if sock is not None (i.e., is connected)
|
||||||
|
message_json = json.dumps(message)
|
||||||
|
try:
|
||||||
|
watcher_sock.sendall(message_json.encode('utf-8') + b'\n')
|
||||||
|
except socket.error:
|
||||||
|
# Handle potential error in sending (e.g., if connection was lost)
|
||||||
|
watcher_sock.close() # Close the current socket to clean up resources
|
||||||
|
watcher_sock = None # Reset sock to ensure reconnection attempt on next call
|
||||||
|
|
||||||
|
#message = {"variable": "car_stats", "value": {"car_lights_on": [3, 5, 7], "car_state": "on"}}
|
||||||
|
#log_watch(sock, message)
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ from openpilot.selfdrive.controls.lib.alertmanager import AlertManager, set_offr
|
|||||||
from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel
|
from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel
|
||||||
from openpilot.system.hardware import HARDWARE
|
from openpilot.system.hardware import HARDWARE
|
||||||
|
|
||||||
|
from openpilot.common.watcher import Watcher
|
||||||
|
|
||||||
SOFT_DISABLE_TIME = 3 # seconds
|
SOFT_DISABLE_TIME = 3 # seconds
|
||||||
LDW_MIN_SPEED = 31 * CV.MPH_TO_MS
|
LDW_MIN_SPEED = 31 * CV.MPH_TO_MS
|
||||||
LANE_DEPARTURE_THRESHOLD = 0.1
|
LANE_DEPARTURE_THRESHOLD = 0.1
|
||||||
@@ -131,6 +133,9 @@ class Controls:
|
|||||||
|
|
||||||
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX
|
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX
|
||||||
|
|
||||||
|
# Test
|
||||||
|
Watcher.log_watch("always_on_lateral", self.always_on_lateral)
|
||||||
|
|
||||||
# read params
|
# read params
|
||||||
self.is_metric = self.params.get_bool("IsMetric")
|
self.is_metric = self.params.get_bool("IsMetric")
|
||||||
self.is_ldw_enabled = self.params.get_bool("IsLdwEnabled")
|
self.is_ldw_enabled = self.params.get_bool("IsLdwEnabled")
|
||||||
|
|||||||
Reference in New Issue
Block a user