Commit 90025b28 authored by Bruno Laurencich's avatar Bruno Laurencich

send rate as parameter

parent 236ed23f
......@@ -17,7 +17,10 @@
</Log>
<Transmit>
osc
</Transmit>
</Transmit>
<Send_rate>
4
</Send_rate>
<Verbosity>
0
</Verbosity>
......
......@@ -161,6 +161,9 @@
<xs:element type="verbosityType" name="Verbosity"
minOccurs="0" maxOccurs="1"/>
<xs:element type="CollapsedFloatType" name="Send_rate"
minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
......
......@@ -60,11 +60,14 @@
#include "osc/OscTypes.h"
#include "ip/NetworkingUtils.h"
// #include "Notochord.h"
#include "Chordata_utils.h"
#include "Chordata_def.h"
#include "Chordata_error.h"
namespace Chordata{
extern config_fn getConf;
namespace Communicator{
extern long log_attemps;
......@@ -235,33 +238,34 @@ namespace Chordata{
#include <iostream>
template <typename Node>
inline void transmit (const Node *n, Quaternion&& q){
static int max_per_second = 4;
static Chordata::microDuration period(1000000 / max_per_second);
auto delta = timekeeper.get_transmision_delta(n->getLabel());
// std::cout << delta.count() << std::endl;
inline void check_transmit(const std::string& addr, const Quaternion& q){
static uint32_t micros_to_wait = 1000000 / Chordata::getConf().comm.send_rate;
static Chordata::microDuration period(micros_to_wait);
auto delta = timekeeper.get_transmision_delta(addr);
if (delta > period){
transmit_handler(n->osc_addr, q);
timekeeper.set_last_transmision(n->getLabel());
std::cout << "SENT " << delta.count() << std::endl;
transmit_handler(addr, q);
timekeeper.set_last_transmision(addr);
// std::cout << addr << " SENT " << delta.count() << std::endl;
} else {
std::cout << "****DROPPED*** " << delta.count() << std::endl;
// std::cout << addr << " ***DROPPED*** " << delta.count() << std::endl;
}
}
template <typename Node>
inline void transmit (const Node *n, Quaternion&& q){
check_transmit(n->osc_addr, q);
}
inline void transmit(const char *s, Quaternion&& q){
transmit_handler(s,q);
check_transmit(s, q);
// transmit_handler(s,q);
}
inline void transmit(const std::string& s, const Quaternion& q){
transmit_handler(s,q);
check_transmit(s,q);
}
inline void transmit(const std::string& s){
......
......@@ -51,6 +51,7 @@
#include <cstdint>
#include <string>
#include <functional>
/**
* @name Globals
......@@ -153,6 +154,8 @@
#define _CHORDATA_VERBOSITY 0
#define _CHORDATA_SEND_RATE 25
#define _CHORDATA_TRANSMIT_ADDR "127.0.0.1"
#define _CHORDATA_TRANSMIT_PORT (uint16_t) 7000
#define _CHORDATA_TRANSMIT_BUFFER_SIZE 1024
......@@ -262,6 +265,10 @@
* The namespace under which are grouped all the Chordata objects
*/
namespace Chordata {
/**
* @defgroup Node i2c active objects
* All the objects that are somehow involved in the i2c communication
......@@ -407,7 +414,8 @@ namespace Chordata {
Output_Redirect error;
Output_Redirect transmit;
std::string filename;
char log_level;
char log_level;
float send_rate;
} comm;
struct Conf_osc{
......@@ -417,6 +425,12 @@ namespace Chordata {
} osc;
};
/////////////////////////////////
///TYPEDEFS AND CHORDATA NAMESPACE OBJECTS
/////////////////////////////////
typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
extern config_fn getConf;
/**
* The possible parsing stages.
*/
......@@ -472,6 +486,8 @@ namespace Chordata {
static const char* verbose = "Verbose output";
static const char* send_rate = "Maximum send rate for transmision";
static const char* osc_g = "\nOSC ADDRESSES";
static const char* osc_base = "Base OSC address, default:\n"
......
......@@ -57,9 +57,9 @@
namespace Chordata{
typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
// typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
extern config_fn getConf;
// extern config_fn getConf;
extern std::vector<std::array<int16_t, 3>> mag_lectures;
extern std::array<int16_t, 3> acel_offsets;
extern std::array<int16_t, 3> gyro_offsets;
......
......@@ -71,9 +71,9 @@ using fmt::format;
namespace comm = Chordata::Communicator;
namespace Chordata{
typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
// typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
extern config_fn getConf;
// extern config_fn getConf;
}
......@@ -148,6 +148,8 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
// (spdlog/common.h:91) SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" };
args::ValueFlag<int> verbose(comm_g, "verbose_output", msgs::verbose, {'v', "verbose"});
args::ValueFlag<float> send_rate(comm_g, "send_rate", msgs::send_rate, {'s', "send-rate"});
args::Group osc_g(parser, msgs::osc_g, args::Group::Validators::DontCare);
......@@ -200,6 +202,7 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
if (adapter) conf.comm.adapter = get(adapter);
if (filename) conf.comm.filename = get(filename);
if (verbose) conf.comm.log_level = std::min(get(verbose),2);
if (send_rate) conf.comm.send_rate = std::max(get(send_rate),0.0f);
if (log) conf.comm.log = get(log);
if (error) conf.comm.error = get(error);
if (transmit) conf.comm.transmit = get(transmit);
......@@ -345,6 +348,10 @@ XML_Parser::XML_Parser(Configuration_Data & conf):
conf.comm.log_level = stoi(temp);
}
if (are_the_same(conf.comm.send_rate , default_conf.comm.send_rate)){
putInConf(temp, "Send_rate"); //** conf.comm.log_level **
conf.comm.send_rate = std::max(stof(temp),0.0f);
}
if (are_the_same(conf.comm.log , default_conf.comm.log))
validate_putInConf(conf.comm.log, "Log"); //** conf.comm.log **
......
......@@ -95,6 +95,7 @@ Chordata::Configuration_Data::Configuration_Data(): //from Chordata_def.h
comm.adapter = _CHORDATA_I2C_DEFAULT_ADAPTER_;
comm.filename = _CHORDATA_FILEOUT_NAME;
comm.log_level = _CHORDATA_VERBOSITY;
comm.send_rate = _CHORDATA_SEND_RATE;
comm.log = _CHORDATA_DEF_LOG_REDIR;
comm.error = _CHORDATA_DEF_ERR_REDIR;
......@@ -107,7 +108,6 @@ Chordata::Configuration_Data::Configuration_Data(): //from Chordata_def.h
fusion.beta_s = fusion.beta_f = _MADGWICK_BETA;
fusion.time = _MADGWICK_BETA_MANGLING_TIME;
append_path();
};
......
......@@ -292,6 +292,8 @@ bool Notochord::run(){
notODRModifiers, scheluder.getODRModifiers(), scheluder.length(),
_CHORDATA_ODR, sleepMicros);
comm::try_info("Sending rate = {}Hz",
Chordata::getConf().comm.send_rate);
try{
......
......@@ -64,9 +64,9 @@
namespace Chordata{
typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
// typedef std::function<const Chordata::Configuration_Data&(void)> config_fn;
extern config_fn getConf;
// extern config_fn getConf;
class Notochord{
private:
......
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