Update of /cvsroot/playerstage/code/player/examples/libplayerc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21719/examples/libplayerc
Modified Files:
service_discovery.c
Log Message:
added multiclient usage
Index: service_discovery.c
===================================================================
RCS file:
/cvsroot/playerstage/code/player/examples/libplayerc/service_discovery.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** service_discovery.c 9 Oct 2007 21:15:04 -0000 1.4
--- service_discovery.c 19 Oct 2007 17:54:14 -0000 1.5
***************
*** 9,22 ****
#include <libplayerc/playerc.h>
! #define MAX_POSITION_DEVS 16
void
browse_cb(player_sd_t* sd, player_sd_dev_t* dev)
{
! printf("found new device: %s:%u:%s:%u\n",
! dev->hostname,
! dev->robot,
! interf_to_str(dev->interf),
! dev->index);
}
--- 9,44 ----
#include <libplayerc/playerc.h>
! #define MAX_DEVS 16
!
! playerc_mclient_t* mclient;
! playerc_client_t* clients[MAX_DEVS];
! playerc_laser_t* lasers[MAX_DEVS];
! int num_laserdevs;
void
browse_cb(player_sd_t* sd, player_sd_dev_t* dev)
{
! if(dev->interf == PLAYER_LASER_CODE)
! {
! clients[num_laserdevs] = playerc_client_create(mclient,
! dev->hostname,
! dev->robot);
! if(0 != playerc_client_connect(clients[num_laserdevs]))
! exit(-1);
!
! // Create and subscribe to a laser device.
! lasers[num_laserdevs] = playerc_laser_create(clients[num_laserdevs],
! dev->index);
! if(playerc_laser_subscribe(lasers[num_laserdevs], PLAYER_OPEN_MODE))
! exit(-1);
!
! num_laserdevs++;
! printf("subscribed to: %s:%u:%s:%u\n",
! dev->hostname,
! dev->robot,
! interf_to_str(dev->interf),
! dev->index);
! printf("Now receiving %d lasers\n", num_laserdevs);
! }
}
***************
*** 25,36 ****
{
int i;
- playerc_client_t *client=NULL;
- playerc_position2d_t *position2d;
// A service discovery object
player_sd_t* sd;
! // An array to store matching devices
! player_sd_dev_t positiondevs[MAX_POSITION_DEVS];
! int num_positiondevs;
// Initialize service discovery
--- 47,56 ----
{
int i;
// A service discovery object
player_sd_t* sd;
!
! // Initialize multiclient
! mclient = playerc_mclient_create();
// Initialize service discovery
***************
*** 44,95 ****
}
! while((num_positiondevs = player_sd_find_devices(sd, positiondevs,
! MAX_POSITION_DEVS,
! NULL, NULL, -1,
! PLAYER_POSITION2D_CODE,
! -1)) < 1)
! {
! // Update name service
! puts("player_sd_update");
! player_sd_update(sd,0.1);
! }
!
! printf("found %d position2d devices\n", num_positiondevs);
!
! // Subscribe to the first one
! client = playerc_client_create(NULL,
! positiondevs[0].hostname,
! positiondevs[0].robot);
! if(0 != playerc_client_connect(client))
! exit(-1);
!
! // Create and subscribe to a position2d device.
! position2d = playerc_position2d_create(client, positiondevs[0].index);
! if(playerc_position2d_subscribe(position2d, PLAYER_OPEN_MODE))
! exit(-1);
!
! // Make the robot move
! if(0 != playerc_position2d_set_cmd_vel(position2d, 0.35, 0, DTOR(40.0), 1))
! return -1;
!
! for(i = 0; i < 200; i++)
{
// Wait for new data from server
! playerc_client_read(client);
// Update name service
player_sd_update(sd,0.0);
// Print current robot pose
printf("position2d : %f %f %f\n",
position2d->px, position2d->py, position2d->pa);
}
// Shutdown
! playerc_position2d_unsubscribe(position2d);
! playerc_position2d_destroy(position2d);
! playerc_client_disconnect(client);
! playerc_client_destroy(client);
return(0);
--- 64,92 ----
}
! for(;;)
{
// Wait for new data from server
! playerc_mclient_read(mclient,100);
// Update name service
player_sd_update(sd,0.0);
+ /*
// Print current robot pose
printf("position2d : %f %f %f\n",
position2d->px, position2d->py, position2d->pa);
+ */
}
// Shutdown
! for(i=0;i<num_laserdevs;i++)
! {
! playerc_laser_unsubscribe(lasers[i]);
! playerc_laser_destroy(lasers[i]);
! playerc_client_disconnect(clients[i]);
! playerc_client_destroy(clients[i]);
! }
+ playerc_mclient_destroy(mclient);
return(0);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit