void sdlog2_start_log() { warnx("start logging"); mavlink_log_info(mavlink_fd, "[sdlog2] start logging"); /* create log dir if needed */ if (create_log_dir() != 0) { mavlink_log_critical(mavlink_fd, "[sdlog2] error creating log dir"); errx(1, "error creating log dir"); } /* initialize statistics counter */ log_bytes_written = 0; start_time = hrt_absolute_time(); log_msgs_written = 0; log_msgs_skipped = 0; /* initialize log buffer emptying thread */ pthread_attr_init(&logwriter_attr); struct sched_param param; /* low priority, as this is expensive disk I/O */ param.sched_priority = SCHED_PRIORITY_DEFAULT - 40; (void)pthread_attr_setschedparam(&logwriter_attr, ¶m); pthread_attr_setstacksize(&logwriter_attr, 2048); logwriter_should_exit = false; /* start log buffer emptying thread */ if (0 != pthread_create(&logwriter_pthread, &logwriter_attr, logwriter_thread, &lb)) { errx(1, "error creating logwriter thread"); } logging_enabled = true; }
void *eng_vdiag_rthread(void *x) { int ser_fd, modem_fd,test_fd = -1; int r_cnt, w_cnt, offset; int retry_num = 0; int dumpmemlen = 0; int ret = -1; int flag = 0; s_dev_info = (eng_dev_info_t*)x; char get_propvalue[PROPERTY_VALUE_MAX] = {0}; ENG_LOG("eng_vdiag_r thread start\n"); /*open usb/uart*/ ENG_LOG("eng_vdiag_r open serial...\n"); ENG_LOG("eng_vdiag_r s_dev_info->host_int.dev_diag=%s\n",s_dev_info->host_int.dev_diag); ser_fd = eng_open_dev(s_dev_info->host_int.dev_diag, O_WRONLY); if(ser_fd < 0) { ENG_LOG("eng_vdiag_r open serial failed, error: %s\n", strerror(errno)); return NULL; } if(s_dev_info->host_int.dev_type == CONNECT_UART){ set_raw_data_speed(ser_fd, 115200); } s_ser_diag_fd = ser_fd; /*open vbpipe/spipe*/ ENG_LOG("eng_vdiag_r open SIPC channel...\n"); do{ modem_fd = open(s_dev_info->modem_int.diag_chan, O_RDONLY); if(modem_fd < 0) { ENG_LOG("eng_vdiag_r cannot open %s, error: %s\n", s_dev_info->modem_int.diag_chan, strerror(errno)); sleep(5); } if((++retry_num) > MAX_OPEN_TIMES) { ENG_LOG("eng_vdiag_r SIPC open times exceed the max times, vlog thread stopped.\n"); goto out; } }while(modem_fd < 0); if(s_dev_info->host_int.cali_flag && (s_dev_info->host_int.dev_type == CONNECT_USB) && !g_ap_cali_flag){ eng_usb_enable(); } ENG_LOG("eng_vdiag_r put log data from SIPC to serial\n"); while(1) { int split_flag = 0; memset(diag_data, 0, sizeof(diag_data)); r_cnt = read(modem_fd, diag_data, DATA_BUF_SIZE); if (r_cnt <= 0) { ENG_LOG("eng_vdiag_r read no log data : r_cnt=%d, %s\n", r_cnt, strerror(errno)); continue; } if(CONNECT_UART == s_dev_info->host_int.dev_type){ property_set("sys.config.engcplog.enable","1"); } property_get("sys.config.engcplog.enable", get_propvalue, "not_find"); if((0 == strcmp(get_propvalue, "1")) && (1 == s_dev_info->host_int.cali_flag)){ ENG_LOG("%s sys.config.engcplog.enable= %s\n",__FUNCTION__, get_propvalue); if (flag == 0) { ret = create_log_dir(); if (!ret) { flag = 1; test_fd = open_log_path(); if(test_fd < 0){ ENG_LOG("eng_vdiag_r cannot open %s.\n", external_path); } } } if (test_fd >= 0) { ret = eng_write_data_to_file(diag_data,r_cnt,test_fd); if(ret < 0){ ENG_LOG("eng_vdiag_r write to logfile failed\n"); } } ENG_LOG("%s: r_cnt=%d\n", __FUNCTION__,r_cnt); eng_filter_calibration_log_diag(diag_data,r_cnt,ser_fd); }else{ // printf dump memory len dump_mem_len_print(r_cnt, &dumpmemlen); if( 0 == eng_diag_write2pc(diag_data, r_cnt, ser_fd)){ close(modem_fd); return 0; } } } out: ENG_LOG("eng_vdiag_r thread end\n"); if (modem_fd >= 0) close(modem_fd); if (test_fd >= 0) close(test_fd); close(ser_fd); return 0; }