#include #include // needed for gethostname #include // needed for string function strchr #include "MyroC.h" int main () { printf ("program to set the name of the Scribbler 2 robot\n"); printf ("to match the controlling MathLAN workstation name\n\n"); char onOff[2]; printf ("print Bluetooth communications ('y' or 'n')? "); scanf ("%s", onOff); rSetBluetoothEcho (onOff[0]); int string_size = 20; char hostname [string_size]; char * newname; const char * hostnamecheck; gethostname(hostname, string_size); // if compound name (e.g., perlis.cs.grinnell.edu) // locate first part (e.g., perlis) and use that as name char * separatorPos = strchr (hostname, '.'); if (separatorPos) *separatorPos = 0; printf ("the name of this computer is %s\n", hostname); newname = hostname; printf ("setting the robot name to %s\n", newname); rConnect("/dev/rfcomm0"); /* connect to robot */ //rConnect ("0950"); /* connect to markov */ //rConnect ("00:1E:19:01:0E:AF"); /* connect to naur */ //char connection_name [40] = "B4:D8:A9:00:09:1B"; //rConnect (connection_name); rSetName(newname); hostnamecheck = rGetName(); rDisconnect(); printf ("robot name now set to %s\n", hostnamecheck); }