public void DeviceActionReqObjectTest() { DeviceActionReq sample = new DeviceActionReq(); sample.reqId = "id"; sample.d = new DMFields(); sample.d.fields = new DMField[1]; Assert.AreEqual(1, sample.d.fields.Length); Assert.AreEqual("id", sample.reqId); }
public void updatedHandler(DeviceActionReq req) { int rc = DeviceManagement.RESPONSECODE_ACCEPTED; string msg = ""; if (this.firmware.state != DeviceManagement.UPDATESTATE_DOWNLOADED) { rc = DeviceManagement.RESPONSECODE_BAD_REQUEST; msg = "Firmware is still not successfully downloaded."; parentGateway.sendResponse(req.reqId, rc, msg, this.deviceType, this.deviceId); return; } parentGateway.sendResponse(req.reqId, rc, msg, this.deviceType, this.deviceId); this.setUpdateState(DeviceManagement.UPDATESTATE_IN_PROGRESS); Console.WriteLine("Start Updateting new Firmware "); Thread.Sleep(2000); Console.WriteLine("Updated new Firmware "); this.setUpdateState(DeviceManagement.UPDATESTATE_SUCCESS); }
public void downloadHandler(DeviceActionReq req) { int rc = DeviceManagement.RESPONSECODE_ACCEPTED; string msg = ""; if (this.firmware.state != DeviceManagement.UPDATESTATE_IDLE) { rc = DeviceManagement.RESPONSECODE_BAD_REQUEST; msg = "Cannot download as the device is not in idle state"; parentGateway.sendResponse(req.reqId, rc, msg, this.deviceType, this.deviceId); return; } parentGateway.sendResponse(req.reqId, rc, msg, this.deviceType, this.deviceId); this.setState(DeviceManagement.UPDATESTATE_DOWNLOADING); Console.WriteLine("Start downloading new Firmware form " + firmware.uri); Thread.Sleep(2000); //call your device to take all the action to download Console.WriteLine("completed Download"); this.setState(DeviceManagement.UPDATESTATE_DOWNLOADED); }
public void infoHandler(DeviceActionReq req) { var fields = req.d.fields; for (int i = 0; i < fields.Length; i++) { if (fields[i].field == "mgmt.firmware") { var update = fields[i].value as IBMWIoTP.DeviceFirmware; this.firmware.uri = update.uri; this.firmware.verifier = update.verifier; this.firmware.name = update.name; this.firmware.state = update.state; this.firmware.updatedDateTime = update.updatedDateTime; this.firmware.updateStatus = update.updateStatus; this.firmware.version = update.version; break; } } if (this.firmware != null) { parentGateway.sendResponse(req.reqId, 204, "", this.deviceType, this.deviceId); } }