public void TestSimpleCommandExecution() { byte[] deviceId = new byte[] { 0x01 }; MockTestDevice device = new MockTestDevice(); device.DeviceID = deviceId; device.NetworkAddress = new byte[] { 1 }; MockDeviceNetwok mdn = new MockDeviceNetwok(); HomeAutomationSystem.DeviceNetworkRegistry.RegisterDeviceNetwork(mdn, "mock"); HomeAutomationSystem.DeviceRegistry.RegisterDevice(mdn, device, deviceId); DeviceCommand dc = new DeviceCommand() { DeviceID = deviceId, DeviceNetworkName = "mock", Name = "DoMyMethod", Parameters = new string[] { "YES" } }; mdn.ExecuteCommand(dc); Assert.IsTrue(device.TestSuccess); }
/// <summary> /// Executes the command on this instance. /// More precisely this invokes the aCommand.Name method with the specified parameters. /// </summary> /// <param name="aCommand"></param> public void ExecuteCommand(DeviceCommand aCommand) { MethodInfo executableMethod = this.GetType().GetMethod(aCommand.Name); object[] parameters = new object[aCommand.Parameters.Length]; ParameterInfo[] parameterInfos = executableMethod.GetParameters(); for (int i = 0; i < parameters.Length; i++) { Type destinationType = parameterInfos[i].ParameterType; parameters[i] = Convert.ChangeType(aCommand.Parameters[i], destinationType); } executableMethod.Invoke(this, parameters); }
/// <summary> /// Builds a device command based on the command message. /// Format: networkname,methodname,param1,param2,param3,... /// </summary> /// <param name="commandMessage"></param> /// <returns></returns> public static DeviceCommand CreateFromString(string commandMessage) { DeviceCommand command = new DeviceCommand(); string[] components = commandMessage.Split(','); command.DeviceNetworkName = components[0]; // first parse the address of this command byte[] address = HexConverter.BytesFromString(components[1]); // copy all items from the components to the parameters starting with index 1 string[] parameters = new String[components.Length - 3]; Array.Copy(components, 3, parameters, 0, parameters.Length); // build a command structure and return it. command.DeviceID = address; command.Name = components[2]; command.Parameters = parameters; return command; }
public void ExecuteCommand(DeviceCommand command) { }
/// <summary> /// Sends a command to the XBee network. /// </summary> /// <param name="command"></param> public void ExecuteCommand(DeviceCommand command) { IXBeeDevice device = HomeAutomationSystem.DeviceRegistry.GetDeviceById(this, command.DeviceID) as IXBeeDevice; device?.ExecuteCommand(command); }
public void ExecuteDeviceCommand(DeviceCommand command) { Gateway.ExecuteDeviceCommand(command); }
public void ExecuteCommand(DeviceCommand command) { HomeAutomationSystem.DeviceRegistry.GetDeviceById(this, command.DeviceID).ExecuteCommand(command); }