Advertisement
Advertisement
| 03.29.2008 at 02:43PM PDT, ID: 23279955 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "../Inc/tlm_defs.h"
#include "../Inc/raw_defs.h"
/******************************************************************************
* local prototypes
******************************************************************************/
static void create_analyzed_file (void);
/******************************************************************************
* global variables
******************************************************************************/
int Current_Day;
int system_up =1;
/******************************************************************************
* Main program
******************************************************************************/
main ( )
{
create_analyzed_file ();
while (system_up)
{
//This is where I need to start checking the directory for rawlogs
printf("Right before sleep");
sleep(60);
}
}
static void create_analyzed_file (void)
{
FILE * pFile;
struct tm *now_ptr;
time_t now;
char date_str[5]; // MMDDYY plus NULL
char file_name[24];
char tmp_name[26];
char tmp[26]={0x0};
char cmd[300];
//time(&now);
now = time(NULL);
now_ptr = localtime(&now);
Current_Day = now_ptr->tm_yday;
//Current_Day = localtime(&now);
/** WARNING: tm_year is defined as (Actual year - 1900) this means
that in the year 2000 %d, tm_year will print "100"
without this additional test.
---------------------------------------------------- */
if(now_ptr->tm_year >= RT_V_YEAR_2000_MOD)
{
now_ptr->tm_year %= RT_V_YEAR_2000_MOD;
}
strftime(date_str, sizeof(date_str), "%m%d", now_ptr);
sprintf(file_name, "rawlog_analyzed_%s.log",date_str);
//find out how many rawlog_analyzed files have been abandend
FILE *in=popen("ls rawlog_analyzed*","r");
if (fgets(tmp,sizeof(tmp),in)!=NULL)
{
strcpy(tmp_name,tmp);
if (strstr(tmp_name,file_name))
{
pFile = fopen (file_name, "a");
printf("Appending to file");
}
else
{
//this is an old file and needs to be printed to the webpage
sprintf(cmd, "rm %s", tmp_name);
system(cmd);
printf("Deleting old file\n");
pFile = fopen (file_name, "w");
printf("OPening new file\n");
}
}
//todays file exists so just append to it
}
|