next up previous contents index
Next: MIDAS Help files Up: Examples Using the Communication Previous: Examples Using the Communication

An interactive Midas client (written in C)

The following module myclient is an interactive Midas client  which connects/disconnects to/from a Midas server and sends user provided commands to the Midas server.

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.COPYRIGHT    (c)  1994   European Southern Observatory
.IDENT        myclient.c
.LANGUAGE     C
.AUTHOR       K. Banse   ESO - Garching
.KEYWORDS     Midas client, communication
.PURPOSE      Communicate with a Midas server (background Midas) which is
              running on the same or different host
.VERSION      1.00  941020:   First version
---------------------------------------------------------------------*/


main()
 
{
int        id, stat, n;
int        noelm, retstat[2], kk, jj, iwa[3], ibuf[80];
int        felem, maxvals, actvals, unit, nullo, kstat;
register int nr;
 
float      rwa[3], rbuf[80];

double     dwa[3], dbuf[80];

char       metho, munit[4], kline[120], cbuf[80], remo[64];



id = -1;

input_loop:
if (id == -1)
   {
   printf("Options are:\n");
   printf("os XY = open socket communication with Midas unit XY\n");
   printf("of XY = open ASCII file based comm. with Midas unit XY\n");
   printf("is XY = start Midas unit XY + open socket communication\n");
   printf("if XY = start Midas unit XY + open ASCII file based comm.\n");
   printf("h = display help text, q = quit the test program\n");
   }

printf("option > ");
gets(kline);


while (kline[0] == ' ')
   strcpy(kline,&kline[1]);

if (kline[0] == '\0')			/* empty line */
   goto input_loop;

else if (kline[0] == 'q') 
   return(0);

else if (kline[0] == 'h')
   {
   printf("Options are:\n");
   printf("h = display help text, q = quit the test program\n");
   printf("c `secs' = send Midas command + wait for `secs'\n");
   printf("w = wait for last command, s = get status\n");
   printf
("x = close client connection, xx = as `x' but also terminate Midas server\n");
   }

else if (kline[0] == 'i')
   {
   munit[0] = kline[3];
   munit[1] = kline[4];

   if (kline[1] == 's')                 /* sockets */
      {
      metho = 'X';
      stat = XCXINI(munit,"",10,&id);   /* wait max. 10 seconds */
      }
   else                                 /* files */
      {
      metho = 'Z';
      stat = XCZINI(munit,"QX","",10,&id);
      }

   printf("XC%cINI, status = %d\n",metho,stat);
   }

else if (kline[0] == 'o')		/* test XCXOPN or XCZOPN */
   {
   munit[0] = kline[3];
   munit[1] = kline[4];
   if (kline[1] == 's')			/* sockets */
      {
      metho = 'X';
      stat = XCXOPN(munit,"",&id);
      }
   else					/* files */
      {
      metho = 'Z';
      stat = XCZOPN(munit,"QX","",&id);
      }

   printf("XC%cOPN, status = %d\n",metho,stat);
   }

else if (kline[0] == 'x')		/* test XCXCLO or XCXSTP */
   {
   if (kline[1] == 'x')                 /* also shut down server */
      {
      stat = XCXSTP(id);
      printf("XCXSTP, status = %d\n",stat);
      }
   else
      {
      stat = XCXCLO(id);
      printf("XCXCLO, status = %d\n",stat);
      }

   id = -1;
   }

else if (kline[0] == 'c')		/* test XCCSND */
   {
   n = CGN_CNVT(&kline[2],1,1,iwa,rwa,dwa);	/* Midas conv. routine */
   if (n<1) iwa[0] = -1;			/* that means No Wait */

   printf("Enter Midas command: ");
   gets(kline);
   stat = XCCSND(id,kline,iwa[0],retstat);

   if (stat != 0)
      printf("XCCSND, status = %d\n",stat);
   else
      printf("background Midas returned status = %d\n",retstat[0]);
   }

else if (kline[0] == 'w')		/* test XCCWAI */
   {
   stat = XCCWAI(id,retstat);

   if (stat != 0)
      printf("XCCWAI, status = %d\n",stat);
   else
      printf("background Midas returned status = %d\n",retstat[0]);
   }

else if (kline[0] == 's')		/* test XCXSTA */
   {
   stat = XCXSTA(id);

   if (stat == 0)
      printf("background Midas %c%c idle\n",munit[0],munit[1]);
   else if (stat == 1)
      printf("background Midas %c%c busy\n",munit[0],munit[1]);
   else
      printf("XCXSTA, status = %d\n",stat);
   }

else
   printf("unknown command...\n");

goto input_loop;		/* get next input */

}

=1 =11 =1992



Send comments to web@eso.org
Last update: 1998-10-23