openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
5.7 KiB

Squashed 'cereal/' changes from 90e48c54..b8382bbb b8382bbb steerLimitTimer should be car dependent 9a229687 add pa0 temp to ThermalData f6f0f60e Add stock Fcw to carState b608683f no l/r distinction for LDW 555f48d6 Add ldw alert 8e8b4a4a Remove plusFrame socket in favor of UiLayoutState 3410325c log stock AEB events 2219f2bd Add warning about not using cython version of sec_since_boot 8f1a5122 for legacy-testing reasons, better to define the used percent instead of avail e86d9545 adding low memory event ad238340 remove TODO d0962b34 log mem available and cpu perc in thermald 3b753be9 Implement error handling and exceptions (#18) a7d5bb76 add explicit dependencies on services.h 1ba64677 fix linter c7d215b6 Added communityFeatureDisallowed event 492140a5 Added communityFeature bit detection to CarParams 266a5fed log Panda fault types 347a8661 Switch from polling on FIFOs to signal (#12) e25bba77 no need to double build the objects fe43a994 20Hz for radar time step is very standard 2aabf1ee Added radar time step to car params e8ae9086 Generate capnp for java 57126a23 cereal_shared da655cd3 Add uptime to health f6a8e394 add test with multiple subscribers 84b3af53 comment out the debugging 4b9c942a added power save state to health packet 66be3708 run python unittest in ci 52c6db87 Run scons in CI (#14) 9414615b do need it, but only for arm 2856c37c remove gnustl_shared 7f05ee64 fix apks e3a6bded Revert "no more makefiles" 487fbd06 don't rely on BASEDIR, and add zmq library 223e37a5 no more makefiles da2ed115 don't link the wrong one fe9fe2a2 scons builds the python lib now 2f81135e err, it can't build services.h 57b03f8b now we shouldn't need that yaml crap everywhere f8e53277 bridge builds with services.h 2b0cb608 noOutput safety mode is now called silent 83880d51 add msgq tests bcad1848 msgq: dont block when fifo does not exists b4b26782 Default to zmq 473e2912 fix compilation in docker 30aaaddc msgq: try again when no timeout on poll but also no message c4f2ad53 msgq: make sure read_fifos is initalized so we dont close random fds 4e513a85 msgq: dont clean up uninitialized sockerts c008b630 also remove the fifo from disk ef64eb27 MSGQ stability improvements when opening and closing lots of queues e147abcc Revert "Revert "deprecate irpwr"" 932dc32e Revert "deprecate irpwr" a6844150 disengage ec27e18c capnpc also generated the header files ee52ab9e deprecate irpwr 301c74c8 Merge branch 'master' of github.com:commaai/cereal 6da7d55a add front frame a5944eb4 add conflate parameter for SubSocket::create ca8df170 Add fault status to health ef4ded06 add conflate support in SubSocket constructor 7fd314af update scons build file 93d814e4 add saturated flags to indi and lqr logs 50302fee add steeringRateLimited to car.capnp 05e3513d add msgq readme a6759a95 faster make 94b73778 Add struct to log FW version 64ce0b5f add scons build dc9ad18a add debug print statement on SIGINT 4a612698 Merge pull request #10 from commaai/msgq 4873449a use recv one or none after poll a054864b default to msgq fbc4a4cf oops bad number 5067cf4c add meta cbd02865 fix export prefix and make shared library world readable c2730541 add c exports for jni usage e77f41ef zmq already sets the errno correctly 3196cf69 Fix service list path in bridge d35515a2 add all msgq files, but dont use as default a68a38fa Don't delete context from python side only bd46c225 Revert "zmq_ctx_term is blocking" a1fc26b8 zmq_ctx_term is blocking 09021820 remote address support 21a35361 only delete subsocket when created by same object 34df7351 remove extra underscore from __dealloc__ c8748f86 fix internal refs 79b2fbf7 fixups 23ad2563 import messaging and services git-subtree-dir: cereal git-subtree-split: b8382bbb2b8156f2f1d7e1c1b42b46c54d85761f
5 years ago
# must be build with scons
from .messaging_pyx import Context, Poller, SubSocket, PubSocket # pylint: disable=no-name-in-module, import-error
from .messaging_pyx import MultiplePublishersError, MessagingError # pylint: disable=no-name-in-module, import-error
assert MultiplePublishersError
assert MessagingError
from cereal import log
from cereal.services import service_list
# sec_since_boot is faster, but allow to run standalone too
try:
from common.realtime import sec_since_boot
except ImportError:
import time
sec_since_boot = time.time
print("Warning, using python time.time() instead of faster sec_since_boot")
context = Context()
def new_message():
dat = log.Event.new_message()
dat.logMonoTime = int(sec_since_boot() * 1e9)
dat.valid = True
return dat
def pub_sock(endpoint):
sock = PubSocket()
sock.connect(context, endpoint)
return sock
def sub_sock(endpoint, poller=None, addr="127.0.0.1", conflate=False, timeout=None):
sock = SubSocket()
addr = addr.encode('utf8')
sock.connect(context, endpoint, addr, conflate)
if timeout is not None:
sock.setTimeout(timeout)
if poller is not None:
poller.registerSocket(sock)
return sock
def drain_sock_raw(sock, wait_for_one=False):
"""Receive all message currently available on the queue"""
ret = []
while 1:
if wait_for_one and len(ret) == 0:
dat = sock.receive()
else:
dat = sock.receive(non_blocking=True)
if dat is None:
break
ret.append(dat)
return ret
def drain_sock(sock, wait_for_one=False):
"""Receive all message currently available on the queue"""
ret = []
while 1:
if wait_for_one and len(ret) == 0:
dat = sock.receive()
else:
dat = sock.receive(non_blocking=True)
if dat is None: # Timeout hit
break
dat = log.Event.from_bytes(dat)
ret.append(dat)
return ret
# TODO: print when we drop packets?
def recv_sock(sock, wait=False):
"""Same as drain sock, but only returns latest message. Consider using conflate instead."""
dat = None
while 1:
if wait and dat is None:
rcv = sock.receive()
else:
rcv = sock.receive(non_blocking=True)
if rcv is None: # Timeout hit
break
dat = rcv
if dat is not None:
dat = log.Event.from_bytes(dat)
return dat
def recv_one(sock):
dat = sock.receive()
if dat is not None:
dat = log.Event.from_bytes(dat)
return dat
def recv_one_or_none(sock):
dat = sock.receive(non_blocking=True)
if dat is not None:
dat = log.Event.from_bytes(dat)
return dat
def recv_one_retry(sock):
"""Keep receiving until we get a message"""
while True:
dat = sock.receive()
if dat is not None:
return log.Event.from_bytes(dat)
def get_one_can(logcan):
while True:
can = recv_one_retry(logcan)
if len(can.can) > 0:
return can
class SubMaster():
def __init__(self, services, ignore_alive=None, addr="127.0.0.1"):
self.poller = Poller()
self.frame = -1
self.updated = {s : False for s in services}
self.rcv_time = {s : 0. for s in services}
self.rcv_frame = {s : 0 for s in services}
self.alive = {s : False for s in services}
self.sock = {}
self.freq = {}
self.data = {}
self.logMonoTime = {}
self.valid = {}
if ignore_alive is not None:
self.ignore_alive = ignore_alive
else:
self.ignore_alive = []
for s in services:
if addr is not None:
self.sock[s] = sub_sock(s, poller=self.poller, addr=addr, conflate=True)
self.freq[s] = service_list[s].frequency
data = new_message()
if s in ['can', 'sensorEvents', 'liveTracks', 'sendCan',
'ethernetData', 'cellInfo', 'wifiScan',
'trafficEvents', 'orbObservation', 'carEvents']:
data.init(s, 0)
else:
data.init(s)
self.data[s] = getattr(data, s)
self.logMonoTime[s] = 0
self.valid[s] = data.valid
def __getitem__(self, s):
return self.data[s]
def update(self, timeout=1000):
msgs = []
for sock in self.poller.poll(timeout):
msgs.append(recv_one_or_none(sock))
self.update_msgs(sec_since_boot(), msgs)
def update_msgs(self, cur_time, msgs):
# TODO: add optional input that specify the service to wait for
self.frame += 1
self.updated = dict.fromkeys(self.updated, False)
for msg in msgs:
if msg is None:
continue
s = msg.which()
self.updated[s] = True
self.rcv_time[s] = cur_time
self.rcv_frame[s] = self.frame
self.data[s] = getattr(msg, s)
self.logMonoTime[s] = msg.logMonoTime
self.valid[s] = msg.valid
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:
# alive if delay is within 10x the expected frequency
self.alive[s] = (cur_time - self.rcv_time[s]) < (10. / self.freq[s])
else:
self.alive[s] = True
def all_alive(self, service_list=None):
if service_list is None: # check all
service_list = self.alive.keys()
return all(self.alive[s] for s in service_list if s not in self.ignore_alive)
def all_valid(self, service_list=None):
if service_list is None: # check all
service_list = self.valid.keys()
return all(self.valid[s] for s in service_list)
def all_alive_and_valid(self, service_list=None):
if service_list is None: # check all
service_list = self.alive.keys()
return self.all_alive(service_list=service_list) and self.all_valid(service_list=service_list)
class PubMaster():
def __init__(self, services):
self.sock = {}
for s in services:
self.sock[s] = pub_sock(s)
def send(self, s, dat):
# accept either bytes or capnp builder
if not isinstance(dat, bytes):
dat = dat.to_bytes()
self.sock[s].send(dat)