示例#1
0
        /// <summary>
        /// Create simulator from command line options.
        /// </summary>
        private static QboxSimulator CreateSimulator(string inSerial, QboxSimulatorOptions inOptions)
        {
            var sim = new QboxSimulator(inSerial)
            {
                Host                    = inOptions.QserverBaseUrl,
                QboxDeviceName          = "666",
                QboxIsDuo               = inOptions.IsDuo,
                SendClientStatus        = inOptions.SendClientStatus,
                ProtocolVersion         = inOptions.ProtocolVersion,
                LoadPersistedSequenceNr = !inOptions.ResetSequenceNr,
                RunContinuously         = !inOptions.OnlySendOnce,
                // Add 2 seconds to give the simulator time to start up, it will try to start at exactly the given timestamp.
                StartTime = DateTime.Now.AddSeconds(2)
            };

            if (inOptions.NoDelay)
            {
                sim.MessageInterval = new TimeSpan(0, 0, 1);
            }

            if (inOptions.MeterType == MeterTypeName.Generic && !sim.RunContinuously)
            {
                throw new InvalidConstraintException("generic meter can only be used in continuous mode");
            }

            if (inOptions.MeterType == MeterTypeName.Generic)
            {
                sim.QboxState = QboxState.Waiting;
            }

            var specs = PatternParser.ParseSpecList(inOptions.Pattern);

            // To make sure that simulators that run once every minute can progress in the pattern,
            // we have to fix the period start.
            if (inOptions.OnlySendOnce)
            {
                specs.ForEach(s => s.PeriodStart = new DateTime(2017, 1, 1));
            }
            sim.SetMeter(Meter.GetMeterType(inOptions.MeterType), specs);

            return(sim);
        }