Skip to content

Loading…

simulation proxy extra functionality #2

Merged
4 commits merged into from

2 participants

@jennyhasahat

Hi,

I needed to be able to read the simulated time from the simulation and nothing seemed to be able to do that, so I added some functionality to SimulationProxy::GetProperty so that you can retrieve the simulation time.
It might be useful to others, so I'm submitting the new stuff for inclusion in the next release.

Jenny

Jenny and others added some commits
Jenny added ability to get simulation time property from the simulation model.
Still needs testing.
97a2719
Jon Modified simulationProxy GetProperty so you can also get the simulation
time that's displayed on the GUI. Could be handy?
6195976
Jon Included code to check that the supplied data structure for the
simulation time is big enough to store a uint64_t.
91a9af3
Jenny Merge commit 'upstream/master'
Fixed conflicts between my stuff and old stuff.
Conflicts:
	libstageplugin/p_simulation.cc
2dac511
@rtv
Owner

I pulled this today and tweaked it just a bit before committing to my master. I changed the name of the property from "simtime" or "sim_time" to simply "time", and simplified the code a little. It might have been a better strategy to modify Player's sim interface to include this functionality, but that's a little more complex. This will work for anyone who really needs it.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2010
  1. added ability to get simulation time property from the simulation model.

    Jenny committed
    Still needs testing.
  2. Modified simulationProxy GetProperty so you can also get the simulation

    Jon committed
    time that's displayed on the GUI. Could be handy?
Commits on Sep 29, 2010
  1. Included code to check that the supplied data structure for the

    Jon committed
    simulation time is big enough to store a uint64_t.
  2. Merge commit 'upstream/master'

    Jenny committed
    Fixed conflicts between my stuff and old stuff.
    Conflicts:
    	libstageplugin/p_simulation.cc
Showing with 92 additions and 43 deletions.
  1. +92 −43 libstageplugin/p_simulation.cc
View
135 libstageplugin/p_simulation.cc
@@ -378,61 +378,110 @@ int InterfaceSimulation::ProcessMessage(QueuePointer &resp_queue,
(player_simulation_property_req_t*)data;
- // check they want to set the colour. If they don't
- // then that's too bad for them.
+
+ // check they want to set the colour.
//strncmp returns 0 if the strings match
- if( strncmp(req->prop, "color", (size_t)req->prop_count) &&
+ if( !(strncmp(req->prop, "color", (size_t)req->prop_count) &&
strncmp(req->prop, "_mp_color", (size_t)req->prop_count) &&
- strncmp(req->prop, "colour", (size_t)req->prop_count) )
- {
- PRINT_WARN1("Property \"%s\" is not accessible. Options are \"color\", \"_mp_color\", or \"colour\". These all change the colour.", req->prop);
- return(-1);
- }
-
- // check the value given is an array of four floats
- if(req->value_count != sizeof(float)*4)
+ strncmp(req->prop, "colour", (size_t)req->prop_count)))
{
- PRINT_WARN("value given by GetProperty must be an array of 4 floats\n");
- return(-1);
+ // check the value given is an array of four floats
+ if(req->value_count != sizeof(float)*4)
+ {
+ PRINT_WARN("Colour requires an array of 4 floats to store\n");
+ return(-1);
+ }
+
+ // look up the named model
+ Model* mod = StgDriver::world->GetModel( req->name );
+
+ if( mod )
+ {
+ Color newColour = mod->GetColor(); //line 2279 of stage.hh
+ // make an array to hold it as floats
+ float col[4];
+ col[0] = newColour.r;
+ col[1] = newColour.g;
+ col[2] = newColour.b;
+ col[3] = newColour.a;
+
+ //copy array of floats into memory provided in the req structure
+ memcpy(req->value, col, req->value_count);
+
+ //make a new structure and copy req into it
+
+ player_simulation_property_req_t reply;
+ memcpy( &reply, req, sizeof(reply));
+
+ //put col array into reply
+ memcpy(reply.value, col, reply.value_count);
+
+
+ this->driver->Publish( this->addr, resp_queue,
+ PLAYER_MSGTYPE_RESP_ACK,
+ PLAYER_SIMULATION_REQ_GET_PROPERTY,
+ (void*)&reply, sizeof(reply), NULL );
+
+ return(0);
+ }
+ else
+ {
+ PRINT_WARN1( "GET_PROPERTY request: simulation model \"%s\" not found", req->name );
+ return(-1);
+ }
}
-
- // look up the named model
- Model* mod = StgDriver::world->GetModel( req->name );
-
- if( mod )
+ else if( !( strncmp(req->prop, "simtime", (size_t)req->prop_count) && strncmp(req->prop, "sim_time", (size_t)req->prop_count)))
{
- Color newColour = mod->GetColor(); //line 2279 of stage.hh
- // make an array to hold it as floats
- float col[4];
- col[0] = newColour.r;
- col[1] = newColour.g;
- col[2] = newColour.b;
- col[3] = newColour.a;
-
- //copy array of floats into memory provided in the req structure
- memcpy(req->value, col, req->value_count);
-
- //make a new structure and copy req into it
-
- player_simulation_property_req_t reply;
- memcpy( &reply, req, sizeof(reply));
+ // check the value given is a uint64_t
+ if(req->value_count != sizeof(uint64_t))
+ {
+ PRINT_WARN("Simulation time requires a uint64_t to store\n");
+ return(-1);
+ }
+
+ //return simulation time
+ // look up the named model
+ Model* mod = StgDriver::world->GetModel( req->name );
+
+ if( mod )
+ {
+ World *stageworld = mod->GetWorld();
+
+ //stg_usec_t is a typedef for uint64_t
+ stg_usec_t time = stageworld->SimTimeNow();
+
+ //copy array of floats into memory provided in the req structure
+ memcpy(req->value, &time, req->value_count);
+
+ //make a new structure and copy req into it
+ player_simulation_property_req_t reply;
+ memcpy( &reply, req, sizeof(reply));
+
+ //put col array into reply
+ memcpy(reply.value, &time, reply.value_count);
+
+
+ this->driver->Publish( this->addr, resp_queue,
+ PLAYER_MSGTYPE_RESP_ACK,
+ PLAYER_SIMULATION_REQ_GET_PROPERTY,
+ (void*)&reply, sizeof(reply), NULL );
+
+ return(0);
+ }
+ else
+ {
+ PRINT_WARN1( "GET_PROPERTY request: simulation model \"%s\" not found", req->name );
+ return(-1);
+ }
- //put col array into reply
- memcpy(reply.value, col, reply.value_count);
-
-
- this->driver->Publish( this->addr, resp_queue,
- PLAYER_MSGTYPE_RESP_ACK,
- PLAYER_SIMULATION_REQ_GET_PROPERTY,
- (void*)&reply, sizeof(reply), NULL );
- return(0);
}
else
{
- PRINT_WARN1( "GET_PROPERTY request: simulation model \"%s\" not found", req->name );
+ PRINT_WARN1("Property \"%s\" is not accessible. Options are \"color\", \"_mp_color\", or \"colour\" for changing colour. \"simtime\" or \"sim_time\" for getting the simulation time.", req->prop);
return(-1);
}
+
}
else
Something went wrong with that request. Please try again.