Exemple #1
0
        /// <summary>
        /// Initializes a new instance of <seealso cref="TimedCountItem"/> class.
        /// </summary>
        /// <param name="timedCount">The <seealso cref="TimedCount"/> object this item represents.</param>
        /// <param name="heightMultiplier">The ratio of height per error count.</param>
        /// <param name="timeLine">
        /// Show the time line under x-axis.
        /// The time line is not shown if the input value is null.
        /// </param>
        /// <param name="timeRangeLabel">
        /// A string that repensents the time range.
        /// The <paramref name="timedCount"/> is the sum of all errors in this time range.
        /// </param>
        public TimedCountItem(
            TimedCount timedCount,
            string timeLine,
            double heightMultiplier,
            string timeRangeLabel)
        {
            _timedCount = timedCount;
            // Example, $"{Count} times in {"1 day"}.{Environment.NewLine}Starting from {_timedCount.StartTime}.";
            string format = Count > 1 ? Resources.ErrorReportingBarchartTooltipPluralFormat : Resources.ErrorReportingBarchartTooltipFormat;

            ToolTipMessage = String.Format(format, Count, timeRangeLabel, Environment.NewLine, _timedCount.StartTime);
            TimeLine       = timeLine;
            BarHeight      = Count * heightMultiplier;
        }
        /// <summary>
        ///
        /// </summary>
        public static void MainLoop()
        {
            // verify needed paths exists
            if (!Directory.Exists(Constants.MESSAGE_FILES_DIR))
            {
                Directory.CreateDirectory(Constants.MESSAGE_FILES_DIR);
            }

            if (!Directory.Exists(Constants.LOG_FILE_DIR))
            {
                Directory.CreateDirectory(Constants.LOG_FILE_DIR);
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Config config =
                serializer.Deserialize <Config>(
                    File.ReadAllText(Constants.ConfigFile));

            SensorDriver sensor = new SensorDriver(config.PreselectorIp,
                                                   config.SensorHostName);

            TimedCount timer              = new TimedCount();
            Stopwatch  stopwatch          = new Stopwatch();
            bool       initialCalComplete = false;
            YfactorCal yFactorCal         = null;
            int        numOfMeasurements  = 0;

            // create and write initial location message
            string     locString  = File.ReadAllText(Constants.LocMessage);
            LocMessage locMessage =
                serializer.Deserialize <LocMessage>(locString);

            locMessage.loadMessageFields();
            Utilites.WriteMessageToFile(locMessage);

            while (true)
            {
                if (timer.elaspedTime() >= SECONDS_IN_HOUR ||
                    !initialCalComplete)
                {
                    // reset stopwatch to zero but do not start
                    stopwatch.Reset();
                    // read in parameters for calibration
                    SweepParams calParams;
                    string      jsonString =
                        File.ReadAllText(Constants.Spn43CalSweepParamsFile);
                    calParams =
                        serializer.Deserialize <SweepParams>(
                            jsonString);

                    SysMessage sysMessage = new SysMessage();
                    sysMessage.loadMessageFields();
                    sysMessage.version = config.Version;
                    sysMessage.calibration.byteOrder               = config.ByteOrder;
                    sysMessage.calibration.compression             = config.Compression;
                    sysMessage.calibration.dataType                = config.DataType;
                    sysMessage.calibration.numOfMeasurementsPerCal =
                        numOfMeasurements;
                    sysMessage.calibration.measurementType =
                        calParams.MeasurementType;
                    sysMessage.calibration.calsPerHour =
                        Constants.CALS_PER_HOUR;
                    sysMessage.calibration.compression =
                        Constants.COMPRESSION;
                    sysMessage.calibration.byteOrder =
                        Constants.BYTE_ORDER;
                    sysMessage.calibration.dataType =
                        Constants.DATA_TYPE;
                    sysMessage.calibration.measurementParameters.detector =
                        calParams.Detector;
                    sysMessage.calibration.measurementParameters.window =
                        calParams.Window;
                    sysMessage.calibration.measurementParameters.attenuation =
                        calParams.Attenuation;
                    sysMessage.calibration.measurementParameters.videoBw   = -1;
                    sysMessage.calibration.measurementParameters.dwellTime =
                        calParams.DwellTime;

                    // if yFactorCall == null and error occured while performing cal
                    sensor.PerformCal(calParams, sysMessage, out yFactorCal);
                    if (yFactorCal == null)
                    {
                        Utilites.LogMessage("Error performing calibration, " +
                                            "cal aborted");
                        // don't write message, start the loop again
                        continue;
                    }
                    Utilites.WriteMessageToFile(sysMessage);
                    initialCalComplete = true;
                    timer.reset();
                    numOfMeasurements = 0;
                }
                else
                {
                    // need to have completed cal to perform sweep
                    if (yFactorCal == null)
                    {
                        continue;
                    }

                    // get last time from stop watch
                    TimeSpan elapsedTime = stopwatch.Elapsed;
                    stopwatch.Restart();

                    SweepParams sweepParams;
                    string      jsonString =
                        File.ReadAllText(Constants.Spn43MeasurementFile);
                    sweepParams =
                        serializer.Deserialize <SweepParams>(
                            jsonString);

                    DataMessage dataMessage = new DataMessage();
                    dataMessage.loadMessageFields();
                    dataMessage.version   = config.Version;
                    dataMessage.byteOrder = config.ByteOrder;
                    dataMessage.dataType  = config.DataType;
                    dataMessage.comment   = config.Compression;
                    dataMessage.timeBetweenAcquisitions =
                        elapsedTime.TotalSeconds;
                    dataMessage.sysToDetect     = sweepParams.sys2Detect;
                    dataMessage.measurementType = sweepParams.MeasurementType;
                    dataMessage.compression     = Constants.COMPRESSION;
                    dataMessage.dataType        = Constants.DATA_TYPE;
                    dataMessage.byteOrder       = Constants.BYTE_ORDER;
                    dataMessage.measurementParameters.attenuation =
                        sweepParams.Attenuation;
                    dataMessage.measurementParameters.detector =
                        sweepParams.Detector;
                    dataMessage.measurementParameters.dwellTime =
                        sweepParams.DwellTime;
                    dataMessage.measurementParameters.window =
                        sweepParams.Window;

                    bool err = sensor.PerformMeasurement(sweepParams,
                                                         dataMessage, yFactorCal);
                    if (err)
                    {
                        throw new Exception("Error performing measurement");
                        // don't write message, start the loop again
                        continue;
                    }

                    numOfMeasurements++;
                    Utilites.WriteMessageToFile(dataMessage);
                }
            }
        }