Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed
Fork of CANary_corrupt by
Diff: main.cpp
- Revision:
- 205:51f0db4cab03
- Parent:
- 204:637771cfc74e
- Child:
- 206:cb5ef167dc7b
diff -r 637771cfc74e -r 51f0db4cab03 main.cpp
--- a/main.cpp Sat May 30 01:46:42 2015 +0000
+++ b/main.cpp Sat Jun 06 14:55:04 2015 +0000
@@ -12,8 +12,8 @@
// * fix bug where charging while on screws up efficiency computation
// * find better kWh estimate than gids
-// rev204
-// * Added a time limit on log files (deletes files older than set days)
+// rev205
+// *
// Include this before other header files
#include "precompile.h"
@@ -27,7 +27,7 @@
#include "displayModes.h"
#include "TOUCH_TFTx2.h"
-char revStr[7] = "204";
+char revStr[7] = "205";
unsigned long maxTarget = 1000;
FATFS USBdrive;
LocalFileSystem local("local");
@@ -129,7 +129,7 @@
bool laccOn = false;
float scale12V = 16.2; // R1:R2 ratio
float kWperGid = 0.080;
-char daysLog = 1; // How many days of log files to save
+char daysLog = 2; // How many days of log files to save
unsigned short startGids = 0; // Gids at start of trip
unsigned short dailyGids = 0; // Gids per day
bool getGids = false;
@@ -396,51 +396,54 @@
can1.attach(NULL);
}// if (logOpen)
- // Take advantage of the idle time to clear some room
- seconds = time(NULL);
- t = *localtime(&seconds) ;
-
- bool bit = false;
- int fmon;
- int fday;
- int ftime;
- rfile = fopen("/local/loglog.txt", "r");
- if (rfile!=NULL){
- file = fopen("/local/loglog.new", "w");
- while (!feof(rfile)) {
- fscanf(rfile,"%2d%2d%4d.alc\r\n",&fmon,&fday,&ftime);
- if ((fmon < 12) || (t.tm_mon > 1)){
- fday = fday + fmon*31; //crude - february will store 3 extra days of data
+ // Take advantage of the idle time to clear some room on USB drive
+ if(logEn && usbEn){
+ seconds = time(NULL);
+ t = *localtime(&seconds) ;
+ bool bit = false;
+ int fmon;
+ int fday;
+ int ftime;
+ int fdays;
+ rfile = fopen("/local/loglog.txt", "r");
+ if (rfile!=NULL){
+ //file = fopen("/local/loglog.new", "w");
+ while (!feof(rfile)) {
+ fscanf(rfile,"%2d%2d%4d.alc\r\n",&fmon,&fday,&ftime);
+ if ((fmon < 12) || (t.tm_mon > 1)){
+ fdays = fday + fmon*31 - 31; //crude - february will store 3 extra days of data
+ }else{
+ fdays = fday;
+ }
+ if ((fdays+daysLog)<(t.tm_mday+t.tm_mon*31)){ // Delete all files more than daysLog old
+ //bit=true;
+ sprintf(sTemp,"%02d%02d%04d.alc",fmon,fday,ftime);
+ //f_unlink(sTemp);
+ //sprintf(sTemp,"Deleted logfile %02d%02d%04d.alc",fmon,fday,ftime);
+ printMsg(sTemp);
+ }else{
+ //fprintf(file,"%02d%02d%04d.alc\r\n",fmon,fday,ftime);
+ }
}
- if ((fday+daysLog)<(t.tm_mday+t.tm_mon*31)){ // Delete all files more than daysLog old
- bit=true;
- sprintf(sTemp,"%02d%02d%04d.alc",fmon,fday,ftime);
- f_unlink(sTemp);
- sprintf(sTemp,"Deleted logfile %02d%02d%04d.alc",fmon,fday,ftime);
- printMsg(sTemp); // config file loaded
- }else{
- fprintf(file,"%02d%02d%04d.alc\r\n",fmon,fday,ftime);
+ //fclose (file);
+ fclose (rfile);
+ if (bit) {
+ remove ("/local/loglog.txt");
+ //rename not working so do it the hard way
+ //rename ("/local/loglog.new","/local/loglog.txt");
+ rfile = fopen("/local/loglog.new", "r");
+ file = fopen("/local/loglog.txt", "w");
+ while (!feof(rfile)) {
+ fscanf(rfile,"%s\r\n",&sTemp);
+ fprintf(file,"%s\r\n",sTemp);
+ }
+ fclose (file);
+ fclose (rfile);
}
- }
- fclose (file);
- fclose (rfile);
- if (bit) {
- remove ("/local/loglog.txt");
- //rename not working so do it the hard way
- //rename ("/local/loglog.new","/local/loglog.txt");
- rfile = fopen("/local/loglog.new", "r");
- file = fopen("/local/loglog.txt", "w");
- while (!feof(rfile)) {
- fscanf(rfile,"%s\r\n",&sTemp);
- fprintf(file,"%s\r\n",sTemp);
- }
- fclose (file);
- fclose (rfile);
- }
- remove ("/local/loglog.new");
- }
- wait(5); // wait a few seconds to ensure SDRAM is done
-
+ //remove ("/local/loglog.new");
+ }
+ wait(2); // wait a few seconds to ensure file access
+ } //if logen
seconds = time(NULL);
t = *localtime(&seconds) ;
strftime(sTemp, 40, "Sleeping: %a %m/%d/%Y %X\n", &t);
