Esempio n. 1
0
def getVersion():
    return {
        "version": get_version(),
        "remote": get_git_remote(),
        "branch": get_git_branch(),
        "commit": get_git_commit(),
    }
Esempio n. 2
0
def register():
    params = Params()
    params.put("Version", version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit())
    params.put("GitBranch", get_git_branch())
    params.put("GitRemote", get_git_remote())
    params.put("SubscriberInfo", get_subscriber_info())

    # create a key for auth
    # your private key is kept on your device persist partition and never sent to our servers
    # do not erase your persist partition
    if not os.path.isfile("/persist/comma/id_rsa.pub"):
        cloudlog.warning("generating your personal RSA key")
        mkdirs_exists_ok("/persist/comma")
        assert os.system(
            "echo -e 'y\n' | ssh-keygen -t rsa -b 2048 -f /persist/comma/id_rsa.tmp -N ''"
        ) == 0
        os.rename("/persist/comma/id_rsa.tmp", "/persist/comma/id_rsa")
        os.rename("/persist/comma/id_rsa.tmp.pub", "/persist/comma/id_rsa.pub")

    dongle_id, access_token = params.get("DongleId"), params.get("AccessToken")
    public_key = open("/persist/comma/id_rsa.pub").read()

    # create registration token
    # in the future, this key will make JWTs directly
    private_key = open("/persist/comma/id_rsa").read()
    register_token = jwt.encode(
        {
            'register': True,
            'exp': datetime.utcnow() + timedelta(hours=1)
        },
        private_key,
        algorithm='RS256')

    try:
        cloudlog.info("getting pilotauth")
        resp = api_get("v2/pilotauth/",
                       method='POST',
                       timeout=15,
                       imei=get_imei(),
                       serial=get_serial(),
                       public_key=public_key,
                       register_token=register_token)
        dongleauth = json.loads(resp.text)
        dongle_id, access_token = dongleauth["dongle_id"].encode(
            'ascii'), dongleauth["access_token"].encode('ascii')

        params.put("DongleId", dongle_id)
        params.put("AccessToken", access_token)
        return dongle_id, access_token
    except Exception:
        cloudlog.exception("failed to authenticate")
        if dongle_id is not None and access_token is not None:
            return dongle_id, access_token
        else:
            return None
Esempio n. 3
0
def register():
    params = Params()
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit())
    params.put("GitBranch", get_git_branch())
    params.put("GitRemote", get_git_remote())
    params.put("SubscriberInfo", get_subscriber_info())

    # make key readable by app users (ai.comma.plus.offroad)
    os.chmod('/persist/comma/', 0o755)
    os.chmod('/persist/comma/id_rsa', 0o744)

    dongle_id, access_token = params.get(
        "DongleId", encoding='utf8'), params.get("AccessToken",
                                                 encoding='utf8')
    public_key = open("/persist/comma/id_rsa.pub").read()

    # create registration token
    # in the future, this key will make JWTs directly
    private_key = open("/persist/comma/id_rsa").read()

    # late import
    import jwt
    register_token = jwt.encode(
        {
            'register': True,
            'exp': datetime.utcnow() + timedelta(hours=1)
        },
        private_key,
        algorithm='RS256')

    try:
        cloudlog.info("getting pilotauth")
        resp = api_get("v2/pilotauth/",
                       method='POST',
                       timeout=15,
                       imei=get_imei(),
                       serial=get_serial(),
                       public_key=public_key,
                       register_token=register_token)
        dongleauth = json.loads(resp.text)
        dongle_id, access_token = dongleauth["dongle_id"], dongleauth[
            "access_token"]

        params.put("DongleId", dongle_id)
        params.put("AccessToken", access_token)
        return dongle_id, access_token
    except Exception:
        cloudlog.exception("failed to authenticate")
        if dongle_id is not None and access_token is not None:
            return dongle_id, access_token
        else:
            return None
