35 #include "modulesettings.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"
57 #include "gpssatellites.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"
72 #include "pios_bl_helper.h"
80 #define STACK_SIZE_BYTES 1200
81 #define TASK_PRIORITY PIOS_THREAD_PRIO_LOW
82 const char DIGITS[16] =
"0123456789abcdef";
84 #define LOGGING_PERIOD_MS 100
113 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
117 .write_size = 0x00000100,
128 if (LoggingSettingsInitialize() == -1) {
133 #ifdef PIOS_COM_OPENLOG
140 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
142 uintptr_t streamfs_id;
149 const uint32_t LOG_BUF_LEN = 768;
151 streamfs_id, 0, LOG_BUF_LEN) != 0) {
161 #ifdef MODULE_Logging_BUILTIN
164 uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM];
165 ModuleSettingsAdminStateGet(module_state);
166 if (module_state[MODULESETTINGS_ADMINSTATE_LOGGING] == MODULESETTINGS_ADMINSTATE_ENABLED) {
180 if (LoggingStatsInitialize() == -1) {
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];
232 LoggingSettingsConnectCopy(&
settings);
237 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
248 if (
settings.LogBehavior == LOGGINGSETTINGS_LOGBEHAVIOR_LOGONSTART) {
249 loggingData.Operation = LOGGINGSTATS_OPERATION_INITIALIZING;
251 loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
263 if (
settings.LogBehavior == LOGGINGSETTINGS_LOGBEHAVIOR_LOGONARM) {
264 FlightStatusData flightStatus;
265 FlightStatusGet(&flightStatus);
267 if (flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED && !armed) {
269 loggingData.Operation = LOGGINGSTATS_OPERATION_INITIALIZING;
272 }
else if (flightStatus.Armed == FLIGHTSTATUS_ARMED_DISARMED && armed) {
273 loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
280 case LOGGINGSTATS_OPERATION_FORMAT:
282 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
284 if (read_open || write_open) {
295 loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
298 case LOGGINGSTATS_OPERATION_INITIALIZING:
301 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
312 loggingData.Operation = LOGGINGSTATS_OPERATION_ERROR;
332 if (
settings.InitiallyLog == LOGGINGSETTINGS_INITIALLYLOG_ALLOBJECTS) {
334 }
else if (
settings.InitiallyLog == LOGGINGSETTINGS_INITIALLYLOG_SETTINGSOBJECTS) {
340 case LOGGINGSETTINGS_PROFILE_BASIC:
343 case LOGGINGSETTINGS_PROFILE_CUSTOM:
344 case LOGGINGSETTINGS_PROFILE_FULLBORE:
351 loggingData.Operation = LOGGINGSTATS_OPERATION_LOGGING;
354 case LOGGINGSTATS_OPERATION_LOGGING:
364 case LOGGINGSTATS_OPERATION_DOWNLOAD:
365 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
370 loggingData.Operation = LOGGINGSTATS_OPERATION_ERROR;
376 if (read_open && read_sector ==
loggingData.FileSectorNum) {
378 memcpy(
loggingData.FileSector, read_data, LOGGINGSTATS_FILESECTOR_NUMELEM);
379 loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
381 }
else if (read_open && (read_sector + 1) ==
loggingData.FileSectorNum) {
383 if (bytes_read < 0) {
385 loggingData.Operation = LOGGINGSTATS_OPERATION_ERROR;
391 loggingData.Operation = LOGGINGSTATS_OPERATION_IDLE;
393 if (bytes_read < LOGGINGSTATS_FILESECTOR_NUMELEM) {
395 loggingData.Operation = LOGGINGSTATS_OPERATION_COMPLETE;
406 memcpy(read_data,
loggingData.FileSector, LOGGINGSTATS_FILESECTOR_NUMELEM);
415 #ifdef PIOS_INCLUDE_LOG_TO_FLASH
486 void *uavo_data,
int uavo_len)
488 (void) cb_ctx; (void) uavo_data; (void) uavo_len;
490 if (
loggingData.Operation != LOGGINGSTATS_OPERATION_LOGGING){
504 uint16_t min_period = 200;
507 case LOGGINGSETTINGS_MAXLOGRATE_5:
510 case LOGGINGSETTINGS_MAXLOGRATE_10:
513 case LOGGINGSETTINGS_MAXLOGRATE_25:
516 case LOGGINGSETTINGS_MAXLOGRATE_50:
519 case LOGGINGSETTINGS_MAXLOGRATE_100:
522 case LOGGINGSETTINGS_MAXLOGRATE_166:
525 case LOGGINGSETTINGS_MAXLOGRATE_250:
528 case LOGGINGSETTINGS_MAXLOGRATE_333:
531 case LOGGINGSETTINGS_MAXLOGRATE_500:
534 case LOGGINGSETTINGS_MAXLOGRATE_1000:
558 if (
settings.Profile == LOGGINGSETTINGS_PROFILE_FULLBORE) {
565 UAVObjMetadata meta_data;
570 if (meta_data.loggingUpdatePeriod == 0){
574 period = meta_data.loggingUpdatePeriod;
599 if (WaypointActiveHandle()) {
603 if (SystemIdentHandle()){
614 if (MagnetometerHandle()) {
623 if (FlightBatteryStateHandle()) {
626 if (BaroAltitudeHandle()) {
629 if (AirspeedActualHandle()) {
632 if (GPSPositionHandle()) {
635 if (PositionActualHandle()) {
638 if (VelocityActualHandle()) {
643 if (GPSTimeHandle()) {
648 if (GPSSatellitesHandle()) {
653 if (RTKFEstimateHandle()) {
656 if (LQGSolutionHandle()) {
668 uint8_t fw_blob[100];
673 #define STR_BUF_LEN 45
680 #define LOG_HEADER "dRonin git hash:\n"
687 info_str = (
char*)(fw_blob + 14);
688 send_data((uint8_t*)info_str, strnlen(info_str, 26));
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)];
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);
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)];
712 tmp_str[pos++] =
'\n';
722 ModuleSettingsOpenLogSpeedGet(&speed);
726 case MODULESETTINGS_OPENLOGSPEED_115200:
729 case MODULESETTINGS_OPENLOGSPEED_250000:
736 case MODULESETTINGS_OPENLOGSPEED_1500000:
739 case MODULESETTINGS_OPENLOGSPEED_2000000:
749 case MODULESETTINGS_OPENLOGSPEED_2470000:
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
uint32_t PIOS_Thread_Systime(void)
int32_t UAVTalkSendObjectTimestamped(UAVTalkConnection connectionHandle, UAVObjHandle obj, uint16_t instId)
static LoggingStatsData loggingData
static bool module_enabled
const struct pios_com_driver pios_streamfs_com_driver
int32_t PIOS_COM_SendBufferNonBlocking(uintptr_t com_id, const uint8_t *buffer, uint16_t len)
static void unregister_object(UAVObjHandle obj)
void date_from_timestamp(uint32_t timestamp, DateTimeT *date_time)
bool UAVObjIsSettings(UAVObjHandle obj)
static uintptr_t logging_com_id
int32_t UAVObjConnectCallbackThrottled(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask, uint16_t interval)
static void loggingTask(void *parameters)
static int32_t send_data_nonblock(void *ctx, uint8_t *data, int32_t length)
#define PIOS_LOGFLASH_SECT_SIZE
static void logAll(UAVObjHandle obj)
static void writeHeader()
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.
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]
UAVTalkConnection UAVTalkInitialize(void *ctx, UAVTalkOutputCb outputStream, UAVTalkAckCb ackCallback, UAVTalkReqCb reqCallback, UAVTalkFileCb fileCallback)
static void register_object(UAVObjHandle obj)
void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t *array, uint8_t size)
static volatile LoggingSettingsData settings
static int32_t send_data(uint8_t *data, int32_t length)
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
int32_t PIOS_STREAMFS_OpenWrite(uintptr_t fs_id)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
int32_t LoggingStart(void)
int32_t UAVObjConnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask)
MODULE_INITCALL(LoggingInitialize, LoggingStart)
static uint16_t get_minimum_logging_period()
static uint32_t written_bytes
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
#define LOGGING_PERIOD_MS
void PIOS_Thread_Sleep(uint32_t time_ms)
static void register_default_profile()
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
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()
int32_t LoggingInitialize(void)
static UAVTalkConnection uavTalkCon
int32_t PIOS_STREAMFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
int32_t PIOS_STREAMFS_MaxFileId(uintptr_t fs_id)
Include file of the UAVTalk library.
static void logSettings(UAVObjHandle obj)
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.