Commit a50f8f5a authored by Dan Gebhardt's avatar Dan Gebhardt

Added a signal handler to "main" to dump the "current stats" of the logging.

The actual dump routine still needs to be added.
parent d2ede4b9
......@@ -3,26 +3,46 @@
#include <iomanip>
#include <vector>
#include <string>
#include <signal.h>
using namespace std;
#include "powerMeasure.h"
#include "exceptions.h"
PowerMeasure* g_powmeas = 0; // pointer to obj to be used by sig handlers
void SIG_dump_handler(int signum)
{
// cout<<"dump..."<<endl;
g_powmeas->dumpStats();
}
int main(int argc, char *argv[])
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_dump_handler;
sigaction( SIGUSR1, &sa, 0 );
vector<double> calPoints;
PowerMeasure::readVtoItable("cal.txt",&calPoints);
string sampleFile = "/tmp/dataq.dat";
string serialPath = "/dev/ttyS0";
if (argc == 2)
serialPath = argv[1];
serialPath = argv[1];
PowerMeasure pwrMeasure( &serialPath, 2, 240.0, &calPoints );
g_powmeas = &pwrMeasure;
pwrMeasure.setFile( &sampleFile, 240*75 );
// pwrMeasure.enableVoltageLogging();
char c;
/*
char c;
cout<<"DO YOU WISH TO CALIBRATE? (y/n)"<<endl;
cin>>c;
if( c == 'y' )
......@@ -42,17 +62,21 @@ int main(int argc, char *argv[])
pwrMeasure.cal_SetHighV(cal_highV);
}
*/
try{
pwrMeasure.startRecording( );
}catch( DataqException& datEx ){
cout<< datEx.what() <<endl;
}
while( pwrMeasure.isCapturing() )
// while(1)
{
// pause();
system("sleep 0.5s");
cout<<"average: "<<pwrMeasure.getAveI() <<endl;
// cout<<"lastsample:"<<pwrMeasure.getLastSampleI()<<endl;
cout<<"lastsample:"<<pwrMeasure.getLastSampleI()<<endl;
// cout<<"lastsample->V "<<
// pwrMeasure.rawToV((short int) pwrMeasure.getLastSampleRaw())<<endl;
}
......
/**
* TODO:
- "dumpStats()": min, max, average, integral, last sample
- miscellaneous TODO's listed in code.
- refactor for niceness.
*/
......@@ -460,3 +461,9 @@ void PowerMeasure::disableVoltageLogging()
{
fLogVoltage = 0;
}
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::dumpStats()
{
//TODO
}
......@@ -39,7 +39,7 @@ public:
vector<double>* f_OUT_vTomAPoints );
void enableVoltageLogging(); /* write voltage as well as current to file*/
void disableVoltageLogging();
void dumpStats();
private:
int channel;
......@@ -57,6 +57,8 @@ public:
vector<float> cal_highV; //pair of voltages: <dataq measured high, DMM measured high>
short int lastSampleRaw;
double averageRaw;
short int minRaw;
short int maxRaw;
string* devicePath;
int fLogVoltage;
void checkError(); //throws a DataqException if error flag on device is set
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment