X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Farducontrol.h;h=d794d00cd83150e4a6bcbb9c455d5faaaf049c1a;hb=4980a05569d29e19cb7af0d31627e17a94353a3b;hp=3a86ceeacc09790bbfc1c7afa04ac6dab29093ff;hpb=4b287b53e9127209864292f583b8ddbdd481d022;p=r2c2.git diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index 3a86cee..d794d00 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -166,11 +166,90 @@ private: Sensor(unsigned); }; + struct PendingCommand + { + Tag tag; + char command[15]; + unsigned char length; + unsigned repeat_count; + + PendingCommand(); + PendingCommand(GeneralCommand); + PendingCommand(Locomotive &, Locomotive::Command, unsigned = 0); + PendingCommand(Accessory &, Accessory::Command, unsigned = 0); + }; + + class Task + { + protected: + Task() { } + public: + virtual ~Task() { } + + virtual bool get_work(PendingCommand &) = 0; + virtual void process_reply(const char *, unsigned) { } + }; + + class RefreshTask: public Task + { + private: + ArduControl &control; + Locomotive *loco; + unsigned phase; + + public: + RefreshTask(ArduControl &); + + virtual bool get_work(PendingCommand &); + }; + + class S88Task: public Task + { + private: + ArduControl &control; + unsigned octets_remaining; + + public: + S88Task(ArduControl &); + + virtual bool get_work(PendingCommand &); + virtual void process_reply(const char *, unsigned); + }; + + class MfxAnnounceTask: public Task + { + private: + ArduControl &control; + Msp::Time::TimeStamp next; + + public: + MfxAnnounceTask(ArduControl &); + + virtual bool get_work(PendingCommand &); + }; + + class MfxSearchTask: public Task + { + private: + ArduControl &control; + Msp::Time::TimeStamp next; + unsigned size; + unsigned bits; + bool pending; + + public: + MfxSearchTask(ArduControl &); + + virtual bool get_work(PendingCommand &); + virtual void process_reply(const char *, unsigned); + }; + class ControlThread: public Msp::Thread { private: ArduControl &control; bool done; + std::vector tasks; public: ControlThread(ArduControl &); @@ -178,18 +257,9 @@ private: void exit(); private: virtual void main(); - }; - - struct QueuedCommand - { - Tag tag; - char command[15]; - unsigned char length; - - QueuedCommand(); - QueuedCommand(GeneralCommand); - QueuedCommand(Locomotive &, Locomotive::Command, unsigned = 0); - QueuedCommand(Accessory &, Accessory::Command, unsigned = 0); + bool get_work(PendingCommand &); + unsigned do_command(const PendingCommand &); + unsigned process_reply(const char *, unsigned); }; typedef std::map LocomotiveMap; @@ -211,7 +281,7 @@ private: AccessoryPtrList accessory_queue; Accessory *active_accessory; Msp::Time::TimeStamp off_timeout; - std::list command_queue; + std::list command_queue; std::list completed_commands; SensorMap sensors; @@ -278,8 +348,8 @@ public: virtual void flush(); private: - void push_command(const QueuedCommand &); - bool pop_command(QueuedCommand &); + void push_command(const PendingCommand &); + bool pop_command(PendingCommand &); void push_completed_tag(const Tag &); Tag pop_completed_tag(); };