virtual protected bool HandleADMDeviceCommand(ArduinoDeviceManager adm, String deviceID, String command, List <Object> args, Message response) { if (adm == null) { throw new Exception("No ADM provided"); } if (!adm.HasDevice(deviceID)) { throw new Exception(String.Format("Device {0} has not been added to ADM", deviceID)); } bool respond = true; ArduinoDevice device = null; MessageSchema schema = new ADMService.MessageSchema(response); switch (command) { case "list-commands": device = adm.GetDevice(deviceID); schema.AddDeviceCommands(device); break; case "status": device = adm.GetDevice(deviceID); if (device.BoardID == 0) { throw new Exception(String.Format("Device {0} does not have a board ID", deviceID)); } AddADMRequest(adm, adm.RequestStatus(device.BoardID), response.Target); respond = false; break; default: var commands = command.Split(','); foreach (var cmd in commands) { var tcmd = cmd.Trim(); if (tcmd.ToLower().IndexOf("wait") == 0) { int delay = tcmd.Length > 4 ? System.Convert.ToInt16(tcmd.Substring(4, tcmd.Length - 4)) : 200; System.Threading.Thread.Sleep(delay); } else { byte tag = adm.IssueCommand(deviceID, tcmd, args); if (tag > 0) { AddADMRequest(adm, tag, response.Target); respond = false; } } } break; } return(respond); }
public void PrepareForBroadcast(ArduinoDeviceManager adm) { ADMMessage message = (ADMMessage)Message; message.AddValue("BoardID", adm.BoardID); ArduinoDevice dev = null; if (message.TargetID > 0) { dev = adm.GetDeviceByBoardID(message.TargetID); } else if (message.Sender != null && message.Sender != String.Empty) { dev = adm.GetDevice(message.Sender); } message.AddValue(DEVICE_ID, dev != null ? dev.ID : ""); message.AddValue(DEVICE_NAME, dev != null ? dev.Name : ""); }