]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/driver.h
Add telemetry framework for drivers
[r2c2.git] / source / libr2c2 / driver.h
index 101426026a15b2c6577e7aceb27376e7c47540d8..3f5a75ce2a6b959d31071d38436c2d73bbef8f0e 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef LIBR2C2_DRIVER_H_
 #define LIBR2C2_DRIVER_H_
 
+#include <map>
 #include <string>
 #include <sigc++/signal.h>
+#include <msp/strings/lexicalcast.h>
 
 namespace R2C2 {
 
@@ -13,11 +15,52 @@ class VehicleType;
 class Driver
 {
 public:
+       class Options
+       {
+       private:
+               typedef std::map<std::string, std::string> OptionMap;
+
+               OptionMap opts;
+
+       public:
+               Options() { }
+               Options(const std::string &);
+
+               void set(const std::string &, const std::string &);
+
+               template<typename T>
+               T get(const std::string &k, const T &d = T()) const
+               {
+                       OptionMap::const_iterator i = opts.find(k);
+                       if(i==opts.end())
+                               return d;
+                       return Msp::lexical_cast<T>(i->second);
+               }
+       };
+
+       struct DetectedLocomotive
+       {
+               std::string protocol;
+               unsigned address;
+               std::string name;
+       };
+
+       struct TelemetryInfo
+       {
+               const char *name;
+               const char *label;
+               const char *unit;
+               unsigned precision;
+       };
+
        sigc::signal<void, bool> signal_power;
        sigc::signal<void, bool> signal_halt;
+       sigc::signal<void, const DetectedLocomotive &> signal_locomotive_detected;
+       sigc::signal<void, const DetectedLocomotive &> signal_locomotive_gone;
        sigc::signal<void, unsigned, unsigned, bool> signal_loco_speed;
        sigc::signal<void, unsigned, unsigned, bool> signal_loco_function;
        sigc::signal<void, unsigned, unsigned> signal_turnout;
+       sigc::signal<void, unsigned> signal_turnout_failed;
        sigc::signal<void, unsigned, unsigned> signal_signal;
        sigc::signal<void, unsigned, bool> signal_sensor;
 
@@ -33,6 +76,8 @@ public:
 
        virtual const char *enumerate_protocols(unsigned) const = 0;
        virtual unsigned get_protocol_speed_steps(const std::string &) const = 0;
+
+       virtual const DetectedLocomotive *enumerate_detected_locos(unsigned) const = 0;
        virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &) = 0;
        virtual void remove_loco(unsigned) = 0;
        virtual void set_loco_speed(unsigned, unsigned) = 0;
@@ -54,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;