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

[driver/print] Updated printing functions

parent 564b2e90
......@@ -684,4 +684,19 @@ inline std::ostream& operator<<(std::ostream& os, narval::seatrac::STATUS_BITS_E
return os;
}
inline std::ostream& operator<<(std::ostream& os, narval::seatrac::STATUSMODE_E mode)
{
using namespace narval::seatrac;
switch(mode) {
case STATUS_MODE_MANUAL: os << "STATUS_MODE_MANUAL"; break;
case STATUS_MODE_1HZ: os << "STATUS_MODE_1HZ"; break;
case STATUS_MODE_2HZ5: os << "STATUS_MODE_2HZ5"; break;
case STATUS_MODE_5HZ: os << "STATUS_MODE_5HZ"; break;
case STATUS_MODE_10HZ: os << "STATUS_MODE_10HZ"; break;
case STATUS_MODE_25HZ: os << "STATUS_MODE_25HZ"; break;
default: os << "Unknown mode"; break;
};
return os;
}
#endif //_DEF_SEATRAC_DRIVER_SEATRAC_ENUMS_H_
......@@ -3,6 +3,7 @@
#include <sstream>
#include <seatrac_driver/SeatracEnums.h>
#include <seatrac_driver/print_utils.h>
namespace narval { namespace seatrac {
......@@ -555,21 +556,6 @@ struct SETTINGS_T {
}; //namespace seatrac
}; //namespace narval
template <typename T>
std::string add_indentation(const T& input, const char* indent = " ")
{
std::ostringstream tmp;
tmp << input;
std::ostringstream oss;
for(auto c : tmp.str()) {
oss << c;
if(c == '\n')
oss << indent;
}
return oss.str();
}
inline std::ostream& operator<<(std::ostream& os,
const narval::seatrac::FIRMWARE_T& msg)
{
......
......@@ -391,6 +391,8 @@ inline std::ostream& operator<<(std::ostream& os,
inline std::ostream& operator<<(std::ostream& os, const narval::seatrac::messages::Status& msg)
{
using namespace narval::seatrac;
using namespace narval::seatrac::print_utils;
const char* prefix = "\n- ";
os << "Status : " << sizeof(msg)
<< prefix << "msgId : " << msg.msgId
......@@ -398,44 +400,38 @@ inline std::ostream& operator<<(std::ostream& os, const narval::seatrac::message
<< prefix << "timestamp : " << msg.timestamp;
//<< prefix << "timestamp : " << msg.timestamp2;
if(msg.contentType & narval::seatrac::ENVIRONMENT) {
os << prefix;
narval::seatrac::print_utils::indent(msg.environment, os);
if(msg.contentType & ENVIRONMENT) {
os << prefix << indent(msg.environment);
}
else {
os << prefix << "Environment : Empty";
}
if(msg.contentType & narval::seatrac::ATTITUDE) {
os << prefix;
narval::seatrac::print_utils::indent(msg.attitude, os);
if(msg.contentType & ATTITUDE) {
os << prefix << indent(msg.attitude);
}
else {
os << prefix << "Attitude : Empty";
}
if(msg.contentType & narval::seatrac::MAG_CAL) {
os << prefix;
narval::seatrac::print_utils::indent(msg.magCalibration, os);
if(msg.contentType & MAG_CAL) {
os << prefix << indent(msg.magCalibration);
}
else {
os << prefix << "MagCalibration : Empty";
}
if(msg.contentType & narval::seatrac::ACC_CAL) {
os << prefix;
narval::seatrac::print_utils::indent(msg.accCalibration, os);
if(msg.contentType & ACC_CAL) {
os << prefix << indent(msg.accCalibration);
}
else {
os << prefix << "AccCalibration : Empty";
}
if(msg.contentType & narval::seatrac::AHRS_RAW_DATA) {
os << prefix;
narval::seatrac::print_utils::indent(msg.rawAHRS, os);
if(msg.contentType & AHRS_RAW_DATA) {
os << prefix << indent(msg.rawAHRS);
}
else {
os << prefix << "RawAHRS : Empty";
}
if(msg.contentType & narval::seatrac::AHRS_COMP_DATA) {
os << prefix;
narval::seatrac::print_utils::indent(msg.compensatedAHRS, os);
if(msg.contentType & AHRS_COMP_DATA) {
os << prefix << indent(msg.compensatedAHRS);
}
else {
os << prefix << "CompensatedAHRS : Empty";
......
......@@ -30,5 +30,5 @@ inline std::ostream& operator<<(std::ostream& os,
return os;
}
#endif //_DEF_SEATRAC_DRIVER_MESSAGES_SYSAlive_H_
#endif //_DEF_SEATRAC_DRIVER_MESSAGES_SYSALIVE_H_
......@@ -29,14 +29,15 @@ struct SysInfo : public Message<SysInfo>
inline std::ostream& operator<<(std::ostream& os,
const narval::seatrac::messages::SysInfo& msg)
{
using namespace narval::seatrac;
static const char* prefix = "\n- ";
os << "SysInfo :"
<< prefix << "msgId : " << (uint32_t)msg.msgId
<< prefix << "alivedFor : " << (uint32_t)msg.alivedFor
<< prefix << "currentApp : " << (uint32_t)msg.currentApp
<< prefix << "hardware : " << add_indentation(msg.hardware)
<< prefix << "bootFirmware : " << add_indentation(msg.bootFirmware)
<< prefix << "mainFirmware : " << add_indentation(msg.mainFirmware)
<< prefix << "hardware : " << print_utils::indent(msg.hardware)
<< prefix << "bootFirmware : " << print_utils::indent(msg.bootFirmware)
<< prefix << "mainFirmware : " << print_utils::indent(msg.mainFirmware)
<< prefix << "boardRev : " << (uint32_t)msg.boardRev;
return os;
}
......
......@@ -6,20 +6,21 @@
namespace narval { namespace seatrac { namespace print_utils {
template <typename T>
void indent(const T& msg, std::ostream& os, const std::string& prefix=" ")
std::string indent(const T& input, const char* indent = " ")
{
std::ostringstream tmp;
tmp << input;
std::ostringstream oss;
oss << msg;
for(char c : oss.str()) {
if(c == '\n') {
os << c << prefix;
}
else {
os << c;
}
for(auto c : tmp.str()) {
oss << c;
if(c == '\n')
oss << indent;
}
return oss.str();
}
}; //namespace print_utils
}; //namespace seatrac
}; //namespace narval
......
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