internal void LookupOpDescriptor(LMMMLingo.Tokens cmd, ref LMMMLingo.OpDesc op) { try { op = (LMMMLingo.OpDesc)LMMMOpOpDescMap[cmd]; } catch (Exception e) { commlog.TraceEvent(LogLevels.Error, 888, "Unable to look up cmd in descriptor map:" + e.Message); } }
internal void CommandPromptMatchPrefix(string input, ref LMMMLingo.OpDesc op) { string s = input.ToLower(); foreach (DictionaryEntry possible in CmdStringOpDescMap) // this supposed to be an IDictionaryElement or something like that. we get a k,v pair here { if (s.StartsWith((string)possible.Key) && ((OpDesc)possible.Value).isAPromptCmd) // it is a prompt prefix { op = ((OpDesc)possible.Value); break; } } }
// extract the single integer arg if there, mark bad if expected and not there bool ParsePrompt(string line, LMMMLingo.OpDesc cmdt, ref Int32 res) { res = 0; bool good = !cmdt.needsArg; string[] temp = line.Split('='); if (cmdt.needsArg && temp.Count() > 1) { good = Int32.TryParse(temp[1], out res); if (!good && cmdt.tok == LMMMLingo.Tokens.assay) { good = AssaySelector.AssayTypeConv(temp[1], out res); } } return(good); }
// UDP broadcast public bool PostLMMMCommand(LMMMLingo.Tokens cmd, bool terminator = false) { bool res = true; if (NC.App.AppContext.Emulate) { // look up OpDesc instance from map // dispatch to thrift based on cmd token LMMMLingo.OpDesc op = null; cmdprocessor.LookupOpDescriptor(cmd, ref op); DivertToEmulation(op, 0, -1); } else { try { string cmds = cmdprocessor.ComposeCommandStrings(cmd, 0); if (cmds.Length > 0) { LMConnectionInfo net = ((LMConnectionInfo)(NC.App.Opstate.Measurement.Detectors[0].Id.FullConnInfo)); // broadcast go message to all cfg.Net.Subnet addresses. This is the instrument group. Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPAddress broadcast = IPAddress.Parse(net.NetComm.Subnet); if (terminator) { cmds += LMMMLingo.eol; } Byte[] sendBuffer = Encoding.ASCII.GetBytes(cmds); IPEndPoint ep = new IPEndPoint(broadcast, net.NetComm.LMListeningPort); s.SendTo(sendBuffer, ep); commlog.TraceEvent(LogLevels.Verbose, 361, "UDP send: '" + LMLoggers.LognLM.FlattenChars(cmds) + "'"); } } catch (ObjectDisposedException ex) { commlog.TraceEvent(LogLevels.Error, 357, "LOST an instrument: " + ex.Message); } }
protected void CommandPrompt(Thread t = null) { // dev note: this Ctrl-C handler does not work when vshost is active in the dev env Console.CancelKeyPress += new ConsoleCancelEventHandler(LiveDAQCtrlCHandler); Console.TreatControlCAsInput = false; string line = ""; bool keepGoing = true; bool explicitPrompt = (t == null); Console.WriteLine(NC.App.AbbrName + "> command prompt " + NC.App.Config.VersionString + " (press CTRL+Z to exit):"); Console.WriteLine(); Console.Write(NC.App.AbbrName + "> "); NC.App.Opstate.SOH = NCC.OperatingState.Living; do { if ((t != null) && !Console.KeyAvailable && !explicitPrompt) { keepGoing = !t.Join(100); // when the batch op thread ends, we're out of the prompt loop, unless we asked for the prompt. "prompt with wait sync point approach" } else { line = Console.ReadLine(); if (line != null && (line.Length > 0)) { string tline = line.Trim(); LMMMLingo.OpDesc cmdt = new LMMMLingo.OpDesc(true); LMMMComm.CommandPromptMatchPrefix(tline, ref cmdt); if (LMMMLingo.Tokens.unknown == cmdt.tok) Console.WriteLine(NC.App.AbbrName + "> skipping '" + tline + "', \r\n enter 'help' for valid commands"); else { Thread pnt = LMMMComm.ProcessUserCommand(cmdt, tline, this, ref keepGoing); if (t == null) t = pnt; Console.Write(NC.App.AbbrName + ">"); } } else Console.Write(NC.App.AbbrName + "> "); } } while (line != null && keepGoing); // Issue: user quits operations via cmd prompt but system is still going waiting for HV or file or DAQ analysis to complete. // todo: Solution 1 (todo): prevent exit if waiting HVCalib or Assay operations to complete, pend woud occur in ProcessUserCommand above or around it via a polling loop // Solution 2 (below): to use the cancellation token here, provided that t is non-null & user typed quit to prompt, so need to stop LMMM and stop the pending thread represented by t, if possible. if (NC.App.Opstate.SOH == NCC.OperatingState.Living && t != null && line.ToLower().StartsWith("quit")) { CancelCurrentAction(); // todo: test this, might need to wait on it or kill it or something if (t.IsAlive) t.Abort(); // messy and likely to fail if sub-threads are pending } }
internal void CommandPromptMatchPrefix(string input, ref LMMMLingo.OpDesc op) { cmdprocessor.CommandPromptMatchPrefix(input, ref op); }