Skip to content

Commit

Permalink
try hardcoding i32
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed May 19, 2024
1 parent b4c781a commit 3c7d8d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cangen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Messages should follow these rules:
3. Wherever possible, bit-wise decoding and byte-wise decoding should happen in seperate bytes to avoid confusion.
Ex. If there are 5 messages of size one (booleans), add a 3 bit filler before adding a 16 bit number
4. Message totals should be byte aligned, meaning total bit size of a message should be a power of 8
5. **Signed messages must be 8,16,32, or 64 bits!**
5. **Signed messages must be 8,16,or 32 bits!**

Message guide:
1. Use previous examples for most things
Expand Down
5 changes: 3 additions & 2 deletions cangen/RustSynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ def parse_decoders(self, field: CANPoint) -> str:
base = f"reader.read_bits({field.size})"

# aware conversion from network to platform endianness
# why this is backwards is beyond me but it works and should work on either platform endianness
if field.endianness == "little":
base = f"u32::from_be({base})"
elif field.endianness == "big":
base = f"u32::from_le({base})"
else:
print("Invalid endianness on point!")
exit(1)

if field.signed:
base = f"({base} as i{field.get_size_bits()}).wrapping_neg()"
base = f"({base} as i32)"

return f"{base} as {field.final_type}"

Expand Down

0 comments on commit 3c7d8d5

Please sign in to comment.