MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / AP_Logger_Write

Function AP_Logger_Write

libraries/AP_Scripting/lua_bindings.cpp:260–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258
259#if HAL_LOGGING_ENABLED
260int AP_Logger_Write(lua_State *L) {
261 AP_Logger * AP_logger = AP_Logger::get_singleton();
262 if (AP_logger == nullptr) {
263 return luaL_argerror(L, 1, "logger not supported on this firmware");
264 }
265
266 // Allow : and . access
267 const int arg_offset = (luaL_testudata(L, 1, "logger") != NULL) ? 1 : 0;
268
269 // check we have at least 4 arguments passed in
270 const int args = lua_gettop(L) - arg_offset;
271 if (args < 4) {
272 return luaL_argerror(L, args, "too few arguments");
273 }
274
275 const char * name = luaL_checkstring(L, 1 + arg_offset);
276 const char * labels = luaL_checkstring(L, 2 + arg_offset);
277 const char * fmt = luaL_checkstring(L, 3 + arg_offset);
278
279 // cheack the name, labels and format are not too long
280 if (strlen(name) >= LS_NAME_SIZE) {
281 return luaL_error(L, "Name must be 4 or less chars long");
282 }
283 uint8_t length = strlen(labels);
284 if (length >= (LS_LABELS_SIZE - 7)) { // need 7 chars to add 'TimeUS,'
285 return luaL_error(L, "labels must be less than 58 chars long");
286 }
287 // Count the number of commas
288 uint8_t commas = 1;
289 for (uint8_t i=0; i<length; i++) {
290 if (labels[i] == ',') {
291 commas++;
292 }
293 }
294
295 length = strlen(fmt);
296 if (length >= (LS_FORMAT_SIZE - 1)) { // need 1 char to add timestamp
297 return luaL_error(L, "format must be less than 15 chars long");
298 }
299
300 // check the number of arguments matches the number of values in the label
301 if (length != commas) {
302 return luaL_argerror(L, args, "label does not match format");
303 }
304
305 bool have_units = false;
306 if (args - 5 == length) {
307 // check if there are enough arguments for units and multiplyers
308 have_units = true;
309 } else if (args - 3 != length) {
310 // check the number of arguments matches the length of the foramt string
311 return luaL_argerror(L, args, "format does not match No. of arguments");
312 }
313
314 // prepend timestamp to format and labels
315 char label_cat[LS_LABELS_SIZE];
316 strcpy(label_cat,"TimeUS,");
317 strcat(label_cat,labels);

Callers

nothing calls this directly

Calls 15

get_singletonFunction · 0.85
luaL_argerrorFunction · 0.85
luaL_testudataFunction · 0.85
lua_gettopFunction · 0.85
strlenFunction · 0.85
luaL_errorFunction · 0.85
memcpyFunction · 0.85
lua_tointegerxFunction · 0.85
lua_tonumberxFunction · 0.85
lua_tobooleanFunction · 0.85
lua_tolstringFunction · 0.85
memsetFunction · 0.85

Tested by

no test coverage detected