Former-commit-id: 7517e58c6ca65cde0185346090b5c311e3748fbb
TangShanKaiPing
wanggang 6 years ago
parent 70cdfe4b57
commit fb752089cb

@ -9,13 +9,13 @@ namespace Application.Domain.Entities
static DeviceId()
{
List.Add(new DeviceId { RawDeviceId = 0x0002, Name = "0x0002", Category = "电器", Icon = "socket", RawCategory = "Generic", EName = "On/Off Output" });
List.Add(new DeviceId { RawDeviceId = 0x0009, Name = "0x0009", Category = "电器", Icon = "socket", RawCategory = "Generic", EName = "Mains Power Outlet" });
List.Add(new DeviceId { RawDeviceId = 0x0051, Name = "0x0051", Category = "电器", Icon = "socket", RawCategory = "Generic", EName = "Smart plug" });
List.Add(new DeviceId { RawDeviceId = 0x0106, Name = "0x0106", Category = "传感器", Icon = "socket", RawCategory = "Lighting", EName = "Light Sensor" });
List.Add(new DeviceId { RawDeviceId = 0x0202, Name = "0x0202", Category = "电器", Icon = "socket", RawCategory = "Closures", EName = "Window Covering Device" });
List.Add(new DeviceId { RawDeviceId = 0x0309, Name = "0x0309", Category = "传感器", Icon = "socket", RawCategory = "HVAC", EName = "PM2.5 Sensor" });
List.Add(new DeviceId { RawDeviceId = 0x0402, Name = "0x0402", Category = "传感器", Icon = "socket", RawCategory = "Intruder Alarm Systems", EName = "IAS Zone" });
List.Add(new DeviceId { RawDeviceId = 0x0002, Name = "开关", Category = "电器", Icon = "socket", RawCategory = "Generic", EName = "On/Off Output" });
List.Add(new DeviceId { RawDeviceId = 0x0009, Name = "插座", Category = "电器", Icon = "socket", RawCategory = "Generic", EName = "Mains Power Outlet" });
List.Add(new DeviceId { RawDeviceId = 0x0051, Name = "智能插座", Category = "电器", Icon = "socket", RawCategory = "Generic", EName = "Smart plug" });
List.Add(new DeviceId { RawDeviceId = 0x0106, Name = "光强检测器", Category = "监测", Icon = "socket", RawCategory = "Lighting", EName = "Light Sensor" });
List.Add(new DeviceId { RawDeviceId = 0x0202, Name = "一路可调窗帘", Category = "电器", Icon = "socket", RawCategory = "Closures", EName = "Window Covering Device" });
List.Add(new DeviceId { RawDeviceId = 0x0309, Name = "粉尘检测器", Category = "监测", Icon = "socket", RawCategory = "HVAC", EName = "PM2.5 Sensor" });
List.Add(new DeviceId { RawDeviceId = 0x0402, Name = "报警器", Category = "监测", Icon = "socket", RawCategory = "Intruder Alarm Systems", EName = "IAS Zone" });
}
public string Name { get; set; }

@ -103,56 +103,81 @@ namespace FBeeService
/// <param name="data"></param>
private void X01(string sn, byte[] data)
{
using (var ms = new MemoryStream(data))
try
{
var responseType = ms.ReadByte();
var dataLength = ms.ReadByte();
var address = ms.ReadHexString(2);
var endpoint = ms.ReadByte();
using (var scope = _applicationServices.CreateScope())
using (var ms = new MemoryStream(data))
{
var profileId = ms.ReadInt();
var deviceId = ms.ReadInt();
var deviceRepo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
var device = deviceRepo.Table().FirstOrDefault(o => o.Sn == sn && o.Address == address);
if (device == null)
var responseType = ms.ReadByte();
var dataLength = ms.ReadByte();
var address = ms.ReadHexString(2);
var endpoint = ms.ReadByte();
using (var scope = _applicationServices.CreateScope())
{
var profileId = ms.ReadInt();
var deviceId = ms.ReadInt();
var deviceType = DeviceId.List.FirstOrDefault(o => o.RawDeviceId == deviceId);
device = new FBeeDevice
if (deviceType != null)
{
Sn = sn,
Name = deviceType.Name,
EName = deviceType.EName,
Icon = deviceType.Icon,
CategoryNumber = deviceType.RawDeviceId,
CategoryName = deviceType.Category
};
deviceRepo.Add(device);
}
device.DataType = responseType;
device.DataLength = dataLength;
device.Address = address;
device.Endpoint = endpoint;
device.ProfileId = profileId;
device.DeviceId = deviceId;
device.SwitchState = ms.ReadByte();
device.NameLength = ms.ReadByte();
if (device.NameLength > 0)
{
device.CName = ms.ReadASIIString(device.NameLength);
var deviceRepo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
var device = deviceRepo.Table().FirstOrDefault(o => o.Sn == sn && o.Address == address);
if (device == null)
{
device = new FBeeDevice
{
Sn = sn,
Name = deviceType.Name,
EName = deviceType.EName,
Icon = deviceType.Icon,
CategoryNumber = deviceType.RawDeviceId,
CategoryName = deviceType.Category
};
deviceRepo.Add(device);
}
device.DataType = responseType;
device.DataLength = dataLength;
device.Address = address;
device.Endpoint = endpoint;
device.ProfileId = profileId;
device.DeviceId = deviceId;
device.SwitchState = ms.ReadByte();
device.NameLength = ms.ReadByte();
if (device.NameLength > 0)
{
device.CName = ms.ReadASIIString(device.NameLength);
}
device.IsOnline = ms.ReadByte();
device.IEEE = ms.ReadHexString(8);
device.SNLength = ms.ReadByte();
device.RawSN = ms.ReadHexString(device.SNLength);
device.ZoneType = ms.ReadInt();
if (device.DeviceId == 0x402)
{
if (device.ZoneType == 0x0028)
{
device.Name = "烟雾传感器";
}
else if (device.ZoneType == 0x000d)
{
device.Name = "红外感应器";
}
}
device.Battery = ms.ReadByte();
device.EpCount = ms.ReadByte();
device.Data = ms.ReadHexString(4);
device.RawValue = BitConverter.ToString(data);
deviceRepo.SaveChanges();
}
else
{
Console.WriteLine("uknown device type");
}
}
device.IsOnline = ms.ReadByte();
device.IEEE = ms.ReadHexString(8);
device.SNLength = ms.ReadByte();
device.RawSN = ms.ReadHexString(device.SNLength);
device.ZoneType = ms.ReadInt();
device.Battery = ms.ReadByte();
device.EpCount = ms.ReadByte();
device.Data = ms.ReadHexString(4);
device.RawValue = BitConverter.ToString(data);
deviceRepo.SaveChanges();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>

Loading…
Cancel
Save