| 1 |
/* @(#)osrtest.c 19.1 (ES0-DMD) 02/25/03 13:56:14 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public |
| 16 |
License along with this program; if not, write to the Free |
| 17 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/*+++++++++++ |
| 30 |
.TYPE Program |
| 31 |
.LANGUAGE C |
| 32 |
.IDENTIFICATION TESTosr |
| 33 |
.VERSION 1.0 06-Oct-1987: Creation |
| 34 |
.AUTHOR Francois Ochsenbein [ESO-IPG] |
| 35 |
.KEYWORDS Test of osr routines |
| 36 |
.ENVIRONMENT |
| 37 |
.COMMENTS |
| 38 |
|
| 39 |
-------------------------------------------------------------------------*/ |
| 40 |
|
| 41 |
#include <osremote.h> |
| 42 |
#include <atype.h> |
| 43 |
#include <macrogen.h> |
| 44 |
|
| 45 |
#ifndef NULL |
| 46 |
#define NULL NULL_PTR(char) |
| 47 |
#endif |
| 48 |
|
| 49 |
extern char *oshenv(); |
| 50 |
|
| 51 |
static char msg[132]; |
| 52 |
static char buf[1000]; |
| 53 |
static struct remstat info; |
| 54 |
static int f = 0; |
| 55 |
static int timeout = 1; |
| 56 |
|
| 57 |
main() |
| 58 |
{ int s, i; |
| 59 |
char *p, *u; |
| 60 |
|
| 61 |
puts("==== Testing OSR (Remote Access) routines ===="); |
| 62 |
puts(" Type ? for Help"); |
| 63 |
|
| 64 |
while(1) |
| 65 |
{ printf("Your choice: "); if (!gets(msg)) break; |
| 66 |
s = 0; |
| 67 |
switch(msg[0]) |
| 68 |
{ default: puts("*** Uknown Command!"); |
| 69 |
case 'H': case '?': help(); continue; |
| 70 |
|
| 71 |
case 'C': case 'c': /* Close */ |
| 72 |
s = osrclose(f); break; |
| 73 |
|
| 74 |
case 'O': case 'o': /* Open */ |
| 75 |
if (msg[1] != ' ') { puts("Specify Destination!"); break;} |
| 76 |
p = msg + 2, u = NULL; |
| 77 |
if (isalpha(*p)) |
| 78 |
{ p = oshenv(p, "PSI$DTE_TABLE"); |
| 79 |
if (p) oscopuc(buf, p, 100, EOS); |
| 80 |
p = buf; |
| 81 |
i = strlen(msg); msg[i++] = '_'; |
| 82 |
msg[i++] = 'U'; msg[i++] = EOS; |
| 83 |
u = oshenv(msg+2, "PSI$DTE_TABLE"); |
| 84 |
if (u) oscopuc(buf+100, u, 100, EOS); |
| 85 |
u = buf + 100; |
| 86 |
} |
| 87 |
s = osropen(p, NULL, u, NULL); |
| 88 |
if (s >= 0) f = s; |
| 89 |
break; |
| 90 |
|
| 91 |
case '@': /* Select File Number */ |
| 92 |
f = atoi(&msg[1]); |
| 93 |
printf("Switching to Circuit %d\n", f); |
| 94 |
break; |
| 95 |
|
| 96 |
case 'T': case 't': /* Modify timeout */ |
| 97 |
timeout = atoi(&msg[1]); |
| 98 |
printf("Timeout is now %ds.\n", timeout); |
| 99 |
break; |
| 100 |
|
| 101 |
case 'I': case 'i': /* Get status */ |
| 102 |
s = osrinfo(f, &info); |
| 103 |
printf("Circuit %d: dte=%s, net=%s, device=%s, unit=%d\n", |
| 104 |
f, info.dte, info.net, info.device, info.unit); |
| 105 |
break; |
| 106 |
continue; |
| 107 |
|
| 108 |
case 'G': case 'g': /* Gets n bytes */ |
| 109 |
s = osrgets(f, buf, atoi(msg+1), timeout); |
| 110 |
if (s >= 0) |
| 111 |
{ printf("Got: "); |
| 112 |
for (p = buf; *p; p++) |
| 113 |
{ if (iscntrl(*p)) printf("^%c", *p+'@'); |
| 114 |
else printf("%c",*p); |
| 115 |
} |
| 116 |
puts(""); |
| 117 |
} |
| 118 |
break; |
| 119 |
|
| 120 |
case 'P': case 'p': /* Write text */ |
| 121 |
if (msg[1] == EOS) { printf("Text: ") ; gets(&msg[2]);} |
| 122 |
s = osrputs(f, &msg[2]); |
| 123 |
break; |
| 124 |
} |
| 125 |
printf("Status is %d", s); |
| 126 |
if (s < 0) printf(": %s",osmsg()); |
| 127 |
puts(""); |
| 128 |
} |
| 129 |
osrend(); |
| 130 |
ospexit(0); |
| 131 |
} |
| 132 |
|
| 133 |
help() |
| 134 |
{ |
| 135 |
printf("Current Circuit is %d, with timeout of %ds.\n", f, timeout); |
| 136 |
puts("Possibilities are: ? Help"); |
| 137 |
puts(" @ f select Circuit f"); |
| 138 |
puts(" C Close Current Circuit"); |
| 139 |
puts(" G n Gets n bytes"); |
| 140 |
puts(" I Display status of Current Circuit"); |
| 141 |
puts(" O dte Open Circuit"); |
| 142 |
puts(" P text Puts text to Remote"); |
| 143 |
puts(" T seconds Modify Time-out"); |
| 144 |
return(0); |
| 145 |
} |