def register():
  params = Params()
  params.put("Version", version)
  params.put("TermsVersion", terms_version)
  params.put("TrainingVersion", training_version)

  params.put("GitCommit", get_git_commit(default=""))
  params.put("GitBranch", get_git_branch(default=""))
  params.put("GitRemote", get_git_remote(default=""))
  params.put("SubscriberInfo", get_subscriber_info())

  # create a key for auth
  # your private key is kept on your device persist partition and never sent to our servers
  # do not erase your persist partition
  if not os.path.isfile(PERSIST+"/comma/id_rsa.pub"):
    cloudlog.warning("generating your personal RSA key")
    mkdirs_exists_ok(PERSIST+"/comma")
    assert os.system("openssl genrsa -out "+PERSIST+"/comma/id_rsa.tmp 2048") == 0
    assert os.system("openssl rsa -in "+PERSIST+"/comma/id_rsa.tmp -pubout -out "+PERSIST+"/comma/id_rsa.tmp.pub") == 0
    os.rename(PERSIST+"/comma/id_rsa.tmp", PERSIST+"/comma/id_rsa")
    os.rename(PERSIST+"/comma/id_rsa.tmp.pub", PERSIST+"/comma/id_rsa.pub")

  # make key readable by app users (ai.comma.plus.offroad)
  os.chmod(PERSIST+'/comma/', 0o755)
  os.chmod(PERSIST+'/comma/id_rsa', 0o744)

  dongle_id = params.get("DongleId", encoding='utf8')
  public_key = open(PERSIST+"/comma/id_rsa.pub").read()

  # create registration token
  # in the future, this key will make JWTs directly
  private_key = open(PERSIST+"/comma/id_rsa").read()

  # late import
  import jwt
  register_token = jwt.encode({'register': True, 'exp': datetime.utcnow() + timedelta(hours=1)}, private_key, algorithm='RS256')

  try:
    cloudlog.info("getting pilotauth")
    resp = api_get("v2/pilotauth/", method='POST', timeout=15,
                   imei=get_imei(0), imei2=get_imei(1), serial=get_serial(), public_key=public_key, register_token=register_token)
    dongleauth = json.loads(resp.text)
    dongle_id = dongleauth["dongle_id"]

    params.put("DongleId", dongle_id)
    return dongle_id
  except Exception:
    cloudlog.exception("failed to authenticate")
    if dongle_id is not None:
      return dongle_id
    else:
      return None
Esempio n. 5
0
def manager_init(should_register=False):
  params = Params()    # apparently not registering in registration.py requires us to do this here
  if should_register:
    reg_res = register()
    if reg_res:
      dongle_id, dongle_secret = reg_res
    else:
      raise Exception("server registration failed")
  else:
    # apparently not registering in registration.py requires us to do this here
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit())
    params.put("GitBranch", get_git_branch())
    params.put("GitRemote", get_git_remote())
    params.put("SubscriberInfo", get_subscriber_info())
    dongle_id = params.get('DongleId')
    if dongle_id:
      dongle_id = dongle_id.decode("utf-8")
    else:
      dongle_id = str("c"*16)

  # set dongle id
  cloudlog.info("dongle id is " + dongle_id)
  os.environ['DONGLE_ID'] = dongle_id

  cloudlog.info("dirty is %d" % dirty)
  if not dirty:
    os.environ['CLEAN'] = '1'

  cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=True)
  crash.bind_user(id=dongle_id)
  crash.bind_extra(version=version, dirty=dirty, is_eon=True)

  os.umask(0)
  try:
    os.mkdir(ROOT, 0o777)
  except OSError:
    pass

  # ensure shared libraries are readable by apks
  if ANDROID:
    os.chmod(BASEDIR, 0o755)
    os.chmod(os.path.join(BASEDIR, "cereal"), 0o755)
    os.chmod(os.path.join(BASEDIR, "cereal", "libmessaging_shared.so"), 0o755)
