Revision: 8022
http://playerstage.svn.sourceforge.net/playerstage/?rev=8022&view=rev
Author: gbiggs
Date: 2009-07-15 03:59:24 +0000 (Wed, 15 Jul 2009)
Log Message:
-----------
Added boolean property type. Added new config option for timestamps to
hokuyo_aist
Modified Paths:
--------------
code/player/trunk/client_libs/libplayerc/device.c
code/player/trunk/client_libs/libplayerc/playerc.h
code/player/trunk/client_libs/libplayerc++/clientproxy.cc
code/player/trunk/client_libs/libplayerc++/clientproxy.h
code/player/trunk/libplayercore/driver.cc
code/player/trunk/libplayercore/property.cpp
code/player/trunk/libplayercore/property.h
code/player/trunk/libplayerinterface/functiontable.c
code/player/trunk/libplayerinterface/player.h
code/player/trunk/server/drivers/ranger/hokuyo_aist.cc
code/player/trunk/utils/playerprop/playerprop.cpp
Modified: code/player/trunk/client_libs/libplayerc/device.c
===================================================================
--- code/player/trunk/client_libs/libplayerc/device.c 2009-07-14 23:32:58 UTC
(rev 8021)
+++ code/player/trunk/client_libs/libplayerc/device.c 2009-07-15 03:59:24 UTC
(rev 8022)
@@ -115,6 +115,40 @@
&capreq, NULL) >= 0 ? 1 : 0;
}
+int playerc_device_get_boolprop(playerc_device_t *device, char *property, BOOL
*value)
+{
+ int result = 0;
+
+ player_boolprop_req_t req, *resp;
+ req.key = property;
+ req.key_count = strlen (property) + 1;
+ req.value = FALSE;
+
+ if((result = playerc_client_request(device->client, device,
+ PLAYER_GET_BOOLPROP_REQ, &req, (void**)&resp)) < 0)
+ return result;
+
+ *value = resp->value;
+ player_boolprop_req_t_free(resp);
+ return 0;
+}
+
+int playerc_device_set_boolprop(playerc_device_t *device, char *property, BOOL
value)
+{
+ int result = 0;
+
+ player_boolprop_req_t req;
+ req.key = property;
+ req.key_count = strlen (property) + 1;
+ req.value = value;
+
+ if((result = playerc_client_request(device->client, device,
+ PLAYER_SET_BOOLPROP_REQ, &req, NULL)) < 0)
+ return result;
+
+ return 0;
+}
+
int playerc_device_get_intprop(playerc_device_t *device, char *property,
int32_t *value)
{
int result = 0;
Modified: code/player/trunk/client_libs/libplayerc/playerc.h
===================================================================
--- code/player/trunk/client_libs/libplayerc/playerc.h 2009-07-14 23:32:58 UTC
(rev 8021)
+++ code/player/trunk/client_libs/libplayerc/playerc.h 2009-07-15 03:59:24 UTC
(rev 8022)
@@ -880,6 +880,12 @@
/** @brief Request capabilities of device */
PLAYERC_EXPORT int playerc_device_hascapability(playerc_device_t *device,
uint32_t type, uint32_t subtype);
+/** @brief Request a boolean property */
+PLAYERC_EXPORT int playerc_device_get_boolprop(playerc_device_t *device, char
*property, BOOL *value);
+
+/** @brief Set a boolean property */
+PLAYERC_EXPORT int playerc_device_set_boolprop(playerc_device_t *device, char
*property, BOOL value);
+
/** @brief Request an integer property */
PLAYERC_EXPORT int playerc_device_get_intprop(playerc_device_t *device, char
*property, int32_t *value);
Modified: code/player/trunk/client_libs/libplayerc++/clientproxy.cc
===================================================================
--- code/player/trunk/client_libs/libplayerc++/clientproxy.cc 2009-07-14
23:32:58 UTC (rev 8021)
+++ code/player/trunk/client_libs/libplayerc++/clientproxy.cc 2009-07-15
03:59:24 UTC (rev 8022)
@@ -110,6 +110,21 @@
return playerc_device_hascapability (mInfo, aType, aSubtype);
}
+int ClientProxy::GetBoolProp(char *aProperty, bool *aValue)
+{
+ scoped_lock_t lock(mPc->mMutex);
+ int temp;
+ int result = playerc_device_get_boolprop (mInfo, aProperty, &temp);
+ *aValue = temp;
+ return result;
+}
+
+int ClientProxy::SetBoolProp(char *aProperty, bool aValue)
+{
+ scoped_lock_t lock(mPc->mMutex);
+ return playerc_device_set_boolprop (mInfo, aProperty, aValue);
+}
+
int ClientProxy::GetIntProp(char *aProperty, int32_t *aValue)
{
scoped_lock_t lock(mPc->mMutex);
Modified: code/player/trunk/client_libs/libplayerc++/clientproxy.h
===================================================================
--- code/player/trunk/client_libs/libplayerc++/clientproxy.h 2009-07-14
23:32:58 UTC (rev 8021)
+++ code/player/trunk/client_libs/libplayerc++/clientproxy.h 2009-07-15
03:59:24 UTC (rev 8022)
@@ -245,6 +245,12 @@
/// type and subtype. If it does, the return value will be 1, and 0
otherwise.
int HasCapability(uint32_t aType, uint32_t aSubtype);
+ /// @brief Request a boolean property
+ int GetBoolProp(char *aProperty, bool *aValue);
+
+ /// @brief Set a boolean property
+ int SetBoolProp(char *aProperty, bool aValue);
+
/// @brief Request an integer property
int GetIntProp(char *aProperty, int32_t *aValue);
Modified: code/player/trunk/libplayercore/driver.cc
===================================================================
--- code/player/trunk/libplayercore/driver.cc 2009-07-14 23:32:58 UTC (rev
8021)
+++ code/player/trunk/libplayercore/driver.cc 2009-07-15 03:59:24 UTC (rev
8022)
@@ -405,8 +405,26 @@
{
Property *property = NULL;
- if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, PLAYER_GET_INTPROP_REQ))
+ if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, PLAYER_GET_BOOLPROP_REQ))
{
+ player_boolprop_req_t req = *reinterpret_cast<player_boolprop_req_t*>
(data);
+ if ((property = propertyBag.GetProperty (req.key)) == NULL)
+ return -1;
+ property->GetValueToMessage (reinterpret_cast<void*> (&req));
+ Publish(hdr->addr, resp_queue, PLAYER_MSGTYPE_RESP_ACK,
PLAYER_GET_BOOLPROP_REQ, reinterpret_cast<void*> (&req),
sizeof(player_boolprop_req_t), NULL);
+ return 0;
+ }
+ else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
PLAYER_SET_BOOLPROP_REQ))
+ {
+ player_boolprop_req_t req = *reinterpret_cast<player_boolprop_req_t*>
(data);
+ if ((property = propertyBag.GetProperty (req.key)) == NULL)
+ return -1;
+ property->SetValueFromMessage (reinterpret_cast<void*> (&req));
+ Publish(hdr->addr, resp_queue, PLAYER_MSGTYPE_RESP_ACK,
PLAYER_SET_BOOLPROP_REQ, NULL, 0, NULL);
+ return 0;
+ }
+ else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
PLAYER_GET_INTPROP_REQ))
+ {
player_intprop_req_t req = *reinterpret_cast<player_intprop_req_t*> (data);
if ((property = propertyBag.GetProperty (req.key)) == NULL)
return -1;
Modified: code/player/trunk/libplayercore/property.cpp
===================================================================
--- code/player/trunk/libplayercore/property.cpp 2009-07-14 23:32:58 UTC
(rev 8021)
+++ code/player/trunk/libplayercore/property.cpp 2009-07-15 03:59:24 UTC
(rev 8022)
@@ -95,6 +95,62 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
+BoolProperty::BoolProperty (const char *newKey, bool newValue, bool readOnly)
+ : Property (newKey, readOnly), value (newValue)
+{
+}
+
+BoolProperty::BoolProperty (const char *newKey, bool newValue, bool readOnly,
Driver * driver, ConfigFile*cf, int section)
+: Property (newKey, readOnly), value (newValue)
+{
+ driver->RegisterProperty(newKey, this, cf, section);
+}
+
+
+void BoolProperty::SetValue (bool newValue)
+{
+ value = newValue;
+}
+
+void BoolProperty::GetValueToMessage (void *data) const
+{
+ reinterpret_cast<player_boolprop_req_t*> (data)->value = value;
+}
+
+void BoolProperty::SetValueFromMessage (const void *data)
+{
+ if (readonly)
+ {
+ PLAYER_WARN2 ("Property %s is read only, cannot change value
%d", key, reinterpret_cast<const player_boolprop_req_t*> (data)->value);
+ return;
+ }
+
+ value = reinterpret_cast<const player_boolprop_req_t*> (data)->value;
+}
+
+bool BoolProperty::ReadConfig (ConfigFile *cf, int section)
+{
+ // Read a boolean from the config file section, using the current prop
value as the default
+ value = cf->ReadBool (section, key, value);
+
+ return true;
+}
+
+const BoolProperty& BoolProperty::operator= (const BoolProperty &rhs)
+{
+ value = rhs.GetValue ();
+ return *this;
+}
+
+bool BoolProperty::operator= (bool rhs)
+{
+ value = rhs;
+ return value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
IntProperty::IntProperty (const char *newKey, int newValue, bool readOnly)
: Property (newKey, readOnly), value (newValue)
{
Modified: code/player/trunk/libplayercore/property.h
===================================================================
--- code/player/trunk/libplayercore/property.h 2009-07-14 23:32:58 UTC (rev
8021)
+++ code/player/trunk/libplayercore/property.h 2009-07-15 03:59:24 UTC (rev
8022)
@@ -82,6 +82,34 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
+/// Boolean property class
+class PLAYERCORE_EXPORT BoolProperty : public Property
+{
+ public:
+ BoolProperty (const char *newKey, bool newValue, bool readOnly);
+ /** Constructor that registers the property with a driver as
well while it is constructed */
+ BoolProperty (const char *newKey, bool newValue, bool readOnly,
Driver * driver, ConfigFile*cf, int section);
+
+ bool GetValue (void) const { return value; }
+ void SetValue (bool newValue);
+ void GetValueToMessage (void *data) const;
+ void SetValueFromMessage (const void *data);
+
+ // Config file read method
+ virtual bool ReadConfig (ConfigFile *cf, int section);
+
+ // Operators
+ operator bool (void) { return value; }
+ const BoolProperty& operator= (const BoolProperty &rhs);
+ bool operator= (bool rhs);
+
+ private:
+ bool value;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
/// Integer property class
class PLAYERCORE_EXPORT IntProperty : public Property
{
Modified: code/player/trunk/libplayerinterface/functiontable.c
===================================================================
--- code/player/trunk/libplayerinterface/functiontable.c 2009-07-14
23:32:58 UTC (rev 8021)
+++ code/player/trunk/libplayerinterface/functiontable.c 2009-07-15
03:59:24 UTC (rev 8022)
@@ -90,6 +90,12 @@
/* universal messages */
{0, PLAYER_MSGTYPE_REQ, PLAYER_CAPABILTIES_REQ,
(player_pack_fn_t)player_capabilities_req_pack, NULL, NULL},
+ {0, PLAYER_MSGTYPE_REQ, PLAYER_GET_BOOLPROP_REQ,
+ (player_pack_fn_t)player_boolprop_req_pack,
(player_copy_fn_t)player_boolprop_req_t_copy,
(player_cleanup_fn_t)player_boolprop_req_t_cleanup,
+
(player_clone_fn_t)player_boolprop_req_t_clone,(player_free_fn_t)player_boolprop_req_t_free,(player_sizeof_fn_t)player_boolprop_req_t_sizeof},
+ {0, PLAYER_MSGTYPE_REQ, PLAYER_SET_BOOLPROP_REQ,
+ (player_pack_fn_t)player_boolprop_req_pack,
(player_copy_fn_t)player_boolprop_req_t_copy,
(player_cleanup_fn_t)player_boolprop_req_t_cleanup,
+
(player_clone_fn_t)player_boolprop_req_t_clone,(player_free_fn_t)player_boolprop_req_t_free,(player_sizeof_fn_t)player_boolprop_req_t_sizeof},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_INTPROP_REQ,
(player_pack_fn_t)player_intprop_req_pack,
(player_copy_fn_t)player_intprop_req_t_copy,
(player_cleanup_fn_t)player_intprop_req_t_cleanup,
(player_clone_fn_t)player_intprop_req_t_clone,(player_free_fn_t)player_intprop_req_t_free,(player_sizeof_fn_t)player_intprop_req_t_sizeof},
Modified: code/player/trunk/libplayerinterface/player.h
===================================================================
--- code/player/trunk/libplayerinterface/player.h 2009-07-14 23:32:58 UTC
(rev 8021)
+++ code/player/trunk/libplayerinterface/player.h 2009-07-15 03:59:24 UTC
(rev 8022)
@@ -411,7 +411,20 @@
#define PLAYER_SET_DBLPROP_REQ 251
#define PLAYER_GET_STRPROP_REQ 250
#define PLAYER_SET_STRPROP_REQ 249
+#define PLAYER_GET_BOOLPROP_REQ 248
+#define PLAYER_SET_BOOLPROP_REQ 247
+/** @brief Request to get a boolean property */
+typedef struct player_boolprop_req
+{
+ /** The property key's length */
+ uint32_t key_count;
+ /** The property key */
+ char *key;
+ /** The property value */
+ char value;
+} player_boolprop_req_t;
+
/** @brief Request to get an integer property */
typedef struct player_intprop_req
{
Modified: code/player/trunk/server/drivers/ranger/hokuyo_aist.cc
===================================================================
--- code/player/trunk/server/drivers/ranger/hokuyo_aist.cc 2009-07-14
23:32:58 UTC (rev 8021)
+++ code/player/trunk/server/drivers/ranger/hokuyo_aist.cc 2009-07-15
03:59:24 UTC (rev 8022)
@@ -105,6 +105,10 @@
- Default: 0m
- Minimum possible distance. Below that means there is an error (a scratch
on the laser for
instance). The reading is then adjusted to the average of the neighboring
valid beams.
+ - hw_timestamps (boolean)
+ - Default: false
+ - When false, the server will use server time stamps in data messages. When
true, the time stamp
+ in the laser data will be used.
@par Example
@@ -132,6 +136,7 @@
const int DEFAULT_SENSITIVITY = 0;
const int DEFAULT_GET_INTENSITIES = 0;
const double DEFAULT_MIN_DIST = 0.0;
+const bool DEFAULT_TIMESTAMPS = false;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver object
@@ -157,6 +162,7 @@
double _minAngle, _maxAngle;
IntProperty _baudRate, _speedLevel, _highSensitivity;
DoubleProperty _minDist;
+ BoolProperty _hwTimeStamps;
std::string _portOpts;
// Geometry
player_ranger_geom_t _geom;
@@ -181,6 +187,7 @@
_speedLevel ("speed_level", DEFAULT_SPEED_LEVEL, false),
_highSensitivity ("high_sensitivity", DEFAULT_SENSITIVITY, false),
_minDist ("min_dist", DEFAULT_MIN_DIST, false),
+ _hwTimeStamps ("hw_timestamps", DEFAULT_TIMESTAMPS, false),
_ranges (NULL), _intensities (NULL)
{
// Get the baudrate, speed and sensitivity
@@ -188,6 +195,7 @@
RegisterProperty ("speed_level", &_speedLevel, cf, section);
RegisterProperty ("high_sensitivity", &_highSensitivity, cf, section);
RegisterProperty ("min_dist", &_minDist, cf, section);
+ RegisterProperty ("hw_timestamps", &_hwTimeStamps, cf, section);
// Get config
_getIntensities = cf->ReadBool (section, "get_intensities", false);
@@ -516,13 +524,31 @@
rangeData.ranges = _ranges;
rangeData.ranges_count = _data.Length ();
- Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_RANGE,
- reinterpret_cast<void*> (&rangeData), sizeof
(rangeData), NULL);
+ if (_hwTimeStamps.GetValue ())
+ {
+ double ts = _data.TimeStamp () / 1000.0;
+ Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_RANGE,
+ reinterpret_cast<void*> (&rangeData),
sizeof (rangeData), &ts);
+ }
+ else
+ {
+ Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_RANGE,
+ reinterpret_cast<void*> (&rangeData),
sizeof (rangeData), NULL);
+ }
intensityData.intensities = _intensities;
intensityData.intensities_count = _data.Length ();
- Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_INTNS,
- reinterpret_cast<void*> (&intensityData),
sizeof (intensityData), NULL);
+ if (_hwTimeStamps.GetValue ())
+ {
+ double ts = _data.TimeStamp () / 1000.0;
+ Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_INTNS,
+ reinterpret_cast<void*>
(&intensityData), sizeof (intensityData), &ts);
+ }
+ else
+ {
+ Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_INTNS,
+ reinterpret_cast<void*>
(&intensityData), sizeof (intensityData), NULL);
+ }
}
else
{
@@ -553,8 +579,17 @@
}
rangeData.ranges = _ranges;
rangeData.ranges_count = _data.Length ();
- Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_RANGE,
- reinterpret_cast<void*> (&rangeData), sizeof
(rangeData), NULL);
+ if (_hwTimeStamps.GetValue ())
+ {
+ double ts = _data.TimeStamp () / 1000.0;
+ Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_RANGE,
+ reinterpret_cast<void*> (&rangeData),
sizeof (rangeData), &ts);
+ }
+ else
+ {
+ Publish (device_addr, PLAYER_MSGTYPE_DATA,
PLAYER_RANGER_DATA_RANGE,
+ reinterpret_cast<void*> (&rangeData),
sizeof (rangeData), NULL);
+ }
}
return true;
Modified: code/player/trunk/utils/playerprop/playerprop.cpp
===================================================================
--- code/player/trunk/utils/playerprop/playerprop.cpp 2009-07-14 23:32:58 UTC
(rev 8021)
+++ code/player/trunk/utils/playerprop/playerprop.cpp 2009-07-15 03:59:24 UTC
(rev 8022)
@@ -47,9 +47,11 @@
{
cout << "Usage: playerprop -d <device> [-i <index> -h <host> -p
<port>] <command> <args>" << endl << endl
<< "Commands:" << endl
+ << "getbool <prop name> Get a boolean property"
<< endl
<< "getint <prop name> Get an interger
property" << endl
<< "getdbl <prop name> Get a double property"
<< endl
<< "getstr <prop name> Get a string property"
<< endl
+ << "setbool <prop name> <value> Set a boolean property"
<< endl
<< "setint <prop name> <value> Set an interger
property" << endl
<< "setdbl <prop name> <value> Set a double property"
<< endl
<< "setstr <prop name> <value> Set a string property"
<< endl;
@@ -94,6 +96,7 @@
int main (int argc, char *argv[])
{
ClientProxy* deviceProxy;
+ bool boolValue;
int32_t argsIndex = 0, intValue;
double dblValue;
char *strValue;
@@ -198,8 +201,13 @@
exit (-1);
}
- if (strncmp (argv[argsIndex], "getint", 6) == 0)
+ if (strncmp (argv[argsIndex], "getbool", 7) == 0)
{
+ if (deviceProxy->GetBoolProp (argv[argsIndex + 1], &boolValue)
>= 0)
+ cout << "Property " << argv[argsIndex + 1] << " = " <<
boolValue << endl;
+ }
+ else if (strncmp (argv[argsIndex], "getint", 6) == 0)
+ {
if (deviceProxy->GetIntProp (argv[argsIndex + 1], &intValue) >=
0)
cout << "Property " << argv[argsIndex + 1] << " = " <<
intValue << endl;
}
@@ -216,6 +224,13 @@
free (strValue);
}
}
+ else if (strncmp (argv[argsIndex], "setbool", 7) == 0)
+ {
+ if (strncmp (argv[argsIndex + 2], "true", 4) == 0)
+ deviceProxy->SetBoolProp (argv[argsIndex + 1], true);
+ else
+ deviceProxy->SetBoolProp (argv[argsIndex + 1], false);
+ }
else if (strncmp (argv[argsIndex], "setint", 6) == 0)
{
deviceProxy->SetIntProp (argv[argsIndex + 1], atoi
(argv[argsIndex + 2]));
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit