- Tue Feb 08, 2022 5:55 am
#55199
Hey there.
On the race car I've been moving the new dashboard to Serial3 so when we go to the dyno in a couple of weeks the laptop can plug in to the primary serial to tune and the dash will still work.
It doesn't. When Serial3 is running at 10Hz Tunerstudio drops to a correct update every couple of seconds with errors generated sometimes. Unplug the dashboard and in a couple of seconds TunerStudio picks up and works correctly.
I started looking at the code. It's a shambles.
There's comms.cpp with code to handle main serial and serial3. The main serial code has an asynchronous send that's broken if you were to use main serial and serial3 at the same time, however the comms.cpp code handling serial3 is all dead and never used. The main speeduino.ino code needs to know details of the implementation to handle the async sends, this is a bad design decision.
There's cancomms.ino for handling true CANBUS and serial3. The merging of the two communication methods is a flawed idea. The data retrieved from serial3 is different and incomplete compared to main serial. There is no valid reason for serial3 to be handled differently than main serial. CANBUS is a different matter altogether and deserves a separate implementation that serves the protocol.
Then there's newcomms.cpp, an in-progress clean up that adds the CRC checking to the protocol. I haven't delved too deeply yet.
I propose that I clean up comms.cpp to handle both main serial and serial3 with proper async transmission.
I will also remove the non-CANBUS parts from cancomms.cpp to allow a clean, non-compromised implementation of the CANBUS protocol. I would like to, but won't without the go-ahead make the live data retrieved by CANBUS to be the same as the data from the UART serial ports. It's silly that the live data is different for the same commands. If you want different data, use a different command.
I haven't found the bug yet that screws up main serial when using serial3 yet, but I stopped looking when the code is need of deeper work.
Any comments? I want to bang this out over the next couple of days so I can get the car to the dyno.
-----EDIT------
I started cleaning up the code and came to the realization that comms.cpp isn't used at all.
This is not a good thing. Remove dead code. If you need to go back and look at it, that's what source control is for.
newComms is still not great code in places. You shouldn't dump all the code in the parser switch statement, it makes the code very hard to inspect. It does ugly things with globals. Code with global side-effects are very hard to debug when things go wrong.
I'll keep looking and post more as I dig.
----- More Edits ------
comms.cpp is used, but it is called from newComms for legacy stuff. So there's four implementations for two things.
The comms data refactor should use the same method of buffering and sending data as newcomms.
Simplify everything.
On the race car I've been moving the new dashboard to Serial3 so when we go to the dyno in a couple of weeks the laptop can plug in to the primary serial to tune and the dash will still work.
It doesn't. When Serial3 is running at 10Hz Tunerstudio drops to a correct update every couple of seconds with errors generated sometimes. Unplug the dashboard and in a couple of seconds TunerStudio picks up and works correctly.
I started looking at the code. It's a shambles.
There's comms.cpp with code to handle main serial and serial3. The main serial code has an asynchronous send that's broken if you were to use main serial and serial3 at the same time, however the comms.cpp code handling serial3 is all dead and never used. The main speeduino.ino code needs to know details of the implementation to handle the async sends, this is a bad design decision.
There's cancomms.ino for handling true CANBUS and serial3. The merging of the two communication methods is a flawed idea. The data retrieved from serial3 is different and incomplete compared to main serial. There is no valid reason for serial3 to be handled differently than main serial. CANBUS is a different matter altogether and deserves a separate implementation that serves the protocol.
Then there's newcomms.cpp, an in-progress clean up that adds the CRC checking to the protocol. I haven't delved too deeply yet.
I propose that I clean up comms.cpp to handle both main serial and serial3 with proper async transmission.
I will also remove the non-CANBUS parts from cancomms.cpp to allow a clean, non-compromised implementation of the CANBUS protocol. I would like to, but won't without the go-ahead make the live data retrieved by CANBUS to be the same as the data from the UART serial ports. It's silly that the live data is different for the same commands. If you want different data, use a different command.
I haven't found the bug yet that screws up main serial when using serial3 yet, but I stopped looking when the code is need of deeper work.
Any comments? I want to bang this out over the next couple of days so I can get the car to the dyno.
-----EDIT------
I started cleaning up the code and came to the realization that comms.cpp isn't used at all.
This is not a good thing. Remove dead code. If you need to go back and look at it, that's what source control is for.
newComms is still not great code in places. You shouldn't dump all the code in the parser switch statement, it makes the code very hard to inspect. It does ugly things with globals. Code with global side-effects are very hard to debug when things go wrong.
I'll keep looking and post more as I dig.
----- More Edits ------
comms.cpp is used, but it is called from newComms for legacy stuff. So there's four implementations for two things.
The comms data refactor should use the same method of buffering and sending data as newcomms.
Simplify everything.