From 44e0bb320e7a99fb099545392b0aff86ade6b36d Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 29 Jul 2025 18:10:53 +0000 Subject: [PATCH 1/3] add subject to monitoring data, split logging and montioring to different ports, set default log verbosity to 9 --- Example/Example.cpp | 54 ++++++++++++++++++++---------------------- Example/Example.py | 8 +++---- InterfaceConfig | 3 ++- SetupDB.sh | 5 ++++ include/DAQInterface.h | 4 ++-- src/DAQInterface.cpp | 4 ++-- 6 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 SetupDB.sh 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/SetupDB.sh b/SetupDB.sh new file mode 100644 index 00000000..10c9880e --- /dev/null +++ b/SetupDB.sh @@ -0,0 +1,5 @@ +export PGHOST=127.0.0.1 +export PGPORT=5432 +export PGUSER=root +export PGDATABASE=daq +export PGCOLOR=always diff --git a/include/DAQInterface.h b/include/DAQInterface.h index db896885..5d726b72 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& subject, const std::string& json_data, 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..8d054dfb 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& subject, const std::string& json_data, const std::string& device, int64_t timestamp){ - return m_services->SendMonitoringData(json_data, device, timestamp); + return m_services->SendMonitoringData(subject, json_data, device, timestamp); } From e17a8bef7cdaa2841224478d725923704036852f Mon Sep 17 00:00:00 2001 From: marc1uk Date: Wed, 30 Jul 2025 00:19:29 +0100 Subject: [PATCH 2/3] Delete SetupDB.sh not relevant for client --- SetupDB.sh | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 SetupDB.sh diff --git a/SetupDB.sh b/SetupDB.sh deleted file mode 100644 index 10c9880e..00000000 --- a/SetupDB.sh +++ /dev/null @@ -1,5 +0,0 @@ -export PGHOST=127.0.0.1 -export PGPORT=5432 -export PGUSER=root -export PGDATABASE=daq -export PGCOLOR=always From b0a77785a640722fe0182e1506ad162fa8f8d2c3 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 5 Aug 2025 10:39:40 +0000 Subject: [PATCH 3/3] swap subject and monitoring data order --- include/DAQInterface.h | 2 +- src/DAQInterface.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/DAQInterface.h b/include/DAQInterface.h index 5d726b72..dc3cd0f7 100644 --- a/include/DAQInterface.h +++ b/include/DAQInterface.h @@ -31,7 +31,7 @@ namespace ToolFramework { 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& subject, 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 8d054dfb..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& subject, 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(subject, json_data, device, timestamp); + return m_services->SendMonitoringData(json_data, subject, device, timestamp); }