Commit 66659a7e authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[messages] Autofilled cmdId in MessageBase

parent c912bba5
......@@ -15,7 +15,10 @@ struct Message
{
CID_E cmdId;
Message() : cmdId(T::Identifier) {}
Message<T>& operator=(const std::vector<uint8_t>& other) {
// This checks that the type T inherit from A<T>, i.e. is a Curriously
// Recurring Template Pattern.
static_assert(std::is_base_of<Message<T>,T>::value,
......
......@@ -210,7 +210,9 @@ struct StatusCompensatedAHRS {
}__attribute__((packed));
struct Status : public Message<Status>
{
{
static const CID_E Identifier = CID_STATUS;
STATUS_BITS_E contentType;
uint64_t timestamp;
StatusEnvironment environment;
......
......@@ -8,7 +8,7 @@ namespace narval { namespace seatrac { namespace messages {
struct SysAlive : public Message<SysAlive>
{
using Request = Message;
static const CID_E Identifier = CID_SYS_ALIVE;
using Message<SysAlive>::operator=;
uint32_t alivedFor;
......
......@@ -8,6 +8,7 @@ namespace narval { namespace seatrac { namespace messages {
struct SysInfo : public Message<SysInfo>
{
static const CID_E Identifier = CID_SYS_INFO;
using Request = Message;
using Message<SysInfo>::operator=;
......
......@@ -6,30 +6,6 @@ using namespace std;
#include <seatrac_driver/commands.h>
using namespace narval::seatrac;
void request_sys_info(boost::asio::steady_timer* timer,
SeatracDriver* seatrac,
const boost::system::error_code& err)
{
if(err) {
std::ostringstream oss;
oss << "Error waiting for timer : " << err << endl;
throw std::runtime_error(oss.str());
}
uint8_t cid = 0x02;
std::vector<uint8_t> respData;
if(!seatrac->send_request(1, &cid, &respData, 5000)) {
cout << "Timeout reached !" << endl;
}
else {
cout << "Response ok" << endl;
}
//seatrac->send(1, &cid);
timer->expires_from_now(boost::asio::chrono::seconds(1));
timer->async_wait(boost::bind(&request_sys_info, timer, seatrac, _1));
}
narval::seatrac::messages::Status get_next_status(SeatracDriver& seatrac)
{
narval::seatrac::messages::Status status;
......@@ -47,22 +23,12 @@ int main()
SeatracDriver seatrac(service.io_service(), "/dev/ttyUSB0");
seatrac.enable_io_dump();
// boost::asio::steady_timer timer(*service.io_service().get(), boost::asio::chrono::milliseconds(200));
// timer.async_wait(boost::bind(&request_sys_info, &timer, &seatrac, _1));
service.start();
//for(int i = 0; i < 10; i++) {
for(int i = 0; i < 1000; i++) {
// uint8_t cid = 0x02;
// std::vector<uint8_t> respData;
// if(!seatrac.send_request(1, &cid, &respData, 1000)) {
// cout << "Timeout reached !" << endl;
// }
// else {
// cout << "Response ok" << endl;
// }
//for(int i = 0; i < 10; i++) {
// getchar();
try {
// cout << command::sys_alive(seatrac) << endl;
// cout << command::sys_info(seatrac) << endl;
......@@ -71,7 +37,6 @@ int main()
catch(const TimeoutReached& e) {
cout << "Timeout reached" << endl;
}
//getchar();
}
service.stop();
......
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