From b78b49d85fbb9b2901c77e6450cfd41c0a818ac1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 19 Feb 2015 14:01:52 +0200 Subject: [PATCH] Add telemetry framework for drivers --- source/libr2c2/arducontrol.cpp | 5 +++++ source/libr2c2/arducontrol.h | 3 +++ source/libr2c2/centralstation.cpp | 6 ++++++ source/libr2c2/centralstation.h | 3 +++ source/libr2c2/driver.h | 11 +++++++++++ source/libr2c2/dummy.cpp | 6 ++++++ source/libr2c2/dummy.h | 3 +++ source/libr2c2/intellibox.cpp | 6 ++++++ source/libr2c2/intellibox.h | 3 +++ 9 files changed, 46 insertions(+) diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index 40b3d35..1af7fca 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -327,6 +327,11 @@ bool ArduControl::get_sensor(unsigned addr) const return get_item(sensors, addr).state; } +float ArduControl::get_telemetry_value(const string &name) const +{ + throw key_error(name); +} + void ArduControl::tick() { Tag tag; diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index c170e42..292700d 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -458,6 +458,9 @@ public: virtual void set_sensor(unsigned, bool) { } virtual bool get_sensor(unsigned) const; + virtual const TelemetryInfo *enumerate_telemetry(unsigned) const { return 0; } + virtual float get_telemetry_value(const std::string &) const; + virtual void tick(); virtual void flush(); private: diff --git a/source/libr2c2/centralstation.cpp b/source/libr2c2/centralstation.cpp index fc7855b..5e82f2e 100644 --- a/source/libr2c2/centralstation.cpp +++ b/source/libr2c2/centralstation.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -328,6 +329,11 @@ bool CentralStation::get_sensor(unsigned addr) const return false; } +float CentralStation::get_telemetry_value(const string &name) const +{ + throw key_error(name); +} + void CentralStation::tick() { while(Message msg = receive()) diff --git a/source/libr2c2/centralstation.h b/source/libr2c2/centralstation.h index f23fa66..959a5ac 100644 --- a/source/libr2c2/centralstation.h +++ b/source/libr2c2/centralstation.h @@ -167,6 +167,9 @@ public: virtual void set_sensor(unsigned, bool) { } virtual bool get_sensor(unsigned) const; + virtual const TelemetryInfo *enumerate_telemetry(unsigned) const { return 0; } + virtual float get_telemetry_value(const std::string &) const; + virtual void tick(); virtual void flush(); diff --git a/source/libr2c2/driver.h b/source/libr2c2/driver.h index a0e5cc4..3f5a75c 100644 --- a/source/libr2c2/driver.h +++ b/source/libr2c2/driver.h @@ -45,6 +45,14 @@ public: std::string name; }; + struct TelemetryInfo + { + const char *name; + const char *label; + const char *unit; + unsigned precision; + }; + sigc::signal signal_power; sigc::signal signal_halt; sigc::signal signal_locomotive_detected; @@ -91,6 +99,9 @@ public: virtual void set_sensor(unsigned, bool) = 0; virtual bool get_sensor(unsigned) const = 0; + virtual const TelemetryInfo *enumerate_telemetry(unsigned) const = 0; + virtual float get_telemetry_value(const std::string &) const = 0; + virtual void tick() = 0; virtual void flush() = 0; diff --git a/source/libr2c2/dummy.cpp b/source/libr2c2/dummy.cpp index 0c3c351..ba23449 100644 --- a/source/libr2c2/dummy.cpp +++ b/source/libr2c2/dummy.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include "dummy.h" @@ -117,6 +118,11 @@ bool Dummy::get_sensor(unsigned addr) const return false; } +float Dummy::get_telemetry_value(const string &name) const +{ + throw key_error(name); +} + void Dummy::tick() { Time::TimeStamp t = Time::now(); diff --git a/source/libr2c2/dummy.h b/source/libr2c2/dummy.h index 547efc3..37aec3a 100644 --- a/source/libr2c2/dummy.h +++ b/source/libr2c2/dummy.h @@ -64,6 +64,9 @@ public: virtual void set_sensor(unsigned, bool); virtual bool get_sensor(unsigned) const; + virtual const TelemetryInfo *enumerate_telemetry(unsigned) const { return 0; } + virtual float get_telemetry_value(const std::string &) const; + virtual void tick(); virtual void flush() { } }; diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index 4c8f2ac..c2e5d75 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -318,6 +319,11 @@ bool Intellibox::get_sensor(unsigned addr) const return false; } +float Intellibox::get_telemetry_value(const string &name) const +{ + throw key_error(name); +} + void Intellibox::tick() { const Time::TimeStamp t = Time::now(); diff --git a/source/libr2c2/intellibox.h b/source/libr2c2/intellibox.h index df379a3..caf8490 100644 --- a/source/libr2c2/intellibox.h +++ b/source/libr2c2/intellibox.h @@ -163,6 +163,9 @@ public: virtual void set_sensor(unsigned, bool) { } virtual bool get_sensor(unsigned) const; + virtual const TelemetryInfo *enumerate_telemetry(unsigned) const { return 0; } + virtual float get_telemetry_value(const std::string &) const; + virtual void tick(); virtual void flush(); -- 2.45.2