dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
logging.c
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  *
29  * Additional note on redistribution: The copyright and license notices above
30  * must be maintained in each individual source file that is a derivative work
31  * of this source file; otherwise redistribution is prohibited.
32  */
33 
34 #include "openpilot.h"
35 #include "modulesettings.h"
36 #include "pios_thread.h"
37 #include "pios_queue.h"
38 #include "pios_mutex.h"
39 #include "uavobjectmanager.h"
40 #include "misc_math.h"
41 #include "timeutils.h"
42 #include "uavobjectmanager.h"
43 
44 #include "pios_streamfs.h"
45 #include <pios_board_info.h>
46 
47 #include "accels.h"
48 #include "actuatorcommand.h"
49 #include "actuatordesired.h"
50 #include "airspeedactual.h"
51 #include "attitudeactual.h"
52 #include "baroaltitude.h"
53 #include "flightbatterystate.h"
54 #include "flightstatus.h"
55 #include "gpsposition.h"
56 #include "gpstime.h"
57 #include "gpssatellites.h"
58 #include "gyros.h"
59 #include "loggingsettings.h"
60 #include "loggingstats.h"
61 #include "magnetometer.h"
62 #include "manualcontrolcommand.h"
63 #include "positionactual.h"
64 #include "stabilizationdesired.h"
65 #include "systemalarms.h"
66 #include "systemident.h"
67 #include "velocityactual.h"
68 #include "waypointactive.h"
69 #include "rtkfestimate.h"
70 #include "lqgsolution.h"
71 
72 #include "pios_bl_helper.h"
73 #include "pios_streamfs_priv.h"
74 
75 #include "pios_com_priv.h"
76 
77 #include <uavtalk.h>
78 
79 // Private constants
80 #define STACK_SIZE_BYTES 1200
81 #define TASK_PRIORITY PIOS_THREAD_PRIO_LOW
82 const char DIGITS[16] = "0123456789abcdef";
83 
84 #define LOGGING_PERIOD_MS 100
85 
86 // Private types
87 
88 // Private variables
90 static struct pios_thread *loggingTaskHandle;
91 static bool module_enabled;
92 static volatile LoggingSettingsData settings;
93 static LoggingStatsData loggingData;
94 
95 // Private functions
96 static void loggingTask(void *parameters);
97 static int32_t send_data(uint8_t *data, int32_t length);
98 static int32_t send_data_nonblock(void *ctx, uint8_t *data, int32_t length);
99 static uint16_t get_minimum_logging_period();
100 static void unregister_object(UAVObjHandle obj);
101 static void register_object(UAVObjHandle obj);
102 static void register_default_profile();
103 static void logAll(UAVObjHandle obj);
104 static void logSettings(UAVObjHandle obj);
105 static void writeHeader();
106 static void updateSettings();
107 
108 // Local variables
109 static uintptr_t logging_com_id;
110 static uint32_t written_bytes;
112 
113 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
114 static const struct streamfs_cfg streamfs_settings = {
115  .fs_magic = 0x89abceef,
116  .arena_size = PIOS_LOGFLASH_SECT_SIZE,
117  .write_size = 0x00000100, /* 256 bytes */
118 };
119 #endif
120 
126 int32_t LoggingInitialize(void)
127 {
128  if (LoggingSettingsInitialize() == -1) {
129  module_enabled = false;
130  return -1;
131  }
132 
133 #ifdef PIOS_COM_OPENLOG
134  if (PIOS_COM_OPENLOG) {
136  updateSettings();
137  }
138 #endif
139 
140 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
141  if (!logging_com_id) {
142  uintptr_t streamfs_id;
143 
144  if (PIOS_STREAMFS_Init(&streamfs_id, &streamfs_settings, FLASH_PARTITION_LABEL_LOG) != 0) {
145  module_enabled = false;
146  return -1;
147  }
148 
149  const uint32_t LOG_BUF_LEN = 768;
151  streamfs_id, 0, LOG_BUF_LEN) != 0) {
152  module_enabled = false;
153  return -1;
154  }
155 
157  updateSettings();
158  }
159 #endif
160 
161 #ifdef MODULE_Logging_BUILTIN
162  module_enabled = true;
163 #else
164  uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM];
165  ModuleSettingsAdminStateGet(module_state);
166  if (module_state[MODULESETTINGS_ADMINSTATE_LOGGING] == MODULESETTINGS_ADMINSTATE_ENABLED) {
167  module_enabled = true;
168  } else {
169  module_enabled = false;
170  }
171 #endif
172 
173  if (!logging_com_id) {
174  module_enabled = false;
175  }
176 
177  if (!module_enabled)
178  return -1;
179 
180  if (LoggingStatsInitialize() == -1) {
181  module_enabled = false;
182  return -1;
183  }
184 
185  // Initialise UAVTalk
187  NULL, NULL, NULL);
188 
189  if (!uavTalkCon) {
190  module_enabled = false;
191  return -1;
192  }
193 
194  return 0;
195 }
196 
202 int32_t LoggingStart(void)
203 {
204  //Check if module is enabled or not
205  if (module_enabled == false) {
206  return -1;
207  }
208 
209  // Start logging task
211 
212  TaskMonitorAdd(TASKINFO_RUNNING_LOGGING, loggingTaskHandle);
213 
214  return 0;
215 }
216 
218 
219 static void loggingTask(void *parameters)
220 {
221  bool armed = false;
222  uint32_t now = PIOS_Thread_Systime();
223 
224 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
225  bool write_open = false;
226  bool read_open = false;
227  int32_t read_sector = 0;
228  uint8_t read_data[LOGGINGSTATS_FILESECTOR_NUMELEM];
229 #endif
230 
231  // Get settings automatically for now on
232  LoggingSettingsConnectCopy(&settings);
233 
234  LoggingStatsGet(&loggingData);
235  loggingData.BytesLogged = 0;
236 
237 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
241  }
242 #endif
243 
245  updateSettings();
246  }
247 
248  if (settings.LogBehavior == LOGGINGSETTINGS_LOGBEHAVIOR_LOGONSTART) {
249  loggingData.Operation = LOGGINGSTATS_OPERATION_INITIALIZING;
250  } else {
251  loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
252  }
253 
254  LoggingStatsSet(&loggingData);
255 
256  // Loop forever
257  while (1)
258  {
259  LoggingStatsGet(&loggingData);
260 
261  // Check for change in armed state if logging on armed
262 
263  if (settings.LogBehavior == LOGGINGSETTINGS_LOGBEHAVIOR_LOGONARM) {
264  FlightStatusData flightStatus;
265  FlightStatusGet(&flightStatus);
266 
267  if (flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED && !armed) {
268  // Start logging because just armed
269  loggingData.Operation = LOGGINGSTATS_OPERATION_INITIALIZING;
270  armed = true;
271  LoggingStatsSet(&loggingData);
272  } else if (flightStatus.Armed == FLIGHTSTATUS_ARMED_DISARMED && armed) {
273  loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
274  armed = false;
275  LoggingStatsSet(&loggingData);
276  }
277  }
278 
279  switch (loggingData.Operation) {
280  case LOGGINGSTATS_OPERATION_FORMAT:
281  // Format the file system
282 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
284  if (read_open || write_open) {
286  read_open = false;
287  write_open = false;
288  }
289 
293  }
294 #endif /* PIOS_INCLUDE_LOG_TO_FLASH */
295  loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
296  LoggingStatsSet(&loggingData);
297  break;
298  case LOGGINGSTATS_OPERATION_INITIALIZING:
299  // Unregister all objects
301 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
303  // Close the file if it is open for reading
304  if (read_open) {
306  read_open = false;
307  }
308 
309  // Open the file if it is not open for writing
310  if (!write_open) {
312  loggingData.Operation = LOGGINGSTATS_OPERATION_ERROR;
313  continue;
314  } else {
315  write_open = true;
316  }
319  LoggingStatsSet(&loggingData);
320  }
321  }
322  else {
323  read_open = false;
324  write_open = true;
325  }
326 #endif /* PIOS_INCLUDE_LOG_TO_FLASH */
327 
328  // Write information at start of the log file
329  writeHeader();
330 
331  // Log settings
332  if (settings.InitiallyLog == LOGGINGSETTINGS_INITIALLYLOG_ALLOBJECTS) {
334  } else if (settings.InitiallyLog == LOGGINGSETTINGS_INITIALLYLOG_SETTINGSOBJECTS) {
336  }
337 
338  // Register objects to be logged
339  switch (settings.Profile) {
340  case LOGGINGSETTINGS_PROFILE_BASIC:
342  break;
343  case LOGGINGSETTINGS_PROFILE_CUSTOM:
344  case LOGGINGSETTINGS_PROFILE_FULLBORE:
346  break;
347  }
348 
349  // Empty the queue
350  LoggingStatsBytesLoggedSet(&written_bytes);
351  loggingData.Operation = LOGGINGSTATS_OPERATION_LOGGING;
352  LoggingStatsSet(&loggingData);
353  break;
354  case LOGGINGSTATS_OPERATION_LOGGING:
355  {
356  // Sleep between updating stats.
358 
359  LoggingStatsBytesLoggedSet(&written_bytes);
360 
361  now = PIOS_Thread_Systime();
362  }
363  break;
364  case LOGGINGSTATS_OPERATION_DOWNLOAD:
365 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
367  if (!read_open) {
368  // Start reading
369  if (PIOS_STREAMFS_OpenRead(logging_com_id, loggingData.FileRequest) != 0) {
370  loggingData.Operation = LOGGINGSTATS_OPERATION_ERROR;
371  } else {
372  read_open = true;
373  read_sector = -1;
374  }
375  }
376  if (read_open && read_sector == loggingData.FileSectorNum) {
377  // Request received for same sector. Reupdate.
378  memcpy(loggingData.FileSector, read_data, LOGGINGSTATS_FILESECTOR_NUMELEM);
379  loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
380 
381  } else if (read_open && (read_sector + 1) == loggingData.FileSectorNum) {
382  int32_t bytes_read = PIOS_STREAMFS_Read(logging_com_id, loggingData.FileSector, LOGGINGSTATS_FILESECTOR_NUMELEM);
383  if (bytes_read < 0) {
384  // close on error
385  loggingData.Operation = LOGGINGSTATS_OPERATION_ERROR;
386  loggingData.FileSectorNum = 0xffff;
388  read_open = false;
389  } else {
390  // Indicate sent
391  loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
392 
393  if (bytes_read < LOGGINGSTATS_FILESECTOR_NUMELEM) {
394  // indicate end of file
395  loggingData.Operation = LOGGINGSTATS_OPERATION_COMPLETE;
397  read_open = false;
398  }
399 
400  }
401  }
402  LoggingStatsSet(&loggingData);
403 
404  // Store the data in case it's needed again /
405  // lost over telemetry link
406  memcpy(read_data, loggingData.FileSector, LOGGINGSTATS_FILESECTOR_NUMELEM);
407  read_sector = loggingData.FileSectorNum;
408  }
409 #endif /* PIOS_INCLUDE_LOG_TO_FLASH */
410 
411  // fall-through to default case
412  default:
413  // Makes sure that we are not hogging the processor
414  PIOS_Thread_Sleep(10);
415 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
417  // Close the file if necessary
418  if (write_open) {
422  LoggingStatsSet(&loggingData);
423  write_open = false;
424  }
425  }
426 #endif /* PIOS_INCLUDE_LOG_TO_FLASH */
427  }
428  }
429 }
430 
435 static void logAll(UAVObjHandle obj)
436 {
438 }
439 
444 static void logSettings(UAVObjHandle obj)
445 {
446  if (UAVObjIsSettings(obj)) {
448  }
449 }
450 
451 
452 static int32_t send_data(uint8_t *data, int32_t length)
453 {
454  if (PIOS_COM_SendBuffer(logging_com_id, data, length) < 0)
455  return -1;
456 
458 
459  return length;
460 }
461 
469 static int32_t send_data_nonblock(void *ctx, uint8_t *data, int32_t length)
470 {
471  (void) ctx;
472 
473  if (PIOS_COM_SendBufferNonBlocking(logging_com_id, data, length) < 0)
474  return -1;
475 
477 
478  return length;
479 }
480 
485 static void obj_updated_callback(const UAVObjEvent *ev, void *cb_ctx,
486  void *uavo_data, int uavo_len)
487 {
488  (void) cb_ctx; (void) uavo_data; (void) uavo_len;
489 
490  if (loggingData.Operation != LOGGINGSTATS_OPERATION_LOGGING){
491  // We are not logging, so all events are discarded
492  return;
493  }
494 
496 }
497 
498 
502 static uint16_t get_minimum_logging_period()
503 {
504  uint16_t min_period = 200;
505 
506  switch (settings.MaxLogRate) {
507  case LOGGINGSETTINGS_MAXLOGRATE_5:
508  min_period = 200;
509  break;
510  case LOGGINGSETTINGS_MAXLOGRATE_10:
511  min_period = 100;
512  break;
513  case LOGGINGSETTINGS_MAXLOGRATE_25:
514  min_period = 40;
515  break;
516  case LOGGINGSETTINGS_MAXLOGRATE_50:
517  min_period = 20;
518  break;
519  case LOGGINGSETTINGS_MAXLOGRATE_100:
520  min_period = 10;
521  break;
522  case LOGGINGSETTINGS_MAXLOGRATE_166:
523  min_period = 6;
524  break;
525  case LOGGINGSETTINGS_MAXLOGRATE_250:
526  min_period = 4;
527  break;
528  case LOGGINGSETTINGS_MAXLOGRATE_333:
529  min_period = 3;
530  break;
531  case LOGGINGSETTINGS_MAXLOGRATE_500:
532  min_period = 2;
533  break;
534  case LOGGINGSETTINGS_MAXLOGRATE_1000:
535  min_period = 1;
536  break;
537  }
538  return min_period;
539 }
540 
541 
546 static void unregister_object(UAVObjHandle obj) {
548 }
549 
555 {
556  uint16_t period;
557 
558  if (settings.Profile == LOGGINGSETTINGS_PROFILE_FULLBORE) {
559  if (UAVObjIsSettings(obj)) {
560  return;
561  }
562 
563  period = 1;
564  } else {
565  UAVObjMetadata meta_data;
566  if (UAVObjGetMetadata(obj, &meta_data) < 0){
567  return;
568  }
569 
570  if (meta_data.loggingUpdatePeriod == 0){
571  return;
572  }
573 
574  period = meta_data.loggingUpdatePeriod;
575  }
576 
577  period = MAX(period, get_minimum_logging_period());
578 
579  if (period == 1) {
580  // log every update
582  } else {
583  // log updates throttled
585  }
586 }
587 
592 {
593  // For the default profile, we limit things to 100Hz (for now)
594  uint16_t min_period = MAX(get_minimum_logging_period(), 10);
595 
596  // Objects for which we log all changes (use 100Hz to limit max data rate)
599  if (WaypointActiveHandle()) {
600  UAVObjConnectCallbackThrottled(WaypointActiveHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10);
601  }
602 
603  if (SystemIdentHandle()){
605  }
606 
607  // Log fast
608  UAVObjConnectCallbackThrottled(AccelsHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, min_period);
609  UAVObjConnectCallbackThrottled(GyrosHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, min_period);
610 
611  // Log a bit slower
612  UAVObjConnectCallbackThrottled(AttitudeActualHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 5 * min_period);
613 
614  if (MagnetometerHandle()) {
615  UAVObjConnectCallbackThrottled(MagnetometerHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 5 * min_period);
616  }
617 
618  UAVObjConnectCallbackThrottled(ManualControlCommandHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 5 * min_period);
619  UAVObjConnectCallbackThrottled(ActuatorDesiredHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 5 * min_period);
620  UAVObjConnectCallbackThrottled(StabilizationDesiredHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 5 * min_period);
621 
622  // Log slow
623  if (FlightBatteryStateHandle()) {
624  UAVObjConnectCallbackThrottled(FlightBatteryStateHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10 * min_period);
625  }
626  if (BaroAltitudeHandle()) {
627  UAVObjConnectCallbackThrottled(BaroAltitudeHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10 * min_period);
628  }
629  if (AirspeedActualHandle()) {
630  UAVObjConnectCallbackThrottled(AirspeedActualHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10 * min_period);
631  }
632  if (GPSPositionHandle()) {
633  UAVObjConnectCallbackThrottled(GPSPositionHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10 * min_period);
634  }
635  if (PositionActualHandle()) {
636  UAVObjConnectCallbackThrottled(PositionActualHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10 * min_period);
637  }
638  if (VelocityActualHandle()) {
639  UAVObjConnectCallbackThrottled(VelocityActualHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 10 * min_period);
640  }
641 
642  // Log very slow
643  if (GPSTimeHandle()) {
644  UAVObjConnectCallbackThrottled(GPSTimeHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 50 * min_period);
645  }
646 
647  // Log very very slow
648  if (GPSSatellitesHandle()) {
649  UAVObjConnectCallbackThrottled(GPSSatellitesHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 500 * min_period);
650  }
651 
652  // Log LQG data
653  if (RTKFEstimateHandle()) {
654  UAVObjConnectCallbackThrottled(RTKFEstimateHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 2 * min_period);
655  }
656  if (LQGSolutionHandle()) {
657  UAVObjConnectCallbackThrottled(LQGSolutionHandle(), obj_updated_callback, NULL, EV_UPDATED | EV_UNPACKED, 100 * min_period);
658  }
659 }
660 
661 
666 static void writeHeader()
667 {
668  uint8_t fw_blob[100];
669  PIOS_BL_HELPER_FLASH_Read_Description((uint8_t *) &fw_blob,
670  sizeof(fw_blob));
671 
672  int pos;
673 #define STR_BUF_LEN 45
674  char tmp_str[STR_BUF_LEN];
675  char *info_str;
676  char this_char;
677  DateTimeT date_time;
678 
679  // Header
680  #define LOG_HEADER "dRonin git hash:\n"
681  send_data((uint8_t *)LOG_HEADER, strlen(LOG_HEADER));
682 
683  // Commit tag name
684  // XXX all of thse should use the fw_version_info structure instead of
685  // doing offset math, but we need to factor out the fw_version_info
686  // struct from the templates first.
687  info_str = (char*)(fw_blob + 14);
688  send_data((uint8_t*)info_str, strnlen(info_str, 26));
689 
690  // Git commit hash
691  pos = 0;
692  tmp_str[pos++] = ':';
693  for (int i = 0; i < 4; i++){
694  this_char = *(char*)(fw_blob + 7 - i);
695  tmp_str[pos++] = DIGITS[(this_char & 0xF0) >> 4];
696  tmp_str[pos++] = DIGITS[(this_char & 0x0F)];
697  }
698  send_data((uint8_t*)tmp_str, pos);
699 
700  // Date
701  date_from_timestamp(*(uint32_t *)(fw_blob + 8), &date_time);
702  uint8_t len = snprintf(tmp_str, STR_BUF_LEN, " %d%02d%02d\n", 1900 + date_time.year, date_time.mon + 1, date_time.mday);
703  send_data((uint8_t*)tmp_str, len);
704 
705  // UAVO SHA1
706  pos = 0;
707  for (int i = 0; i < 20; i++){
708  this_char = *(char*)(fw_blob + 60 + i);
709  tmp_str[pos++] = DIGITS[(this_char & 0xF0) >> 4];
710  tmp_str[pos++] = DIGITS[(this_char & 0x0F)];
711  }
712  tmp_str[pos++] = '\n';
713  send_data((uint8_t*)tmp_str, pos);
714 }
715 
716 static void updateSettings()
717 {
718  if (logging_com_id) {
719 
720  // Retrieve settings
721  uint8_t speed;
722  ModuleSettingsOpenLogSpeedGet(&speed);
723 
724  // Set port speed
725  switch (speed) {
726  case MODULESETTINGS_OPENLOGSPEED_115200:
728  break;
729  case MODULESETTINGS_OPENLOGSPEED_250000:
731  break;
732  /* Serial @ 42MHz 16OS can precisely hit 2mbps, 1.5mbps;
733  * Serial @ 45MHz 16OS can precisely hit 1.5mbps (2mbps off by 2%)
734  * Serial @ 48MHz 16OS can precisely hit 2mbps, 1.5mbps
735  */
736  case MODULESETTINGS_OPENLOGSPEED_1500000:
738  break;
739  case MODULESETTINGS_OPENLOGSPEED_2000000:
741  break;
742  /* This is the weird one.
743  * Serial @ 42MHz will pick 2470588 - 0.4% from openlager
744  * Serial @ 45MHz will pick 2500000 - 1.6% away
745  * Serial @ 96MHz (OpenLager) will pick 2461538
746  * Tolerance is supposed to be 3.3%-ish, but this is a
747  * high-noise environment and a fast signal, so..
748  */
749  case MODULESETTINGS_OPENLOGSPEED_2470000:
751  break;
752  }
753  }
754 }
755 
uint16_t speed
Definition: msp_messages.h:101
int32_t PIOS_STREAMFS_Init(uintptr_t *fs_id, const struct streamfs_cfg *cfg, enum pios_flash_partition_labels partition_label)
Initialize the flash object setting FS.
static bool destination_onboard_flash
Definition: logging.c:111
uint32_t PIOS_Thread_Systime(void)
Definition: pios_thread.c:212
int32_t UAVTalkSendObjectTimestamped(UAVTalkConnection connectionHandle, UAVObjHandle obj, uint16_t instId)
Definition: uavtalk.c:142
static LoggingStatsData loggingData
Definition: logging.c:93
static bool module_enabled
Definition: logging.c:91
const struct pios_com_driver pios_streamfs_com_driver
Definition: pios_streamfs.c:64
int32_t PIOS_COM_SendBufferNonBlocking(uintptr_t com_id, const uint8_t *buffer, uint16_t len)
static void unregister_object(UAVObjHandle obj)
Definition: logging.c:546
#define STR_BUF_LEN
void date_from_timestamp(uint32_t timestamp, DateTimeT *date_time)
Definition: timeutils.c:51
bool UAVObjIsSettings(UAVObjHandle obj)
static uintptr_t logging_com_id
Definition: logging.c:109
COM private definitions.
int32_t UAVObjConnectCallbackThrottled(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask, uint16_t interval)
#define TASK_PRIORITY
Definition: logging.c:81
static void loggingTask(void *parameters)
Definition: logging.c:219
static int32_t send_data_nonblock(void *ctx, uint8_t *data, int32_t length)
Definition: logging.c:469
#define PIOS_LOGFLASH_SECT_SIZE
Definition: pios_config.h:99
static void logAll(UAVObjHandle obj)
Definition: logging.c:435
static void writeHeader()
Definition: logging.c:666
int32_t PIOS_STREAMFS_OpenRead(uintptr_t fs_id, uint32_t file_id)
static void obj_updated_callback(const UAVObjEvent *ev, void *cb_ctx, void *uavo_data, int uavo_len)
Callback for adding an object to the logging queue.
Definition: logging.c:485
UAVObjHandle obj
int32_t PIOS_STREAMFS_Close(uintptr_t fs_id)
int32_t PIOS_STREAMFS_MinFileId(uintptr_t fs_id)
uint8_t data[XFER_BYTES_PER_PACKET]
Definition: bl_messages.h:129
uint8_t length
void * UAVTalkConnection
Definition: uavtalk.h:53
UAVTalkConnection UAVTalkInitialize(void *ctx, UAVTalkOutputCb outputStream, UAVTalkAckCb ackCallback, UAVTalkReqCb reqCallback, UAVTalkFileCb fileCallback)
Definition: uavtalk.c:59
static void register_object(UAVObjHandle obj)
Definition: logging.c:554
#define PIOS_COM_OPENLOG
Definition: pios_board.h:122
void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t *array, uint8_t size)
static volatile LoggingSettingsData settings
Definition: logging.c:92
struct _msp_pid_item pos
Definition: msp_messages.h:100
static int32_t send_data(uint8_t *data, int32_t length)
Definition: logging.c:452
#define MAX(a, b)
Definition: misc_math.h:40
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
Definition: pios_thread.c:89
#define STACK_SIZE_BYTES
Definition: logging.c:80
int32_t PIOS_STREAMFS_OpenWrite(uintptr_t fs_id)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
Definition: taskmonitor.c:67
uint8_t i
Definition: msp_messages.h:97
int32_t LoggingStart(void)
Definition: logging.c:202
int32_t UAVObjConnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask)
MODULE_INITCALL(LoggingInitialize, LoggingStart)
static uint16_t get_minimum_logging_period()
Definition: logging.c:502
static uint32_t written_bytes
Definition: logging.c:110
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
Definition: pios_thread.c:255
#define LOGGING_PERIOD_MS
Definition: logging.c:84
void PIOS_Thread_Sleep(uint32_t time_ms)
Definition: pios_thread.c:229
static void register_default_profile()
Definition: logging.c:591
PIOS_COM_SendBuffer(shub_global->frsky_port, shub_global->serial_buf, msg_length)
int32_t UAVObjGetMetadata(UAVObjHandle obj_handle, UAVObjMetadata *dataOut)
int32_t PIOS_COM_Init(uintptr_t *com_id, const struct pios_com_driver *driver, uintptr_t lower_id, uint16_t rx_buffer_len, uint16_t tx_buffer_len)
static struct pios_thread * loggingTaskHandle
Definition: logging.c:90
int32_t PIOS_STREAMFS_Read(uintptr_t fs_id, uint8_t *data, uint32_t len)
Includes PiOS and core architecture components.
int snprintf(char *buf, size_t count, const char *format,...)
static void updateSettings()
Definition: logging.c:716
int32_t LoggingInitialize(void)
Definition: logging.c:126
static UAVTalkConnection uavTalkCon
Definition: logging.c:89
int32_t PIOS_STREAMFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
const char DIGITS[16]
Definition: logging.c:82
int32_t PIOS_STREAMFS_MaxFileId(uintptr_t fs_id)
Include file of the UAVTalk library.
#define LOG_HEADER
static void logSettings(UAVObjHandle obj)
Definition: logging.c:444
int32_t PIOS_COM_ChangeBaud(uintptr_t com_id, uint32_t baud)
int32_t UAVObjDisconnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx)
void UAVObjIterate(void(*iterator)(UAVObjHandle obj))
Time conversion functions.