diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs index 6828a8ec..0807e7f3 100644 --- a/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs +++ b/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs @@ -1,13 +1,65 @@ -using Swashbuckle.AspNetCore.Annotations; +using Application.Models; +using Infrastructure.Extensions; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; using System; +using System.ComponentModel.DataAnnotations; namespace FBeeService.Controllers { [SwaggerTag("调色灯")] public class ColorLightController : SwitchController { - public ColorLightController(IServiceProvider applicationService, DeviceService deviceService) : base(applicationService, deviceService) + protected readonly DeviceService _deviceService; + + public ColorLightController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices, deviceService) + { + this._deviceService = deviceService; + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("亮度")] + public ApiResponse SetBrightness([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [Range(0, 255)]int brightness) + { + try + { + this._deviceService.X83(sn, id, (byte)brightness); + } + catch (Exception ex) + { + ex.PrintStack(); + return ApiResponse.Error(ex.Message); + } + return ApiResponse.AsyncSuccess(); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("色度")] + public ApiResponse SetColor([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [Range(0, 255)]int hue, [Range(0, 255)]int saturation) + { + try + { + this._deviceService.X84(sn, id, (byte)hue, (byte)saturation); + } + catch (Exception ex) + { + ex.PrintStack(); + return ApiResponse.Error(ex.Message); + } + return ApiResponse.AsyncSuccess(); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("色温")] + public ApiResponse SetColorTemperature([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [Range(2700, 6500)]int colorTemperature) { + try + { + this._deviceService.XA8(sn, id, (ushort)colorTemperature); + } + catch (Exception ex) + { + ex.PrintStack(); + return ApiResponse.Error(ex.Message); + } + return ApiResponse.AsyncSuccess(); } } } \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs index 2c3a3852..75f76c85 100644 --- a/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs +++ b/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs @@ -170,10 +170,10 @@ namespace FBeeService.Controllers return GetApiJson("/colorlight/"); } - [SwaggerOperation("调节亮度")] + [SwaggerOperation("亮度")] [HttpGet] [Route("/colorlight/23setbrightness")] - public ApiResponse SetBrightness([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [Range(0, 255)]int brightness) + public ApiResponse SetBrightness([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [SwaggerParameter("亮度")][Range(0, 255)]int brightness) { try { @@ -187,10 +187,10 @@ namespace FBeeService.Controllers return ApiResponse.AsyncSuccess(); } - [SwaggerOperation("调节亮度")] + [SwaggerOperation("颜色")] [HttpGet] [Route("/colorlight/24setcolor")] - public ApiResponse SetColor([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [Range(0, 255)]int hue, [Range(0, 255)]int saturation) + public ApiResponse SetColor([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [SwaggerParameter("色度")][Range(0, 255)]int hue, [SwaggerParameter("饱和度")][Range(0, 255)]int saturation) { try { @@ -204,10 +204,10 @@ namespace FBeeService.Controllers return ApiResponse.AsyncSuccess(); } - [SwaggerOperation("调节色温")] + [SwaggerOperation("色温")] [HttpGet] [Route("/colorlight/25setcolortemperature")] - public ApiResponse SetColorTemperature([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [Range(2700, 6500)]int colorTemperature) + public ApiResponse SetColorTemperature([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [SwaggerParameter("色温")][Range(2700, 6500)]int colorTemperature) { try { diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs index 1a916448..5b452a80 100644 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs +++ b/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs @@ -456,15 +456,15 @@ namespace FBeeService { if (zoneType == 0x0001) { - deviceName = "1路开关"; + deviceName = "一路开关"; } else if (zoneType == 0x0002) { - deviceName = "2路开关"; + deviceName = "二路开关"; } else if (zoneType == 0x0003) { - deviceName = "3路开关"; + deviceName = "三路开关"; } } var infoNumber = $"fbee:{deviceType.RawDeviceId.ToString("x4")}:{zoneType.ToString("x2")}"; @@ -485,15 +485,15 @@ namespace FBeeService { deviceInfo.ApiJson = this.GetApiJson("/Socket/"); } - else if (deviceName == "1路开关") + else if (deviceName == "一路开关") { deviceInfo.ApiJson = this.GetApiJson("/Switch/"); } - else if (deviceName == "2路开关") + else if (deviceName == "二路开关") { deviceInfo.ApiJson = this.GetApiJson("/Switch2/"); } - else if (deviceName == "3路开关") + else if (deviceName == "三路开关") { deviceInfo.ApiJson = this.GetApiJson("/Switch3/"); } @@ -539,7 +539,7 @@ namespace FBeeService device.AddorUpdateData(Keys.EndPoint, endpoint, DeviceDataType.Int, Keys.EndPoint, hidden: true); if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) { - device.AddorUpdateData(Keys.State, switchState, DeviceDataType.Int, "状态"); + device.AddorUpdateData(Keys.State, switchState == 0 ? "关" : (switchState == 1 ? "关" : "停"), DeviceDataType.String, "状态"); } var battery = ms.ReadByte(); device.AddorUpdateData(Keys.Battery, battery, DeviceDataType.Int, Keys.Battery); @@ -643,7 +643,25 @@ namespace FBeeService var device = this.GetDeviceByAddress(deviceRepo, sn, address); if (device != null) { - device.AddorUpdateData(Keys.State, ms.ReadInt(), DeviceDataType.Int, "状态"); + if (device.Name.Contains("二路开关") || device.Name.Contains("三路开关")) + { + if (endpoint == 0x10) + { + device.AddorUpdateData(Keys.L1State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "L1状态"); + } + else if (endpoint == 0x11) + { + device.AddorUpdateData(Keys.L2State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "L2状态"); + } + else if (endpoint == 0x12) + { + device.AddorUpdateData(Keys.L3State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "L3状态"); + } + } + else + { + device.AddorUpdateData(Keys.State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "状态"); + } deviceRepo.SaveChanges(); this.SendDevice(device); } diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs index 5fce733a..8ff7c445 100644 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs +++ b/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs @@ -9,6 +9,9 @@ public const string Electricity = "Electricity"; public const string KeyPress = "KeyPress"; public const string State = "State"; + public const string L1State = "L1State"; + public const string L2State = "L2State"; + public const string L3State = "L3State"; public const string Battery = "Battery"; public const string EndPointCount = "EndPointCount"; public const string Data = "Data"; diff --git a/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml b/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml index 695b0bb8..5ffab186 100644 --- a/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml +++ b/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml @@ -23,7 +23,7 @@ var deviceId = Convert.ToInt32(item.Data.FirstOrDefault(o => o.Key == "DeviceId").Value); var address = item.Data.FirstOrDefault(o => o.Key == "Address").Value; var voltage = item.Data.FirstOrDefault(o => o.Key == "Voltage")?.Value; - var state = Convert.ToInt32(item.Data.FirstOrDefault(o => o.Key == "State")?.Value); + var state = item.Data.FirstOrDefault(o => o.Key == "State")?.Value; var battery = item.Data.FirstOrDefault(o => o.Key == "Battery")?.Value; @(++index) @@ -36,18 +36,7 @@ @if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) { - if (state == 0) - { - - } - else if (state == 1) - { - - } - else if (state == 2) - { - - } + @state } @if (deviceId == 0x0106) { diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html index 114b14e2..f08b4221 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html @@ -156,7 +156,7 @@ - + @@ -226,6 +226,242 @@ + + + + + + + + +