Changeset 3206


Ignore:
Timestamp:
12/18/07 08:36:03 (12 years ago)
Author:
paulf
Message:

version 2.43 which improves modem handling for new kmi firmware on k2 instruments

Location:
trunk/src/data_sources/k2ew
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/data_sources/k2ew/ChangeLog

    r3002 r3206  
     1For the latest notes, proceed to the END of this file... 
    12 
    232000-03-11  Pete Lombard  <lomb4185@pacbell.net> 
     
    287288        THIS VERSION ONLY COMPILED on SOLARIS by Paul Friberg 
    288289         
    289  
    2902902005-06-01 Paul Friberg Version 2.40: added in a new directive 
    291291        ForceBlockMode to wrest control from the modem for K2s configured 
     
    295295        modem-enabled K2. Also added new communications 
    296296        statistics message for pickup by k2ewagent. 
    297  
    298297  
    2992982005-09-15 Paul Friberg Version 2.41: cleaned up all of the 
     
    308307        instead of a numeric value for handled signals. 
    309308 
    310  
     3092007-12-17 Paul Friberg Version 2.43: modified ForceBlockMode to check 
     310        for modem active strings and not regain control if modem is 
     311        active.  Note that I also fixed the returns from redo_socket  
     312        in k2c_tcp.c only to do this check if ForceBlockMode is set. 
     313        The previous version where ForceBlockMode (2.40) was introduced, 
     314        would only regrab control from the modem if RestartComm was 
     315        set in the .d file. THis is not necessary in 2.43. 
     316 
     317        Again, this is special code to handle dual feed K2s that have 
     318        both a LIVE SDS stream of data and a modem backup for dialout. 
     319        This is a common usage at Calif. Geological Survey. 
     320 
     321        Here is text from Dennis Pumphrey of KMI in an email 
     322        from 5/29/2007: 
     323 
     324************* 
     325Paul, 
     326 
     327The Altus has one command task. The command task is needed whenever you 
     328want to talk to the unit - either by sending commands in command mode, 
     329sending command packets, or sending retransmission requests. 
     330 
     331If an internal modem is installed, the Altus will insist on talking back 
     332to the modem after 5 minutes of inactivity on the command task. 
     333 
     334So: 
     3351) If you continue to send command packets (even pings), then control 
     336will never be sent back to the modem (because it is never idle) - but 
     337then you will never be able to call in to the unit through the modem. 
     338 
     3392) If you send a CR to the SDS port when the modem has control, you'll 
     340bet back a message "modem in control and active" vs. "modem in control 
     341an inactive". "active" means there's someone on the line. "inactive" 
     342means that the command task is just monitoring the modem. The command 
     343task will automatically hang up after 5 minutes of inactivity so you 
     344don't have to worry about someone dialing in and camping on the modem 
     345line. 
     346 
     347Actual text: 
     348MODEM in control and active\r\n 
     349-or- 
     350MODEM in control and inactive\r\n 
     351                  } 
     3523) "occasionally" is some combination of these, or you can deal with 
     353losing access to the command task because you won't get responses. You 
     354can recover with CR to tell what's happening (as in (2) above), and then 
     355send "\\\\" for force control back to the SDS port. 
     356 
     357If you just wrest control back from the modem (by sending "\\\\") then 
     358you may take control away from an active modem session. 
     359 
     360  
     361Dennis 
     362************* 
  • trunk/src/data_sources/k2ew/k2c_tcp.c

    r2995 r3206  
    88 *    Revision history: 
    99 *     $Log$ 
     10 *     Revision 1.11  2007/12/18 13:36:03  paulf 
     11 *     version 2.43 which improves modem handling for new kmi firmware on k2 instruments 
     12 * 
    1013 *     Revision 1.10  2007/05/10 00:20:14  dietz 
    1114 *     included <string.h> to fix missing prototypes 
     
    330333        else if (redo--)  /* decrement our local copy of redo */ 
    331334        {     /* Timeout occured; fiddle with the socket */ 
    332           if ( (rc = redo_socket()) == K2R_NO_ERROR) 
     335          if ( (rc = redo_socket()) == K2R_NO_ERROR) { 
     336            if (gcfg_force_blkmde)  
     337              k2mi_force_blkmde();      /* newly added for modem control regrab, if told to */ 
    333338            continue;    /* socket reopened; try for more */ 
    334           else 
     339          } else { 
    335340            return rc;   /* error or timeout */ 
     341          } 
    336342        } 
    337343        else  /* no more redo's allowed, return the timeout */ 
     
    377383        else if (redo--)  /* decrement our local copy of redo */ 
    378384        {     /* Timeout occured; fiddle with the socket */ 
    379           if ( (rc = redo_socket()) == K2R_NO_ERROR) 
     385          if ( (rc = redo_socket()) == K2R_NO_ERROR) { 
     386            if (gcfg_force_blkmde)  
     387              k2mi_force_blkmde();      /* newly added for modem control regrab, if told to */ 
    380388            continue;    /* socket reopened; try for more */ 
    381           else 
    382           { 
     389          } else { 
    383390            if (rc == K2R_ERROR || bcount == 0) 
    384391              return rc;   /* error or timeout */ 
     
    511518    { 
    512519      if (gcfg_debug > 1) 
    513         logit("e", "Closing socket\n"); 
     520        logit("et", "Closing socket\n"); 
    514521      if (closesocket(sfd) == SOCKET_ERROR) 
    515522      { 
     
    525532 
    526533    if (gcfg_debug > 1) 
    527       logit("e", "Opening socket\n"); 
     534      logit("et", "Opening socket\n"); 
    528535 
    529536    if ( (sfd = socket_ew(AF_INET, SOCK_STREAM, 0)) == SOCKET_ERROR) 
  • trunk/src/data_sources/k2ew/k2cirbuf.c

    r1232 r3206  
    77 *    Revision history: 
    88 *     $Log$ 
     9 *     Revision 1.9  2007/12/18 13:36:03  paulf 
     10 *     version 2.43 which improves modem handling for new kmi firmware on k2 instruments 
     11 * 
    912 *     Revision 1.8  2003/05/29 13:33:40  friberg 
    1013 *     cleaned up some warnings 
     
    335338 
    336339  if (gcfg_debug > 2 && cbptr->timestamp < 10000) 
    337     fprintf(stderr, "[timestamp=%lu in 'k2cb_block_out()']\n", 
     340    logit("et", "[timestamp=%lu in 'k2cb_block_out()']\n", 
    338341            cbptr->timestamp); 
    339342 
  • trunk/src/data_sources/k2ew/k2ewmain.c

    r3001 r3206  
    77 *    Revision history: 
    88 *     $Log$ 
     9 *     Revision 1.41  2007/12/18 13:36:03  paulf 
     10 *     version 2.43 which improves modem handling for new kmi firmware on k2 instruments 
     11 * 
    912 *     Revision 1.40  2007/05/15 23:29:24  dietz 
    1013 *     Changed version to 2.42 to reflect previous Windows Service-friendly mods 
     
    286289        all indicate the station name or the config filename so that  
    287290        the K2 having the error can be identified. 
     291 
     292        2007-12-17 Paul Friberg Version 2.43: new dual feed k2 with 
     293        modems improvements. This requires a new firmware upgrade 
     294        from KMI that was completed in August of 2007. 
    288295  
    289296*/ 
     
    314321#include "glbvars.h"         /* externs to globals & 'K2_MAX_STREAMS' define */ 
    315322 
    316 #define K2EW_VERSION_STR "2.42" /* version string for program */ 
     323#define K2EW_VERSION_STR "2.43" /* version string for program */ 
    317324 
    318325#define K2_STMDEBUG_FLG 0       /* 1 for stream input debug display enabled */ 
     
    467474  static struct StrDataHdr datahdr; 
    468475  static long databuff[K2PM_MIN_DBUFSIZ+2]; 
    469   static time_t prog_start_time, timevar, last_stat_time = (time_t)0; 
     476  static time_t prog_start_time, timevar, last_stat_time = (time_t)0;  
     477  static time_t last_force_block, last_attempted_force_block, now; 
    470478  static char msg_txt[180]; 
    471479  static struct tm tmblk; 
     
    475483  gcfg_stnid_remap[0]='\0'; 
    476484  g_k2_stnid[0] ='\0'; 
     485  last_force_block = 0; 
     486  last_attempted_force_block = 0; 
    477487 
    478488  if (argc != 2) 
     
    572582     } 
    573583     logit("et","Forced block mode with K2\n"); 
     584     time(&last_force_block); 
    574585  } 
    575586 
     
    14081419              if(resendcnt <= 1)  /* if first resend for block then */ 
    14091420                ++g_req_pend;     /* inc total # of resend req count */ 
     1421 
     1422              /* if there is a resend request, then we need to make sure the serial port has control, 
     1423                not sure we need to do this EACH resend request , 
     1424                so, only do this if we haven't succeeded in forcing it in the last FORCE_TIMEOUT_CHECK secs or  
     1425                        if we last_attempted to force it within 10 seconds of the last time we tried */ 
     1426 
     1427#define FORCE_TIMEOUT_CHECK 20  /* this is in seconds */ 
     1428 
     1429              time(&now); 
     1430              if (gcfg_force_blkmde == 1 && ((now - last_force_block) > FORCE_TIMEOUT_CHECK) )  
     1431              { 
     1432                 if( (now - last_attempted_force_block >= 10) && k2mi_force_blkmde() == K2R_ERROR) 
     1433                 {      
     1434                   logit ("et", "Unable to force block mode with K2 as requested for resend requests\n"); 
     1435                   time(&last_attempted_force_block); 
     1436                   continue; 
     1437                 } else { 
     1438                   logit("et","Forced block mode with K2 for resend requests, will not try again for %d secs\n", FORCE_TIMEOUT_CHECK); 
     1439                   time(&last_force_block); 
     1440                 } 
     1441              } 
    14101442              if (gcfg_debug > 0) 
    14111443              { 
     
    15241556                 } 
    15251557                 logit("et","Forced block mode with K2\n"); 
     1558                 time(&last_force_block); 
    15261559              } 
    15271560              /* confirm or restart block mode in the K2: */ 
  • trunk/src/data_sources/k2ew/k2misc.c

    r2718 r3206  
    77 *    Revision history: 
    88 *     $Log$ 
     9 *     Revision 1.31  2007/12/18 13:36:03  paulf 
     10 *     version 2.43 which improves modem handling for new kmi firmware on k2 instruments 
     11 * 
    912 *     Revision 1.30  2007/02/26 17:16:53  paulf 
    1013 *     made sure time_t are casted to long for heartbeat sprintf() 
     
    138141#define K2MI_FLSH_SHORT   100      /* short flush interval in ms */ 
    139142#define K2MI_FLSH_LONG    500      /* long flush interval in ms */ 
    140 #define K2MI_MONMODE_MAX  6        /* number of times to try mon-mode cmd */ 
     143#define K2MI_MONMODE_MAX  9        /* number of times to try mon-mode cmd */ 
    141144#define K2MI_BLKMODE_MAX  6        /* number of times to try block-mode cmd */ 
    142145#define K2MI_PKT_SRCNUM   44       /* arbitrary packet source # for file */ 
     
    174177  int idx, dcnt, slen, rc1, rc2; 
    175178  static const char *monmde_str_arr[]={          /* monitor-mode strings */ 
    176                                  "\\\\\\\\\r", "\r","\\\\\\\r","\\","\r\\\\\\\\\r"}; 
     179                                 "\\\\\\\\\r", "\r","\\\\\\\r","\\","\r\\\\\\\\\r","\r\\\\\\\\\r", "\r\\\\\\\\\\\r", "\n\r\n\r", "\r\n", "\n\r\n\r\r"}; 
    177180  static const char blkmde_str[]="BLOCK\r";      /* block-mode command string */ 
    178181 
     
    261264        g_k2mi_buff[dcnt] = '\0';           /* NULL terminate buffer */ 
    262265        if (gcfg_debug > 2) 
    263           logit("e", "received:  %s\n", g_k2mi_buff); 
     266          logit("e", "received:  %d bytes '%s'\n", dcnt, g_k2mi_buff); 
    264267 
    265268        /* check if returned data contains monitor-mode prompt ('*') */ 
     
    291294  return K2R_ERROR; 
    292295} 
     296 
     297/* returns -1 if str not found anywhere in buf, or position of first char of str */ 
     298char * find_string_(char* buf, char * str, int buf_len)  
     299{ 
     300int i; 
     301int len_of_str; 
     302char *cptr; 
     303 
     304len_of_str= strlen(str); 
     305for (i=0; i< buf_len-len_of_str; i++) { 
     306   if ( (cptr=strstr(&buf[i], str)) != NULL) { 
     307      logit("et", "find_string_(): located string %s\n", cptr); 
     308      return cptr; 
     309   } 
     310} 
     311logit("et", "find_string_(): no %s in buffer\n", str); 
     312return NULL; 
     313} 
     314 
     315/* returns -1 if MODEM not in buf, or position of first char of MODEM string if found  
     316        This was written because the raw data stream could have 0s in it which would 
     317        nullify the strstr test! */ 
     318char * find_MODEM(char * buf, int len) { 
     319 
     320char modem_str[]="MODEM"; 
     321 
     322     return find_string_(buf, modem_str, len); 
     323} 
     324char * find_PROMPT(char * buf, int len) { 
     325char prompt_line_str[] = "\r * "; 
     326 
     327     return find_string_(buf, prompt_line_str, len); 
     328} 
     329 
     330 
     331 
     332static int block_mode_started = 1; 
    293333 
    294334/************************************************************************** 
     
    306346  int idx, dcnt, slen, rc1, rc2; 
    307347  static const char *monmde_str_arr[]={          /* monitor-mode strings */ 
    308                                  "\\\\\\\\\r", "\r","\\\\\\\r","\\","\r\\\\\\\\\r"}; 
     348                                 "\n\r\n\r", "\r\n", "\n\r\n\r\r", "\\\\\\\\\r","\\\\\\\r","\\\\\\\\\r","\r\\\\\\\\\r","\n\r\n\r", "\r\n\\\\\\\\\r\r\n", "\\\\\\\\\r\n\r\\\\\\\\\r\n\r\r"}; 
    309349  static const char blkmde_str[]="BLOCK\r";      /* block-mode command string */ 
     350  static const char ansmde_str[]="ANSWERMODE\r";      /* answermode command string */ 
     351 
     352  char *cptr; 
     353 
     354  int local_timeout_ms = 250; 
     355  int prompt_flag=0; 
    310356 
    311357  idx = 0;                  /* initialize monitor-mode string array index */ 
     
    314360  do     /* loop while attempting to activate and confirm K2 block mode */ 
    315361  { 
    316         /* Tell heartbeat thread we're happy */ 
    317           g_mt_working = 1; 
    318  
    319  
     362    /* Tell heartbeat thread we're happy */ 
     363    g_mt_working = 1; 
     364 
     365#ifdef FLUSH_IT 
    320366    if (gcfg_debug > 2) 
    321       logit("e", "flushing..."); 
     367      logit("et", "k2mi_force_blkmde: flushing recv buffer..."); 
    322368    if (k2c_flush_recv(K2MI_FLSH_SHORT) != K2R_NO_ERROR) 
    323369      return K2R_ERROR; 
    324370    if (gcfg_debug > 2) 
    325371      logit("e", "done\n"); 
     372#endif 
    326373 
    327374    monmde_count = K2MI_MONMODE_MAX; 
     
    329376    {    /* loop while attempting to activate and confirm K2 monitor mode */ 
    330377 
    331           /* Tell heartbeat thread we're happy */ 
    332           g_mt_working = 1; 
     378      /* Tell heartbeat thread we're happy */ 
     379      g_mt_working = 1; 
    333380 
    334381      /* send a monitor-mode string */ 
     382 
     383#ifdef FLUSH_IT 
    335384      if ( (slen = strlen(monmde_str_arr[idx])) == 1) 
    336385      { 
     
    339388          return rc1; 
    340389      } 
     390#endif 
    341391 
    342392      if (gcfg_debug > 2) 
    343         logit("e", "sending MM %d\n", idx); 
     393        logit("et", "k2mi_force_blkmde: sending MM %d - string '%s'\n", idx, monmde_str_arr[idx]); 
    344394 
    345395      if ( (rc1 = k2c_tran_buff((const unsigned char *)(monmde_str_arr[idx]), 
    346                                 slen, gcfg_commtimeout_itvl, 0)) != slen) 
     396                                slen, local_timeout_ms, 0)) != slen) 
    347397        return rc1;     /* if error transmitting then return */ 
    348398 
     
    351401        idx = 0;             /* if past end-of-array then wrap around to beg */ 
    352402 
     403#ifdef FLUSH_IT 
    353404      /* wait a bit for (possible) data to appear */ 
    354405      /*  (wait a bit longer if '\' (or '\r') command) */ 
     
    356407           == K2R_ERROR) 
    357408        return rc1; 
    358  
    359       /* save any data returned from K2 */ 
     409#endif 
     410 
     411      /* save any data returned from K2 - make sure not to redo socket conn */ 
    360412      if ( (dcnt = k2c_recv_buff(g_k2mi_buff, K2MI_IBFSIZ, 
    361                                  gcfg_commtimeout_itvl, 0)) > 0) 
     413                                 local_timeout_ms, 0)) > 0) 
    362414      {       /* data was received */ 
    363415        /* Tell heartbeat thread we're happy */ 
     
    366418        g_k2mi_buff[dcnt] = '\0';           /* NULL terminate buffer */ 
    367419        if (gcfg_debug > 2) 
    368           logit("e", "received:  %s\n", g_k2mi_buff); 
     420          logit("et", "k2mi_force_blkmde: received:  %d bytes '%s'\n", dcnt, g_k2mi_buff); 
     421 
     422        /* check if returned data contains modem command and its active, 
     423                actual string provided by Dennis Pumphrey of KMI 2007-05-29 */ 
     424        cptr = find_MODEM((char *)g_k2mi_buff, dcnt); 
     425 
     426        if (cptr == NULL && idx==3) { 
     427          logit("et", "k2mi_force_blkmde: No MODEM strings upon \\r, so assuming BLOCK mode.\n"); 
     428          return K2R_POSITIVE; 
     429        } 
     430 
     431        if (cptr != NULL && strstr((char*) cptr, "MODEM in control and active") != NULL) { 
     432          if (gcfg_debug > 2) 
     433            logit("et", "k2mi_force_blkmde: modem in control! not forcing block mode.\n"); 
     434          /* for now, just exit and let the modem do its thing till its done */ 
     435          return K2R_ERROR;  
     436          /* later we need to check a config setting if modems should be allowed to take precedent */ 
     437        } 
     438        if (cptr != NULL && strstr((char*) cptr, "MODEM in control and inactive") != NULL) { 
     439          if (gcfg_debug > 2) 
     440            logit("et", "k2mi_force_blkmde: modem in control! but inactive, try forcing block mode.\n"); 
     441            idx=4; 
     442        } 
    369443 
    370444        /* check if returned data contains monitor-mode prompt ('*') */ 
    371         if ( strchr((char *)g_k2mi_buff, (int)'*') != NULL) 
     445        if ( strchr((char *)g_k2mi_buff, (int)'*') != NULL || find_PROMPT((char *)g_k2mi_buff,dcnt)!=NULL) {  
     446          if (gcfg_debug > 2) 
     447            logit("et", "k2mi_force_blkmde: received:  command prompt\n"); 
     448          prompt_flag=1; 
    372449          break;             /* if monitor-mode prompt ('*') then exit loop */ 
     450        } 
    373451      } 
    374452      else if (dcnt == K2R_ERROR) 
    375453        return dcnt; 
     454      else if (gcfg_debug>2) 
     455          logit("et", "k2mi_force_blkmde: received:  %d bytes  after timeout of %d ms'\n", dcnt, local_timeout_ms); 
    376456    } 
    377457    while(--monmde_count);         /* loop if count not expired */ 
     458  
     459    /* for tests to see if sending BLOCK at the end works, fire it in regardless of prompt 2007.12.05 */ 
     460    prompt_flag=1;  /* paulf 2007.12.05 */ 
    378461    /* Now we should be in monitor mode, unless monmde_count expired */ 
    379  
    380     /* send block-mode command string */ 
    381     slen = strlen(blkmde_str); 
    382     if (gcfg_debug > 2) 
    383       logit("e", "%s\n",blkmde_str); 
    384  
    385     if ( (rc1 = k2c_tran_buff((unsigned char *)blkmde_str, slen, 
    386                                           gcfg_commtimeout_itvl,0)) != slen) 
    387     {    /* error transmitting; return code */ 
    388       return (rc1 < 0) ? rc1 : K2R_ERROR;   /* only use code if negative */ 
     462    if (block_mode_started && prompt_flag) { 
     463      unsigned char seqnum = 0; 
     464      /* send block-mode command string */ 
     465      slen = strlen(blkmde_str); 
     466      if (gcfg_debug > 2) 
     467        logit("et", "k2mi_force_blkmde: sending %s\n",blkmde_str); 
     468 
     469      if ( (rc1 = k2c_tran_buff((unsigned char *)blkmde_str, slen, 
     470                                          local_timeout_ms,0)) != slen) 
     471      {    /* error transmitting; return code */ 
     472        return (rc1 < 0) ? rc1 : K2R_ERROR;   /* only use code if negative */ 
    389473                                            /* 1/29/2002 -- [ET] */ 
     474      } 
     475      return K2R_POSITIVE; /* added 2007-11-07 to kick back faster for CGS firmware */ 
     476 
     477      /* new send start of streaming here for kicks */ 
     478      logit("et", "k2mi_force_blkmde: sent %s, now sending START_STREAM command\n",blkmde_str); 
     479 
     480      rc1 = k2pm_send_strctrl(K2SCC_START_STREAM, &seqnum, 0); 
     481 
     482      block_mode_started++;  /* this is for when we alternated testing, could be removed 2007.12.05 */ 
     483    }  
     484    if (!prompt_flag) { 
     485      logit("et", "k2mi_init_blkmde: no command prompt received, failed to go into block mode\n"); 
     486      return K2R_ERROR; 
    390487    } 
    391488    if ( (rc1 = k2c_flush_recv(K2MI_FLSH_SHORT)) == K2R_ERROR) 
  • trunk/src/data_sources/k2ew/makefile.sol

    r1236 r3206  
    77#    Revision history: 
    88#     $Log$ 
     9#     Revision 1.8  2007/12/18 13:36:03  paulf 
     10#     version 2.43 which improves modem handling for new kmi firmware on k2 instruments 
     11# 
    912#     Revision 1.7  2003/05/29 13:49:37  friberg 
    1013#     added in k2info.o 
     
    3235# 
    3336 
    34 CFLAGS = -g ${GLOBALFLAGS} 
     37CFLAGS = -g ${GLOBALFLAGS} -DFLUSH_IT 
     38#CFLAGS = -g ${GLOBALFLAGS} 
    3539 
    3640B = ${EW_HOME}/${EW_VERSION}/bin 
Note: See TracChangeset for help on using the changeset viewer.