aboutsummaryrefslogtreecommitdiff
path: root/apps/sdlog/sdlog.c
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2012-10-25 15:47:14 +0200
committerLorenz Meier <lm@inf.ethz.ch>2012-10-25 15:47:14 +0200
commit569938e6808286f3aa4e8a03ca4e1c8467955f5f (patch)
treefd8adeedd95da664941c4ca1def1357991b34c80 /apps/sdlog/sdlog.c
parent8e4c45322e318db559d7c09ec9ef1f50ad808855 (diff)
downloadpx4-firmware-569938e6808286f3aa4e8a03ca4e1c8467955f5f.tar.gz
px4-firmware-569938e6808286f3aa4e8a03ca4e1c8467955f5f.tar.bz2
px4-firmware-569938e6808286f3aa4e8a03ca4e1c8467955f5f.zip
Copying log analysis file directly to the SD card during logging
Diffstat (limited to 'apps/sdlog/sdlog.c')
-rw-r--r--apps/sdlog/sdlog.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/apps/sdlog/sdlog.c b/apps/sdlog/sdlog.c
index 312768095..a934d0d33 100644
--- a/apps/sdlog/sdlog.c
+++ b/apps/sdlog/sdlog.c
@@ -72,6 +72,7 @@ static int deamon_task; /**< Handle of deamon task / thread */
static const int MAX_NO_LOGFOLDER = 999; /**< Maximum number of log folders */
static const char *mountpoint = "/fs/microsd";
+static const char *mfile_in = "/etc/logging/logconv.m";
/**
* SD log management function.
@@ -90,10 +91,12 @@ static void usage(const char *reason);
static int file_exist(const char *filename);
+static int file_copy(const char* file_old, const char* file_new);
+
/**
* Print the current status.
*/
-static void print_sdlog_status();
+static void print_sdlog_status(void);
/**
* Create folder for current logging session.
@@ -181,7 +184,17 @@ int create_logfolder(char* folder_path) {
/* the result is -1 if the folder exists */
if (mkdir_ret == 0) {
- /* folder does not exist */
+ /* folder does not exist, success */
+
+ /* now copy the Matlab/Octave file */
+ char mfile_out[100];
+ sprintf(mfile_out, "%s/session%04u/run_to_plot_data.m", mountpoint, foldernumber);
+ int ret = file_copy(mfile_in, mfile_out);
+ if (!ret) {
+ warnx("copied m file to %s", mfile_out);
+ } else {
+ warnx("failed copying m file from %s to\n %s", mfile_in, mfile_out);
+ }
break;
} else if (mkdir_ret == -1) {
@@ -379,7 +392,7 @@ int sdlog_thread_main(int argc, char *argv[]) {
* set up poll to block for new data,
* wait for a maximum of 1000 ms (1 second)
*/
- const int timeout = 1000;
+ // const int timeout = 1000;
thread_running = true;
@@ -550,3 +563,38 @@ int file_exist(const char *filename)
return stat(filename, &buffer);
}
+int file_copy(const char* file_old, const char* file_new)
+{
+ FILE *source, *target;
+ source = fopen(file_old, "r");
+
+ if( source == NULL )
+ {
+ warnx("failed opening input file to copy");
+ return 1;
+ }
+
+ target = fopen(file_new, "w");
+
+ if( target == NULL )
+ {
+ fclose(source);
+ warnx("failed to open output file to copy");
+ }
+
+ char buf[128];
+ int nread;
+ while ((nread = fread(buf, sizeof(buf), 1, source)) > 0) {
+ int ret = fwrite(buf, sizeof(buf), 1, target);
+ if (ret <= 0) {
+ warnx("error writing file");
+ break;
+ }
+ }
+
+ fclose(source);
+ fclose(target);
+
+ return 0;
+}
+