|
|
|
@ -1,8 +1,5 @@
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
using Application.Models;
|
|
|
|
|
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Infrastructure.Models;
|
|
|
|
@ -23,7 +20,7 @@ using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace LiChuangService
|
|
|
|
|
namespace FBeeService
|
|
|
|
|
{
|
|
|
|
|
public class DeviceService : IDisposable
|
|
|
|
|
{
|
|
|
|
@ -89,6 +86,34 @@ namespace LiChuangService
|
|
|
|
|
Console.WriteLine("notify end ...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SmartPlugOn(string id)
|
|
|
|
|
{
|
|
|
|
|
this.DeviceOnOff(id, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SmartPlugOff(string id)
|
|
|
|
|
{
|
|
|
|
|
this.DeviceOnOff(id, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeviceOnOff(string id, byte status)
|
|
|
|
|
{
|
|
|
|
|
var sn = id.Split('-')[0];
|
|
|
|
|
var address = id.Split('-')[1];
|
|
|
|
|
var list = new List<byte>() { 0x16, 0x00 };
|
|
|
|
|
list.AddRange(sn.HexToBytes().Reverse());
|
|
|
|
|
list.Add(0xfe);
|
|
|
|
|
list.Add(0x82);
|
|
|
|
|
list.Add(0x0d);
|
|
|
|
|
list.Add(0x02);
|
|
|
|
|
list.AddRange(address.HexToBytes());
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
|
|
|
|
|
list.Add(0x01);
|
|
|
|
|
list.AddRange(new byte[] { 0x00, 0x00 });
|
|
|
|
|
list.Add(status);
|
|
|
|
|
this.Clients[sn].Client.GetStream().Write(list.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Switch2AllOn(string id)
|
|
|
|
|
{
|
|
|
|
|
this.Command16(new byte[] { this.GetNumber(id), 0x0f, 0x00, 0x00, 0x00, 0x03, 0x01, 0x07 });
|
|
|
|
@ -332,15 +357,15 @@ namespace LiChuangService
|
|
|
|
|
{
|
|
|
|
|
var responseType = ms.ReadByte();
|
|
|
|
|
var dataLength = ms.ReadByte();
|
|
|
|
|
var deviceNumber = ms.ReadInt();
|
|
|
|
|
var address = ms.ReadHexString(2);
|
|
|
|
|
var endpoint = ms.ReadByte();
|
|
|
|
|
using (var scope = _applicationServices.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
var deviceRepo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
|
|
|
|
|
var device = deviceRepo.Table().FirstOrDefault(o => o.Number == deviceNumber);
|
|
|
|
|
var device = deviceRepo.Table().FirstOrDefault(o => o.Address == address);
|
|
|
|
|
if (device == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"{deviceNumber} dose not save in database");
|
|
|
|
|
Console.WriteLine($"{address} hasn't save in database");
|
|
|
|
|
}
|
|
|
|
|
if (responseType == MessageType.DeviceResponse)//获取设备返回值
|
|
|
|
|
{
|
|
|
|
@ -349,7 +374,7 @@ namespace LiChuangService
|
|
|
|
|
var deviceType = DeviceId.List.FirstOrDefault(o => o.RawDeviceId == deviceId);
|
|
|
|
|
if (deviceType == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"{deviceId} dose not config in database");
|
|
|
|
|
Console.WriteLine($"{deviceId} hasn't config in database");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -358,7 +383,7 @@ namespace LiChuangService
|
|
|
|
|
device = new FBeeDevice
|
|
|
|
|
{
|
|
|
|
|
Sn = sn,
|
|
|
|
|
Number = deviceNumber,
|
|
|
|
|
Number = $"{sn}-{address}",
|
|
|
|
|
Name = deviceType.Name,
|
|
|
|
|
Icon = deviceType.Icon,
|
|
|
|
|
CategoryNumber = deviceType.RawDeviceId,
|
|
|
|
|