Diffstat (limited to 'gammu/emb/common/device/serial') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/device/serial/ser_djg.c | 10 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_unx.c | 38 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_w32.c | 6 |
3 files changed, 43 insertions, 11 deletions
diff --git a/gammu/emb/common/device/serial/ser_djg.c b/gammu/emb/common/device/serial/ser_djg.c index ac9d7c8..2524187 100644 --- a/gammu/emb/common/device/serial/ser_djg.c +++ b/gammu/emb/common/device/serial/ser_djg.c | |||
@@ -1,74 +1,74 @@ | |||
1 | 1 | ||
2 | #include "../../gsmstate.h" | 2 | #include "../../gsmstate.h" |
3 | 3 | ||
4 | #ifdef GSM_ENABLE_SERIALDEVICE | 4 | #ifdef GSM_ENABLE_SERIALDEVICE |
5 | #ifdef DJGPP | 5 | #ifdef DJGPP |
6 | 6 | ||
7 | #include "../../gsmcomon.h" | 7 | #include "../../gsmcomon.h" |
8 | #include "ser_djg.h" | 8 | #include "ser_djg.h" |
9 | 9 | ||
10 | static GSM_Error serial_close(GSM_StateMachine *s) | 10 | static GSM_Error serial_close(GSM_StateMachine *s) |
11 | { | 11 | { |
12 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 12 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
13 | 13 | ||
14 | return ERR_NONE; | 14 | return ERR_NOTIMPLEMENTED; |
15 | } | 15 | } |
16 | 16 | ||
17 | static GSM_Error serial_open (GSM_StateMachine *s) | 17 | static GSM_Error serial_open (GSM_StateMachine *s) |
18 | { | 18 | { |
19 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 19 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
20 | 20 | ||
21 | return ERR_NONE; | 21 | return ERR_NOTIMPLEMENTED; |
22 | } | 22 | } |
23 | 23 | ||
24 | static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) | 24 | static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) |
25 | { | 25 | { |
26 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 26 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
27 | 27 | ||
28 | return ERR_NONE; | 28 | return ERR_NOTIMPLEMENTED; |
29 | } | 29 | } |
30 | 30 | ||
31 | static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) | 31 | static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) |
32 | { | 32 | { |
33 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 33 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
34 | 34 | ||
35 | return ERR_NONE; | 35 | return ERR_NOTIMPLEMENTED; |
36 | } | 36 | } |
37 | 37 | ||
38 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) | 38 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) |
39 | { | 39 | { |
40 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 40 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
41 | 41 | ||
42 | return ERR_NONE; | 42 | return ERR_NOTIMPLEMENTED; |
43 | } | 43 | } |
44 | 44 | ||
45 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) | 45 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) |
46 | { | 46 | { |
47 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 47 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
48 | 48 | ||
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) | 52 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) |
53 | { | 53 | { |
54 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 54 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
55 | 55 | ||
56 | return 0; | 56 | return 0; |
57 | } | 57 | } |
58 | 58 | ||
59 | GSM_Device_Functions SerialDevice = { | 59 | GSM_Device_Functions SerialDevice = { |
60 | serial_open, | 60 | serial_open, |
61 | serial_close, | 61 | serial_close, |
62 | serial_setparity, | 62 | serial_setparity, |
63 | serial_setdtrrts, | 63 | serial_setdtrrts, |
64 | serial_setspeed, | 64 | serial_setspeed, |
65 | serial_read, | 65 | serial_read, |
66 | serial_write | 66 | serial_write |
67 | }; | 67 | }; |
68 | 68 | ||
69 | #endif | 69 | #endif |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | /* How should editor hadle tabs in this file? Add editor commands here. | 72 | /* How should editor hadle tabs in this file? Add editor commands here. |
73 | * vim: noexpandtab sw=8 ts=8 sts=8: | 73 | * vim: noexpandtab sw=8 ts=8 sts=8: |
74 | */ | 74 | */ |
diff --git a/gammu/emb/common/device/serial/ser_unx.c b/gammu/emb/common/device/serial/ser_unx.c index 2a87b11..69c7515 100644 --- a/gammu/emb/common/device/serial/ser_unx.c +++ b/gammu/emb/common/device/serial/ser_unx.c | |||
@@ -1,83 +1,107 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | 1 | /* (c) 2002-2004 by Marcin Wiacek */ |
2 | /* locking device and settings all speeds by Michal Cihar */ | 2 | /* locking device and settings all speeds by Michal Cihar */ |
3 | /* based on some work from Gnokii (www.gnokii.org) | ||
4 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
5 | * GNU GPL version 2 or later | ||
6 | */ | ||
3 | 7 | ||
4 | #include "../../gsmstate.h" | 8 | #include "../../gsmstate.h" |
5 | 9 | ||
6 | #ifdef GSM_ENABLE_SERIALDEVICE | 10 | #ifdef GSM_ENABLE_SERIALDEVICE |
7 | #ifndef WIN32 | 11 | #ifndef WIN32 |
8 | #ifndef DJGPP | 12 | #ifndef DJGPP |
9 | 13 | ||
10 | #include <sys/file.h> | 14 | #include <sys/file.h> |
11 | #include <sys/time.h> | 15 | #include <sys/time.h> |
12 | #include <string.h> | 16 | #include <string.h> |
13 | #include <termios.h> | 17 | #include <termios.h> |
14 | #include <errno.h> | 18 | #include <errno.h> |
15 | 19 | ||
16 | #include "../../gsmcomon.h" | 20 | #include "../../gsmcomon.h" |
17 | #include "ser_unx.h" | 21 | #include "ser_unx.h" |
18 | 22 | ||
23 | #ifndef O_NONBLOCK | ||
24 | # define O_NONBLOCK 0 | ||
25 | #endif | ||
26 | |||
27 | #ifdef __NetBSD__ | ||
28 | # define FNONBLOCK O_NONBLOCK | ||
29 | |||
30 | # define B57600 0010001 | ||
31 | # define B115200 0010002 | ||
32 | # define B230400 0010003 | ||
33 | # define B460800 0010004 | ||
34 | # define B500000 0010005 | ||
35 | # define B576000 0010006 | ||
36 | # define B921600 0010007 | ||
37 | # define B1000000 0010010 | ||
38 | # define B1152000 0010011 | ||
39 | # define B1500000 0010012 | ||
40 | # define B2000000 0010013 | ||
41 | # define B2500000 0010014 | ||
42 | # define B3000000 0010015 | ||
43 | # define B3500000 0010016 | ||
44 | # define B4000000 0010017 | ||
45 | #endif | ||
46 | |||
19 | static GSM_Error serial_close(GSM_StateMachine *s) | 47 | static GSM_Error serial_close(GSM_StateMachine *s) |
20 | { | 48 | { |
21 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 49 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
22 | 50 | ||
23 | /* Restores old settings */ | 51 | /* Restores old settings */ |
24 | tcsetattr(d->hPhone, TCSANOW, &d->old_settings); | 52 | tcsetattr(d->hPhone, TCSANOW, &d->old_settings); |
25 | 53 | ||
26 | /* Closes device */ | 54 | /* Closes device */ |
27 | close(d->hPhone); | 55 | close(d->hPhone); |
28 | 56 | ||
29 | return ERR_NONE; | 57 | return ERR_NONE; |
30 | } | 58 | } |
31 | 59 | ||
32 | #ifndef O_NONBLOCK | ||
33 | # define O_NONBLOCK 0 | ||
34 | #endif | ||
35 | |||
36 | static GSM_Error serial_open (GSM_StateMachine *s) | 60 | static GSM_Error serial_open (GSM_StateMachine *s) |
37 | { | 61 | { |
38 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 62 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
39 | struct termios t; | 63 | struct termios t; |
40 | int i; | 64 | int i; |
41 | 65 | ||
42 | /* O_NONBLOCK MUST is required to avoid waiting for DCD */ | 66 | /* O_NONBLOCK MUST is required to avoid waiting for DCD */ |
43 | d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK); | 67 | d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK); |
44 | if (d->hPhone < 0) { | 68 | if (d->hPhone < 0) { |
45 | i = errno; | 69 | i = errno; |
46 | GSM_OSErrorInfo(s,"open in serial_open"); | 70 | GSM_OSErrorInfo(s,"open in serial_open"); |
47 | if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory | 71 | if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory |
48 | if (i == 13) return ERR_DEVICENOPERMISSION;//permission denied | 72 | if (i == 13) return ERR_DEVICENOPERMISSION;//permission denied |
49 | return ERR_DEVICEOPENERROR; | 73 | return ERR_DEVICEOPENERROR; |
50 | } | 74 | } |
51 | 75 | ||
52 | #ifdef TIOCEXCL | 76 | #ifdef TIOCEXCL |
53 | /* open() calls from other applications shall fail now */ | 77 | /* open() calls from other applications shall fail now */ |
54 | ioctl(d->hPhone, TIOCEXCL, (char *) 0); | 78 | ioctl(d->hPhone, TIOCEXCL, (char *) 0); |
55 | #endif | 79 | #endif |
56 | 80 | ||
57 | if (tcgetattr(d->hPhone, &d->old_settings) == -1) { | 81 | if (tcgetattr(d->hPhone, &d->old_settings) == -1) { |
58 | close(d->hPhone); | 82 | close(d->hPhone); |
59 | GSM_OSErrorInfo(s,"tcgetattr in serial_open"); | 83 | GSM_OSErrorInfo(s,"tcgetattr in serial_open"); |
60 | return ERR_DEVICEREADERROR; | 84 | return ERR_DEVICEREADERROR; |
61 | } | 85 | } |
62 | 86 | ||
63 | if (tcflush(d->hPhone, TCIOFLUSH) == -1) { | 87 | if (tcflush(d->hPhone, TCIOFLUSH) == -1) { |
64 | serial_close(s); | 88 | serial_close(s); |
65 | GSM_OSErrorInfo(s,"tcflush in serial_open"); | 89 | GSM_OSErrorInfo(s,"tcflush in serial_open"); |
66 | return ERR_DEVICEOPENERROR; | 90 | return ERR_DEVICEOPENERROR; |
67 | } | 91 | } |
68 | 92 | ||
69 | memcpy(&t, &d->old_settings, sizeof(struct termios)); | 93 | memcpy(&t, &d->old_settings, sizeof(struct termios)); |
70 | 94 | ||
71 | /* Opening without parity */ | 95 | /* Opening without parity */ |
72 | t.c_iflag = IGNPAR; | 96 | t.c_iflag = IGNPAR; |
73 | t.c_oflag = 0; | 97 | t.c_oflag = 0; |
74 | /* disconnect line, 8 bits, enable receiver, | 98 | /* disconnect line, 8 bits, enable receiver, |
75 | * ignore modem lines,lower modem line after disconnect | 99 | * ignore modem lines,lower modem line after disconnect |
76 | */ | 100 | */ |
77 | t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL; | 101 | t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL; |
78 | /* enable hardware (RTS/CTS) flow control (NON POSIX) */ | 102 | /* enable hardware (RTS/CTS) flow control (NON POSIX) */ |
79 | /* t.c_cflag |= CRTSCTS; */ | 103 | /* t.c_cflag |= CRTSCTS; */ |
80 | t.c_lflag = 0; | 104 | t.c_lflag = 0; |
81 | t.c_cc[VMIN] = 1; | 105 | t.c_cc[VMIN] = 1; |
82 | t.c_cc[VTIME] = 0; | 106 | t.c_cc[VTIME] = 0; |
83 | 107 | ||
@@ -132,136 +156,140 @@ static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) | |||
132 | if (tcgetattr(d->hPhone, &t)) { | 156 | if (tcgetattr(d->hPhone, &t)) { |
133 | GSM_OSErrorInfo(s,"tcgetattr in serial_setdtrrts"); | 157 | GSM_OSErrorInfo(s,"tcgetattr in serial_setdtrrts"); |
134 | return ERR_DEVICEREADERROR; | 158 | return ERR_DEVICEREADERROR; |
135 | } | 159 | } |
136 | 160 | ||
137 | #ifdef CRTSCTS | 161 | #ifdef CRTSCTS |
138 | /* Disabling hardware flow control */ | 162 | /* Disabling hardware flow control */ |
139 | t.c_cflag &= ~CRTSCTS; | 163 | t.c_cflag &= ~CRTSCTS; |
140 | #endif | 164 | #endif |
141 | 165 | ||
142 | if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) { | 166 | if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) { |
143 | serial_close(s); | 167 | serial_close(s); |
144 | GSM_OSErrorInfo(s,"tcsetattr in serial_setdtrrts"); | 168 | GSM_OSErrorInfo(s,"tcsetattr in serial_setdtrrts"); |
145 | return ERR_DEVICEDTRRTSERROR; | 169 | return ERR_DEVICEDTRRTSERROR; |
146 | } | 170 | } |
147 | 171 | ||
148 | flags = TIOCM_DTR; | 172 | flags = TIOCM_DTR; |
149 | if (dtr) { | 173 | if (dtr) { |
150 | ioctl(d->hPhone, TIOCMBIS, &flags); | 174 | ioctl(d->hPhone, TIOCMBIS, &flags); |
151 | } else { | 175 | } else { |
152 | ioctl(d->hPhone, TIOCMBIC, &flags); | 176 | ioctl(d->hPhone, TIOCMBIC, &flags); |
153 | } | 177 | } |
154 | 178 | ||
155 | flags = TIOCM_RTS; | 179 | flags = TIOCM_RTS; |
156 | if (rts) { | 180 | if (rts) { |
157 | ioctl(d->hPhone, TIOCMBIS, &flags); | 181 | ioctl(d->hPhone, TIOCMBIS, &flags); |
158 | } else { | 182 | } else { |
159 | ioctl(d->hPhone, TIOCMBIC, &flags); | 183 | ioctl(d->hPhone, TIOCMBIC, &flags); |
160 | } | 184 | } |
161 | 185 | ||
162 | flags = 0; | 186 | flags = 0; |
163 | ioctl(d->hPhone, TIOCMGET, &flags); | 187 | ioctl(d->hPhone, TIOCMGET, &flags); |
164 | 188 | ||
165 | dbgprintf("Serial device:"); | 189 | dbgprintf("Serial device:"); |
166 | dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down"); | 190 | dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down"); |
167 | dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down"); | 191 | dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down"); |
168 | dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down"); | 192 | dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down"); |
169 | dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down"); | 193 | dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down"); |
170 | if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR; | 194 | if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR; |
171 | if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR; | 195 | if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR; |
172 | 196 | ||
173 | return ERR_NONE; | 197 | return ERR_NONE; |
174 | } | 198 | } |
175 | 199 | ||
176 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) | 200 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) |
177 | { | 201 | { |
178 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 202 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
179 | struct termios t; | 203 | struct termios t; |
180 | int speed2 = B19200; | 204 | int speed2 = B19200; |
181 | 205 | ||
182 | if (tcgetattr(d->hPhone, &t)) { | 206 | if (tcgetattr(d->hPhone, &t)) { |
183 | GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed"); | 207 | GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed"); |
184 | return ERR_DEVICEREADERROR; | 208 | return ERR_DEVICEREADERROR; |
185 | } | 209 | } |
186 | 210 | ||
187 | smprintf(s, "Setting speed to %d\n", speed); | 211 | smprintf(s, "Setting speed to %d\n", speed); |
188 | 212 | ||
189 | switch (speed) { | 213 | switch (speed) { |
190 | case 50: speed2 = B50; break; | 214 | case 50: speed2 = B50; break; |
191 | case 75: speed2 = B75; break; | 215 | case 75: speed2 = B75; break; |
192 | case 110: speed2 = B110; break; | 216 | case 110: speed2 = B110; break; |
193 | case 134: speed2 = B134; break; | 217 | case 134: speed2 = B134; break; |
194 | case 150: speed2 = B150; break; | 218 | case 150: speed2 = B150; break; |
195 | case 200: speed2 = B200; break; | 219 | case 200: speed2 = B200; break; |
196 | case 300: speed2 = B300; break; | 220 | case 300: speed2 = B300; break; |
197 | case 600: speed2 = B600; break; | 221 | case 600: speed2 = B600; break; |
198 | case 1200: speed2 = B1200; break; | 222 | case 1200: speed2 = B1200; break; |
199 | case 1800: speed2 = B1800; break; | 223 | case 1800: speed2 = B1800; break; |
200 | case 2400: speed2 = B2400; break; | 224 | case 2400: speed2 = B2400; break; |
201 | case 4800: speed2 = B4800; break; | 225 | case 4800: speed2 = B4800; break; |
202 | case 9600: speed2 = B9600; break; | 226 | case 9600: speed2 = B9600; break; |
203 | case 19200: speed2 = B19200;break; | 227 | case 19200: speed2 = B19200;break; |
204 | case 38400: speed2 = B38400;break; | 228 | case 38400: speed2 = B38400;break; |
229 | #ifdef B57600 | ||
205 | case 57600: speed2 = B57600;break; | 230 | case 57600: speed2 = B57600;break; |
206 | case 115200: speed2 = B115200;break; | 231 | case 115200: speed2 = B115200;break; |
207 | case 230400: speed2 = B230400;break; | 232 | case 230400: speed2 = B230400;break; |
208 | case 460800: speed2 = B460800;break; | 233 | case 460800: speed2 = B460800;break; |
234 | #ifdef B500000 | ||
209 | case 500000: speed2 = B500000;break; | 235 | case 500000: speed2 = B500000;break; |
210 | case 576000: speed2 = B576000;break; | 236 | case 576000: speed2 = B576000;break; |
211 | case 921600: speed2 = B921600;break; | 237 | case 921600: speed2 = B921600;break; |
212 | case 1000000: speed2 = B1000000;break; | 238 | case 1000000: speed2 = B1000000;break; |
213 | case 1152000: speed2 = B1152000;break; | 239 | case 1152000: speed2 = B1152000;break; |
214 | case 1500000: speed2 = B1500000;break; | 240 | case 1500000: speed2 = B1500000;break; |
215 | case 2000000: speed2 = B2000000;break; | 241 | case 2000000: speed2 = B2000000;break; |
216 | case 2500000: speed2 = B2500000;break; | 242 | case 2500000: speed2 = B2500000;break; |
217 | case 3000000: speed2 = B3000000;break; | 243 | case 3000000: speed2 = B3000000;break; |
218 | case 3500000: speed2 = B3500000;break; | 244 | case 3500000: speed2 = B3500000;break; |
219 | case 4000000: speed2 = B4000000; break; | 245 | case 4000000: speed2 = B4000000; break; |
246 | #endif | ||
247 | #endif | ||
220 | } | 248 | } |
221 | 249 | ||
222 | /* This should work on all systems because it is done according to POSIX */ | 250 | /* This should work on all systems because it is done according to POSIX */ |
223 | cfsetispeed(&t, speed2); | 251 | cfsetispeed(&t, speed2); |
224 | cfsetospeed(&t, speed2); | 252 | cfsetospeed(&t, speed2); |
225 | 253 | ||
226 | if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) { | 254 | if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) { |
227 | serial_close(s); | 255 | serial_close(s); |
228 | GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed"); | 256 | GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed"); |
229 | return ERR_DEVICECHANGESPEEDERROR; | 257 | return ERR_DEVICECHANGESPEEDERROR; |
230 | } | 258 | } |
231 | 259 | ||
232 | return ERR_NONE; | 260 | return ERR_NONE; |
233 | } | 261 | } |
234 | 262 | ||
235 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) | 263 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) |
236 | { | 264 | { |
237 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 265 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
238 | struct timeval timeout2; | 266 | struct timeval timeout2; |
239 | fd_set readfds; | 267 | fd_set readfds; |
240 | int actual = 0; | 268 | int actual = 0; |
241 | 269 | ||
242 | FD_ZERO(&readfds); | 270 | FD_ZERO(&readfds); |
243 | FD_SET(d->hPhone, &readfds); | 271 | FD_SET(d->hPhone, &readfds); |
244 | 272 | ||
245 | timeout2.tv_sec = 0; | 273 | timeout2.tv_sec = 0; |
246 | timeout2.tv_usec = 1; | 274 | timeout2.tv_usec = 1; |
247 | 275 | ||
248 | if (select(d->hPhone+1, &readfds, NULL, NULL, &timeout2)) { | 276 | if (select(d->hPhone+1, &readfds, NULL, NULL, &timeout2)) { |
249 | actual = read(d->hPhone, buf, nbytes); | 277 | actual = read(d->hPhone, buf, nbytes); |
250 | if (actual == -1) GSM_OSErrorInfo(s,"serial_read"); | 278 | if (actual == -1) GSM_OSErrorInfo(s,"serial_read"); |
251 | } | 279 | } |
252 | return actual; | 280 | return actual; |
253 | } | 281 | } |
254 | 282 | ||
255 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) | 283 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) |
256 | { | 284 | { |
257 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 285 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
258 | int ret; | 286 | int ret; |
259 | size_t actual = 0; | 287 | size_t actual = 0; |
260 | 288 | ||
261 | do { | 289 | do { |
262 | ret = write(d->hPhone, (unsigned char *)buf, nbytes - actual); | 290 | ret = write(d->hPhone, (unsigned char *)buf, nbytes - actual); |
263 | if (ret < 0 && errno == EAGAIN) continue; | 291 | if (ret < 0 && errno == EAGAIN) continue; |
264 | if (ret < 0) { | 292 | if (ret < 0) { |
265 | if (actual != nbytes) GSM_OSErrorInfo(s,"serial_write"); | 293 | if (actual != nbytes) GSM_OSErrorInfo(s,"serial_write"); |
266 | return actual; | 294 | return actual; |
267 | } | 295 | } |
diff --git a/gammu/emb/common/device/serial/ser_w32.c b/gammu/emb/common/device/serial/ser_w32.c index 9fa0135..7d88fc7 100644 --- a/gammu/emb/common/device/serial/ser_w32.c +++ b/gammu/emb/common/device/serial/ser_w32.c | |||
@@ -1,50 +1,54 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | 1 | /* (c) 2002-2004 by Marcin Wiacek */ |
2 | /* based on some work from Gnokii, MSDN and others */ | 2 | /* based on some work from MSDN and others */ |
3 | /* based on some work from Gnokii (www.gnokii.org) | ||
4 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
5 | * GNU GPL version 2 or later | ||
6 | */ | ||
3 | 7 | ||
4 | #include "../../gsmstate.h" | 8 | #include "../../gsmstate.h" |
5 | 9 | ||
6 | #ifdef GSM_ENABLE_SERIALDEVICE | 10 | #ifdef GSM_ENABLE_SERIALDEVICE |
7 | #ifdef WIN32 | 11 | #ifdef WIN32 |
8 | 12 | ||
9 | #include <windows.h> | 13 | #include <windows.h> |
10 | #include <string.h> | 14 | #include <string.h> |
11 | #include <stdio.h> | 15 | #include <stdio.h> |
12 | #include <io.h> | 16 | #include <io.h> |
13 | #include <memory.h> | 17 | #include <memory.h> |
14 | 18 | ||
15 | #include "../../gsmcomon.h" | 19 | #include "../../gsmcomon.h" |
16 | #include "ser_w32.h" | 20 | #include "ser_w32.h" |
17 | 21 | ||
18 | static GSM_Error serial_close(GSM_StateMachine *s) | 22 | static GSM_Error serial_close(GSM_StateMachine *s) |
19 | { | 23 | { |
20 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 24 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
21 | 25 | ||
22 | /* Disables all monitored events for device */ | 26 | /* Disables all monitored events for device */ |
23 | SetCommMask(d->hPhone, 0); | 27 | SetCommMask(d->hPhone, 0); |
24 | 28 | ||
25 | /* Discards all characters from input/output buffer and terminates | 29 | /* Discards all characters from input/output buffer and terminates |
26 | * pending read/write operations | 30 | * pending read/write operations |
27 | */ | 31 | */ |
28 | PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT | | 32 | PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT | |
29 | PURGE_TXCLEAR | PURGE_RXCLEAR); | 33 | PURGE_TXCLEAR | PURGE_RXCLEAR); |
30 | 34 | ||
31 | /* Clears the DTR (data-terminal-ready) signal */ | 35 | /* Clears the DTR (data-terminal-ready) signal */ |
32 | EscapeCommFunction(d->hPhone, CLRDTR); | 36 | EscapeCommFunction(d->hPhone, CLRDTR); |
33 | 37 | ||
34 | /* Restores old settings */ | 38 | /* Restores old settings */ |
35 | if (SetCommState(d->hPhone, &d->old_settings)==0) { | 39 | if (SetCommState(d->hPhone, &d->old_settings)==0) { |
36 | GSM_OSErrorInfo(s, "SetCommState in serial_close"); | 40 | GSM_OSErrorInfo(s, "SetCommState in serial_close"); |
37 | } | 41 | } |
38 | 42 | ||
39 | /* Closes device */ | 43 | /* Closes device */ |
40 | if (CloseHandle(d->hPhone)==0) { | 44 | if (CloseHandle(d->hPhone)==0) { |
41 | GSM_OSErrorInfo(s, "CloseHandle in serial_close"); | 45 | GSM_OSErrorInfo(s, "CloseHandle in serial_close"); |
42 | } | 46 | } |
43 | 47 | ||
44 | return ERR_NONE; | 48 | return ERR_NONE; |
45 | } | 49 | } |
46 | 50 | ||
47 | static GSM_Error serial_open (GSM_StateMachine *s) | 51 | static GSM_Error serial_open (GSM_StateMachine *s) |
48 | { | 52 | { |
49 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 53 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
50 | DCB dcb; | 54 | DCB dcb; |