mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-05 22:24:47 +08:00
Improved param load / store text feedback, ported sensors app to new driver model, ready for merge and test
This commit is contained in:
@@ -47,6 +47,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <systemlib/param/param.h>
|
#include <systemlib/param/param.h>
|
||||||
|
#include <systemlib/err.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
extern mavlink_system_t mavlink_system;
|
extern mavlink_system_t mavlink_system;
|
||||||
|
|
||||||
@@ -65,6 +67,20 @@ static unsigned int mavlink_param_queue_index = 0;
|
|||||||
*/
|
*/
|
||||||
void mavlink_pm_callback(void *arg, param_t param);
|
void mavlink_pm_callback(void *arg, param_t param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save parameters to EEPROM.
|
||||||
|
*
|
||||||
|
* Stores the parameters to /eeprom/parameters
|
||||||
|
*/
|
||||||
|
static int mavlink_pm_save_eeprom(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load parameters from EEPROM.
|
||||||
|
*
|
||||||
|
* Loads the parameters from /eeprom/parameters
|
||||||
|
*/
|
||||||
|
static int mavlink_pm_load_eeprom(void);
|
||||||
|
|
||||||
void mavlink_pm_callback(void *arg, param_t param)
|
void mavlink_pm_callback(void *arg, param_t param)
|
||||||
{
|
{
|
||||||
mavlink_pm_send_param(param);
|
mavlink_pm_send_param(param);
|
||||||
@@ -126,6 +142,8 @@ int mavlink_pm_send_param(param_t param)
|
|||||||
mavlink_type = MAVLINK_TYPE_INT32_T;
|
mavlink_type = MAVLINK_TYPE_INT32_T;
|
||||||
} else if (type == PARAM_TYPE_FLOAT) {
|
} else if (type == PARAM_TYPE_FLOAT) {
|
||||||
mavlink_type = MAVLINK_TYPE_FLOAT;
|
mavlink_type = MAVLINK_TYPE_FLOAT;
|
||||||
|
} else {
|
||||||
|
mavlink_type = MAVLINK_TYPE_FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -150,27 +168,28 @@ int mavlink_pm_send_param(param_t param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char *mavlink_parameter_file = "/eeprom/parameters";
|
static const char *mavlink_parameter_file = "/eeprom/parameters";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 0 on success, -1 if device open failed, -2 if writing parameters failed
|
* @return 0 on success, -1 if device open failed, -2 if writing parameters failed
|
||||||
*/
|
*/
|
||||||
static int
|
static int mavlink_pm_save_eeprom()
|
||||||
mavlink_pm_save_eeprom()
|
|
||||||
{
|
{
|
||||||
|
/* delete the file in case it exists */
|
||||||
unlink(mavlink_parameter_file);
|
unlink(mavlink_parameter_file);
|
||||||
|
|
||||||
|
/* create the file */
|
||||||
int fd = open(mavlink_parameter_file, O_WRONLY | O_CREAT | O_EXCL);
|
int fd = open(mavlink_parameter_file, O_WRONLY | O_CREAT | O_EXCL);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
warn("opening '%s' failed", mavlink_parameter_file);
|
warn("opening '%s' for writing failed", mavlink_parameter_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
int result = param_export(fd, false);
|
int result = param_export(fd, false);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
unlink(mavlink_parameter_file);
|
unlink(mavlink_parameter_file);
|
||||||
warn("error exporting to '%s'", mavlink_parameter_file);
|
warn("error exporting parameters to '%s'", mavlink_parameter_file);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,17 +197,25 @@ mavlink_pm_save_eeprom()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 0 on success, -1 if device open failed, -2 if writing parameters failed
|
* @return 0 on success, 1 if all params have not yet been stored, -1 if device open failed, -2 if writing parameters failed
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
mavlink_pm_load_eeprom()
|
mavlink_pm_load_eeprom()
|
||||||
{
|
{
|
||||||
|
/* check if eeprom is mounted - if yes and an eeprom open fail is no error */
|
||||||
|
struct stat buffer;
|
||||||
|
int eeprom_stat = stat("/eeprom", &buffer);
|
||||||
|
|
||||||
int fd = open(mavlink_parameter_file, O_RDONLY);
|
int fd = open(mavlink_parameter_file, O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
warn("open '%s' failed", mavlink_parameter_file);
|
if (eeprom_stat == OK) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
warn("open '%s' for reading failed", mavlink_parameter_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int result = param_import(fd);
|
int result = param_import(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -266,7 +293,7 @@ void mavlink_pm_message_handler(const mavlink_channel_t chan, const mavlink_mess
|
|||||||
mavlink_command_long_t cmd_mavlink;
|
mavlink_command_long_t cmd_mavlink;
|
||||||
mavlink_msg_command_long_decode(msg, &cmd_mavlink);
|
mavlink_msg_command_long_decode(msg, &cmd_mavlink);
|
||||||
|
|
||||||
uint8_t result;
|
uint8_t result = MAV_RESULT_UNSUPPORTED;
|
||||||
|
|
||||||
if (cmd_mavlink.target_system == mavlink_system.sysid &&
|
if (cmd_mavlink.target_system == mavlink_system.sysid &&
|
||||||
((cmd_mavlink.target_component == mavlink_system.compid) ||(cmd_mavlink.target_component == MAV_COMP_ID_ALL))) {
|
((cmd_mavlink.target_component == mavlink_system.compid) ||(cmd_mavlink.target_component == MAV_COMP_ID_ALL))) {
|
||||||
@@ -283,7 +310,9 @@ void mavlink_pm_message_handler(const mavlink_channel_t chan, const mavlink_mess
|
|||||||
//printf("[mavlink pm] Loaded EEPROM params in RAM\n");
|
//printf("[mavlink pm] Loaded EEPROM params in RAM\n");
|
||||||
mavlink_missionlib_send_gcs_string("[mavlink pm] OK loaded EEPROM params");
|
mavlink_missionlib_send_gcs_string("[mavlink pm] OK loaded EEPROM params");
|
||||||
result = MAV_RESULT_ACCEPTED;
|
result = MAV_RESULT_ACCEPTED;
|
||||||
|
} else if (read_ret == 1) {
|
||||||
|
mavlink_missionlib_send_gcs_string("[mavlink pm] No stored parameters to load");
|
||||||
|
result = MAV_RESULT_ACCEPTED;
|
||||||
} else {
|
} else {
|
||||||
if (read_ret < -1) {
|
if (read_ret < -1) {
|
||||||
mavlink_missionlib_send_gcs_string("[mavlink pm] ERR loading params from EEPROM");
|
mavlink_missionlib_send_gcs_string("[mavlink pm] ERR loading params from EEPROM");
|
||||||
@@ -317,6 +346,9 @@ void mavlink_pm_message_handler(const mavlink_channel_t chan, const mavlink_mess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* send back command result */
|
||||||
|
// mavlink_message_t tx;
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+315
-551
File diff suppressed because it is too large
Load Diff
@@ -48,6 +48,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <nuttx/i2c.h>
|
#include <nuttx/i2c.h>
|
||||||
#include <nuttx/mtd.h>
|
#include <nuttx/mtd.h>
|
||||||
@@ -99,7 +100,7 @@ int eeprom_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errx(1, "expected a command, try 'start'\n\t'save_param /eeprom/params'\n\t'load_param /eeprom/params'\n\t'erase'\n");
|
errx(1, "expected a command, try 'start'\n\t'save_param /eeprom/parameters'\n\t'load_param /eeprom/parameters'\n\t'erase'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,9 +175,16 @@ eeprom_ioctl(unsigned operation)
|
|||||||
static void
|
static void
|
||||||
eeprom_save(const char *name)
|
eeprom_save(const char *name)
|
||||||
{
|
{
|
||||||
if (!name)
|
if (!started)
|
||||||
err(1, "missing argument for device name, try '/eeprom'");
|
errx(1, "must be started first");
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
err(1, "missing argument for device name, try '/eeprom/parameters'");
|
||||||
|
|
||||||
|
/* delete the file in case it exists */
|
||||||
|
unlink(name);
|
||||||
|
|
||||||
|
/* create the file */
|
||||||
int fd = open(name, O_WRONLY | O_CREAT | O_EXCL);
|
int fd = open(name, O_WRONLY | O_CREAT | O_EXCL);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@@ -196,8 +204,11 @@ eeprom_save(const char *name)
|
|||||||
static void
|
static void
|
||||||
eeprom_load(const char *name)
|
eeprom_load(const char *name)
|
||||||
{
|
{
|
||||||
|
if (!started)
|
||||||
|
errx(1, "must be started first");
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
err(1, "missing argument for device name, try '/eeprom'");
|
err(1, "missing argument for device name, try '/eeprom/parameters'");
|
||||||
|
|
||||||
int fd = open(name, O_RDONLY);
|
int fd = open(name, O_RDONLY);
|
||||||
|
|
||||||
|
|||||||
@@ -651,8 +651,8 @@ CONFIG_ARCH_BZERO=n
|
|||||||
CONFIG_MAX_TASKS=32
|
CONFIG_MAX_TASKS=32
|
||||||
CONFIG_MAX_TASK_ARGS=8
|
CONFIG_MAX_TASK_ARGS=8
|
||||||
CONFIG_NPTHREAD_KEYS=4
|
CONFIG_NPTHREAD_KEYS=4
|
||||||
CONFIG_NFILE_DESCRIPTORS=20
|
CONFIG_NFILE_DESCRIPTORS=25
|
||||||
CONFIG_NFILE_STREAMS=20
|
CONFIG_NFILE_STREAMS=25
|
||||||
CONFIG_NAME_MAX=32
|
CONFIG_NAME_MAX=32
|
||||||
CONFIG_STDIO_BUFFER_SIZE=256
|
CONFIG_STDIO_BUFFER_SIZE=256
|
||||||
CONFIG_STDIO_LINEBUFFER=y
|
CONFIG_STDIO_LINEBUFFER=y
|
||||||
|
|||||||
Reference in New Issue
Block a user