beademingstoestel / OpenSource_ventilator_lungs

Frontend for the beademingstoestel project
GNU General Public License v3.0
3 stars 7 forks source link

Add exception handling to serial decode #10

Closed frankvanbever closed 4 years ago

frankvanbever commented 4 years ago

At startup it's possible that we receive incomplete serial data. We need to account for this. We'll need to determine what level of errors are tolerable here. For testing purposes now I would stop the application so we get immediate feedback if this occurs more than once.

Signed-off-by: Frank Vanbever frank.vanbever@essensium.com

rubdos commented 4 years ago

Can't you reset (eg. DTR RTS) the serial port on start-up, and capture that on the controller? That way, there shouldn't be partial data. I'm unsure whether you can actually capture such signals on de Arduino though, since they use an FTDI.

It's still useful to handle this error though, but it may fail less often.

TThetier commented 4 years ago

I know from experience that errors at startups can be frequent (sometimes had to start 4-5 times before I had complete data on startup), and that it can also happen at random moments during execution. I think the program should check every time that the data is complete, for safety. We cannot assume (especially with serial communication) that we received the data without any problem.

Might also be useful to add a flush() in the arduino code to make sure the transmission is complete, might avoid some failures on the python side.

TomBruyneel commented 4 years ago

flush might be good for the python code, but it pauses the microcontroller

frankvanbever commented 4 years ago

@TThetier @rubdos can you take another look at everything please? I've got a whole bunch of commits lined up in this PR.

TThetier commented 4 years ago

All the commits look really good, but small concerns :

rubdos commented 4 years ago
* What do we do when there is an error in decoding ? Do we just assume we can do without printing this data (I guess if we receive and plot a lot of datas per second, we can do without 1 or 2 batches of data) and send nothing and just hope the communication will go back to normal, or do we decide we absolutely need everything and therefore no failure in communication is acceptable ?

Can't we track both errors and correct condition? You could compute the error rate over time, and trigger some alarm when it raises over like 1 error/second, or say over 5% of all messages on a second.