]> git.droids-corp.org - protos/imu.git/commitdiff
introduce sd_log for logging on the sdcard
authorOlivier Matz <zer0@droids-corp.org>
Thu, 10 Jul 2014 16:53:33 +0000 (18:53 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 10 Jul 2014 16:53:33 +0000 (18:53 +0200)
Makefile
gps_venus.c
imu.c
main.c

index ec375bca2e85a56e9bb635d5639f7e1a80729efa..50e213761bb9c555750607dff0fcda80d64f1e6e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@ SRC += sd_main.c
 SRC += partition.c
 SRC += sd_raw.c
 SRC += gps_venus.c
+SRC += sd_log.c
 
 
 CFLAGS += -W -Wall -Werror
index 7150ef2fcadbb575fd2b91c9993584a67e5c160a..20d8639fb1e44dad2b0086866784fe33d98c021c 100644 (file)
@@ -16,6 +16,7 @@
 #include "partition.h"
 #include "sd_raw.h"
 #include "sd_raw_config.h"
+#include "sd_log.h"
 
 #define debug_printf(args...) do { } while (0)
 /* #define debug_printf(args...) printf(args) */
@@ -533,125 +534,6 @@ int gps_venus_init(void)
        return 0;
 }
 
-static uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry)
-{
-       (void)fs;
-
-    while(fat_read_dir(dd, dir_entry))
-    {
-       if(strcmp(dir_entry->long_name, name) == 0)
-       {
-           fat_reset_dir(dd);
-           return 1;
-       }
-    }
-
-    return 0;
-}
-
-static struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name)
-{
-    struct fat_dir_entry_struct file_entry;
-    if(!find_file_in_dir(fs, dd, name, &file_entry))
-       return 0;
-
-    return fat_open_file(fs, &file_entry);
-}
-
-static struct fat_file_struct *open_log_file(void)
-{
-       struct fat_file_struct *fd;
-       struct fat_fs_struct *fs;
-       struct partition_struct *partition ;
-       struct fat_dir_struct *dd;
-       struct fat_dir_entry_struct directory;
-       struct fat_dir_entry_struct file_entry;
-       int16_t i = 0;
-       char name[16];
-
-       /* setup sd card slot */
-       if (!sd_raw_init()) {
-#if SD_DEBUG
-               printf_P(PSTR("MMC/SD initialization failed\n"));
-#endif
-               return NULL;
-       }
-
-       /* open first partition */
-       partition = partition_open(sd_raw_read,
-               sd_raw_read_interval,
-#if SD_RAW_WRITE_SUPPORT
-               sd_raw_write, sd_raw_write_interval,
-#else
-               0, 0,
-#endif
-               0);
-
-       if (!partition) {
-               /* If the partition did not open, assume the storage device
-                * is a "superfloppy", i.e. has no MBR.
-                */
-               partition = partition_open(sd_raw_read,
-                       sd_raw_read_interval,
-#if SD_RAW_WRITE_SUPPORT
-                       sd_raw_write,
-                       sd_raw_write_interval,
-#else
-                       0,
-                       0,
-#endif
-                       -1);
-               if (!partition) {
-#if SD_DEBUG
-                       printf_P(PSTR("opening partition failed\n"));
-#endif
-                       return NULL;
-               }
-       }
-
-       /* open file system */
-       fs = fat_open(partition);
-       if (!fs) {
-#if SD_DEBUG
-               printf_P(PSTR("opening filesystem failed\n"));
-#endif
-               return NULL;
-       }
-
-       /* open root directory */
-       fat_get_dir_entry_of_path(fs, "/", &directory);
-       dd = fat_open_dir(fs, &directory);
-       if (!dd) {
-#if SD_DEBUG
-               printf_P(PSTR("opening root directory failed\n"));
-#endif
-               return NULL;
-       }
-
-       /* print some card information as a boot message */
-       //print_disk_info(fs);
-
-       printf("choose log file name\n");
-       while (1) {
-               snprintf(name, sizeof(name), "log%.4d", i++);
-               if (!find_file_in_dir(fs, dd, name, &file_entry))
-                       break;
-       }
-
-       printf("create log file %s\n", name);
-       if (!fat_create_file(dd, name, &file_entry)) {
-               printf_P(PSTR("error creating file: "));
-       }
-
-       fd = open_file_in_dir(fs, dd, name);
-       if (!fd) {
-               printf_P(PSTR("error opening "));
-               return NULL;
-       }
-
-       return fd;
-}
-
 void gps_get_pos(struct gps_pos *pos)
 {
        memcpy(pos, &gps_pos, sizeof(*pos));
@@ -666,11 +548,7 @@ int gps_loop(void)
        char buf[128];
        struct gps_pos pos;
 
-       if (1) {
-               fd = open_log_file();
-               if (fd == NULL)
-                       printf("open log failed\r\n");
-       }
+       fd = get_log_file();
 
        while (1) {
 
diff --git a/imu.c b/imu.c
index 72bdd74b451606c1219b7935dca80725e85e8ce7..86b34b46b1e7eb22789676ca96d778e1567904d1 100644 (file)
--- a/imu.c
+++ b/imu.c
@@ -36,6 +36,7 @@
 #include "partition.h"
 #include "sd_raw.h"
 #include "sd_raw_config.h"
+#include "sd_log.h"
 
 #include <uart.h>
 #include <stdio.h>
@@ -96,33 +97,6 @@ void do_led_blink(void *dummy)
 }
 
 
-static uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry)
-{
-       (void)fs;
-
-    while(fat_read_dir(dd, dir_entry))
-    {
-       if(strcmp(dir_entry->long_name, name) == 0)
-       {
-           fat_reset_dir(dd);
-           return 1;
-       }
-    }
-
-    return 0;
-}
-
-static struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name)
-{
-    struct fat_dir_entry_struct file_entry;
-    if(!find_file_in_dir(fs, dd, name, &file_entry))
-       return 0;
-
-    return fat_open_file(fs, &file_entry);
-}
-
-
-
 /* for i2c */
 //uint8_t command_buf[I2C_SEND_BUFFER_SIZE];
 
