Esempio n. 1
0
def get_car(logcan, sendcan=None, passive=True):
    # TODO: timeout only useful for replays so controlsd can start before unlogger
    timeout = 2. if passive else None
    candidate, fingerprints = fingerprint(logcan, timeout)

    if candidate is None:
        cloudlog.warning("car doesn't match any fingerprints: %r",
                         fingerprints)
        if passive:
            candidate = "mock"
        else:
            return None, None
    else:
        cloudlog.warning("car does match fingerprint: %r", fingerprints)
        try:
            crash.capture_warning("fingerprinted %s" % candidate)
        except:  # fixes occasional travis errors
            pass

    interface_cls = interfaces[candidate]

    if interface_cls is None:
        cloudlog.warning(
            "car matched %s, but interface wasn't available or failed to import"
            % candidate)
        return None, None

    params = interface_cls.get_params(candidate, fingerprints)

    return interface_cls(params, sendcan), params
Esempio n. 2
0
def crash_log2(fingerprints, fw):
    while True:
        if is_connected_to_internet():
            crash.capture_warning("car doesn't match any fingerprints: %s" %
                                  fingerprints)
            crash.capture_warning("car doesn't match any fw: %s" % fw)
            break
Esempio n. 3
0
def fingerprint(logcan, timeout):
    if os.getenv("SIMULATOR2") is not None:
        return ("simulator2", None)
    elif os.getenv("SIMULATOR") is not None:
        return ("simulator", None)

    cloudlog.warning("waiting for fingerprint...")
    candidate_cars = all_known_cars()
    finger = {}
    st = None
    st_passive = sec_since_boot()  # only relevant when passive
    can_seen = False
    while 1:
        for a in messaging.drain_sock(logcan):
            for can in a.can:
                can_seen = True
                # ignore everything not on bus 0 and with more than 11 bits,
                # which are ussually sporadic and hard to include in fingerprints
                if can.src == 0 and can.address < 0x800:
                    finger[can.address] = len(can.dat)
                    candidate_cars = eliminate_incompatible_cars(
                        can, candidate_cars)

        if st is None and can_seen:
            st = sec_since_boot()  # start time
        ts = sec_since_boot()
        # if we only have one car choice and the time_fingerprint since we got our first
        # message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not
        # broadcast immediately
        if len(candidate_cars) == 1 and st is not None:
            # TODO: better way to decide to wait more if Toyota
            time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS"
                                       in candidate_cars[0]) else 0.1
            if (ts - st) > time_fingerprint:
                break

        # bail if no cars left or we've been waiting too long
        elif len(candidate_cars) == 0 or (timeout and
                                          (ts - st_passive) > timeout):
            return None, finger

        time.sleep(0.01)

    cloudlog.warning("fingerprinted %s", candidate_cars[0])
    crash.capture_warning("fingerprinted %s" % candidate_cars[0])
    return (candidate_cars[0], finger)
Esempio n. 4
0
def get_car(logcan, sendcan, is_panda_black=False):

  candidate, fingerprints, vin = fingerprint(logcan, sendcan, is_panda_black)

  if candidate is None:
    cloudlog.warning("car doesn't match any fingerprints: %r", fingerprints)
    candidate = "mock"
  else:
    cloudlog.warning("car does match fingerprint: %r", fingerprints)
    try:
      crash.capture_warning("fingerprinted %s" % candidate)
    except:  # fixes occasional travis errors
      pass

  CarInterface, CarController = interfaces[candidate]
  car_params = CarInterface.get_params(candidate, fingerprints[0], vin, is_panda_black)

  return CarInterface(car_params, CarController), car_params
Esempio n. 5
0
def query_thread():
    global last_query_result, last_query_pos, cache_valid
    #api = overpy.Overpass(url=OVERPASS_API_URL, headers=OVERPASS_HEADERS, timeout=20.)
    api = overpy.Overpass(url=OVERPASS_API_URL)

    while True:
        time.sleep(1)
        if last_gps is not None:
            fix_ok = last_gps.flags & 1
            if not fix_ok:
                continue

            if last_query_pos is not None:
                cur_ecef = geodetic2ecef(
                    (last_gps.latitude, last_gps.longitude, last_gps.altitude))
                prev_ecef = geodetic2ecef(
                    (last_query_pos.latitude, last_query_pos.longitude,
                     last_query_pos.altitude))
                dist = np.linalg.norm(cur_ecef - prev_ecef)
                if dist < 3000:  #updated when we are 1km from the edge of the downloaded circle
                    continue

                if dist > 4000:
                    cache_valid = False

            q = build_way_query(last_gps.latitude,
                                last_gps.longitude,
                                radius=4000)
            if connected_to_internet():
                try:
                    try:
                        new_result = api.query(q)
                    except:
                        api2 = overpy.Overpass(url=OVERPASS_API_URL2)
                        print("Using backup Server")
                        new_result = api2.query(q)

                    # Build kd-tree
                    nodes = []
                    real_nodes = []
                    node_to_way = defaultdict(list)
                    location_info = {}

                    for n in new_result.nodes:
                        nodes.append((float(n.lat), float(n.lon), 0))
                        real_nodes.append(n)

                    for way in new_result.ways:
                        for n in way.nodes:
                            node_to_way[n.id].append(way)

                    for area in new_result.areas:
                        if area.tags.get('admin_level', '') == "2":
                            location_info['country'] = area.tags.get(
                                'ISO3166-1:alpha2', '')
                        if area.tags.get('admin_level', '') == "4":
                            location_info['region'] = area.tags.get('name', '')

                    nodes = np.asarray(nodes)
                    nodes = geodetic2ecef(nodes)
                    tree = spatial.cKDTree(nodes)

                    query_lock.acquire()
                    last_query_result = new_result, tree, real_nodes, node_to_way, location_info
                    last_query_pos = last_gps
                    cache_valid = True
                    query_lock.release()

                except Exception as e:
                    print(e)
                    crash.capture_warning(e)
                    query_lock.acquire()
                    last_query_result = None
                    query_lock.release()
            else:
                query_lock.acquire()
                last_query_result = None
                query_lock.release()
Esempio n. 6
0
def crash_log(candidate):
  while True:
    if is_connected_to_internet():
      crash.capture_warning("fingerprinted %s" % candidate)
      break
Esempio n. 7
0
def log_fingerprinted(candidate):
    while True:
        crash.capture_warning("fingerprinted %s" % candidate)
        break
Esempio n. 8
0
def crash_log2(fingerprints):
    crash.capture_warning("car doesn't match any fingerprints: %s" %
                          fingerprints)
Esempio n. 9
0
def crash_log(candidate):
    crash.capture_warning("fingerprinted %s" % candidate)
Esempio n. 10
0
def event_fingerprinted_error(fingerprints, fw):
    crash.capture_warning("car doesn't match any fingerprints: %s" %
                          fingerprints)
    crash.capture_warning("car doesn't match any fw: %s" % fw)