Esempio n. 6
0
def manager_init():

    # update system time from panda
    set_time(cloudlog)

    params = Params()
    params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)

    default_params = [
        ("OpenpilotEnabledToggle", "1"),
        ("CommunityFeaturesToggle", "1"),
        ("IsMetric", "1"),

        # HKG
        ("UseClusterSpeed", "1"),
        ("LongControlEnabled", "0"),
        ("MadModeEnabled", "1"),
        ("IsLdwsCar", "0"),
        ("LaneChangeEnabled", "0"),
        ("AutoLaneChangeEnabled", "0"),
        ("SccSmootherSlowOnCurves", "0"),
        ("SccSmootherSyncGasPressed", "0"),
        ("StockNaviDecelEnabled", "0"),
        ("ShowDebugUI", "0"),
        ("CustomLeadMark", "0")
    ]
    if not PC:
        default_params.append(
            ("LastUpdateTime",
             datetime.datetime.utcnow().isoformat().encode('utf8')))

    if params.get_bool("RecordFrontLock"):
        params.put_bool("RecordFront", True)

    # set unset params
    for k, v in default_params:
        if params.get(k) is None:
            params.put(k, v)

    # is this dashcam?
    if os.getenv("PASSIVE") is not None:
        params.put_bool("Passive", bool(int(os.getenv("PASSIVE"))))

    if params.get("Passive") is None:
        raise Exception("Passive must be set to continue")

    # Create folders needed for msgq
    try:
        os.mkdir("/dev/shm")
    except FileExistsError:
        pass
    except PermissionError:
        print("WARNING: failed to make /dev/shm")

    # set version params
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit(default=""))
    params.put("GitBranch", get_git_branch(default=""))
    params.put("GitRemote", get_git_remote(default=""))

    # set dongle id
    reg_res = register(show_spinner=True)
    if reg_res:
        dongle_id = reg_res
    else:
        serial = params.get("HardwareSerial")
        raise Exception(f"Registration failed for device {serial}")
    os.environ['DONGLE_ID'] = dongle_id  # Needed for swaglog

    if not dirty:
        os.environ['CLEAN'] = '1'

    cloudlog.bind_global(dongle_id=dongle_id,
                         version=version,
                         dirty=dirty,
                         device=HARDWARE.get_device_type())

    if comma_remote and not (os.getenv("NOLOG") or os.getenv("NOCRASH") or PC):
        crash.init()
    crash.bind_user(id=dongle_id)
    crash.bind_extra(dirty=dirty,
                     origin=origin,
                     branch=branch,
                     commit=commit,
                     device=HARDWARE.get_device_type())
Esempio n. 7
0
def manager_init():
  # update system time from panda
  set_time(cloudlog)

  # save boot log
  subprocess.call("./bootlog", cwd=os.path.join(BASEDIR, "selfdrive/loggerd"))

  params = Params()
  params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)

  default_params = [
    ("CompletedTrainingVersion", "0"),
    ("HasAcceptedTerms", "0"),
    ("OpenpilotEnabledToggle", "1"),
  ]
  if not PC:
    default_params.append(("LastUpdateTime", datetime.datetime.utcnow().isoformat().encode('utf8')))

  if params.get_bool("RecordFrontLock"):
    params.put_bool("RecordFront", True)

  if not params.get_bool("DisableRadar_Allow"):
    params.delete("DisableRadar")

  # set unset params
  for k, v in default_params:
    if params.get(k) is None:
      params.put(k, v)

  # is this dashcam?
  if os.getenv("PASSIVE") is not None:
    params.put_bool("Passive", bool(int(os.getenv("PASSIVE"))))

  if params.get("Passive") is None:
    raise Exception("Passive must be set to continue")

  # Create folders needed for msgq
  try:
    os.mkdir("/dev/shm")
  except FileExistsError:
    pass
  except PermissionError:
    print("WARNING: failed to make /dev/shm")

  # set version params
  params.put("Version", version)
  params.put("TermsVersion", terms_version)
  params.put("TrainingVersion", training_version)
  params.put("GitCommit", get_git_commit(default=""))
  params.put("GitBranch", get_git_branch(default=""))
  params.put("GitRemote", get_git_remote(default=""))

  # set dongle id
  reg_res = register(show_spinner=True)
  if reg_res:
    dongle_id = reg_res
  else:
    serial = params.get("HardwareSerial")
    raise Exception(f"Registration failed for device {serial}")
  os.environ['DONGLE_ID'] = dongle_id  # Needed for swaglog

  if not dirty:
    os.environ['CLEAN'] = '1'

  cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty,
                       device=HARDWARE.get_device_type())

  if comma_remote and not (os.getenv("NOLOG") or os.getenv("NOCRASH") or PC):
    crash.init()
  crash.bind_user(id=dongle_id)
  crash.bind_extra(dirty=dirty, origin=origin, branch=branch, commit=commit,
                   device=HARDWARE.get_device_type())