@@ -328,117 +302,10 @@ void quaternion2euler(void)
        yaw = atan2f(2.0f * (q1 * q2 + q0 * q3), q0*q0 + q1*q1 - q2*q2 - q3*q3);
 }
 
-static struct fat_file_struct *open_log_file(void)
-{
-       struct fat_file_struct *fd;
-       struct fat_fs_struct *fs;
-       struct partition_struct *partition ;
-       struct fat_dir_struct *dd;
-       struct fat_dir_entry_struct directory;
-       struct fat_dir_entry_struct file_entry;
-       int16_t i = 0;
-       char name[16];
-
-       /* setup sd card slot */
-       if (!sd_raw_init()) {
-#if SD_DEBUG
-               printf_P(PSTR("MMC/SD initialization failed\n"));
-#endif
-               return NULL;
-       }
-
-       /* open first partition */
-       partition = partition_open(sd_raw_read,
-               sd_raw_read_interval,
-#if SD_RAW_WRITE_SUPPORT
-               sd_raw_write, sd_raw_write_interval,
-#else
-               0, 0,
-#endif
-               0);
-
-       if (!partition) {
-               /* If the partition did not open, assume the storage device
-                * is a "superfloppy", i.e. has no MBR.
-                */
-               partition = partition_open(sd_raw_read,
-                       sd_raw_read_interval,
-#if SD_RAW_WRITE_SUPPORT
-                       sd_raw_write,
-                       sd_raw_write_interval,
-#else
-                       0,
-                       0,
-#endif
-                       -1);
-               if (!partition) {
-#if SD_DEBUG
-                       printf_P(PSTR("opening partition failed\n"));
-#endif
-                       return NULL;
-               }
-       }
-
-       /* open file system */
-       fs = fat_open(partition);
-       if (!fs) {
-#if SD_DEBUG
-               printf_P(PSTR("opening filesystem failed\n"));
-#endif
-               return NULL;
-       }
-
-       /* open root directory */
-       fat_get_dir_entry_of_path(fs, "/", &directory);
-       dd = fat_open_dir(fs, &directory);
-       if (!dd) {
-#if SD_DEBUG
-               printf_P(PSTR("opening root directory failed\n"));
-#endif
-               return NULL;
-       }
-
-       /* print some card information as a boot message */
-       //print_disk_info(fs);
-
-       printf("choose log file name\n");
-       while (1) {
-               snprintf(name, sizeof(name), "log%.4d", i++);
-               if (!find_file_in_dir(fs, dd, name, &file_entry))
-                       break;
-       }
-
-       printf("create log file %s\n", name);
-       if (!fat_create_file(dd, name, &file_entry)) {
-               printf_P(PSTR("error creating file: "));
-       }
-
-       fd = open_file_in_dir(fs, dd, name);
-       if (!fd) {
-               printf_P(PSTR("error opening "));
-               return NULL;
-       }
-
-       return fd;
-}
-
 #define swap_u16(a) (((a>>8)&0xff) | (((a&0xFF)<<8)))
-int imu_loop(void)
-{
-       //int16_t temp;
-       //uint8_t err;
-       //uint16_t * ptr;
-       //uint8_t a;
-       //int i;
-
-
-       struct fat_file_struct *fd = NULL;
-       int16_t mpu6050_axes[10];
-       char buf[128];
-       int16_t len;
-       uint32_t ms;
-       uint8_t flags;
 
+void imu_init(void)
+{
        /*
        bma150_init();
        itg3200_init();
@@ -450,12 +317,16 @@ int imu_loop(void)
                                                GYRO_PRIO);
        */
        mpu6050_init();
+}
 
-       if (1) {
-               fd = open_log_file();
-               if (fd == NULL)
-                       printf("open log failed\r\n");
-       }
+int imu_loop(void)
+{
+       struct fat_file_struct *fd = NULL;
+       int16_t mpu6050_axes[10];
+       char buf[128];
+       int16_t len;
+       uint32_t ms;
+       uint8_t flags;
 
        while (1) {
 
diff --git a/main.c b/main.c
index 454b54bc81f3fb5b03c06faf525a4512cff14da2..9b801f5c1dc1adc8c2fcfea464d55673c91952da 100644 (file)
--- a/main.c
+++ b/main.c
@@ -54,6 +54,7 @@
 
 #include "eeprom_config.h"
 #include "gps_venus.h"
+#include "sd_log.h"
 #include "main.h"
 
 struct imuboard imuboard;
@@ -167,11 +168,13 @@ int main(void)
 
        eeprom_load_config();
 
+       open_log_file();
+
        printf_P(PSTR("\r\n"));
        rdline_newline(&imuboard.rdl, imuboard.prompt);
 
-
        //sd_main();
+       //imu_init();
        //imu_loop();
        gps_venus_init();
        gps_loop();