.
Dependencies: SDHCFileSystem mbed
Diff: main.cpp
- Revision:
- 6:594d9717e609
- Parent:
- 5:ddbc3d4bc266
- Child:
- 7:281df0ba57d0
diff -r ddbc3d4bc266 -r 594d9717e609 main.cpp --- a/main.cpp Mon Dec 03 13:55:04 2012 +0000 +++ b/main.cpp Mon Dec 03 14:04:54 2012 +0000 @@ -79,6 +79,7 @@ void Log (char *message); void LogErr (char *message); +extern "C" void mbed_reset(); time_t seconds ; DigitalIn CD(p17); @@ -265,51 +266,54 @@ RTC_Init(); // start the RTC Interrupts that sync the timer wait(1.1); // give time to sync - if(CD == 1) { - int fileNum = 0; - sprintf(fileName,"/sd/canary%d.evc",fileNum); - file = fopen(fileName, "r"); - while ((file != NULL)&&(fileNum++<100)) { - fclose(file); + while (true) { + if(CD == 1) { + int fileNum = 0; sprintf(fileName,"/sd/canary%d.evc",fileNum); file = fopen(fileName, "r"); - } - - file = fopen(fileName, "wb"); - if(file==NULL){ - pc.printf("\nUnable to open canlog\n\n\n\n"); + while ((file != NULL)&&(fileNum++<100)) { + fclose(file); + sprintf(fileName,"/sd/canary%d.evc",fileNum); + file = fopen(fileName, "r"); + } + + file = fopen(fileName, "wb"); + if(file==NULL){ + pc.printf("\nUnable to open canlog\n\n\n\n"); + mbed_reset(); + } else { + logOpen = true; + pc.printf("\nStarting Can Log %s\n\n\n\n",fileName); + unsigned long secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 + tsMsg.id=0xfff; + tsMsg.len=0xf; + tsMsg.data[0]=secs&0xff; + tsMsg.data[1]=(secs>>0)&0xff; + tsMsg.data[2]=(secs>>16)&0xff; + tsMsg.data[3]=secs>>24; + tsMsg.data[4]=0xff; + tsMsg.data[5]=0xff; + tsMsg.data[6]=0xff; + tsMsg.data[7]=0xff; + logCan(0,tsMsg); //write full timestamp + fclose(file); + } + ticker1.attach(&send1, .0052); //start sending messages + ticker2.attach(&send2, .0051); //start sending messages + + while ((PB1==1)&&(CD==1)){ + wait(0.25); // Keep logging until button pushed or SDRAM removed + } + ticker1.detach(); + ticker2.detach(); + logOpen=false; + pc.printf("Stopping log\n\n"); + wait(1); + if (CD==1) + readLog(); } else { - logOpen = true; - pc.printf("\nStarting Can Log %s\n\n\n\n",fileName); - unsigned long secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 - tsMsg.id=0xfff; - tsMsg.len=0xf; - tsMsg.data[0]=secs&0xff; - tsMsg.data[1]=(secs>>0)&0xff; - tsMsg.data[2]=(secs>>16)&0xff; - tsMsg.data[3]=secs>>24; - tsMsg.data[4]=0xff; - tsMsg.data[5]=0xff; - tsMsg.data[6]=0xff; - tsMsg.data[7]=0xff; - logCan(0,tsMsg); //write full timestamp - fclose(file); + pc.printf("\nNo SDRAM Inserted.\n\n\n\n"); } - } else { - pc.printf("\nNo SDRAM Inserted.\n\n\n\n"); + wait(1); } - - ticker1.attach(&send1, .0052); //start sending messages - ticker2.attach(&send2, .0051); //start sending messages - - while ((PB1==1)&&(CD==1)){ - wait(0.25); // Keep logging until button pushed or SDRAM removed - } - ticker1.detach(); - ticker2.detach(); - logOpen=false; - pc.printf("Stopping log\n\n"); - wait(1); - if (CD==1) - readLog(); } \ No newline at end of file