using System.Collections.Concurrent;
namespace BLWLogServer.Services
{
public class Device
{
///
/// 设备地址
///
public string Address { get; set; }
///
/// 地址类型
///
//public AddressType AddressType { get; set; }
///
/// 设备开关状态:1开,2关,6停(窗帘),下发1个字节
///
public byte Status { get; set; }
///
/// 设备开关状态:1开,2关,6停(窗帘),接收2个字节
///
public ushort StatusReceiver { get; set; }
///
/// 亮度值
///
public byte Brightness { get; set; }
///
/// 温度
///
public byte Temperature { get; set; }
///
/// 风速
///
public byte FanSpeed { get; set; }
///
/// 模式
///
public byte Mode { get; set; }
///
/// 阀门开关
///
public byte Valve { get; set; }
///
/// 空调执行方式和内容
///
public Int32 AirExecMode { get; set; }
///
/// 地暖执行方式和内容
///
public Int32 FloorHotExecMode { get; set; }
///
/// 背景音乐执行方式和内容
///
public Int32 MusicExecMode { get; set; }
///
/// 色温执行方式和内容
///
//public Int32 ColorTempExecMode { get; set; }
}
public class Status
{
///
/// RCU是否锁定
///
public bool SysLock { get; set; }
///
/// 房卡类型
///
public byte CardType { get; set; }
///
/// 房门开关
///
public bool Door { get; set; }
///
/// 电量
///
public ushort ElecQty { get; set; }
///
/// 主机温度
///
public byte HostTemp { get; set; }
///
/// 空调状态
///
public ConcurrentDictionary AirConditions = new ConcurrentDictionary();
///
/// 设备状态
///
public ConcurrentDictionary Devices = new ConcurrentDictionary();
///
/// 故障列表
///
public ConcurrentDictionary Faults = new ConcurrentDictionary();
}
///
/// 空调状态
///
public class AirConditionStatus
{
///
/// 空调号
///
public byte AirNo { get; set; }
///
/// 当前温度
///
public int CurrentTemp { get; set; }
///
/// 设定温度
///
public int SettingTemp { get; set; }
///
/// 风机开关
///
public bool OnOff { get; set; }
///
/// 风速:0/停止, 1/低速, 2/中速, 3/高速, 4/自动
///
public int Speed { get; set; }
///
/// 模式: 0/制冷,1/制热,2/送风,3/除湿
///
public int Mode { get; set; }
///
/// 阀状态: 1/阀开,2/阀关
///
public int Valve { get; set; }
///
/// 补偿温度,范围-6.0~6.0
///
public float CompensatoryTemp { get; set; }
///
/// 保温温度
///
public int KeepTemp { get; set; }
///
/// 冷热模式:0/手动,1/自动
///
public int ColdHotMode { get; set; }
///
/// 死区温度
///
public int DeadTemp { get; set; }
///
/// 热偏差
///
public int HotDevition { get; set; }
///
/// 冷偏差
///
public int ColdDevition { get; set; }
}
public class FaultStaus
{
///
/// 故障号
///
public string FaultNo { get; set; }
///
/// 类型:1在线状态(0在线,1离线),2电量(0~100%),3电流,4 1901故障检测次数,5设备单个回路状态(0正常,1损坏)
///
public byte Type { get; set; }
///
/// 内容
///
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;
}
}
}
}