public TalkToLMMMM(LMLoggers.LognLM logger) { cmdprocessor = new LMMMLingo(); // same for cfg copy commlog = logger; cmdprocessor.CommLog = logger; }
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; } } }
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) { cmdprocessor.CommandPromptMatchPrefix(input, ref op); }
bool DivertToEmulation(LMMMLingo.OpDesc op, Int32 arg, Int32 LMIndex) { if (emulator != null) { return emulator.DivertToEmulation(op, arg, LMIndex); } else { return false; } }
internal Thread ProcessUserCommand(LMMMLingo.OpDesc cmdt, string tline, LMDAQ.DAQControl control, ref bool keepgoing) { Thread t = null; // each prompt command might have a '=' followed by a single numeric argument e.g. cmd = 1 Int32 arg = 0; bool hasarg = ParsePrompt(tline, cmdt, ref arg); // if we didnt get an arg but one is required for the operation (5 or 6 commands, see the list) // then go get the config value from the config state and use it for arg if (cmdt.needsArg && !hasarg) // use the lambda to get the config value arg = cmdt.cfgInt32.Value; keepgoing = true; switch (cmdt.tok) { case LMMMLingo.Tokens.quit: // quit console prompt Console.WriteLine(NC.App.AbbrName + "> Be seeing you . . ."); keepgoing = false; break; case LMMMLingo.Tokens.lm: // set or show cur LM # try { CurrentLM = arg; Console.WriteLine(NC.App.AbbrName + ">LM= " + arg); } catch (Exception e) { commlog.TraceEvent(LogLevels.Error, 361, "Current instrument and measurement undefined or incomplete: " + e.Message); } break; case LMMMLingo.Tokens.help: //Console.Write(NC.App.AbbrName + ">"); foreach (string s in cmdprocessor.CmdPromptHelp) Console.WriteLine(s); break; case LMMMLingo.Tokens.config: // //Console.Write(NC.App.AbbrName + ">"); NCCConfig.Config.ShowCfg(NC.App.Config, NC.App.AppContext.Verbose() == System.Diagnostics.TraceEventType.Verbose); break; case LMMMLingo.Tokens.stop: // mostly for stopping an assay, might work for HV Calib too but must test it Console.Write(NC.App.AbbrName + ">"); control.StopCurrentAction(); // NEXT: see if this works for HV Calib break; case LMMMLingo.Tokens.assay: if (hasarg) { NC.App.Opstate.Measurement.MeasurementId.MeasOption = (AssaySelector.MeasurementOption)arg; Console.WriteLine(NC.App.AbbrName + ">assay type= " + arg + " (" + ((AssaySelector.MeasurementOption)arg).ToString() + ")"); } else { t = control.AssayOperation(); } break; case LMMMLingo.Tokens.hvcalib: t = control.HVCalibOperation(); break; case LMMMLingo.Tokens.broadcast: // UDP "NDAC Control" { NCC.NCCAction x = NC.App.Opstate.Action; NC.App.Opstate.Action = NCC.NCCAction.Discover; control.StartLMDAQServer(null); Console.WriteLine(NC.App.AbbrName + "> Broadcasting to LM instruments. . ."); PostLMMMCommand(cmdt.tok); Console.WriteLine(NC.App.AbbrName + "> Sent broadcast. Waiting for LM instruments to connect"); control.PrepSRDAQHandler(); control.ConnectSRInstruments(); NC.App.Opstate.Action = x; } break; default: try { FormatAndSendLMMMCommand(cmdt.tok, arg, CurrentLM); } catch (Exception e) { commlog.TraceEvent(LogLevels.Error, 360, "Current instrument and measurement undefined or incomplete: " + e.Message); } break; } return t; }
// TCP/IP synchronous send public bool FormatAndSendLMMMCommand(LMMMLingo.Tokens cmd, Int32 arg = 0, Int32 LMRankPosition = -1) { 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, arg, LMRankPosition); } else { try { string cmds = cmdprocessor.ComposeCommandStrings(cmd, arg); if (cmds.Length > 0) { SendToLM(cmds, LMRankPosition); } } catch (Exception e) { commlog.TraceEvent(LogLevels.Error, 354, "TCP send parse issue: " + e.Message); } } return res; }
// 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); } catch (SocketException se) { commlog.TraceEvent(LogLevels.Error, 358, "UDP send socket error: " + se.Message); } catch (Exception e) { commlog.TraceEvent(LogLevels.Error, 359, "UDP send cough: " + e.Message); } return res; }
// 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; }