2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Sat Dec 22 20:28:52 2018 +0000
Parent:
28:eab1b0680bb2
Child:
30:ed791f1f7f7d
Commit message:
Updates to shell. Implemented eventqueue-based data logging for gps. added start/stop/enabled functions to Logger and shell commands to start/stop/status logging

Changed in this revision

Logger.cpp Show annotated file Show diff for this revision Revisions of this file
Logger.h Show annotated file Show diff for this revision Revisions of this file
SimpleShell.lib Show annotated file Show diff for this revision Revisions of this file
SystemState.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Logger.cpp	Sat Dec 22 06:56:55 2018 +0000
+++ b/Logger.cpp	Sat Dec 22 20:28:52 2018 +0000
@@ -2,37 +2,43 @@
 
 Logger::Logger(const char *file) {
     _file = file;
+    _fp = NULL;
+}
+
+
+void Logger::start() {
+    if (_fp == NULL) _fp = fopen(_file, "a");
+}
+
+
+void Logger::stop() {
+    if (_fp && fclose(_fp) != EOF) {
+        _fp = NULL;
+    }
+}
+
+
+bool Logger::enabled() {
+    return (_fp != NULL);
 }
 
 
 void Logger::log_gps(GpsData gd) {
-    _open();
-    fprintf(_fp, "G,%3.7f,%3.7f,%3.1f,%2.1f,%2.1f,%d\n",
-        gd.latitude, 
-        gd.longitude,
-        gd.course,
-        gd.speed,
-        gd.hdop,
-        gd.svcount
-    );
-    _close();
+    if (enabled()) {
+        fprintf(_fp, "G,%llu,%3.9f,%3.9f,%3.1f,%2.1f,%2.1f,%d\n",
+            Kernel::get_ms_count(),
+            gd.latitude, 
+            gd.longitude,
+            gd.course,
+            gd.speed,
+            gd.hdop,
+            gd.svcount
+        );
+    }
 }
 
 
 void Logger::log_estimation() {
-    _open();
-    
-    _close();
-}
-
-
-void Logger::_open() {
-    _fp = fopen(_file, "a");
-}
-
-
-void Logger::_close() {
-    if (_fp) {
-        fclose(_fp);
+    if (enabled()) {
     }
 }
\ No newline at end of file
--- a/Logger.h	Sat Dec 22 06:56:55 2018 +0000
+++ b/Logger.h	Sat Dec 22 20:28:52 2018 +0000
@@ -7,14 +7,15 @@
 class Logger {
 public:
     Logger(const char *file);
+    void start();
+    void stop();
+    bool enabled();
     void log_gps(GpsData gd);
     void log_estimation();
 
 private:
     const char *_file;
     FILE *_fp;
-    void _open();
-    void _close();
 };
 
 #endif
\ No newline at end of file
--- a/SimpleShell.lib	Sat Dec 22 06:56:55 2018 +0000
+++ b/SimpleShell.lib	Sat Dec 22 20:28:52 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/shimniok/code/SimpleShell/#2b5ed529ab37
+https://os.mbed.com/users/shimniok/code/SimpleShell/#bf5f5ea4e762
--- a/SystemState.h	Sat Dec 22 06:56:55 2018 +0000
+++ b/SystemState.h	Sat Dec 22 20:28:52 2018 +0000
@@ -53,6 +53,7 @@
  */
 
 typedef struct {
+    float dt;
     double latitude;
     double longitude;
     float course;
--- a/main.cpp	Sat Dec 22 06:56:55 2018 +0000
+++ b/main.cpp	Sat Dec 22 20:28:52 2018 +0000
@@ -42,9 +42,8 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 // Logging
-EventQueue logQueue(8 * EVENTS_EVENT_SIZE);
-Logger logger("/etc/test.log");
-
+EventQueue logQueue(16 * EVENTS_EVENT_SIZE);
+Logger logger("/log/test.csv");
 
 ///////////////////////////////////////////////////////////////////////////////
 // Updater
@@ -66,9 +65,9 @@
     
     led2 = !led2;
     ublox.read(d.latitude, d.longitude, d.course, d.speed, d.hdop, d.svcount);   
-    //logQueue.call(&logger, &Logger::log_gps, d);
+    logQueue.call(&logger, &Logger::log_gps, d);
 }
-    
+
 // ISR for GPS serial, passes off to thread
 void gps_handler() {
     while (s.readable()) {
@@ -125,6 +124,31 @@
     printf("Encoder: %d\n", u->encoder());
 }
 
+void log(int argc, char **argv)
+{
+    char *usage = "usage: log [start|stop]";
+    
+    if (argc == 1) {
+        printf("logging ");
+        if (logger.enabled())
+            printf("enabled");
+        else
+            printf("disabled");
+        printf("\n");
+    } else if (argc == 2) {
+        if (!strcmp("start", argv[1])) {
+            logger.start();
+        } else if (!strcmp("stop", argv[1])) {
+            logger.stop();
+        } else {
+            puts(usage);
+        }
+    } else {
+        puts(usage);
+    }
+}
+
+
 void bridge_uart1(int argc, char **argv) {
     RawSerial s(UART1TX, UART1RX, 38400);
     while (1) {
@@ -185,13 +209,13 @@
     updaterThread.start(callback(&updaterQueue, &EventQueue::dispatch_forever));
     
     printf("Starting gps...\n");
-    Thread gpsThread(osPriorityHigh, 256, 0, "gps");
+    Thread gpsThread(osPriorityHigh, 2048, 0, "gps");
     gpsThread.start(callback(&gpsQueue, &EventQueue::dispatch_forever));
     ublox.subscribe(gps_callback);
     s.attach(gps_handler);
     
     printf("Starting logging...\n");    
-    Thread logThread(osPriorityNormal, 256, 0, "log");
+    Thread logThread(osPriorityNormal, 2048, 0, "log");
     logThread.start(callback(&logQueue, &EventQueue::dispatch_forever));
 
     printf("Starting shell...\n");
@@ -201,6 +225,7 @@
     sh.attach(read_gps, "gps");
     sh.attach(reset, "reset");
     sh.attach(stats, "stats");
+    sh.attach(log, "log");
     sh.run();
     
     while (true) {