|
|
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
@ -29,11 +30,6 @@ namespace FBeeService
|
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
|
private readonly IServiceProvider _applicationServices;
|
|
|
|
|
private CancellationTokenSource _tokenSource;
|
|
|
|
|
private static readonly object lockObject = new Object();
|
|
|
|
|
private string _tcpIp;
|
|
|
|
|
private int _tcpPort;
|
|
|
|
|
private byte[] _address;
|
|
|
|
|
private string _addressValue;
|
|
|
|
|
private readonly Dictionary<int, int> _types = new Dictionary<int, int>();
|
|
|
|
|
private readonly ConcurrentDictionary<string, TcpClientWrapper> Clients = new ConcurrentDictionary<string, TcpClientWrapper>();
|
|
|
|
|
|
|
|
|
@ -44,8 +40,6 @@ namespace FBeeService
|
|
|
|
|
this._configuration = configuration;
|
|
|
|
|
this._httpClientFactory = httpClientFactory;
|
|
|
|
|
this._tokenSource = new CancellationTokenSource();
|
|
|
|
|
this._tcpIp = this._configuration["tcp.ip"];
|
|
|
|
|
this._tcpPort = this._configuration.GetValue<int>("tcp.port");
|
|
|
|
|
//this.Connect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -57,7 +51,28 @@ namespace FBeeService
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("timer ...");
|
|
|
|
|
foreach (var item in this.Clients)
|
|
|
|
|
{
|
|
|
|
|
var client = item.Value;
|
|
|
|
|
if (client != null && !client.Client.Connected)
|
|
|
|
|
{
|
|
|
|
|
this.Connect(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
await Task.Delay(5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
while (!_tokenSource.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -69,21 +84,6 @@ namespace FBeeService
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Refresh()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("notify start ...");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this.CheckConnection();
|
|
|
|
|
//this.SearchAddress();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine("notify end ...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region api
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -409,7 +409,7 @@ namespace FBeeService
|
|
|
|
|
{
|
|
|
|
|
var deviceRepo = scope.ServiceProvider.GetService<IRepository<FBeeDevice>>();
|
|
|
|
|
var device = deviceRepo.Table().FirstOrDefault(o => o.Sn == sn && o.Address == address);
|
|
|
|
|
var clusterId = ms.ReadInt();
|
|
|
|
|
var clusterId = (ClusterId)ms.ReadInt();
|
|
|
|
|
if (device != null)
|
|
|
|
|
{
|
|
|
|
|
var reportCount = ms.ReadByte();
|
|
|
|
@ -458,6 +458,23 @@ namespace FBeeService
|
|
|
|
|
var propData = ms.Read(propDataLength);
|
|
|
|
|
props.Add(propId, propData);
|
|
|
|
|
}
|
|
|
|
|
if (clusterId == ClusterId.light)
|
|
|
|
|
{
|
|
|
|
|
device.Light = BitConverter.ToInt16(props[0x0000]);
|
|
|
|
|
}
|
|
|
|
|
else if (clusterId == ClusterId.alarm)
|
|
|
|
|
{
|
|
|
|
|
//0x0011有烟雾泄露且电压正常
|
|
|
|
|
//0x0010无烟雾泄露且电压正常
|
|
|
|
|
//0x0018无烟雾泄露且电压偏低
|
|
|
|
|
//0x0019有烟雾泄露电压偏低
|
|
|
|
|
|
|
|
|
|
device.Warning = BitConverter.ToInt16(props[0x0080]);
|
|
|
|
|
var bitArray = new BitArray(props[0x0080]);
|
|
|
|
|
device.IsWarning = bitArray[0];
|
|
|
|
|
device.UnderVoltage = bitArray[7];
|
|
|
|
|
}
|
|
|
|
|
deviceRepo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -475,7 +492,7 @@ namespace FBeeService
|
|
|
|
|
|
|
|
|
|
#endregion api
|
|
|
|
|
|
|
|
|
|
private void CheckConnection()
|
|
|
|
|
public void Refresh()
|
|
|
|
|
{
|
|
|
|
|
var ips = NetworkInterface.GetAllNetworkInterfaces()
|
|
|
|
|
.Where(nic => nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
|
|
|
|
@ -648,7 +665,6 @@ namespace FBeeService
|
|
|
|
|
}
|
|
|
|
|
else if (responseType == ResponseType.x01)
|
|
|
|
|
{
|
|
|
|
|
//Console.WriteLine($"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
|
this.X01(sn, data);
|
|
|
|
|
}
|
|
|
|
|
else if (responseType == ResponseType.x07)
|
|
|
|
|