05-05-2020 12:17 PM
Hi Billko,
It is some thing similar but more in line with my previous post.
05-05-2020 12:38 PM - edited 05-05-2020 12:51 PM
@SolPS wrote:
I can only provide a description as shown below
Byte no of Bits Data Value Data Type
0 2 Data1 0-2 Enumeration
Looks like we cross-posted. That's perfect. So it looks like you're sending one byte. The data itself is a two bit number 0-2, or 00, 01, 10 binary.
Oh, Data1 is an 8-bit enum. Enum prevents you from entering invalid data. Guess it would've been helpful if I took the screenie after I ran it. Sorry.
Also, some people like to use Boolean arrays; I like to use clusters and convert them into an array so there is no way you can end up with too many/not enough elements.
05-05-2020 12:45 PM
You won't be able to represent your enum with less than 8 bits. You'll just have to live with it and make it impossible for the user to select invalid values like how I did in the snippet.
05-05-2020 12:52 PM
Hi Bilko,
I'm sending a combination of data types in one byte. More like the description below.
Byte no of Bits Data Value Data Type
0 2 Data1 0-2 Enumeration
1 Data2 1/0 1bit Boolean
1 Data3 1/0 1bit Boolean
1 Data4 1/0 1bit Boolean
3 Data5 0-2 Enumeration
05-05-2020 12:54 PM
You should be able to expand my example to include your revised format. 🙂
05-05-2020 12:57 PM
Ok. I will give it a try. Thanks for your replies.
05-05-2020 01:53 PM - edited 05-05-2020 01:54 PM
@SolPS wrote:
Hi Bilko,
I'm sending a combination of data types in one byte. More like the description below.
Byte no of Bits Data Value Data Type
0 2 Data1 0-2 Enumeration
1 Data2 1/0 1bit Boolean
1 Data3 1/0 1bit Boolean
1 Data4 1/0 1bit Boolean
3 Data5 0-2 Enumeration
That last value (3bits) can be from 0..7, of course, but you don't really need to use all bits.
It is extremely wasteful to explicitly code all these shifts and masks, because there are so many places for bugs to hide. Use a FOR loop and you are all set. All you need to know is the number of bits per field. Right?
Here's a simple draft:
Of course you don't really save anything useful. Sending one byte vs. five bytes over UDP costs you a packet either way and the size difference in payload is negligible compared to the entire packet with headers, etc. You could just cast of flatten the cluster to a string and back.
05-05-2020 02:04 PM
Hi Altenbach,
I need to send the entire byte. The last 3 bits will be used in padding the data.
Thanks.
05-05-2020 02:08 PM
@SolPS wrote:
Hi Altenbach,
I need to send the entire byte. The last 3 bits will be used in padding the data.
Since the minimum size is on byte, there is no padding. You re simply ignoring these bits. 😉
05-05-2020 02:43 PM
@altenbach wrote:
@SolPS wrote:
Hi Bilko,
I'm sending a combination of data types in one byte. More like the description below.
Byte no of Bits Data Value Data Type
0 2 Data1 0-2 Enumeration
1 Data2 1/0 1bit Boolean
1 Data3 1/0 1bit Boolean
1 Data4 1/0 1bit Boolean
3 Data5 0-2 Enumeration
That last value (3bits) can be from 0..7, of course, but you don't really need to use all bits.
It is extremely wasteful to explicitly code all these shifts and masks, because there are so many places for bugs to hide. Use a FOR loop and you are all set. All you need to know is the number of bits per field. Right?
Here's a simple draft:
Of course you don't really save anything useful. Sending one byte vs. five bytes over UDP costs you a packet either way and the size difference in payload is negligible compared to the entire packet with headers, etc. You could just cast of flatten the cluster to a string and back.
I don't think that is correct. It seems to me that the formatting of the data has already been set. It is one byte, consisting of: one number represented by two bits, three Booleans, then another number represented by three bits. I think there is no room for interpretation here.