Commit fa9178f7 authored by Bruno Laurencich's avatar Bruno Laurencich

Merge branch 'f_runner_mode'

parents 31ab6a6a a4d806b7
......@@ -72,9 +72,9 @@ Chordata::Timekeeper Chordata::Communicator::timekeeper;
long Chordata::Communicator::log_attemps = 0;
Comm_Substrate::Comm_Substrate(const Chordata::Configuration_Data& global_config):
config(global_config)
{
Comm_Substrate::Comm_Substrate(const Chordata::Configuration_Data& global_config){
Chordata::Configuration_Data config = global_config;
switch (global_config.comm.log_level){
case 1: log_level = spd::level::debug; break;
case 2: log_level = spd::level::trace; break;
......@@ -87,11 +87,10 @@ Comm_Substrate::Comm_Substrate(const Chordata::Configuration_Data& global_config
if ( 0 != create_dir( fmt::format("{}/{}", global_config.exe_path ,_CHORDATA_FILEOUT_DIR).c_str()))
throw Chordata::System_Error(errno);
auto push_redirect = [&global_config] (const auto source, auto& dest, auto level)
auto push_redirect = [&config] (const auto source, auto& dest, auto level)
{
for (unsigned i =0,mask; i<=_Output_Redirect_keywords_n; ++i ){
mask = 1 << i-1;
switch (source & mask){
case Chordata::NONE:
break;
......@@ -106,22 +105,40 @@ Comm_Substrate::Comm_Substrate(const Chordata::Configuration_Data& global_config
case Chordata::FILE:
dest.push_back(make_shared
<spdlog::sinks::daily_file_sink_mt>
(global_config.comm.filename, 0, 0)
(config.comm.filename, 0, 0)
);
// cout<< "FILE"<< endl;
break;
case Chordata::OSC:
dest.push_back(make_shared<OscOut>(config));
// cout<< "OSC"<< endl;
dest.push_back(make_shared<OscOut>(global_config));
break;
}
}
};
push_redirect(global_config.comm.log, log, log_level);
push_redirect(global_config.comm.error, error, err_level);
push_redirect(global_config.comm.transmit, transmit, log_level);
Chordata::Output_Redirect log_redirect = global_config.comm.log;
Chordata::Output_Redirect err_redirect = global_config.comm.error;
if (global_config.runner_mode){
Chordata::Output_Redirect remove_stdouts = ___CAST_REDIR_(Chordata::STDOUT|Chordata::STDERR);
log_redirect &= ~remove_stdouts;
err_redirect &= ~remove_stdouts;
log_redirect |= Chordata::OSC;
err_redirect |= Chordata::OSC;
config.comm.ip = "localhost";
config.comm.port = 50419;
}
push_redirect(log_redirect, log, log_level);
push_redirect(err_redirect, error, err_level);
}
#define _PATTERN_FORMAT "[{{:>{}}}] {{}}"
......@@ -129,9 +146,9 @@ Comm_Substrate::Comm_Substrate(const Chordata::Configuration_Data& global_config
using spdlevel = spdlog::level::level_enum;
#define TRANSMIT_OSC(S,Q) osc_sink->transmit(S,Q); osc_sink->flush()
#define TRANSMIT_OTHERS(S,Q) logger.log(which, "{},{:d},{:f},{:f},{:f},{:f}", S, timekeeper.ellapsedMillis(), Q.w, Q.x, Q.y, Q.z);\
logger.flush()
#define TRANSMIT_OSC(S,Q) osc_sink->transmit(S,Q)/*; osc_sink->flush()*/
#define TRANSMIT_OTHERS(S,Q) logger.log(which, "{},{:d},{:f},{:f},{:f},{:f}", S, timekeeper.ellapsedMillis(), Q.w, Q.x, Q.y, Q.z);/*\
logger.flush()*/
auto Chordata::Communicator::initializers::transmit_fn(spdlevel which, Comm_Substrate::redirects&& v, spdlevel global_level){
static auto transmitRedirects = std::move(v);
......@@ -285,13 +302,15 @@ void Chordata::Communicator::OscOut::transmit(const std::string& s, const Quater
p << osc::BeginMessage( s.c_str() )
// << static_cast<int64_t>(timekeeper.ellapsedMicros())
<< q.w << q.x << q.y << q.z << osc::EndMessage;
flush_();
}
void Chordata::Communicator::OscOut::sink_it_(const spdlog::details::log_msg& msg){
p << osc::BeginMessage( (msg.level < spdlog::level::warn)? OscOut::comm_address.c_str() : OscOut::error_address.c_str() )
<< fmt::to_string(msg.raw).c_str() << osc::EndMessage;
flush();
flush_();
}
void Chordata::Communicator::OscOut::flush_(){
......
......@@ -77,6 +77,8 @@ namespace Chordata{
extern Chordata::Timekeeper timekeeper;
struct Comm_Substrate{
//A temporary structure that fills the vectors with spdlog::sinks,
//which are then moved to the communication functions
using redirects = std::vector< spdlog::sink_ptr >;
redirects transmit;
redirects error;
......@@ -84,7 +86,7 @@ namespace Chordata{
spdlog::level::level_enum log_level, err_level;
const Chordata::Configuration_Data& config;
Chordata::Configuration_Data config;
explicit Comm_Substrate(const Chordata::Configuration_Data&);
};
......
......@@ -319,7 +319,7 @@ namespace Chordata {
};
/**
* Utility template for gettinh size of array on compile time.
* Utility template for getting size of array on compile time.
* From Efficient Modern c++ by S. Meyers
*/
template<typename T, std::size_t N>
......@@ -348,6 +348,21 @@ namespace Chordata {
return a= static_cast<Output_Redirect>(static_cast<char>(a) | static_cast<char>(b));
}
inline Output_Redirect& operator &=(Output_Redirect& a, Output_Redirect b)
{
return a= static_cast<Output_Redirect>(static_cast<char>(a) & static_cast<char>(b));
}
inline Output_Redirect& operator &(Output_Redirect& a, Output_Redirect &b)
{
return a= static_cast<Output_Redirect>(static_cast<char>(a) & static_cast<char>(b));
}
inline Output_Redirect operator ~(Output_Redirect& a)
{
return static_cast<Output_Redirect>(~ static_cast<char>(a));
}
static const char* _Output_Redirect_keywords[] =
{"none","stdout", "stderr", "file", "osc"};
......@@ -394,6 +409,8 @@ namespace Chordata {
bool raw;
bool calib;
bool scan;
bool runner_mode;
int kc_ver;
int empirical_add;
int odr;
......@@ -502,6 +519,8 @@ namespace Chordata {
static const char* transmit = "Where to redirect the actual payload (mostly Quaternion data)";
static const char* runner = "Used when the notochord is initialized by a daemon who expects communications by OSC in localhost:50419";
static const char* i2c = "The user space i2c adapter, default: "
_CHORDATA_I2C_DEFAULT_ADAPTER_;
......
......@@ -148,6 +148,7 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
redirectFlag log(comm_g, "output", msgs::log, {'l', "log"});
redirectFlag error(comm_g, "output", msgs::error, {'e', "errors"});
redirectFlag transmit(comm_g, "output", msgs::transmit, {'t', "transmit"});
args::Flag runner(comm_g, "runner_mode", msgs::runner, {"runner_mode"});
textFlag adapter(comm_g, "i2c_adapter", msgs::i2c, {'a', "i2c_adapter"});
textFlag filename(comm_g, "log_filename", msgs::filename, {'f', "log_file"});
......@@ -193,6 +194,7 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
conf.calib = (calib)? true : false;
conf.scan = (scan)? true : false;
conf.empirical_add = (empirical_add)? get(empirical_add) : 0;
conf.runner_mode = (runner)? true : false;
if (odr){
if (get(odr) > 100){
......
......@@ -83,6 +83,7 @@ Chordata::Configuration_Data::Configuration_Data(): //from Chordata_def.h
scan(false),
kc_ver(-1),
odr(_CHORDATA_ODR),
runner_mode(false),
state({.beta_timer_init = 0, .imu_setup_complete = false})
{
......
......@@ -523,13 +523,19 @@ void print_banner(const Notochord& notochord){
std::cout<< separator << '\n';
std::cout<< "Notochord start @ " << comm::timekeeper.initialTime();
std::cout<< "\nOutputs:" << "\n";
std::cout<< "Log -> " << notochord.getConf().comm.log << "\n";
std::cout<< "Error -> " << notochord.getConf().comm.error << "\n";
std::cout<< "Transmit -> " << notochord.getConf().comm.transmit<< "\n";
std::cout<< "\nTargets:" << "\n";
std::cout<< "File -> " << notochord.getConf().comm.filename << "<DATE>\n";
std::cout<< "OSC ip/port -> " << notochord.getConf().comm.ip
<< " / " << notochord.getConf().comm.port << "\n";
if (notochord.getConf().runner_mode){
std::cout<< " === RUNNER MODE ===" << "\n";
std::cout << "[ Log / Error / Transmit ] -> localhost:50419"<< "\n";
std::cout << "(this mode will also output to file if set in conf)"<< "\n";
} else {
std::cout<< "Log -> " << notochord.getConf().comm.log << "\n";
std::cout<< "Error -> " << notochord.getConf().comm.error << "\n";
std::cout<< "Transmit -> " << notochord.getConf().comm.transmit<< "\n";
std::cout<< "\nTargets:" << "\n";
std::cout<< "File -> " << notochord.getConf().comm.filename << "<DATE>\n";
std::cout<< "OSC ip/port -> " << notochord.getConf().comm.ip
<< " / " << notochord.getConf().comm.port << "\n";
}
std::cout<< separator << '\n';
std::cout<< std::endl;
......
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