From e622d224927f061c72126c61cc1c2185914320fd Mon Sep 17 00:00:00 2001 From: short <> Date: Thu, 10 Jul 2003 10:00:55 +0000 Subject: [PATCH] New option -w|--waittime as requested by Markus Widauer --- NEWS | 1 + mdsms.1.in | 11 +++++++ mdsms.c | 103 +++++++++++++++++++++++++++++++++---------------------------- setup.h | 1 + 4 files changed, 69 insertions(+), 47 deletions(-) diff --git a/NEWS b/NEWS index 0159879..ee5f9a1 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Mobile Device SMS tool NEWS $Id$ 1.5.3: Sending of picture messages implemented + New option -w|--waittime as requested by Markus Widauer 1.5.2: Minor crossplatformity fixes diff --git a/mdsms.1.in b/mdsms.1.in index ded0992..a192278 100644 --- a/mdsms.1.in +++ b/mdsms.1.in @@ -38,6 +38,7 @@ options: .RB [ "-r " ] .RB [ "-t " ] .RB [ "-T " ] +.RB [ "-w " ] .RB [ "\-vhV" ] .SH DESCRIPTION @@ -248,6 +249,16 @@ approach. The default value is .BR DEF_CMDTIME ms. .TP +.BR -w | --waittime\ < sec > +This delay is maximum time allowed silently waiting for incoming data. +After approx 30 minutes of waiting for Nokia 9110 data it will turn off +its FaxModem feature disabling any further reading of messages. +After such idle time \fBmdsms\fP will also reinitialize the modem to +handle the case where the modem was silently powercycled in the meanwhile +loosing its initial settings done by \fBmdsms\fP during its startup. +The default value is +.BR DEF_WAITTIME s. +.TP .BR -f | --file When parameter <\fBmsg text\fP> has been specified, by using this option \fBmdsms\fP will read the file with the <\fBmsg text\fP> filename instead diff --git a/mdsms.c b/mdsms.c index 69ab8a4..f50b12a 100644 --- a/mdsms.c +++ b/mdsms.c @@ -107,9 +107,9 @@ static int verbose static char *pname; static int dis_cleanup=0,devfd=-1; -static char *phone,*device,*logname,*lockfile,*smsmode,*pdusmscmode,*smsc,*maxretry,*readtime,*chartime,*cmdtime,*baud,*restore; +static char *phone,*device,*logname,*lockfile,*smsmode,*pdusmscmode,*smsc,*maxretry,*readtime,*chartime,*cmdtime,*waittime,*baud,*restore; static int readbody; -static long maxretryn=DEF_MAXRETRY,readtimen=-1,chartimen=DEF_CHARTIME,cmdtimen=DEF_CMDTIME,baudn=DEF_BAUD; +static long maxretryn=DEF_MAXRETRY,readtimen=-1,chartimen=DEF_CHARTIME,cmdtimen=DEF_CMDTIME,waittimen=DEF_WAITTIME,baudn=DEF_BAUD; #ifdef HAVE_CRTSCTS static int handshake_rtscts; static unsigned handshake_stamp; @@ -274,7 +274,7 @@ Usage: %s [-c|--config ] [-d|--device ]\n\ [-M|--smsmode ] [-P|--pdusmscmode ]\n\ [-s|--smsc ] [-m|--maxretry <#>]\n\ [-r|--readtime ] [-t|--chartime ] [-T|--cmdtime ]\n\ - [-v|--verbose] [-h|--help] [-V|--version]\n\ + [-w|--waittime ] [-v|--verbose] [-h|--help] [-V|--version]\n\ {--send | --send-mobildock | --receive | --logo-send}\n\ --send / --send-mobildock:\n\ [-f|--file] \n\ @@ -305,6 +305,7 @@ Usage: %s [-c|--config ] [-d|--device ]\n\ \t\t multiplied %dx for long cmds)\n\ -t, --chartime\tMilliseconds between each char (def. %dms)\n\ -T, --cmdtime\tMilliseconds before each whole AT command (def. %dms)\n\ + -w, --waittime\tSeconds to prevent timeout of 9110 FaxModem (def. %ds)\n\ -v, --verbose\tIncrease verbosity level, more \"-v\"s give more messages\n\ -h, --help\tPrint a summary of the options\n\ -V, --version\tPrint the version number\n\ @@ -332,7 +333,7 @@ You may need to use the following line to catch all of this help text:\n\ #else _("\n\t\t(Not supported on this platform!)"), #endif -DEF_MAXRETRY,DEF_READTIME,DEF_READTIME_MOBILDOCK,EXT_READTIME,DEF_CHARTIME,DEF_CMDTIME, +DEF_MAXRETRY,DEF_READTIME,DEF_READTIME_MOBILDOCK,EXT_READTIME,DEF_CHARTIME,DEF_CMDTIME,DEF_WAITTIME, WORD_NET,WORD_GROUP); exit(EXIT_FAILURE); } @@ -366,6 +367,7 @@ static const struct option longopts[]={ {"readtime" ,1,0,'r'}, {"chartime" ,1,0,'t'}, {"cmdtime" ,1,0,'T'}, +{"waittime" ,1,0,'w'}, {"file" ,0,0,'f'}, {"verbose" ,0,0,'v'}, {"help" ,0,0,'h'}, @@ -577,6 +579,7 @@ static struct { { 'r',&readtime }, { 't',&chartime }, { 'T',&cmdtime }, + { 'w',&waittime }, }; static void processargs(int argp,char **args,const char *from) @@ -587,7 +590,7 @@ int i; seq++; optarg=NULL; optind=0; /* FIXME: Possible portability problem. */ - while ((optc=getopt_long(argp,args,"c:d:L:l:b:xCM:P:s:m:r:t:T:fvhV",longopts,NULL))!=EOF) switch (optc) { + while ((optc=getopt_long(argp,args,"c:d:L:l:b:xCM:P:s:m:r:t:T:w:fvhV",longopts,NULL))!=EOF) switch (optc) { case 'c': if (cfgstacki>=NELEM(cfgstack)) { error(_("Looping (%d) during attempt to read config file \"%s\", break-out"),NELEM(cfgstack),from); @@ -595,7 +598,7 @@ int i; } chk(cfgstack[cfgstacki++]=strdup(optarg)); break; - case 'd': case 'L': case 'b': case 'l': case 'M': case 'P': case 's': case 'm': case 'r': case 't': case 'T': + case 'd': case 'L': case 'b': case 'l': case 'M': case 'P': case 's': case 'm': case 'r': case 't': case 'T': case 'w': for (i=0;i=0); retry: - if (!immed && verbose>=2) + if (timeout && verbose>=2) error(_(".Waiting for device incoming data..")); #ifdef HAVE_POLL ufd.fd=devfd; ufd.events=POLLIN; ufd.revents=0; errno=0; - i=poll(&ufd,1,(immed?0:-1)); + i=poll(&ufd,1,timeout*1000); #else /* HAVE_POLL */ #ifdef HAVE_FD_SETSIZE if (devfd>=FD_SETSIZE) @@ -1600,7 +1603,7 @@ retry: errno=0; i=select(devfd+1,&rfds,NULL,&xfds,NULL); #endif /* HAVE_POLL */ - if (immed && i==0) return(0); + if (i==0) return(0); if (i==-1 && errno==EINTR) goto retry; /* silent retry, for example SIGCHLD could occur */ if (i!=1) @@ -2013,6 +2016,7 @@ static struct { { &readtime,&readtimen,"readtime" }, { &chartime,&chartimen,"chartime" }, { &cmdtime ,&cmdtimen ,"cmdtime" }, + { &waittime,&waittimen,"waittime" }, { &baud ,&baudn ,"baud" }, }; @@ -2292,50 +2296,55 @@ struct hexdata *hd; parts++; } } break; - case MODE_RECEIVE: + case MODE_RECEIVE: { +int gotdatawait; + restore="\r\nAT+CNMI=,0"; devcmd(NULL,NULL,"\r\nAT+CNMI=,2"); devcmd(NULL,NULL,"\r\nAT+CSDH=0"); - for (;;) { continue_receive: - unlockdevice(0); - /* Never bail-out when we got up to this point */ - if (maxretryn!=-1 && verbose>=1) - error(_(".Initialization successful, infinite retry count set")); - maxretryn=-1; + unlockdevice(0); + /* Never bail-out when we got up to this point */ + if (maxretryn!=-1 && verbose>=1) + error(_(".Initialization successful, infinite retry count set")); + maxretryn=-1; #if RECEIVE_TEST - receive_headerparse(" \"+420602123456\",,\"99/10/25,03:21:03-00\""); - receive_accept("TESTBODY"); - exit(EXIT_SUCCESS); + receive_headerparse(" \"+420602123456\",,\"99/10/25,03:21:03-00\""); + receive_accept("TESTBODY"); + exit(EXIT_SUCCESS); #endif - datawait(0); - if (!lockdevice(1)) { - if (verbose>=1) - error(_(".Dialout detected, waiting for lock..")); - if (verbose>=1) error(_(".Closing device \"%s\".."),device); - if (close(devfd)) - error(_("Error closing device \"%s\""),device); - lockdevice(0); - goto retryopen; - } - d1("Lock-device succeeded\n"); - do { - d1("Reading a message for us...\n"); - if (!(s=devcmd("\n","+CMT:"," "))) - goto retryall; - if (s==&devcmd_empty_return) /* only newlines found */ - goto continue_receive; - if (cmgf && !(i=receive_headerparse(s))) - error(_("Receive-header parsing failed on: %s"),s); - if (!(s=devcmd("\n","@"," "))) + gotdatawait=datawait(waittimen); + if (!lockdevice(1)) { + if (verbose>=1) + error(_(".Dialout detected, waiting for lock..")); + if (verbose>=1) error(_(".Closing device \"%s\".."),device); + if (close(devfd)) + error(_("Error closing device \"%s\""),device); + lockdevice(0); + goto retryopen; + } + d1("Lock-device succeeded\n"); + do { + if (!(s=devcmd("\n","+CMT:"," "))) + goto retryall; + if (s==&devcmd_empty_return) { /* only newlines found */ + if (gotdatawait==0) /* timeout, rather reinitialize the modem */ goto retryall; - if (cmgf) { - if (i) receive_text(s); - } - else receive_pdu(s); - } while (datawait(1)); - } /* return to 'continue receive' point */ - break; + goto continue_receive; + } + d1("Reading a message for us...\n"); + if (cmgf && !(i=receive_headerparse(s))) + error(_("Receive-header parsing failed on: %s"),s); + if (!(s=devcmd("\n","@"," "))) + goto retryall; + if (cmgf) { + if (i) receive_text(s); + } + else receive_pdu(s); + } while (datawait(0)); + goto retryall; + } + default: assert(0); } if (!s) { retrying(); goto retryall; } diff --git a/setup.h b/setup.h index 85a8113..ba96b47 100644 --- a/setup.h +++ b/setup.h @@ -18,6 +18,7 @@ #define DEF_CHARTIME 10 /* --chartime default (500ms per 80char=6.25ms recommended by Siemens */ #define DEF_CMDTIME 500 /* --cmdtime default */ +#define DEF_WAITTIME 500 /* --waittime default */ #define WORD_NET "net" /* load as network logo */ #define WORD_GROUP "group" /* load as group graphics */ #define MAXCONFIG 4096 /* maximum allowed size of any configuration file */ -- 1.8.3.1