From: short <> Date: Thu, 3 Jun 1999 10:38:52 +0000 (+0000) Subject: Implemented remaining communication timeouts and maximum retry count. X-Git-Tag: bp_sms9110~13 X-Git-Url: https://git.jankratochvil.net/?p=mdsms.git;a=commitdiff_plain;h=4b0accf3496139854917959b47ad6d71c10370d8 Implemented remaining communication timeouts and maximum retry count. --- diff --git a/mdsms.1.in b/mdsms.1.in index 44d3088..8e829f9 100644 --- a/mdsms.1.in +++ b/mdsms.1.in @@ -3,6 +3,9 @@ .\~ $Id$ .\~ .\~ $Log$ +.\~ Revision 1.2 1999/06/03 10:38:52 short +.\~ Implemented remaining communication timeouts and maximum retry count. +.\~ .\~ Revision 1.1.1.1 1999/05/26 13:06:26 short .\~ First alpha release. .\~ @@ -16,6 +19,8 @@ mdsms \- send SMSes through MobilDock .RB [ "-d " ] .RB [ "-l " ] .RB [ "-s " ] +.RB [ "-m <#>" ] +.RB [ "-r " ] .RB [ "-t " ] .RB [ "-T " ] .RB [ "\-vhV" ] @@ -64,6 +69,31 @@ Known SMS centers as of May 1999: .BR "CZ EuroTel " ( "230 02" "): " +420602909909 .RE .TP +.BR -m | --maxretry\ < # > +Maximum retries of any \fBAT\fP-style command during the session. All the +retries are summed during one run of +.B mdsms +and no more retries of the command are permitted. After exceeding this +value the program is terminated. +.TP +.BR -r | --readtime\ < sec > +Maximum response read timeout before give up. +.B mdsms +sends the requested \fBAT\fP-style command to +.B MobilDock +and expects response. Unfortunately when the voice call is in progress, +.B MobilDock +will block any serial device communication and it is impossible to differentiate +between calling +.B MobilDock +and stucked/disconnected one. After exceeding this time interval, +.B mdsms +is terminated immediately, +.B maxretry +parameter notwithstanding. Standard value is +.BR DEF_READTIME +seconds and should be enough for any voice call. +.TP .BR -t | --chartime\ < msec > Although the fixed used baudrate of .B 19200 diff --git a/mdsms.c b/mdsms.c index f0837c6..af7fe28 100644 --- a/mdsms.c +++ b/mdsms.c @@ -5,6 +5,9 @@ static char rcsid[] ATTR_UNUSED = "$Id$"; /* * $Log$ + * Revision 1.2 1999/06/03 10:38:52 short + * Implemented remaining communication timeouts and maximum retry count. + * * Revision 1.1.1.1 1999/05/26 13:06:26 short * First alpha release. * @@ -69,9 +72,9 @@ static int verbose static char *pname; static int dis_cleanup=0,devfd=-1; -static char *phone,*body,*device,*lockfile,*smsc,*chartime,*cmdtime; +static char *phone,*body,*device,*lockfile,*smsc,*maxretry,*readtime,*chartime,*cmdtime; static int readbody; -static long chartimen=DEF_CHARTIME,cmdtimen=DEF_CMDTIME; +static long maxretryn=DEF_MAXRETRY,readtimen=DEF_READTIME,chartimen=DEF_CHARTIME,cmdtimen=DEF_CMDTIME; static size_t bodylen; static char *devicename; /* path stripped */ @@ -153,8 +156,8 @@ static void usage(void) %s\ \n\ Usage: " PACKAGE " [-c|--config ] [-d|--device ]\n\ - [-l|--lockfile ] [-s|--smsc ]\n\ - [-t|--chartime ] [-T|--cmdtime ]\n\ + [-l|--lockfile ] [-s|--smsc ] [-m|--maxretry <#>]\n\ + [-r|--readtime ] [-t|--chartime ] [-T|--cmdtime ]\n\ [-f|--file] [-v|--verbose] [-h|--help] [-V|--version]\n\ \n\ \n\ @@ -164,13 +167,15 @@ Usage: " PACKAGE " [-c|--config ] [-d|--device ]\n\ -l, --lockfile\tLock serial port by this file, \"%%s\" is basename of device\n\ \t\t(def. \"%s\")\n\ -s, --smsc\tUse this SMS Center number (def. query from Siemens A1)\n\ + -m, --maxretry\tMaximum retries of any command before giving up (def. %d)\n\ + -r, --readtime\tSeconds for maximum wait time for response (def. %ds)\n\ -t, --chartime\tMilliseconds between each char on baud 19200 (def. %dms)\n\ -T, --cmdtime\tMilliseconds before each whole AT command (def. %dms)\n\ -f, --file\tRead contents of message from file instead\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\ -\n",version,DEF_LOCKFILE,DEF_CHARTIME,DEF_CMDTIME); +\n",version,DEF_LOCKFILE,DEF_MAXRETRY,DEF_READTIME,DEF_CHARTIME,DEF_CMDTIME); exit(EXIT_FAILURE); } @@ -179,6 +184,8 @@ static const struct option longopts[]={ {"device" ,1,0,'d'}, {"lockfile",1,0,'l'}, {"smsc" ,1,0,'s'}, +{"maxretry",1,0,'m'}, +{"readtime",1,0,'r'}, {"chartime",1,0,'t'}, {"cmdtime" ,1,0,'T'}, {"file" ,0,0,'f'}, @@ -271,6 +278,8 @@ static struct { { 'd',&device }, { 'l',&lockfile }, { 's',&smsc }, + { 'm',&maxretry }, + { 'r',&readtime }, { 't',&chartime }, { 'T',&cmdtime }, }; @@ -283,7 +292,7 @@ int i; seq++; optarg=NULL; optind=0; /* FIXME: Possible portability problem. */ - while ((optc=getopt_long(argp,args,"c:d:l:s:t:T:fvhV",longopts,NULL))!=EOF) switch (optc) { + while ((optc=getopt_long(argp,args,"c:d:l:s:m:r:t:T: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),optind); @@ -291,7 +300,7 @@ int i; } chk(cfgstack[cfgstacki++]=strdup(optarg)); break; - case 'd': case 'l': case 's': case 't': case 'T': + case 'd': case 'l': case 's': case 'm': case 'r': case 't': case 'T': for (i=0;i=1) error("Timed out"); } @@ -457,12 +467,19 @@ void *p; assert(catchdatal<=catchdatasiz); } +static void retrying(void) +{ +static int cnt=0; + + if (++cnt>maxretryn) error("!Maximum command retry count (%d) exceeded",maxretryn); + if (verbose>=2) error(".Retrying phase, %d out of %d..",cnt,maxretryn); +} + static char *devcmd(const char *term,const char *catch,const char *send,...) { size_t l,bufl,terml,catchl,fragl,offs; char buf[LINE_MAX]; ssize_t got; -RETSIGTYPE (*origsig)(int); char *hit,*s; va_list ap; char errout; @@ -471,8 +488,9 @@ char errout; if ((errout=(*send=='!'))) send++; if (0) { err: + alarm(0); if (errout) return(NULL); - if (verbose>=2) error(".Retrying last device command.."); + retrying(); } catchdatal=0; va_start(ap,send); @@ -481,7 +499,6 @@ err: if (bufl>=sizeof(buf)-1) error("!Command too big (%d>%d)",bufl,sizeof(buf)-1); if (verbose>=2) error(".devcmd(send=\"%s\",term=\"%s\",catch=\"%s\")",buf,term,catch); buf[l]='\r'; buf[l+1]='\n'; - origsig=signal(SIGALRM,(RETSIGTYPE (*)(int))sigalarm); for (offs=0,got=0;offs ",NULL,"\r\nAT+CMGS=%d",(strlen(pdusmsc)+strlen(pdudata))/2); - s=devcmd(NULL,"\n+CMGS:","!%s%s\x1A",pdusmsc,pdudata); + if (!(s=devcmd(NULL,"\n+CMGS:","!%s%s\x1A",pdusmsc,pdudata))) retrying(); } while (!s); while (isspace(*s)) s++; if (verbose>=1) error("\nMessage successfuly sent with MR: %s",s); diff --git a/setup.h b/setup.h index c32de27..64baf64 100644 --- a/setup.h +++ b/setup.h @@ -2,6 +2,9 @@ * $Id$ * * $Log$ + * Revision 1.2 1999/06/03 10:38:52 short + * Implemented remaining communication timeouts and maximum retry count. + * * Revision 1.1.1.1 1999/05/26 13:06:26 short * First alpha release. * @@ -13,6 +16,8 @@ #ifndef DEF_LOCKFILE #define DEF_LOCKFILE "/var/lock/LCK..%s" #endif +#define DEF_MAXRETRY 10 +#define DEF_READTIME 60*60 #define DEF_CHARTIME 10 #define DEF_CMDTIME 500 #define MAXCONFIG 4096