/*
* For the specified robot, walk through the remainder of
* argument list and have mrd_map_element(3mrd) convert
* each address to a relative element address and type.
*
* mrd_map_element robot address [ address... ]
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_map_element.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[])
{
char *robot ; /* Robot for command */
int status ; /* status from mrd_startup(3mrd) */
int address ; /* Input argument */
int type ; /* element type */
int i ; /* index counter */
robot_info_t robot_info ; /* Set by mrd_startup(3mrd) */
char result[MRD_NAME_SIZE+1] ; /* relative address */
char log_info[MRD_MAX_LOG_STRING+1] ; /* error text */
/*
* Two required arguments, many optional ones.
*/
if( argc < 3 ) {
printf("usage: %s robot address [ address... ]\n", argv[0]) ;
exit(1) ;
}
else
robot = argv[1] ;
/*
* Open the robot. Must set channel to BAD_CHANNEL so
* it will really open the robot.
*/
robot_info.channel = BAD_CHANNEL ;
status = mrd_startup(robot, &robot_info, log_info) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Can't open robot %s: %s: %s.\n", robot,
mrd_strstatus(status),
log_info[0] ? log_info : "none") ;
exit(1) ;
}
/*
* We don't need to keep the robot for the remainder of
* the example.
*/
(void)mrd_shutdown(&robot_info) ;
/*
* For each address in the list, call mrd_map_element(3mrd).
*/
for(i = 2; i < argc; i++) {
address = atoi(argv[i]) ;
type = mrd_map_element(&robot_info, address, result) ;
if( type == 0 )
printf("Can't map %d on robot %s.\n", address, robot) ;
else
printf("Element %d -> %s %s\n", address,
mrd_strelement(type), result) ;
}
return 0 ;
}