Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions Example/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ int main(){
///////////////////////////////// logging alarms and alerts ///////////////////////////////

std::cout<<"Testing logging..."<<std::flush;
DAQ_inter.SendLog("unimportant message", 9, device_name); //sending log message to database specifing severity and device name
DAQ_inter.SendLog("severity 2 message", 2, device_name); //sending log message to database specifing severity and device name
DAQ_inter.SendLog("important message", 0, device_name);
DAQ_inter.SendLog("normal message"); // if not specified, the default severity level is 2 and the default name is the one passed to the DAQInterface constructor
DAQ_inter.SendLog("unimportant message"); // if not specified, the default severity level is 9 and the default name is the one passed to the DAQInterface constructor
if(verbose) std::cout<<"Logs sent"<<std::endl;

std::cout<<"Sending test alarm..."<<std::flush;
Expand Down Expand Up @@ -261,18 +261,34 @@ int main(){

//////////////////////////////// a Plotly plot /////////////////
// Monitoring can plot how something changes with respect to time, but what
// if you want a generic plot to appear on the web page? Use this class.
// if you want to make a specific plot to appear on the web page? Use this class.
// Each submitted plot with the same name is stored in the database as a different version.
/////////////////////////////////////////////////////////////////
std::vector<float> plot_x(5);
for (size_t i = 0; i < plot_x.size(); ++i) plot_x[i] = i;

std::vector<float> 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<float> plot_y(plot_x.size()); // see below

std::vector<std::string> 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;
Expand Down Expand Up @@ -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<std::string> 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;
Expand Down Expand Up @@ -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"<<std::endl;
}

//////////////////////////////////////////////////////////////////////////////////////////

Expand Down
8 changes: 4 additions & 4 deletions Example/Example.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def change_voltage(self, control_name: str) -> 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)

Expand Down Expand Up @@ -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
###########################################
Expand Down
3 changes: 2 additions & 1 deletion InterfaceConfig
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
4 changes: 2 additions & 2 deletions include/DAQInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/DAQInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down