5
5
6
6
#include < wiringSerial.h>
7
7
8
- bool initializeGPIO (int * serial) {
8
+ void echoOn (int serial) {
9
+ serialPuts (serial, " echo on\n " );
10
+ }
11
+
12
+ bool initializeSerial (int * serial) {
9
13
if ((*serial = serialOpen (" /dev/serial/by-id/usb-MicroPython_Board_in_FS_mode_e6614864d3798738-if00" , 115200 )) < 0 ) {
10
14
return false ;
11
15
}
16
+ echoOn (*serial);
12
17
return true ;
13
18
}
14
19
15
20
int getSerialChar (int * serial) {
16
21
if (*serial == -1 ) {
17
- if (!initializeGPIO (serial)) {
22
+ if (!initializeSerial
23
+ (serial)) {
18
24
std::cerr << " Unable to open serial port! Exiting." << std::endl;
19
25
exit (42 );
20
26
}
21
27
}
22
28
return serialGetchar (*serial); // from wiringSerial
23
29
}
24
30
25
- void echoOn (int serial) {
26
- serialPuts (serial, " echo on\n " );
27
- }
28
-
29
31
#else
30
32
31
- bool initializeGPIO (int * serial) {
33
+ bool initializeSerial (int * serial) {
32
34
return true ;
33
35
}
34
36
35
- void echoOn (int serial) {
36
- return ;
37
- }
38
-
39
37
int getSerialChar (int * serial) {
40
38
return EOF;
41
39
}
@@ -45,7 +43,8 @@ int getSerialChar(int* serial) {
45
43
TEST (CommandInterpreterTest, CreateCommandInterpreter) {
46
44
testing::internal::CaptureStdout ();
47
45
int serial = -1 ;
48
- initializeGPIO (&serial);
46
+ initializeSerial
47
+ (&serial);
49
48
50
49
auto pinNumbers = std::vector<int >{4 , 5 , 2 , 3 , 9 , 7 , 8 , 6 };
51
50
@@ -83,14 +82,16 @@ TEST(CommandInterpreterTest, CreateCommandInterpreter) {
83
82
ASSERT_EQ (output, expectedOutput);
84
83
}
85
84
else {
85
+ expectedOutput.insert (0 , " echo on\n " );
86
86
ASSERT_EQ (serialOutput, expectedOutput);
87
87
}
88
88
}
89
89
90
90
TEST (CommandInterpreterTest, CreateCommandInterpreterWithDigitalPins) {
91
91
testing::internal::CaptureStdout ();
92
92
int serial = -1 ;
93
- initializeGPIO (&serial);
93
+ initializeSerial
94
+ (&serial);
94
95
95
96
auto pinNumbers = std::vector<int >{4 , 5 , 2 , 3 , 9 , 7 , 8 , 6 };
96
97
@@ -133,14 +134,16 @@ TEST(CommandInterpreterTest, CreateCommandInterpreterWithDigitalPins) {
133
134
ASSERT_EQ (output, expectedOutput);
134
135
}
135
136
else {
137
+ expectedOutput.insert (0 , " echo on\n " );
136
138
ASSERT_EQ (serialOutput, expectedOutput);
137
139
}
138
140
}
139
141
140
142
TEST (CommandInterpreterTest, BlindExecuteHardwarePwm) {
141
143
testing::internal::CaptureStdout ();
142
144
int serial = -1 ;
143
- initializeGPIO (&serial);
145
+ initializeSerial
146
+ (&serial);
144
147
145
148
const CommandComponent acceleration = {1900 , 1900 , 1100 ,
146
149
1250 , 1300 , 1464 , 1535 ,
@@ -195,14 +198,16 @@ TEST(CommandInterpreterTest, BlindExecuteHardwarePwm) {
195
198
ASSERT_EQ (output, expectedOutput);
196
199
}
197
200
else {
201
+ expectedOutput.insert (0 , " echo on\n " );
198
202
ASSERT_EQ (serialOutput, expectedOutput);
199
203
}
200
204
}
201
205
202
206
TEST (CommandInterpreterTest, BlindExecuteSoftwarePwm) {
203
207
testing::internal::CaptureStdout ();
204
208
int serial = -1 ;
205
- initializeGPIO (&serial);
209
+ initializeSerial
210
+ (&serial);
206
211
207
212
const CommandComponent acceleration = {1100 , 1900 , 1100 ,
208
213
1250 , 1300 , 1464 , 1535 ,
@@ -258,6 +263,7 @@ TEST(CommandInterpreterTest, BlindExecuteSoftwarePwm) {
258
263
ASSERT_EQ (output, expectedOutput);
259
264
}
260
265
else {
266
+ expectedOutput.insert (0 , " echo on\n " );
261
267
ASSERT_EQ (serialOutput, expectedOutput);
262
268
}
263
269
}
0 commit comments