|
|
|
@ -89,7 +89,7 @@ namespace FBeeService
|
|
|
|
|
public void X81(string sn)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"refresh {sn}");
|
|
|
|
|
this.Write(sn, RequestType.x81, null);
|
|
|
|
|
this.Write(sn, RequestType.x81);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -105,7 +105,7 @@ namespace FBeeService
|
|
|
|
|
{
|
|
|
|
|
var responseType = ms.ReadByte();
|
|
|
|
|
var dataLength = ms.ReadByte();
|
|
|
|
|
var address = ms.ReadHexString(2);
|
|
|
|
|
var address = ms.ReadHexStringDesc(2);
|
|
|
|
|
var endpoint = ms.ReadByte();
|
|
|
|
|
using (var scope = _applicationServices.CreateScope())
|
|
|
|
|
{
|
|
|
|
@ -184,20 +184,10 @@ namespace FBeeService
|
|
|
|
|
public void X95(string sn, string ieee)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"delete {ieee} from {sn}");
|
|
|
|
|
this.Clients.TryGetValue(sn, out TcpClientWrapper client);
|
|
|
|
|
using (var scope = _applicationServices.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
var repo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
|
|
|
|
|
var device = repo.ReadOnlyTable().FirstOrDefault(o => o.IsOnline != 0 && o.IEEE == ieee);
|
|
|
|
|
var address = device.Address;
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(0x0c);
|
|
|
|
|
list.Add(0x02);
|
|
|
|
|
list.AddRange(address.HexToBytes());
|
|
|
|
|
list.AddRange(ieee.HexToBytes());
|
|
|
|
|
list.Add(0x01);
|
|
|
|
|
this.Write(sn, RequestType.x95, list);
|
|
|
|
|
}
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.AddRange(ieee.HexToBytes());
|
|
|
|
|
list.Add(0x01);
|
|
|
|
|
this.Write(sn, RequestType.x95, ieee, list, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//0x94更改指定设备名
|
|
|
|
@ -209,24 +199,9 @@ namespace FBeeService
|
|
|
|
|
/// <param name="status"></param>
|
|
|
|
|
public void X82(string sn, string ieee, byte status)
|
|
|
|
|
{
|
|
|
|
|
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 (device != null)
|
|
|
|
|
{
|
|
|
|
|
var address = device.Address;
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(0x0d);
|
|
|
|
|
list.Add(0x02);
|
|
|
|
|
list.AddRange(address.HexToBytes());
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
|
|
|
|
|
list.Add((byte)device.Endpoint);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
list.Add(status);
|
|
|
|
|
this.Write(sn, RequestType.x82, list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(status);
|
|
|
|
|
this.Write(sn, RequestType.x82, ieee, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -240,7 +215,7 @@ namespace FBeeService
|
|
|
|
|
{
|
|
|
|
|
var responseType = ms.ReadByte();
|
|
|
|
|
var dataLength = ms.ReadByte();
|
|
|
|
|
var address = ms.ReadHexString(2);
|
|
|
|
|
var address = ms.ReadHexStringDesc(2);
|
|
|
|
|
var endpoint = ms.ReadByte();
|
|
|
|
|
using (var scope = _applicationServices.CreateScope())
|
|
|
|
|
{
|
|
|
|
@ -267,24 +242,10 @@ namespace FBeeService
|
|
|
|
|
/// <param name="value">0-255</param>
|
|
|
|
|
public void X83(string sn, string ieee, [Range(0, 255)]byte brightness)
|
|
|
|
|
{
|
|
|
|
|
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 (device != null)
|
|
|
|
|
{
|
|
|
|
|
var address = device.Address;
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(0x02);
|
|
|
|
|
list.AddRange(address.HexToBytes());
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
|
|
|
|
|
list.Add((byte)device.Endpoint);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
list.Add(brightness);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
this.Write(sn, RequestType.x83, list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(brightness);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
this.Write(sn, RequestType.x83, ieee, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -292,25 +253,11 @@ namespace FBeeService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void X84(string sn, string ieee, [Range(0, 255)]byte hue, [Range(0, 255)]byte saturation)
|
|
|
|
|
{
|
|
|
|
|
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 (device != null)
|
|
|
|
|
{
|
|
|
|
|
var address = device.Address;
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(0x02);
|
|
|
|
|
list.AddRange(address.HexToBytes());
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
|
|
|
|
|
list.Add((byte)device.Endpoint);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
list.Add(hue);
|
|
|
|
|
list.Add(saturation);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
this.Write(sn, RequestType.x84, list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(hue);
|
|
|
|
|
list.Add(saturation);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
this.Write(sn, RequestType.x84, ieee, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//0x84
|
|
|
|
@ -339,7 +286,7 @@ namespace FBeeService
|
|
|
|
|
//0x9d获取网关信息
|
|
|
|
|
public void X9d(string sn)
|
|
|
|
|
{
|
|
|
|
|
this.Write(sn, RequestType.x9d, null);
|
|
|
|
|
this.Write(sn, RequestType.x9d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -394,25 +341,10 @@ namespace FBeeService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void XA8(string sn, string ieee, [Range(2700, 6500)]ushort color)
|
|
|
|
|
{
|
|
|
|
|
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 (device != null)
|
|
|
|
|
{
|
|
|
|
|
var address = device.Address;
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.Add(0x10);
|
|
|
|
|
list.Add(0x02);
|
|
|
|
|
list.AddRange(address.HexToBytes());
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
|
|
|
|
|
list.Add((byte)device.Endpoint);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
list.AddRange(BitConverter.GetBytes(color));
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
this.Write(sn, RequestType.xa8, list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var list = new List<byte>();
|
|
|
|
|
list.AddRange(BitConverter.GetBytes(color));
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
this.Write(sn, RequestType.xa8, ieee, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//0xa9
|
|
|
|
@ -454,7 +386,7 @@ namespace FBeeService
|
|
|
|
|
{
|
|
|
|
|
var responseType = ms.ReadByte();
|
|
|
|
|
var dataLength = ms.ReadByte();
|
|
|
|
|
var address = ms.ReadHexString(2);
|
|
|
|
|
var address = ms.ReadHexStringDesc(2);
|
|
|
|
|
var endpoint = ms.ReadByte();
|
|
|
|
|
using (var scope = _applicationServices.CreateScope())
|
|
|
|
|
{
|
|
|
|
@ -767,18 +699,28 @@ namespace FBeeService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Write(string sn, byte commandType, List<byte> command)
|
|
|
|
|
private void Write(string sn, byte commandType, string ieee = null, List<byte> command = null, bool needEndPoint = true, byte addressType = 0x02)
|
|
|
|
|
{
|
|
|
|
|
this.Clients.TryGetValue(sn, out TcpClientWrapper client);
|
|
|
|
|
if (command == null)
|
|
|
|
|
{
|
|
|
|
|
command = new List<byte>();
|
|
|
|
|
}
|
|
|
|
|
var data = new List<byte>();
|
|
|
|
|
data.AddRange(sn.HexToBytes().Reverse());
|
|
|
|
|
data.Add(RequestType.xfe);
|
|
|
|
|
data.Add(commandType);
|
|
|
|
|
data.AddRange(command);
|
|
|
|
|
if (command != null && command.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
data.Add((byte)(command.Count() + 13));
|
|
|
|
|
data.Add(addressType);
|
|
|
|
|
using (var scope = _applicationServices.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
var repo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
|
|
|
|
|
var device = repo.ReadOnlyTable().FirstOrDefault(o => o.Sn == sn && o.IEEE == ieee);
|
|
|
|
|
data.AddRange(device.Address.HexToBytes().Reverse());
|
|
|
|
|
data.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
|
|
|
|
|
data.Add((byte)device.Endpoint);
|
|
|
|
|
data.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
}
|
|
|
|
|
data.AddRange(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var head = BitConverter.GetBytes(data.Count() + 2).ToList();
|
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
@ -790,6 +732,11 @@ namespace FBeeService
|
|
|
|
|
list.AddRange(head);
|
|
|
|
|
list.AddRange(data);
|
|
|
|
|
var bytes = list.ToArray();
|
|
|
|
|
this.Send(client, bytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Send(TcpClientWrapper client, byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"write:{BitConverter.ToString(bytes).Replace("-", " ")}");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|