Skip to content

Commit 5e08821

Browse files
committed
Add custom patch for libserialport, allowing virtual ports
Signed-off-by: falkTX <[email protected]>
1 parent 2729774 commit 5e08821

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
diff --git a/linux.c b/linux.c
2+
index 9016489..916c810 100644
3+
--- a/linux.c
4+
+++ b/linux.c
5+
@@ -44,13 +44,18 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port)
6+
RETURN_ERROR(SP_ERR_ARG, "Device name not recognized");
7+
8+
snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s", dev);
9+
- if (lstat(file_name, &statbuf) == -1)
10+
- RETURN_ERROR(SP_ERR_ARG, "Device not found");
11+
- if (!S_ISLNK(statbuf.st_mode))
12+
- snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s/device", dev);
13+
- count = readlink(file_name, file_name, sizeof(file_name));
14+
- if (count <= 0 || count >= (int)(sizeof(file_name) - 1))
15+
- RETURN_ERROR(SP_ERR_ARG, "Device not found");
16+
+ if (lstat(file_name, &statbuf) >= 0)
17+
+ {
18+
+ if (!S_ISLNK(statbuf.st_mode))
19+
+ snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s/device", dev);
20+
+ count = readlink(file_name, file_name, sizeof(file_name));
21+
+ if (count <= 0 || count >= (int)(sizeof(file_name) - 1))
22+
+ RETURN_ERROR(SP_ERR_ARG, "Device not found");
23+
+ }
24+
+ else
25+
+ {
26+
+ count = 0;
27+
+ }
28+
file_name[count] = 0;
29+
if (strstr(file_name, "bluetooth"))
30+
port->transport = SP_TRANSPORT_BLUETOOTH;
31+
diff --git a/serialport.c b/serialport.c
32+
index d271478..44ac11a 100644
33+
--- a/serialport.c
34+
+++ b/serialport.c
35+
@@ -1625,6 +1625,7 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data,
36+
struct sp_port_config *config)
37+
{
38+
unsigned int i;
39+
+ int err_TIOCMGET = 0;
40+
41+
TRACE("%p, %p, %p", port, data, config);
42+
43+
@@ -1731,7 +1732,10 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data,
44+
RETURN_FAIL("tcgetattr() failed");
45+
46+
if (ioctl(port->fd, TIOCMGET, &data->controlbits) < 0)
47+
- RETURN_FAIL("TIOCMGET ioctl failed");
48+
+ {
49+
+ err_TIOCMGET = 1;
50+
+ data->controlbits = -1;
51+
+ }
52+
53+
#ifdef USE_TERMIOX
54+
int ret = get_flow(port->fd, data);
55+
@@ -1827,6 +1831,14 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data,
56+
}
57+
#endif
58+
59+
+ if (err_TIOCMGET)
60+
+ {
61+
+ config->rts = -1;
62+
+ config->cts = -1;
63+
+ config->dtr = -1;
64+
+ config->dsr = -1;
65+
+ }
66+
+
67+
RETURN_OK();
68+
}
69+

0 commit comments

Comments
 (0)