COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
cssl_lib.h
Go to the documentation of this file.
1 
6 
7 /* Copyright 2003 Marcin Siennicki <m.siennicki@cloos.pl>
8  * see COPYING file for details */
9 
10 #include "support/configCosmos.h"
11 #include "support/sliplib.h"
12 
13 #ifndef __CSSL_H__
14 #define __CSSL_H__
15 
16 //#include <stdint.h>
17 #if defined(COSMOS_LINUX_OS) || defined(COSMOS_CYGWIN_OS) || defined(COSMOS_MAC_OS)
18 #include <termios.h>
19 #endif
20 
24 #define XMODEM_SOH 0x01
25 #define XMODEM_EOT 0x04
26 #define XMODEM_ACK 0x06
27 #define XMODEM_NAK 0x15
28 #define XMODEM_CAN 0x18
29 
34 typedef struct __cssl_t {
35 
36  uint8_t buffer[255]; /* input buffer */
37 
38  int fd; /* tty file descriptor */
39 
40 #if defined(COSMOS_LINUX_OS) || defined(COSMOS_CYGWIN_OS) || defined(COSMOS_MAC_OS)
41  struct termios tio; /* termios structure for the port */
42  struct termios oldtio; /* old termios structure */
43 #else // windows
44  struct _DCB dcb;
45  struct _DCB olddcb;
46  HANDLE handle;
47 #endif
48 
49  int baud;
50 
51  struct __cssl_t *next;
52 
53 } cssl_t;
54 
55 typedef enum {
56  CSSL_OK=0, /* everything is all right */
57  CSSL_ERROR_NOSIGNAL=CSSL_ERROR_BASE, /* there's no free signal */
58  CSSL_ERROR_NOTSTARTED, /* you should first start cssl */
59  CSSL_ERROR_NULLPOINTER, /* you gave a null pointer to the function */
60  CSSL_ERROR_OOPS, /* internal error, something's erong */
61  CSSL_ERROR_MEMORY, /* there's no memory for cssl_t structure */
62  CSSL_ERROR_OPEN /* file doesnt exist or you aren't good user */
63 } cssl_error_t;
64 
69 /* get the error message */
70 const char *cssl_geterrormsg();
71 
72 /* get the error code */
73 int32_t cssl_geterror();
74 
75 /* start the cssl */
76 int32_t cssl_start();
77 
78 /* finish all jobs, clear memory, etc. */
79 int32_t cssl_stop();
80 
81 /* alloc new cssl_t struct and open the port */
82 cssl_t *cssl_open(const char *fname, /* pathname of port file,
83  * for example "/dev/ttyS0" */
84  int baud, /* baudrate, integer, for example 19200 */
85  int bits, /* data bits: 7 or 8 */
86  int parity, /* parity: 0 - none, 1-odd, 2-even */
87  int stop); /* stop bits: 1 or 2 */
88 
89 /* closes the port, and frees its cssl_t struct */
90 int32_t cssl_close(cssl_t *serial);
91 
92 /* setups the port, look at cssl_open */
93 int32_t cssl_setup(cssl_t *serial,
94  int baud,
95  int bits,
96  int parity,
97  int stop);
98 
100  int rtscts, /* Boolean:
101  * 0 - no rts/cts control,
102  * 1 - rts/cts control
103  */
104  int xonxoff); /* Boolean:
105  * 0 - no xon/xoff,
106  * 1 - xon/xoff
107  */
108 
109 /* sends a char via serial port */
110 int32_t cssl_putchar(cssl_t *serial, uint8_t c);
111 
112 /* sends a null terminated string */
113 int32_t cssl_putstring(cssl_t *serial,
114  char *str);
115 
116 /* sends a data of known size */
117 int32_t cssl_putdata(cssl_t *serial,
118  uint8_t *data, /* data */
119  uint32_t datalen); /* length of data */
120 
121 int32_t cssl_putslip(cssl_t *serial, uint8_t *buf, size_t size);
122 int32_t cssl_putnmea(cssl_t *serial, uint8_t *buf, size_t size);
123 
124 /* waits until all data has been transmited */
125 
126 int32_t cssl_drain(cssl_t *serial);
127 
128 /*======================================
129  * Blocking mode
130  */
131 
132 int32_t cssl_settimeout(cssl_t *serial, int minchar, double timeout);
133 
134 /* reads a char in blocking mode */
135 int32_t cssl_getchar(cssl_t *serial);
136 
137 /* reads a data to a buffer in blocking mode*/
138 int32_t cssl_getdata(cssl_t *serial,
139  uint8_t *buffer, /* buffer for data */
140  int size); /* buffer size */
141 
142 int32_t cssl_getslip(cssl_t *serial, uint8_t *buffer, uint16_t size);
143 int32_t cssl_getnmea(cssl_t *serial, uint8_t *buf, uint16_t size);
144 int32_t cssl_getxmodem(cssl_t* serial, uint8_t* buffer);
145 
147 
148 #endif /* __CSSL_H__ */
struct __cssl_t cssl_t
struct _DCB dcb
Definition: cssl_lib.h:44
COSMOS SLIP support include file.
HANDLE handle
Definition: cssl_lib.h:46
struct __cssl_t * next
Definition: cssl_lib.h:51
int32_t cssl_getslip(cssl_t *serial, uint8_t *buf, uint16_t size)
Read SLIP frame.
Definition: cssl_lib.cpp:826
int32_t cssl_start()
Definition: cssl_lib.cpp:73
cssl_error_t
Definition: cssl_lib.h:55
Definition: cssl_lib.h:62
const string & str
Definition: json11.cpp:360
Definition: cssl_lib.h:59
int32_t cssl_getnmea(cssl_t *serial, uint8_t *buf, uint16_t size)
Read NMEA response.
Definition: cssl_lib.cpp:902
#define CSSL_ERROR_BASE
Definition: cosmos-errno.h:159
int32_t cssl_getxmodem(cssl_t *serial, uint8_t *buf)
Read Xmodem frame.
Definition: cssl_lib.cpp:771
int fd
Definition: cssl_lib.h:38
int datalen
Definition: mcastclient.c:41
Definition: cssl_lib.h:58
const char * cssl_geterrormsg()
Definition: cssl_lib.cpp:56
static char fname[100]
Definition: geomag.cpp:89
int32_t cssl_putchar(cssl_t *serial, uint8_t c)
Definition: cssl_lib.cpp:505
Headers and definitions common to all COSMOS.
Definition: cssl_lib.h:61
int32_t cssl_setup(cssl_t *serial, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:257
int32_t cssl_stop()
Definition: cssl_lib.cpp:86
uint8_t buffer[255]
Definition: cssl_lib.h:36
int32_t cssl_setflowcontrol(cssl_t *serial, int rtscts, int xonxoff)
Definition: cssl_lib.cpp:389
int32_t cssl_close(cssl_t *serial)
Definition: cssl_lib.cpp:197
int32_t cssl_getchar(cssl_t *serial)
Definition: cssl_lib.cpp:709
Definition: cssl_lib.h:56
Definition: cssl_lib.h:57
Definition: cssl_lib.h:60
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
int32_t cssl_putnmea(cssl_t *serial, uint8_t *buf, size_t size)
Definition: cssl_lib.cpp:617
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
int32_t cssl_geterror()
Definition: cssl_lib.cpp:63
char buf[128]
Definition: rw_test.cpp:40
int32_t cssl_getdata(cssl_t *serial, uint8_t *buffer, int size)
Definition: cssl_lib.cpp:738
int32_t cssl_drain(cssl_t *serial)
Definition: cssl_lib.cpp:685
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
int32_t cssl_putslip(cssl_t *serial, uint8_t *buf, size_t size)
Definition: cssl_lib.cpp:586
struct _DCB olddcb
Definition: cssl_lib.h:45
cssl_t * serial
Definition: arduino_lib.cpp:63
int32_t cssl_putdata(cssl_t *serial, uint8_t *data, uint32_t datalen)
Definition: cssl_lib.cpp:553
int baud
Definition: cssl_lib.h:49
Definition: cssl_lib.h:34