/*
* Example to do mrd_show(3mrd) on the first element of each type.
* The usage of this command is:
*
* mrd_show robot
*
* This examples show keeping the robot open across multiple
* calls to mrd_show(3mrd). In one happens to close it, the
* channel will be reset the BAD_CHANNEL and the next one will
* open it again. On some robot subsystems, opening the robot
* is fairly time consuming and if multiple "shows" are needed
* the time savings can be signficiant.
*
* The subsystems where this is most noticable are HSJ and HSD
* connected robots, which aren't supported on Digital UNIX.
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_show.c 1.2 3/5/97" ;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <mrd_common.h>
#include <mrd_message.h>
main(int argc, char *argv[])
{
robot_info_t robot_info ; /* keep the robot open */
element_info_t element ; /* place to put element data */
int el ; /* type index */
int status ; /* status from mrd_show(3mrd) */
char *robot ; /* Robot to use */
char *content ; /* pointer to a content string */
char log_info[MRD_MAX_LOG_STRING+1] ; /* error text */
/*
* Only one argument is used; the robot name.
*/
if( argc == 1 ) {
printf("usage: %s robot\n", argv[0]) ;
exit(1) ;
}
else
robot = argv[1] ;
/*
* The channel number must be set to BAD_CHANNEL before
* mrd_startup or mrd_show is called, otherwise it will
* assume the robot is already open and not try to open
* it again.
*/
robot_info.channel = BAD_CHANNEL ;
/*
* In this case we want to open the robot once, and then
* call mrd_show(3mrd) in turn for each type of element.
* If there is an error and it happens to close the robot,
* the channel will be reset and the robot opened again on
* the next call.
*/
status = mrd_startup(robot, &robot_info, log_info) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Startup failed: %s (%s).\n", mrd_strstatus(status),
log_info[0] ? log_info : "none") ;
exit(1) ;
}
/*
* We rely on the fact that the element numbers are
* are 1 through 4.
*/
for(el = 1; el <= 4; el++) {
log_info[0] = '\0' ;
status = mrd_show(robot, &robot_info, el, "0", 1,
&element, log_info) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Can't show %s 0: %s (%s)\n",
mrd_strelement(el), mrd_strstatus(status),
log_info[0] ? log_info : "none") ;
continue ;
}
if( element.status != MRD_STATUS_SUCCESS ) {
printf("Can't show %s 0: %s\n", mrd_strelement(el),
mrd_strstatus(element.status)) ;
continue ;
}
if( element.name[0] )
content = element.name ;
else if( element.state & ELEMENT_FULL )
content = "Full" ;
else if( element.state & ELEMENT_EXCEPT )
content = "Exception" ;
else
content = "Empty" ;
printf("%-9s 0: %s\n", mrd_strelement(el), content) ;
}
/*
* Close it when done.
*/
(void)mrd_shutdown(&robot_info) ;
return 0 ;
}