Former-commit-id: 7b12dfcee895f62f0dbc080a0ea607c377b278b6
TangShanKaiPing
wanggang 6 years ago
parent 5b6d686ef4
commit 5b12174199

@ -9,7 +9,7 @@ namespace Application.Domain.Entities
{ {
public int DataType { get; set; } public int DataType { get; set; }
public int DataLength { get; set; } public int DataLength { get; set; }
public int Address { get; set; } public string Address { get; set; }
public int Endpoint { get; set; } public int Endpoint { get; set; }
public int ProfileId { get; set; } public int ProfileId { get; set; }
public int DeviceId { get; set; } public int DeviceId { get; set; }
@ -30,7 +30,7 @@ namespace Application.Domain.Entities
public string Sn { get; set; } public string Sn { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int Number { get; set; } public string Number { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public int CategoryNumber { get; set; } public int CategoryNumber { get; set; }
public string CategoryName { get; set; } public string CategoryName { get; set; }
@ -41,7 +41,7 @@ namespace Application.Domain.Entities
{ {
this.DataType = ms.ReadByte(); this.DataType = ms.ReadByte();
this.DataLength = ms.ReadByte(); this.DataLength = ms.ReadByte();
this.Address = ms.ReadInt(); this.Address = ms.ReadHexString(2);
this.Endpoint = ms.ReadByte(); this.Endpoint = ms.ReadByte();
this.ProfileId = ms.ReadInt(); this.ProfileId = ms.ReadInt();
this.DeviceId = ms.ReadInt(); this.DeviceId = ms.ReadInt();

@ -7,7 +7,7 @@ using Infrastructure.Web.Mvc;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SPService.Applicaiton.Models; using SPService.Applicaiton.Models;
namespace LiChuangService.Areas.Controllers namespace FBeeService.Areas.Controllers
{ {
[Area("Admin")] [Area("Admin")]
public class HomeController : CrudController<Gateway, PagedListModel<EditGatewayModel>, EditGatewayModel, EditGatewayModel> public class HomeController : CrudController<Gateway, PagedListModel<EditGatewayModel>, EditGatewayModel, EditGatewayModel>

@ -13,7 +13,7 @@ using Polly;
using SPService.Applicaiton.Models; using SPService.Applicaiton.Models;
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
namespace LiChuangService.Controllers namespace FBeeService.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
@ -37,15 +37,49 @@ namespace LiChuangService.Controllers
return View(this._repo.ReadOnlyTable().ToList()); return View(this._repo.ReadOnlyTable().ToList());
} }
#region api
[HttpGet] [HttpGet]
[Route("/switch2/api")] [Route("/smartplug/api")]
[SwaggerOperation("API")] [SwaggerOperation("API")]
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public string Switch2Api() public string Switch2Api()
{ {
return GetApiJson("/switch2/"); return GetApiJson("/smartplug/");
}
#region api
[SwaggerOperation("开")]
[HttpGet]
[Route("/smartplug/21on")]
public ApiResponse SmartPlugOn([SwaggerParameter("设备Id")]string id)
{
try
{
this._deviceService.SmartPlugOn(id);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
}
[SwaggerOperation("关")]
[HttpGet]
[Route("/smartplug/22off")]
public ApiResponse SmartPlugOff([SwaggerParameter("设备Id")]string id)
{
try
{
this._deviceService.SmartPlugOff(id);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
} }
[HttpGet] [HttpGet]

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<RootNamespace>FBeeService</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
namespace LiChuangService namespace FBeeService
{ {
public static class CommandHelper public static class CommandHelper
{ {

@ -1,4 +1,4 @@
namespace LiChuangService namespace FBeeService
{ {
public static class Crc16 public static class Crc16
{ {

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

@ -5,7 +5,7 @@ using Infrastructure.Extensions;
using Infrastructure.Web.Hosting; using Infrastructure.Web.Hosting;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
namespace LiChuangService namespace FBeeService
{ {
public class Program public class Program
{ {

@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
namespace LiChuangService namespace FBeeService
{ {
public class Startup : ShardStartup public class Startup : ShardStartup
{ {

@ -1,6 +1,7 @@
@model List<FBeeDevice> @model List<FBeeDevice>
<table> <table>
<tr> <tr>
<th>编号</th>
<th>Sn</th> <th>Sn</th>
<th>地址</th> <th>地址</th>
<th>开关</th> <th>开关</th>
@ -9,6 +10,7 @@
@foreach (var item in Model) @foreach (var item in Model)
{ {
<tr> <tr>
<td>@item.Number</td>
<td>@item.Sn</td> <td>@item.Sn</td>
<td>@item.Address</td> <td>@item.Address</td>
<td>@item.Power</td> <td>@item.Power</td>

Loading…
Cancel
Save