Skip to content

Commit

Permalink
[arch/linux] implement persistent settings
Browse files Browse the repository at this point in the history
  • Loading branch information
flixr committed Feb 15, 2015
1 parent 8b1742f commit 429ae81
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions sw/airborne/arch/linux/subsystems/settings_arch.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2013 The Paparazzi Team
* Copyright (C) 2009-2015 The Paparazzi Team
*
* This file is part of paparazzi.
*
Expand All @@ -23,21 +23,37 @@
* @file arch/linux/subsystems/settings_arch.c
* linux arch Persistent settings.
*
* Unimplemented.
* Saves the PersistentSettings struct to a binary file.
*/

#include "subsystems/settings.h"
#include <stdio.h>

/** Default file used to store persistent settings */
#ifndef PERSISTENT_SETTINGS_FILE
#define PERSISTENT_SETTINGS_FILE "pprz_persistent_settings.binary"
#endif

int32_t persistent_write(uint32_t ptr, uint32_t size)
{
ptr = ptr;
size = size;
FILE *file= fopen(PERSISTENT_SETTINGS_FILE, "wb");
if (file != NULL) {
fwrite(ptr, size, 1, file);
fclose(file);
return 0;
}
printf("Could not open settings file %s to write!\n", PERSISTENT_SETTINGS_FILE);
return -1;
}

int32_t persistent_read(uint32_t ptr, uint32_t size)
{
ptr = ptr;
size = size;
FILE *file= fopen(PERSISTENT_SETTINGS_FILE, "rb");
if (file != NULL) {
fread(ptr, size, 1, file);
fclose(file);
return 0;
}
printf("Could not open settings file %s to read!\n", PERSISTENT_SETTINGS_FILE);
return -1;
}

0 comments on commit 429ae81

Please sign in to comment.