DataFlash: write CHIBIOS_GIT_VERSION to opened log file

DataFlash: use AP_FWVersion singleton
This commit is contained in:
Peter Barker 2018-06-12 13:34:00 +10:00 committed by Francisco Ferreira
parent 6ba1678c5e
commit 611dcb694b
8 changed files with 40 additions and 23 deletions

View File

@ -141,6 +141,8 @@ void DFMessageWriter_DFLogStart::set_mission(const AP_Mission *mission)
void DFMessageWriter_WriteSysInfo::process() {
const AP_FWVersion &fwver = AP::fwversion();
switch(stage) {
case ws_blockwriter_stage_init:
@ -148,18 +150,28 @@ void DFMessageWriter_WriteSysInfo::process() {
FALLTHROUGH;
case ws_blockwriter_stage_firmware_string:
if (! _dataflash_backend->Log_Write_Message(_firmware_string)) {
if (! _dataflash_backend->Log_Write_Message(fwver.fw_string)) {
return; // call me again
}
stage = ws_blockwriter_stage_git_versions;
FALLTHROUGH;
case ws_blockwriter_stage_git_versions:
#if defined(PX4_GIT_VERSION) && defined(NUTTX_GIT_VERSION)
if (! _dataflash_backend->Log_Write_Message("PX4: " PX4_GIT_VERSION " NuttX: " NUTTX_GIT_VERSION)) {
return; // call me again
if (fwver.middleware_name && fwver.os_name) {
if (! _dataflash_backend->Log_Write_MessageF("%s: %s %s: %s",
fwver.middleware_name,
fwver.middleware_hash_str,
fwver.os_name,
fwver.os_hash_str)) {
return; // call me again
}
} else if (fwver.os_name) {
if (! _dataflash_backend->Log_Write_MessageF("%s: %s",
fwver.os_name,
fwver.os_hash_str)) {
return; // call me again
}
}
#endif
stage = ws_blockwriter_stage_system_id;
FALLTHROUGH;

View File

@ -23,10 +23,6 @@ protected:
class DFMessageWriter_WriteSysInfo : public DFMessageWriter {
public:
DFMessageWriter_WriteSysInfo(const char *firmware_string) :
DFMessageWriter(),
_firmware_string(firmware_string)
{ }
void reset();
void process();
@ -39,8 +35,6 @@ private:
ws_blockwriter_stage_system_id
};
write_sysinfo_blockwriter_stage stage = ws_blockwriter_stage_init;
const char *_firmware_string;
};
class DFMessageWriter_WriteEntireMission : public DFMessageWriter {
@ -66,8 +60,8 @@ private:
class DFMessageWriter_DFLogStart : public DFMessageWriter {
public:
DFMessageWriter_DFLogStart(const char *firmware_string) :
_writesysinfo(firmware_string),
DFMessageWriter_DFLogStart() :
_writesysinfo(),
_writeentiremission()
{
}

View File

@ -62,9 +62,8 @@ const AP_Param::GroupInfo DataFlash_Class::var_info[] = {
#define streq(x, y) (!strcmp(x, y))
DataFlash_Class::DataFlash_Class(const char *firmware_string, const AP_Int32 &log_bitmask)
: _firmware_string(firmware_string)
, _log_bitmask(log_bitmask)
DataFlash_Class::DataFlash_Class(const AP_Int32 &log_bitmask)
: _log_bitmask(log_bitmask)
{
AP_Param::setup_object_defaults(this, var_info);
if (_instance != nullptr) {
@ -93,7 +92,7 @@ void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_ty
if (_params.backend_types == DATAFLASH_BACKEND_FILE ||
_params.backend_types == DATAFLASH_BACKEND_BOTH) {
DFMessageWriter_DFLogStart *message_writer =
new DFMessageWriter_DFLogStart(_firmware_string);
new DFMessageWriter_DFLogStart();
if (message_writer != nullptr) {
backends[_next_backend] = new DataFlash_File(*this,
message_writer,
@ -111,7 +110,7 @@ void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_ty
_params.backend_types == DATAFLASH_BACKEND_BOTH) {
DFMessageWriter_DFLogStart *message_writer =
new DFMessageWriter_DFLogStart(_firmware_string);
new DFMessageWriter_DFLogStart();
if (message_writer != nullptr) {
#if defined(BOARD_SDCARD_NAME) || defined(BOARD_DATAFLASH_FATFS)
@ -138,7 +137,7 @@ void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_ty
return;
}
DFMessageWriter_DFLogStart *message_writer =
new DFMessageWriter_DFLogStart(_firmware_string);
new DFMessageWriter_DFLogStart();
if (message_writer != nullptr) {
backends[_next_backend] = new DataFlash_MAVLink(*this,
message_writer);

View File

@ -52,7 +52,7 @@ class DataFlash_Class
public:
FUNCTOR_TYPEDEF(vehicle_startup_message_Log_Writer, void);
DataFlash_Class(const char *firmware_string, const AP_Int32 &log_bitmask);
DataFlash_Class(const AP_Int32 &log_bitmask);
/* Do not allow copies */
DataFlash_Class(const DataFlash_Class &other) = delete;
@ -240,7 +240,6 @@ private:
#define DATAFLASH_MAX_BACKENDS 2
uint8_t _next_backend;
DataFlash_Backend *backends[DATAFLASH_MAX_BACKENDS];
const char *_firmware_string;
const AP_Int32 &_log_bitmask;
void internal_error() const;

View File

@ -359,3 +359,15 @@ bool DataFlash_Backend::ShouldLog(bool is_critical)
return true;
}
bool DataFlash_Backend::Log_Write_MessageF(const char *fmt, ...)
{
char msg[64] {};
va_list ap;
va_start(ap, fmt);
hal.util->vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
return Log_Write_Message(msg);
}

View File

@ -91,6 +91,7 @@ public:
bool Log_Write_Format(const struct LogStructure *structure);
bool Log_Write_MavCmd(uint16_t cmd_total, const mavlink_mission_item_t& mav_cmd);
bool Log_Write_Message(const char *message);
bool Log_Write_MessageF(const char *fmt, ...);
bool Log_Write_Mission_Cmd(const AP_Mission &mission,
const AP_Mission::Mission_Command &cmd);
bool Log_Write_Mode(uint8_t mode, uint8_t reason = 0);

View File

@ -91,7 +91,7 @@ public:
private:
AP_Int32 log_bitmask;
DataFlash_Class dataflash{"DF AllTypes 0.2", log_bitmask};
DataFlash_Class dataflash{log_bitmask};
void print_mode(AP_HAL::BetterStream *port, uint8_t mode);
void Log_Write_TypeMessages();

View File

@ -40,7 +40,7 @@ public:
private:
AP_Int32 log_bitmask;
DataFlash_Class dataflash{"DF Test 0.1", log_bitmask};
DataFlash_Class dataflash{log_bitmask};
};