Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
settings.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2014 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 #include "modules/core/settings.h"
29 #include "generated/settings.h"
30 #include "generated/airframe.h"
31 #include "pprzlink/messages.h"
32 #include "pprzlink/dl_protocol.h"
33 
34 struct PersistentSettings pers_settings;
35 
42 
44 
45 
46 void settings_init(void)
47 {
48 #if USE_PERSISTENT_SETTINGS
49  if (persistent_read((void *)&pers_settings, sizeof(struct PersistentSettings))) {
50  return; // return -1 ?
51  }
52  /* from generated/settings.h */
53  persistent_settings_load();
54 #endif
55 }
56 
61 {
62 #if USE_PERSISTENT_SETTINGS
63  if (settings_store_flag) {
64  /* from generated/settings.h */
65  persistent_settings_store();
66  if (!persistent_write((void *)&pers_settings, sizeof(struct PersistentSettings))) {
67  /* persistent write was successful */
68  settings_store_flag = true;
69  return 0;
70  }
71  }
72 #endif
73  settings_store_flag = false;
74  return -1;
75 }
76 
81 {
82 #if USE_PERSISTENT_SETTINGS
83  if (settings_clear_flag) {
84  if (!persistent_clear()) {
85  /* clearing all persistent settings was successful */
86  settings_clear_flag = true;
87  return 0;
88  }
89  }
90 #endif
91  settings_clear_flag = false;
92  return -1;
93 }
94 
95 void settings_parse_msg_SETTING(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
96 {
97 #ifndef INTERMCU_FBW
98  if (DL_SETTING_ac_id(buf) != AC_ID) { return; }
99  uint8_t sender_id = pprzlink_get_msg_sender_id(buf);
100  uint8_t i = DL_SETTING_index(buf);
101  float var = DL_SETTING_value(buf);
102  DlSetting(i, var);
103  // Reply to the sender of the message
104  struct pprzlink_msg msg;
105  msg.trans = trans;
106  msg.dev = dev;
107  msg.sender_id = AC_ID;
108  msg.receiver_id = sender_id;
109  msg.component_id = 0;
110  pprzlink_msg_send_DL_VALUE(&msg, &i, &var);
111 #else
112  (void)dev;
113  (void)trans;
114  (void)buf;
115 #endif
116 }
117 
118 void settings_parse_msg_GET_SETTING(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
119 {
120 #ifndef INTERMCU_FBW
121  if (DL_GET_SETTING_ac_id(buf) != AC_ID) { return; }
122  uint8_t sender_id = pprzlink_get_msg_sender_id(buf);
123  uint8_t i = DL_GET_SETTING_index(buf);
124  float val = settings_get_value(i);
125  // Reply to the sender of the message
126  struct pprzlink_msg msg;
127  msg.trans = trans;
128  msg.dev = dev;
129  msg.sender_id = AC_ID;
130  msg.receiver_id = sender_id;
131  msg.component_id = 0;
132  pprzlink_msg_send_DL_VALUE(&msg, &i, &val);
133 #else
134  (void)dev;
135  (void)trans;
136  (void)buf;
137 #endif
138 }
139 
persistent_write
int32_t persistent_write(void *ptr, uint32_t size)
Definition: settings_arch.c:33
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
val
uint16_t val[TCOUPLE_NB]
Definition: temp_tcouple_adc.c:49
settings_parse_msg_SETTING
void settings_parse_msg_SETTING(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
Definition: settings.c:95
settings_clear_flag
bool settings_clear_flag
Definition: settings.c:43
settings_parse_msg_GET_SETTING
void settings_parse_msg_GET_SETTING(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
Definition: settings.c:118
settings.h
msg
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
Definition: high_speed_logger_direct_memory.c:134
pers_settings
struct PersistentSettings pers_settings
Definition: settings.c:34
settings_init
void settings_init(void)
Definition: settings.c:46
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
settings_store_flag
bool settings_store_flag
flag for setting feedback.
Definition: settings.c:41
settings_clear
int32_t settings_clear(void)
clear all persistent settings from flash
Definition: settings.c:80
int32_t
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
persistent_clear
int32_t persistent_clear(void)
Definition: settings_arch.c:74
settings_store
int32_t settings_store(void)
store settings marked as persistent to flash
Definition: settings.c:60
persistent_read
int32_t persistent_read(void *ptr, uint32_t size)
Definition: settings_arch.c:38