made sleep time config and changed voltage levels for stby
authoraidan@aidan-laptop
Fri, 04 Jun 2010 17:21:55 +0100
changeset 23 56d1680cbb1e
parent 22 89d488d6a3c2
child 24 86613545ad8c
made sleep time config and changed voltage levels for stby
pbm
pbmd
pbmd.c
stateManager.c
stateManager.h
--- a/pbm	Thu Jun 03 10:43:40 2010 +0100
+++ b/pbm	Fri Jun 04 17:21:55 2010 +0100
@@ -20,7 +20,7 @@
 DESC="power manager daemon"
 NAME=pbmd
 DAEMON=/usr/sbin/$NAME
-DAEMON_ARGS="/var/log/battery.log /var/log/battery-snapshot.log /etc/bootflag 60"
+DAEMON_ARGS="/var/log/battery.log /var/log/battery-snapshot.log /etc/bootflag 60 22 6"
 PIDFILE=/var/run/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
Binary file pbmd has changed
--- a/pbmd.c	Thu Jun 03 10:43:40 2010 +0100
+++ b/pbmd.c	Fri Jun 04 17:21:55 2010 +0100
@@ -33,7 +33,9 @@
     FILE *logFile;
     char *snapFileName;
     char *bootFileName;
-    int sleepTime;    
+    int sleepTime; 
+    int sleepHourStart;
+    int sleepHourEnd;   
     int ret;
        
     char *bootflag = (char*) malloc( 2 );
@@ -53,6 +55,8 @@
     snapFileName = argv[2];             // Arg 2 is snapshot file
     bootFileName = argv[3];             // Arg 3 is boot flag file
     sleepTime = atoi( argv[4] );        // Arg 4 is sleep interval
+    sleepHourStart = atoi( argv[5] );   // Arg 5 is sleep hour start
+    sleepHourEnd = atoi( argv[6] );     // Arg 6 is sleep hour end
                                   
     if (logFile == 0) 
         syslog ( LOG_ERR, "Could not open log file: %s Continuing without logging", argv[1] );       
@@ -64,7 +68,7 @@
 
     fputs("\nYYYY-M-MDD,HH:MM:SS,mVolts,mAmps,State,Spike\n", logFile);
 
-    ret = test_interfacekit(progName, logFile, snapFileName, bootflag, boottime, sleepTime);// and off we go
+    ret = test_interfacekit(progName, logFile, snapFileName, bootflag, boottime, sleepTime, sleepHourStart, sleepHourEnd);// and off we go
         
     fclose ( logFile );
     ret == 0 ? syslog (LOG_NOTICE, "Program closing" ) : syslog (LOG_ERR, "Program closing with error code: %d", ret );
@@ -100,9 +104,9 @@
 {
     int i;
     
-    if ( argc != 5 )        // 5 args inc program name
+    if ( argc != 7 )        // 5 args inc program name
     {                                    
-        syslog (LOG_ERR, "Error: Program started with incorrect args. Usage: %s logfile snapshotfile bootflagfile sleeptime", argv[0]);
+        syslog (LOG_ERR, "Error: Program started with incorrect args. Usage: %s logfile snapshotfile bootflagfile sleeptime sleephourstart sleephourend", argv[0]);
         exit(1);
     }
 
@@ -110,13 +114,13 @@
     {
         if(argv[i] == NULL)
         {                                       
-            syslog (LOG_ERR, "Error: Program started with incorrect arg %d. Usage: %s logfile snapshotfile bootflagfile sleeptime", i, argv[0]);         
+            syslog (LOG_ERR, "Error: Program started with incorrect arg %d. Usage: %s logfile snapshotfile bootflagfile sleeptime sleephourstart sleephourend", i, argv[0]);         
             exit(1);
         }
     }
     
-    syslog (LOG_NOTICE, "Program started correctly with args: logfile=%s, snapshotfile=%s, bootflagfile=%s, sleeptime=%s", 
-        argv[1], argv[2], argv[3], argv[4]);
+    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]);
         
     return 0;
 }
--- a/stateManager.c	Thu Jun 03 10:43:40 2010 +0100
+++ b/stateManager.c	Fri Jun 04 17:21:55 2010 +0100
@@ -185,7 +185,7 @@
     return;
 }
 