Esempio n. 8
0
def manager_init():

    # update system time from panda
    set_time(cloudlog)

    params = Params()
    params.manager_start()

    default_params = [
        ("CompletedTrainingVersion", "0"),
        ("HasAcceptedTerms", "0"),
        ("LastUpdateTime",
         datetime.datetime.utcnow().isoformat().encode('utf8')),
        ("OpenpilotEnabledToggle", "1"),
    ]

    if TICI:
        default_params.append(("IsUploadRawEnabled", "1"))

    if params.get_bool("RecordFrontLock"):
        params.put_bool("RecordFront", True)

    # set unset params
    for k, v in default_params:
        if params.get(k) is None:
            params.put(k, v)

    # is this dashcam?
    if os.getenv("PASSIVE") is not None:
        params.put_bool("Passive", bool(int(os.getenv("PASSIVE"))))

    if params.get("Passive") is None:
        raise Exception("Passive must be set to continue")

    os.umask(0)  # Make sure we can create files with 777 permissions

    # Create folders needed for msgq
    try:
        os.mkdir("/dev/shm")
    except FileExistsError:
        pass
    except PermissionError:
        print("WARNING: failed to make /dev/shm")

    # set version params
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit(default=""))
    params.put("GitBranch", get_git_branch(default=""))
    params.put("GitRemote", get_git_remote(default=""))

    # set dongle id
    dongle_id = register(show_spinner=True)
    if dongle_id is not None:
        os.environ['DONGLE_ID'] = dongle_id  # Needed for swaglog

    if not dirty:
        os.environ['CLEAN'] = '1'

    cloudlog.bind_global(dongle_id=dongle_id,
                         version=version,
                         dirty=dirty,
                         device=HARDWARE.get_device_type())

    if not (dongle_id is None or os.getenv("NOLOG") or os.getenv("NOCRASH")
            or PC):
        crash.init()
    crash.bind_user(id=dongle_id)
    crash.bind_extra(dirty=dirty,
                     origin=origin,
                     branch=branch,
                     commit=commit,
                     device=HARDWARE.get_device_type())
Esempio n. 9
0
def register(show_spinner=False):
    params = Params()
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)

    params.put("GitCommit", get_git_commit(default=""))
    params.put("GitBranch", get_git_branch(default=""))
    params.put("GitRemote", get_git_remote(default=""))
    params.put("SubscriberInfo", HARDWARE.get_subscriber_info())

    IMEI = params.get("IMEI", encoding='utf8')
    HardwareSerial = params.get("HardwareSerial", encoding='utf8')

    needs_registration = (None in [IMEI, HardwareSerial])

    # create a key for auth
    # your private key is kept on your device persist partition and never sent to our servers
    # do not erase your persist partition
    if not os.path.isfile(PERSIST + "/comma/id_rsa.pub"):
        needs_registration = True
        cloudlog.warning("generating your personal RSA key")
        mkdirs_exists_ok(PERSIST + "/comma")
        assert os.system("openssl genrsa -out " + PERSIST +
                         "/comma/id_rsa.tmp 2048") == 0
        assert os.system("openssl rsa -in " + PERSIST +
                         "/comma/id_rsa.tmp -pubout -out " + PERSIST +
                         "/comma/id_rsa.tmp.pub") == 0
        os.rename(PERSIST + "/comma/id_rsa.tmp", PERSIST + "/comma/id_rsa")
        os.rename(PERSIST + "/comma/id_rsa.tmp.pub",
                  PERSIST + "/comma/id_rsa.pub")

    # make key readable by app users (ai.comma.plus.offroad)
    os.chmod(PERSIST + '/comma/', 0o755)
    os.chmod(PERSIST + '/comma/id_rsa', 0o744)

    dongle_id = params.get("DongleId", encoding='utf8')
    needs_registration = needs_registration or dongle_id is None

    if needs_registration:
        if show_spinner:
            spinner = Spinner()
            spinner.update("registering device")

        # Create registration token, in the future, this key will make JWTs directly
        private_key = open(PERSIST + "/comma/id_rsa").read()
        public_key = open(PERSIST + "/comma/id_rsa.pub").read()
        register_token = jwt.encode(
            {
                'register': True,
                'exp': datetime.utcnow() + timedelta(hours=1)
            },
            private_key,
            algorithm='RS256')

        # Block until we get the imei
        imei1, imei2 = None, None
        while imei1 is None and imei2 is None:
            try:
                imei1, imei2 = HARDWARE.get_imei(0), HARDWARE.get_imei(1)
            except Exception:
                cloudlog.exception("Error getting imei, trying again...")
                time.sleep(1)

        serial = HARDWARE.get_serial()
        params.put("IMEI", imei1)
        params.put("HardwareSerial", serial)

        while True:
            try:
                cloudlog.info("getting pilotauth")
                resp = api_get("v2/pilotauth/",
                               method='POST',
                               timeout=15,
                               imei=imei1,
                               imei2=imei2,
                               serial=serial,
                               public_key=public_key,
                               register_token=register_token)
                dongleauth = json.loads(resp.text)
                dongle_id = dongleauth["dongle_id"]
                params.put("DongleId", dongle_id)
                break
            except Exception:
                cloudlog.exception("failed to authenticate")
                time.sleep(1)

        if show_spinner:
            spinner.close()

    return dongle_id
