change - 修改 Nan 值过滤逻辑

main
Wen JY 2 months ago
parent 2db7a44df2
commit 995a32d2dc

@ -0,0 +1,76 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Business
* 8BCBBC2D-F2EB-45A3-9DBA-24217C772093
*
* WenJY
*
* 2025-05-07 13:44:30
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using Sln.Iot.Business.@base;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.Model.dto;
using Sln.Iot.Serilog;
using Sln.Iot.Socket.Adapter;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace Sln.Iot.Business
{
/// <summary>
/// 校时指令
/// </summary>
public class CheckTimeBusiness:BaseBusiness
{
public CheckTimeBusiness(SerilogHelper logger, AppConfig appConfig, StringChange stringChange) : base(logger, appConfig, stringChange)
{
}
public override FilterResult BufferAnalysis(ISocketClient client, BufferRequestInfo requestInfo, int bodyLength)
{
MessagePack SendMessagePackInfo = new MessagePack()
{
m_MessageType = 0x08,
m_PackLen = new byte[] {0x00, 0x06}
};
base.GetMessagePack(ref SendMessagePackInfo,requestInfo.buffer);
DateTime currentTime = DateTime.Now;
byte[] timeBuffer = new byte[]
{
base._stringChange.HexStrTorbytes(currentTime.ToString("ss"))[0],
base._stringChange.HexStrTorbytes(currentTime.ToString("mm"))[0],
base._stringChange.HexStrTorbytes(currentTime.ToString("HH"))[0],
base._stringChange.HexStrTorbytes(currentTime.ToString("dd"))[0],
base._stringChange.HexStrTorbytes(currentTime.ToString("MM"))[0],
base._stringChange.HexStrTorbytes(currentTime.ToString("yy"))[0],
};
base.SendMessageAsync(client, SendMessagePackInfo,timeBuffer);
return FilterResult.Success;
}
public override void ResponseHandle(ISocketClient client, byte[] buffer)
{
//校时指令通过业务数据返回
}
}
}

