|
|
|
@ -335,6 +335,10 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
{
|
|
|
|
|
this.X27(sn, data);
|
|
|
|
|
}
|
|
|
|
|
else if (responseType == ResponseType.x50)
|
|
|
|
|
{
|
|
|
|
|
this.X50(sn, data);
|
|
|
|
|
}
|
|
|
|
|
else if (responseType == ResponseType.x70)
|
|
|
|
|
{
|
|
|
|
|
this.X70(sn, data);
|
|
|
|
@ -398,6 +402,14 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
payload.Add(ep ?? (byte)endPoint);
|
|
|
|
|
payload.AddRange(command);
|
|
|
|
|
}
|
|
|
|
|
else if (format == 3)
|
|
|
|
|
{
|
|
|
|
|
payload.Add((byte)(command.Count() + 1 + 2 + 1));//数据总长
|
|
|
|
|
payload.Add(addressType);//地址模式
|
|
|
|
|
payload.AddRange(address);
|
|
|
|
|
payload.Add(ep ?? (byte)endPoint);
|
|
|
|
|
payload.AddRange(command);
|
|
|
|
|
}
|
|
|
|
|
data.AddRange(payload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -689,22 +701,22 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
var ieee = device.Number;
|
|
|
|
|
if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId))
|
|
|
|
|
{
|
|
|
|
|
//this.X85(sn, ieee);
|
|
|
|
|
//this.X85(sn, ieee);//获取开关状态
|
|
|
|
|
}
|
|
|
|
|
if (deviceId == 0x0210 || deviceId == 0x0220)
|
|
|
|
|
{
|
|
|
|
|
this.X86(sn, ieee);
|
|
|
|
|
this.X87(sn, ieee);
|
|
|
|
|
this.X88(sn, ieee);
|
|
|
|
|
this.XA9(sn, ieee);
|
|
|
|
|
this.X86(sn, ieee);//获取亮度
|
|
|
|
|
this.X87(sn, ieee);//获取色调
|
|
|
|
|
this.X88(sn, ieee);//获取饱和度
|
|
|
|
|
this.XA9(sn, ieee);//色温
|
|
|
|
|
}
|
|
|
|
|
else if (deviceId == 0x0163)
|
|
|
|
|
{
|
|
|
|
|
this.XA70080(sn, ieee);
|
|
|
|
|
this.XA70080(sn, ieee);//读版本号
|
|
|
|
|
}
|
|
|
|
|
else if (deviceId == 0x0051)
|
|
|
|
|
{
|
|
|
|
|
this.X8D07020000(sn, ieee);
|
|
|
|
|
this.X8D0702(sn, ieee);//读取电量
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -966,12 +978,16 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 0x8d-0x70发送zcl指令,读取簇id为0702属性为0000的电量值
|
|
|
|
|
/// 0x8d-0x70发送zcl指令,读取簇id为0702的电量、电功率
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void X8D07020000(string sn, string ieee)
|
|
|
|
|
public void X8D0702(string sn, string ieee)
|
|
|
|
|
{
|
|
|
|
|
this.Write(sn, RequestType.xa7, ieee, new List<byte>() { 0x02, 0x07, 0x00, 0x00, 0x00 }, 2);
|
|
|
|
|
this.Write(sn, RequestType.xa7, ieee, new List<byte>() { 0x02, 0x07, 0x0b, 0x05, 0x00 }, 2);
|
|
|
|
|
this.Write(sn, RequestType.x8d, ieee, new List<byte>() { 0x02, 0x07, 0x01, 0x03, 0x00 }, 3);//0301电量乘数
|
|
|
|
|
this.Write(sn, RequestType.x8d, ieee, new List<byte>() { 0x02, 0x07, 0x02, 0x03, 0x00 }, 3);//0302电量除数
|
|
|
|
|
this.Write(sn, RequestType.x8d, ieee, new List<byte>() { 0x04, 0x0b, 0x04, 0x06, 0x00 }, 3);//0604功率乘数
|
|
|
|
|
this.Write(sn, RequestType.x8d, ieee, new List<byte>() { 0x04, 0x0b, 0x05, 0x06, 0x00 }, 3);//0605功率除数
|
|
|
|
|
this.Write(sn, RequestType.xa7, ieee, new List<byte>() { 0x02, 0x07, 0x00, 0x00, 0x00 }, 2);//0000电量
|
|
|
|
|
this.Write(sn, RequestType.xa7, ieee, new List<byte>() { 0x02, 0x07, 0x0b, 0x05, 0x00 }, 2);//050b功率
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -1204,6 +1220,43 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
this.Write(sn, RequestType.xa9, ieee, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void X50(string sn, byte[] data)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var ms = new MemoryStream(data);
|
|
|
|
|
if (ms.ReadByte() != 0x50)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var length = ms.ReadByte();
|
|
|
|
|
ms.Seek(10, SeekOrigin.Current);
|
|
|
|
|
var success = ms.ReadByte();
|
|
|
|
|
if (success == 0x01)
|
|
|
|
|
{
|
|
|
|
|
ms.Seek(1, SeekOrigin.Current);
|
|
|
|
|
var controlType = ms.ReadByte();
|
|
|
|
|
if (controlType == 0x95)
|
|
|
|
|
{
|
|
|
|
|
ms.Seek(2, SeekOrigin.Current);
|
|
|
|
|
var address = ms.ReadHexStringDesc(2);
|
|
|
|
|
using var scope = _applicationServices.CreateScope();
|
|
|
|
|
var deviceRepo = scope.ServiceProvider.GetService<IRepository<Device>>();
|
|
|
|
|
var device = this.GetDeviceByAddress(deviceRepo, sn, address);
|
|
|
|
|
if (device != null)
|
|
|
|
|
{
|
|
|
|
|
deviceRepo.Delete(device);
|
|
|
|
|
deviceRepo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this._logger.LogError(ex, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//0xac
|
|
|
|
|
//0xaf
|
|
|
|
|
//0xb0
|
|
|
|
@ -1455,6 +1508,10 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in props)
|
|
|
|
|
{
|
|
|
|
|
if (item.Key == 0x0400)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(item.Value.ToInt());
|
|
|
|
|
}
|
|
|
|
|
if (item.Key == 0x0000)
|
|
|
|
|
{
|
|
|
|
|
var tempBytes = new List<byte>();
|
|
|
|
@ -1463,8 +1520,14 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
tempBytes.Add(0x00);
|
|
|
|
|
if (tempBytes.Count == 8)
|
|
|
|
|
{
|
|
|
|
|
var electricity = BitConverter.ToInt64(tempBytes.ToArray()) / 10000f;
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Electricity, electricity.ToString("f2"), DeviceDataType.Float, "电量", "kWh", timestamp: timestamp));
|
|
|
|
|
var multiplier = device.Data.FirstOrDefault(o => o.Key == Keys.ElectricityMultiplier)?.Value;
|
|
|
|
|
var divisor = device.Data.FirstOrDefault(o => o.Key == Keys.ElectricityDivisor)?.Value;
|
|
|
|
|
if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor))
|
|
|
|
|
{
|
|
|
|
|
var electricity = BitConverter.ToInt64(tempBytes.ToArray());
|
|
|
|
|
var value = electricity * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor);
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Electricity, value.ToString("f2"), DeviceDataType.Float, "电量", "kWh", timestamp: timestamp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -1473,14 +1536,51 @@ namespace IoTNode.DeviceServices.FBee
|
|
|
|
|
}
|
|
|
|
|
else if (item.Key == 0x050b)
|
|
|
|
|
{
|
|
|
|
|
var power = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Power, power, DeviceDataType.Float, "功率", "W", timestamp: timestamp));
|
|
|
|
|
var multiplier = device.Data.FirstOrDefault(o => o.Key == Keys.PowerMultiplier)?.Value;
|
|
|
|
|
var divisor = device.Data.FirstOrDefault(o => o.Key == Keys.PowerDivisor)?.Value;
|
|
|
|
|
if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor))
|
|
|
|
|
{
|
|
|
|
|
var power = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
var value = power * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor);
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Power, value.ToString("f2"), DeviceDataType.Float, "功率", "W", timestamp: timestamp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (item.Key == 0x0400)//0x050b
|
|
|
|
|
{
|
|
|
|
|
var multiplier = device.Data.FirstOrDefault(o => o.Key == Keys.PowerMultiplier)?.Value;
|
|
|
|
|
var divisor = device.Data.FirstOrDefault(o => o.Key == Keys.PowerDivisor)?.Value;
|
|
|
|
|
if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor))
|
|
|
|
|
{
|
|
|
|
|
var power = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
var value = power * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor);
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Power, value.ToString("f2"), DeviceDataType.Float, "功率", "W", timestamp: timestamp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (item.Key == 0x0301)
|
|
|
|
|
{
|
|
|
|
|
var value = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.ElectricityMultiplier, value, DeviceDataType.Int, "电功乘数", timestamp: timestamp, hidden: true));
|
|
|
|
|
}
|
|
|
|
|
else if (item.Key == 0x0302)
|
|
|
|
|
{
|
|
|
|
|
var value = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.ElectricityDivisor, value, DeviceDataType.Int, "电功除数", timestamp: timestamp, hidden: true));
|
|
|
|
|
}
|
|
|
|
|
else if (item.Key == 0x0604)
|
|
|
|
|
{
|
|
|
|
|
var value = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.PowerMultiplier, value, DeviceDataType.Int, "电功乘数", timestamp: timestamp, hidden: true));
|
|
|
|
|
}
|
|
|
|
|
else if (item.Key == 0x0605)
|
|
|
|
|
{
|
|
|
|
|
var value = BitConverter.ToUInt16(item.Value.ToArray());
|
|
|
|
|
this.UpdateData(deviceRepo, device, device.CreateData(Keys.PowerDivisor, value, DeviceDataType.Int, "电功除数", timestamp: timestamp, hidden: true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (clusterId == ClusterId.SummationDivisor)
|
|
|
|
|
{
|
|
|
|
|
this.X8D07020000(sn, device.Number);
|
|
|
|
|
}
|
|
|
|
|
//if (clusterId == ClusterId.SummationDivisor)
|
|
|
|
|
//{
|
|
|
|
|
// this.X8D0702(sn, device.Number);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|