influxDB: add test URL valid
This commit is contained in:
parent
8a48d43e7e
commit
86dfc176af
14
influxdb.cpp
14
influxdb.cpp
|
@ -19,6 +19,12 @@ void InfluxDB::SetURL(std::string url){
|
||||||
this->databaseIP = url;
|
this->databaseIP = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InfluxDB::TestingConnection(){
|
||||||
|
ShowDatabases();
|
||||||
|
if( respond != CURLE_OK ) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string InfluxDB::ShowDatabases(){
|
std::string InfluxDB::ShowDatabases(){
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||||
|
|
||||||
|
@ -34,8 +40,10 @@ std::string InfluxDB::ShowDatabases(){
|
||||||
|
|
||||||
Execute();
|
Execute();
|
||||||
|
|
||||||
printf("|%s|\n", readBuffer.c_str());
|
//printf("|%s|\n", readBuffer.c_str());
|
||||||
|
|
||||||
|
if( respond != CURLE_OK) return "";
|
||||||
|
|
||||||
databaseList.clear();
|
databaseList.clear();
|
||||||
|
|
||||||
size_t pos = readBuffer.find("values");
|
size_t pos = readBuffer.find("values");
|
||||||
|
@ -88,7 +96,7 @@ std::string InfluxDB::Query(std::string databaseName, std::string query){
|
||||||
|
|
||||||
Execute();
|
Execute();
|
||||||
|
|
||||||
printf("|%s|\n", readBuffer.c_str());
|
//printf("|%s|\n", readBuffer.c_str());
|
||||||
|
|
||||||
return readBuffer;
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +137,7 @@ void InfluxDB::Execute(){
|
||||||
respond = curl_easy_perform(curl);
|
respond = curl_easy_perform(curl);
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &respondCode);
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &respondCode);
|
||||||
//printf("==== respond code %ld \n", 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){
|
size_t InfluxDB::WriteCallBack(char *contents, size_t size, size_t nmemb, void *userp){
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
class InfluxDB{
|
class InfluxDB{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool isURLValid;
|
||||||
|
|
||||||
CURL * curl;
|
CURL * curl;
|
||||||
CURLcode respond;
|
CURLcode respond;
|
||||||
long respondCode;
|
long respondCode;
|
||||||
|
@ -29,6 +31,8 @@ class InfluxDB{
|
||||||
~InfluxDB();
|
~InfluxDB();
|
||||||
|
|
||||||
void SetURL(std::string url);
|
void SetURL(std::string url);
|
||||||
|
bool TestingConnection();
|
||||||
|
bool IsURLValid() const {return isURLValid;}
|
||||||
|
|
||||||
/// Query
|
/// Query
|
||||||
std::string ShowDatabases(); /// this save the list of database into databaseList
|
std::string ShowDatabases(); /// this save the list of database into databaseList
|
||||||
|
|
|
@ -30,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
|
||||||
|
|
||||||
nDigi = 0;
|
nDigi = 0;
|
||||||
digiSetting = NULL;
|
digiSetting = NULL;
|
||||||
|
influx = NULL;
|
||||||
readDataThread = NULL;
|
readDataThread = NULL;
|
||||||
scope = NULL;
|
scope = NULL;
|
||||||
|
|
||||||
|
@ -236,6 +237,8 @@ MainWindow::~MainWindow(){
|
||||||
if( scope != NULL ) delete scope;
|
if( scope != NULL ) delete scope;
|
||||||
if( digiSetting != NULL ) delete digiSetting;
|
if( digiSetting != NULL ) delete digiSetting;
|
||||||
|
|
||||||
|
if( influx != NULL ) delete influx;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//^################################################################ ACQ control
|
//^################################################################ ACQ control
|
||||||
|
@ -502,6 +505,8 @@ void MainWindow::UpdateScalar(){
|
||||||
|
|
||||||
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
|
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
|
||||||
|
|
||||||
|
if( influx ) influx->ClearDataPointsBuffer();
|
||||||
|
|
||||||
///===== Get trigger for all channel
|
///===== Get trigger for all channel
|
||||||
for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){
|
for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){
|
||||||
if( digi[iDigi]->IsDummy() ) return;
|
if( digi[iDigi]->IsDummy() ) return;
|
||||||
|
@ -515,24 +520,35 @@ void MainWindow::UpdateScalar(){
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//=========== another method, directly readValue
|
//=========== another method, directly readValue
|
||||||
|
|
||||||
|
std::string haha[MaxNumberOfChannel] = {""};
|
||||||
|
double acceptRate[MaxNumberOfChannel] = {0};
|
||||||
|
|
||||||
digiMTX.lock();
|
digiMTX.lock();
|
||||||
for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch ++){
|
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 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);
|
haha[ch] = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::SelfTrgRate);
|
||||||
leTrigger[iDigi][ch]->setText(QString::fromStdString(haha));
|
leTrigger[iDigi][ch]->setText(QString::fromStdString(haha[ch]));
|
||||||
std::string kaka = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::ChannelSavedCount);
|
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" ) {
|
//if( kaka != "0" ) {
|
||||||
// printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate);
|
// printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate);
|
||||||
//}
|
//}
|
||||||
leAccept[iDigi][ch]->setText(QString::number(acceptRate,'f', 1));
|
leAccept[iDigi][ch]->setText(QString::number(acceptRate[ch],'f', 1));
|
||||||
|
|
||||||
///TODO============== push the trigger, acceptRate rate database
|
|
||||||
|
|
||||||
}
|
}
|
||||||
digiMTX.unlock();
|
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
|
//^###################################################################### Program Settings
|
||||||
|
@ -721,6 +737,7 @@ bool MainWindow::OpenProgramSettings(){
|
||||||
if( ret ){
|
if( ret ){
|
||||||
|
|
||||||
DecodeIPList();
|
DecodeIPList();
|
||||||
|
SetupInflux();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
@ -752,6 +769,24 @@ void MainWindow::DecodeIPList(){
|
||||||
nDigi = IPList.size();
|
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 (<b>"+ DatabaseIP + "</b>) is Valid");
|
||||||
|
}else{
|
||||||
|
LogMsg("<font style=\"color : red;\"> InfluxDB URL (<b>"+ DatabaseIP + "</b>) is NOT Valid </font>");
|
||||||
|
delete influx;
|
||||||
|
influx = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::SaveProgramSettings(){
|
void MainWindow::SaveProgramSettings(){
|
||||||
|
|
||||||
IPListStr = lIPDomain->text();
|
IPListStr = lIPDomain->text();
|
||||||
|
@ -784,6 +819,7 @@ void MainWindow::SaveProgramSettings(){
|
||||||
bnOpenDigitizers->setEnabled(true);
|
bnOpenDigitizers->setEnabled(true);
|
||||||
|
|
||||||
DecodeIPList();
|
DecodeIPList();
|
||||||
|
SetupInflux();
|
||||||
|
|
||||||
OpenExpSettings();
|
OpenExpSettings();
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ private slots:
|
||||||
bool OpenProgramSettings();
|
bool OpenProgramSettings();
|
||||||
void SaveProgramSettings();
|
void SaveProgramSettings();
|
||||||
void DecodeIPList();
|
void DecodeIPList();
|
||||||
|
void SetupInflux();
|
||||||
void OpenDirectory(int id);
|
void OpenDirectory(int id);
|
||||||
|
|
||||||
void SetupNewExp();
|
void SetupNewExp();
|
||||||
|
@ -93,6 +94,7 @@ private:
|
||||||
QGridLayout * scalarLayout;
|
QGridLayout * scalarLayout;
|
||||||
ScalarThread * scalarThread;
|
ScalarThread * scalarThread;
|
||||||
QLabel * lbLastUpdateTime;
|
QLabel * lbLastUpdateTime;
|
||||||
|
InfluxDB * influx;
|
||||||
|
|
||||||
//@------ ACQ things
|
//@------ ACQ things
|
||||||
QPushButton * bnStartACQ;
|
QPushButton * bnStartACQ;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user