home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / modem / byepc300.arc / BYESTAT.ARC / STAT.C < prev    next >
Text File  |  1987-10-24  |  14KB  |  777 lines

  1. /*
  2. **  Program:    <stat.c>
  3. **
  4. **  Purpose:    Provides status control for BYE-PC testing and
  5. **        control of modem functions.
  6. **
  7. **  Author:    R.E. Starr, Jr.
  8. **
  9. **  Revisons:
  10. **
  11. **     1.00 (12/01/86) -- First release
  12. **     1.01 (03/30/87) -- Modfiied for change in CSW.
  13. **     1.02 (03/30/87) -- Added new status functions implemented
  14. **              in BYE200
  15. **     1.03 (08/08/87) -- Modified for byexface version 2.0
  16. **     1.04 (10/23/87) -- Added name setting capability
  17. */
  18.  
  19. #include    <stdio.h>
  20. #include    <conio.h>
  21. #include    <process.h>
  22. #include    <ctype.h>
  23. #include    <string.h>
  24. #include    "bit.h"
  25. #include    "byexface.h"
  26.  
  27. #define YES 1
  28. #define NO  0
  29. #define ON  1
  30. #define OFF 0
  31.  
  32. #define VER 1        /* version of STAT running */
  33. #define REV 4
  34.  
  35. #define BYE_VER 3    /* BYE version# 3.00 or > required */
  36. #define BYE_REV 0
  37.  
  38.  
  39.     /* function delcarations */
  40.  
  41. int binary();
  42.  
  43. void null_cmd();
  44. void commands();
  45. void remote();
  46. void send_tx();
  47. void show_baud(), show_stat();
  48. void show_nulls();
  49. void show_rxsize();
  50. void set_mdmbreak();
  51. void set_mdmcd();
  52. void set_dtr();
  53. void set_mdmpause();
  54. void set_timer();
  55. void get_rx();
  56. void set_status();
  57. void set_mdmtrap();
  58. void set_name();
  59.  
  60.  
  61.     /* static command table */
  62.  
  63. #define PCMDS  (sizeof(cmdpri) / sizeof(struct key))
  64.  
  65. struct key
  66.     {
  67.     char *keyword;        /* pointer to key word */
  68.     void (*key_fxn)();        /* pointer to function */
  69.     };
  70. struct key cmdpri[] =            /* primary command set */
  71.     {
  72.     "BAUD", show_baud,
  73.     "BOOT", _bye_warmboot,
  74.     "BREAK", set_mdmbreak,
  75.     "CD", set_mdmcd,
  76.     "DTR", set_dtr,
  77.     "FLUSH", _bye_rxflush,
  78.     "HELP", commands,
  79.     "NAME", set_name,
  80.     "NULLS", show_nulls,
  81.     "PAUSE", set_mdmpause,
  82.     "QUEUE", show_rxsize,
  83.     "REMOTE", remote,
  84.     "RX", get_rx,
  85.     "STATUS", set_status,
  86.     "TIME", set_timer,
  87.     "TRAP", set_mdmtrap,
  88.     "TX", send_tx
  89.     };
  90.  
  91. #define SCMDS  (sizeof(cmdsec) / sizeof(struct key))
  92.  
  93. struct key cmdsec[] =            /* secondary command set */
  94.     {
  95.     "OFF", null_cmd,
  96.     "ON", null_cmd
  97.     };
  98.  
  99.  
  100. main(argc, argv)
  101.  
  102.  int argc;
  103.  char *argv[];
  104.     {
  105.     char *ptr;
  106.     int n, rtn;
  107.  
  108.     rtn = _bye_check(BYE_VER, BYE_REV);
  109.     if (rtn)
  110.     {
  111.     switch(rtn)
  112.         {
  113.         case 1:
  114.         printf("\nBYE-PC is not loaded!\n");
  115.         break;
  116.         case 2:
  117.         printf("\nBYE-PC loaded is the wrong Version!\n");
  118.         break;
  119.         case 3:
  120.         printf("\nBYE-PC loaded is the wrong Revision!\n");
  121.         break;
  122.         default:
  123.         printf("\nBYE-PC returned invalid error code!\n");
  124.         break;
  125.         }
  126.     exit(1);
  127.     }
  128.     if (argc > 1 && (_bye_getcsw() == 0xffff))
  129.     {
  130.     n = binary(argv[1], cmdpri, PCMDS);
  131.     if (n != EOF)
  132.         (*cmdpri[n].key_fxn)(argv[2]);
  133.     else
  134.         {
  135.         commands();
  136.         exit(1);
  137.         }
  138.     }
  139.     else
  140.     show_stat();
  141.     exit(0);
  142.     }
  143.  
  144.  
  145. /*
  146. **
  147. **  Function:    int binary(*word, tab, n);
  148. **
  149. **  Paramters:    char *word --> pointer to string to search for
  150. **        struct tab --> command table structure
  151. **        int n       --> number of commands in command table
  152. **
  153. **  Purpose:    Performs a binary search of the command table structure
  154. **        passed in the structure 'tab'. The strings are compared
  155. **        without regard to case.
  156. **
  157. **  Return:    EOF = command not found, else return the index of the
  158. **        command in the command table (0 to n).
  159. **
  160. */
  161.  
  162. int binary(word, tab, n)
  163.  
  164.  char *word;
  165.  struct key tab[];
  166.  int n;
  167.     {
  168.     int low, high, mid, cond;
  169.  
  170.     low = 0;
  171.     high = n - 1;
  172.     while (low <= high)
  173.     {
  174.     mid = (low + high) / 2;
  175.     if ((cond = strcmpi(word, tab[mid].keyword)) < 0)
  176.         high = mid - 1;
  177.     else if (cond > 0)
  178.         low = mid + 1;
  179.     else
  180.         return(mid);
  181.     }
  182.     return(-1);
  183.     }
  184.  
  185.  
  186. /*
  187. **
  188. **  Function:    void null_cmd();
  189. **
  190. **  Paramters:    <none>
  191. **
  192. **  Purpose:    Empty command for structure tables
  193. **
  194. **  Return:    <none>
  195. **
  196. */
  197.  
  198. void null_cmd()
  199.  {
  200.  return;
  201.  }
  202.  
  203.  
  204. /*
  205. **
  206. **  Function:    void commands();
  207. **
  208. **  Paramters:    <none>
  209. **
  210. **  Purpose:    Displays a list of all valid commands
  211. **
  212. **  Return:    <none>
  213. **
  214. */
  215.  
  216. void commands()
  217.  {
  218.  printf("\n\t** BYE-PC STAT Version %1d.%-2.2d **\n\n", VER, REV);
  219.  printf("BAUD ............. Displays Current Baud Rate On-Line.\n");
  220.  printf("BOOT ............. Hang up and warm boot system.\n");
  221.  printf("BREAK {ON/OFF} ... Sets Remote ^C & ^S option state.\n");
  222.  printf("CD {ON/OFF} ...... Sets Carrier Lost Detect State.\n");
  223.  printf("DTR {ON/OFF} ..... Toggle DTR line state.\n");
  224.  printf("FLUSH ............ Flush Rx-Queue of all data.\n");
  225.  printf("NULLS [#] ........ Displays and Sets Number of nulls (0-9).\n");
  226.  printf("NAME [string]..... Displays and Sets Callers name (63 chars max).\n");
  227.  printf("PAUSE {ON/OFF} ... Sets the ^S pause timeout state.\n");
  228.  printf("QUEUE ............ Displays Rx-Queue size.\n");
  229.  printf("REMOTE {ON/OFF} .. Disables remote console.\n");
  230.  printf("RX {#} ........... Rx up to 'n' characters & display.\n");
  231.  printf("STATUS [#] ....... Set caller status level (0-255)\n");
  232.  printf("TIME [0-255] ..... Show/set time allowed on the system.\n");
  233.  printf("TRAP {ON/OFF} .... Filter/Trap all ^C & ^S characters.\n");
  234.  printf("TX {literal} ..... Transmit the string literal to remote.\n");
  235.  printf("\nNote: {} are required arguments and [] indicates optional.\n\n");
  236.  }
  237.  
  238.  
  239. /*
  240. **
  241. **  Function:    void show_stat();
  242. **
  243. **  Paramters:    <none>
  244. **
  245. **  Purpose:    Displays current caller status data
  246. **
  247. **  Return:    <none>
  248. **
  249. */
  250.  
  251. void show_stat()
  252.  {
  253.  char d, name[64];
  254.  int baud, vers, rev;
  255.  unsigned x, t1, t2, t3;
  256.  
  257.  x = _bye_getcsw();
  258.  if (x == 0xffff)
  259.     printf("\n(System Operator)");
  260.  _bye_version(&vers, &rev);    /* read version number of BYE */
  261.  printf("\nSTAT %1d.%-2.2d under BYE-PC Version %1d.%-2.2d\n\n", VER, REV, vers, rev);
  262.  
  263.  _bye_getname(name);
  264.  printf("Caller on line       : %s\n", name);
  265.  printf("Modem Line Status    : (");
  266.  if (_bye_getcd())
  267.      printf("On");
  268.  else
  269.      printf("Off");
  270.  printf(" line)\n");
  271.  
  272.  printf("Current Baud Rate    : ");
  273.  baud = _bye_baud();
  274.  switch(baud)
  275.      {
  276.      case 0:
  277.      printf("300bps");
  278.      break;
  279.      case 1:
  280.      printf("1200bps");
  281.      break;
  282.      case 2:
  283.      printf("2400bps");
  284.      break;
  285.      default:
  286.      printf("(High Speed!)");
  287.      }
  288.  printf("\nNulls set to         : %1d\n", _bye_getnulls());
  289.  d = (char)((x >> 8) & 0x0F) + 'A';
  290.  printf("Maximum Drive Access : %c:\n", d);
  291.  printf("DOS Path Restriction : ");
  292.  if (x & BIT_2)
  293.      printf("(Un-Restricted)\n");
  294.  else
  295.      printf("(Restricted)\n");
  296.  printf("CD Command Status    : ");
  297.  if (x & BIT_3)
  298.      printf("(Active)\n");
  299.  else
  300.      printf("(Inactive)\n");
  301.  printf("File Send access     : ");
  302.  if (x & BIT_4)
  303.      printf("(Active)\n");
  304.  else
  305.      printf("(Inactive)\n");
  306.  printf("File Receive access  : ");
  307.  if (x & BIT_5)
  308.      printf("(Active)\n");
  309.  else
  310.      printf("(Inactive)\n");
  311.  t1 = _bye_gettimer();            /* minutes passed since log on */
  312.  t2 = _bye_gettimeon();         /* time allowed this call */
  313.  printf("Time since logged on : %u minute(s)\n", t1);
  314.  printf("Time limit this call : ");
  315.  if (t2)
  316.     printf("%u minute(s)\n", t2);
  317.  else
  318.     printf("(unlimited)\n");
  319.  printf("Time left this call  : ");
  320.  if (t2)
  321.     printf("%u minute(s)\n", t2 - t1);
  322.  else
  323.     printf("(unlimited)\n");
  324.  if (x == 0xffff)
  325.     printf("\n{STAT HELP or ?} for a list of commands...\n\n");
  326.  }
  327.  
  328.  
  329. /*
  330. **  Function:    void remote()
  331. **
  332. **  Purpose:    disables remote tx/rx status.
  333. **
  334. */
  335.  
  336. void remote(str)
  337.  
  338.  char str[];
  339.     {
  340.     int n;
  341.     extern struct cmdsec;
  342.  
  343.     n = binary(str, cmdsec, SCMDS);
  344.     switch(n)
  345.     {
  346.     case EOF:
  347.         printf("\nInvalid LOCAL option!\n");
  348.         return;
  349.     case 0:
  350.         printf("\nRemote OFF\n");
  351.         _bye_stdout(0);    /* set local tx-state */
  352.         _bye_stdin(0);    /* set remote rx-state */
  353.         break;
  354.     case 1:
  355.         _bye_stdout(1);    /* set local tx-state */
  356.         _bye_stdin(1);    /* set remote rx-state */
  357.         printf("\nRemote ON\n");
  358.         break;
  359.     }
  360.     }
  361.  
  362.  
  363. /*
  364. **  Function:    void show_baud()
  365. **
  366. **  Purpose:    Shows the Baud rate of the caller on line.
  367. **
  368. */
  369.  
  370. void show_baud()
  371.  {
  372.  int baud;
  373.  
  374.  printf("\nModem ");
  375.  if (_bye_getcd())
  376.     printf("ON");
  377.  else
  378.     printf("OFF");
  379.  printf(" line at ");
  380.  
  381.  baud = _bye_baud();
  382.  switch(baud)
  383.     {
  384.     case 0:
  385.     printf("300bps");
  386.     break;
  387.     case 1:
  388.     printf("1200bps");
  389.     break;
  390.     case 2:
  391.     printf("2400bps");
  392.     break;
  393.     default:
  394.     printf("(High Speed!)");
  395.     }
  396.  printf("\n");
  397.  }
  398.  
  399.  
  400. /*
  401. **  Function:    void show_vers()
  402. **
  403. **  Purpose:    Shows the version/revison of BYE-PC running.
  404. **
  405. */
  406.  
  407. void show_vers()
  408.  {
  409.  int ver, rev;
  410.  
  411.  _bye_version(&ver, &rev);
  412.  printf("\nBYE-PC Version %1d.%-2.2d\n", ver, rev);
  413.  }
  414.  
  415.  
  416. /*
  417. **  Function:    void show_nulls()
  418. **
  419. **  Purpose:    Shows the # of nulls sent before each char.
  420. **
  421. */
  422.  
  423. void show_nulls(str)
  424.  
  425.  char str[];
  426.     {
  427.     int n, x;
  428.  
  429.     if (str[0] == NULL)
  430.     {
  431.     x = _bye_getnulls();            /* read # of nulls */
  432.     printf("\nNumber of nulls: %1d\n", x);
  433.     }
  434.     else
  435.     {
  436.     n = atoi(str);
  437.     _bye_setnulls(n);
  438.     x = _bye_getnulls();            /* read # of nulls */
  439.     printf("\nNulls set to: %1d  [%-2.2xh]\n", x, n);
  440.     }
  441.     }
  442.  
  443.  
  444. /*
  445. **  Function:    void show_rxsize()
  446. **
  447. **  Purpose:    Shows the # chars in the rx queue.
  448. **
  449. */
  450.  
  451. void show_rxsize()
  452.  {
  453.  printf("\nRx-Queue size: %d\n", _bye_rxsize());
  454.  }
  455.  
  456.  
  457. /*
  458. **  Function:    void send_tx(string)
  459. **
  460. **  Purpose:    Send a string of text to modem.
  461. **
  462. */
  463.  
  464. void send_tx(s)
  465.  
  466.  char s[];
  467.     {
  468.     int i;
  469.  
  470.     printf("\n[START Data-Tx]\n");
  471.     for (i = 0; i < strlen(s); ++i)
  472.     _bye_putc(s[i]);
  473.     printf("\n[END of Data-Tx]\n");
  474.     }
  475.  
  476.  
  477. /*
  478. **  Function:    void get_rx(n)
  479. **
  480. **  Purpose:    Receive 'n' characters from the modem.
  481. **
  482. */
  483.  
  484. void get_rx(str)
  485.  
  486.  char str[];
  487.     {
  488.     int n, i, err;
  489.     unsigned c;
  490.  
  491.     err = 0;
  492.     printf("\n[START Data-Rx]\n");
  493.     n = atoi(str);
  494.     for (i = 0; i < n; ++i)
  495.     {
  496.     err = 0;
  497.     while(1)
  498.         {
  499.         c = _bye_getc();
  500.         if (c == EOF)
  501.         {
  502.         tdelay(8*1);
  503.         if (err++ > 6)
  504.             {
  505.             printf("[TIME-OUT]\n");
  506.             break;
  507.             }
  508.         }
  509.         else
  510.         {
  511.         printf("%c", (int)c);
  512.         break;
  513.         }
  514.         }
  515.     }
  516.     printf("\n[END of Data-Rx]\n");
  517.     }
  518.  
  519.  
  520. /*
  521. **  Function:    void mdm_flush()
  522. **
  523. **  Purpose:    Flushes rx-queue of all rx-data.
  524. **
  525. */
  526.  
  527. void mdm_flush()
  528.  {
  529.  _bye_rxflush();
  530.  printf("\nRx-Queue Flushed...\n");
  531.  }
  532.  
  533.  
  534. /*
  535. **  Function:    void set_dtr()
  536. **
  537. **  Purpose:    Set the DTR line to the modem.
  538. **
  539. */
  540.  
  541. void set_dtr(str)
  542.  
  543.  char str[];
  544.     {
  545.     int n;
  546.     extern struct cmdsec;
  547.  
  548.     n = binary(str, cmdsec, SCMDS);
  549.     switch(n)
  550.     {
  551.     case EOF:
  552.         printf("\nInvalid DTR option!\n");
  553.         return;
  554.     case 0:
  555.         _bye_dtr(0);
  556.         break;
  557.     case 1:
  558.         _bye_dtr(1);
  559.         break;
  560.     }
  561.     }
  562.  
  563.  
  564. /*
  565. **  Function:    void set_mdmcd()
  566. **
  567. **  Purpose:    Set the CD status from modem.
  568. **
  569. */
  570.  
  571. void set_mdmcd(str)
  572.  
  573.  char str[];
  574.     {
  575.     int n;
  576.     extern struct cmdsec;
  577.  
  578.     n = binary(str, cmdsec, SCMDS);
  579.     switch(n)
  580.     {
  581.     case EOF:
  582.         printf("\nInvalid CD option!\n");
  583.         return;
  584.     case 0:
  585.         _bye_setcd(0);
  586.         printf("\nModem CD status OFF...\n");
  587.         break;
  588.     case 1:
  589.         _bye_setcd(1);
  590.         printf("\nModem CD status ON...\n");
  591.         break;
  592.     }
  593.     }
  594.  
  595.  
  596. /*
  597. **  Function:    void set_mdmbreak()
  598. **
  599. **  Purpose:    Set ^C status flag in BYE.
  600. **
  601. */
  602.  
  603. void set_mdmbreak(str)
  604.  
  605.  char str[];
  606.     {
  607.     int n;
  608.     extern struct cmdsec;
  609.  
  610.     n = binary(str, cmdsec, SCMDS);
  611.     switch(n)
  612.     {
  613.     case EOF:
  614.         printf("\nInvalid BREAK option!\n");
  615.         return;
  616.     case 0:
  617.         _bye_setbreak(CTRL_NOBRK);
  618.         printf("\nRemote BREAK status OFF...\n");
  619.         break;
  620.     case 1:
  621.         _bye_setbreak(CTRL_BRK);
  622.         printf("\nRemote BREAK status ON...\n");
  623.         break;
  624.     }
  625.     }
  626.  
  627.  
  628. /*
  629. **  Function:    void set_mdmpause()
  630. **
  631. **  Purpose:    Set ^S timeout status flag in BYE.
  632. **
  633. */
  634.  
  635. void set_mdmpause(str)
  636.  
  637.  char str[];
  638.     {
  639.     int n;
  640.     extern struct cmdsec;
  641.  
  642.     n = binary(str, cmdsec, SCMDS);
  643.     switch(n)
  644.     {
  645.     case EOF:
  646.         printf("\nInvalid PAUSE option!\n");
  647.         return;
  648.     case 0:
  649.         _bye_setbreak(CTRL_NOTOUT);
  650.         printf("\nRemote PAUSE timeout OFF...\n");
  651.         break;
  652.     case 1:
  653.         _bye_setbreak(CTRL_TOUT);
  654.         printf("\nRemote PAUSE timeout ON...\n");
  655.         break;
  656.     }
  657.     }
  658.  
  659.  
  660. /*
  661. **  Function:    void set_mdmtrap()
  662. **
  663. **  Purpose:    Sets pass/ignore all ^C and ^S status flag in BYE.
  664. **
  665. */
  666.  
  667. void set_mdmtrap(str)
  668.  
  669.  char str[];
  670.     {
  671.     int n;
  672.     extern struct cmdsec;
  673.  
  674.     n = binary(str, cmdsec, SCMDS);
  675.     switch(n)
  676.     {
  677.     case EOF:
  678.         printf("\nInvalid TRAP option!\n");
  679.         return;
  680.     case 0:
  681.         _bye_setbreak(CTRL_NOTRAP);
  682.         printf("\nRemote TRAP ^C & ^S status OFF...\n");
  683.         break;
  684.     case 1:
  685.         _bye_setbreak(CTRL_TRAP);
  686.         printf("\nRemote TRAP ^C & ^S status ON...\n");
  687.         break;
  688.     }
  689.     }
  690.  
  691.  
  692.  
  693. /*
  694. **  Function:    void set_status(str)
  695. **
  696. **  Purpose:    Sets/shows caller status level in BYE.
  697. **
  698. */
  699.  
  700. void set_status(str)
  701.  
  702.  char str[];
  703.     {
  704.     int n;
  705.  
  706.     if (str[0] == NULL)
  707.     printf("\nCaller Status Level: %-4.4xh\n", _bye_getcsw());
  708.     else
  709.     {
  710.     n = atoi(str);
  711.     if (n <= 0 || n > 255)
  712.         n = 0;
  713.     _bye_setcsw(n);
  714.     printf("\nCaller Status Set to: %-4.4xh\n", _bye_getcsw());
  715.     }
  716.     }
  717.  
  718.  
  719. /*
  720. **  Function:    void set_timer()
  721. **
  722. **  Purpose:    Set ^S timeout status flag in BYE.
  723. **
  724. */
  725.  
  726. void set_timer(str)
  727.  
  728.  char str[];
  729.     {
  730.     int n, x;
  731.  
  732.     if (str[0] == NULL)
  733.     {
  734.     x = _bye_gettimer();
  735.     printf("\nMinutes on system: %d\n", x);
  736.     }
  737.     else
  738.     {
  739.     n = atoi(str);
  740.     if (n < 0)
  741.         n = 0;
  742.     if (n > 255)
  743.         n = 255;
  744.     _bye_settimeon(n);
  745.     printf("\nTime on system set to: %d minutes\n", n);
  746.     }
  747.     }
  748.  
  749.  
  750. /*
  751. **  Function:    void set_name(str)
  752. **
  753. **  Purpose:    Sets/shows caller status level in BYE.
  754. **
  755. */
  756.  
  757. void set_name(str)
  758.  
  759.  char str[];
  760.     {
  761.     char name[65];
  762.     int n;
  763.  
  764.     _bye_getname(name);
  765.     if (str[0] == NULL)
  766.     printf("\nCaller on line: %s\n", name);
  767.     else
  768.     {
  769.     strncpy(name, str, 63);
  770.     _bye_setname(name);
  771.     _bye_getname(name);
  772.     printf("\nCaller Name Set to: %s\n", name);
  773.     }
  774.     }
  775.  
  776.  
  777.