Commit 9095c55e authored by Dan Gebhardt's avatar Dan Gebhardt

Initial checkin

parent 0cc9c313
CC=g++
LD=g++
CFLAGS= -Wall -c -g -I../DataqSDK_Linux/DataqSDK
LDFLAGS= #-L../DataqSDK_Linux/DataqSDK -ldataqsdk -lpthread
SOURCES= main.cpp powerMeasure.cpp exceptions.cpp
OBJS = main.o powerMeasure.o exceptions.o
EXECUTABLE=main
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJS)
(cd ../DataqSDK_Linux/DataqSDK/ && $(MAKE) static)
$(LD) $(LDFLAGS) $(OBJS) -o $(EXECUTABLE) -L../DataqSDK_Linux/DataqSDK -ldataqsdk -lpthread
%.o: %.cpp
$(CC) $(CFLAGS) -c $<
#debug: $(SOURCES)
# $(CC) $(LDFLAGS) $(SOURCES) -g -o $(EXECUTABLE) -L../DataqSDK_Linux/DataqSDK -ldataqsdk
clean:
rm -f *.o $(EXECUTABLE) *stackdump
\ No newline at end of file
1.11
0.0
1.21
0.39
2.33
4.76
6.71
21.41
10.0
33.92
#include <stdlib.h>
#include <string>
using namespace std;
#include "exceptions.h"
#include "dataqsdk.h"
#include "constants.h"
///////////////////////////////////////////////////////////////////////////////
// Implement classes to throw indicating errors
///////////////////////////////////////////////////////////////////////////////
DataqException::DataqException( long int f_errorcode )
: std::runtime_error("DataqException")
{
errorcode = f_errorcode;
}
DataqException::~DataqException() throw()
{
}
string DataqException::what()
{
if( errorcode == ENODEV ){
msg = "DataqException: No Device Specified";
}else if( errorcode == ENOSYS ){
msg = "DataqException: Function not supported";
}else if( errorcode == EBUSY ){
msg = "DataqException: Acquiring/Busy";
}else if( errorcode == ENOLINK ){
msg = "DataqException: Not Connected";
}else if( errorcode == EINVAL ){
msg = "DataqException: Bad parameter pointer";
}else if( errorcode == EBOUNDS ){
msg = "DataqException: Parameter value(s) out of bounds.";
}else{
msg = "DataqException: unknown";
}
return msg;
}
#include <stdexcept>
#include <string>
///////////////////////////////////////////////////////////////////////////////
// Define classes to throw indicating errors
///////////////////////////////////////////////////////////////////////////////
class DataqException : public std::runtime_error {
public:
DataqException(long int f_errorcode);
virtual ~DataqException() throw();
string what();
long int errorcode;
string msg;
};
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
#include "powerMeasure.h"
#include "exceptions.h"
int main(void)
{
vector<double> calPoints;
PowerMeasure::readVtoItable("cal.txt",&calPoints);
string sampleFile = "/tmp/dataq.dat";
string serialPath = "/dev/ttyS0";
PowerMeasure pwrMeasure( &serialPath, 2, 240.0, &calPoints );
pwrMeasure.setFile( &sampleFile, 240*75 );
// pwrMeasure.enableVoltageLogging();
char c;
/*
cout<<"DO YOU WISH TO CALIBRATE? (y/n)"<<endl;
cin>>c;
if( c == 'y' )
{
while( cin.get() != '\n' ){;} //read extra stuff from previous cin
//need to calibrate, if not already done so:
cout<<"CALIBRATE: 0-point. Set input channel to 0 and hit a key"<<endl;
cin.get();
//the "zero point" is set to whatever is the current input value
// on the channel
pwrMeasure.cal_SetZeroV();
cout<<"CALIBRATE: high-point. Set input channel to digital"
<<" input and enter the actual voltage measured by a DMM"<<endl;
float cal_highV = 0.0;
cin >> cal_highV;
//the second point on the linear calibration curve is set to what
pwrMeasure.cal_SetHighV(cal_highV);
}
*/
try{
pwrMeasure.startRecording( );
}catch( DataqException& datEx ){
cout<< datEx.what() <<endl;
}
while( pwrMeasure.isCapturing() )
{
system("sleep 0.5s");
cout<<"average: "<<pwrMeasure.getAveI() <<endl;
// cout<<"lastsample:"<<pwrMeasure.getLastSampleI()<<endl;
// cout<<"lastsample->V "<<
// pwrMeasure.rawToV((short int) pwrMeasure.getLastSampleRaw())<<endl;
}
return(0);
}
This diff is collapsed.
/**
Author: Dan Gebhardt
Group: Flux, University of Utah
Description:
Linux interface to the mote power measurement system, based on a
Dataq Instruments DI-194RS. Requires the DataqSDK library for Linux.
*/
#include "dataqsdk.h"
class PowerMeasure
{
public:
//PowerMeasure();
//f_channel = 1...4
PowerMeasure( string* f_devicePath,
int f_channel,
double f_sampleRate,
vector<double>* f_vTomAPoints );
~PowerMeasure();
//file to store recorded values
void setFile( string* f_filePath, int f_sampleLimit );
void startRecording();
void stopRecording();
int isCapturing();
int loggerThreadBusy; //TODO convert this to a semaphore
void cal_SetZeroV();
void cal_SetHighV(float f_highV);
void setLastSampleRaw( short int f_raw );
short int getLastSampleRaw( );
float getLastSampleI( );
void setAveRaw( double f_raw );
double getAveRaw();
float getAveI();
static void readVtoItable( string f_filepath,
vector<double>* f_OUT_vTomAPoints );
void enableVoltageLogging(); /* write voltage as well as current to file*/
void disableVoltageLogging();
private:
int channel;
int CHANNELLIST[2];
double sampleRate;
unsigned long long sampleLimit;
vector<double>* vTomAPoints;
string* filePath;
dataqsdk dataq;
long int errorCode;
pthread_t loggerThread;
int retLoggerThread;
int fStopLogger;
vector<float> cal_zeroV; //pair of voltages: <dataq measured 0, actual 0>
vector<float> cal_highV; //pair of voltages: <dataq measured high, DMM measured high>
short int lastSampleRaw;
double averageRaw;
string* devicePath;
int fLogVoltage;
void checkError(); //throws a DataqException if error flag on device is set
//executed in a separate thread which saves data to disk
static void* logData(void *);
void setupDevice(string* f_devicePath);
float rawToMa(short int f_raw); //convert raw data value to milli-amp float
float rawToV( short int f_raw );
};
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