Telescope Control Library
EqMountServer.h
- Committer:
- caoyu@caoyuan9642-desktop.MIT.EDU
- Date:
- 2018-09-24
- Revision:
- 19:fd854309cb4c
- Parent:
- 10:e356188d208e
File content as of revision 19:fd854309cb4c:
/* * EqMountServer.h * * Created on: 2018��3��1�� * Author: caoyuan9642 */ #ifndef EQMOUNTSERVER_H_ #define EQMOUNTSERVER_H_ #include "MountServer.h" #include "EquatorialMount.h" class EquatorialMount; class EqMountServer; /** Command structure for the mount server */ struct ServerCommand { const char *cmd; /// Name of the command const char *desc; /// Description of the command int (*fptr)(EqMountServer *, const char *, int, char **); /// Function pointer to the command ServerCommand(const char *n = "", const char *d = "", int (*fp)(EqMountServer *, const char *, int, char **) = NULL) : cmd(n), desc(d), fptr(fp) { } }; #define MAX_COMMAND 128 #define ERR_WRONG_NUM_PARAM 1 #define ERR_PARAM_OUT_OF_RANGE 2 /** EqMount server class. Receives commands from a stream and execute on the binded EqMount. */ class EqMountServer: public MountServer { protected: EquatorialMount *eq_mount; /// EqMount to be binded FileHandle &stream; /// Input stream Thread thread;bool echo; /// Echo void task_thread(); /// Main task entrance void command_execute(ServerCommand &, int argn, char *argv[], char *buffer); /// To execute a server command public: /** Creates a server with input stream and optionally echoing to the stream. */ EqMountServer(FileHandle &stream, bool echo = false); virtual ~EqMountServer(); /** Bind to a EqMount. Commands will be ignored if no mount is binded. */ void bind(EquatorialMount &eq) { eq_mount = &eq; } /** @return binded EqMount */ EquatorialMount* getEqMount() const { return eq_mount; } /** @return associated stream */ FileHandle& getStream() const { return stream; } /** Add a command to the available commands. Must have unique names. */ static void addCommand(const ServerCommand &cmd); }; /** * Print to stream */ void stprintf(FileHandle &f, const char *fmt, ...); #endif /* EQMOUNTSERVER_H_ */