Commit 8ed67c52 authored by Dan Gebhardt's avatar Dan Gebhardt

Added:

- unbounded record time
- stats dump (by stdout) with USR1 signal
parent 38300979
......@@ -21,4 +21,5 @@ $(EXECUTABLE): $(OBJS)
# $(CC) $(LDFLAGS) $(SOURCES) -g -o $(EXECUTABLE) -L../DataqSDK_Linux/DataqSDK -ldataqsdk
clean:
rm -f *.o $(EXECUTABLE) *stackdump
\ No newline at end of file
rm -f *.o $(EXECUTABLE) *stackdump
(cd ../DataqSDK_Linux/DataqSDK/ && $(MAKE) clean)
\ No newline at end of file
......@@ -20,15 +20,21 @@ void SIG_dump_handler(int signum)
g_powmeas->dumpStats();
}
int main(int argc, char *argv[])
void SIG_exit_handler(int signum)
{
cout<<"received term signal: stopping recording..."<<endl;
g_powmeas->stopRecording();
}
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 );
sa.sa_handler = SIG_exit_handler;
sigaction( SIGTERM, &sa, 0 );
vector<double> calPoints;
......@@ -39,7 +45,7 @@ int main(int argc, char *argv[])
serialPath = argv[1];
PowerMeasure pwrMeasure( &serialPath, 2, 240.0, &calPoints );
g_powmeas = &pwrMeasure;
pwrMeasure.setFile( &sampleFile, 240*75 );
pwrMeasure.setFile( &sampleFile, 240*0 );
// pwrMeasure.enableVoltageLogging();
/*
char c;
......@@ -69,18 +75,21 @@ int main(int argc, char *argv[])
}catch( DataqException& datEx ){
cout<< datEx.what() <<endl;
}
while( pwrMeasure.isCapturing() )
// while(1)
{
// sleep(1);
// pause();
system("sleep 0.5s");
cout<<"average: "<<pwrMeasure.getAveI() <<endl;
cout<<"lastsample:"<<pwrMeasure.getLastSampleI()<<endl;
system("sleep 1s");
// cout<<"average: "<<pwrMeasure.getAveI() <<endl;
// cout<<"lastsample:"<<pwrMeasure.getLastSampleI()<<endl;
// cout<<"lastsample->V "<<
// pwrMeasure.rawToV((short int) pwrMeasure.getLastSampleRaw())<<endl;
}
return(0);
}
/**
* TODO:
- "dumpStats()": min, max, average, integral, last sample
- save "dump" to file - append existing, label with "timestamp"
- miscellaneous TODO's listed in code.
- refactor for niceness.
*/
......@@ -50,7 +50,10 @@ PowerMeasure::PowerMeasure( string* f_devicePath,
errorCode=0;
fStopLogger = 0;
lastSampleRaw = 0;
averageRaw = 0;
averageRaw = 0.0;
minRaw = 0x7fff;
maxRaw = 0;
total_mAH = 0.0;
fLogVoltage = 0;
//read in the calibration data for the channel, if it exists
......@@ -107,6 +110,13 @@ void PowerMeasure::startRecording()
&loggerThread, NULL, logData, (void *)this);
}
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::stopRecording()
{
fStopLogger = 1;
pthread_join( loggerThread, NULL );
}
///////////////////////////////////////////////////////////////////////////////
void* PowerMeasure::logData( void* ptr )
{
......@@ -124,12 +134,17 @@ void* PowerMeasure::logData( void* ptr )
pwrMeasure->averageRaw = 0;
//save data to disk until limit reached
while( sampleCnt <= pwrMeasure->sampleLimit )
//when sampleLimit == 0, record indefinitely
while( sampleCnt <= pwrMeasure->sampleLimit
|| pwrMeasure->sampleLimit == 0 )
{
//check request for thread destruction
if( pwrMeasure->fStopLogger == 1 )
{
pwrMeasure->loggerThreadBusy = 0;
pthread_exit(NULL);
}
//check if new data is available
// cout<<"checking for new data"<<endl;
if( pwrMeasure->dataq.NewData(newDataCnt) )
......@@ -148,7 +163,6 @@ void* PowerMeasure::logData( void* ptr )
newCurSamples[0] = pwrMeasure->rawToMa(newDataPoints[0]);
//write to disk
//cout<<newCurSamples[0]<<endl;
if( pwrMeasure->fLogVoltage == 1 )
{
fout<<pwrMeasure->rawToV(newDataPoints[0])<<",";
......@@ -159,11 +173,40 @@ void* PowerMeasure::logData( void* ptr )
//set last sample
pwrMeasure->setLastSampleRaw(newDataPoints[0]);
//set min
if( newDataPoints[0] < pwrMeasure->getMinRaw() )
pwrMeasure->setMinRaw( newDataPoints[0] );
//set max
if( newDataPoints[0] > pwrMeasure->getMaxRaw() )
pwrMeasure->setMaxRaw( newDataPoints[0] );
//average samples
double ave = (pwrMeasure->getAveRaw()*(sampleCnt+r-1)
+ newDataPoints[0])
+ newDataPoints[0])
/ (sampleCnt+r);
pwrMeasure->setAveRaw(ave);
//set total mA-h
double hrs = (sampleCnt+r+1)
/ (double)pwrMeasure->getSampleRate()
/ 60 / 60;
// cout<<"ave "<<pwrMeasure->rawToMa((short int)ave);
// cout<<" hrs "<<hrs;
// cout<<" ave*hrs "<<
// pwrMeasure->rawToMa((short int)ave)
// * hrs<<endl;
pwrMeasure->setTotal_mAH(
(double)(
pwrMeasure->rawToMa((short int)ave)
* hrs) );
// ave*(sampleCnt+r+1));
// /
// (double)pwrMeasure->getSampleRate() /
// 60);
}
fout.close();
}
......@@ -336,6 +379,48 @@ float PowerMeasure::getAveI( )
return rawToMa((short int)getAveRaw());
}
///////////////////////////////////////////////////////////////////////////////
short int PowerMeasure::getMinRaw( )
{
return minRaw;
}
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::setMinRaw(short int f_raw )
{
minRaw = f_raw;
}
///////////////////////////////////////////////////////////////////////////////
short int PowerMeasure::getMaxRaw( )
{
return maxRaw;
}
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::setMaxRaw(short int f_raw )
{
maxRaw = f_raw;
}
///////////////////////////////////////////////////////////////////////////////
double PowerMeasure::getTotal_mAH( )
{
return total_mAH;
}
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::setTotal_mAH( double f_mAH )
{
total_mAH = f_mAH;
}
///////////////////////////////////////////////////////////////////////////////
double PowerMeasure::getSampleRate( )
{
return sampleRate;
}
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::cal_SetZeroV()
{
......@@ -465,5 +550,10 @@ void PowerMeasure::disableVoltageLogging()
///////////////////////////////////////////////////////////////////////////////
void PowerMeasure::dumpStats()
{
//TODO
cout<<"last "<< rawToMa(lastSampleRaw)<<endl;
cout<<"average "<< rawToMa((short int)averageRaw)<<endl;
cout<<"min "<<rawToMa(minRaw)<<endl;
cout<<"max "<<rawToMa(maxRaw)<<endl;
cout<<"accum_mA-H "<<total_mAH<<endl;
}
......@@ -45,6 +45,7 @@ public:
int channel;
int CHANNELLIST[2];
double sampleRate;
double getSampleRate();
unsigned long long sampleLimit;
vector<double>* vTomAPoints;
string* filePath;
......@@ -59,6 +60,15 @@ public:
double averageRaw;
short int minRaw;
short int maxRaw;
double total_mAH;
short int getMinRaw();
void setMinRaw(short int f_raw);
short int getMaxRaw();
void setMaxRaw(short int f_raw);
double getTotal_mAH( );
void setTotal_mAH(double f_mAH );
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