* Added simple console logger application.
authorUrban Wallasch <urban.wallasch@freenet.de>
Sun, 21 Jul 2019 21:40:38 +0000 (23:40 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sun, 21 Jul 2019 21:40:38 +0000 (23:40 +0200)
.gitignore
Makefile
telelogger.c [new file with mode: 0644]

index c6d1916f130b3ab390311780a25eecf7a93ac700..65014a49ae342c98b4b0509496156ed460ca4095 100644 (file)
@@ -1,3 +1,4 @@
 *.o
 *.so
 telehttpd
+telelogger
index e4156d456d6653bcda4b48c4ebcb71b544bcbd43..00c00745fcbc4a2706cf3d8251ad37763a015786 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,7 @@ endif
 
 .PHONY: all clean
 
-all: telehttpd telemetry.so
+all: telehttpd telelogger telemetry.so
 
 telemetry.so: telemetry.cpp $(SDK_HEADERS)
        g++ -o $@ -fPIC -Wall --shared -Wl,$(LIB_NAME_OPTION),$@ $(SDK_INCLUDES) telemetry.cpp
@@ -33,6 +33,9 @@ telemetry.so: telemetry.cpp $(SDK_HEADERS)
 telehttpd: telehttpd.o shmget.o net.o fserv.o ntime.o
        $(CC) $(LDFLAGS) -o $@ -pthread $^
 
+telelogger: telelogger.o shmget.o net.o fserv.o ntime.o
+       $(CC) $(LDFLAGS) -o $@ $^
+
 %.o: %.c $(SELF)
        $(CC) -c $(CFLAGS) -o $*.o $*.c
 
diff --git a/telelogger.c b/telelogger.c
new file mode 100644 (file)
index 0000000..b79b145
--- /dev/null
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "fserv.h"
+#include "net.h"
+#include "log.h"
+#include "shmget.h"
+
+static int log_console(void) {
+    uint64_t last_timestamp = telemetry->timestamp;
+    while ( 1 ) {
+        printf("timestamp: %"PRIu64"\n", telemetry->timestamp);
+    //    uint64_t raw_rendering_timestamp;
+    //    uint64_t raw_simulation_timestamp;
+    //    uint64_t raw_paused_simulation_timestamp;
+        if ( telemetry->placement_available ) {
+            printf( "position: %.3f, %.3f, %.3f\n",
+                    telemetry->x, telemetry->y, telemetry->z );
+            printf( "orientation: h:%.1f p:%.1f r:%.1f\n",
+                    telemetry->heading * 360.0, telemetry->pitch * 360.0, telemetry->roll * 360.0  );
+        }
+        else {
+            printf( "position: n.a.\n" );
+            printf( "orientation: n.a.\n" );
+        }
+        printf( "speed: %.1fkm/h (%.1fm/s)\n", telemetry->speed * 3.6, telemetry->speed );
+        printf( "cctrl: %.1fkm/h (%.1fm/s)\n", telemetry->cc * 3.6, telemetry->cc );
+        printf( "rpm: %.0f\n", telemetry->rpm );
+        printf( "gear: %d\n", telemetry->gear );
+        printf( "fc_avg: %.1f\n", telemetry->fc_avg );
+        puts("");
+        sleep( 1 );
+        while ( last_timestamp == telemetry->timestamp )
+            sleep( 1 );
+        last_timestamp = telemetry->timestamp;
+    }
+    return 0;
+}
+
+int main(int argc, char *argv[]) {
+    if ( 0 != init_shm() )
+        exit( EXIT_FAILURE);
+    if ( 0 != log_console() )
+        exit( EXIT_FAILURE);
+    exit( EXIT_SUCCESS );
+    (void)argc; (void)argv;
+}