Files

247 lines
9.1 KiB
C#
Raw Permalink Normal View History

2025-11-21 08:48:01 +08:00
using System.Collections.Concurrent;
namespace BLWLogServer.Services
{
public class Device
{
/// <summary>
/// 设备地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 地址类型
/// </summary>
//public AddressType AddressType { get; set; }
/// <summary>
/// 设备开关状态1开2关6停窗帘下发1个字节
/// </summary>
public byte Status { get; set; }
/// <summary>
/// 设备开关状态1开2关6停窗帘,接收2个字节
/// </summary>
public ushort StatusReceiver { get; set; }
/// <summary>
/// 亮度值
/// </summary>
public byte Brightness { get; set; }
/// <summary>
/// 温度
/// </summary>
public byte Temperature { get; set; }
/// <summary>
/// 风速
/// </summary>
public byte FanSpeed { get; set; }
/// <summary>
/// 模式
/// </summary>
public byte Mode { get; set; }
/// <summary>
/// 阀门开关
/// </summary>
public byte Valve { get; set; }
/// <summary>
/// 空调执行方式和内容
/// </summary>
public Int32 AirExecMode { get; set; }
/// <summary>
/// 地暖执行方式和内容
/// </summary>
public Int32 FloorHotExecMode { get; set; }
/// <summary>
/// 背景音乐执行方式和内容
/// </summary>
public Int32 MusicExecMode { get; set; }
/// <summary>
/// 色温执行方式和内容
/// </summary>
//public Int32 ColorTempExecMode { get; set; }
}
public class Status
{
/// <summary>
/// RCU是否锁定
/// </summary>
public bool SysLock { get; set; }
/// <summary>
/// 房卡类型
/// </summary>
public byte CardType { get; set; }
/// <summary>
/// 房门开关
/// </summary>
public bool Door { get; set; }
/// <summary>
/// 电量
/// </summary>
public ushort ElecQty { get; set; }
/// <summary>
/// 主机温度
/// </summary>
public byte HostTemp { get; set; }
/// <summary>
/// 空调状态
/// </summary>
public ConcurrentDictionary<byte, AirConditionStatus> AirConditions = new ConcurrentDictionary<byte, AirConditionStatus>();
/// <summary>
/// 设备状态
/// </summary>
public ConcurrentDictionary<string, Device> Devices = new ConcurrentDictionary<string, Device>();
/// <summary>
/// 故障列表
/// </summary>
public ConcurrentDictionary<string, FaultStaus> Faults = new ConcurrentDictionary<string, FaultStaus>();
}
/// <summary>
/// 空调状态
/// </summary>
public class AirConditionStatus
{
/// <summary>
/// 空调号
/// </summary>
public byte AirNo { get; set; }
/// <summary>
/// 当前温度
/// </summary>
public int CurrentTemp { get; set; }
/// <summary>
/// 设定温度
/// </summary>
public int SettingTemp { get; set; }
/// <summary>
/// 风机开关
/// </summary>
public bool OnOff { get; set; }
/// <summary>
/// 风速0/停止, 1/低速, 2/中速, 3/高速, 4/自动
/// </summary>
public int Speed { get; set; }
/// <summary>
/// 模式: 0/制冷1/制热2/送风3/除湿
/// </summary>
public int Mode { get; set; }
/// <summary>
/// 阀状态: 1/阀开2/阀关
/// </summary>
public int Valve { get; set; }
/// <summary>
/// 补偿温度,范围-6.0~6.0
/// </summary>
public float CompensatoryTemp { get; set; }
/// <summary>
/// 保温温度
/// </summary>
public int KeepTemp { get; set; }
/// <summary>
/// 冷热模式0/手动1/自动
/// </summary>
public int ColdHotMode { get; set; }
/// <summary>
/// 死区温度
/// </summary>
public int DeadTemp { get; set; }
/// <summary>
/// 热偏差
/// </summary>
public int HotDevition { get; set; }
/// <summary>
/// 冷偏差
/// </summary>
public int ColdDevition { get; set; }
}
public class FaultStaus
{
/// <summary>
/// 故障号
/// </summary>
public string FaultNo { get; set; }
/// <summary>
/// 类型1在线状态0在线1离线2电量0~100%3电流4 1901故障检测次数5设备单个回路状态0正常1损坏
/// </summary>
public byte Type { get; set; }
/// <summary>
/// 内容
/// </summary>
public byte Data { get; set; }
}
public class S
{
public static Status NewStatusParse(Stream stream)
{
Status roomStatus = new Status();
try
{
using (BinaryReader reader = new BinaryReader(stream))
{
roomStatus.SysLock = reader.ReadBoolean(); //RCU是否锁定0/否1/是
roomStatus.CardType = reader.ReadByte(); //房卡类型0/无人1/有人2/客人3/经理4/服务员
roomStatus.Door = reader.ReadBoolean(); //门磁开关1/开2/关
roomStatus.ElecQty = reader.ReadUInt16(); //门锁电量单位MV
roomStatus.HostTemp = reader.ReadByte(); //主机温度
//空调数量默认0新的回路方式此处无用兼容老版本
int airConditionNumber = reader.ReadByte();
for (int i = 0; i < airConditionNumber; i++)
{
byte airNo = reader.ReadByte();
if (!roomStatus.AirConditions.ContainsKey(airNo))
{
roomStatus.AirConditions[airNo] = new AirConditionStatus();
}
roomStatus.AirConditions[airNo].AirNo = airNo;
roomStatus.AirConditions[airNo].CurrentTemp = reader.ReadSByte();
roomStatus.AirConditions[airNo].SettingTemp = reader.ReadSByte();
roomStatus.AirConditions[airNo].OnOff = reader.ReadBoolean();
roomStatus.AirConditions[airNo].Speed = reader.ReadByte();
roomStatus.AirConditions[airNo].Mode = reader.ReadByte();
roomStatus.AirConditions[airNo].Valve = reader.ReadByte();
roomStatus.AirConditions[airNo].CompensatoryTemp = reader.ReadByte();
roomStatus.AirConditions[airNo].KeepTemp = reader.ReadByte();
roomStatus.AirConditions[airNo].ColdHotMode = reader.ReadByte();
roomStatus.AirConditions[airNo].DeadTemp = reader.ReadByte();
roomStatus.AirConditions[airNo].HotDevition = reader.ReadByte();
roomStatus.AirConditions[airNo].ColdDevition = reader.ReadByte();
}
//设备状态数量,包含所有回路状态
int deviceNumber = reader.ReadByte();
long originalPosition = reader.BaseStream.Position;
// 读取前先记录当前位置
try
{
//0x19数据缓冲区异常问题处理
//0x19 取电数据不处理
//非0x19 取电数据处理,但是不触发 欢迎词
for (int i = 0; i < deviceNumber; i++)
{
var QA = reader.ReadBytes(4);
var Status = reader.ReadUInt16();
string address = String.Format("{0:000}{1:000}{2:000}", QA[0], QA[1], QA[0]);
if (!roomStatus.Devices.ContainsKey(address))
{
roomStatus.Devices[address] = new Device();
}
roomStatus.Devices[address].Address = address;//设备地址
roomStatus.Devices[address].StatusReceiver = Status;//设备状态改为2个字节,Modified By 20181213
originalPosition = reader.BaseStream.Position;
}
}
catch (Exception)
{
// 发生异常时回退到原始位置
reader.BaseStream.Position = originalPosition;
}
return roomStatus;
}
}
catch (Exception)
{
return null;
}
}
}
}