优化温度数据保存功能:1. 在DeviceManager.cs中新增接受TemperatureData参数的SaveTemperatureDataToCsv方法重载 2. 修改Camera.cs以直接使用缓存的温度数据进行保存 3. 更新相关注释说明实现逻辑
This commit is contained in:
@@ -80,69 +80,69 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析原始温度数据
|
||||
/// </summary>
|
||||
/// <param name="rawData">原始温度数据</param>
|
||||
/// <param name="compensationValue">温度补偿值</param>
|
||||
private void ParseRawData(byte[] rawData, float compensationValue)
|
||||
{
|
||||
// 检查数据是否有效
|
||||
if (rawData == null || rawData.Length == 0)
|
||||
/// 解析原始温度数据
|
||||
/// </summary>
|
||||
/// <param name="rawData">原始温度数据</param>
|
||||
/// <param name="compensationValue">温度补偿值</param>
|
||||
private void ParseRawData(byte[] rawData, float compensationValue)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(rawData), "原始温度数据为空");
|
||||
}
|
||||
|
||||
// 根据SDK文档要求,使用24字节头部
|
||||
const int HEADER_SIZE = 24;
|
||||
|
||||
// 确保数据长度足够(至少包含头部)
|
||||
if (rawData.Length < HEADER_SIZE)
|
||||
{
|
||||
throw new ArgumentException("数据长度不足,无法解析");
|
||||
}
|
||||
|
||||
// 计算温度数据长度和像素总数
|
||||
int dataLength = rawData.Length - HEADER_SIZE;
|
||||
int pixelCount = dataLength / 2; // 每个像素2字节
|
||||
|
||||
// 计算最大可处理的像素数
|
||||
int maxPixels = Math.Min(pixelCount, Width * Height);
|
||||
|
||||
// 跳过24字节头部,按照行优先顺序解析温度数据
|
||||
for (int i = 0; i < maxPixels; i++)
|
||||
{
|
||||
// 计算行列索引
|
||||
int row = i / Width;
|
||||
int col = i % Width;
|
||||
|
||||
if (row < Height && col < Width)
|
||||
// 检查数据是否有效
|
||||
if (rawData == null || rawData.Length == 0)
|
||||
{
|
||||
// 计算数据偏移量(跳过24字节头部)
|
||||
int offset = HEADER_SIZE + i * 2;
|
||||
|
||||
if (offset + 1 < rawData.Length)
|
||||
throw new ArgumentNullException(nameof(rawData), "原始温度数据为空");
|
||||
}
|
||||
|
||||
// 根据SDK文档要求,使用24字节头部
|
||||
const int HEADER_SIZE = 24;
|
||||
|
||||
// 确保数据长度足够(至少包含头部)
|
||||
if (rawData.Length < HEADER_SIZE)
|
||||
{
|
||||
throw new ArgumentException("数据长度不足,无法解析");
|
||||
}
|
||||
|
||||
// 计算温度数据长度和像素总数
|
||||
int dataLength = rawData.Length - HEADER_SIZE;
|
||||
int pixelCount = dataLength / 2; // 每个像素2字节
|
||||
|
||||
// 计算最大可处理的像素数
|
||||
int maxPixels = Math.Min(pixelCount, Width * Height);
|
||||
|
||||
// 跳过24字节头部,按照行优先顺序解析温度数据
|
||||
for (int i = 0; i < maxPixels; i++)
|
||||
{
|
||||
// 计算行列索引
|
||||
int row = i / Width;
|
||||
int col = i % Width;
|
||||
|
||||
if (row < Height && col < Width)
|
||||
{
|
||||
// 根据SDK文档要求,温度值计算方法:(H×256+L)/10,单位为摄氏度
|
||||
// H为高8位,L为低8位
|
||||
int highByte = rawData[offset + 1]; // 高8位
|
||||
int lowByte = rawData[offset]; // 低8位
|
||||
int tempValue = (highByte << 8) | lowByte;
|
||||
// 计算数据偏移量(跳过24字节头部)
|
||||
int offset = HEADER_SIZE + i * 2;
|
||||
|
||||
if (offset + 1 < rawData.Length)
|
||||
{
|
||||
// 根据SDK文档要求,温度值计算方法:(H×256+L)/10,单位为摄氏度
|
||||
// H为高8位,L为低8位
|
||||
int highByte = rawData[offset + 1]; // 高8位
|
||||
int lowByte = rawData[offset]; // 低8位
|
||||
int tempValue = (highByte << 8) | lowByte;
|
||||
|
||||
// 计算实际温度值:(H×256+L)/10
|
||||
float rawTemperature = tempValue / 10.0f;
|
||||
// 计算实际温度值:(H×256+L)/10
|
||||
float rawTemperature = tempValue / 10.0f;
|
||||
|
||||
// 应用温度补偿值
|
||||
float compensatedTemperature = rawTemperature + compensationValue;
|
||||
// 应用温度补偿值
|
||||
float compensatedTemperature = rawTemperature + compensationValue;
|
||||
|
||||
// 原始温度存入TemperatureMatrix(未温补)
|
||||
TemperatureMatrix[row, col] = rawTemperature;
|
||||
// 原始温度存入TemperatureMatrix(未温补)
|
||||
TemperatureMatrix[row, col] = rawTemperature;
|
||||
|
||||
// 温补后的温度存入RealTemperatureMatrix(映射到512×384矩阵)
|
||||
MapToRealTemperatureMatrix(row, col, compensatedTemperature);
|
||||
// 温补后的温度存入RealTemperatureMatrix(映射到512×384矩阵)
|
||||
MapToRealTemperatureMatrix(row, col, compensatedTemperature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将原始温度数据映射到512×384的实际温度矩阵
|
||||
|
||||
Reference in New Issue
Block a user