|
@@ -22,15 +22,9 @@
|
22
|
22
|
#define CHECKSUMBYTES 2
|
23
|
23
|
#define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
|
24
|
24
|
#define CHANNELS 6
|
25
|
|
-
|
26
|
|
-/*
|
27
|
25
|
#define TESTCHANNEL 2
|
28
|
|
-#define TESTCHANNELVALUE 2044
|
29
|
|
-*/
|
30
|
26
|
|
31
|
27
|
static int running = 1;
|
32
|
|
-static int firstPrint = 0;
|
33
|
|
-static int extraLine = 0;
|
34
|
28
|
|
35
|
29
|
static void signalHandler(int signo) {
|
36
|
30
|
running = 0;
|
|
@@ -42,6 +36,8 @@ int main(int argc, char* argv[]) {
|
42
|
36
|
return 1;
|
43
|
37
|
}
|
44
|
38
|
|
|
39
|
+ printf("Opening serial port...\n");
|
|
40
|
+
|
45
|
41
|
int fd = serialOpen(argv[1], BAUDRATE);
|
46
|
42
|
if (fd == -1) {
|
47
|
43
|
return 1;
|
|
@@ -90,45 +86,32 @@ int main(int argc, char* argv[]) {
|
90
|
86
|
}
|
91
|
87
|
|
92
|
88
|
if (checksum != ((checksumData[0] << 8) | checksumData[1])) {
|
93
|
|
- printf("Wrong checksum: %d != %d \n",
|
|
89
|
+ printf("Wrong checksum: %d != %d\n",
|
94
|
90
|
checksum, ((checksumData[0] << 8) | checksumData[1]));
|
95
|
|
- extraLine++;
|
96
|
|
- if (extraLine > 1) {
|
97
|
|
- extraLine--;
|
98
|
|
- printf("\r\033[1A");
|
99
|
|
- }
|
100
|
91
|
} else {
|
101
|
92
|
// Decode channel values
|
102
|
93
|
uint16_t buff[CHANNELS + 1];
|
103
|
94
|
for (int i = 0; i < (CHANNELS + 1); i++) {
|
104
|
95
|
buff[i] = data[2 * i] << 8;
|
105
|
96
|
buff[i] |= data[(2 * i) + 1];
|
106
|
|
- }
|
107
|
97
|
|
108
|
|
- /*
|
109
|
|
- // Check Test Channel Value (?)
|
110
|
|
- if (buff[CHANNELS] != (TESTCHANNELVALUE - buff[TESTCHANNEL])) {
|
111
|
|
- printf("Wrong test channel value: %d != %d (%d - %d)\n",
|
112
|
|
- buff[CHANNELS], TESTCHANNELVALUE - buff[TESTCHANNEL],
|
113
|
|
- TESTCHANNELVALUE, buff[TESTCHANNEL]);
|
|
98
|
+ if (i < CHANNELS) {
|
|
99
|
+ buff[i] -= 1000;
|
|
100
|
+ }
|
|
101
|
+ }
|
114
|
102
|
|
115
|
|
- printf("Correct would be: %d\n",
|
116
|
|
- buff[TESTCHANNEL] + buff[CHANNELS]);
|
|
103
|
+ // Check Test Channel Value
|
|
104
|
+ if (buff[CHANNELS] != buff[TESTCHANNEL]) {
|
|
105
|
+ printf("Wrong test channel value: %d != %d\n",
|
|
106
|
+ buff[CHANNELS], buff[TESTCHANNEL]);
|
117
|
107
|
}
|
118
|
|
- */
|
119
|
|
-
|
120
|
|
- if (firstPrint == 0) {
|
121
|
|
- firstPrint = 1;
|
122
|
|
- } else {
|
123
|
|
- int num = CHANNELS + extraLine;
|
124
|
|
- extraLine = 0;
|
125
|
|
- for (int i = 0; i < num; i++) {
|
126
|
|
- printf("\r\033[1A");
|
127
|
|
- }
|
|
108
|
+
|
|
109
|
+ for (int i = 0; i < CHANNELS; i++) {
|
|
110
|
+ printf("CH%d: %d\n", i + 1, buff[i]);
|
128
|
111
|
}
|
129
|
112
|
|
130
|
113
|
for (int i = 0; i < CHANNELS; i++) {
|
131
|
|
- printf("CH%d: %d \n", i + 1, buff[i] - 1000);
|
|
114
|
+ printf("\r\033[1A");
|
132
|
115
|
}
|
133
|
116
|
}
|
134
|
117
|
}
|
|
@@ -138,6 +121,7 @@ int main(int argc, char* argv[]) {
|
138
|
121
|
usleep(1000);
|
139
|
122
|
}
|
140
|
123
|
|
|
124
|
+ printf("Closing serial port... \n");
|
141
|
125
|
serialClose(fd);
|
142
|
126
|
|
143
|
127
|
return 0;
|