static void Main(string[] args) { try { Type implementation; string TCPAddress, ComPort; int TCPPort, baud; bool UsesTCP; SetupSession(args, out implementation, out TCPAddress, out TCPPort, out UsesTCP, out ComPort, out baud); using (MicrowaveReceiver rx = (MicrowaveReceiver)Activator.CreateInstance(implementation, TCPAddress, TCPPort, UsesTCP, ComPort, baud)) { if (rx.Connected) { Console.WriteLine("Ready. (type help? to see full command listing)"); Console.Write(" > "); string command = Console.ReadLine(); string[] set = command.Split(new char[] { ' ' }, 2); int stressRepeat = 1; int stressSuccess = 0; int stressFailure = 0; Stopwatch stopwatch = new Stopwatch(); UInt64 totalTime = 0; while (!set[0].Equals("quit")) { stressSuccess = 0; stressFailure = 0; totalTime = 0; for (int i = 0; i < stressRepeat; i++) { if ((set[0] == "stress") && (i > 0)) { break; } switch (set[0]) { case "help": case "help?": case "?": ShowHelp(); break; case "band?": Console.Out.WriteLine("Band: " + rx.GetBand()); break; case "freq?": try { stopwatch.Stop(); stopwatch.Reset(); stopwatch.Start(); MicrowaveTuning t = rx.GetTuning(); stopwatch.Stop(); Console.WriteLine("Current Tuning Information"); Console.WriteLine(" Frequency: " + t.Frequency + " Hz"); Console.WriteLine(" Bandwidth: " + t.ChannelBandwidth + " Hz"); Console.WriteLine(" Transport: " + t.TransportMode); Console.WriteLine(" Modulation: " + t.Modulation); Console.WriteLine(" FEC: " + t.ForwardErrorCorrection); Console.WriteLine(" Guard Int.: " + t.GuardInterval); Console.WriteLine(" Encryption: " + ((t.Encryption == null) ? "<null>" : (t.Encryption.Type + " " + t.Encryption.KeyLength + " bit"))); stressSuccess++; totalTime += (UInt64)stopwatch.ElapsedMilliseconds; } catch (Exception ex) { Console.WriteLine(ex.ToString()); stressFailure++; } break; case "str?": case "strength?": try { stopwatch.Stop(); stopwatch.Reset(); stopwatch.Start(); MicrowaveLinkQuality q = rx.GetLinkQuality(); stopwatch.Stop(); Console.WriteLine("Link Quality"); Console.WriteLine(" RCL: " + q.ReceivedCarrierLevel + " dB"); Console.WriteLine(" SNR: " + q.SignalToNoiseRatio + " dB"); Console.WriteLine(" Pre EC: " + q.BitErrorRatioPre); Console.WriteLine(" Post EC: " + q.BitErrorRatioPost); Console.WriteLine(" Tuner Lock: " + q.TunerLocked); Console.WriteLine(" Demod Lock: " + q.DemodulatorLocked); Console.WriteLine(" TS Lock: " + q.TransportStreamLocked); Console.WriteLine(" FEC Lock: " + q.FECLocked); Console.WriteLine("Decoder Lock: " + q.DecoderLocked); stressSuccess++; totalTime += (UInt64)stopwatch.ElapsedMilliseconds; } catch (Exception ex) { Console.WriteLine(ex.ToString()); stressFailure++; } break; //case "band": // MicrowaveReceiver.OperatingBand band = MicrowaveReceiver.OperatingBand.NotSet; // switch (set[1]) // { // case "S": band = MicrowaveReceiver.OperatingBand.S; // break; // case "L": band = MicrowaveReceiver.OperatingBand.L; // break; // case "C": band = MicrowaveReceiver.OperatingBand.C; // break; // case "X": band = MicrowaveReceiver.OperatingBand.X; // break; // default: band = MicrowaveReceiver.OperatingBand.NotSet; // break; // } // bool result = rx.SetBand(band); // Console.Out.WriteLine(result ? "Successful!" : "Failed!"); // break; case "freq": try { int freq = -1; if (int.TryParse(set[1], out freq)) { MicrowaveCapabilities caps = rx.GetCapabilities(); if (caps.AutoTuningRequirements != (int)MicrowaveTuning.Parameters.Frequency) { Console.WriteLine(" WARNING: not all AutoTune requirements met"); } rx.SetTuning(new MicrowaveTuning(caps.AutoTuning) { FrequencyMHz = (UInt64)freq }); Console.WriteLine("OK"); stressSuccess++; } } catch (Exception ex) { Console.WriteLine("Failure"); Console.WriteLine(ex.ToString()); stressFailure++; } break; case "test": Console.WriteLine("Test Connection: " + rx.TestConnection()); break; case "peak": Console.WriteLine("Not implemented"); break; case "stress": try { stressRepeat = int.Parse(set[1]); if (stressRepeat <= 1) { stressRepeat = 1; Console.WriteLine("Stress test mode OFF"); } else { Console.WriteLine("Commands will be executed " + stressRepeat + " times"); } } catch (Exception ex) { Console.WriteLine(ex); } break; case "stress?": if (stressRepeat <= 1) { Console.WriteLine("Stress test mode OFF"); } else { Console.WriteLine("Stress repeat = " + stressRepeat); } break; case "info?": Console.WriteLine(rx.GetDeviceInfo()); break; case "raw": Console.WriteLine(rx.RawCommand(set[1])); break; default: Console.WriteLine("-not a command-"); break; } } if (stressRepeat > 1) { Console.WriteLine(); Console.WriteLine(" -- Stress Test Results --"); Console.WriteLine(" " + stressSuccess + " / " + stressRepeat + " Succeeded"); Console.WriteLine(" " + stressFailure + " / " + stressRepeat + " Failed"); Console.WriteLine(" " + (UInt64)((double)totalTime / (double)stressSuccess) + " ms per successful operation (avg)"); } Console.Write(" > "); command = Console.ReadLine(); set = command.Split(new char[] { ' ' }); } } else { Console.Out.WriteLine("Not Connected"); Console.ReadLine(); } } } catch (Exception ex) { Console.WriteLine(""); Console.WriteLine("FAILTOWN"); Console.WriteLine(ex.ToString()); Console.WriteLine("press enter to quit"); Console.ReadLine(); } }
/// <summary> /// Scans from last start to last end using <see cref="RoughInterval"/>, /// putting rough results into PeakDictionary. /// </summary> /// <returns>List of start,end intervals of possible peaks.</returns> public List <UInt64> RoughScan() { List <UInt64> results = new List <UInt64>(); PeakDictionary = new Dictionary <MicrowaveTuning, MicrowaveLinkQuality>(); if (bgw.CancellationPending) { return(results); } _prototype.Frequency = _startFreq; rx.SetTuning(_prototype); UInt64 prePeakStart = _startFreq;//Set on strength below UInt64 currentPeak = 0; MicrowaveLinkQuality currentPeakStrength = new MicrowaveLinkQuality(0); for (UInt64 currentFreq = _startFreq; (currentFreq < _endFreq + RoughInterval) && !bgw.CancellationPending; currentFreq += RoughInterval) { if (currentFreq > _endFreq) { currentFreq = _endFreq; } _prototype.Frequency = currentFreq; try { rx.SetTuning(_prototype); } catch { continue; } MicrowaveLinkQuality strength = rx.GetLinkQuality(); Debug.WriteLine("Freq Changed: " + currentFreq + "\r\nStrength: " + strength); if (strength.ReceivedCarrierLevel > _minStrength) { if (strength.ReceivedCarrierLevel > currentPeakStrength.ReceivedCarrierLevel) //Save as highest peak so far { if (currentPeak > prePeakStart) //update to more accurate start of peak { prePeakStart = currentPeak; } currentPeak = currentFreq; currentPeakStrength = strength; } else if (strength.ReceivedCarrierLevel == currentPeakStrength.ReceivedCarrierLevel) { //Let the interval roll on } else//Above minimum, but lower than last peak //strength < currentPeakStrength { PeakDictionary.Add(new MicrowaveTuning(_prototype), strength); results.Add(prePeakStart); results.Add(currentFreq); Debug.WriteLine("Interval Added: " + prePeakStart + " to: " + currentFreq); //Reset prePeak to catch higher peaks within same set currentPeakStrength = strength; prePeakStart = currentFreq; } } else//Don't track peaks here, but make sure to start or end them if they are here { //If tracking peak, save it if (currentPeak > prePeakStart) { if (currentPeakStrength.ReceivedCarrierLevel > 0) { PeakDictionary.Add(new MicrowaveTuning(_prototype), new MicrowaveLinkQuality(currentPeakStrength)); } results.Add(prePeakStart); results.Add(currentFreq); Debug.WriteLine("Interval Added: " + prePeakStart + " to: " + currentFreq); } //Reset prePeak to catch any peaks currentPeakStrength.ReceivedCarrierLevel = 0; prePeakStart = currentFreq; } } //Complete interval if still tracking peak if (currentPeak > prePeakStart) { if (currentPeakStrength.ReceivedCarrierLevel > 0) { PeakDictionary.Add(new MicrowaveTuning(_prototype), new MicrowaveLinkQuality(currentPeakStrength)); } results.Add(prePeakStart); results.Add(_endFreq); Debug.WriteLine("Interval Added: " + prePeakStart + " to: " + _endFreq); } return(results); }