Esempio n. 10
0
def manager_init():

    # update system time from panda
    set_time(cloudlog)

    params = Params()
    params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)

    default_params = [
        ("CompletedTrainingVersion", "0"),
        ("HasAcceptedTerms", "0"),
        ("LastUpdateTime",
         datetime.datetime.utcnow().isoformat().encode('utf8')),
        ("OpenpilotEnabledToggle", "1"),
        ("IsOpenpilotViewEnabled", "0"),
        ("OpkrAutoShutdown", "2"),
        ("OpkrAutoScreenOff", "0"),
        ("OpkrUIBrightness", "0"),
        ("OpkrUIBrightness", "0"),
        ("OpkrUIVolumeBoost", "0"),
        ("OpkrEnableDriverMonitoring", "1"),
        ("OpkrEnableLogger", "0"),
        ("OpkrEnableUploader", "0"),
        ("OpkrEnableGetoffAlert", "1"),
        ("OpkrAutoResume", "1"),
        ("OpkrVariableCruise", "1"),
        ("OpkrLaneChangeSpeed", "45"),
        ("OpkrAutoLaneChangeDelay", "0"),
        ("OpkrSteerAngleCorrection", "0"),
        ("PutPrebuiltOn", "0"),
        ("LdwsCarFix", "0"),
        ("LateralControlMethod", "0"),
        ("CruiseStatemodeSelInit", "1"),
        ("InnerLoopGain", "35"),
        ("OuterLoopGain", "20"),
        ("TimeConstant", "14"),
        ("ActuatorEffectiveness", "20"),
        ("Scale", "1500"),
        ("LqrKi", "15"),
        ("DcGain", "27"),
        ("IgnoreZone", "1"),
        ("PidKp", "20"),
        ("PidKi", "40"),
        ("PidKd", "150"),
        ("PidKf", "5"),
        ("CameraOffsetAdj", "60"),
        ("SteerRatioAdj", "155"),
        ("SteerRatioMaxAdj", "175"),
        ("SteerActuatorDelayAdj", "15"),
        ("SteerRateCostAdj", "35"),
        ("SteerLimitTimerAdj", "40"),
        ("TireStiffnessFactorAdj", "85"),
        ("SteerMaxBaseAdj", "300"),
        ("SteerMaxAdj", "384"),
        ("SteerDeltaUpBaseAdj", "3"),
        ("SteerDeltaUpAdj", "3"),
        ("SteerDeltaDownBaseAdj", "7"),
        ("SteerDeltaDownAdj", "7"),
        ("SteerMaxvAdj", "13"),
        ("OpkrBatteryChargingControl", "1"),
        ("OpkrBatteryChargingMin", "70"),
        ("OpkrBatteryChargingMax", "80"),
        ("LeftCurvOffsetAdj", "0"),
        ("RightCurvOffsetAdj", "0"),
        ("DebugUi1", "0"),
        ("DebugUi2", "0"),
        ("LongLogDisplay", "0"),
        ("OpkrBlindSpotDetect", "1"),
        ("OpkrMaxAngleLimit", "90"),
        ("OpkrSpeedLimitOffset", "0"),
        ("LimitSetSpeedCamera", "0"),
        ("LimitSetSpeedCameraDist", "0"),
        ("OpkrLiveSteerRatio", "1"),
        ("OpkrVariableSteerMax", "1"),
        ("OpkrVariableSteerDelta", "0"),
        ("FingerprintTwoSet", "1"),
        ("OpkrVariableCruiseProfile", "0"),
        ("OpkrLiveTune", "0"),
        ("OpkrDrivingRecord", "0"),
        ("OpkrTurnSteeringDisable", "0"),
        ("CarModel", ""),
        ("CarModelAbb", ""),
        ("OpkrHotspotOnBoot", "0"),
        ("OpkrSSHLegacy", "1"),
        ("ShaneFeedForward", "0"),
        ("CruiseOverMaxSpeed", "0"),
        ("JustDoGearD", "0"),
        ("LanelessMode", "0"),
        ("ComIssueGone", "0"),
        ("MaxSteer", "384"),
        ("MaxRTDelta", "112"),
        ("MaxRateUp", "3"),
        ("MaxRateDown", "7"),
        ("SteerThreshold", "150"),
        ("RecordingCount", "100"),
        ("RecordingQuality", "1"),
        ("CruiseGapAdjust", "0"),
        ("AutoEnable", "1"),
        ("CruiseAutoRes", "0"),
        ("AutoResOption", "0"),
        ("SteerWindDown", "0"),
        ("OpkrMonitoringMode", "0"),
        ("OpkrMonitorEyesThreshold", "75"),
        ("OpkrMonitorNormalEyesThreshold", "50"),
        ("OpkrMonitorBlinkThreshold", "50"),
        ("MadModeEnabled", "1"),
        ("OpkrFanSpeedGain", "0"),
        ("WhitePandaSupport", "0"),
        ("SteerWarningFix", "0"),
    ]

    if TICI:
        default_params.append(("IsUploadRawEnabled", "0"))

    if params.get_bool("RecordFrontLock"):
        params.put_bool("RecordFront", True)

    # set unset params
    for k, v in default_params:
        if params.get(k) is None:
            params.put(k, v)

    # is this dashcam?
    if os.getenv("PASSIVE") is not None:
        params.put_bool("Passive", bool(int(os.getenv("PASSIVE"))))

    if params.get("Passive") is None:
        raise Exception("Passive must be set to continue")

    if EON:
        update_apks()

    os.umask(0)  # Make sure we can create files with 777 permissions

    # Create folders needed for msgq
    try:
        os.mkdir("/dev/shm")
    except FileExistsError:
        pass
    except PermissionError:
        print("WARNING: failed to make /dev/shm")

    # set version params
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit(default=""))
    params.put("GitBranch", get_git_branch(default=""))
    params.put("GitRemote", get_git_remote(default=""))

    # set dongle id
    reg_res = register(show_spinner=True)
    if reg_res:
        dongle_id = reg_res
    elif not reg_res:
        dongle_id = ""
    else:
        serial = params.get("HardwareSerial")
        raise Exception(f"Registration failed for device {serial}")
    os.environ['DONGLE_ID'] = dongle_id  # Needed for swaglog

    if not dirty:
        os.environ['CLEAN'] = '1'

    cloudlog.bind_global(dongle_id=dongle_id,
                         version=version,
                         dirty=dirty,
                         device=HARDWARE.get_device_type())

    # ensure shared libraries are readable by apks
    if EON:
        os.chmod(BASEDIR, 0o755)
        os.chmod("/dev/shm", 0o777)
        os.chmod(os.path.join(BASEDIR, "cereal"), 0o755)

    #if not (os.getenv("NOLOG") or os.getenv("NOCRASH") or PC):
    #  crash.init()
    crash.bind_user(id=dongle_id)
    crash.bind_extra(dirty=dirty,
                     origin=origin,
                     branch=branch,
                     commit=commit,
                     device=HARDWARE.get_device_type())

    os.system("/data/openpilot/gitcommit.sh")
