Author Topic: Transmitting and receiving error states for sensors with human readable packet  (Read 466 times)

0 Members and 1 Guest are viewing this topic.

Offline daqq

  • Super Contributor
  • ***
  • Posts: 1844
  • Country: sk
    • My site
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"?


Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2704
  • Country: tr
ERR is clear, nan not as much.
The further a society drifts from truth, the more it will hate those who speak it.
The following users thanked this post: cdev, daqq, TomS_

Offline Gribo

  • Frequent Contributor
  • **
  • Posts: 468
  • Country: ca
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.
I am available for freelance work.
The following users thanked this post: daqq

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo