Exemple #1
0
        private void UpdateFrequency()
        {
            long          previousFrequency = 0;
            OperatingMode previousMode      = OperatingMode.Unknown;

            while (!Disposing && !IsDisposed)
            {
                try
                {
                    long          frequency = m_Radio.PrimaryFrequency;
                    OperatingMode mode      = m_Radio.PrimaryMode;

                    if (frequency != previousFrequency || mode != previousMode)
                    {
                        // Sanity check: re-read and make sure we get the same values!
                        long          checkFrequency = m_Radio.PrimaryFrequency;
                        OperatingMode checkMode      = m_Radio.PrimaryMode;

                        if (checkFrequency == frequency && checkMode == mode)
                        {
                            // Updated frequency or mode
                            CATModel model = new CATModel
                            {
                                Frequency = frequency,
                                Mode      = mode.ToString(),
                                Timestamp = DateTime.UtcNow,
                                Radio     = m_Radio.ToString()
                            };
                            m_API.PushCAT(model);

                            previousFrequency = frequency;
                            previousMode      = mode;
                        }
                    }

                    // Update the UI
                    Invoke(new MethodInvoker(() =>
                    {
                        m_Status.Text    = "Successfully updated at " + DateTime.Now.ToLongTimeString();
                        m_Frequency.Text = FormatFrequency(frequency);
                        m_Mode.Text      = mode.ToString();
                    }));
                }
                catch (Exception ex)
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        m_Status.Text = ex.Message;
                    }));
                }
                Thread.Sleep(1000);
            }
        }
Exemple #2
0
        public string Examine(Vector3 worldPos = default)
        {
            string stateDescription =
                powerState == PowerState.Off ? "unpowered."
                                        : IsTurnedOn == false ? "turned off."
                                        : OperatingMode == Mode.Siphoning && IsExpandedRange ? "manically siphoning!"
                                        : $"{OperatingMode.ToString().ToLower()}.";

            if (isWelded)
            {
                return(IsOperating
                                                ? $"It is tenaciously welded shut, but you can still hear the induction motor {stateDescription}"
                                                : $"It is teanciously welded shut and is dead silent. It seems to be {stateDescription}");
            }

            return($"It seems to be {stateDescription}");
        }
Exemple #3
0
 /// <summary/>
 public bool SetStaticPulseFrequency(OperatingMode mode, uint frequency)
 {
     bool status = false;
     string traceText = MethodBase.GetCurrentMethod().Name + "(" + mode.ToString() + ", " + frequency.ToString() + ")";
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.StaticPulseFreq, BooleanValue.True, ActionEnum.Set, (byte)mode);
         BitConverter.GetBytes(frequency).CopyTo(command.Payload, 0);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         string text = CommandReplyValidate(reply, CommandEnum.StaticPulseFreq, (byte)mode);
         if (/*fail?*/ text != string.Empty)
             throw new Exception(traceText + "; " + text);
         if (/*fail?*/ frequency != BitConverter.ToInt32(reply.Value.Payload, 0))
             throw new Exception(traceText + "; " + "frequency != " + frequency.ToString());
         status = true;
     }
     catch (Exception ex)
     {
         status = false;
         throw ex;
     }
     return status;
 }
Exemple #4
0
        /// <summary/>
        public bool SetOperatingMode(OperatingMode mode, ushort frequencyMinimum, ushort frequencyMaximum, bool confirm)
        {
            bool status = false;
            try
            {
                CommandDefinition.CommandFormat command = CommandMake(CommandEnum.OperatingMode, BooleanValue.True, ActionEnum.Set, (byte)mode);
                BitConverter.GetBytes(frequencyMinimum).CopyTo(command.Payload, 0);
                BitConverter.GetBytes(frequencyMaximum).CopyTo(command.Payload, 2);
                CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
                if (/*ignore results?*/ !confirm)
                    status = true;
                else
                {
                    string text = CommandReplyValidate(reply, CommandEnum.OperatingMode, (byte)mode);
                    if (/*fail?*/ !string.IsNullOrWhiteSpace(text))
                        throw new Exception(text);
                    if (/*fail?*/ frequencyMinimum != BitConverter.ToInt16(reply.Value.Payload, 0))
                        throw new Exception("frequencyMinimum != " + frequencyMinimum.ToString());
                    else if (/*fail?*/ frequencyMaximum != BitConverter.ToInt16(reply.Value.Payload, 2))
                        throw new Exception("frequencyMaximum != " + frequencyMaximum.ToString());
                    status = true;
                }
            }
            catch (Exception ex)
            {
                Debug.Assert(!status);
                if (/*OK to log?*/ LogPauseExpired)
                    try { Logger.LogError(Utilities.TextTidy(ex.ToString())); }
                    catch { }
            }
#if DEBUG
            try { Logger.LogInfo(MethodBase.GetCurrentMethod() + "(" + mode.ToString() + ", " + frequencyMinimum.ToString() + ", " + frequencyMaximum.ToString() + ", " + confirm.ToString() + ") returns " + status.ToString()); }
            catch { }
#endif
            return status;
        }
