diff --git a/Example/Example.cpp b/Example/Example.cpp index 456dbe32..0b9d5f47 100644 --- a/Example/Example.cpp +++ b/Example/Example.cpp @@ -89,9 +89,9 @@ int main(){ ///////////////////////////////// logging alarms and alerts /////////////////////////////// std::cout<<"Testing logging..."< plot_x(5); for (size_t i = 0; i < plot_x.size(); ++i) plot_x[i] = i; - + std::vector plot_y(plot_x.size()); + for (auto& y : plot_y) y = rand(); + std::string plot_layout = "{" "\"title\":\"A random plot\"," "\"xaxis\":{\"title\":\"x\"}," "\"yaxis\":{\"title\":\"y\"}" "}"; - - std::vector plot_y(plot_x.size()); // see below + + std::vector traces(2); + + Store store; + store.Set("x", plot_x); + store.Set("y", plot_y); + store >> traces[0]; + + for (auto& y : plot_y) y = rand(); + store.Set("x", plot_x); + store.Set("y", plot_y); + store >> traces[1]; + + DAQ_inter.SendPlotlyPlot("test_plot", traces, plot_layout); + /////////////////////////// generic SQL query example ////////////////////// std::string resp; @@ -309,27 +325,6 @@ int main(){ DAQ_inter.sc_vars["Start"]->SetValue(false); // important! reset the slow control value after use. DAQ_inter.sc_vars.AlertSend("new_event"); // example of sending alert to all DAQ devices - - ////////////////////////////////////// plot ///////////////////////////////////////////// - /// Each plot is stored in the database as a different version. We place - /// this example here to avoid sending a new plot each second. - { - std::vector traces(2); - - for (auto& y : plot_y) y = rand(); - Store store; - store.Set("x", plot_x); - store.Set("y", plot_y); - store >> traces[0]; - - for (auto& y : plot_y) y = rand(); - store.Set("x", plot_x); - store.Set("y", plot_y); - store >> traces[1]; - - DAQ_inter.SendPlotlyPlot("test_plot", traces, plot_layout); - }; - ////////////////////////////////////////////////////////////////////////////////////////// } last_started = started; @@ -378,7 +373,10 @@ int main(){ monitoring_data>>monitoring_json; /// prducing monitoring json // send to the database - DAQ_inter.SendMonitoringData(monitoring_json); + bool ok = DAQ_inter.SendMonitoringData("general", monitoring_json); + if(!ok){ + std::cerr<<"sendmonitoringdata failed"< str: # send a log message to the database, specifing severity and device name # severity 0 is critical, higher numbers => lower severity DAQ_inter.SendLog("important message", 0, device_name) - DAQ_inter.SendLog("unimportant message", 9, device_name) - # we may omit the severity and/or logging source, in which case a default severity of 2 will be used, + DAQ_inter.SendLog("severity 2 message", 2, device_name) + # we may omit the severity and/or logging source, in which case a default severity of 9 will be used, # and the logging source will be the device name we passed to the DAQInterface constructor - DAQ_inter.SendLog("normal message") + DAQ_inter.SendLog("unimportant message") # the signature for sending alarms is the same as logging messages DAQ_inter.SendAlarm("High current on channel 3", 0, device_name) @@ -336,7 +336,7 @@ def change_voltage(self, control_name: str) -> str: monitoring_data.__rshift__['std::string'](monitoring_json) # send to the Database for plotting on the webpage - DAQ_inter.SendMonitoringData(monitoring_json) + DAQ_inter.SendMonitoringData("general", monitoring_json) # retrieve and respond to control changes ########################################### diff --git a/InterfaceConfig b/InterfaceConfig index fac218c0..5aa55684 100644 --- a/InterfaceConfig +++ b/InterfaceConfig @@ -13,5 +13,6 @@ clt_dlr_socket_timeout 500 # inpoll_timeout 50 # keep these short! outpoll_timeout 50 # keep these short! command_timeout 2000 # -multicast_port 55554 # +log_port 55554 # +mon_port 55553 # multicast_address 239.192.1.1 # diff --git a/include/DAQInterface.h b/include/DAQInterface.h index db896885..dc3cd0f7 100644 --- a/include/DAQInterface.h +++ b/include/DAQInterface.h @@ -29,9 +29,9 @@ namespace ToolFramework { bool SQLQuery(const std::string& database, const std::string& query, std::string& response, const unsigned int timeout=300); bool SQLQuery(const std::string& database, const std::string& query, const unsigned int timeout=300); - bool SendLog(const std::string& message, unsigned int severity=2, const std::string& device="", const int64_t timestamp=0); //serverity levels are 0 = critical, 1 = Error, 2 = warning, 3= info , 4-9 debug + bool SendLog(const std::string& message, unsigned int severity=9, const std::string& device="", const int64_t timestamp=0); //serverity levels are 0 = critical, 1 = Error, 2 = warning, 3= info , 4-9 debug bool SendAlarm(const std::string& message, unsigned int level=0, const std::string& device="", const int64_t timestamp=0, const unsigned int timeout=300); - bool SendMonitoringData(const std::string& json_data, const std::string& device="", int64_t timestamp=0); + bool SendMonitoringData(const std::string& json_data, const std::string& subject, const std::string& device="", int64_t timestamp=0); bool SendCalibrationData(const std::string& json_data, const std::string& description, const std::string& device="", int64_t timestamp=0, int* version=nullptr, const unsigned int timeout=300); bool GetCalibrationData(std::string& json_data, int version=-1, const std::string& device="", const unsigned int timeout=300); bool SendDeviceConfig(const std::string& json_data, const std::string& author, const std::string& description, const std::string& device="", int64_t timestamp=0, int* version=nullptr, const unsigned int timeout=300); diff --git a/src/DAQInterface.cpp b/src/DAQInterface.cpp index 943b77cc..497138c4 100644 --- a/src/DAQInterface.cpp +++ b/src/DAQInterface.cpp @@ -146,10 +146,10 @@ bool DAQInterface::SendLog(const std::string& message, unsigned int severity, co } -bool DAQInterface::SendMonitoringData(const std::string& json_data, const std::string& device, int64_t timestamp){ +bool DAQInterface::SendMonitoringData(const std::string& json_data, const std::string& subject, const std::string& device, int64_t timestamp){ - return m_services->SendMonitoringData(json_data, device, timestamp); + return m_services->SendMonitoringData(json_data, subject, device, timestamp); }