Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 8f1e25d

Browse files
jasperlaynezz
authored andcommitted
Convert all Linux bits to Posix and add define for 460800 baudrate
- rename all Linux bits to Posix, to make it clear, that is (should) work on any Posix system - sprinkle a bit of BSD into device names and examples - added define for a non-standard badurate 460800 Signed-off-by: Jasper Lievisse Adriaanse <[email protected]> Signed-off-by: Petr Stetiar <[email protected]>
1 parent a007fb2 commit 8f1e25d

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

bindings/lua/luars232.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#ifdef WIN32
3535
#include "librs232/rs232_windows.h"
3636
#else
37-
#include "librs232/rs232_linux.h"
37+
#include "librs232/rs232_posix.h"
3838
#endif
3939

4040
#define MODULE_TIMESTAMP __DATE__ " " __TIME__

doc/example.lua

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ rs232 = require("luars232")
33
-- Linux
44
-- port_name = "/dev/ttyS0"
55

6+
-- (Open)BSD
7+
-- port_name = "/dev/cua00"
8+
69
-- Windows
710
port_name = "COM1"
811

include/librs232/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
pkginclude_HEADERS = rs232.h rs232_linux.h
2+
pkginclude_HEADERS = rs232.h rs232_posix.h

include/librs232/rs232.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131

3232
#define RS232_STRLEN 512
3333
#define RS232_STRLEN_DEVICE 30
34-
#define RS232_PORT_LINUX "/dev/ttyS0"
34+
35+
#ifdef __linux__
36+
#define RS232_PORT_POSIX "/dev/ttyS0"
37+
#else
38+
#define RS232_PORT_POSIX "/dev/cua00"
39+
#endif /* __linux__ */
40+
3541
#define RS232_PORT_WIN32 "COM1"
3642

3743
#if defined(WIN32) || defined(UNDER_CE)

include/librs232/rs232_linux.h include/librs232/rs232_posix.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
*
2525
*/
2626

27-
#ifndef __LIBRS232_LINUX_H__
28-
#define __LIBRS232_LINUX_H__
27+
#ifndef __LIBRS232_POSIX_H__
28+
#define __LIBRS232_POSIX_H__
2929

3030
#include <termios.h>
3131

