Skip to content

Commit

Permalink
impl wheel speed decoders
Browse files Browse the repository at this point in the history
  • Loading branch information
Squidtoon99 committed Apr 29, 2024
1 parent 8903374 commit c4e7397
Showing 1 changed file with 331 additions and 9 deletions.
340 changes: 331 additions & 9 deletions data_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
],
218102344: ["Percent Slip", "Driven Wheel Rate of Change", "Desired Value"],
218102600: [
"Driven AVG Wheel Speed",
"Non-Driven AVG Wheel Speed",
"Driven Avg Wheel Speed",
"Non-Driven Avg Wheel Speed",
"Ignition Compensation",
"Ignitiion Cut Percentage",
"Ignition Cut Percentage",
],
218102856: [
"Driven Wheel Speed #1",
Expand All @@ -57,8 +57,9 @@
"Fuel Comp-Air Temp",
"Fuel Comp-Coolant Temp",
],
218103368: ["Fuel Comp-Barometer", "Fuel Comp-MAP"]
}
218103368: ["Fuel Comp-Barometer", "Fuel Comp-MAP"],
} # Wait, was there not supposed to be a bracket here??? - Gino


class pressure_type(Enum):
"""The pressure unit type."""
Expand All @@ -79,6 +80,7 @@ class temp_type(Enum):
def __str__(self):
return self.name


class MessageData:
_DESERIALIZERS = []

Expand Down Expand Up @@ -250,6 +252,329 @@ def invoke_deserializer(self, __name: str) -> Any:

# CAN ID GROUP: 0xCFFF048

# ////////////////above is original code-------------------------------------------------


# --------------------------------------------------------------------------------------


@MessageData.deserializer(
can_id=0xCFFF748,
pname="PE8",
rate=100,
start_position=1,
length=2,
name="RPM Rate",
units="rpm/sec",
resolution_per_bit=1,
data_range=(-10000, 10000),
)
def rpm(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFF748,
pname="PE8",
rate=100,
start_position=3,
length=2,
name="TPS Rate",
units="%/sec",
resolution_per_bit=1,
data_range=(-3000, 3000),
)
def tps(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFF748,
pname="PE8",
rate=100,
start_position=5,
length=2,
name="MAP Rate",
units="psi/sec",
resolution_per_bit=1,
data_range=(-300, 300),
)
def map_rate(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFA48,
pname="PE11",
rate=100,
start_position=1,
length=2,
name="Percent Slip",
units="%",
resolution_per_bit=0.1,
data_range=(-3000, 3000),
)
def slip(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFB48,
pname="PE12",
rate=100,
start_position=1,
length=2,
name="Driven Avg Wheel Speed",
units="ft/sec",
resolution_per_bit=0.1,
data_range=(0, 3000),
)
def driven_avg_wheel_speed(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=False)


@MessageData.deserializer(
can_id=0xCFFFB48,
pname="PE12",
rate=100,
start_position=3,
length=2,
name="Non-Driven Avg Wheel Speed",
units="ft/sec",
resolution_per_bit=0.1,
data_range=(0, 3000),
)
def non_driven_avg_wheel_speed(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=False)


@MessageData.deserializer(
can_id=0xCFFFB48,
pname="PE12",
rate=100,
start_position=5,
length=2,
name="Ignition Compensation",
units="deg",
resolution_per_bit=0.1,
data_range=(0, 100),
)
def ignition_comp(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFB48,
pname="PE12",
rate=100,
start_position=7,
length=2,
name="Ignition Cut Percentage",
units="%",
resolution_per_bit=1,
data_range=(0, 100),
)
def ignition_cut(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFC48,
pname="PE13",
rate=100,
start_position=1,
length=2,
name="Driven Wheel Speed #1",
units="ft/sec",
resolution_per_bit=0.1,
data_range=(0, 3000),
)
def wheel_speed_1(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=False)


@MessageData.deserializer(
can_id=0xCFFFC48,
pname="PE13",
rate=100,
start_position=3,
length=2,
name="Driven Wheel Speed #2",
units="ft/sec",
resolution_per_bit=0.1,
data_range=(0, 3000),
)
def wheel_speed_2(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=False)


