Commit b0cc0e93 authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[messages/commands] Added SettingsGet command and message

parent 60c1f83e
......@@ -75,6 +75,20 @@ inline messages::StatusConfigSet status_config_set(SeatracDriver& seatrac,
return response;
}
inline messages::SettingsGet settings_get(SeatracDriver& seatrac, int64_t timeout=1000)
{
messages::SettingsGet response;
messages::SettingsGet::Request request;
if(!seatrac.send_request(sizeof(request), (const uint8_t*)&request, &response, timeout)) {
throw TimeoutReached();
}
return response;
}
}; //namespace command
}; //namespace seatrac
}; //namespace narval
......
......@@ -25,7 +25,10 @@ struct Message
"T is not derived from Message<T> (search CRTP).");
if(other.size() != sizeof(T)) {
throw std::runtime_error("Wrong size to copy message from raw data");
std::ostringstream oss;
oss << "Wrong size to copy message from raw data (expected "
<< sizeof(T) << ", got " << other.size() << ")";
throw std::runtime_error(oss.str());
}
memcpy(this, other.data(), sizeof(T));
......
......@@ -10,6 +10,8 @@
#include <seatrac_driver/messages/StatusConfigGet.h>
#include <seatrac_driver/messages/StatusConfigSet.h>
#include <seatrac_driver/messages/SettingsGet.h>
#endif //_DEF_SEATRAC_DRIVER_MESSAGES_MESSAGES_H_
#ifndef _DEF_SEATRAC_DRIVER_MESSAGES_SETTINGS_GET_H_
#define _DEF_SEATRAC_DRIVER_MESSAGES_SETTINGS_GET_H_
#include <seatrac_driver/SeatracTypes.h>
#include <seatrac_driver/messages/MessageBase.h>
namespace narval { namespace seatrac { namespace messages {
struct SettingsGet : public Message<SettingsGet>
{
using Message<SettingsGet>::operator=;
static const CID_E Identifier = CID_SETTINGS_GET;
struct Request : public Message<Request> {
static const CID_E Identifier = CID_SETTINGS_GET;
};
SETTINGS_T settings;
}__attribute__((packed));
}; //namespace messages
}; //namespace seatrac
}; //namespace narval
inline std::ostream& operator<<(std::ostream& os,
const narval::seatrac::messages::SettingsGet& msg)
{
using namespace narval::seatrac;
static const char* prefix = "\n- ";
os << "SettingsGet :"
<< prefix << "settings : " << print_utils::indent(msg.settings);
return os;
}
#endif //_DEF_SEATRAC_DRIVER_MESSAGES_SETTINGS_GET_H_
......@@ -39,17 +39,18 @@ int main(int argc, char** argv)
// STATUS_MODE_1HZ
//) << endl;
//for(int i = 0; i < 10; i++) {
// getchar();
// try {
// //cout << command::sys_alive(seatrac) << endl;
// //cout << command::sys_info(seatrac) << endl;
// cout << command::status_config_get(seatrac) << endl;
// }
// catch(const TimeoutReached& e) {
// cout << "Timeout reached" << endl;
// }
//}
for(int i = 0; i < 10; i++) {
getchar();
try {
//cout << command::sys_alive(seatrac) << endl;
//cout << command::sys_info(seatrac) << endl;
//cout << command::status_config_get(seatrac) << endl;
cout << command::settings_get(seatrac) << endl;
}
catch(const TimeoutReached& e) {
cout << "Timeout reached" << endl;
}
}
for(int i = 0; i < 100; i++) {
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment