Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 51246f7

Browse files
author
dcyoung
authored
Bugfix: getBaud() now works on mac, and only check for appropriate baud rate (#106)
Closes #1 Closes #104
1 parent afeff51 commit 51246f7

File tree

1 file changed

+4
-194
lines changed

1 file changed

+4
-194
lines changed

libsweep/src/unix/serial.cc

Lines changed: 4 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -22,201 +22,11 @@ struct device {
2222

2323
static speed_t get_baud(int32_t bitrate) {
2424
SWEEP_ASSERT(bitrate > 0);
25-
26-
speed_t baud;
27-
28-
switch (bitrate) {
29-
#ifdef B0
30-
case 0:
31-
baud = B0;
32-
break;
33-
#endif
34-
#ifdef B50
35-
case 50:
36-
baud = B50;
37-
break;
38-
#endif
39-
#ifdef B75
40-
case 75:
41-
baud = B75;
42-
break;
43-
#endif
44-
#ifdef B110
45-
case 110:
46-
baud = B110;
47-
break;
48-
#endif
49-
#ifdef B134
50-
case 134:
51-
baud = B134;
52-
break;
53-
#endif
54-
#ifdef B150
55-
case 150:
56-
baud = B150;
57-
break;
58-
#endif
59-
#ifdef B200
60-
case 200:
61-
baud = B200;
62-
break;
63-
#endif
64-
#ifdef B300
65-
case 300:
66-
baud = B300;
67-
break;
68-
#endif
69-
#ifdef B600
70-
case 600:
71-
baud = B600;
72-
break;
73-
#endif
74-
#ifdef B1200
75-
case 1200:
76-
baud = B1200;
77-
break;
78-
#endif
79-
#ifdef B1800
80-
case 1800:
81-
baud = B1800;
82-
break;
83-
#endif
84-
#ifdef B2400
85-
case 2400:
86-
baud = B2400;
87-
break;
88-
#endif
89-
#ifdef B4800
90-
case 4800:
91-
baud = B4800;
92-
break;
93-
#endif
94-
#ifdef B7200
95-
case 7200:
96-
baud = B7200;
97-
break;
98-
#endif
99-
#ifdef B9600
100-
case 9600:
101-
baud = B9600;
102-
break;
103-
#endif
104-
#ifdef B14400
105-
case 14400:
106-
baud = B14400;
107-
break;
108-
#endif
109-
#ifdef B19200
110-
case 19200:
111-
baud = B19200;
112-
break;
113-
#endif
114-
#ifdef B28800
115-
case 28800:
116-
baud = B28800;
117-
break;
118-
#endif
119-
#ifdef B57600
120-
case 57600:
121-
baud = B57600;
122-
break;
123-
#endif
124-
#ifdef B76800
125-
case 76800:
126-
baud = B76800;
127-
break;
128-
#endif
129-
#ifdef B38400
130-
case 38400:
131-
baud = B38400;
132-
break;
133-
#endif
134-
#ifdef B115200
135-
case 115200:
136-
baud = B115200;
137-
break;
138-
#endif
139-
#ifdef B128000
140-
case 128000:
141-
baud = B128000;
142-
break;
143-
#endif
144-
#ifdef B153600
145-
case 153600:
146-
baud = B153600;
147-
break;
148-
#endif
149-
#ifdef B230400
150-
case 230400:
151-
baud = B230400;
152-
break;
153-
#endif
154-
#ifdef B256000
155-
case 256000:
156-
baud = B256000;
157-
break;
158-
#endif
159-
#ifdef B460800
160-
case 460800:
161-
baud = B460800;
162-
break;
163-
#endif
164-
#ifdef B576000
165-
case 576000:
166-
baud = B576000;
167-
break;
168-
#endif
169-
#ifdef B921600
170-
case 921600:
171-
baud = B921600;
172-
break;
173-
#endif
174-
#ifdef B1000000
175-
case 1000000:
176-
baud = B1000000;
177-
break;
178-
#endif
179-
#ifdef B1152000
180-
case 1152000:
181-
baud = B1152000;
182-
break;
183-
#endif
184-
#ifdef B1500000
185-
case 1500000:
186-
baud = B1500000;
187-
break;
188-
#endif
189-
#ifdef B2000000
190-
case 2000000:
191-
baud = B2000000;
192-
break;
193-
#endif
194-
#ifdef B2500000
195-
case 2500000:
196-
baud = B2500000;
197-
break;
198-
#endif
199-
#ifdef B3000000
200-
case 3000000:
201-
baud = B3000000;
202-
break;
203-
#endif
204-
#ifdef B3500000
205-
case 3500000:
206-
baud = B3500000;
207-
break;
208-
#endif
209-
#ifdef B4000000
210-
case 4000000:
211-
baud = B4000000;
212-
break;
213-
#endif
214-
default:
215-
throw error{"baud rate could not be determined"};
216-
baud = -1;
25+
if (bitrate != 115200) {
26+
throw error{"Only baud rate 115200 is supported at this time."};
27+
return -1;
21728
}
218-
219-
return baud;
29+
return bitrate;
22030
}
22131

22232
static bool wait_readable(device_s serial) {

0 commit comments

Comments
 (0)