@ -87,7 +87,7 @@ namespace Sln.Iot.Business
iotEnvInstant.monitorId = equipId;
#region 物联网参数解析 Add By Wenjy 2024-09-19
#region 物联网参数解析 Edit By Wenjy 2025-05-07 修改 Nan 值过滤
do
{
@ -99,11 +99,9 @@ namespace Sln.Iot.Business
byteBlock.Read(out byte[] tempreture, 4);
base._stringChange.SwapBytes(ref tempreture);
float f_tempreture = BitConverter.ToSingle(tempreture, 0);
if (double.IsNaN(f_tempreture))
{
f_tempreture = 0;
}
ValueIsNan(ref f_tempreture);
iotEnvInstant.temperature = (decimal) f_tempreture;
break;
@ -111,10 +109,8 @@ namespace Sln.Iot.Business
byteBlock.Read(out byte[] humidity, 4);
base._stringChange.SwapBytes(ref humidity);
float f_humidity = BitConverter.ToSingle(humidity, 0);
if (double.IsNaN(f_humidity))
{
f_humidity = 0;
}
ValueIsNan(ref f_humidity);
iotEnvInstant.humidity = (decimal) f_humidity;
break;
@ -123,10 +119,8 @@ namespace Sln.Iot.Business
byteBlock.Read(out byte[] noise, 4);
base._stringChange.SwapBytes(ref noise);
float f_noise = BitConverter.ToSingle(noise, 0);
if (double.IsNaN(f_noise))
{
f_noise = 0;
}
ValueIsNan(ref f_noise);
iotEnvInstant.noise = (decimal) f_noise;
break;
@ -135,10 +129,8 @@ namespace Sln.Iot.Business
byteBlock.Read(out byte[] vibrationSpeed, 4);
base._stringChange.SwapBytes(ref vibrationSpeed);
float f_vibrationSpeed = BitConverter.ToSingle(vibrationSpeed, 0);
if (double.IsNaN(f_vibrationSpeed))
{
f_vibrationSpeed = 0;
}
ValueIsNan(ref f_vibrationSpeed);
iotEnvInstant.VibrationSpeed = (decimal) f_vibrationSpeed;
break;
@ -147,20 +139,17 @@ namespace Sln.Iot.Business
byteBlock.Read(out byte[] vibrationDisplacement, 4);
base._stringChange.SwapBytes(ref vibrationDisplacement);
float f_vibrationDisplacement = BitConverter.ToSingle(vibrationDisplacement, 0);
if (double.IsNaN(f_vibrationDisplacement))
{
f_vibrationDisplacement = 0;
}
ValueIsNan(ref f_vibrationDisplacement);
iotEnvInstant.VibrationDisplacement = (decimal)f_vibrationDisplacement;
break;
case CommParams.VibrationAcceleration: //振动-加速度
byteBlock.Read(out byte[] vibrationAcceleration, 4);
base._stringChange.SwapBytes(ref vibrationAcceleration);
float f_vibrationAcceleration = BitConverter.ToSingle(vibrationAcceleration, 0);
if (double.IsNaN(f_vibrationAcceleration))
{
f_vibrationAcceleration = 0;
}
ValueIsNan(ref f_vibrationAcceleration);
iotEnvInstant.VibrationAcceleration = (decimal)f_vibrationAcceleration;
break;
@ -168,10 +157,9 @@ namespace Sln.Iot.Business
byteBlock.Read(out byte[] vibrationTemp, 4);
base._stringChange.SwapBytes(ref vibrationTemp);
float f_vibrationTemp = BitConverter.ToSingle(vibrationTemp, 0);
if (double.IsNaN(f_vibrationTemp))
{
f_vibrationTemp = 0;
}
ValueIsNan(ref f_vibrationTemp);
iotEnvInstant.VibrationTemp = (decimal)f_vibrationTemp;
break;
case CommParams.CJSJ:
@ -202,16 +190,16 @@ namespace Sln.Iot.Business
if (result.Count > 0)
{
//是否开启 FF 异常值过滤
if (_appConfig.virtualFlag)
{
ParamVerification(ref result);
}
var inRes = _service.SplitInsert(result,out List<long> insertIds);
/*Task.Run(() => //保存至TD引擎
{
base.SaveDnbToTDengine(result);
this.RefreshMonitorInfo(result);
});*/
_logger.Info($"{amount}个物联网数据解析处理完成,数据保存{(inRes ? "" : "")}");
_logger.Info($"{amount}个物联网数据解析处理完成,保存{result.Count}个物联网数据,保存{(inRes ? "" : "")}");
}
else
{
@ -243,5 +231,91 @@ namespace Sln.Iot.Business
base.SendMessageAsync(client,SendMessagePackInfo);
}
/// <summary>
/// Nan 值处理
/// </summary>
/// <param name="value"></param>
private void ValueIsNan(ref float value)
{
if (double.IsNaN(value))
{
if (_appConfig.virtualFlag)
{
value = _appConfig.virtualValue;
}
else
{
value = 0;
}
}
}
/// <summary>
/// FF FF参数过滤
/// </summary>
/// <param name="iotEnvInstants"></param>
/// <exception cref="ArgumentNullException"></exception>
private void ParamVerification(ref List<RecordIotEnvInstant> iotEnvInstants)
{
if (iotEnvInstants == null)
{
throw new ArgumentNullException($"过滤参数方法异常,传入参数为空");
}
for (int i = iotEnvInstants.Count - 1; i >= 0; i--)
{
var item = iotEnvInstants[i];
if (item.temperature == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},温度值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
if (item.humidity == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},湿度值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
if (item.noise == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},噪音值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
if (item.VibrationSpeed == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},振动速度值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
if (item.VibrationDisplacement == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},振动位移值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
if (item.VibrationAcceleration == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},振动加速度值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
if (item.VibrationTemp == _appConfig.virtualValue)
{
_logger.Info($"MonitorId:{item.monitorId},振动温度值为 FF FF FF FF已启用过滤不保存该表数据");
iotEnvInstants.RemoveAt(i);
continue;
}
}
}
}
}

@ -1 +1 @@
1a87674c6ab35ba5ae0a5d1ecc4eed06aadb5dbd
2ce0c4f9ee62a08488a9a35d5ddbc19f5bbae93b

@ -35,11 +35,6 @@ namespace Sln.Iot.Config
/// </summary>
public string logPath { get; set; }
/// <summary>
/// 电量采集时间间隔,单位:分钟
/// </summary>
public string CollectElectricTime { get; set; }
/// <summary>
/// 监听端口
/// </summary>

@ -38,6 +38,9 @@ class Program
int bodyLength = 0;
switch (info.DataType)
{
case 0x08:
_business = ServiceProvider.GetService<CheckTimeBusiness>();
break;
case 0x21: //登录指令
_business = ServiceProvider.GetService<LoginBusiness>();
break;

@ -1,8 +1,9 @@
{
"AppConfig": {
"logPath": "\\\\Mac\\Home\\Public\\WorkSpace\\Mesnac\\项目资料\\IOT物联网数据采集\\日志信息",
"CollectElectricTime": "3",
"listernPort": 7001,
"virtualFlag": true,
"virtualValue": 99999,
"SqlConfig": [
{
"configId": "mesTD",

@ -1,8 +1,9 @@
{
"AppConfig": {
"logPath": "\\\\Mac\\Home\\Public\\WorkSpace\\Mesnac\\项目资料\\IOT物联网数据采集\\日志信息",
"CollectElectricTime": "3",
"listernPort": 7001,
"virtualFlag": true,
"virtualValue": 99999,
"SqlConfig": [
{
"configId": "mesTD",

Loading…
Cancel
Save