//=================================================== file = sleepSim.c ===== //= Program to detemine sleep time for an idleCollect data series = //= - //=========================================================================== //= Notes: = //= 1) Input from input file "in.dat" to stdin (see example below) = //= 2) Output is to stdout = //= 3) Input is of format 111000111... where a "1" signifies that the = //= minute was on-active (or busy) and a "0" signifies that the = //= minutes was on-idle (or idle). = //= 4) Must initialize timeOut to desired inactivity time value = //=-------------------------------------------------------------------------= //= Example "in.dat" file: = //= = //= 11100011000011000000110101 = //=-------------------------------------------------------------------------= //= Example output (for above "in.dat" and timeOut = 3): = //= = //= ---------------------------------------------- sleepSim.c ----- = //= Total time = 26 minutes = //= Initialized time out = 3 minutes = //= Resulting sleep time = 4 minutes = //= Resulting number of wake-ups = 3 events = //= --------------------------------------------------------------- = //=-------------------------------------------------------------------------= //= Build: bcc32 sleepSim.c = //=-------------------------------------------------------------------------= //= Execute: sleepSim < in.dat = //=-------------------------------------------------------------------------= //= Author: Ken Christensen = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~christen = //= Email: christen@csee.usf.edu = //=-------------------------------------------------------------------------= //= History: KJC (07/17/12) - Genesis = //=========================================================================== //----- Include files ------------------------------------------------------- #include // Needed for printf() and feof() #include // Needed for exit() //----- Defines ------------------------------------------------------------- #define FALSE 0 // Boolean false #define TRUE 1 // Boolean true #define MAX_SIZE 50000 // Maximum size of input data in minutes //=========================================================================== //= Main program = //=========================================================================== void main(void) { int X[MAX_SIZE]; // Time series read from "in.dat" int N; // Number of values in "in.dat" int timeOut; // Inactivity timeout value int idleState; // Flag for idle state int idleCount; // Counter for idle state int wakeUpCount; // Counter for wake-up events int sleepTime; // Total sleep time char value; // Value read-in int i; // Loop counter // Initialize timeout value timeOut = 3; // Output banner printf("---------------------------------------------- sleepSim.c -----\n"); // Load the series X and determine N i = 0; while(1) { value = getchar(); if (feof(stdin)) break; if (value == '0') // Idle X[i] = 0; else if (value == '1') // Busy X[i] = 1; else X[i] = 2; // Bogus (should not occur) i++; } N = i - 1; // Loop to process X for a given timeout value idleState = FALSE; for (i=0; i