]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/arducontrol.h
Remove an unused mutex
[r2c2.git] / source / libr2c2 / arducontrol.h
index a8bdfa7a7ba1b018d3798c9ff3d50f25f8d640ff..01ee2814c6f2bff1f3e52ad11b67070a97e85900 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;
 
@@ -217,6 +219,7 @@ private:
        public:
                void push(const T &);
                bool pop(T &);
+               bool empty() const;
        };
 
        class Task
@@ -317,6 +320,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:
@@ -347,35 +372,37 @@ private:
        Msp::FS::Path state_file;
 
        ControlledVariable<bool> power;
+       bool halted;
 
        LocomotiveMap locomotives;
        MfxInfoArray mfx_info;
        AccessoryMap accessories;
        AccessoryPtrList accessory_queue;
        Accessory *active_accessory;
+       unsigned char active_index;
        Msp::Time::TimeStamp off_timeout;
 
        SensorMap sensors;
 
-       Msp::Mutex mutex;
        Queue<PendingCommand> command_queue;
        Queue<Tag> completed_commands;
        RefreshTask refresh;
        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);
        virtual bool get_power() const { return power; }
        virtual void halt(bool);
-       virtual bool is_halted() const { return false; }
+       virtual bool is_halted() const { return halted; }
 
        virtual const char *enumerate_protocols(unsigned) const;
 private: