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; }
};
Kind kind;
unsigned address;
unsigned bits;
+ unsigned valid_states;
ControlledVariable<unsigned> state;
+ unsigned uncertain;
unsigned target;
Msp::Time::TimeDelta active_time;
- Accessory(Kind, unsigned, unsigned);
+ Accessory(Kind, unsigned, unsigned, unsigned);
unsigned create_state_command(unsigned, bool, char *) const;
};
public:
void push(const T &);
bool pop(T &);
+ bool empty() const;
};
class Task
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:
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;
Msp::FS::Path state_file;
ControlledVariable<bool> power;
+ bool halted;
LocomotiveMap locomotives;
MfxInfoArray mfx_info;
SensorMap sensors;
- Msp::Mutex mutex;
+ Msp::Time::TimeDelta command_timeout;
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];
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:
virtual unsigned get_signal(unsigned) const;
private:
- unsigned add_accessory(Accessory::Kind, unsigned, unsigned);
+ unsigned add_accessory(Accessory::Kind, unsigned, unsigned, unsigned);
void remove_accessory(Accessory::Kind, unsigned);
void set_accessory(Accessory::Kind, unsigned, unsigned);
unsigned get_accessory(Accessory::Kind, unsigned) const;
+ void activate_accessory_by_mask(Accessory &, unsigned);
public:
virtual unsigned add_sensor(unsigned);