Skip to content

Commit

Permalink
more support mavlink event interface
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Apr 27, 2021
1 parent 91b8d03 commit 097e0fb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
102 changes: 100 additions & 2 deletions libraries/AP_Filesystem/AP_Filesystem_Sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <AP_Math/AP_Math.h>
#include <AP_CANManager/AP_CANManager.h>
#include <AP_Scheduler/AP_Scheduler.h>
#include <AP_Logger/AP_Logger.h>
#include <AP_Common/ExpandingString.h>

extern const AP_HAL::HAL& hal;
Expand All @@ -30,13 +31,20 @@ struct SysFileList {
const char* name;
};

#ifndef HAL_LOG_EVENT_METADATA
#define HAL_LOG_EVENT_METADATA 1
#endif

static const SysFileList sysfs_file_list[] = {
{"threads.txt"},
{"tasks.txt"},
{"dma.txt"},
{"memory.txt"},
{"uarts.txt"},
{"general_metadata.json"},
#if HAL_LOG_EVENT_METADATA
{"events_metadata.json"},
#endif
#if HAL_MAX_CAN_PROTOCOL_DRIVERS
{"can_log.txt"},
{"can0_stats.txt"},
Expand All @@ -63,26 +71,111 @@ void AP_Filesystem_Sys::general_metadata(ExpandingString &str)
const char * uri;
} metadata[] = {
3, // COMP_METADATA_TYPE_EVENTS
#if HAL_LOG_EVENT_METADATA
"mftp:/@SYS/events_metadata.json"
#else
"https://firmware.ardupilot.org/GITHASH/events_metadata.json"
#endif
};
// a header to allow for machine parsers to determine format
str.printf(
"{"
" \"version\": 1,"
" \"metadataTypes\": ["
);

// FIXME: too many [?
const char *joiner = "";
for (const MetaDataInfo &info : metadata) {
str.printf("[ {\"type\": %d, \"uri\": \"%s\", \"fileCrc\": 133761337} ],",
str.printf("%s{\"type\": %d, \"uri\": \"%s\", \"fileCrc\": 133761337}",
joiner,
info.type_id,
info.uri);
joiner = ",";
}

str.printf(
" ]"
" ]}"
);

}

#if HAL_LOG_EVENT_METADATA

void AP_Filesystem_Sys::events_metadata(ExpandingString &str)
{
static const struct {
LogEvent value;
const char *name;
const char *description;
} logevent_metadata[] {
{ LogEvent::ARMED, "Armed", "Vehicle was armed" },
{ LogEvent::DISARMED, "Disarmed", "Vehicle was disarmed" },
{ LogEvent::SET_HOME, "SetHome", "Vehicle home location was set" },
};

// FIXME: this is really the wrong schema for the LogError stuff.
static const struct {
LogErrorSubsystem value;
const char *name;
const char *description;
} logerror_metadata[] {
{ LogErrorSubsystem::MAIN, "Main", "Bogus generic bucket for everything unclassified elsewhere" },
};

// a header to allow for machine parsers to determine format
str.printf(
"{ "
" \"version\": 1, "
" \"components\": [ "
" { "
" \"component_id\": %u, "
" \"namespace\": \"common\", "
" \"enums\": [ "
" { "
" \"name\": \"ardupilot_event\", "
" \"type\": \"uint8_t\", "
" \"description\": \"Generic ArduPilot events from AP_Logger::LogEvent\", "
" \"entries\": [ ",
1); // FIXME: should be mavlink component ID of autopilot

const char *joiner = "";
for (auto &x : logevent_metadata) {
str.printf(
"%s{\"value\":%u, \"name\":\"%s\", \"description\":\"%s\"}\n",
joiner,
(unsigned)x.value,
x.name,
x.description
);
joiner = ",";
}
str.printf("]}, [{");
str.printf(
" \"name\": \"ardupilot_errors\", "
" \"type\": \"uint8_t\", "
" \"description\": \"Generic ArduPilot errors from AP_Logger::LogErrorSubsystem\", "
" \"entries\": [ "
);

joiner = "";
for (auto &x : logerror_metadata) {
str.printf(
"%s{\"value\":%u, \"name\":\"%s\", \"description\":\"%s\"}\n",
joiner,
(unsigned)x.value,
x.name,
x.description
);
joiner = ",";
}

str.printf("]}]");
str.printf("]}]}");
}

#endif

int AP_Filesystem_Sys::open(const char *fname, int flags)
{
if ((flags & O_ACCMODE) != O_RDONLY) {
Expand Down Expand Up @@ -133,6 +226,11 @@ int AP_Filesystem_Sys::open(const char *fname, int flags)
if (strcmp(fname, "general_metadata.json") == 0) {
general_metadata(*r.str);
}
#if HAL_LOG_EVENT_METADATA
if (strcmp(fname, "events_metadata.json") == 0) {
events_metadata(*r.str);
}
#endif
#if HAL_MAX_CAN_PROTOCOL_DRIVERS
int8_t can_stats_num = -1;
if (strcmp(fname, "can_log.txt") == 0) {
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Filesystem/AP_Filesystem_Sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ class AP_Filesystem_Sys : public AP_Filesystem_Backend
} file[max_open_file];

void general_metadata(ExpandingString &str);
void events_metadata(ExpandingString &str);
};

0 comments on commit 097e0fb

Please sign in to comment.