Former-commit-id: e6c078b913f267cccaa5e0daee4f6c2b415af6d1
TangShanKaiPing
wanggang 6 years ago
parent 1edf3fd27c
commit 90041df2ca

@ -20,28 +20,28 @@ namespace Demo.Droid.Controls
public void OnPreviewFrame(byte[] data, Camera camera)
{
//byte[] rotatedData = new byte[bytes.Length];
//for (int y = 0; y < height; y++)
//{
// for (int x = 0; x < width; x++)
// {
// rotatedData[x * height + height - y - 1] = bytes[x + y * width];
// }
//}
var jpegBytes = this.ConvertYuvToJpeg(data);
var droidBitmap = Android.Graphics.BitmapFactory.DecodeByteArray(jpegBytes, 0, jpegBytes.Length);
var skBitmap = droidBitmap.ToSKBitmap();
var base64 = Convert.ToBase64String(jpegBytes);
using (var droidBitmap = Android.Graphics.BitmapFactory.DecodeByteArray(jpegBytes, 0, jpegBytes.Length))
{
using (var skBitmap = droidBitmap.ToSKBitmap())
{
var base64 = Convert.ToBase64String(jpegBytes);
}
}
}
private byte[] ConvertYuvToJpeg(byte[] yuvData, int quality = 80)
{
var yuv = new Android.Graphics.YuvImage(yuvData, previewFormat, width, height, null);
var ms = new MemoryStream();
yuv.CompressToJpeg(new Android.Graphics.Rect(0, 0, width, height), quality, ms);
var jpegData = ms.ToArray();
ms.Close();
return jpegData;
byte[] result = null;
using (var yuv = new Android.Graphics.YuvImage(yuvData, previewFormat, width, height, null))
{
using (var ms = new MemoryStream())
{
yuv.CompressToJpeg(new Android.Graphics.Rect(0, 0, width, height), quality, ms);
result = ms.ToArray();
}
}
return result;
}
}
}

@ -0,0 +1,8 @@
namespace Application.Domain.Entities
{
public enum ClusterId
{
light = 0x0400,
alarm = 0x0500
}
}

@ -2,6 +2,24 @@
{
public enum DataType
{
null0 = 0x00,
bit1 = 0x08,
bit2,
bit3,
bit4,
bit5,
bit6,
bit7,
bit8,
bool1,
bitmap1 = 0x18,
bitmap2,
bitmpa3,
bitmap4,
bitmap5,
bitmap6,
bitmap7,
bitmap8,
uint1 = 0x20,
uint2,
uint3,

@ -36,5 +36,13 @@ namespace Application.Domain.Entities
public int CategoryNumber { get; set; }
public string CategoryName { get; set; }
public string EName { get; set; }
//
public int Light { get; set; }
public string Unit { get; set; }
public int Warning { get; set; }
public bool IsWarning { get; set; }
public bool UnderVoltage { get; set; }
}
}

@ -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)

@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
namespace FBeeService
{
@ -34,9 +33,5 @@ namespace FBeeService
modelBuilder.Entity<Gateway>().HasIndex(o => o.Sn).IsUnique();
modelBuilder.Entity<FBeeDevice>().HasIndex(o => new { o.Sn, o.IEEE }).IsUnique();
}
public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration)
{
}
}
}

@ -17,7 +17,10 @@
<th>分类编号</th>
<th>电量</th>
<th>在线</th>
<th>开关</th>
<th>光强</th>
<th>电压低</th>
<th>警报</th>
<th>操作</th>
<th>删除</th>
</tr>
@foreach (var item in Model)
@ -35,6 +38,9 @@
<td>@item.Battery</td>
<td><input type="checkbox" readonly disabled @Html.Raw(item.IsOnline == 0 ? "" : "checked") /></td>
<td><input type="checkbox" readonly disabled @Html.Raw(item.SwitchState == 0 ? "" : "checked") /> @item.SwitchState</td>
<td>@item.Light</td>
<td>@Html.DisplayFor(o => item.UnderVoltage)</td>
<td>@Html.DisplayFor(o => item.IsWarning)</td>
<td>
<a class="btn btn-primary cmd" href="/api/x82?sn=@item.Sn&ieee=@item.IEEE&status=1">开</a>
<a class="btn btn-primary cmd" href="/api/x82?sn=@item.Sn&ieee=@item.IEEE&status=0">关</a>

Loading…
Cancel
Save