Skip to content

Commit 8b4817f

Browse files
authored
Merge pull request #132 from REVrobotics/chore/port-rhsp-changes
Port last error code and device path fixes from librhsp
2 parents 0f4e36d + 0e1f83c commit 8b4817f

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

packages/rhsplib/librhsp/include/rhsp/serial.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ int rhsp_serialWrite(RhspSerial* serial, const uint8_t* buffer, size_t bytesToWr
113113
* */
114114
void rhsp_serialClose(RhspSerial* serial);
115115

116+
/**
117+
* @brief Get the last error code from the OS.
118+
* This is errno on unix, and GetLastError on windows.
119+
* */
120+
int rhsp_getLastOsError();
121+
116122
#ifdef __cplusplus
117123
}
118124
#endif

packages/rhsplib/librhsp/src/arch/linux/serial.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string.h>
1010
#include <termios.h>
1111
#include <unistd.h>
12+
#include <errno.h>
1213

1314
#include "rhsp/serial.h"
1415

@@ -359,4 +360,6 @@ static int baudrateToBits(uint32_t baudrate)
359360
}
360361
}
361362

362-
363+
int rhsp_getLastOsError() {
364+
return errno;
365+
}

packages/rhsplib/librhsp/src/arch/mac/serial.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string.h>
1010
#include <termios.h>
1111
#include <unistd.h>
12+
#include <errno.h>
1213

1314
#include "rhsp/serial.h"
1415

@@ -228,3 +229,7 @@ void rhsp_serialClose(RhspSerial* serial)
228229
serial->fd = -1;
229230
}
230231

232+
int rhsp_getLastOsError() {
233+
return errno;
234+
}
235+

packages/rhsplib/librhsp/src/arch/win/serial.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,18 @@ int rhsp_serialOpen(RhspSerial* serial,
109109
{
110110
return RHSP_SERIAL_ERROR;
111111
}
112+
113+
char modifiedSerialPortName[20];
114+
115+
// if the user has already prefixed the workaround, don't add it again
116+
if(serialPort[0] == '\\') {
117+
strncpy(modifiedSerialPortName, serialPort, 20);
118+
} else {
119+
snprintf(modifiedSerialPortName, 20, "\\\\.\\%s", serialPort);
120+
}
112121

113122
/* Try to open specified COM-port */
114-
serial->handle = CreateFile(serialPort,
123+
serial->handle = CreateFile(modifiedSerialPortName,
115124
GENERIC_READ | GENERIC_WRITE,
116125
0, // must be opened with exclusive-access
117126
NULL, // default security attributes
@@ -242,3 +251,7 @@ void rhsp_serialClose(RhspSerial* serial)
242251
}
243252
}
244253
}
254+
255+
int rhsp_getLastOsError(void) {
256+
return (int) GetLastError();
257+
}

0 commit comments

Comments
 (0)