|
|
@@ -1,13 +1,16 @@
|
|
|
#include "Detector_TiRayDR.h"
|
|
|
#include "CCOS.Dev.FPD.TiRayDR.h"
|
|
|
#include "MyPingip.h"
|
|
|
-#include <dlfcn.h>
|
|
|
+#include <dlfcn.h>
|
|
|
#include <pthread.h>
|
|
|
-#include "LogLocalHelper.h"
|
|
|
+#include "LogLocalHelper.h"
|
|
|
#include "Log4CPP.h"
|
|
|
using EventListenerType = void(*)(TiRayEvent, void*);
|
|
|
Detector_TiRayDR* g_pDetector = nullptr;
|
|
|
|
|
|
+// 函数声明
|
|
|
+static std::string generateReadableTimestamp();
|
|
|
+
|
|
|
//extern Log4CPP::Logger* mLog::gLogger;
|
|
|
|
|
|
/****************************************/
|
|
|
@@ -80,6 +83,8 @@ Detector_TiRayDR::Detector_TiRayDR()
|
|
|
m_pZSKKCalib{},
|
|
|
m_strDetectorType{},
|
|
|
m_strSerialNum{},
|
|
|
+ m_strCurrentSessionTimestamp{},
|
|
|
+ m_nSessionFrameCounter{0},
|
|
|
m_nImageNum{},
|
|
|
m_nDetectorID{},
|
|
|
m_nNotifyStatusTimePeriod{},
|
|
|
@@ -331,79 +336,95 @@ void Detector_TiRayDR::EnterExamMode(int nExamMode)
|
|
|
bool Detector_TiRayDR::SetAcqMode(int nMode)
|
|
|
{
|
|
|
FINFO("--TiRayDR Func-- SetAcqMode Start");
|
|
|
- FINFO("Detector_TiRayDR::SetAcqMode mode:{$}", nMode);
|
|
|
+ FINFO("SetAcqMode mode: {$}", nMode);
|
|
|
+
|
|
|
if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
|
|
|
{
|
|
|
FERROR("Detector not connected, return");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- int nRes;
|
|
|
m_bExitRadAcqStatus = false;
|
|
|
|
|
|
+ // 从配置中读取图像参数
|
|
|
try
|
|
|
{
|
|
|
- //设置采集模式,根据不同的场景设置不同的采集模式
|
|
|
m_nImageWidth = (int)m_ModeConfig["ModeTable"][0]["ImageWidth"];
|
|
|
m_nImageHeight = (int)m_ModeConfig["ModeTable"][0]["ImageHeight"];
|
|
|
m_nWidthOffset = (int)m_ModeConfig["ModeTable"][0]["WidthOffset"];
|
|
|
m_nHeightOffset = (int)m_ModeConfig["ModeTable"][0]["HeightOffset"];
|
|
|
- FINFO("After crop image width: {$}, height: {$}, WidthOffset: {$}, HeightOffset: {$}", m_nImageWidth, m_nImageHeight, m_nWidthOffset, m_nHeightOffset);
|
|
|
+ FINFO("Image config - Width: {$}, Height: {$}, WidthOffset: {$}, HeightOffset: {$}",
|
|
|
+ m_nImageWidth, m_nImageHeight, m_nWidthOffset, m_nHeightOffset);
|
|
|
|
|
|
m_bSaveRaw = (int)m_ModeConfig["ModeTable"][0]["IsSaveRaw"];
|
|
|
- FINFO("m_nSaveRaw:{$}", m_bSaveRaw);
|
|
|
+ FINFO("SaveRaw: {$}", m_bSaveRaw);
|
|
|
|
|
|
- if (nullptr != m_pImgBuffer)
|
|
|
+ // 重新分配图像缓冲区
|
|
|
+ if (m_pImgBuffer != nullptr)
|
|
|
{
|
|
|
delete[] m_pImgBuffer;
|
|
|
m_pImgBuffer = nullptr;
|
|
|
}
|
|
|
m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight];
|
|
|
-
|
|
|
}
|
|
|
catch (ResDataObjectExption& e)
|
|
|
{
|
|
|
- FERROR("Get config FERROR: {$}", e.what());
|
|
|
+ FERROR("Failed to get config: {$}", e.what());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- TiRayVariant Param[2]{};
|
|
|
- Param[0].Type = TiRayVariant::TiRayInt;
|
|
|
- Param[0].IntValue = TiRayAttribute::Attr_BinningMode;
|
|
|
- Param[1].Type = TiRayVariant::TiRayInt;
|
|
|
- Param[1].IntValue = BinningMode::Binning_None;
|
|
|
+ // 根据采集模式设置工作模式
|
|
|
+ int workMode;
|
|
|
+ const char* modeName;
|
|
|
|
|
|
- nRes = Execute_Ptr(m_nDetectorID, Cmd_WriteAttribute, Param, 2);
|
|
|
- if ((TiRayError)nRes != TiRayError::Err_Success)
|
|
|
+ // 设置拍摄参数
|
|
|
+ int nXWindow = (int)m_ModeConfig["ModeTable"][0]["XWindow"];
|
|
|
+
|
|
|
+ if (nMode == AcqMode::RAD)
|
|
|
{
|
|
|
- FERROR("Set BinningMode Failed, Reason:{$}", nRes);
|
|
|
- return false;
|
|
|
+ workMode = WorkMode_FreeSync;
|
|
|
+ modeName = "RAD";
|
|
|
+ }
|
|
|
+ else if (nMode == AcqMode::DDR)
|
|
|
+ {
|
|
|
+ workMode = WorkMode_DDR;
|
|
|
+ modeName = "DDR";
|
|
|
+ nXWindow = 800;
|
|
|
+ }
|
|
|
+ else if (nMode == AcqMode::PF)
|
|
|
+ {
|
|
|
+ workMode = WorkMode_SyncIn;
|
|
|
+ modeName = "PF";
|
|
|
+ nXWindow = 800;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- FINFO("Set BinningMode Success");
|
|
|
+ FERROR("Invalid acquisition mode: {$}", nMode);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- TiRayVariant ParamAED[2]{};
|
|
|
- ParamAED[0].Type = TiRayVariant::TiRayInt;
|
|
|
- ParamAED[0].IntValue = TiRayAttribute::Attr_AEDSensitivity;
|
|
|
- ParamAED[1].Type = TiRayVariant::TiRayInt;
|
|
|
- ParamAED[1].IntValue = 200;
|
|
|
+ FINFO("Setting work mode to {$} (WorkMode: {$})", modeName, workMode);
|
|
|
|
|
|
- nRes = Execute_Ptr(m_nDetectorID, Cmd_WriteAttribute, ParamAED, 2);
|
|
|
- if ((TiRayError)nRes != TiRayError::Err_Success)
|
|
|
+ // 设置工作模式
|
|
|
+ auto err = write_attribute(Attr_WorkMode, workMode);
|
|
|
+ if (err != Err_Success)
|
|
|
{
|
|
|
- FERROR("Set BinningMode Failed, Reason:{$}", nRes);
|
|
|
+ FERROR("Failed to set work mode, error code: {$}", err);
|
|
|
return false;
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ FINFO("Work mode set successfully");
|
|
|
+
|
|
|
+ err = write_attribute(Attr_PhotoInterval, nXWindow);
|
|
|
+ if (err != Err_Success)
|
|
|
{
|
|
|
- FINFO("Set BinningMode Success");
|
|
|
+ FERROR("Failed to write Attr_PhotoInterval, error code: {$}", err);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
StatusFeedback(EVT_STATUS_PANEL, PANEL_SLEEP);
|
|
|
FINFO("TiRayDR SetAcqMode Over");
|
|
|
-
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -500,6 +521,10 @@ bool Detector_TiRayDR::PrepareAcquisition(FPDDeviceTiRay* pDrvDPC)
|
|
|
}
|
|
|
g_pDetector->StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
|
|
|
|
|
|
+ // 生成新的会话时间戳,这次拍摄的所有图片都将使用这个时间戳
|
|
|
+ m_strCurrentSessionTimestamp = generateReadableTimestamp();
|
|
|
+ m_nSessionFrameCounter = 0; // 重置帧计数器
|
|
|
+ FINFO("New session started with timestamp: {$}", m_strCurrentSessionTimestamp);
|
|
|
|
|
|
//m_hRadEvent->SetEvent();
|
|
|
|
|
|
@@ -1899,94 +1924,195 @@ bool Detector_TiRayDR::cropImage(unsigned short* srcData, int srcWidth, int srcH
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// 生成可读的时间戳字符串: YYYYMMDD_HHMMSS_mmm
|
|
|
+static std::string generateReadableTimestamp()
|
|
|
+{
|
|
|
+ GlobalTime currentTime = { 0 };
|
|
|
+ GetLocalTime(¤tTime);
|
|
|
+
|
|
|
+ char timestamp[32];
|
|
|
+ snprintf(timestamp, sizeof(timestamp), "%04d%02d%02d_%02d%02d%02d_%03d",
|
|
|
+ currentTime.wYear, currentTime.wMonth, currentTime.wDay,
|
|
|
+ currentTime.wHour, currentTime.wMinute, currentTime.wSecond,
|
|
|
+ currentTime.wMilliseconds);
|
|
|
+
|
|
|
+ return std::string(timestamp);
|
|
|
+}
|
|
|
+
|
|
|
std::string Detector_TiRayDR::saveProcessedImage(Detector_TiRayDR& detector, unsigned short* data, size_t size, const std::string& baseTimestamp)
|
|
|
{
|
|
|
const size_t MAX_PROC_FILE_COUNT = 10;
|
|
|
const std::string TMPFS_DIR = "/mnt/tmpfs/";
|
|
|
+ const std::string BACKUP_DIR = "/userdata/RawData/";
|
|
|
const std::string ORIGINAL_DIR = detector.m_strWorkPath + "/RawData/";
|
|
|
+ const std::string FILE_PREFIX = "Proc_";
|
|
|
+ const uintmax_t MIN_REQUIRED_SPACE = size * 2; // 至少需要两倍图像大小的空间
|
|
|
+
|
|
|
std::string procDir;
|
|
|
bool useTmpfs = false;
|
|
|
+ std::string filePath;
|
|
|
|
|
|
- // 确定存储目录
|
|
|
- if (std::filesystem::exists(TMPFS_DIR) && std::filesystem::is_directory(TMPFS_DIR))
|
|
|
- {
|
|
|
- procDir = TMPFS_DIR;
|
|
|
- useTmpfs = true;
|
|
|
- std::cout << "[Detector_TiRayDR::saveProcessedImage] Using tmpfs directory: " << procDir << std::endl;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- procDir = ORIGINAL_DIR;
|
|
|
- std::cout << "[Detector_TiRayDR::saveProcessedImage] /mnt/tmpfs not found, using original directory: " << procDir << std::endl;
|
|
|
- }
|
|
|
+ // 辅助函数:检查目录空间是否足够
|
|
|
+ auto hasEnoughSpace = [&](const std::string& dirPath) -> bool {
|
|
|
+ try {
|
|
|
+ if (!std::filesystem::exists(dirPath))
|
|
|
+ return false;
|
|
|
|
|
|
- const std::string FILE_PREFIX = "Proc_";
|
|
|
- std::string filePath;
|
|
|
+ auto fsInfo = std::filesystem::space(dirPath);
|
|
|
+ bool hasSpace = fsInfo.available >= MIN_REQUIRED_SPACE;
|
|
|
+ return hasSpace;
|
|
|
+ }
|
|
|
+ catch (const std::filesystem::filesystem_error& e) {
|
|
|
+ FINFO("Failed to check space for {$}: {$}", dirPath, e.what());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- std::filesystem::create_directories(procDir);
|
|
|
- filePath = procDir + FILE_PREFIX + baseTimestamp + ".raw";
|
|
|
+ // 辅助函数:尝试在指定目录保存图像
|
|
|
+ auto tryToSaveInDir = [&](const std::string& dirPath, bool isTmpfs) -> bool {
|
|
|
+ try {
|
|
|
+ std::filesystem::create_directories(dirPath);
|
|
|
+ filePath = dirPath + FILE_PREFIX + baseTimestamp + ".raw";
|
|
|
+
|
|
|
+ std::ofstream file(filePath, std::ios::binary);
|
|
|
+ if (!file.is_open())
|
|
|
+ {
|
|
|
+ FINFO("Failed to open file: {$}", filePath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- std::ofstream file(filePath, std::ios::binary);
|
|
|
- if (file.is_open())
|
|
|
- {
|
|
|
file.write(reinterpret_cast<const char*>(detector.m_pImgBuffer), size);
|
|
|
- std::cout << "[Detector_TiRayDR::saveProcessedImage] Saved image: " << filePath << std::endl;
|
|
|
+ file.close();
|
|
|
+
|
|
|
+ if (file.fail())
|
|
|
+ {
|
|
|
+ FINFO("Failed to write processed image: {$}", filePath);
|
|
|
+ // 尝试删除不完整的文件
|
|
|
+ std::filesystem::remove(filePath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ FINFO("Saved processed image: {$}", filePath);
|
|
|
+
|
|
|
+ // 使用完整的 baseTimestamp 作为会话标识(格式:YYYYMMDD_HHMMSS_mmm)
|
|
|
+ // 清理旧文件,但保护当前会话的文件
|
|
|
+ cleanOldFiles(dirPath, FILE_PREFIX, MAX_PROC_FILE_COUNT, isTmpfs, baseTimestamp);
|
|
|
+ return true;
|
|
|
}
|
|
|
- else
|
|
|
+ catch (const std::filesystem::filesystem_error& e)
|
|
|
{
|
|
|
- std::cout << "[Detector_TiRayDR::saveProcessedImage] Failed to open file: " << filePath << std::endl;
|
|
|
- return "";
|
|
|
+ FINFO("File system error in {$}: {$}", dirPath, e.what());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ catch (const std::exception& e)
|
|
|
+ {
|
|
|
+ FINFO("Unexpected error in {$}: {$}", dirPath, e.what());
|
|
|
+ return false;
|
|
|
}
|
|
|
+ };
|
|
|
|
|
|
- cleanOldFiles(procDir, FILE_PREFIX, MAX_PROC_FILE_COUNT, useTmpfs);
|
|
|
+ // 策略1: 优先使用 tmpfs(如果存在且空间足够)
|
|
|
+ if (std::filesystem::exists(TMPFS_DIR) && std::filesystem::is_directory(TMPFS_DIR))
|
|
|
+ {
|
|
|
+ if (hasEnoughSpace(TMPFS_DIR))
|
|
|
+ {
|
|
|
+ if (tryToSaveInDir(TMPFS_DIR, true))
|
|
|
+ return filePath;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FINFO("tmpfs space insufficient, trying alternatives");
|
|
|
+ }
|
|
|
}
|
|
|
- catch (const std::filesystem::filesystem_error& e)
|
|
|
+
|
|
|
+ // 策略2: 尝试原始目录
|
|
|
+ if (hasEnoughSpace(ORIGINAL_DIR))
|
|
|
{
|
|
|
- std::cout << "[Detector_TiRayDR::saveProcessedImage] File system error: " << e.what() << std::endl;
|
|
|
- return "";
|
|
|
+ if (tryToSaveInDir(ORIGINAL_DIR, false))
|
|
|
+ return filePath;
|
|
|
}
|
|
|
- catch (const std::exception& e)
|
|
|
+ else
|
|
|
{
|
|
|
- std::cout << "[Detector_TiRayDR::saveProcessedImage] Unexpected error: " << e.what() << std::endl;
|
|
|
- return "";
|
|
|
+ FINFO("Original directory space insufficient, trying backup");
|
|
|
}
|
|
|
|
|
|
- return filePath;
|
|
|
+ // 策略3: 使用备用目录 /userdata/
|
|
|
+ FINFO("Using backup directory: {$}", BACKUP_DIR);
|
|
|
+ if (tryToSaveInDir(BACKUP_DIR, false))
|
|
|
+ return filePath;
|
|
|
+
|
|
|
+ // 所有策略都失败
|
|
|
+ FINFO("ERROR: Failed to save processed image in all available directories!");
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
void Detector_TiRayDR::saveRawImage(Detector_TiRayDR& detector, unsigned short* data, size_t size, const std::string& baseTimestamp)
|
|
|
{
|
|
|
const std::string RAW_DIR = detector.m_strWorkPath + "/OriginalData/";
|
|
|
+ const std::string BACKUP_RAW_DIR = "/userdata/OriginalData/";
|
|
|
const std::string FILE_PREFIX = "orig_";
|
|
|
- const size_t MAX_RAW_FILE_COUNT = 20;
|
|
|
+ const size_t MAX_RAW_FILE_COUNT = 20;
|
|
|
+ const uintmax_t MIN_REQUIRED_SPACE = size * 2;
|
|
|
std::string filePath;
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- std::filesystem::create_directories(RAW_DIR);
|
|
|
- filePath = RAW_DIR + FILE_PREFIX + baseTimestamp + ".raw";
|
|
|
+ // 辅助函数:尝试保存到指定目录
|
|
|
+ auto tryToSaveRawInDir = [&](const std::string& dirPath) -> bool {
|
|
|
+ try {
|
|
|
+ std::filesystem::create_directories(dirPath);
|
|
|
+ filePath = dirPath + FILE_PREFIX + baseTimestamp + ".raw";
|
|
|
+
|
|
|
+ std::ofstream file(filePath, std::ios::binary);
|
|
|
+ if (!file.is_open())
|
|
|
+ {
|
|
|
+ FINFO("Failed to open raw image file: {$}", filePath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- std::ofstream file(filePath, std::ios::binary);
|
|
|
- if (file.is_open())
|
|
|
- {
|
|
|
- // 直接写入unsigned short缓冲区数据
|
|
|
file.write(reinterpret_cast<const char*>(data), size);
|
|
|
- cout << "[Detector_TiRayDR::saveRawImage] Saved raw image: " << filePath << endl;
|
|
|
+ file.close();
|
|
|
+
|
|
|
+ if (file.fail())
|
|
|
+ {
|
|
|
+ FINFO("Failed to write raw image: {$}", filePath);
|
|
|
+ std::filesystem::remove(filePath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ FINFO("Saved raw image: {$}", filePath);
|
|
|
+
|
|
|
+ // 使用完整的 baseTimestamp 作为会话标识(格式:YYYYMMDD_HHMMSS_mmm)
|
|
|
+ // 清理旧的原始图,但保护当前会话
|
|
|
+ cleanOldFiles(dirPath, FILE_PREFIX, MAX_RAW_FILE_COUNT, false, baseTimestamp);
|
|
|
+ return true;
|
|
|
}
|
|
|
- else
|
|
|
+ catch (const std::filesystem::filesystem_error& e)
|
|
|
{
|
|
|
- cout << "[Detector_TiRayDR::saveRawImage] Failed to open file: " << filePath << endl;
|
|
|
- return;
|
|
|
+ FINFO("File system error in {$}: {$}", dirPath, e.what());
|
|
|
+ return false;
|
|
|
}
|
|
|
+ };
|
|
|
|
|
|
- // 清理旧的原始图
|
|
|
- cleanOldFiles(RAW_DIR, FILE_PREFIX, MAX_RAW_FILE_COUNT, false);
|
|
|
+ // 尝试主目录
|
|
|
+ try {
|
|
|
+ auto fsInfo = std::filesystem::space(RAW_DIR);
|
|
|
+ if (fsInfo.available >= MIN_REQUIRED_SPACE)
|
|
|
+ {
|
|
|
+ if (tryToSaveRawInDir(RAW_DIR))
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FINFO("Primary directory space insufficient, using backup");
|
|
|
+ }
|
|
|
}
|
|
|
- catch (const std::filesystem::filesystem_error& e)
|
|
|
+ catch (const std::filesystem::filesystem_error& e) {
|
|
|
+ FINFO("Failed to check primary directory space: {$}", e.what());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试备用目录
|
|
|
+ if (!tryToSaveRawInDir(BACKUP_RAW_DIR))
|
|
|
{
|
|
|
- cout << "[Detector_TiRayDR::saveRawImage] File system error: " << e.what() << endl;
|
|
|
+ FINFO("ERROR: Failed to save raw image in all available directories!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1995,27 +2121,25 @@ std::filesystem::space_info getFileSystemInfo(const std::string& dirPath) {
|
|
|
return std::filesystem::space(dirPath);
|
|
|
}
|
|
|
catch (const std::filesystem::filesystem_error& e) {
|
|
|
- std::cout << "[getFileSystemInfo] Failed to get filesystem info for "
|
|
|
- << dirPath << ": " << e.what() << std::endl;
|
|
|
+ FINFO("Failed to get filesystem info for {$}: {$}", dirPath, e.what());
|
|
|
return {};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::string& filePrefix,
|
|
|
- size_t maxCount, bool checkSize)
|
|
|
+ size_t maxCount, bool checkSize, const std::string& currentSessionTimestamp)
|
|
|
{
|
|
|
- const std::string funcTag = "[Detector_TiRayDR::cleanOldFiles] ";
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
// 检查目录是否存在
|
|
|
if (!std::filesystem::exists(dirPath) || !std::filesystem::is_directory(dirPath))
|
|
|
{
|
|
|
- std::cout << funcTag << "Directory not found: " << dirPath << std::endl;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
std::vector<std::filesystem::directory_entry> targetFiles;
|
|
|
+ std::vector<std::filesystem::directory_entry> currentSessionFiles;
|
|
|
+
|
|
|
for (const auto& entry : std::filesystem::directory_iterator(dirPath))
|
|
|
{
|
|
|
// 只处理常规文件
|
|
|
@@ -2034,10 +2158,39 @@ void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::stri
|
|
|
|
|
|
if (filename.substr(0, filePrefix.length()) == filePrefix)
|
|
|
{
|
|
|
- targetFiles.push_back(entry);
|
|
|
+ // 如果提供了当前会话时间戳,检查文件是否属于当前会话
|
|
|
+ bool isCurrentSession = false;
|
|
|
+ if (!currentSessionTimestamp.empty())
|
|
|
+ {
|
|
|
+ // 文件名格式:Proc_YYYYMMDD_HHMMSS_mmm_frameNNN.raw
|
|
|
+ // currentSessionTimestamp 格式:YYYYMMDD_HHMMSS_mmm
|
|
|
+ // 同一次拍摄的所有图片共享相同的会话时间戳(在PrepareAcquisition时生成)
|
|
|
+ // 检查文件名是否以 prefix + currentSessionTimestamp 开头
|
|
|
+ std::string expectedPrefix = filePrefix + currentSessionTimestamp;
|
|
|
+ if (filename.length() >= expectedPrefix.length())
|
|
|
+ {
|
|
|
+ std::string fileTimestampPart = filename.substr(0, expectedPrefix.length());
|
|
|
+ isCurrentSession = (fileTimestampPart == expectedPrefix);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isCurrentSession)
|
|
|
+ {
|
|
|
+ // 当前会话的文件,单独保存,不参与清理
|
|
|
+ currentSessionFiles.push_back(entry);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ targetFiles.push_back(entry);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (!currentSessionFiles.empty())
|
|
|
+ {
|
|
|
+ FINFO("Protected {$} files from current session (timestamp: {$})", currentSessionFiles.size(), currentSessionTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
// 按文件最后修改时间排序(最旧的在前)
|
|
|
std::sort(targetFiles.begin(), targetFiles.end(),
|
|
|
[](const std::filesystem::directory_entry& a, const std::filesystem::directory_entry& b)
|
|
|
@@ -2055,13 +2208,9 @@ void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::stri
|
|
|
for (size_t i = 0; i < filesToDelete; ++i)
|
|
|
{
|
|
|
const auto& fileToDelete = targetFiles[i];
|
|
|
- if (std::filesystem::remove(fileToDelete.path()))
|
|
|
- {
|
|
|
- std::cout << funcTag << "Deleted old file (count limit): " << fileToDelete.path() << std::endl;
|
|
|
- }
|
|
|
- else
|
|
|
+ if (!std::filesystem::remove(fileToDelete.path()))
|
|
|
{
|
|
|
- std::cout << funcTag << "Failed to delete file: " << fileToDelete.path() << std::endl;
|
|
|
+ FINFO("Failed to delete file: {$}", fileToDelete.path().string());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2077,7 +2226,6 @@ void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::stri
|
|
|
auto fsInfo = getFileSystemInfo(dirPath);
|
|
|
if (fsInfo.capacity == 0) // 获取信息失败
|
|
|
{
|
|
|
- std::cout << funcTag << "Cannot check filesystem size, skipping size check" << std::endl;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -2095,8 +2243,6 @@ void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::stri
|
|
|
};
|
|
|
|
|
|
uintmax_t currentTotalSize = calculateTotalSize(targetFiles);
|
|
|
- std::cout << funcTag << "Current files total size: " << currentTotalSize
|
|
|
- << ", Max allowed size: " << maxAllowedSize << std::endl;
|
|
|
|
|
|
// 如果当前总大小超过限制,继续删除最旧的文件
|
|
|
while (currentTotalSize > maxAllowedSize && !targetFiles.empty())
|
|
|
@@ -2106,9 +2252,6 @@ void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::stri
|
|
|
|
|
|
if (std::filesystem::remove(fileToDelete.path()))
|
|
|
{
|
|
|
- std::cout << funcTag << "Deleted old file (size limit): " << fileToDelete.path()
|
|
|
- << " (" << fileSize << " bytes)" << std::endl;
|
|
|
-
|
|
|
// 更新总量和文件列表
|
|
|
currentTotalSize -= fileSize;
|
|
|
targetFiles.erase(targetFiles.begin());
|
|
|
@@ -2116,22 +2259,24 @@ void Detector_TiRayDR::cleanOldFiles(const std::string& dirPath, const std::stri
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- std::cout << funcTag << "Failed to delete file: " << fileToDelete.path() << std::endl;
|
|
|
+ FINFO("Failed to delete file: {$}", fileToDelete.path().string());
|
|
|
break; // 删除失败时停止处理
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- std::cout << funcTag << "Cleanup completed. Deleted " << filesToDelete
|
|
|
- << " files. Remaining: " << targetFiles.size() << std::endl;
|
|
|
+ if (filesToDelete > 0)
|
|
|
+ {
|
|
|
+ FINFO("Cleanup completed. Deleted {$} files. Remaining: {$}", filesToDelete, targetFiles.size());
|
|
|
+ }
|
|
|
}
|
|
|
catch (const std::filesystem::filesystem_error& e)
|
|
|
{
|
|
|
- std::cout << funcTag << "File system error: " << e.what() << std::endl;
|
|
|
+ FINFO("File system error during cleanup: {$}", e.what());
|
|
|
}
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
- std::cout << funcTag << "Unexpected error: " << e.what() << std::endl;
|
|
|
+ FINFO("Unexpected error during cleanup: {$}", e.what());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2157,12 +2302,11 @@ void Detector_TiRayDR::handleHardwareSyncImage(Detector_TiRayDR& detector, TiRay
|
|
|
|
|
|
const size_t processedSize = detector.m_nImageWidth * detector.m_nImageHeight * sizeof(unsigned short);
|
|
|
|
|
|
- // 生成关联的基础文件名
|
|
|
- const std::string baseTimestamp = std::to_string(
|
|
|
- std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
- std::chrono::system_clock::now().time_since_epoch()
|
|
|
- ).count()
|
|
|
- );
|
|
|
+ // 使用会话时间戳 + 帧号生成文件名
|
|
|
+ detector.m_nSessionFrameCounter++;
|
|
|
+ char frameStr[16];
|
|
|
+ snprintf(frameStr, sizeof(frameStr), "_frame%03d", detector.m_nSessionFrameCounter);
|
|
|
+ const std::string baseTimestamp = detector.m_strCurrentSessionTimestamp + std::string(frameStr);
|
|
|
|
|
|
std::string processedImagePath = saveProcessedImage(
|
|
|
detector,
|
|
|
@@ -2211,12 +2355,11 @@ void Detector_TiRayDR::handleSoftwareSyncImage(Detector_TiRayDR& detector, TiRay
|
|
|
|
|
|
const size_t processedSize = detector.m_nImageWidth * detector.m_nImageHeight * sizeof(unsigned short);
|
|
|
|
|
|
- // 生成关联的基础文件名
|
|
|
- const std::string baseTimestamp = std::to_string(
|
|
|
- std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
- std::chrono::system_clock::now().time_since_epoch()
|
|
|
- ).count()
|
|
|
- );
|
|
|
+ // 使用会话时间戳 + 帧号生成文件名
|
|
|
+ detector.m_nSessionFrameCounter++;
|
|
|
+ char frameStr[16];
|
|
|
+ snprintf(frameStr, sizeof(frameStr), "_frame%03d", detector.m_nSessionFrameCounter);
|
|
|
+ const std::string baseTimestamp = detector.m_strCurrentSessionTimestamp + std::string(frameStr);
|
|
|
|
|
|
std::string processedImagePath = saveProcessedImage(
|
|
|
detector,
|
|
|
@@ -2267,12 +2410,11 @@ void Detector_TiRayDR::handleAedSyncImage(Detector_TiRayDR& detector, TiRayVaria
|
|
|
|
|
|
const size_t processedSize = detector.m_nImageWidth * detector.m_nImageHeight * sizeof(unsigned short);
|
|
|
|
|
|
- // 生成关联的基础文件名
|
|
|
- const std::string baseTimestamp = std::to_string(
|
|
|
- std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
- std::chrono::system_clock::now().time_since_epoch()
|
|
|
- ).count()
|
|
|
- );
|
|
|
+ // 使用会话时间戳 + 帧号生成文件名
|
|
|
+ detector.m_nSessionFrameCounter++;
|
|
|
+ char frameStr[16];
|
|
|
+ snprintf(frameStr, sizeof(frameStr), "_frame%03d", detector.m_nSessionFrameCounter);
|
|
|
+ const std::string baseTimestamp = detector.m_strCurrentSessionTimestamp + std::string(frameStr);
|
|
|
|
|
|
std::string processedImagePath = saveProcessedImage(
|
|
|
detector,
|
|
|
@@ -2345,7 +2487,7 @@ void Detector_TiRayDR::handleDarkCalibration(Detector_TiRayDR& detector, TiRayVa
|
|
|
template_image.height = image.height;
|
|
|
|
|
|
// 生成模板并检查结果
|
|
|
- auto err = GenerateTemplate_Ptr(Offset, datas.data(), static_cast<int>(datas.size()),
|
|
|
+ auto err = GenerateTemplate_Ptr(TemplateType_Offset, datas.data(), static_cast<int>(datas.size()),
|
|
|
template_image.data.data(), static_cast<int>(template_image.data.size()));
|
|
|
|
|
|
if (err != Err_Success) {
|
|
|
@@ -2414,7 +2556,7 @@ void Detector_TiRayDR::handleGainCalibration(Detector_TiRayDR& detector, TiRayVa
|
|
|
template_image.height = detector.m_gainCalibImages[0].height;
|
|
|
template_image.data.resize(datas[0].DataLen);
|
|
|
|
|
|
- auto err = GenerateTemplate_Ptr(Gain, datas.data(), static_cast<int>(datas.size()),
|
|
|
+ auto err = GenerateTemplate_Ptr(TemplateType_Gain, datas.data(), static_cast<int>(datas.size()),
|
|
|
template_image.data.data(), static_cast<int>(template_image.data.size()));
|
|
|
if (err != Err_Success)
|
|
|
{
|
|
|
@@ -2470,7 +2612,7 @@ void Detector_TiRayDR::handleGainCalibration(Detector_TiRayDR& detector, TiRayVa
|
|
|
mean_image.height = detector.m_currentDoseImages[0].height;
|
|
|
mean_image.data.resize(datas[0].DataLen);
|
|
|
|
|
|
- auto err = GenerateTemplate_Ptr(Mean, datas.data(), static_cast<int>(datas.size()),
|
|
|
+ auto err = GenerateTemplate_Ptr(TemplateType_Mean, datas.data(), static_cast<int>(datas.size()),
|
|
|
mean_image.data.data(), static_cast<int>(mean_image.data.size()));
|
|
|
if (err != Err_Success)
|
|
|
{
|
|
|
@@ -2510,7 +2652,7 @@ void Detector_TiRayDR::handleGainCalibration(Detector_TiRayDR& detector, TiRayVa
|
|
|
final_template.height = detector.m_gainV2MeanImages[0].height;
|
|
|
final_template.data.resize(meanDatas[0].DataLen);
|
|
|
|
|
|
- auto err = GenerateTemplate_Ptr(GainV2, meanDatas.data(), static_cast<int>(meanDatas.size()),
|
|
|
+ auto err = GenerateTemplate_Ptr(TemplateType_GainV2, meanDatas.data(), static_cast<int>(meanDatas.size()),
|
|
|
final_template.data.data(), static_cast<int>(final_template.data.size()));
|
|
|
if (err != Err_Success)
|
|
|
{
|
|
|
@@ -2623,7 +2765,7 @@ void Detector_TiRayDR::on_event_callback(int detectorId, TiRayEvent eventType, T
|
|
|
}
|
|
|
case TiRayEvent::Evt_ExposureStatus:
|
|
|
{
|
|
|
- FINFO("argv {$}, argc {$}", argv[0].IntValue, argc);
|
|
|
+ FINFO("Evt_ExposureStatus:argv {$}, argc {$}", argv[0].IntValue, argc);
|
|
|
if (argv[0].IntValue == 0)
|
|
|
{
|
|
|
detector.m_bAEDReady = true;
|