Binary file pbmd has changed
--- a/pbmd.c Fri Jun 18 14:17:01 2010 +0000
+++ b/pbmd.c Fri Jun 18 15:52:34 2010 +0000
@@ -74,7 +74,11 @@
clearShapFile(snapFileName);
- getBootflag ( bootFileName, bootflag );
+ ret=getBootflag ( bootFileName, bootflag );
+ if (ret!=0) {
+ syslog ( LOG_ERR, "Could not open bootflag file: %s Continuing without logging", bootFileName );
+
+ }
setBootflag ( bootFileName, BOOTFLAG_MAN_RESTART );
fputs("\nYYYY-M-MDD,HH:MM:SS,mVolts,mAmps,State,Spike\n",logFile);
@@ -127,8 +131,14 @@
exit(1);
}
- syslog (LOG_NOTICE, "Program started correctly with args: logfile=%s, snapshotfile=%s, bootflagfile=%s, sleeptime=%s sleephourstart=%s sleephourend=%s",
+ if (argc==7) {
+ syslog (LOG_NOTICE, "Program started correctly with args: logfile=%s, snapshotfile=%s, bootflagfile=%s, sleeptime=%s sleephourstart=%s sleephourend=%s",
argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
+ } else if (argc==9) {
+ syslog (LOG_NOTICE, "Program started correctly with args: logfile=%s, snapshotfile=%s, bootflagfile=%s, sleeptime=%s sleepstart=%s:%s sleepend=%s:%s",
+ argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
+ }
+
return 0;
}
@@ -161,6 +171,7 @@
{
syslog ( LOG_INFO, "Could not open bootflag file: %s - assuming manual override \"%s\"", bootFileName, BOOTFLAG_MAN_OVERRIDE );
sprintf(bootflag, BOOTFLAG_MAN_OVERRIDE);
+ snprintf(bootflag,2,BOOTFLAG_NORMAL);
return -1;
}
else // read from boot state file
@@ -173,7 +184,7 @@
else
{
syslog ( LOG_INFO, "Bootflag not normal, assuming manual restart \"%s\"", BOOTFLAG_MAN_RESTART );
- sprintf(bootflag, BOOTFLAG_MAN_RESTART);
+ snprintf(bootflag, 2, BOOTFLAG_MAN_RESTART);
}
fclose( fileboot );
--- a/stateManager.c Fri Jun 18 14:17:01 2010 +0000
+++ b/stateManager.c Fri Jun 18 15:52:34 2010 +0000
@@ -210,27 +210,42 @@
// let's assume not
int sleepytime=0;
// does sleep period span midnight?
+ syslog(LOG_DEBUG,"now: %02d:%02d start:%02d:%02d, end:%02d:%02d",
+ timeinfo->tm_hour,timeinfo->tm_min,
+ sleepHourStart,sleepMinStart,
+ sleepHourEnd,sleepMinEnd);
int spanmidnight=0;
if (sleepHourEnd<sleepHourStart) {
spanmidnight=1;
+ syslog(LOG_DEBUG,"Sleep over midnight");
} else if (sleepHourEnd==sleepHourStart &&
sleepMinStart>sleepMinEnd) {
spanmidnight=1;
- }
+ syslog(LOG_DEBUG,"Sleep over midnight (2)");
+
+ } else {
+ syslog(LOG_DEBUG,"Siesta!");
+ }
if (spanmidnight==0) { // sleep if start<=now<end
if (
(timeinfo->tm_hour>=sleepHourStart && timeinfo->tm_min>=sleepMinStart)
&&
- (timeinfo->tm_hour<sleepHourEnd && timeinfo->tm_min<sleepMinEnd)
- )
+ (timeinfo->tm_hour<sleepHourEnd
+ || (timeinfo->tm_hour==sleepHourEnd && timeinfo->tm_min<sleepMinEnd))
+ ) {
sleepytime=1;
+ syslog(LOG_DEBUG,"set sleepytime (siesta)");
+ }
} else { // sleep if start<=now || now<end
if (
(timeinfo->tm_hour>=sleepHourStart && timeinfo->tm_min>=sleepMinStart)
||
- (timeinfo->tm_hour<sleepHourEnd && timeinfo->tm_min<sleepMinEnd)
- )
+ (timeinfo->tm_hour<sleepHourEnd
+ || (timeinfo->tm_hour==sleepHourEnd && timeinfo->tm_min<sleepMinEnd))
+ ) {
sleepytime=1;
+ syslog(LOG_DEBUG,"set sleepytime (midnight)");
+ }
}
// Anything except an S will mean manual start
@@ -320,9 +335,10 @@
int sleepMinEnd)
{
syslog ( LOG_DEBUG,
- "test_interfacekit called with args: progName=%s, logfile=..., snapFileName=%s, bootflag=%s, boottime=..., sleepTime=%d",
+ "test_interfacekit args: progName=%s, snapFileName=%s, bootflag=%s, pollTime=%d",
progName, snapFileName, bootflag, sleepTime);
-
+ syslog (LOG_DEBUG, "\tsleepstart: %02d:%02d, sleepend: %02d:%02d",
+ sleepHourStart,sleepMinStart,sleepHourEnd,sleepMinEnd);
int err;
int lightTrigger;
int prevVoltage = 0, Voltage = 0, Amps = 0;