author | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
commit | 50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (unidiff) | |
tree | 0d1939e2297fa7bbd8e1f2030f154463854164c6 /gammu/emb/common/device/serial | |
parent | cf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff) | |
download | kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2 |
updated to latest gammu version
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,66 +1,66 @@ | |||
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 |
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,59 +1,83 @@ | |||
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"); |
@@ -156,88 +180,92 @@ static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool 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); |
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,26 +1,30 @@ | |||
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 |