Loading Common/Libraries/DiscosBackendProtocol/include/DiscosBackendProtocol 0 → 100644 +7 −0 Original line number Diff line number Diff line #ifndef DISCOS_BACKEND_PROTOCOL #define DISCOS_BACKEND_PROTOCOL #include "protocol.hpp" #include "command.hpp" #endif Common/Libraries/DiscosBackendProtocol/include/command.hpp 0 → 100644 +32 −0 Original line number Diff line number Diff line #ifndef DISCOS_BACKEND_COMMANDS_HPP #define DISCOS_BACKEND_COMMANDS_HPP #include "protocol.hpp" #include <string> using namespace std; namespace DiscosBackend{ class Command { public: static Message status(){return Message(REQUEST, "status");}; static Message version(){return Message(REQUEST, "version");}; static Message getConfiguration(){return Message(REQUEST, "get-configuration");}; static Message setConfiguration(string conf); static Message getIntegration(){return Message(REQUEST, "get-integration");}; static Message setIntegration(int integration); static Message getTpi(){return Message(REQUEST, "get-tpi");}; static Message getTp0(){return Message(REQUEST, "get-tp0");}; static Message time(){return Message(REQUEST, "time");}; static Message start(unsigned long long utctimestamp = 0); static Message stop(unsigned long long utctimestamp = 0); static Message setSection(long, double, double, long, long, double, long); static Message calOn(long interleave = 0); static Message setFilename(string filename); }; //class Command }; //namespace DiscosBackend #endif Common/Libraries/DiscosBackendProtocol/include/protocol.hpp 0 → 100644 +88 −0 Original line number Diff line number Diff line #ifndef DISCOS_BACKEND_PROTOCOL_HPP #define DISCOS_BACKEND_PROTOCOL_HPP #include <string> #include <sstream> #include <vector> #include <stdexcept> #define FAIL_CODE "fail" #define SUCCESS_CODE "ok" #define INVALID_CODE "invalid" #define TERMINATOR "\r\n" #define SEPARATOR ',' #define REQUEST_CODE '?' #define REPLY_CODE '!' using namespace std; namespace DiscosBackend{ typedef enum{REQUEST, REPLY} MESSAGE_TYPE; typedef enum{SUCCESS, INVALID, FAIL, NOCODE} MESSAGE_CODE; class BackendProtocolError : public runtime_error { public: BackendProtocolError(const char* msg) : runtime_error(string(msg)){}; }; class Message { public: Message( MESSAGE_TYPE type, string name, MESSAGE_CODE code = NOCODE, vector<string> arguments = vector<string>() ) : _type(type), _name(name), _code(code), _arguments(arguments){}; Message(string message, bool terminator = false); Message(const Message&); virtual ~Message(){}; MESSAGE_TYPE get_type(){return _type;}; string get_name(){return _name;}; MESSAGE_CODE get_code(){return _code;}; vector<string> get_arguments(){return _arguments;}; template <typename T> void add_argument(T argument){ stringstream ss; ss << argument; _arguments.push_back(ss.str()); }; template <typename T> T get_argument(const unsigned int& position) { if(position >= _arguments.size()) throw BackendProtocolError("cannot access command argument"); stringstream ss; ss << _arguments[position]; T result; try{ ss >> result; }catch(...){ throw BackendProtocolError("cannot convert argument to given type"); } return result; }; void add_argument(string); void add_argument(float); void add_argument(int); string toString(bool terminate = false); bool validate(); bool is_valid_reply_for(const Message&); bool is_valid_request_for(const Message&); bool is_success_reply(){return (_code == SUCCESS);}; private: MESSAGE_TYPE _type; string _name; MESSAGE_CODE _code; vector<string> _arguments; }; //class Message }; //namespace DiscosBackend #endif Common/Libraries/DiscosBackendProtocol/src/Makefile 0 → 100644 +82 −0 Original line number Diff line number Diff line #******************************************************************************* # PPPPPPPP # # "@(#) $Id$" # # Makefile of ........ # # who when what # -------- -------- ---------------------------------------------- # mbartolini 19/11/15 created # USER_LIB = -lstdc++ # # Includes (.h) files (public only) # --------------------------------- INCLUDES = command.hpp protocol.hpp DiscosBackendProtocol # # Libraries (public and local) # ---------------------------- LIBRARIES = DiscosBackendProtocolLib LIBRARIES_L = # # <brief description of lllll library> DiscosBackendProtocolLib_OBJECTS = protocol command DiscosBackendProtocolLib_LIBS = # # list of all possible C-sources (used to create automatic dependencies) # ------------------------------ CSOURCENAMES = \ $(foreach exe, $(EXECUTABLES) $(EXECUTABLES_L), $($(exe)_OBJECTS)) \ $(foreach rtos, $(RTAI_MODULES) , $($(rtos)_OBJECTS)) \ $(foreach lib, $(LIBRARIES) $(LIBRARIES_L), $($(lib)_OBJECTS)) # #>>>>> END OF standard rules # # INCLUDE STANDARDS # ----------------- ifdef ACSROOT MAKEDIR = $(shell if [ -f $(INTROOT)/include/acsMakefile ]; then \ echo $(INTROOT)/include; \ else \ echo $(ACSROOT)/include; \ fi;) include $(MAKEDIR)/acsMakefile else MAKEDIR = $(shell if [ -f $(INTROOT)/include/vltMakefile ]; then \ echo $(INTROOT)/include; \ else \ echo $(VLTROOT)/include; \ fi;) include $(MAKEDIR)/vltMakefile endif # # TARGETS # ------- all: do_all @echo " . . . 'all' done" clean : clean_all @echo " . . . clean done" clean_dist : clean_all clean_dist_all @echo " . . . clean_dist done" man : do_man @echo " . . . man page(s) done" install : install_all @echo " . . . installation done" #___oOo___ Common/Libraries/DiscosBackendProtocol/src/command.cpp 0 → 100644 +71 −0 Original line number Diff line number Diff line #include "command.hpp" using namespace DiscosBackend; Message Command::setConfiguration(string conf) { Message command(REQUEST, "set-configuration"); command.add_argument<string>(conf); return command; } Message Command::setIntegration(int integration) { Message command(REQUEST, "set-integration"); command.add_argument<int>(integration); return command; } Message Command::start(unsigned long long utctimestamp) { Message command(REQUEST, "start"); if(utctimestamp > 0) command.add_argument<unsigned long long>(utctimestamp); return command; } Message Command::stop(unsigned long long utctimestamp) { Message command(REQUEST, "stop"); if(utctimestamp > 0) command.add_argument<unsigned long long>(utctimestamp); return command; } Message Command::setSection(long input, double freq, double bandwidth, long feed, long pol, double sampleRate, long bins) { Message command(REQUEST, "set-section"); command.add_argument<long>(input); command.add_argument<double>(freq); command.add_argument<double>(bandwidth); command.add_argument<long>(feed); command.add_argument<long>(pol); command.add_argument<double>(sampleRate); command.add_argument<long>(bins); return command; } Message Command::calOn(long interleave) { Message command(REQUEST, "cal-on"); if(interleave > 0) command.add_argument<long>(interleave); return command; } Message Command::setFilename(string filename) { Message command(REQUEST, "set-filename"); command.add_argument<string>(filename); return command; } Loading
Common/Libraries/DiscosBackendProtocol/include/DiscosBackendProtocol 0 → 100644 +7 −0 Original line number Diff line number Diff line #ifndef DISCOS_BACKEND_PROTOCOL #define DISCOS_BACKEND_PROTOCOL #include "protocol.hpp" #include "command.hpp" #endif
Common/Libraries/DiscosBackendProtocol/include/command.hpp 0 → 100644 +32 −0 Original line number Diff line number Diff line #ifndef DISCOS_BACKEND_COMMANDS_HPP #define DISCOS_BACKEND_COMMANDS_HPP #include "protocol.hpp" #include <string> using namespace std; namespace DiscosBackend{ class Command { public: static Message status(){return Message(REQUEST, "status");}; static Message version(){return Message(REQUEST, "version");}; static Message getConfiguration(){return Message(REQUEST, "get-configuration");}; static Message setConfiguration(string conf); static Message getIntegration(){return Message(REQUEST, "get-integration");}; static Message setIntegration(int integration); static Message getTpi(){return Message(REQUEST, "get-tpi");}; static Message getTp0(){return Message(REQUEST, "get-tp0");}; static Message time(){return Message(REQUEST, "time");}; static Message start(unsigned long long utctimestamp = 0); static Message stop(unsigned long long utctimestamp = 0); static Message setSection(long, double, double, long, long, double, long); static Message calOn(long interleave = 0); static Message setFilename(string filename); }; //class Command }; //namespace DiscosBackend #endif
Common/Libraries/DiscosBackendProtocol/include/protocol.hpp 0 → 100644 +88 −0 Original line number Diff line number Diff line #ifndef DISCOS_BACKEND_PROTOCOL_HPP #define DISCOS_BACKEND_PROTOCOL_HPP #include <string> #include <sstream> #include <vector> #include <stdexcept> #define FAIL_CODE "fail" #define SUCCESS_CODE "ok" #define INVALID_CODE "invalid" #define TERMINATOR "\r\n" #define SEPARATOR ',' #define REQUEST_CODE '?' #define REPLY_CODE '!' using namespace std; namespace DiscosBackend{ typedef enum{REQUEST, REPLY} MESSAGE_TYPE; typedef enum{SUCCESS, INVALID, FAIL, NOCODE} MESSAGE_CODE; class BackendProtocolError : public runtime_error { public: BackendProtocolError(const char* msg) : runtime_error(string(msg)){}; }; class Message { public: Message( MESSAGE_TYPE type, string name, MESSAGE_CODE code = NOCODE, vector<string> arguments = vector<string>() ) : _type(type), _name(name), _code(code), _arguments(arguments){}; Message(string message, bool terminator = false); Message(const Message&); virtual ~Message(){}; MESSAGE_TYPE get_type(){return _type;}; string get_name(){return _name;}; MESSAGE_CODE get_code(){return _code;}; vector<string> get_arguments(){return _arguments;}; template <typename T> void add_argument(T argument){ stringstream ss; ss << argument; _arguments.push_back(ss.str()); }; template <typename T> T get_argument(const unsigned int& position) { if(position >= _arguments.size()) throw BackendProtocolError("cannot access command argument"); stringstream ss; ss << _arguments[position]; T result; try{ ss >> result; }catch(...){ throw BackendProtocolError("cannot convert argument to given type"); } return result; }; void add_argument(string); void add_argument(float); void add_argument(int); string toString(bool terminate = false); bool validate(); bool is_valid_reply_for(const Message&); bool is_valid_request_for(const Message&); bool is_success_reply(){return (_code == SUCCESS);}; private: MESSAGE_TYPE _type; string _name; MESSAGE_CODE _code; vector<string> _arguments; }; //class Message }; //namespace DiscosBackend #endif
Common/Libraries/DiscosBackendProtocol/src/Makefile 0 → 100644 +82 −0 Original line number Diff line number Diff line #******************************************************************************* # PPPPPPPP # # "@(#) $Id$" # # Makefile of ........ # # who when what # -------- -------- ---------------------------------------------- # mbartolini 19/11/15 created # USER_LIB = -lstdc++ # # Includes (.h) files (public only) # --------------------------------- INCLUDES = command.hpp protocol.hpp DiscosBackendProtocol # # Libraries (public and local) # ---------------------------- LIBRARIES = DiscosBackendProtocolLib LIBRARIES_L = # # <brief description of lllll library> DiscosBackendProtocolLib_OBJECTS = protocol command DiscosBackendProtocolLib_LIBS = # # list of all possible C-sources (used to create automatic dependencies) # ------------------------------ CSOURCENAMES = \ $(foreach exe, $(EXECUTABLES) $(EXECUTABLES_L), $($(exe)_OBJECTS)) \ $(foreach rtos, $(RTAI_MODULES) , $($(rtos)_OBJECTS)) \ $(foreach lib, $(LIBRARIES) $(LIBRARIES_L), $($(lib)_OBJECTS)) # #>>>>> END OF standard rules # # INCLUDE STANDARDS # ----------------- ifdef ACSROOT MAKEDIR = $(shell if [ -f $(INTROOT)/include/acsMakefile ]; then \ echo $(INTROOT)/include; \ else \ echo $(ACSROOT)/include; \ fi;) include $(MAKEDIR)/acsMakefile else MAKEDIR = $(shell if [ -f $(INTROOT)/include/vltMakefile ]; then \ echo $(INTROOT)/include; \ else \ echo $(VLTROOT)/include; \ fi;) include $(MAKEDIR)/vltMakefile endif # # TARGETS # ------- all: do_all @echo " . . . 'all' done" clean : clean_all @echo " . . . clean done" clean_dist : clean_all clean_dist_all @echo " . . . clean_dist done" man : do_man @echo " . . . man page(s) done" install : install_all @echo " . . . installation done" #___oOo___
Common/Libraries/DiscosBackendProtocol/src/command.cpp 0 → 100644 +71 −0 Original line number Diff line number Diff line #include "command.hpp" using namespace DiscosBackend; Message Command::setConfiguration(string conf) { Message command(REQUEST, "set-configuration"); command.add_argument<string>(conf); return command; } Message Command::setIntegration(int integration) { Message command(REQUEST, "set-integration"); command.add_argument<int>(integration); return command; } Message Command::start(unsigned long long utctimestamp) { Message command(REQUEST, "start"); if(utctimestamp > 0) command.add_argument<unsigned long long>(utctimestamp); return command; } Message Command::stop(unsigned long long utctimestamp) { Message command(REQUEST, "stop"); if(utctimestamp > 0) command.add_argument<unsigned long long>(utctimestamp); return command; } Message Command::setSection(long input, double freq, double bandwidth, long feed, long pol, double sampleRate, long bins) { Message command(REQUEST, "set-section"); command.add_argument<long>(input); command.add_argument<double>(freq); command.add_argument<double>(bandwidth); command.add_argument<long>(feed); command.add_argument<long>(pol); command.add_argument<double>(sampleRate); command.add_argument<long>(bins); return command; } Message Command::calOn(long interleave) { Message command(REQUEST, "cal-on"); if(interleave > 0) command.add_argument<long>(interleave); return command; } Message Command::setFilename(string filename) { Message command(REQUEST, "set-filename"); command.add_argument<string>(filename); return command; }