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); }
protected virtual bool OnADMInactivityTimeout(ArduinoDeviceManager adm, long msQuiet) { Tracing?.TraceEvent(TraceEventType.Warning, 100, "ADMService::MonitorADM: Last activity of ADM (BoardID={0}) on {1} was {2} ms ago ... so attempting a clear", adm.BoardID, adm.PortAndNodeID, msQuiet); try { adm.Clear(); Tracing?.TraceEvent(TraceEventType.Information, 100, "ADMService::MonitorADM: Clearing ADM (BoardID={0}) on {1} was successful so attempting to Ping", adm.BoardID, adm.PortAndNodeID); adm.RequestStatus(); return(true); } catch (Exception e) { Tracing?.TraceEvent(TraceEventType.Error, 100, "ADMService::MonitorADM: Error clearing ADM (BoardID={0}) on {1}: {2} {3}", adm.BoardID, adm.PortAndNodeID, e.GetType(), e.Message); return(false); } }