Skip to content

Commit

Permalink
SubMaster: replace SIMULATION constant with property (#495)
Browse files Browse the repository at this point in the history
* Add simulation property to python submaster

* decode bstrings before formatting error messages
  • Loading branch information
fredyshox authored Jul 12, 2023
1 parent c94c7c6 commit a2f1f0c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

NO_TRAVERSAL_LIMIT = 2**64-1
AVG_FREQ_HISTORY = 100
SIMULATION = "SIMULATION" in os.environ

# sec_since_boot is faster, but allow to run standalone too
try:
Expand Down Expand Up @@ -179,6 +178,7 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None,

self.ignore_average_freq = [] if ignore_avg_freq is None else ignore_avg_freq
self.ignore_alive = [] if ignore_alive is None else ignore_alive
self.simulation = bool(int(os.getenv("SIMULATION", "0")))

for s in services:
if addr is not None:
Expand Down Expand Up @@ -231,11 +231,11 @@ def update_msgs(self, cur_time: float, msgs: List[capnp.lib.capnp._DynamicStruct
self.logMonoTime[s] = msg.logMonoTime
self.valid[s] = msg.valid

if SIMULATION:
if self.simulation:
self.freq_ok[s] = True
self.alive[s] = True

if not SIMULATION:
if not self.simulation:
for s in self.data:
# arbitrary small number to avoid float comparison. If freq is 0, we can skip the check
if self.freq[s] > 1e-5:
Expand Down
4 changes: 2 additions & 2 deletions messaging/messaging_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ from .messaging cimport Event as cppEvent, SocketEventHandle as cppSocketEventHa

class MessagingError(Exception):
def __init__(self, endpoint=None):
suffix = "with {endpoint}" if endpoint else ""
message = f"Messaging failure {suffix}: {strerror(errno.errno)}"
suffix = f"with {endpoint.decode('utf-8')}" if endpoint else ""
message = f"Messaging failure {suffix}: {strerror(errno.errno).decode('utf-8')}"
super().__init__(message)


Expand Down

0 comments on commit a2f1f0c

Please sign in to comment.