@MessageData.deserializer(
can_id=0xCFFFC48,
pname="PE13",
rate=100,
start_position=5,
length=2,
name="Non-Driven Wheel Speed #1",
units="ft/sec",
resolution_per_bit=0.1,
data_range=(0, 3000),
)
def wheel_non_speed_1(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=False)


@MessageData.deserializer(
can_id=0xCFFFC48,
pname="PE13",
rate=100,
start_position=7,
length=2,
name="Non-Driven Wheel Speed #2",
units="ft/sec",
resolution_per_bit=0.1,
data_range=(0, 3000),
)
def wheel_non_speed_2(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=False)


@MessageData.deserializer(
can_id=0xCFFFD48,
pname="PE14",
rate=100,
start_position=1,
length=2,
name="Fuel Comp - Acceleration",
units="%",
resolution_per_bit=0.1,
data_range=(0, 500),
)
def fuel_comp_accel(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFD48,
pname="PE14",
rate=100,
start_position=3,
length=2,
name="Fuel Comp - Starting",
units="%",
resolution_per_bit=0.1,
data_range=(0, 500),
)
def fuel_comp_starting(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFD48,
pname="PE14",
rate=100,
start_position=5,
length=2,
name="Fuel Comp - Air Temp",
units="%",
resolution_per_bit=0.1,
data_range=(0, 500),
)
def fuel_comp_air_temp(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFD48,
pname="PE14",
rate=100,
start_position=7,
length=2,
name="Fuel Comp - Coolant Temp",
units="%",
resolution_per_bit=0.1,
data_range=(0, 500),
)
def fuel_comp_coolant_temp(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFFE48,
pname="PE15",
rate=100,
start_position=3,
length=2,
name="Fuel Comp - MAP",
units="%",
resolution_per_bit=0.1,
data_range=(0, 500),
)
def fuel_comp_map(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFD048,
pname="PE16",
rate=100,
start_position=1,
length=2,
name="Ignition Comp - Air Temp",
units="deg",
resolution_per_bit=0.1,
data_range=(-20, 20),
)
def ignition_comp_air_temp(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFD048,
pname="PE16",
rate=100,
start_position=3,
length=2,
name="Ignition Comp - Coolant Temp",
units="deg",
resolution_per_bit=0.1,
data_range=(-20, 20),
)
def ignition_comp_coolant_temp(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFD048,
pname="PE16",
rate=100,
start_position=5,
length=2,
name="Ignition Comp - Barometer",
units="deg",
resolution_per_bit=0.1,
data_range=(-20, 20),
)
def ignition_comp_barometer(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


@MessageData.deserializer(
can_id=0xCFFD048,
pname="PE16",
rate=100,
start_position=7,
length=2,
name="Ignition Comp - MAP",
units="deg",
resolution_per_bit=0.1,
data_range=(-20, 20),
)
def ignition_comp_map(data: bytes) -> UINT: # data is an unsigned int
return int.from_bytes(data, byteorder="little", signed=True)


# ////////////////////////////////////////////////////below is original code


@MessageData.deserializer(
can_id=0xCFFF048,
Expand Down Expand Up @@ -281,7 +606,6 @@ def tps(data: bytes) -> int:
return int.from_bytes(data, byteorder="little", signed=True)



@MessageData.deserializer(
can_id=0xCFFF048,
pname="PE1",
Expand All @@ -297,7 +621,6 @@ def fuel_open_time(data: bytes) -> int:
return int.from_bytes(data, byteorder="little", signed=True)



@MessageData.deserializer(
can_id=0xCFFF048,
pname="PE1",
Expand Down Expand Up @@ -346,7 +669,6 @@ def map_data(data: bytes) -> int:
return int.from_bytes(data, byteorder="little", signed=True)



@MessageData.deserializer(
can_id=0xCFFF148,
pname="PE2",
Expand Down Expand Up @@ -622,4 +944,4 @@ def coolant_temp(data: bytes) -> int:
data_range=(0, 255),
)
def temp_type_fn(data: bytes) -> temp_type:
return temp_type(int.from_bytes(data, byteorder="little", signed=False))
return temp_type(int.from_bytes(data, byteorder="little", signed=False))

0 comments on commit c4e7397

Please sign in to comment.