]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/arducontrol.h
React to overcurrent events
[r2c2.git] / source / libr2c2 / arducontrol.h
index 555280985767a7e37ea512607a0337359ac11618..8d27a2f572d74e561acdbc0266dc20561a777f8c 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
@@ -354,8 +357,9 @@ private:
                virtual void main();
                void init_baud_rate();
                bool get_work(PendingCommand &);
-               unsigned do_command(const PendingCommand &);
+               unsigned do_command(const PendingCommand &, const Msp::Time::TimeDelta &);
                unsigned process_reply(const char *, unsigned);
+               void set_power(bool);
        };
 
        typedef std::map<unsigned, Locomotive> LocomotiveMap;
@@ -369,6 +373,7 @@ private:
        Msp::FS::Path state_file;
 
        ControlledVariable<bool> power;
+       bool halted;
 
        LocomotiveMap locomotives;
        MfxInfoArray mfx_info;
@@ -380,7 +385,7 @@ private:
 
        SensorMap sensors;
 
-       Msp::Mutex mutex;
+       Msp::Time::TimeDelta command_timeout;
        Queue<PendingCommand> command_queue;
        Queue<Tag> completed_commands;
        RefreshTask refresh;
@@ -399,7 +404,7 @@ public:
        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: