Former-commit-id: da7c7469eb810e7c87d21700ce620f495a5c9286
TangShanKaiPing
wanggang 6 years ago
parent bd92e4b6f1
commit a8b5ae7f7d

@ -9,6 +9,11 @@
public const int x82 = 0x82;
public const int x83 = 0x83;
public const int x84 = 0x84;
public const int x85 = 0x85;
public const int x86 = 0x86;
public const int x87 = 0x87;
public const int x88 = 0x88;
public const int xa9 = 0xa9;
public const int xc1 = 0xc1;
public const int xa7 = 0xa7;
public const int xa8 = 0xa8;

@ -99,6 +99,7 @@ namespace FBeeService
/// <param name="data"></param>
private void X01(string sn, byte[] data)
{
var create = false;
try
{
using (var ms = new MemoryStream(data))
@ -118,6 +119,7 @@ namespace FBeeService
var device = deviceRepo.Table().FirstOrDefault(o => o.Sn == sn && o.Address == address);
if (device == null)
{
create = true;
device = new FBeeDevice
{
Sn = sn,
@ -162,6 +164,10 @@ namespace FBeeService
device.Data = ms.ReadHexString(4);
device.RawValue = BitConverter.ToString(data);
deviceRepo.SaveChanges();
if (create)
{
this.UpdateStatus(device);
}
}
else
{
@ -176,6 +182,24 @@ namespace FBeeService
}
}
private void UpdateStatus(FBeeDevice device)
{
var deviceId = device.DeviceId;
var sn = device.Sn;
var ieee = device.IEEE;
if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId))
{
this.X85(sn, ieee);
}
if (deviceId == 0x0220)
{
this.X86(sn, ieee);
this.X87(sn, ieee);
this.X88(sn, ieee);
this.XA9(sn, ieee);
}
}
/// <summary>
/// 0x95删除指定设备
/// </summary>
@ -187,7 +211,7 @@ namespace FBeeService
var list = new List<byte>();
list.AddRange(ieee.HexToBytes());
list.Add(0x01);
this.Write(sn, RequestType.x95, ieee, list);
this.Write(sn, RequestType.x95, ieee, list, 0);
}
//0x94更改指定设备名
@ -205,7 +229,7 @@ namespace FBeeService
}
/// <summary>
/// 0x07接收指定设备的开关状态
/// 0x85-0x07接收指定设备的开关状态
/// </summary>
/// <param name="sn"></param>
/// <param name="data"></param>
@ -321,7 +345,7 @@ namespace FBeeService
}
/// <summary>
/// 0x09接收指定设备的色调返回值
/// 0x09接收指定设备的饱和度返回值
/// </summary>
/// <param name="sn"></param>
/// <param name="data"></param>
@ -350,12 +374,42 @@ namespace FBeeService
}
}
//0x84
//0x85
/// <summary>
/// 0x85-0x07查询开关状态
/// </summary>
public void X85(string sn, string ieee)
{
var list = new List<byte>();
this.Write(sn, RequestType.x85, ieee, list);
}
/// <summary>
/// 0x86-0x08查询亮度状态
/// </summary>
public void X86(string sn, string ieee)
{
var list = new List<byte>();
this.Write(sn, RequestType.x86, ieee, list);
}
/// <summary>
/// 0x87-0x09查询色度状态
/// </summary>
public void X87(string sn, string ieee)
{
var list = new List<byte>();
this.Write(sn, RequestType.x87, ieee, list);
}
/// <summary>
/// 0x88-0x0a查询饱和度状态
/// </summary>
public void X88(string sn, string ieee)
{
var list = new List<byte>();
this.Write(sn, RequestType.x88, ieee, list);
}
//0x86
//0x87
//0x88
//0x8d
//0x96
//0x8e
@ -467,21 +521,55 @@ namespace FBeeService
}
}
/// <summary>
/// 0080查询红外版本号
/// </summary>
/// <param name="sn"></param>
/// <param name="ieee"></param>
public void XA70080(string sn, string ieee)
{
var list = new List<byte>();
list.Add(0x03);
list.Add(0xff);
list.Add(0x00);
list.Add(0x03);//控制标志
list.Add(0xff);//包长
list.Add(0x00);//包序号
list.AddRange(new byte[] { 0x55, 0x55 });
list.Add(0x02);
list.AddRange(new byte[] { 0x80, 0x00 });
list.Add(0x82);
list[1] = (byte)(list.Count() - 3);
this.Write(sn, RequestType.xa7, ieee, list, 1);
this.Write(sn, RequestType.xa7, ieee, list, 2);
}
/// <summary>
/// 0081开始匹配遥控器
/// </summary>
/// <param name="sn"></param>
/// <param name="ieee"></param>
public void XA70081(string sn, string ieee, string version, [Range(1, 5)]byte type)
{
var list = new List<byte>();
list.Add(0x03);//控制标志
list.Add(0xff);//包长
list.Add(0x00);//包序号
list.AddRange(new byte[] { 0x55, 0x55 });
list.Add(0x09);
//list.AddRange(6);
list.AddRange(new byte[] { 0x81, 0x00 });
list.Add(type);
list[1] = (byte)(list.Count() - 3 + 1);
list.Add((byte)list.Skip(3).Take(12).Select(o => (int)o).Sum());
this.Write(sn, RequestType.xa7, ieee, list, 2);
}
/// <summary>
/// 0xa9-0x27查询色温状态
/// </summary>
public void XA9(string sn, string ieee)
{
var list = new List<byte>();
this.Write(sn, RequestType.xa9, ieee, list);
}
//0xa9
//0xab
///// <summary>
///// 0xa7查询红外数据
@ -853,20 +941,27 @@ namespace FBeeService
}
}
private void Write(string sn, byte commandType, string ieee = null, List<byte> command = null, int format = 0, byte addressType = 0x02)
private void Write(string sn, byte commandType, string ieee = null, List<byte> command = null, int format = 1, byte addressType = 0x02)
{
this.Clients.TryGetValue(sn, out TcpClientWrapper client);
var data = new List<byte>();
data.AddRange(sn.HexToBytes().Reverse());//sn号
data.Add(RequestType.xfe);//控制标志
data.Add(commandType);//控制类型
if (command != null && command.Count > 0)
if (command != null)
{
using (var scope = _applicationServices.CreateScope())
{
var repo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
var device = repo.ReadOnlyTable().FirstOrDefault(o => o.Sn == sn && o.IEEE == ieee);
if (format == 0)
{
data.Add((byte)(command.Count() + 1 + 2));//数据总长
data.Add(addressType);//地址模式
data.AddRange(device.Address.HexToBytes().Reverse());
data.AddRange(command);
}
else if (format == 1)
{
data.Add((byte)(command.Count() + 1 + 2 + 6 + 1 + 2));//数据总长
data.Add(addressType);//地址模式
@ -876,7 +971,7 @@ namespace FBeeService
data.AddRange(new byte[] { 0x00, 0x00 });
data.AddRange(command);
}
else if (format == 1)
else if (format == 2)
{
data.Add((byte)(command.Count() + 2 + 1));//数据总长
data.AddRange(device.Address.HexToBytes().Reverse());

Loading…
Cancel
Save