-void getnewState(int Voltage, const char *bootflag, int *newState)
+void getnewState(int Voltage, const char *bootflag, int *newState, int sleepHourStart, int sleepHourEnd)
 {
     int localState = 0;
     
@@ -199,7 +199,7 @@
     if ( strncmp(bootflag, BOOTFLAG_NORMAL, 1) != 0 )   // Anything except an S will mean manual start
         localState = OVERRIDE;
         
-    else if (timeinfo->tm_hour < SLEEPHOUREND || timeinfo->tm_hour >= SLEEPHOURSTART )
+    else if (timeinfo->tm_hour < sleepHourEnd || timeinfo->tm_hour >= sleepHourStart )
         localState = SLEEP;
     
     else if ( Voltage >= GREEN) 
@@ -275,7 +275,7 @@
         return "INVALID STATE";            
 }         
         
-int test_interfacekit(const char *progName, FILE *logfile, const char *snapFileName, char * bootflag, time_t boottime, int sleepTime)
+int test_interfacekit(const char *progName, FILE *logfile, const char *snapFileName, char * bootflag, time_t boottime, int sleepTime, int sleepHourStart, int sleepHourEnd)
 {
     syslog ( LOG_DEBUG, 
             "test_interfacekit called with args: progName=%s, logfile=..., snapFileName=%s, bootflag=%s, boottime=..., sleepTime=%d",
@@ -390,7 +390,7 @@
         
         Amps = getAmps(IFK);
 
-        getnewState (Voltage, bootflag, &newState);
+        getnewState (Voltage, bootflag, &newState, sleepHourStart, sleepHourEnd);
 
         updateLogfile (logfile, Voltage, Amps, newState, spiking, progName);
         updateSnapshotfile (snapFileName, Voltage, Amps, newState, spiking);
@@ -459,8 +459,7 @@
         else if(newState == SLEEP)
         {
             // We're running during night time - go to sleep
-            wakeTimeStr = SLEEPTIMEENDSTR;
-            snprintf (buffer1, bufferSize, "%-s Wake@%-s", getStateDesc(newState), wakeTimeStr);
+            snprintf (buffer1, bufferSize, "%-s Wake@%2d:00", getStateDesc(newState), sleepHourEnd);
 
             CPhidgetTextLCD_setDisplayString (LCD, 1, buffer1);
         
--- a/stateManager.h	Thu Jun 03 10:43:40 2010 +0100
+++ b/stateManager.h	Fri Jun 04 17:21:55 2010 +0100
@@ -17,8 +17,8 @@
 #define SLEEP      4        // Sleep during the night
 #define UP         9        // Running normally - dont sleep
 
-#define GREEN   1160        // Voltage level for normal running
-#define AMBER   1139        // Voltage level at which we must go asleep
+#define GREEN   1145        // Voltage level for normal running
+#define AMBER   1135        // Voltage level at which we must go asleep
 
 #define IFK_WAIT_TIME   5000    //  5 second wait time
 #define LCD_WAIT_TIME   10000   // 10 second wait time
@@ -33,9 +33,9 @@
 #define STBYSHORT_TIME    1800      // 30 min
 #define OVERRIDE_TIME     1800      // 30 min
 
-#define SLEEPHOURSTART    22        // Time to start sleeping
-#define SLEEPHOUREND      6         // Time to end sleeping
-#define SLEEPTIMEENDSTR   "06:00"   // Time to end sleeping
+//#define SLEEPHOURSTART    22        // Time to start sleeping
+//#define SLEEPHOUREND      6         // Time to end sleeping
+//#define SLEEPTIMEENDSTR   "06:00"   // Time to end sleeping
 
 #define SPIKELIMIT        20
 
@@ -54,13 +54,13 @@
 int updateLogfile(FILE *logfile, int Voltage, int Amps, int state, int spiking, const char *progName);
 
 void getTimeString (int wakeTime, char *wakeTimeStr);
-void getnewState(int Voltage, const char *bootflag, int *newState);
+void getnewState(int Voltage, const char *bootflag, int *newState, int sleepHourStart, int sleepHourEnd);
 void closeCPhidget(CPhidgetHandle handle);
 int testVoltageSpike(int *prevVoltage, time_t *prevVoltageTime, int *Voltage, time_t *VoltageTime);
 
 char* getStateDesc(int state);
 
-int test_interfacekit(const char *progName, FILE *logfile, const char *snapFileName, char * bootflag, time_t boottime, int sleepTime);
+int test_interfacekit(const char *progName, FILE *logfile, const char *snapFileName, char * bootflag, time_t boottime, int sleepTime, int sleepHourStart, int sleepHourEnd);
 
 #endif