*/
+#include "config.h"
+
#ifndef WIN32
#include "devices/unixserial.h"
- #include "devices/unixirda.h"
- #include "devices/tekram.h"
#include <sys/ioctl.h>
- #include <pthread.h>
#include <termios.h>
#include <signal.h>
#include <errno.h>
#include "mversion.h"
#endif
-char PortDevice[GSM_MAX_DEVICE_NAME_LENGTH]={0x00};
+static char PortDevice[GSM_MAX_DEVICE_NAME_LENGTH]={0x00};
-bool duringwrite;
+static bool duringwrite;
#ifndef WIN32
* Structure to store the filedescriptor we use.
*
*/
-int device_getfd(void)
+#ifdef DEBUG
+static int device_getfd(void)
{
return device_portfd;
}
+#endif /* DEBUG */
-int device_open(__const char *__file, int __with_odd_parity) {
+static int device_open(__const char *__file, int __with_odd_parity) {
switch (CurrentConnectionType) {
- case GCT_Tekram:
- device_portfd = tekram_open(__file);
- break;
- case GCT_Irda:
- device_portfd = irda_open();
- break;
default:
device_portfd = serial_opendevice(__file, __with_odd_parity, true, false);
break;
//pthread_join(Thread, NULL);
switch (CurrentConnectionType) {
- case GCT_Tekram: tekram_close(device_portfd); break;
- case GCT_Irda : irda_close(device_portfd); break;
default : serial_close(device_portfd); break;
}
PortDevice[0]=0x00;
}
+#ifndef UCLINUX
+
void device_reset(void) {
}
+#endif /* UCLINUX */
+
+#ifdef DEBUG
+static void device_dumpserial(void);
+#endif /* DEBUG */
+
void device_setdtrrts(int __dtr, int __rts)
{
switch (CurrentConnectionType) {
- case GCT_Tekram:
- case GCT_Irda:
- break;
default:
serial_setdtrrts(device_portfd, __dtr, __rts);
#ifdef DEBUG
void device_changespeed(int __speed)
{
switch (CurrentConnectionType) {
- case GCT_Irda:
- break;
- case GCT_Tekram:
- tekram_changespeed(device_portfd, __speed);
- break;
default:
serial_changespeed(device_portfd, __speed);
#ifdef DEBUG
}
}
-size_t device_read(__ptr_t __buf, size_t __nbytes)
+static size_t device_read(__ptr_t __buf, size_t __nbytes)
{
switch (CurrentConnectionType) {
- case GCT_Tekram: return (tekram_read(device_portfd, __buf, __nbytes)); break;
- case GCT_Irda : return ( irda_read(device_portfd, __buf, __nbytes)); break;
default : return (serial_read(device_portfd, __buf, __nbytes)); break;
}
}
u8 buffer[300];
size_t mysize;
- while (duringwrite) {}
+ while (duringwrite) {
+ fprintf(stderr,"device_write: reentrance violation!\n");
+ _exit(1);
+ }
memcpy(buffer,__buf,__n);
AppendLog(buffer,__n,true);
duringwrite=true;
switch (CurrentConnectionType) {
- case GCT_Irda : mysize = irda_write(device_portfd, __buf, __n); break;
- case GCT_Tekram: mysize = tekram_write(device_portfd, __buf, __n); break;
default : mysize = serial_write(device_portfd, __buf, __n); break;
}
duringwrite=false;
+ if (mysize!=__n)
+ fprintf(stderr,"WARNING: device_write(__n=%ld)=%ld\n",(long)__n,(long)mysize);
return mysize;
}
#ifdef DEBUG
-void device_dumpserial(void)
+static void device_dumpserial(void)
{
int PortFD;
unsigned int Flags=0;
}
#endif /* DEBUG */
+static char SigHandler_buffer[255];
+
void SigHandler(int status)
{
-
- unsigned char buffer[2048];
-
int count, res;
- res = device_read(buffer, 255);
+ LIVE_DISABLE;
+ LIVE;
+
+ res = device_read(SigHandler_buffer, sizeof(SigHandler_buffer));
for (count = 0; count < res ; count ++) {
- Protocol->StateMachine(buffer[count]);
+ Protocol->StateMachine(SigHandler_buffer[count]);
}
+ LIVE_ENABLE;
}
+#ifdef UCLINUX
+void usleep_watchdevice(unsigned long usecs)
+{
+int err;
+fd_set readfds;
+struct timeval target,timeout;
+long timeout_sec,timeout_usec; /* signed! */
+
+ if (gettimeofday(&target/*tv*/,NULL/*tz*/))
+ perror("usleep_watchdevice()/gettimeofday(2) init");
+ target.tv_usec+=usecs%1000000;
+ target.tv_sec +=usecs/1000000 + (target.tv_usec/1000000);
+ target.tv_usec%=1000000;
+
+ for (;;) {
+ if (gettimeofday(&timeout/*tv*/,NULL/*tz*/))
+ perror("usleep_watchdevice()/gettimeofday(2) loop");
+
+ timeout_sec =target.tv_sec -(long)timeout.tv_sec ;
+ timeout_usec=target.tv_usec-(long)timeout.tv_usec;
+
+ if (timeout_usec<0) {
+ timeout_sec--;
+ timeout_usec+=1000000;
+ }
+ if (timeout_sec<0)
+ return;
+
+ timeout.tv_sec =timeout_sec ;
+ timeout.tv_usec=timeout_usec;
+
+ FD_ZERO(&readfds);
+ if (device_portfd>=0)
+ FD_SET(device_portfd,&readfds);
+
+ err=select((device_portfd<0 ? 0 : device_portfd+1),&readfds,NULL,NULL,&timeout);
+ if ( err > 0 ) {
+ if (device_portfd>=0 && FD_ISSET(device_portfd,&readfds)) {
+ /* call singal handler to process incoming data */
+ SigHandler(0);
+ }
+ } else {
+ if (err == -1)
+ perror("Error in SelectLoop");
+ }
+ }
+}
+#endif
#if defined(__svr4__) || defined(__FreeBSD__)
/* thread for handling incoming data */
if ( err > 0 ) {
/* call singal handler to process incoming data */
SigHandler(0);
- /* refresh timeout, just for linux :-( */\r
+ /* refresh timeout, just for linux :-( */
/* required for irda */
- timeout.tv_sec=15;\r
+ timeout.tv_sec=15;
} else {
if (err == -1)
perror("Error in SelectLoop");
char text[100];
+#ifndef UCLINUX
#if defined(__svr4__) || defined(__FreeBSD__)
int rtn;
#else
struct sigaction sig_io;
#endif
+#endif /* UCLINUX */
+#ifndef UCLINUX
#ifdef DEBUG
if ((strstr(GSM_Info->IrdaModels,"decode")!=NULL) && (CurrentConnectionType == GCT_Irda))
{
return true;
}
#endif
+#endif /* UCLINUX */
if (PortDevice[0]!=0x00) return true;
strcpy(text,"Connection ");
switch (con) {
case GCT_FBUS :strcpy(text+strlen(text),"FBUS");break;
- case GCT_Infrared:strcpy(text+strlen(text),"infrared");break;
- case GCT_Irda :strcpy(text+strlen(text),"irda sockets");break;
+#ifndef UCLINUX
case GCT_MBUS :strcpy(text+strlen(text),"MBUS");break;
case GCT_DLR3 :strcpy(text+strlen(text),"DLR3");break;
- case GCT_Tekram :strcpy(text+strlen(text),"Tekram");break;
case GCT_AT :strcpy(text+strlen(text),"AT");break;
default :strcpy(text+strlen(text),"unknown");break;
+#endif /* UCLINUX */
}
strcpy(text+strlen(text),"\n");
AppendLogText(text,false);
// return false;
// }
+#ifndef UCLINUX
#if defined(__svr4__) || defined(__FreeBSD__)
#else
/* Set up and install handler before enabling async IO on port. */
sig_io.sa_flags = 0;
sigaction (SIGIO, &sig_io, NULL);
#endif
+#endif /* UCLINUX */
/* Open device. */
result = device_open(PortDevice, with_odd_parity);
return false;
}
+#ifndef UCLINUX
#if defined(__svr4__) || defined(__FreeBSD__)
/* create a thread to handle incoming data from mobile phone */
rtn=pthread_create(&selThread,NULL,(void*)SelectLoop,(void*)NULL);
return false;
}
#endif
+#endif /* UCLINUX */
return true;
}
strcpy(text,"Connection ");
switch (con) {
case GCT_FBUS :strcpy(text+strlen(text),"FBUS");break;
- case GCT_Infrared:strcpy(text+strlen(text),"infrared");break;
- case GCT_Irda :strcpy(text+strlen(text),"irda sockets");break;
case GCT_MBUS :strcpy(text+strlen(text),"MBUS");break;
case GCT_DLR3 :strcpy(text+strlen(text),"DLR3");break;
- case GCT_Tekram :strcpy(text+strlen(text),"Tekram");break;
case GCT_AT :strcpy(text+strlen(text),"AT");break;
default :strcpy(text+strlen(text),"unknown");break;
}