diff --git a/influxdb.cpp b/influxdb.cpp
index 2c71345..403da5f 100644
--- a/influxdb.cpp
+++ b/influxdb.cpp
@@ -19,6 +19,12 @@ void InfluxDB::SetURL(std::string url){
this->databaseIP = url;
}
+bool InfluxDB::TestingConnection(){
+ ShowDatabases();
+ if( respond != CURLE_OK ) return false;
+ return true;
+}
+
std::string InfluxDB::ShowDatabases(){
curl_easy_setopt(curl, CURLOPT_POST, 1);
@@ -34,8 +40,10 @@ std::string InfluxDB::ShowDatabases(){
Execute();
- printf("|%s|\n", readBuffer.c_str());
+ //printf("|%s|\n", readBuffer.c_str());
+ if( respond != CURLE_OK) return "";
+
databaseList.clear();
size_t pos = readBuffer.find("values");
@@ -88,7 +96,7 @@ std::string InfluxDB::Query(std::string databaseName, std::string query){
Execute();
- printf("|%s|\n", readBuffer.c_str());
+ //printf("|%s|\n", readBuffer.c_str());
return readBuffer;
}
@@ -129,7 +137,7 @@ void InfluxDB::Execute(){
respond = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &respondCode);
//printf("==== respond code %ld \n", respondCode);
- if( respond != CURLE_OK) printf("############# fail\n");
+ if( respond != CURLE_OK) printf("############# InfluxDB::Execute fail\n");
}
size_t InfluxDB::WriteCallBack(char *contents, size_t size, size_t nmemb, void *userp){
diff --git a/influxdb.h b/influxdb.h
index 310e642..c59c9cd 100644
--- a/influxdb.h
+++ b/influxdb.h
@@ -10,6 +10,8 @@
class InfluxDB{
private:
+ bool isURLValid;
+
CURL * curl;
CURLcode respond;
long respondCode;
@@ -29,6 +31,8 @@ class InfluxDB{
~InfluxDB();
void SetURL(std::string url);
+ bool TestingConnection();
+ bool IsURLValid() const {return isURLValid;}
/// Query
std::string ShowDatabases(); /// this save the list of database into databaseList
diff --git a/mainwindow.cpp b/mainwindow.cpp
index b174ce3..0ad03c9 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -30,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
nDigi = 0;
digiSetting = NULL;
+ influx = NULL;
readDataThread = NULL;
scope = NULL;
@@ -236,6 +237,8 @@ MainWindow::~MainWindow(){
if( scope != NULL ) delete scope;
if( digiSetting != NULL ) delete digiSetting;
+ if( influx != NULL ) delete influx;
+
}
//^################################################################ ACQ control
@@ -502,6 +505,8 @@ void MainWindow::UpdateScalar(){
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
+ if( influx ) influx->ClearDataPointsBuffer();
+
///===== Get trigger for all channel
for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){
if( digi[iDigi]->IsDummy() ) return;
@@ -515,24 +520,35 @@ void MainWindow::UpdateScalar(){
//}
//=========== another method, directly readValue
+
+ std::string haha[MaxNumberOfChannel] = {""};
+ double acceptRate[MaxNumberOfChannel] = {0};
+
digiMTX.lock();
for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch ++){
std::string time = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::ChannelRealtime); // for refreashing SelfTrgRate and SavedCount
- std::string haha = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::SelfTrgRate);
- leTrigger[iDigi][ch]->setText(QString::fromStdString(haha));
+ haha[ch] = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::SelfTrgRate);
+ leTrigger[iDigi][ch]->setText(QString::fromStdString(haha[ch]));
std::string kaka = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::ChannelSavedCount);
- double acceptRate = atoi(kaka.c_str())*1e9*1.0 / atol(time.c_str());
+ acceptRate[ch] = atoi(kaka.c_str())*1e9*1.0 / atol(time.c_str());
//if( kaka != "0" ) {
// printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate);
//}
- leAccept[iDigi][ch]->setText(QString::number(acceptRate,'f', 1));
-
- ///TODO============== push the trigger, acceptRate rate database
-
+ leAccept[iDigi][ch]->setText(QString::number(acceptRate[ch],'f', 1));
}
digiMTX.unlock();
+
+ ///============== push the trigger, acceptRate rate database
+ if( influx ){
+ for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch++ ){
+ influx->AddDataPoint("Rate,Bd=" + std::to_string(digi[iDigi]->GetSerialNumber()) + ",Ch=" + std::to_string(ch) + " value=" + haha[ch]);
+ }
+ }
}
+ influx->WriteData(DatabaseName.toStdString());
+ influx->ClearDataPointsBuffer();
+
}
//^###################################################################### Program Settings
@@ -721,6 +737,7 @@ bool MainWindow::OpenProgramSettings(){
if( ret ){
DecodeIPList();
+ SetupInflux();
return true;
}else{
@@ -752,6 +769,24 @@ void MainWindow::DecodeIPList(){
nDigi = IPList.size();
}
+void MainWindow::SetupInflux(){
+ if( influx ) {
+ delete influx;
+ influx = NULL;
+ }
+ if( DatabaseIP != ""){
+ influx = new InfluxDB(DatabaseIP.toStdString(), false);
+
+ if( influx->TestingConnection() ){
+ LogMsg("InfluxDB URL ("+ DatabaseIP + ") is Valid");
+ }else{
+ LogMsg(" InfluxDB URL ("+ DatabaseIP + ") is NOT Valid ");
+ delete influx;
+ influx = NULL;
+ }
+ }
+}
+
void MainWindow::SaveProgramSettings(){
IPListStr = lIPDomain->text();
@@ -784,6 +819,7 @@ void MainWindow::SaveProgramSettings(){
bnOpenDigitizers->setEnabled(true);
DecodeIPList();
+ SetupInflux();
OpenExpSettings();
diff --git a/mainwindow.h b/mainwindow.h
index 0a430c7..cc5efd0 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -52,6 +52,7 @@ private slots:
bool OpenProgramSettings();
void SaveProgramSettings();
void DecodeIPList();
+ void SetupInflux();
void OpenDirectory(int id);
void SetupNewExp();
@@ -93,6 +94,7 @@ private:
QGridLayout * scalarLayout;
ScalarThread * scalarThread;
QLabel * lbLastUpdateTime;
+ InfluxDB * influx;
//@------ ACQ things
QPushButton * bnStartACQ;