Share the packet format with the Pi instead of duplicating it - #6
Conversation
The firmware defined the packet struct, the checksum, and the frame encoder itself, and the Raspberry Pi defined all three again on its side. Editing one without the other would not break a build, it would just make the car log nonsense. Both ends now use the same definition from the SensorHub library, so the drift is no longer expressible. Costs 22 bytes of flash, 0.07% of a Nano, and no RAM. Frames are byte-identical to before, checked against the old encoder over 200,000 random packets. Adds CI that compiles for the actual board, reports flash and RAM use, and fails if the sketch grows past 80% of flash, since running out of room on a Nano is a real failure mode when someone adds a sensor. Needs HEEV/SensorHub to land first; CI here installs it from main.
The install script reads its first positional argument as a version, so passing a bindir made it try to download arduino-cli_-b_Linux_64bit.
Follows the wire format change in SensorHub: the frame now carries a version and a length, and the payload has room to grow. The fan and pump pins have been configured as outputs since this was written and their state appeared nowhere in telemetry, so nobody could see or log what the car was doing to itself. They are now reported alongside the inputs. Also adds the sequence number the receiver needs to notice a packet never arrived, and names the output pins so the pinMode calls and the packet cannot drift apart. Costs 292 bytes of flash, taking the sketch from 18% to 19% of a Nano.
Without pipefail, tee's exit status hid a broken build and the error turned up two steps later as an empty grep. Also checks that the SensorHub checkout actually contains a usable library.
|
Updated: the wire format now carries a version and a length byte from the start, rather than being retrofitted later. The version byte exists for one specific failure. If the payload changes size, framing desyncs and you notice. But if it stays the same size and a field changes meaning, the checksum still passes and the receiver decodes confidently wrong data. That is exactly what happened on the Python side in April, when columns 5 and 6 silently went from The length byte lets an old receiver skip a packet from a newer sender and stay framed instead of desynchronising. Payload also widened while it was cheap to do so, since breaking the format twice is much worse than once:
Outputs are reported now. The firmware drives a radiator fan and a water pump whose state appeared nowhere in telemetry, so there was no way to see or log what the car was doing to itself. The sequence number makes dropped packets visible. A checksum cannot tell you about a packet that never arrived, so a link losing half its traffic looked identical to a healthy one. Costs: frame 26 to 41 bytes, which takes the link from 4.5% to 7% utilisation, and the sketch from 18% to 19% of a Nano. |
|
Version is interesting, yet kinda a waste to send each packet, same thing with packet length. If the packet structure version is the newest, then length and version wouldn't change at all. If anything, you may wanna add a interrupt on the nano when it receives a byte that causes it to hand over a version, then have the Sensor Hub throw an error if the version doesn't match. Add that and I'll approve this one, but I gotta finish looking over the SensorHub pull request. Thanks for the effort btw! |
|
Oh also, if you would mind checking to see if you can put the engine and radiator temp on a timer interrupt as well so that the packet sending wouldn't be bogged down by the temp polling. I'm thinking polling every 100ms, since the datasheet for these sensors says it only can really update every 90ish ms |
Why
This merges the definitions for the binary packed protocol so the rpi and the arduino don't go out of sync
Both ends now use a library from SensorHub
Depends on HEEV/SensorHub#2 to merge first. CI installs from SensorHub main
etc
engine temp needs a defined address as currently its just reading zeros