I want to map the termios bytes returned by the Libc function tcgetattr to a class in C#.
In C termios is defined as:
#define NCCS 12
typedef unsigned cc_t;
typedef unsigned speed_t;
typedef unsigned tcflag_t;
struct termios {
cc_t c_cc[NCCS];
tcflag_t c_cflag;
tcflag_t c_iflag;
tcflag_t c_lflag;
tcflag_t c_oflag;
speed_t c_ispeed;
speed_t c_ospeed;
};
Below is the termios bytes for a serial port. The only difference between them is the baud rate B9600 vs. B38400 set with Libc cfsetspeed (the platform is Raspberry PI running Raspbian Stretch):
Byte# B38400 B9600
0 0 0
1 5 5
2 0 0
3 0 0
4 5 5
5 0 0
6 0 0
7 0 0
8 191 189
9 12 12
10 0 0
11 0 0
12 59 59
13 138 138
14 0 0
15 0 0
16 0 0
17 3 3
18 28 28
19 127 127
20 21 21
21 4 4
22 0 0
23 0 1
24 0 0
25 17 17
26 19 19
27 26 26
28 0 0
29 18 18
30 15 15
31 23 23
32 22 22
The only difference between B9600 and B38400 is the byte with index=8 and the bit pattern for the byte with index=8 makes sense, since B9600=0xd and B38400=0xf. The last byte of 189 is 0xd and the last byte of 191 os 0xf so it looks correct. But, I don't know exactly how to make sense of how to map the bytes to the C struct. When speed was changed shouldn't bytes for c_ispeed and c_ospeed have changed?
Can anyone explain how to map the byte indexes to the C struct?