| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
2
|
|
|
|
|
|
|
#include "perl.h" |
|
3
|
|
|
|
|
|
|
#include "XSUB.h" |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
#include |
|
8
|
|
|
|
|
|
|
#include |
|
9
|
|
|
|
|
|
|
#include |
|
10
|
|
|
|
|
|
|
#include |
|
11
|
|
|
|
|
|
|
#include |
|
12
|
|
|
|
|
|
|
#include |
|
13
|
|
|
|
|
|
|
#include |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
void tty_close (int fd){ |
|
16
|
0
|
|
|
|
|
|
printf("%d\n", fd); |
|
17
|
0
|
|
|
|
|
|
close (fd) ; |
|
18
|
0
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
int tty_available (int fd){ |
|
21
|
|
|
|
|
|
|
int bytes_available; |
|
22
|
0
|
|
|
|
|
|
ioctl(fd, FIONREAD, &bytes_available); |
|
23
|
0
|
|
|
|
|
|
return bytes_available; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
int tty_putc(int fd, char b){ |
|
27
|
0
|
|
|
|
|
|
int n = write(fd,&b,1); |
|
28
|
0
|
0
|
|
|
|
|
if( n!=1) |
|
29
|
0
|
|
|
|
|
|
return -1; |
|
30
|
0
|
|
|
|
|
|
return 0; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
int tty_puts(int fd, const char* str){ |
|
34
|
0
|
|
|
|
|
|
int len = strlen(str); |
|
35
|
0
|
|
|
|
|
|
int n = write(fd, str, len); |
|
36
|
0
|
0
|
|
|
|
|
if( n!=len ) |
|
37
|
0
|
|
|
|
|
|
return -1; |
|
38
|
0
|
|
|
|
|
|
return 0; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
int tty_getc (int fd){ |
|
42
|
|
|
|
|
|
|
uint8_t x; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if (read (fd, &x, 1) != 1) |
|
45
|
0
|
|
|
|
|
|
return -1; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return ((int)x) & 0xFF; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
char* tty_gets(int fd, char* buf, int nbytes){ |
|
51
|
0
|
|
|
|
|
|
int bytes_read = 0; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
while (bytes_read < nbytes){ |
|
54
|
0
|
|
|
|
|
|
int result = read(fd, buf + bytes_read, nbytes - bytes_read); |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (0 >= result){ |
|
57
|
0
|
0
|
|
|
|
|
if (0 > result){ |
|
58
|
0
|
|
|
|
|
|
exit(-1); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
|
|
|
|
|
break; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
bytes_read += result; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return buf; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
int tty_open(const char *serialport, int baud){ |
|
69
|
|
|
|
|
|
|
struct termios toptions; |
|
70
|
|
|
|
|
|
|
int fd; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY); |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (fd == -1) { |
|
75
|
0
|
|
|
|
|
|
perror("open(): Unable to open port "); |
|
76
|
0
|
|
|
|
|
|
return -1; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if (tcgetattr(fd, &toptions) < 0) { |
|
80
|
0
|
|
|
|
|
|
perror("init_serialport: Couldn't get term attributes"); |
|
81
|
0
|
|
|
|
|
|
return -1; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
speed_t brate = baud; |
|
84
|
0
|
|
|
|
|
|
switch(baud) { |
|
85
|
0
|
|
|
|
|
|
case 4800: brate=B4800; break; |
|
86
|
0
|
|
|
|
|
|
case 9600: brate=B9600; break; |
|
87
|
|
|
|
|
|
|
#ifdef B14400 |
|
88
|
|
|
|
|
|
|
case 14400: brate=B14400; break; |
|
89
|
|
|
|
|
|
|
#endif |
|
90
|
0
|
|
|
|
|
|
case 19200: brate=B19200; break; |
|
91
|
|
|
|
|
|
|
#ifdef B28800 |
|
92
|
|
|
|
|
|
|
case 28800: brate=B28800; break; |
|
93
|
|
|
|
|
|
|
#endif |
|
94
|
0
|
|
|
|
|
|
case 38400: brate=B38400; break; |
|
95
|
0
|
|
|
|
|
|
case 57600: brate=B57600; break; |
|
96
|
0
|
|
|
|
|
|
case 115200: brate=B115200; break; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
cfsetispeed(&toptions, brate); |
|
100
|
0
|
|
|
|
|
|
cfsetospeed(&toptions, brate); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
// 8N1 |
|
103
|
0
|
|
|
|
|
|
toptions.c_cflag &= ~PARENB; |
|
104
|
0
|
|
|
|
|
|
toptions.c_cflag &= ~CSTOPB; |
|
105
|
0
|
|
|
|
|
|
toptions.c_cflag &= ~CSIZE; |
|
106
|
0
|
|
|
|
|
|
toptions.c_cflag |= CS8; |
|
107
|
|
|
|
|
|
|
// no flow control |
|
108
|
0
|
|
|
|
|
|
toptions.c_cflag &= ~CRTSCTS; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
toptions.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines |
|
111
|
0
|
|
|
|
|
|
toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw |
|
114
|
0
|
|
|
|
|
|
toptions.c_oflag &= ~OPOST; // make raw |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
toptions.c_cc[VMIN] = 0; |
|
117
|
0
|
|
|
|
|
|
toptions.c_cc[VTIME] = 10; |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if( tcsetattr(fd, TCSANOW, &toptions) < 0) { |
|
120
|
0
|
|
|
|
|
|
perror("init_serialport: Couldn't set term attributes"); |
|
121
|
0
|
|
|
|
|
|
return -1; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return fd; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
MODULE = RPi::Serial PACKAGE = RPi::Serial |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
int |
|
132
|
|
|
|
|
|
|
tty_available (fd) |
|
133
|
|
|
|
|
|
|
int fd |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
int |
|
136
|
|
|
|
|
|
|
tty_putc (fd, b) |
|
137
|
|
|
|
|
|
|
int fd |
|
138
|
|
|
|
|
|
|
char b |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
int |
|
141
|
|
|
|
|
|
|
tty_puts (fd, str) |
|
142
|
|
|
|
|
|
|
int fd |
|
143
|
|
|
|
|
|
|
const char * str |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
int |
|
146
|
|
|
|
|
|
|
tty_getc (fd) |
|
147
|
|
|
|
|
|
|
int fd |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
char * |
|
150
|
|
|
|
|
|
|
tty_gets (fd, buf, nbytes) |
|
151
|
|
|
|
|
|
|
int fd |
|
152
|
|
|
|
|
|
|
char * buf |
|
153
|
|
|
|
|
|
|
int nbytes |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
int |
|
156
|
|
|
|
|
|
|
tty_open (serialport, baud) |
|
157
|
|
|
|
|
|
|
const char * serialport |
|
158
|
|
|
|
|
|
|
int baud |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
void |
|
161
|
|
|
|
|
|
|
tty_close (fd) |
|
162
|
|
|
|
|
|
|
int fd |