]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/arducontrol.h
Use current monitoring to detect failed turnouts
[r2c2.git] / source / libr2c2 / arducontrol.h
index 1f45534a1ca472ee22cfbd40159fe2be806cf7a7..c3ca7a4106f570a418a6a7166a19a9048c1bcf67 100644 (file)
@@ -117,6 +117,7 @@ private:
 
                bool set(T v) { if(v==pending) return false; pending = v; ++serial; return true; }
                bool commit(unsigned short s) { if(s!=serial) return false; current = pending; return true; }
+               void rollback() { pending = current; ++serial; }
 
                operator T() const { return current; }
        };
@@ -173,6 +174,7 @@ private:
                unsigned address;
                unsigned bits;
                ControlledVariable<unsigned> state;
+               unsigned uncertain;
                unsigned target;
                Msp::Time::TimeDelta active_time;
 
@@ -269,6 +271,7 @@ private:
                ArduControl &control;
                unsigned n_octets;
                unsigned octets_remaining;
+               unsigned delay;
 
        public:
                S88Task(ArduControl &);
@@ -316,6 +319,28 @@ private:
                bool pop_info(MfxInfo &);
        };
 
+       class MonitorTask: public Task
+       {
+       private:
+               float voltage;
+               float current;
+               float base_level;
+               float peak_level;
+               Msp::Time::TimeStamp next_poll;
+               unsigned next_type;
+
+       public:
+               MonitorTask();
+
+               virtual bool get_work(PendingCommand &);
+               virtual void process_reply(const char *, unsigned);
+
+               float get_voltage() const { return voltage; }
+               float get_current() const { return current; }
+               void reset_peak();
+               float get_peak() const { return peak_level-base_level; }
+       };
+
        class ControlThread: public Msp::Thread
        {
        private:
@@ -352,6 +377,7 @@ private:
        AccessoryMap accessories;
        AccessoryPtrList accessory_queue;
        Accessory *active_accessory;
+       unsigned char active_index;
        Msp::Time::TimeStamp off_timeout;
 
        SensorMap sensors;
@@ -363,12 +389,13 @@ private:
        S88Task s88;
        MfxAnnounceTask mfx_announce;
        MfxSearchTask mfx_search;
+       MonitorTask monitor;
        ControlThread thread;
 
        static ProtocolInfo protocol_info[2];
 
 public:
-       ArduControl(const std::string &);
+       ArduControl(const Options &);
        ~ArduControl();
 
        virtual void set_power(bool);