Exemple #5
0
        /// <summary/>
        public bool SetAdaptiveModeTriggerRatio(OperatingMode mode, float ratio, bool confirm)
        {
            bool status = false;
            try
            {
                CommandDefinition.CommandFormat command = CommandMake(CommandEnum.AdaptiveModeToTrigRatio, BooleanValue.True, ActionEnum.Set, (byte)mode);
                BitConverter.GetBytes(ratio).CopyTo(command.Payload, 0);
                CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
                if (/*ignore results?*/ !confirm)
                    status = true;
                else
                {
                    string text = CommandReplyValidate(reply, CommandEnum.AdaptiveModeToTrigRatio, (byte)mode);
                    if (/*fail?*/ text != string.Empty)
                        throw new Exception(text);
                    if (/*fail?*/ ratio != BitConverter.ToSingle(reply.Value.Payload, 0))
                        throw new Exception("ratio != " + ratio.ToString()); //set result to false
                    status = true;
                }
            }
            catch (Exception ex)
            {
                status = false;
                if (/*OK to log?*/ LogPauseExpired)
                    try { Logger.LogError(Utilities.TextTidy(ex.ToString())); }
                    catch { }
            }
#if DEBUG
            try { Logger.LogInfo(MethodBase.GetCurrentMethod() + "(" + mode.ToString() + ", " + ratio.ToString() + ", " + confirm.ToString() + ") returns " + status.ToString()); }
            catch { }
#endif
            return status;
        }
Exemple #6
0
        /// <summary>
        /// Get status of the current calibration operation.
        /// </summary>
        /// <param name="position">The position of the sensor to check.</param>
        /// <returns>The cal status of the sensor.
        /// true - sensor is calibrating;
        /// false - sensor is not calibrating;
        /// null - InstrumentAborted</returns>
        public override bool?IsSensorCalibrating(int pos)
        {
            bool?isCalibrating = false;

            // instruments dockable on MX4 docking stations have been losing contact with the
            // charging pins on the DS  which causes the instrument to leave the Calibrating mode.
            // The instrument  likely goes to Charging mode when this happens.  However, we need to read the
            // instrument operating mode before the sensor mode to prevent timing issues.
            // These can occur when the sensor finishes a normal calibration and both the
            // sensor and the instrument transition back to Running mode.
            OperatingMode opMode = Driver.getOperatingMode();

            // If the sensor reports it is still calibrating, verify that the instrument
            // is on the same page.
            if (Driver.isSensorCalibrating(pos))
            {
                if (opMode == OperatingMode.Calibrating)
                {
                    isCalibrating = true;
                }
                else
                {
                    Log.Debug("******************************************");
                    Log.Debug(string.Format("* INSTRUMENT IS NOT IN CALIBRATING MODE! *  Instrument is in \"{0}\" mode.", opMode.ToString()));
                    Log.Debug("******************************************");

                    // return null to indicate that the instrument has reset
                    isCalibrating = null;
                }
            }

            return(isCalibrating);
        }
Exemple #7
0
 /// <summary/>
 public bool SetStaticPulseFrequency(OperatingMode mode, uint frequency, bool confirm)
 {
     bool status = false;
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.StaticPulseFreq, BooleanValue.True, ActionEnum.Set, (byte)mode);
         BitConverter.GetBytes(frequency).CopyTo(command.Payload, 0);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         if (/*ignore results?*/ !confirm)
             status = true;
         else
         {
             string text = CommandReplyValidate(reply, CommandEnum.StaticPulseFreq, (byte)mode);
             if (/*fail?*/ text != string.Empty)
                 throw new Exception(text);
             if (/*fail?*/ frequency != BitConverter.ToInt32(reply.Value.Payload, 0))
                 throw new Exception("frequency != " + frequency.ToString()); //set result to false
             status = true;
         }
     }
     catch (Exception ex)
     {
         Debug.Assert(!status);
         status = false;
         throw ex;
     }
     try { Logger.LogInfo(MethodBase.GetCurrentMethod() + "(" + mode.ToString() + ", " + confirm.ToString() + ") returns " + status.ToString()); }
     catch { }
     return status;
 }