5 #include "../hubolib.h"
6 #include "../hubocfg.h"
44 string GetDateTime (
char seperator,
char timeSeperator);
50 int main(
int argc,
char* argv[])
54 printf (
"Usage: \n BatteryTest <AD pins> <sample rate [ms]> <DO pins> <duty count> <relax count> <charge/discharge {c, d}> <stop at AD> <filename>\n");
55 printf (
" example: BatteryTest 0 1000 128 3600 900 d 2152 discharge_test.csv\n");
59 unsigned char adPin = 0;
61 unsigned char doPins = 0;
64 char chargeDischarge =
'c';
65 unsigned long stopAtADValue = 0;
69 if (sscanf (argv[1],
"%hhu", &adPin) != 1 || adPin>7 )
71 printf (
"AD Pin could not be determined!\n");
76 if (sscanf (argv[2],
"%ld", &logSpeed) != 1)
78 printf (
"Logspeed could not be determined!\n");
83 if (sscanf (argv[3],
"%hhu", &doPins) != 1)
85 printf (
"DO Pin(s) could not be determined!\n");
90 if (sscanf (argv[4],
"%ld", &dutyCount) != 1 || dutyCount<1)
92 printf (
"Duty count could not be determined!\n");
97 if (sscanf (argv[5],
"%ld", &relaxCount) != 1 || relaxCount<1)
99 printf (
"Relax count could not be determined!\n");
104 if (sscanf (argv[6],
"%c", &chargeDischarge) != 1 || ! (chargeDischarge==
'c' || chargeDischarge==
'd'))
106 printf (
"Charge discahrge at could not be determined!\n");
111 if (sscanf (argv[7],
"%lu", &stopAtADValue) != 1)
113 printf (
"Stop at AD value could not be determined!\n");
118 if (sscanf (argv[8],
"%s",
g_buffer) != 1)
120 printf (
"File name could not be determined!\n");
133 printf (
"Error: Initialize\n");
138 sprintf (
g_buffer,
"%s %d %ld 0x%02X %ld %ld %c %ld %s\n", argv[0], (
int) adPin, logSpeed, (
int) doPins, dutyCount, relaxCount, chargeDischarge, stopAtADValue, sFile.c_str());
139 string sLine = string(
g_buffer) +
"\n";
152 unsigned long adcCount = 0;
154 unsigned long long relaxTime = 0;
155 unsigned long long dutyTime = 0;
156 unsigned long long adcDutySum = 0;
157 unsigned long long adcDutyCount = 0;
163 printf (
"%s\n", sLine.c_str());
167 for (
int count=0; count<relaxCount; count++)
170 usleep(1000L * logSpeed);
171 relaxTime += logSpeed;
174 if (chargeDischarge==
'c')
177 if (adcCount>stopAtADValue)
179 sLine =
"End of relaxing phase and voltage above limit.";
180 printf (
"%s\n", sLine.c_str());
186 printf (
"adcCount=%ld stopAtADValue=%ld\n", adcCount, stopAtADValue);
190 sLine = chargeDischarge==
'c' ?
"Charging" :
"Discharging";
191 printf (
"%s\n", sLine.c_str());
195 for (
int count=0; count<dutyCount; count++)
200 if (chargeDischarge==
'd')
203 if (adcCount<stopAtADValue)
205 sLine =
"Passing lower limit while discharging.";
206 printf (
"%s\n", sLine.c_str());
213 usleep(1000L * logSpeed);
214 dutyTime += logSpeed;
217 adcDutySum += adcCount;
229 for (
int count=0; count<relaxCount; count++)
232 usleep(1000L * logSpeed);
233 relaxTime += logSpeed;
237 sprintf (
g_buffer,
"Total relax time: %llds = %lfh\n", relaxTime/1000L, ((
double)(relaxTime/1000L))/3600.0);
242 sprintf (
g_buffer,
"Total duty time: %llds = %lfh\n", dutyTime/1000L, ((
double)(dutyTime/1000L))/3600.0);
249 sprintf (
g_buffer,
"Average ADC duty value: %ld digit\n", (
long)(adcDutySum / adcDutyCount));
269 unsigned long adcCount = 0;
272 sprintf (
g_buffer,
"%04ld", adcCount);
278 printf (
"%s", sLine.c_str());
287 struct tm *pNow = localtime (&t);
288 sprintf (
g_buffer,
"%02d.%02d.%d%c%02d%c%02d%c%02d", pNow->tm_mday, (pNow->tm_mon + 1), (pNow->tm_year + 1900), seperator, pNow->tm_hour, timeSeperator, pNow->tm_min, timeSeperator, pNow->tm_sec);
295 FILE* pFile = fopen (sFile.c_str(),
"a+");
298 bool bResult = fputs (sText.c_str(), pFile) > 0;
306 if (sprintf(
g_buffer,
"%ld", value) != 1)
const char * m_sI2CDevice
unsigned long GetADValueAndLog(unsigned char adPin, string sFile)
bool Wait_For_MCP3x08_Buffered_Values()
Waits until the input buffer of the MCP3x08 are initialized from the hardware.
#define MAX_MCP3x08_CHANNELS
int main(int argc, char *argv[])
bool Initialize()
Initializes the library.
bool Set_DO_Channels(unsigned char value)
Requests the background thread to update all 8 bits of the digital output to the value specified...
bool AppendFile(string sFile, string sText)
string Convert2String(long value)
void Uninitialize()
Releases any resources bound to the library.
bool Wait_For_MCP23017_Buffered_Values()
Waits until input and output buffers of the MCP23017 master are initialized from the hardware...
string GetDateTime(char seperator, char timeSeperator)