def serial(self): """S300 serial number""" indexes_1 = { constants.S3003_ID: constants.S3003_SERIAL1, } indexes_2 = { constants.S3003_ID: constants.S3003_SERIAL2, } return ( 256 * get_value_from_ecu(self.version, indexes_2, self.data4, 0) ) + get_value_from_ecu(self.version, indexes_1, self.data4, 0)
def firmware(self): """Firmware version""" indexes_1 = { constants.S3003_ID: constants.S3003_FIRM1, } indexes_2 = { constants.S3003_ID: constants.S3003_FIRM2, } return "{}.{:02d}".format( get_value_from_ecu(self.version, indexes_1, self.data4), get_value_from_ecu(self.version, indexes_2, self.data4), )
def map(self): """Manifold absolute pressure""" indexes_1 = { constants.S3003_ID: constants.S3003_MAP1, } indexes_2 = { constants.S3003_ID: constants.S3003_MAP2, } data_from_s300 = ( 256 * get_value_from_ecu(self.version, indexes_2, self.data6) ) + get_value_from_ecu(self.version, indexes_1, self.data6) map_bar = data_from_s300 / 100.0 map_mbar = map_bar * 1000 map_psi = Formula.bar_to_psi(map_bar) return {"bar": map_bar, "mbar": map_mbar, "psi": map_psi}
def rpm(self): """ Revs per minute return unit: revs per minute """ indexes_1 = { constants.S3003_ID: constants.S3003_RPM1, } indexes_2 = { constants.S3003_ID: constants.S3003_RPM2, } return int( (256 * get_value_from_ecu(self.version, indexes_2, self.data6)) + get_value_from_ecu(self.version, indexes_1, self.data6) )
def bksw(self): """Brake switch""" mask = 0x02 indexes = { constants.S3003_ID: constants.S3003_BKSW, } return bool(get_value_from_ecu(self.version, indexes, self.data6) & mask)
def scs(self): """Service connector""" mask = 0x10 indexes = { constants.S3003_ID: constants.S3003_SCS, } return bool(get_value_from_ecu(self.version, indexes, self.data6) & mask)
def gear(self): """Gear""" indexes = { constants.KPRO23_ID: constants.KPRO23_GEAR, constants.KPRO4_ID: constants.KPRO4_GEAR, } return get_value_from_ecu(self.version, indexes, self.data0)
def mil(self): """Malfunction indicator light also known as check engine light""" indexes = { constants.S3003_ID: constants.S3003_MIL, } mask = 0x20 return bool(get_value_from_ecu(self.version, indexes, self.data6) & mask)
def fanc(self): """Fan switch""" mask = 0x80 indexes = { constants.S3003_ID: constants.S3003_FANC, } return bool(get_value_from_ecu(self.version, indexes, self.data6) & mask)
def flt(self): """Fuel temperature TODO: RETURN {"celsius": 0, "fahrenheit": 0} if fails """ indexes = {constants.KPRO4_ID: constants.KPRO4_FLT} flt_celsius = get_value_from_ecu(self.version, indexes, self.data3) flt_fahrenheit = Formula.celsius_to_fahrenheit(flt_celsius) return {"celsius": flt_celsius, "fahrenheit": flt_fahrenheit}
def eth(self): """ Ethanol content return unit: per cent """ indexes = { constants.S3003_ID: constants.S3003_ETH, } return get_value_from_ecu(self.version, indexes, self.data5)
def flr(self): """Fuel relay""" mask = 0x40 indexes = { constants.KPRO23_ID: constants.KPRO23_FLR, constants.KPRO4_ID: constants.KPRO4_FLR, } return bool( get_value_from_ecu(self.version, indexes, self.data0) & mask)
def rvslck(self): """Reverse gear lock""" mask = 0x01 indexes = { constants.KPRO23_ID: constants.KPRO23_RVSLCK, constants.KPRO4_ID: constants.KPRO4_RVSLCK, } return bool( get_value_from_ecu(self.version, indexes, self.data0) & mask)
def eps(self): """Electric power steering""" mask = 0x20 indexes = { constants.KPRO23_ID: constants.KPRO23_EPS, constants.KPRO4_ID: constants.KPRO4_EPS, } return bool( get_value_from_ecu(self.version, indexes, self.data0) & mask)
def bat(self): """ Battery voltage return unit: volts """ indexes = { constants.S3003_ID: constants.S3003_BAT, } return get_value_from_ecu(self.version, indexes, self.data6) * 0.1 - 0.5
def accl(self): """A/C clutch""" mask = 0x08 indexes = { constants.KPRO23_ID: constants.KPRO23_ACCL, constants.KPRO4_ID: constants.KPRO4_ACCL, } return bool( get_value_from_ecu(self.version, indexes, self.data0) & mask)
def acsw(self): """A/C switch""" mask = 0x04 indexes = { constants.KPRO23_ID: constants.KPRO23_ACSW, constants.KPRO4_ID: constants.KPRO4_ACSW, } return bool( get_value_from_ecu(self.version, indexes, self.data0) & mask)
def o2(self): """Oxygen sensor""" indexes_1 = { constants.KPRO23_ID: constants.KPRO23_AFR1, constants.KPRO4_ID: constants.KPRO4_AFR1, } indexes_2 = { constants.KPRO23_ID: constants.KPRO23_AFR2, constants.KPRO4_ID: constants.KPRO4_AFR2, } try: o2_lambda = 32768.0 / ( 256 * get_value_from_ecu(self.version, indexes_2, self.data0) + get_value_from_ecu(self.version, indexes_1, self.data0)) except ZeroDivisionError: # something happen collecting the value then return 0 return {"afr": 0, "lambda": 0} o2_afr = o2_lambda * 14.7 return {"afr": o2_afr, "lambda": o2_lambda}
def vss(self): """Vehicle speed sensor""" indexes = { constants.KPRO23_ID: constants.KPRO23_VSS, constants.KPRO4_ID: constants.KPRO4_VSS, } vss_kmh = get_value_from_ecu(self.version, indexes, self.data0) vss_mph = Formula.kmh_to_mph(vss_kmh) return {"kmh": vss_kmh, "mph": int(vss_mph)}
def ecu_type(self): """Model of ECU""" indexes = { constants.KPRO23_ID: constants.KPRO23_ECU_TYPE, constants.KPRO4_ID: constants.KPRO4_ECU_TYPE, } data_from_kpro = get_value_from_ecu(self.version, indexes, self.data4) if data_from_kpro == 3: # TODO the rest of ecu types return "RSX - PRB" return "unknown"
def o2(self): """Oxygen sensor""" indexes_1 = { constants.S3003_ID: constants.S3003_AFR, } o2_lambda = ( get_value_from_ecu(self.version, indexes_1, self.data6) - 1.1588 ) / 126.35 o2_afr = o2_lambda * 14.7 return {"afr": o2_afr, "lambda": o2_lambda}
def mil(self): """Malfunction indicator light also known as check engine light""" indexes = { constants.KPRO23_ID: constants.KPRO23_MIL, constants.KPRO4_ID: constants.KPRO4_MIL, } if self.version == constants.KPRO23_ID: data_from_kpro = get_value_from_ecu(self.version, indexes, self.data0) if data_from_kpro == 9: return True return False elif self.version == constants.KPRO4_ID: data_from_kpro = get_value_from_ecu(self.version, indexes, self.data3) if data_from_kpro >= 36: return True return False return False
def vss(self): """Vehicle speed sensor""" indexes_1 = { constants.S3003_ID: constants.S3003_VSS1, } indexes_2 = { constants.S3003_ID: constants.S3003_VSS2, } try: vss_kmh = int( 227125 / ( 256 * get_value_from_ecu(self.version, indexes_2, self.data6) + get_value_from_ecu(self.version, indexes_1, self.data6) ) ) except ZeroDivisionError: vss_kmh = 0 vss_mph = Formula.kmh_to_mph(vss_kmh) return {"kmh": vss_kmh, "mph": int(vss_mph)}
def iat(self): """Intake air temperature""" indexes = { constants.S3003_ID: constants.S3003_IAT, } data_from_s300 = get_value_from_ecu( self.version, indexes, self.data6, {"celsius": 0, "fahrenheit": 0} ) if isinstance(data_from_s300, int): return Formula.kpro_temp(data_from_s300) else: return data_from_s300
def ign(self): """Ignition status""" indexes = { constants.KPRO23_ID: constants.KPRO23_IGN, constants.KPRO4_ID: constants.KPRO4_IGN, } data_from_kpro = get_value_from_ecu(self.version, indexes, self.data4, 0) if data_from_kpro == 1: return True return False
def ect(self): """Engine coolant temperature""" indexes = { constants.S3003_ID: constants.S3003_ECT, } data_from_kpro = get_value_from_ecu( self.version, indexes, self.data6, {"celsius": 0, "fahrenheit": 0} ) if isinstance(data_from_kpro, int): return Formula.kpro_temp(data_from_kpro) else: return data_from_kpro
def tps(self): """ Throttle position sensor return unit: 0-100% """ indexes = { constants.S3003_ID: constants.S3003_TPS, } return int( interp( get_value_from_ecu(self.version, indexes, self.data6), [25, 255], [0, 115], ) )
def tps(self): """ Throttle position sensor return unit: 0-100% """ indexes = { constants.KPRO23_ID: constants.KPRO23_TPS, constants.KPRO4_ID: constants.KPRO4_TPS, } return int( interp( get_value_from_ecu(self.version, indexes, self.data0), [21, 229], [0, 100], ))
def cam(self): """ VTC cam angle return units: degrees """ indexes = { constants.KPRO23_ID: constants.KPRO23_CAM, constants.KPRO4_ID: constants.KPRO4_CAM, } data_from_kpro = get_value_from_ecu(self.version, indexes, self.data0, None) if data_from_kpro is not None: return (data_from_kpro - 40) * 0.5 else: return 0
def map(self): """Manifold absolute pressure""" indexes = { constants.KPRO23_ID: constants.KPRO23_MAP, constants.KPRO4_ID: constants.KPRO4_MAP, } data_from_kpro = get_value_from_ecu(self.version, indexes, self.data0, { "bar": 0, "mbar": 0, "psi": 0 }) if isinstance(data_from_kpro, int): map_bar = data_from_kpro / 100.0 map_mbar = map_bar * 1000 map_psi = Formula.bar_to_psi(map_bar) return {"bar": map_bar, "mbar": map_mbar, "psi": map_psi} return data_from_kpro