+
+
diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js
index 771f30b4..7cefa513 100644
--- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js
+++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js
@@ -70,6 +70,47 @@ methods = {
ajax(url, null, 'get');
});
},
+ GetButtons() {
+ return Enumerable.from(JSON.parse(this.GetDataValue("指令")))
+ //.orderBy(function (o) { return o.Value; })
+ .toArray();
+ },
+ Study(code) {
+ ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: this.model.Number, method: "/Ir/Study", type: 5,code:code }, 'post');
+ },
+ AddButton() {
+ var data = Enumerable.from(this.model.Data)
+ .where(function (o) { return o.Name === "指令" })
+ .firstOrDefault();
+ var buttons = this.GetButtons();
+ var newBtn = { Key:"测试", Value:603};
+ buttons.push(newBtn);
+ data.Value = JSON.stringify(buttons);
+ },
+ RemoveButton(key) {
+ var data = Enumerable.from(this.model.Data)
+ .where(function (o) { return o.Name === "指令" })
+ .firstOrDefault();
+ var buttons = this.GetButtons();
+ for (var i = buttons.length - 1; i >= 0; i--) {
+ if (buttons[i].Key == key) {
+ buttons.splice(i, 1);
+ break;
+ }
+ }
+ data.Value = JSON.stringify(buttons);
+ },
+ SaveButtons() {
+ var buttons = [];
+ $('#irbuttons').find('.button').each(function () {
+ buttons.push({
+ Key: $(this).find("input[name='key']").val(),
+ Value: $(this).find("input[name='value']").val()
+ });
+ });
+ var value = JSON.stringify(buttons);
+ ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: this.model.Number, method: "/Ir/Buttons", buttons: value }, 'post');
+ },
SendCode1(event) {
console.log(event.target + ',' + event.type + ',' + event.target.checked);
var form = $(event.target).parents('form');
diff --git a/projects/IoTNode/Controllers/FBee/ColorLightController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/ColorLightController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/ColorLightController.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/ColorLightController.cs
diff --git a/projects/IoTNode/Controllers/FBee/CurtainController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/CurtainController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/CurtainController.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/CurtainController.cs
diff --git a/projects/IoTNode/Controllers/FBee/GatewayController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/GatewayController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/GatewayController.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/GatewayController.cs
diff --git a/projects/IoTNode/Controllers/FBee/IrController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/IrController.cs
similarity index 77%
rename from projects/IoTNode/Controllers/FBee/IrController.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/IrController.cs
index 50b27fe7..1b32ff68 100644
--- a/projects/IoTNode/Controllers/FBee/IrController.cs
+++ b/projects/IoTNode/DeviceServices/FBee/Controllers/IrController.cs
@@ -30,7 +30,7 @@ namespace IoTNode.Controllers
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("学习")]
- public ApiResponse Study([SwaggerParameter("设备编号")]string number, [SwaggerParameter("按键类型")]byte type, [SwaggerParameter("键值"), Required, Range(1, 10)]ushort code)
+ public ApiResponse Study([SwaggerParameter("设备编号")]string number, [SwaggerParameter("按键类型")]byte type, [SwaggerParameter("键值"), Required, Range(603, 703)]ushort code)
{
return this.AsyncAction(() =>
{
@@ -38,5 +38,14 @@ namespace IoTNode.Controllers
this._deviceService.XA70083(values[0], values[1], type, code);
});
}
+
+ [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("自定义指令")]
+ public ApiResponse Buttons([SwaggerParameter("设备编号")]string number, [SwaggerParameter("指令")]string buttons)
+ {
+ return this.AsyncAction(() =>
+ {
+ this._deviceService.UpdateButtons(number, buttons);
+ });
+ }
}
}
\ No newline at end of file
diff --git a/projects/IoTNode/Controllers/FBee/SocketController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/SocketController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/SocketController.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/SocketController.cs
diff --git a/projects/IoTNode/Controllers/FBee/Switch2Controller.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/Switch2Controller.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/Switch2Controller.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/Switch2Controller.cs
diff --git a/projects/IoTNode/Controllers/FBee/Switch3Controller.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/Switch3Controller.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/Switch3Controller.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/Switch3Controller.cs
diff --git a/projects/IoTNode/Controllers/FBee/SwitchController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/SwitchController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/FBee/SwitchController.cs
rename to projects/IoTNode/DeviceServices/FBee/Controllers/SwitchController.cs
diff --git a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs
index 299aeb20..f3e109a2 100644
--- a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs
+++ b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs
@@ -55,6 +55,27 @@ namespace IoTNode.DeviceServices.FBee
return base.StartAsync(cancellationToken);
}
+ public void UpdateButtons(string number, string buttons)
+ {
+ using (var scope = _applicationServices.CreateScope())
+ {
+ var deviceRepo = scope.ServiceProvider.GetService
>();
+ var device = deviceRepo.Table().Include(o => o.Data).FirstOrDefault(o => o.Number == number);
+ if (device != null)
+ {
+ var data = device.Data.FirstOrDefault(o => o.Key == Keys.Buttons);
+ if (data != null)
+ {
+ data.Value = buttons.FromJson>>().ToJson();
+ if (deviceRepo.SaveChanges() > 0)
+ {
+ this.SendDataToServer(data);
+ }
+ }
+ }
+ }
+ }
+
public override void Execute()
{
var ips = NetworkInterface.GetAllNetworkInterfaces()
@@ -480,6 +501,7 @@ namespace IoTNode.DeviceServices.FBee
var deviceRepo = scope.ServiceProvider.GetService>();
var device = this.GetDevice(deviceRepo, sn, ieee);
+ var online = isOnline != 0x00;
if (device == null)
{
device = new Device
@@ -493,9 +515,19 @@ namespace IoTNode.DeviceServices.FBee
NodeId = node.Id
};
deviceRepo.Add(device);
+ device.IsOnline = online;
+ this.UpdateDevice(deviceRepo, device);
+ if (device.Name == "红外转发器")
+ {
+ var buttons = new List>() { new KeyValuePair("测试", 603) }.ToJson();
+ this.UpdateData(deviceRepo, device, device.CreateData(Keys.Buttons, buttons, DeviceDataType.String, "指令", timestamp: timestamp));
+ }
+ }
+ else
+ {
+ device.IsOnline = online;
+ this.UpdateDevice(deviceRepo, device);
}
- device.IsOnline = isOnline != 0x00;
- this.UpdateDevice(deviceRepo, device);
this.UpdateData(deviceRepo, device, device.CreateData(Keys.DeviceId, deviceId, DeviceDataType.Int, Keys.DeviceId, hidden: true, timestamp: timestamp));
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Address, address, DeviceDataType.String, Keys.Address, hidden: true, timestamp: timestamp));
this.UpdateData(deviceRepo, device, device.CreateData(Keys.EndPoint, endpoint, DeviceDataType.Int, Keys.EndPoint, hidden: true, timestamp: timestamp));
diff --git a/projects/IoTNode/DeviceServices/FBee/Keys.cs b/projects/IoTNode/DeviceServices/FBee/Keys.cs
index 01b1114a..85fb91fd 100644
--- a/projects/IoTNode/DeviceServices/FBee/Keys.cs
+++ b/projects/IoTNode/DeviceServices/FBee/Keys.cs
@@ -13,6 +13,7 @@
public const string L2State = "L2State";
public const string L3State = "L3State";
public const string Battery = "Battery";
+ public const string Buttons = "Buttons";
public const string EndPointCount = "EndPointCount";
public const string Data = "Data";
public const string ZoneType = "ZoneType";
diff --git a/projects/IoTNode/Controllers/Onvif/OnvifController.cs b/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/Onvif/OnvifController.cs
rename to projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs
diff --git a/projects/IoTNode/Controllers/SerialPort/SerialPortController.cs b/projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs
similarity index 100%
rename from projects/IoTNode/Controllers/SerialPort/SerialPortController.cs
rename to projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs