Beispiel #1
0
 /// <summary>
 /// Initializes PeakScan object using receiver to check signal strengths for
 /// different frequencies.
 /// </summary>
 /// <param name="receiver">Receiver to use when checking frequencies.</param>
 public PeakScan(MicrowaveReceiver receiver)
 {
     rx = receiver;
     bgw.WorkerSupportsCancellation = true;
     bgw.DoWork             += new DoWorkEventHandler(bgw_DoWork);
     bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
 }
Beispiel #2
0
        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();
            }
        }