Esempio n. 11
0
def manager_init():

    # update system time from panda
    set_time(cloudlog)

    params = Params()
    params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)

    default_params = [
        ("CompletedTrainingVersion", "0"),
        ("HasAcceptedTerms", "0"),
        ("HandsOnWheelMonitoring", "0"),
        ("OpenpilotEnabledToggle", "1"),
        ("ShowDebugUI", "1"),
        ("SpeedLimitControl", "1"),
        ("SpeedLimitPercOffset", "1"),
        ("TurnSpeedControl", "1"),
        ("TurnVisionControl", "1"),
        ("GMAutoHold", "1"),
        ("CruiseSpeedOffset", "1"),
        ("StockSpeedAdjust", "1"),
        ("CustomSounds", "0"),
        ("SilentEngageDisengage", "0"),
        ("AccelModeButton", "0"),
        ("AccelMode", "0"),
        ("EndToEndToggle", "1"),
        ("LanelessMode", "2"),
        ("NudgelessLaneChange", "0"),
        ("Coasting", "0"),
        ("RegenBraking", "0"),
        ("OnePedalMode", "0"),
        ("OnePedalModeSimple", "0"),
        ("OnePedalModeEngageOnGas", "0"),
        ("OnePedalBrakeMode", "0"),
        ("OnePedalPauseBlinkerSteering", "1"),
        ("FollowLevel", "2"),
        ("CoastingBrakeOverSpeed", "0"),
        ("FrictionBrakePercent", "0"),
        ("BrakeIndicator", "1"),
        ("DisableOnroadUploads", "0"),
        ("MeasureNumSlots", "0"),
        ("MeasureSlot00", "12"),  # right column: percent grade
        ("MeasureSlot01", "10"),  # altitude
        ("MeasureSlot02", "2"),  # steering torque
        ("MeasureSlot03", "3"),  # engine rpm
        ("MeasureSlot04", "7"),  # engine coolant temperature
        ("MeasureSlot05", "16"),  # lead dist [s]
        ("MeasureSlot06", "15"),  # lead dist [m]
        ("MeasureSlot07", "20"),  # lead rel spd [mph]
        ("MeasureSlot08", "21"),  # lead spd [mph]
        ("MeasureSlot09", "23"),  # device cpu percent and temp
    ]
    if not PC:
        default_params.append(
            ("LastUpdateTime",
             datetime.datetime.utcnow().isoformat().encode('utf8')))

    if params.get_bool("RecordFrontLock"):
        params.put_bool("RecordFront", True)

    # set unset params
    for k, v in default_params:
        if params.get(k) is None:
            params.put(k, v)

    # parameters set by Enviroment Varables
    if os.getenv("HANDSMONITORING") is not None:
        params.put_bool("HandsOnWheelMonitoring",
                        bool(int(os.getenv("HANDSMONITORING"))))

    # is this dashcam?
    if os.getenv("PASSIVE") is not None:
        params.put_bool("Passive", bool(int(os.getenv("PASSIVE"))))

    if params.get("Passive") is None:
        raise Exception("Passive must be set to continue")

    # Create folders needed for msgq
    try:
        os.mkdir("/dev/shm")
    except FileExistsError:
        pass
    except PermissionError:
        print("WARNING: failed to make /dev/shm")

    # set version params
    params.put("Version", version)
    params.put("TermsVersion", terms_version)
    params.put("TrainingVersion", training_version)
    params.put("GitCommit", get_git_commit(default=""))
    params.put("GitBranch", get_git_branch(default=""))
    params.put("GitRemote", get_git_remote(default=""))

    # set dongle id
    reg_res = register(show_spinner=True)
    if reg_res:
        dongle_id = reg_res
    else:
        serial = params.get("HardwareSerial")
        raise Exception(f"Registration failed for device {serial}")
    os.environ['DONGLE_ID'] = dongle_id  # Needed for swaglog

    if not dirty:
        os.environ['CLEAN'] = '1'

    cloudlog.bind_global(dongle_id=dongle_id,
                         version=version,
                         dirty=dirty,
                         device=HARDWARE.get_device_type())

    if comma_remote and not (os.getenv("NOLOG") or os.getenv("NOCRASH") or PC):
        crash.init()
    crash.bind_user(id=dongle_id)
    crash.bind_extra(dirty=dirty,
                     origin=origin,
                     branch=branch,
                     commit=commit,
                     device=HARDWARE.get_device_type())