test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Revision 110:ffddff3ad2f2, committed 2013-06-30
- Comitter:
- TickTock
- Date:
- Sun Jun 30 19:52:38 2013 +0000
- Branch:
- Metric
- Parent:
- 109:3e6f0e8fca0d
- Child:
- 111:d1559bb25c43
- Commit message:
- Got battery and trip logs working. Fixed canlog to append (was overwriting previous data).
Changed in this revision
--- a/CHAN_FS/ff.c Sun Jun 30 17:52:58 2013 +0000 +++ b/CHAN_FS/ff.c Sun Jun 30 19:52:38 2013 +0000 @@ -2112,11 +2112,12 @@ if (res != FR_OK) LEAVE_FF(fp->fs, res); if (fp->flag & FA__ERROR) /* Check abort flag */ LEAVE_FF(fp->fs, FR_INT_ERR); - if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ -#if !_FS_READONLY - && !(fp->flag & FA_WRITE) -#endif - ) ofs = fp->fsize; +// if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ +//#if !_FS_READONLY /* LAJ: Always clip offset with file size */ +// && !(fp->flag & FA_WRITE) +//#endif + if (ofs > fp->fsize) + ofs = fp->fsize; /* LAJ: Always clip offset with file size */ ifptr = fp->fptr; fp->fptr = nsect = 0; fp->csect = 255;
--- a/main.cpp Sun Jun 30 17:52:58 2013 +0000 +++ b/main.cpp Sun Jun 30 19:52:38 2013 +0000 @@ -29,12 +29,12 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "108"; +char revStr[7] = "110"; // gg - revision string, max 6 characters + FATFS USBdrive; LocalFileSystem local("local"); bool waitasec = true; // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer) -//MSCFileSystem fs("usb"); // to write to a USB Flash Drive FRESULT mfr=f_mount(0,&USBdrive); time_t seconds ; @@ -59,11 +59,6 @@ PwmOut dled(p23); Beep spkr(p21); -// revision string, max 6 characters -// gg - revStr is used in 2 places -// gg - and is easy to edit here -// gg - added ZeroSecTick and revStr - bool debugMode = false; bool usbEn = false; bool logEn = true; @@ -297,9 +292,10 @@ if (repeatPoll) { // stop autopolling if enabled autoPoll.detach(); } - if (logOpen){ - f_close(&efile); - } // if (logOpen)*/ + //keep file open when asleep - new lseek not fast + //if (logOpen){ + // f_close(&efile); + //} // if (logOpen)*/ seconds = time(NULL); t = *localtime(&seconds) ; strftime(sTemp, 40, "Sleeping: %a %m/%d/%Y %X\n", &t); @@ -329,10 +325,15 @@ strftime(sTemp, 40, "Waking: %a %m/%d/%Y %X\n", &t); printMsg(sTemp); // wakeup date time if (time(NULL)>(secs+1800)) { - logOpen = false; // Start new file if asleep for more than 30 minutes + if (logOpen){ + f_close(&efile); + logOpen = false; // Start new file if asleep for more than 30 minutes + } // if (logOpen) if (secsNoTouch>100) secsNoTouch = 100; // also mostly reset user Idle counter } else if (logOpen){ // insert timestamp on each wake if logging enabled (disabled for now) - efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS); + //file kept open + //efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS); + //f_lseek(&efile,0xffffffff); // goto end of file (append existing) logEvent("WakingUp"); // gg - use messeges logTS(); // Date-Time at wakeup }
--- a/utility.cpp Sun Jun 30 17:52:58 2013 +0000 +++ b/utility.cpp Sun Jun 30 19:52:38 2013 +0000 @@ -396,6 +396,7 @@ can1SleepMode = 1; // disable TX can1.monitor(true); // set to snoop mode msgReq.detach(); // stop ticker + //logCP=true; //LAJ for bench test default: data[0]=0x30; //change to request next line message data[1]=0x01; @@ -607,7 +608,7 @@ } void logPackVoltages() { // Turbo3 - routine to dump CP values to text file - /*char sTemp[40]; + char sTemp[40]; struct tm t; // pointer to a static tm structure short unsigned max, min, jv, i, bd; unsigned avg; @@ -645,26 +646,30 @@ jv=0; } - FILE *bfile; - bfile = fopen("/usb/batvolt.txt", "a"); - if(bfile!=NULL) { + FIL bfile; + FRESULT bfr; + bfr = f_open(&bfile,"batvolt.txt",FA_WRITE|FA_OPEN_ALWAYS); + if(bfr==FR_OK) { + f_lseek(&bfile,0xffffffff); // go to end of file to append strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); - fprintf(bfile,"%s,%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",sTemp,gids,(float)SOC/10,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); - fprintf(bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); - fprintf(bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]); + f_printf(&bfile,"%s,",sTemp); + sprintf(sTemp,"%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); + f_printf(&bfile,"%s,",sTemp); + f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); + f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]); for(i=0; i<96; i++) { bd=(battData[i*2+3]<<8)+battData[i*2+4]; - fprintf(bfile,",%d",bd); + f_printf(&bfile,",%d",bd); } - fprintf(bfile,"\r\n"); - fclose(bfile); - }*/ + f_printf(&bfile,"\r\n"); + f_close(&bfile); + } logCP=false; showCP=true; } void tripLog() { // Daily log - /*char sTemp[40]; + char sTemp[40]; struct tm t; // pointer to a static tm structure short unsigned max, min, jv, i, bd; unsigned avg; @@ -702,22 +707,24 @@ jv=0; } - FILE *bfile; - bfile = fopen("/usb/triplog.txt", "a"); - if(bfile!=NULL) { + FIL bfile; + FRESULT bfr; + bfr = f_open(&bfile,"batvolt.txt",FA_WRITE|FA_OPEN_ALWAYS); + if(bfr==FR_OK) { + f_lseek(&bfile,0xffffffff); // go to end of file to append strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); - fprintf(bfile,"%s,%d,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%5.1f,%d,%d,%d,%d,%d",sTemp,gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); - fprintf(bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); - fprintf(bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]); + f_printf(&bfile,"%s,",sTemp); + sprintf(sTemp,"%d,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%5.1f,%d,%d,%d,%d,%d",gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); + f_printf(&bfile,"%s,",sTemp); + f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); + f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]); for(i=0; i<96; i++) { bd=(battData[i*2+3]<<8)+battData[i*2+4]; - fprintf(bfile,",%d",bd); + f_printf(&bfile,",%d",bd); } - fprintf(bfile,"\r\n"); - fclose(bfile); - }*/ - logCP=false; - showCP=true; + f_printf(&bfile,"\r\n"); + f_close(&bfile); + } } //LM - updates firmware off a usb key, eliminating the need to plug
--- a/utility.h Sun Jun 30 17:52:58 2013 +0000 +++ b/utility.h Sun Jun 30 19:52:38 2013 +0000 @@ -5,6 +5,8 @@ #include "TOUCH_TFTx2.h" #include "beep.h" #include <cctype> +#include "ff.h" + extern Timer timer; extern Ticker msgReq; extern volatile unsigned short secsNoMsg;