.

Dependencies:   SDHCFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Mon Dec 17 02:57:31 2012 +0000
Parent:
17:f0209f149b3e
Child:
19:610a71236b6e
Commit message:
Fixed timestamp bug

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Dec 16 23:00:29 2012 +0000
+++ b/main.cpp	Mon Dec 17 02:57:31 2012 +0000
@@ -188,6 +188,21 @@
     }
 }
 
+void logTS () {
+    CANMessage tsMsg;
+    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>>8)&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);
+}
 void recieve1() {
     CANMessage msg1;
     secsIdle=0; // reset deadman switch
@@ -210,7 +225,6 @@
     int readPointer=0;
     unsigned long secs;
     pc.baud(460800);        // change serial interface to pc to 450800, 8N1
-    CANMessage tsMsg;
     can1.frequency(500000);
     can2.frequency(500000);
     can1_SleepMode = 1;         // Monitor_only Mode
@@ -308,18 +322,7 @@
                     }
                     pc.printf("\nStarting Can Log %s\n",fileName);
                     // write full timestamp
-                    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);
+                    logTS();
                     fclose(file);
                 }
             } // if (!logOpen)
@@ -356,8 +359,13 @@
                     while (secsIdle>canTimeout)
                         //DeepPowerDown();
                         __wfi(); // freeze CPU and wait for interrupt (from canbus)
-                    if (time(NULL)>(secs+3600))
+                    if (time(NULL)>(secs+3600)) {
                         logOpen = false; // Start new file if asleep for more than an hour
+                    } else { // insert timestamp on each wake
+                        file = fopen(fileName, "ab");
+                        logTS();
+                        fclose(file);
+                    }
                     //LPC_RTC->CIIR=0x01; // re-enable RTC interrupts
                 }
                 wait(0.2); // We get >2K messages per second