2525#include < AP_Math/AP_Math.h>
2626#include < AP_CANManager/AP_CANManager.h>
2727#include < AP_Scheduler/AP_Scheduler.h>
28+ #include < AP_Logger/AP_Logger.h>
2829#include < AP_Common/ExpandingString.h>
2930
3031extern const AP_HAL::HAL& hal;
@@ -33,13 +34,21 @@ struct SysFileList {
3334 const char * name;
3435};
3536
37+ #ifndef HAL_LOG_EVENT_METADATA
38+ #define HAL_LOG_EVENT_METADATA 1
39+ #endif
40+
3641static const SysFileList sysfs_file_list[] = {
3742 {" threads.txt" },
3843 {" tasks.txt" },
3944 {" dma.txt" },
4045 {" memory.txt" },
4146 {" uarts.txt" },
4247 {" timers.txt" },
48+ {" general_metadata.json" },
49+ #if HAL_LOG_EVENT_METADATA
50+ {" events_metadata.json" },
51+ #endif
4352#if HAL_MAX_CAN_PROTOCOL_DRIVERS
4453 {" can_log.txt" },
4554#endif
@@ -66,6 +75,118 @@ int8_t AP_Filesystem_Sys::file_in_sysfs(const char *fname) {
6675 return -1 ;
6776}
6877
78+ void AP_Filesystem_Sys::general_metadata (ExpandingString &str)
79+ {
80+ const struct MetaDataInfo {
81+ int type_id;
82+ const char * uri;
83+ } metadata[] = {
84+ 3 , // COMP_METADATA_TYPE_EVENTS
85+ #if HAL_LOG_EVENT_METADATA
86+ " mftp:/@SYS/events_metadata.json"
87+ #else
88+ " https://firmware.ardupilot.org/GITHASH/events_metadata.json"
89+ #endif
90+ };
91+ // a header to allow for machine parsers to determine format
92+ str.printf (
93+ " {"
94+ " \" version\" : 1,"
95+ " \" metadataTypes\" : ["
96+ );
97+
98+ // FIXME: too many [?
99+ const char *joiner = " " ;
100+ for (const MetaDataInfo &info : metadata) {
101+ str.printf (" %s{\" type\" : %d, \" uri\" : \" %s\" , \" fileCrc\" : 133761337}" ,
102+ joiner,
103+ info.type_id ,
104+ info.uri );
105+ joiner = " ," ;
106+ }
107+
108+ str.printf (
109+ " ]}"
110+ );
111+
112+ }
113+
114+ #if HAL_LOG_EVENT_METADATA
115+
116+ void AP_Filesystem_Sys::events_metadata (ExpandingString &str)
117+ {
118+ static const struct {
119+ LogEvent value;
120+ const char *name;
121+ const char *description;
122+ } logevent_metadata[] {
123+ { LogEvent::ARMED, " Armed" , " Vehicle was armed" },
124+ { LogEvent::DISARMED, " Disarmed" , " Vehicle was disarmed" },
125+ { LogEvent::SET_HOME, " SetHome" , " Vehicle home location was set" },
126+ };
127+
128+ // FIXME: this is really the wrong schema for the LogError stuff.
129+ static const struct {
130+ LogErrorSubsystem value;
131+ const char *name;
132+ const char *description;
133+ } logerror_metadata[] {
134+ { LogErrorSubsystem::MAIN, " Main" , " Bogus generic bucket for everything unclassified elsewhere" },
135+ };
136+
137+ // a header to allow for machine parsers to determine format
138+ str.printf (
139+ " { "
140+ " \" version\" : 1, "
141+ " \" components\" : [ "
142+ " { "
143+ " \" component_id\" : %u, "
144+ " \" namespace\" : \" common\" , "
145+ " \" enums\" : [ "
146+ " { "
147+ " \" name\" : \" ardupilot_event\" , "
148+ " \" type\" : \" uint8_t\" , "
149+ " \" description\" : \" Generic ArduPilot events from AP_Logger::LogEvent\" , "
150+ " \" entries\" : [ " ,
151+ 1 ); // FIXME: should be mavlink component ID of autopilot
152+
153+ const char *joiner = " " ;
154+ for (auto &x : logevent_metadata) {
155+ str.printf (
156+ " %s{\" value\" :%u, \" name\" :\" %s\" , \" description\" :\" %s\" }\n " ,
157+ joiner,
158+ (unsigned )x.value ,
159+ x.name ,
160+ x.description
161+ );
162+ joiner = " ," ;
163+ }
164+ str.printf (" ]}, [{" );
165+ str.printf (
166+ " \" name\" : \" ardupilot_errors\" , "
167+ " \" type\" : \" uint8_t\" , "
168+ " \" description\" : \" Generic ArduPilot errors from AP_Logger::LogErrorSubsystem\" , "
169+ " \" entries\" : [ "
170+ );
171+
172+ joiner = " " ;
173+ for (auto &x : logerror_metadata) {
174+ str.printf (
175+ " %s{\" value\" :%u, \" name\" :\" %s\" , \" description\" :\" %s\" }\n " ,
176+ joiner,
177+ (unsigned )x.value ,
178+ x.name ,
179+ x.description
180+ );
181+ joiner = " ," ;
182+ }
183+
184+ str.printf (" ]}]" );
185+ str.printf (" ]}]}" );
186+ }
187+
188+ #endif
189+
69190int AP_Filesystem_Sys::open (const char *fname, int flags, bool allow_absolute_paths)
70191{
71192 if ((flags & O_ACCMODE) != O_RDONLY) {
@@ -120,6 +241,14 @@ int AP_Filesystem_Sys::open(const char *fname, int flags, bool allow_absolute_pa
120241 if (strcmp (fname, " timers.txt" ) == 0 ) {
121242 hal.util ->timer_info (*r.str );
122243 }
244+ if (strcmp (fname, " general_metadata.json" ) == 0 ) {
245+ general_metadata (*r.str );
246+ }
247+ #if HAL_LOG_EVENT_METADATA
248+ if (strcmp (fname, " events_metadata.json" ) == 0 ) {
249+ events_metadata (*r.str );
250+ }
251+ #endif
123252#if HAL_CANMANAGER_ENABLED
124253 if (strcmp (fname, " can_log.txt" ) == 0 ) {
125254 AP::can ().log_retrieve (*r.str );
0 commit comments