Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #28280

Re: How to transmit the value of an enumeration

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.arch.embedded
Subject Re: How to transmit the value of an enumeration
Date 2018-10-24 16:59 +0200
Organization A noiseless patient Spider
Message-ID <pqq1cd$12c$2@dont-email.me> (permalink)
References <pqpkdn$ed3$1@dont-email.me> <pqpqvr$nep$1@dont-email.me> <pqps0e$t0l$1@dont-email.me>

Show all headers | View raw


On 24/10/18 15:27, pozz wrote:
> Il 24/10/2018 15:10, David Brown ha scritto:
>> On 24/10/18 13:18, pozz wrote:
>>> enum type_t {
>>>    TYPE_1,
>>>    TYPE_2,
>>>    ...
>>>    TYPE_100,
>>> }
>>>
>>> void tx_byte(unsigned char c);
>>>
>>> enum type_t t;
>>> ...
>>> tx_byte((unsigned char)t);
>>>
>>>
>>> If the maximum value in the enumeration is lower than 256, you can cast
>>> to (unsigned char) and transmit it as a byte.
>>>
>>>
>>> However the receiver must have the same enumeration.  The transmitter
>>> and the receiver must agreed on *the exact values* of the enumeration.
>>>
>>> What happens if the developer of the transmitter thinks that it is
>>> better to swap some values during a future release?  The enumeration
>>> isn't used only for transmission, it is also used for general logic of
>>> the software.
>>>
>>> Until now I didn't found a good solution.  I only write some comments
>>> before the enumeration declaration:
>>>
>>> /* WARNING!! DON'T CHANGE THE ORDER OF THE VALUES INSIDE ENUMERATION
>>>   * They are also used in the transmission */
>>>
>>> I sometimes prefer explicit the value transmitted:
>>>
>>> if (t == TYPE_1) tx_byte(0);
>>> if (t == TYPE_2) tx_byte(1);
>>> ...
>>>
>>>
>>> What is your strategy?
>>
>> It doesn't matter whether you are sending "raw" integers, enumerations,
>> text strings, lead balloons - the sender and the receiver need to agree
>> on the protocol and the messages sent.  The easiest way is to make sure
>> things like your enumeration here are in a common header that both the
>> receiver and the transmitter include in their code - then it is hard to
>> get out of sync.
>>
>> It can also be worth including some sort of version information in the
>> initial handshake of the protocol - any changes in the enumeration or
>> other details should be accompanied by a change in the version number,
>> so that the other end can see that something has changed.
> 
> The problem here is not to share a new version of the protocol, but to
> avoid that a developer could change some part of the code (an
> enumeration) and broke the protocol *inadvertently*.

That is a people problem, not a technical one.

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to transmit the value of an enumeration pozz <pozzugno@gmail.com> - 2018-10-24 13:18 +0200
  Re: How to transmit the value of an enumeration Jack <jack4747@gmail.com> - 2018-10-24 04:45 -0700
    Re: How to transmit the value of an enumeration pozz <pozzugno@gmail.com> - 2018-10-24 15:18 +0200
      Re: How to transmit the value of an enumeration David Brown <david.brown@hesbynett.no> - 2018-10-24 17:05 +0200
  Re: How to transmit the value of an enumeration David Brown <david.brown@hesbynett.no> - 2018-10-24 15:10 +0200
    Re: How to transmit the value of an enumeration pozz <pozzugno@gmail.com> - 2018-10-24 15:27 +0200
      Re: How to transmit the value of an enumeration David Brown <david.brown@hesbynett.no> - 2018-10-24 16:59 +0200
      Re: How to transmit the value of an enumeration Clifford Heath <no.spam@please.net> - 2018-10-25 08:57 +1100
  Re: How to transmit the value of an enumeration Joe Chisolm <jchisolm6@earthlink.net> - 2018-10-24 12:48 -0500
    Re: How to transmit the value of an enumeration pozz <pozzugno@gmail.com> - 2018-10-24 23:20 +0200
      Re: How to transmit the value of an enumeration Joe Chisolm <jchisolm6@earthlink.net> - 2018-10-24 22:21 -0500
    Re: How to transmit the value of an enumeration David Brown <david.brown@hesbynett.no> - 2018-10-25 09:31 +0200
      Re: How to transmit the value of an enumeration Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2018-10-25 09:58 -0700
      Re: How to transmit the value of an enumeration Joe Chisolm <jchisolm6@earthlink.net> - 2018-10-25 18:38 -0500
        Re: How to transmit the value of an enumeration David Brown <david.brown@hesbynett.no> - 2018-10-26 09:24 +0200
  Re: How to transmit the value of an enumeration George Neuner <gneuner2@comcast.net> - 2018-10-24 15:19 -0400
  Re: How to transmit the value of an enumeration Les Cargill <lcargill99@comcast.com> - 2018-10-26 20:30 -0500

csiph-web