EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: daqq on November 29, 2018, 11:51:35 am

Title: Transmitting and receiving error states for sensors with human readable packet
Post by: daqq on November 29, 2018, 11:51:35 am
Hi guys,

I'm creating two devices that communicate together with a simple packet, formated like this:
Code: [Select]
!H,12.01,42.24,Checksum\r\nWhere the 12.01 and 42.24 values are used to transmit floating point numbers. Generally, the two devices will be used together, but there might be a scenario where they are used separately.

The transmitting device pretty much reads out several sensors. How would you go about transmitting a bad state (sensor channel disconnected, shorted...) to the upper system? At the moment I'm setting the float values to nan, which is then conveniently printf'd into "nan" and on the other side it's scanf'd back into nan.

Transmitting some special string (say, "ERR") when the sensor is broken complicates things on both sides, but it would look much nicer. The parsing at the moment can be achieved by one sscanf line.

If you were buying a device, would you be OK with "nan" used when the specific channel has an error, or would you prefer "ERR"?

Thanks,

David
Title: Re: Transmitting and receiving error states for sensors with human readable packet
Post by: GeorgeOfTheJungle on November 29, 2018, 12:09:25 pm
ERR is clear, nan not as much.
Title: Re: Transmitting and receiving error states for sensors with human readable packet
Post by: Gribo on November 29, 2018, 12:55:12 pm
Don't overload messages. Since you already use a human readable format, there is nothing gained by sending a NaN vs a proper error message.