Skip to content

Commit

Permalink
initial bidirectionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Jun 26, 2024
1 parent 6e54750 commit a1e21b3
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 88 deletions.
5 changes: 5 additions & 0 deletions cangen/CANField.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import Optional
from dataclasses import dataclass
import math

@dataclass
class CANPoint:
Expand All @@ -13,6 +14,7 @@ class CANPoint:
endianness : str = "big"
final_type: str = "f32"
format: Optional[str] = None
default: Optional[float] = 0

def get_size_bytes(self):
# Calculate max number of bytes to represent value
Expand All @@ -25,6 +27,9 @@ def get_size_bytes(self):
def get_size_bits(self):
return self.size

def get_size_min_bytes(self):
return math.ceil(self.size / 8.0) * 8

@dataclass
class NetField:
'''
Expand Down
19 changes: 17 additions & 2 deletions cangen/CANMsg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import Optional
from .CANField import NetField

@dataclass
Expand All @@ -11,5 +12,19 @@ class CANMsg:
desc: str # Brief name of CAN message, used for generating function names
fields: list[NetField] # List of CAN fields in the message

def __setstate__(self, state):
self.__init__(**state)
@dataclass
class EncodableCANMsg(CANMsg):
'''
Represents a CAN message that can also be encoded to using the command_data protobuf spec.
Has all properties of a decodable message, but also has a key and optional is_ext field.
IMPORTANT: Use the default flag in each CANPoint to specify a default value to be sent before a command is sent.
'''
'''
The name to be used to look up command data over mqtt
'''
key: str
'''
Whether the CAN ID is extended or standard
'''
is_ext: Optional[bool] = False
12 changes: 9 additions & 3 deletions cangen/Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ class Result:
master_mapping is the synthesized Rust code for the master_mapping.rs file.
"""
decode_data: str
master_mapping: str
decode_master_mapping: str
encode_data: str
encode_master_mapping: str
format_data: str

def __init__(self, decode_data: str, master_mapping: str):
def __init__(self, decode_data: str, master_mapping: str, encode_data: str, encode_master_mapping: str, format_data: str):
self.decode_data = decode_data
self.master_mapping = master_mapping
self.decode_master_mapping = master_mapping
self.encode_data = encode_data
self.encode_master_mapping = encode_master_mapping
self.format_data = format_data
Loading

0 comments on commit a1e21b3

Please sign in to comment.