
.
Dependencies: SDHCFileSystem mbed
Revision 17:f0209f149b3e, committed 2012-12-16
- Comitter:
- TickTock
- Date:
- Sun Dec 16 23:00:29 2012 +0000
- Parent:
- 16:ec5fcd5d1bb8
- Child:
- 18:a4cf0547bfc2
- Commit message:
- Fixed
Changed in this revision
--- a/SDHCFileSystem.lib Sun Dec 16 22:08:23 2012 +0000 +++ b/SDHCFileSystem.lib Sun Dec 16 23:00:29 2012 +0000 @@ -1,1 +1,1 @@ -SDHCFileSystem#89846a293813 +SDHCFileSystem#1efbf75bd807
--- a/chan_fatfs.lib Sun Dec 16 22:08:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/emh203/code/chan_fatfs/#68378811b1e2
--- a/main.cpp Sun Dec 16 22:08:23 2012 +0000 +++ b/main.cpp Sun Dec 16 23:00:29 2012 +0000 @@ -87,7 +87,7 @@ #define upLine "\033[1A" #define maxBufLen 2048 #define canTimeout 5 -#define maxFileNum 20 +#define maxFileNum 100 void Log (char *message); void LogErr (char *message); @@ -108,7 +108,8 @@ DigitalOut can2_SleepMode(p28); // Use pin 28 to control the sleep mode of can2 bool logOpen = false; FILE *file; -char fileName[32] = "" ; +FILE *fTemp; +char fileName[35] = "" ; char writeBuffer[maxBufLen][13]; char c; char sTemp[35] ; @@ -284,7 +285,9 @@ file = fopen(fileName, "r"); pc.printf("Checked file %s\n",fileName); } - //fclose(file); //close and reopen for write + //close and reopen for write + //fclose(file); + wait(1); pc.printf("Using file %s\n",fileName); file = fopen(fileName, "wb"); @@ -294,14 +297,16 @@ } else { logOpen = true; readPointer=writePointer; + // delete next opening (only maxFileNum files allowed on SDRAM) + sprintf(sTemp,"/sd/cancan%d.alc",(fileNum+1)%maxFileNum); + remove(sTemp); + fTemp = fopen(sTemp, "r"); + if (!(fTemp == NULL)) { + pc.printf("Unable to delete %s\n",sTemp); + } else { + pc.printf("Removed file %s\n",sTemp); + } pc.printf("\nStarting Can Log %s\n",fileName); - //delete next opening (only maxFileNum files allowed on SDRAM) - sprintf(fileName,"/sd/cancan%d.alc",(fileNum+1)%maxFileNum); - pc.printf("Removing file %s\n",fileName); - remove(fileName); - file = fopen(fileName, "r"); - if (!(file == NULL)) - pc.printf("Unable to delete %s\n"); // write full timestamp secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 tsMsg.id=0xfff; @@ -319,6 +324,7 @@ } } // if (!logOpen) do { + //pc.printf("loop\n"); if (((writePointer+maxBufLen-readPointer)%maxBufLen)>(maxBufLen/2)||canIdle||(PB1==0)) { // Dump buffer if > 1/2 full, canbus has stopped, or PB1 pressed if (logOpen) { @@ -338,8 +344,9 @@ fclose(file); } } // if (logOpen) - } + } // if > 1/2 full, canbus has stopped, or PB1 pressed if (canIdle) { // canbus idle --> sleep to save power + pc.printf("Putting uC to sleep.\n"); //LPC_RTC->CIIR=0x00; // block RTC interrupts led1=0; led2=0; @@ -353,7 +360,7 @@ logOpen = false; // Start new file if asleep for more than an hour //LPC_RTC->CIIR=0x01; // re-enable RTC interrupts } - wait(0.25); // We get >2K messages per second + wait(0.2); // We get >2K messages per second } while ((PB1==1)&&(CD==1)&&logOpen); // keep going until button or SDram removed if (PB1==0) { @@ -364,6 +371,8 @@ pc.printf("Log stopped\n\n"); logOpen=false; wait(5); // wait 5 seconds to give time to remove SDRAM if desired + if (PB1==0) + readLog(); // dump file if PB still pressed } } else { pc.printf("\nNo SDRAM Inserted.\n\n");