-/**
- * \file
- *
- * \author Bernie Innocenti <bernie@codewiz.org>
- *
- * \brief Serial data logger for RMS
+/*
+ * Copyleft 2011 Bernie Innocenti <bernie@codewiz.org>
+ * Serial data logger for RMS
*
* This application records all incoming data from an RS-232 serial port
* to a file on a FAT-formatted SD card. It can be used to log kernel
// Configuration
#define FILE_NAME "log.txt"
-#define FILE_OVERWRITE 1
+#define FILE_NAME_PATTERN "log%04d.txt"
+#define FILE_OVERWRITE 0
#define FILE_PREALLOC_SIZE 102400
#include <drv/timer.h>
#include <kern/proc.h>
-#include <string.h>
+#include <stdio.h> // sprintf()
+#include <string.h> // strcmp()
// Our serial port
init();
size_t size;
- char buf[256];
bool sync_pending = false;
+ char buf[256];
- /* create file */
- if(!fat_create_file(dd, FILE_NAME, &dir_entry))
+ #if FILE_OVERWRITE
{
- #if FILE_OVERWRITE
- fat_delete_file(fs, &dir_entry);
- fat_create_file(dd, FILE_NAME, &dir_entry);
- #endif
+ if(!fat_create_file(dd, FILE_NAME, &dir_entry))
+ {
+ fat_delete_file(fs, &dir_entry);
+ fat_create_file(dd, FILE_NAME, &dir_entry);
+ }
+
+ fd = open_file_in_dir(fs, dd, FILE_NAME);
}
+ #else /* Generate a new filename */
+ {
+ int n;
+ char filename[8+1+3+1];
+
+ for (n = 0; /**/; ++n)
+ {
+ sprintf(filename, FILE_NAME_PATTERN, n);
+ if (fat_create_file(dd, filename, &dir_entry))
+ break;
+ }
- fd = open_file_in_dir(fs, dd, FILE_NAME);
+ fd = open_file_in_dir(fs, dd, filename);
+ }
+ #endif
- /* preallocate file */
#if FILE_PREALLOC_SIZE
{
LED_ON();
+ memset(buf, ' ', sizeof(buf));
for (int i = 0; i < (int)(FILE_PREALLOC_SIZE / sizeof(buf)); ++i)
fat_write_file(fd, (void *)buf, sizeof(buf));
}
#endif
- while (1)
+ for (;;)
{
if ((size = ser_read(&ser, buf, sizeof(buf))) != 0)
{