home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff247.lzh / RemoteLogin / spmon.c < prev   
C/C++ Source or Header  |  1989-09-15  |  2KB  |  107 lines

  1.  
  2. /* Placed in the public domain by the author David Kinzer */
  3.  
  4. #include "exec/types.h"
  5. #include "exec/nodes.h"
  6. #include "exec/lists.h"
  7. #include "exec/ports.h"
  8. #include "exec/libraries.h"
  9. #include "exec/devices.h"
  10. #include "exec/io.h"
  11. #include "devices/serial.h"
  12. #include "hardware/cia.h"
  13.  
  14. main(ac,av)
  15. int ac;
  16. char *av[];
  17.  
  18. {
  19.  
  20. unsigned char status = CIAF_COMCD;
  21. unsigned char newstat;
  22.  
  23.    if (ac < 2) return;
  24.  
  25.    for (;;) {
  26.  
  27.       /* wait until the carrier detect bit makes a high to low */
  28.       /* transition indicating new carrier detect.  */
  29.  
  30.       newstat = ciab.ciapra & CIAF_COMCD;
  31.       if (newstat != status) {
  32.          status = newstat;
  33.          if (status) {
  34.             /* ignore this, phone just hung up */
  35.          } else {
  36.             /* the carrier detect just came up */
  37.             /* check serial device to see if anyone else is using */
  38.             /* this.  If so, we ignore, else, we fire up the task */
  39.  
  40.             if (openamigaserial()) {
  41.                /* it errored, someone else is using */
  42.             } else {
  43.                /* ours, close serial device, and start routine */
  44.                closeamigaserial();
  45.                Execute(av[1],0L,0L);
  46.             }
  47.  
  48.          }
  49.       }
  50.  
  51.       /* Delay a while, ain't multitasking easy? */
  52.       Delay(150L);
  53.    }
  54. }
  55.  
  56.  
  57. /* Standard Amiga Serial Port Routines */
  58.  
  59. static struct Port *mySerPort;
  60. struct IOExtSer *mySerReq;
  61.  
  62. int openamigaserial()
  63. {
  64. int gotport = 0;
  65. int gotextio = 0;
  66. long error;
  67. long OpenDevice();
  68. VOID *CreateExtIO();
  69. struct Port *CreatePort();
  70.  
  71.  
  72.    mySerPort = CreatePort("mySerial",0L);
  73.    if (mySerPort == NULL) 
  74.       goto errorexit;
  75.    gotport = 1;
  76.  
  77.    mySerReq = (struct IOExtSer *)CreateExtIO(mySerPort,
  78.               (long)sizeof(struct IOExtSer));
  79.    if (mySerReq == NULL) 
  80.       goto errorexit;
  81.    gotextio = 1;
  82.  
  83.    error = OpenDevice("serial.device",0L,mySerReq,0L);
  84.    if (error) 
  85.       goto errorexit;
  86.  
  87.    return 0;  /* return success */
  88.  
  89.  
  90. errorexit:
  91.    if (gotextio) 
  92.       DeleteExtIO(mySerReq,sizeof(struct IOExtSer));
  93.    if (gotport)
  94.       DeletePort(mySerPort);
  95.  
  96.    return 1;  /* return error */
  97.  
  98. }
  99.  
  100. closeamigaserial()
  101. {
  102.    CloseDevice(mySerReq);
  103.    DeleteExtIO(mySerReq,sizeof(struct IOExtSer));
  104.    DeletePort(mySerPort);
  105. }
  106.  
  107.