32-
struct rs232_linux_t {
32+
#ifndef B460800
33+
#define B460800 460800
34+
#endif
35+
36+
struct rs232_posix_t {
3337
int fd;
3438
struct termios oldterm;
3539
};
@@ -46,4 +50,4 @@ struct rs232_linux_t {
4650
return RS232_ERR_CONFIG; \
4751
} \
4852

49-
#endif /* __LIBRS232_LINUX_H__ */
53+
#endif /* __LIBRS232_POSIX_H__ */

src/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ AM_CFLAGS = -Wall -ansi -pedantic -W -Wmissing-prototypes -Wmissing-declarations
1111

1212
lib_LTLIBRARIES = librs232.la
1313
librs232_la_LDFLAGS = -Wc,-nostartfiles -version-info $(LIBVERSION)
14-
librs232_la_SOURCES = rs232.c rs232_linux.c
14+
librs232_la_SOURCES = rs232.c rs232_posix.c
1515

1616
if ENABLE_DEBUG
1717
bin_PROGRAMS = rs232_test

src/rs232_linux.c src/rs232_posix.c

+23-23
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <unistd.h>
3939

4040
#include "librs232/rs232.h"
41-
#include "librs232/rs232_linux.h"
41+
#include "librs232/rs232_posix.h"
4242

4343
struct rs232_port_t *
4444
rs232_init(void)
@@ -48,15 +48,15 @@ rs232_init(void)
4848
if (p == NULL)
4949
return NULL;
5050

51-
p->pt = (struct rs232_linux_t *) malloc(sizeof(struct rs232_linux_t));
51+
p->pt = (struct rs232_posix_t *) malloc(sizeof(struct rs232_posix_t));
5252
if (p->pt == NULL)
5353
return NULL;
5454

5555
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
5656

57-
memset(p->pt, 0, sizeof(struct rs232_linux_t));
57+
memset(p->pt, 0, sizeof(struct rs232_posix_t));
5858
memset(p->dev, 0, RS232_STRLEN_DEVICE+1);
59-
strncpy(p->dev, RS232_PORT_LINUX, RS232_STRLEN_DEVICE);
59+
strncpy(p->dev, RS232_PORT_POSIX, RS232_STRLEN_DEVICE);
6060

6161
p->baud = RS232_BAUD_115200;
6262
p->data = RS232_DATA_8;
@@ -73,7 +73,7 @@ rs232_init(void)
7373
void
7474
rs232_end(struct rs232_port_t *p)
7575
{
76-
struct rs232_linux_t *ux = p->pt;
76+
struct rs232_posix_t *ux = p->pt;
7777

7878
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
7979

@@ -102,7 +102,7 @@ rs232_in_qeue(struct rs232_port_t *p, unsigned int *in_bytes)
102102
int ret;
103103
int b;
104104
struct timeval tv;
105-
struct rs232_linux_t *ux = p->pt;
105+
struct rs232_posix_t *ux = p->pt;
106106

107107
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
108108

@@ -139,7 +139,7 @@ rs232_in_qeue_clear(struct rs232_port_t *p)
139139
unsigned int blen;
140140
unsigned char *buf = NULL;
141141
struct timeval tv;
142-
struct rs232_linux_t *ux = p->pt;
142+
struct rs232_posix_t *ux = p->pt;
143143

144144
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
145145

@@ -175,7 +175,7 @@ rs232_read(struct rs232_port_t *p, unsigned char *buf, unsigned int buf_len,
175175
unsigned int *read_len)
176176
{
177177
int r;
178-
struct rs232_linux_t *ux = p->pt;
178+
struct rs232_posix_t *ux = p->pt;
179179

180180
DBG("p=%p p->pt=%p buf_len=%d\n", (void *)p, p->pt, buf_len);
181181

@@ -216,7 +216,7 @@ rs232_read_timeout_forced(struct rs232_port_t *p, unsigned char *buf,
216216
int reti;
217217
fd_set set;
218218
int r;
219-
struct rs232_linux_t *ux = p->pt;
219+
struct rs232_posix_t *ux = p->pt;
220220
struct timeval tv;
221221
struct timeval t1;
222222
struct timeval t2;
@@ -301,7 +301,7 @@ rs232_read_timeout(struct rs232_port_t *p, unsigned char *buf,
301301
fd_set set;
302302
int r;
303303
struct timeval tv;
304-
struct rs232_linux_t *ux = p->pt;
304+
struct rs232_posix_t *ux = p->pt;
305305

306306
DBG("p=%p p->pt=%p buf_len=%d timeout=%d\n", (void *)p, p->pt,
307307
buf_len, timeout);
@@ -346,7 +346,7 @@ rs232_write(struct rs232_port_t *p, unsigned char *buf, unsigned int buf_len,
346346
unsigned int *write_len)
347347
{
348348
int w;
349-
struct rs232_linux_t *ux = p->pt;
349+
struct rs232_posix_t *ux = p->pt;
350350

351351
DBG("p=%p p->pt=%p hex='%s' ascii='%s' buf_len=%d\n",
352352
(void *)p, p->pt, rs232_hex_dump(buf, buf_len),
@@ -379,7 +379,7 @@ rs232_write_timeout(struct rs232_port_t *p, unsigned char *buf,
379379
int ret;
380380
fd_set set;
381381
int w;
382-
struct rs232_linux_t *ux = p->pt;
382+
struct rs232_posix_t *ux = p->pt;
383383
struct timeval tv;
384384

385385
DBG("p=%p p->pt=%p timeout=%d\n", (void *)p, p->pt, timeout);
@@ -425,7 +425,7 @@ rs232_open(struct rs232_port_t *p)
425425
{
426426
int flags;
427427
struct termios term;
428-
struct rs232_linux_t *ux = p->pt;
428+
struct rs232_posix_t *ux = p->pt;
429429

430430
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
431431

@@ -490,7 +490,7 @@ unsigned int
490490
rs232_set_baud(struct rs232_port_t *p, enum rs232_baud_e baud)
491491
{
492492
struct termios term;
493-
struct rs232_linux_t *ux = p->pt;
493+
struct rs232_posix_t *ux = p->pt;
494494

495495
DBG("p=%p p->pt=%p baud=%d (%s bauds)\n",
496496
(void *)p, p->pt, baud, rs232_strbaud(baud));
@@ -549,7 +549,7 @@ rs232_set_dtr(struct rs232_port_t *p, enum rs232_dtr_e state)
549549
{
550550
int ret;
551551
int set;
552-
struct rs232_linux_t *ux = p->pt;
552+
struct rs232_posix_t *ux = p->pt;
553553

554554
DBG("p=%p p->pt=%p dtr=%d (dtr control %s)\n",
555555
(void *)p, p->pt, state, rs232_strdtr(state));
@@ -587,7 +587,7 @@ rs232_set_rts(struct rs232_port_t *p, enum rs232_rts_e state)
587587
{
588588
int ret;
589589
int set;
590-
struct rs232_linux_t *ux = p->pt;
590+
struct rs232_posix_t *ux = p->pt;
591591

592592
DBG("p=%p p->pt=%p rts=%d (rts control %s)\n",
593593
(void *)p, p->pt, state, rs232_strrts(state));
@@ -624,7 +624,7 @@ unsigned int
624624
rs232_set_parity(struct rs232_port_t *p, enum rs232_parity_e parity)
625625
{
626626
struct termios term;
627-
struct rs232_linux_t *ux = p->pt;
627+
struct rs232_posix_t *ux = p->pt;
628628

629629
DBG("p=%p p->pt=%p parity=%d (parity %s)\n",
630630
(void *)p, p->pt, parity, rs232_strparity(parity));
@@ -656,7 +656,7 @@ unsigned int
656656
rs232_set_stop(struct rs232_port_t *p, enum rs232_stop_e stop)
657657
{
658658
struct termios term;
659-
struct rs232_linux_t *ux = p->pt;
659+
struct rs232_posix_t *ux = p->pt;
660660

661661
DBG("p=%p p->pt=%p stop=%d (%s stop bits)\n",
662662
(void *)p, p->pt, stop, rs232_strstop(stop));
@@ -684,7 +684,7 @@ unsigned int
684684
rs232_set_data(struct rs232_port_t *p, enum rs232_data_e data)
685685
{
686686
struct termios term;
687-
struct rs232_linux_t *ux = p->pt;
687+
struct rs232_posix_t *ux = p->pt;
688688

689689
DBG("p=%p p->pt=%p data=%d (%s data bits)\n",
690690
(void *)p, p->pt, data, rs232_strdata(data));
@@ -719,7 +719,7 @@ unsigned int
719719
rs232_set_flow(struct rs232_port_t *p, enum rs232_flow_e flow)
720720
{
721721
struct termios term;
722-
struct rs232_linux_t *ux = p->pt;
722+
struct rs232_posix_t *ux = p->pt;
723723

724724
DBG("p=%p p->pt=%p flow=%d (flow control %s)\n",
725725
(void *)p, p->pt, flow, rs232_strflow(flow));
@@ -753,7 +753,7 @@ unsigned int
753753
rs232_flush(struct rs232_port_t *p)
754754
{
755755
int ret;
756-
struct rs232_linux_t *ux = p->pt;
756+
struct rs232_posix_t *ux = p->pt;
757757

758758
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
759759

@@ -771,7 +771,7 @@ unsigned int
771771
rs232_close(struct rs232_port_t *p)
772772
{
773773
int ret;
774-
struct rs232_linux_t *ux = p->pt;
774+
struct rs232_posix_t *ux = p->pt;
775775

776776
DBG("p=%p p->pt=%p\n", (void *)p, p->pt);
777777

@@ -789,7 +789,7 @@ rs232_close(struct rs232_port_t *p)
789789
unsigned int
790790
rs232_fd(struct rs232_port_t *p)
791791
{
792-
struct rs232_linux_t *ux = p->pt;
792+
struct rs232_posix_t *ux = p->pt;
793793

794794
DBG("p=%p p->pt=%p ux->fd=%d\n", (void *)p, p->pt, ux->fd);
795795

0 commit comments

Comments
 (0)