更新:1、增加日志模块,将标准输出信息写入到日志文件;
2、将RadarPara中DATA_RATE_TAS的单位由Hz改为s; 3、修复TAS_Ctrl::tas_beam_output函数中给Tracking_beam->TAS_track_index赋值错误的问题; Signed-off-by: waiwaylee <waiwaylee@foxmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "data_process.h"
|
||||
#include "rdp_log.h"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
@@ -163,7 +164,7 @@ int model)
|
||||
// {
|
||||
// std::cout << "point_recv_tas :" <<point_recv_tas[0].Azimuth/PI*180<<" "<<point_recv_tas[0].Range;
|
||||
// }
|
||||
//std::cout << "TAS process :" << TAS_track_idx << "p a r:"<<point_recv_tas[0].Point_Sum<<" " <<point_recv_tas[0].Azimuth/PI*180<<" "<<point_recv_tas[0].Range;
|
||||
// RDP_LOG << "TAS process :" << TAS_track_idx << "p a r:"<<point_recv_tas[0].Point_Sum<<" " <<point_recv_tas[0].Azimuth/PI*180<<" "<<point_recv_tas[0].Range << std::endl;
|
||||
|
||||
std::vector<PointRecv>().swap(Data_buffer_tas);//凝聚完毕 清除Data_buffer
|
||||
|
||||
@@ -252,7 +253,7 @@ int Data_Process:: track_delete(int delete_track_num, //手动
|
||||
{
|
||||
|
||||
trust_track[j].manual_delete_flag=1;
|
||||
std::cout << "Delete :" << trust_track[j].Track_Index << std::endl;
|
||||
// RDP_LOG << "Delete :" << trust_track[j].Track_Index << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#endif
|
||||
#include "data_process_class_dll.h"
|
||||
#include "data_process.h"
|
||||
#include "rdp_log.h"
|
||||
|
||||
/*
|
||||
Data_process_class_dll::Data_process_class_dll()
|
||||
@@ -16,7 +17,9 @@ Data_process_class_dll *Data_Process_Factory::GetB()
|
||||
{
|
||||
if(!p)
|
||||
{
|
||||
p=new Data_Process();
|
||||
//初始化日志输出:RDP_LOG_ENABLE 开启时重定向 std::cout 到日志文件
|
||||
//rdp_log::Init();
|
||||
p=new Data_Process();
|
||||
}
|
||||
|
||||
return p;
|
||||
@@ -30,5 +33,8 @@ void Data_Process_Factory::Destroy()
|
||||
if (p) {
|
||||
delete p;
|
||||
p = nullptr;
|
||||
|
||||
//恢复 std::cout 到控制台并关闭日志文件
|
||||
//rdp_log::Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ struct DATA_PROCESS_CLASS_DLLSHARED_EXPORT RadarPara
|
||||
float DATA_RATE_MIDDLE;
|
||||
float DATA_RATE_FAR;
|
||||
|
||||
float DATA_RATE_TAS; //TAS模式数据率,由dll调用者输入;TAS波束输出间隔阈值为 1/DATA_RATE_TAS 秒
|
||||
float DATA_RATE_TAS; //TAS模式数据率,由dll调用者输入;TAS波束输出间隔阈值为 DATA_RATE_TAS 秒
|
||||
|
||||
//数据关联参数
|
||||
int track_start_point_num; //起批点数(典型值 3或4)
|
||||
|
||||
@@ -7,6 +7,17 @@
|
||||
//频点(GHz)
|
||||
#define FREQ0 9.2
|
||||
|
||||
/**********************************日志输出开关**********************************************/
|
||||
// 日志文件输出功能开关:
|
||||
// 1) 定义(默认)RDP_LOG_ENABLE:启用日志文件输出 —— 调用 Data_Process_Factory::GetB()
|
||||
// 时自动将 std::cout 重定向到日志文件,日志文件存放于 RDP_LOG_DIR 目录,
|
||||
// 文件名按当前日期+时间自动命名(如 rdp_20240826_153000.log);
|
||||
// 2) 注释掉 RDP_LOG_ENABLE:关闭 —— 不做重定向,日志仍输出到标准输出(控制台)。
|
||||
//#define RDP_LOG_ENABLE
|
||||
|
||||
//日志文件输出目录(相对当前工作目录的路径,目录不存在时自动创建)
|
||||
#define RDP_LOG_DIR ".\\rdp_logs\\"
|
||||
|
||||
//#define MECHANICAL_SCANNING
|
||||
//#define PHASE_SCANNING
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
#include "rdp_log.h"
|
||||
#include "parameters.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <direct.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
//日志模块内部状态:日志文件流 + 重定向前 std::cout 的原始缓冲区
|
||||
struct RdpLogState
|
||||
{
|
||||
std::ofstream file; //日志文件输出流
|
||||
std::streambuf *original_buf; //重定向前 std::cout 的原始缓冲区
|
||||
bool enabled; //是否已成功重定向到日志文件
|
||||
|
||||
RdpLogState() : original_buf(0), enabled(false) {}
|
||||
|
||||
~RdpLogState()
|
||||
{
|
||||
//进程退出兜底:若宿主进程未调用 Data_Process_Factory::Destroy(),
|
||||
//此处恢复 std::cout,避免其仍指向即将析构的日志文件流缓冲区。
|
||||
if (enabled && original_buf)
|
||||
{
|
||||
std::cout.rdbuf(original_buf);
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RdpLogState &State()
|
||||
{
|
||||
static RdpLogState s;
|
||||
return s;
|
||||
}
|
||||
|
||||
//当前本地时间字符串,格式 "YYYY-MM-DD HH:MM:SS"
|
||||
std::string CurrentTime()
|
||||
{
|
||||
char buf[32] = {0};
|
||||
time_t now = time(NULL);
|
||||
struct tm local;
|
||||
if (localtime_s(&local, &now) != 0)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &local);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
//提取纯文件名(去掉路径前缀),日志前缀中只显示 文件名:行号
|
||||
const char *FileName(const char *path)
|
||||
{
|
||||
if (path == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
const char *base = path;
|
||||
for (const char *p = path; *p != '\0'; ++p)
|
||||
{
|
||||
if (*p == '\\' || *p == '/')
|
||||
{
|
||||
base = p + 1;
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
||||
namespace rdp_log
|
||||
{
|
||||
bool Init()
|
||||
{
|
||||
RdpLogState &st = State();
|
||||
if (st.enabled)
|
||||
{
|
||||
return true; //已经重定向,避免重复初始化
|
||||
}
|
||||
|
||||
#ifdef RDP_LOG_ENABLE
|
||||
//创建日志目录(目录已存在时 _mkdir 返回 EEXIST,忽略)
|
||||
std::string log_dir = RDP_LOG_DIR;
|
||||
while (log_dir.size() > 0 &&
|
||||
(log_dir[log_dir.size() - 1] == '\\' || log_dir[log_dir.size() - 1] == '/'))
|
||||
{
|
||||
log_dir.erase(log_dir.size() - 1);
|
||||
}
|
||||
if (log_dir.size() > 0)
|
||||
{
|
||||
_mkdir(log_dir.c_str());
|
||||
}
|
||||
|
||||
//按当前日期+时间生成日志文件名:rdp_YYYYMMDD_HHMMSS.log
|
||||
char time_buf[32] = {0};
|
||||
time_t now = time(NULL);
|
||||
struct tm local;
|
||||
if (localtime_s(&local, &now) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
strftime(time_buf, sizeof(time_buf), "%Y%m%d_%H%M%S", &local);
|
||||
|
||||
std::string log_path = RDP_LOG_DIR;
|
||||
log_path += "rdp_";
|
||||
log_path += time_buf;
|
||||
log_path += ".log";
|
||||
|
||||
st.file.open(log_path.c_str(), std::ios::out | std::ios::trunc);
|
||||
if (!st.file.is_open())
|
||||
{
|
||||
//日志文件打开失败(目录不可写等):保持控制台输出,不做重定向
|
||||
std::cout << "[rdp_log] cannot open log file: " << log_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//用 rdbuf() 将 std::cout 的流缓冲区替换为日志文件输出流
|
||||
st.original_buf = std::cout.rdbuf();
|
||||
std::cout.rdbuf(st.file.rdbuf());
|
||||
st.enabled = true;
|
||||
|
||||
//重定向成功后写入起始标记(该行已写入日志文件)
|
||||
std::cout << prefix(__FILE__, __LINE__)
|
||||
<< "rdp_log enabled, log file: " << log_path << std::endl;
|
||||
return true;
|
||||
#else
|
||||
//日志开关关闭:不重定向,日志仍输出到标准输出
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
RdpLogState &st = State();
|
||||
if (!st.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//写入结束标记后刷新、恢复 std::cout 并关闭日志文件
|
||||
std::cout << prefix(__FILE__, __LINE__) << "rdp_log shutdown" << std::endl;
|
||||
st.file.flush();
|
||||
std::cout.rdbuf(st.original_buf);
|
||||
st.enabled = false;
|
||||
st.file.close();
|
||||
}
|
||||
|
||||
std::string prefix(const char *file, int line)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "[" << CurrentTime() << "][" << FileName(file) << ":" << line << "] ";
|
||||
return oss.str();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef RDP_LOG_H
|
||||
#define RDP_LOG_H
|
||||
#pragma once
|
||||
/*************************************日志输出模块*******************************************/
|
||||
// 功能:
|
||||
// 1) rdp_log::Init():按 parameters.h 中 RDP_LOG_ENABLE 宏开关决定是否将 std::cout
|
||||
// 重定向到日志文件(RDP_LOG_DIR 目录,文件名按当前日期+时间自动生成)。
|
||||
// 开关关闭(注释掉 RDP_LOG_ENABLE)时不做重定向,日志仍输出到标准输出。
|
||||
// 2) rdp_log::Shutdown():恢复 std::cout 原始缓冲区(回到控制台)并关闭日志文件。
|
||||
// 3) RDP_LOG 宏:日志输出宏,在每条日志前自动附加 [时间戳][代码文件:行号] 信息,
|
||||
// 随后输出到 std::cout(若开关开启则随 cout 一并写入日志文件)。
|
||||
// 用法示例:
|
||||
// RDP_LOG << "目标批号:" << track_index << std::endl;
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace rdp_log
|
||||
{
|
||||
bool Init(); //初始化日志输出(由 Data_Process_Factory::GetB() 调用)
|
||||
void Shutdown(); //恢复 std::cout 并关闭日志文件(由 Data_Process_Factory::Destroy() 调用)
|
||||
std::string prefix(const char *file, int line); //生成 "[时间戳][文件名:行号] " 前缀字符串
|
||||
}
|
||||
|
||||
//日志输出宏:自动附加 时间戳、代码文件、代码行号 后输出到标准输出(std::cout)
|
||||
#define RDP_LOG std::cout << rdp_log::prefix(__FILE__, __LINE__)
|
||||
|
||||
#endif // RDP_LOG_H
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "tas_ctrl.h"
|
||||
#include "coor_trans.h"
|
||||
#include "rdp_log.h"
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -280,8 +283,8 @@ void TAS_Ctrl::tas_beam_output(std::vector<Trust_Track> *trust_track
|
||||
CPI_time = (*trust_track)[track_idx].T_track;
|
||||
delta_T = (latest_timestamp - CPI_time) / 1000.0f;
|
||||
|
||||
//查找最早的CPI时间, 航迹时间与当前最新时间戳的差值大于 1/DATA_RATE_TAS 时才输出TAS跟踪波束
|
||||
if(CPI_time < earliest_CPI_time && (latest_timestamp - tas_target_queue[tas_idx].last_track_time) / 1000.0f > 1.0f / Work_Parameter.DATA_RATE_TAS && delta_T > 1.0f / Work_Parameter.DATA_RATE_TAS)
|
||||
//查找最早的CPI时间, 航迹时间与当前最新时间戳的差值大于 DATA_RATE_TAS 时才输出TAS跟踪波束
|
||||
if(CPI_time < earliest_CPI_time && (latest_timestamp - tas_target_queue[tas_idx].last_track_time) / 1000.0f > Work_Parameter.DATA_RATE_TAS && delta_T > Work_Parameter.DATA_RATE_TAS)
|
||||
{
|
||||
earliest_CPI_time = CPI_time;
|
||||
H_track = (*trust_track)[track_idx].Height;
|
||||
@@ -292,8 +295,6 @@ void TAS_Ctrl::tas_beam_output(std::vector<Trust_Track> *trust_track
|
||||
for(int ii=0;ii<6;ii++){
|
||||
X_now[ii]=(*trust_track)[track_idx].X[ii];
|
||||
}
|
||||
|
||||
printf("TAS: earliest_track_idx: %d, CPI_time: %lld, delta_T: %.3f\n", earliest_track_idx, CPI_time, delta_T);
|
||||
|
||||
}
|
||||
|
||||
@@ -340,10 +341,10 @@ void TAS_Ctrl::tas_beam_output(std::vector<Trust_Track> *trust_track
|
||||
Tracking_beam->type=1;
|
||||
|
||||
//跟踪目标批号
|
||||
Tracking_beam->TAS_track_index = earliest_track_idx;
|
||||
Tracking_beam->TAS_track_index = (*trust_track)[earliest_track_idx].Track_Index;
|
||||
|
||||
//跟踪波束开关开启
|
||||
Tracking_beam->open_flag=1;
|
||||
|
||||
//std::cout << "TAS: range: " <<Tracking_beam->Range << "azi: " <<Tracking_beam->Azi <<"pit: " <<Tracking_beam->Elev;
|
||||
//RDP_LOG << "TAS <" << (*trust_track)[earliest_track_idx].Track_Index << "> output: range: " <<Tracking_beam->Range << "azi: " <<Tracking_beam->Azi <<"pit: " <<Tracking_beam->Elev << std::endl;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "track_asso.h"
|
||||
#include "kalman.h"
|
||||
#include "coor_trans.h"
|
||||
#include "rdp_log.h"
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
@@ -611,6 +612,8 @@ void Track_Asso:: model_filter(std::vector <Trust_Track> *trust_track,struct Ra
|
||||
|
||||
if (delta_T <= 0)
|
||||
{
|
||||
|
||||
RDP_LOG<<"delta_T <= 0, track_index: "<<track_index<<", point_index: "<<point_index<<", delta_T: "<<delta_T<<std::endl;
|
||||
// 乱序/重复时间戳:不作为有效关联,不标记点迹已使用、不刷新航迹新鲜度
|
||||
for (int ii=0;ii<associated_num;)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "track_asso_tas.h"
|
||||
#include "kalman.h"
|
||||
#include "coor_trans.h"
|
||||
#include "rdp_log.h"
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
@@ -244,11 +245,6 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
{
|
||||
found_tas_track = true;
|
||||
|
||||
// if(point_process.size()>0)
|
||||
// {
|
||||
// std::cout << "model_filter point_process :" <<point_process[0].Azimuth/PI*180<<" "<<point_process[0].Range;
|
||||
// }
|
||||
|
||||
(*trust_track)[loop_of_track].point_flag = 0; //航迹的point_flag置为0 关联上点后再置为1
|
||||
memcpy(X1,(*trust_track)[loop_of_track].X1,6*sizeof(double));
|
||||
memcpy(X2,(*trust_track)[loop_of_track].X2,6*sizeof(double));
|
||||
@@ -281,8 +277,11 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
double prt = point_process[loop_of_point].PRF_index;
|
||||
double freq_ind = point_process[loop_of_point].Freq_index;
|
||||
double delta_T = (point_process[loop_of_point].CPI_Time - T_track)/1000.0;
|
||||
if (delta_T <= 0)
|
||||
if (delta_T <= 0){
|
||||
RDP_LOG << "Warning: delta_T <= 0, skipping point association for point index " << point_process[loop_of_point].CPI_Time << " " << T_track << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
double h_point = point_process[loop_of_point].Height;
|
||||
|
||||
//计算统计距离d
|
||||
@@ -370,7 +369,7 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
//有关联 滤波
|
||||
if (associated_info.size()>0)
|
||||
{
|
||||
|
||||
//RDP_LOG << "associated point for track index " << tas_track_idx << std::endl;
|
||||
// std::cout << "TAS asoooooo222" ;
|
||||
|
||||
//找最近点
|
||||
@@ -495,7 +494,7 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
//未关联上,航迹外推
|
||||
else
|
||||
{
|
||||
|
||||
//RDP_LOG << "unassociated point for track index " << tas_track_idx << std::endl;
|
||||
for(size_t i=0;i<trust_track->size();i++)
|
||||
if((*trust_track)[i].Track_Index == tas_track_idx)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "track_die_tas.h"
|
||||
#include "kalman.h"
|
||||
#include "coor_trans.h"
|
||||
#include "rdp_log.h"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
@@ -20,7 +21,7 @@ void Track_Die_Tas::track_die_process_tas( std::vector <Trust_Track> *trust_trac
|
||||
||(*Iter).manual_delete_flag == 1)
|
||||
|
||||
{
|
||||
std::cout << "remove tas target :" << (*Iter).Track_Index << std::endl;
|
||||
// RDP_LOG << "remove tas target :" << (*Iter).Track_Index << std::endl;
|
||||
//输出消亡信息
|
||||
*Track_die_num_Output=*Track_die_num_Output+1;
|
||||
Track_die_Index_Output[*Track_die_num_Output-1]=(*Iter).Track_Index;
|
||||
|
||||
Reference in New Issue
Block a user