bool Data_logging::create_new_log_file(const char* file_name__, bool continuous_write__, uint32_t sysid) { bool init_success = true; // Allocate memory for the onboard data_log //data_logging_set = (data_logging_set_t*)malloc(sizeof(data_logging_set_t) + sizeof(data_logging_entry_t[config->max_data_logging_count])); file_init_ = false; file_opened_ = false; sys_status_ = true; // Setting the maximal size of the name string #if _USE_LFN buffer_name_size_ = _MAX_LFN; #else #ifdef _MAX_LFN buffer_name_size_ = 8; #else buffer_name_size_ = 255; #endif #endif // Allocating memory for the file name string file_name_ = (char*)malloc(buffer_name_size_); name_n_extension_ = (char*)malloc(buffer_name_size_); if (file_name_ == NULL) { init_success &= false; } if (name_n_extension_ == NULL) { init_success &= false; } sys_id_ = sysid; // Append sysid to filename filename_append_int(file_name_, (char*)file_name__, sysid, buffer_name_size_); init_success &= open_new_log_file(); logging_time_ = time_keeper_get_ms(); cksum_a_ = 0.0; cksum_b_ = 0.0; return init_success; }
static void open_log_file(struct logging_status *ls) { pr_info("Logging: Opening log file\r\n"); ls->writing_status = WRITING_INACTIVE; const int rc = InitFS(); if (0 != rc) { pr_error_int_msg("Logging: FS init error: ", rc); return; } pr_debug("Logging: FS init success. Opening file...\r\n"); // Open a file if one is set, else create a new one. ls->writing_status = ls->name[0] ? open_existing_log_file(ls) : open_new_log_file(ls); if (WRITING_INACTIVE == ls->writing_status) { pr_warning_str_msg("Logging: Failed to open: ", ls->name); return; } pr_info_str_msg("Logging: Opened " , ls->name); ls->flush_tick = xTaskGetTickCount(); }
bool Data_logging::update(void) { uint32_t time_ms = 0; if (log_data_ == 1) { if (file_opened_) { if (!file_init_) { add_header_name(); } if (!state_.is_armed()) { time_ms = time_keeper_get_ms(); if ((time_ms - logging_time_) > 5000) { console_.get_stream()->flush(); logging_time_ = time_ms; } } if (continuous_write_) { log_parameters(); } else { if (checksum_control()) { log_parameters(); } } } //end of if (file_opened_) else { if (sys_status_) { open_new_log_file(); } cksum_a_ = 0.0; cksum_b_ = 0.0; }//end of else if (file_opened_) } //end of if (log_data_ == 1) else { sys_status_ = true; if (file_opened_) { bool succeed = console_.get_stream()->close(); cksum_a_ = 0.0; cksum_b_ = 0.0; file_opened_ = false; file_init_ = false; if (debug_) { if (succeed) { print_util_dbg_print("File closed\r\n"); } else { print_util_dbg_print("Error closing file\r\n"); } } } //end of if (file_opened_) } //end of else (log_data_ != 1) return true; }