在飞多架无人机的时候,会给飞机修改设备编号id,地面站默认的sys_id设置范围1~255
在读取多个飞机的log日志时候,如果能够直接生成带着飞机编号的log文件是最好的,调研了一下,发现修改log的名称需要两个地方,一个是飞控端,生成的log存放在内存卡中。另一个是地面站QGC读取飞控的内存生成文件,这样是方便不用拆开机架方便读取。
1.px4 log日志文件的名称修改
生成log名称的代码路径//src/modules/logger/logger.cpp 1151行
可以看到代码段
首先获取设备id号,从参数中读取 int log_id = _param_mav_sys_id.get();
然后在名称的拼成上加上id
找不到参数 _param_mav_sys_id?
头文件中添加
(ParamInt<px4::params::MAV_SYS_ID>) _param_mav_sys_id
最后改完代码
if (time_ok) {
int n = create_log_dir(type, &tt, file_name, file_name_size);
if (n < 0) {
return -1;
}
char log_file_name_time[16] = "";
strftime(log_file_name_time, sizeof(log_file_name_time), "%H_%M_%S", &tt);
snprintf(log_file_name, sizeof(LogFileName::log_file_name), "%s%s_%d.ulg", log_file_name_time, replay_suffix,log_id);
snprintf(file_name + n, file_name_size - n, "/%s", log_file_name);
} else {
int n = create_log_dir(type, nullptr, file_name, file_name_size);
if (n < 0) {
return -1;
}
uint16_t file_number = 1; // start with file log001
/* look for the next file that does not exist */
while (file_number <= MAX_NO_LOGFILE) {
/* format log file path: e.g. /fs/microsd/log/sess001/log001.ulg */
snprintf(log_file_name, sizeof(LogFileName::log_file_name), "log%03u%s_%d.ulg", file_number, replay_suffix,log_id);
snprintf(file_name + n, file_name_size - n, "/%s", log_file_name);
if (!util::file_exist(file_name)) {
break;
}
file_number++;
}
if (file_number > MAX_NO_LOGFILE) {
/* we should not end up here, either we have more than MAX_NO_LOGFILE on the SD card, or another problem */
return -1;
}
}
这样从飞控板内存卡中读取出的log文件名最后就加上了飞机编号
2、地面站从飞控中读取的log文件名
代码路径/src/AnalyzeView/LogDownloadController.cc 600行
一样,先获取设备id
QString vehicleId = QString::number(_vehicle->id());
然后在名称的拼成上加上id
bool
LogDownloadController::_prepareLogDownload()
{
delete _downloadData;
_downloadData = nullptr;
QGCLogEntry* entry = _getNextSelected();
if(!entry) {
return false;
}
//-- Deselect file
entry->setSelected(false);
emit selectionChanged();
bool result = false;
QString ftime;
if(entry->time().date().year() < 2010) {
ftime = tr("UnknownDate");
} else {
ftime = entry->time().toString(QStringLiteral("yyyy-M-d-hh-mm-ss"));
}
//log file name add VehicleId
QString vehicleId = QString::number(_vehicle->id());
_downloadData = new LogDownloadData(entry);
//加这里
_downloadData->filename = QString("log_") + vehicleId+ "_" + QString::number(entry->id()) + "_" + ftime ;
if (_vehicle->firmwareType() == MAV_AUTOPILOT_PX4) {
QString loggerParam = QStringLiteral("SYS_LOGGER");
if (_vehicle->parameterManager()->parameterExists(FactSystem::defaultComponentId, loggerParam) &&
_vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, loggerParam)->rawValue().toInt() == 0) {
_downloadData->filename += ".px4log";
} else {
_downloadData->filename += ".ulg";
}
} else {
_downloadData->filename += ".bin";
}
_downloadData->file.setFileName(_downloadPath + _downloadData->filename);
//-- Append a number to the end if the filename already exists
if (_downloadData->file.exists()){
uint num_dups = 0;
QStringList filename_spl = _downloadData->filename.split('.');
do {
num_dups +=1;
_downloadData->file.setFileName(filename_spl[0] + '_' + QString::number(num_dups) + '.' + filename_spl[1]);
} while( _downloadData->file.exists());
}
//-- Create file
if (!_downloadData->file.open(QIODevice::WriteOnly)) {
qWarning() << "Failed to create log file:" << _downloadData->filename;
} else {
//-- Preallocate file
if(!_downloadData->file.resize(entry->size())) {
qWarning() << "Failed to allocate space for log file:" << _downloadData->filename;
} else {
_downloadData->current_chunk = 0;
_downloadData->chunk_table = QBitArray(_downloadData->chunkBins(), false);
_downloadData->elapsed.start();
result = true;
}
}
if(!result) {
if (_downloadData->file.exists()) {
_downloadData->file.remove();
}
_downloadData->entry->setStatus(tr("Error"));
delete _downloadData;
_downloadData = nullptr;
}
return result;
}
这样就能从qgc上直接读取到名称带有设备id号的log文件