示例#1
0
 public void SendAdaptiveSpeedFeedbackConfigResponse(AdaptiveSpeedFeedbackConfig mode, float frequency)
 {
     //everton byte[] f = Reflection.Serialize(freq, typeof(float));
     byte[] data = BitConverter.GetBytes(frequency);
     CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.True, ActionEnum.Response, (byte)mode, data);
     ReplySend(packet);
 }
示例#2
0
 public bool SetAdaptiveSpeedFeedbackConfiguration(AdaptiveSpeedFeedbackConfig config, float freq, bool confirm)
 {
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
     {
         return(false);
     }
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.True, ActionEnum.Set, (byte)config);
     BitConverter.GetBytes(freq).CopyTo(command.Payload, 0);
     CommandDefinition.CommandFormat?response = SendCommand(command, confirm);
     if (confirm && (!ConfirmSetActionResponse(response, CommandEnum.AdaptiveSpeedFeedbackConfig, (byte)config) ||
                     freq != BitConverter.ToSingle(response.Value.Payload, 0)))
     {
         return(false);
     }
     return(true);
 }
示例#3
0
 /// <summary/>
 public bool GetAdaptiveSpeedFeedbackConfiguration(out AdaptiveSpeedFeedbackConfig? configuration, out float? frequency, bool confirm)
 {
     bool status = false;
     try
     {
         CommandDefinition.CommandFormat command = CommandMake(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.False, ActionEnum.Get, 0);
         CommandDefinition.CommandFormat? reply = CommandSend(command, /*reply expected*/ true);
         string text = CommandReplyValidate(reply, CommandEnum.AdaptiveSpeedFeedbackConfig);
         if (/*fail?*/ !string.IsNullOrWhiteSpace(text))
             throw new Exception(text);
         configuration = (AdaptiveSpeedFeedbackConfig)OperatingMode.ToObject(typeof(AdaptiveSpeedFeedbackConfig), reply.Value.Action.SubAction);
         frequency = BitConverter.ToSingle(reply.Value.Payload, 0);
         status = true;
     }
     catch (Exception ex)
     {
         configuration = null;
         frequency = null;
         status = false;
         if (/*OK to log?*/ LogPauseExpired)
             try { Logger.LogError(Utilities.TextTidy(ex.ToString())); }
             catch { }
     }
     return status;
 }
示例#4
0
        /// <summary/>
        public bool SetAdaptiveSpeedFeedbackConfiguration(AdaptiveSpeedFeedbackConfig configuration, float frequency, bool confirm)
        {
            bool status = false;
            try
            {
                CommandDefinition.CommandFormat command = CommandMake(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.True, ActionEnum.Set, (byte)configuration);
                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.AdaptiveSpeedFeedbackConfig, (byte)configuration);
                    if (/*fail?*/ text != string.Empty)
                        throw new Exception(text);
                    if (/*fail?*/ frequency != BitConverter.ToSingle(reply.Value.Payload, 0))
                        throw new Exception("frequency != " + frequency.ToString());
                    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() + "(" + configuration.ToString() + ", " + frequency.ToString() + ", " + confirm.ToString() + ") returns " + status.ToString()); }
            catch { }
#endif
            return status;
        }
示例#5
0
        static void hostAccess_ProcessCommandEvent(CommandDefinition.CommandFormat command)
        {
            if (command.CommandAck.Command == CommandEnum.ScanMode)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    currentEnergyMode = (ScanEnergyMode)command.Action.SubAction;

                    PWMOutputConfig pwmConfig = (PWMOutputConfig)pc.GetPWMRunStatus();

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                    {
                        pc.PWMOutputDisable();
                    }

                    if (currentEnergyMode == ScanEnergyMode.Dual)
                    {
                        Reset.Write(true);
                        Preset.Write(true);
                    }
                    else if (currentEnergyMode == ScanEnergyMode.High)
                    {
                        Reset.Write(true);
                        Preset.Write(false);
                    }
                    else
                    {
                        Reset.Write(false);
                        Preset.Write(true);
                    }

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                    {
                        pc.PWMOutputEnable();
                    }
                }

                hostAccess.SendScanModeResponse(currentEnergyMode);
            }
            else if (command.CommandAck.Command == CommandEnum.StaticPulseFreq)
            {
                OperatingMode mode = (OperatingMode)command.Action.SubAction;
                int           freq = BitConverter.ToInt32(command.Payload, 0);;

                if (command.Action.Action == ActionEnum.Set)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                    {
                        StaticPulseFreq[0] = freq;
                    }
                    else if (mode == OperatingMode.NonAdpativePortal)
                    {
                        StaticPulseFreq[1] = freq;
                    }

                    if (currentOperatingMode == mode)
                    {
                        currentStaticPulseFreq = freq;
                        pc.UpdatePWMFrequency(freq);
                    }

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                    {
                        freq = StaticPulseFreq[0];
                    }
                    else if (mode == OperatingMode.NonAdpativePortal)
                    {
                        freq = StaticPulseFreq[1];
                    }

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.PulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if (currentPulseWidth != (PulseWidth)command.Action.SubAction)
                    {
                        currentPulseWidth = (PulseWidth)command.Action.SubAction;
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                    }
                }

                hostAccess.SendPulseWidthResponse(currentPulseWidth);
            }
            else if (command.CommandAck.Command == CommandEnum.ConfigPulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    int index = command.Action.SubAction - 1;
                    PulseWidthsDutyCycle[index] = BitConverter.ToSingle(command.Payload, 0);

                    if (currentPulseWidth == (PulseWidth)command.Action.SubAction)
                    {
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[index]);
                    }
                }

                PulseWidth width = (PulseWidth)command.Action.SubAction;
                hostAccess.SendPulseWidthConfigResponse(width, PulseWidthsDutyCycle[(byte)width - 1]);
            }
            else if (command.CommandAck.Command == CommandEnum.OperatingMode)
            {
                short minFreq, maxFreq;

                if (command.Action.Action == ActionEnum.Set)
                {
                    minFreq = (short)BitConverter.ToInt16(command.Payload, 0);
                    maxFreq = (short)BitConverter.ToInt16(command.Payload, 2);
                    currentOperatingMode = (OperatingMode)command.Action.SubAction;

                    if ((currentOperatingMode == OperatingMode.NonAdaptiveMobile) || (currentOperatingMode == OperatingMode.NonAdpativePortal))
                    {
                        if (currentOperatingMode == OperatingMode.NonAdaptiveMobile)
                        {
                            currentStaticPulseFreq = StaticPulseFreq[0];
                        }
                        else
                        {
                            currentStaticPulseFreq = StaticPulseFreq[1];
                        }

                        pc.SetOperatingMode(currentOperatingMode);
                        pc.UpdatePWMFrequency(currentStaticPulseFreq);
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                        pc.PWMOutputEnable();
                    }
                    else if ((currentOperatingMode == OperatingMode.AdaptiveMobile) || (currentOperatingMode == OperatingMode.AdaptivePortal))
                    {
                        pc.SetFrequencyRange(currentOperatingMode, minFreq, maxFreq);
                        pc.SetOperatingMode(currentOperatingMode);
                        pc.PWMOutputEnable();
                    }

                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetFrequencyRange(currentOperatingMode, out minFreq, out maxFreq);
                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveModeToTrigRatio)
            {
                float         ratio;
                OperatingMode mode = (OperatingMode)command.Action.SubAction;

                if (command.Action.Action == ActionEnum.Set)
                {
                    ratio = BitConverter.ToSingle(command.Payload, 0);

                    pc.SetInputToOutputRatio(mode, ratio);

                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetInputToOutputRatio(mode, out ratio);
                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveSpeedFeedbackConfig)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    adaptiveSpeedMsgFreq = BitConverter.ToSingle(command.Payload, 0);
                    speedMsgMode         = (AdaptiveSpeedFeedbackConfig)command.Action.SubAction;

                    if ((speedMsgMode == AdaptiveSpeedFeedbackConfig.EnabledWithFreq) && (adaptiveSpeedMsgFreq > 0.0f))
                    {
                        int period = (int)(1000.0f / adaptiveSpeedMsgFreq);
                        adaptiveSpeedMsgTimer.Change(period, period);
                    }
                    else
                    {
                        adaptiveSpeedMsgTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    }
                }

                hostAccess.SendAdaptiveSpeedFeedbackConfigResponse(speedMsgMode, adaptiveSpeedMsgFreq);
            }
            else if (command.CommandAck.Command == CommandEnum.PWMOutput)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if ((PWMOutputConfig)command.Action.SubAction == PWMOutputConfig.OutputEnabled)
                    {
                        pc.PWMOutputEnable();
                    }
                    else
                    {
                        pc.PWMOutputDisable();
                    }

                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)command.Action.SubAction);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)pc.GetPWMRunStatus());
                }
            }
            else if (command.CommandAck.Command == CommandEnum.ResetBoard)
            {
                ResetBoard();
            }
        }
示例#6
0
 public void SendAdaptiveSpeedFeedbackConfigResponse(AdaptiveSpeedFeedbackConfig mode, float frequency)
 {
     //everton byte[] f = Reflection.Serialize(freq, typeof(float));
     byte[] data = BitConverter.GetBytes(frequency);
     CommandDefinition.CommandFormat packet = ReplyCreate(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.True, ActionEnum.Response, (byte)mode, data);
     ReplySend(packet);
 }
示例#7
0
 public bool GetAdaptiveSpeedFeedbackConfiguration(out AdaptiveSpeedFeedbackConfig? config, out float? freq, bool confirm)
 {
     config = null; freq = null;
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
         return false;
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.False, ActionEnum.Get, 0);
     CommandDefinition.CommandFormat? response = SendCommand(command, confirm);
     if (response != null && response.Value.CommandAck.Command == CommandEnum.AdaptiveSpeedFeedbackConfig && response.Value.Action.Action == ActionEnum.Response)
     {
         config = (AdaptiveSpeedFeedbackConfig)OperatingMode.ToObject(typeof(AdaptiveSpeedFeedbackConfig), response.Value.Action.SubAction);
         freq = BitConverter.ToSingle(response.Value.Payload, 0);
         return true;
     }
     else
         return false;
 }
示例#8
0
 public bool SetAdaptiveSpeedFeedbackConfiguration(AdaptiveSpeedFeedbackConfig config, float freq, bool confirm)
 {
     if (/*terminated?*/ _cancelEvent.WaitOne(0))
         return false;
     CommandDefinition.CommandFormat command = ConstructCommand(CommandEnum.AdaptiveSpeedFeedbackConfig, BooleanValue.True, ActionEnum.Set, (byte)config);
     BitConverter.GetBytes(freq).CopyTo(command.Payload, 0);
     CommandDefinition.CommandFormat? response = SendCommand(command, confirm);
     if (confirm && (!ConfirmSetActionResponse(response, CommandEnum.AdaptiveSpeedFeedbackConfig, (byte)config) ||
         freq != BitConverter.ToSingle(response.Value.Payload, 0)))
         return false;
     return true;
 }
示例#9
0
文件: Program.cs 项目: BdGL3/CXPortal
        static void hostAccess_ProcessCommandEvent(CommandDefinition.CommandFormat command)
        {
            if (command.CommandAck.Command == CommandEnum.ScanMode)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    currentEnergyMode = (ScanEnergyMode)command.Action.SubAction;

                    PWMOutputConfig pwmConfig = (PWMOutputConfig)pc.GetPWMRunStatus();

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                        pc.PWMOutputDisable();

                    if (currentEnergyMode == ScanEnergyMode.Dual)
                    {
                        Reset.Write(true);
                        Preset.Write(true);
                    }
                    else if (currentEnergyMode == ScanEnergyMode.High)
                    {
                        Reset.Write(true);
                        Preset.Write(false);
                    }
                    else
                    {
                        Reset.Write(false);
                        Preset.Write(true);
                    }

                    if (pwmConfig == PWMOutputConfig.OutputEnabled)
                        pc.PWMOutputEnable();
                }

                hostAccess.SendScanModeResponse(currentEnergyMode);
            }
            else if (command.CommandAck.Command == CommandEnum.StaticPulseFreq)
            {
                OperatingMode mode = (OperatingMode)command.Action.SubAction;
                int freq = BitConverter.ToInt32(command.Payload, 0); ;

                if (command.Action.Action == ActionEnum.Set)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                        StaticPulseFreq[0] = freq;
                    else if (mode == OperatingMode.NonAdpativePortal)
                        StaticPulseFreq[1] = freq;

                    if (currentOperatingMode == mode)
                    {
                        currentStaticPulseFreq = freq;
                        pc.UpdatePWMFrequency(freq);
                    }

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    if (mode == OperatingMode.NonAdaptiveMobile)
                        freq = StaticPulseFreq[0];
                    else if (mode == OperatingMode.NonAdpativePortal)
                        freq = StaticPulseFreq[1];

                    hostAccess.SendStaticPulseFreqResponse(mode, freq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.PulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if (currentPulseWidth != (PulseWidth)command.Action.SubAction)
                    {
                        currentPulseWidth = (PulseWidth)command.Action.SubAction;
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                    }
                }

                hostAccess.SendPulseWidthResponse(currentPulseWidth);
            }
            else if (command.CommandAck.Command == CommandEnum.ConfigPulseWidth)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    int index = command.Action.SubAction - 1;
                    PulseWidthsDutyCycle[index] = BitConverter.ToSingle(command.Payload, 0);

                    if (currentPulseWidth == (PulseWidth)command.Action.SubAction)
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[index]);
                }

                PulseWidth width = (PulseWidth)command.Action.SubAction;
                hostAccess.SendPulseWidthConfigResponse(width, PulseWidthsDutyCycle[(byte)width - 1]);
            }
            else if (command.CommandAck.Command == CommandEnum.OperatingMode)
            {
                short minFreq, maxFreq;

                if (command.Action.Action == ActionEnum.Set)
                {
                    minFreq = (short)BitConverter.ToInt16(command.Payload, 0);
                    maxFreq = (short)BitConverter.ToInt16(command.Payload, 2);
                    currentOperatingMode = (OperatingMode)command.Action.SubAction;

                    if ((currentOperatingMode == OperatingMode.NonAdaptiveMobile) || (currentOperatingMode == OperatingMode.NonAdpativePortal))
                    {
                        if (currentOperatingMode == OperatingMode.NonAdaptiveMobile)
                            currentStaticPulseFreq = StaticPulseFreq[0];
                        else
                            currentStaticPulseFreq = StaticPulseFreq[1];

                        pc.SetOperatingMode(currentOperatingMode);
                        pc.UpdatePWMFrequency(currentStaticPulseFreq);
                        pc.UpdatePWMPulseWidth(PulseWidthsDutyCycle[(int)currentPulseWidth - 1]);
                        pc.PWMOutputEnable();
                    }
                    else if ((currentOperatingMode == OperatingMode.AdaptiveMobile) || (currentOperatingMode == OperatingMode.AdaptivePortal))
                    {
                        pc.SetFrequencyRange(currentOperatingMode, minFreq, maxFreq);
                        pc.SetOperatingMode(currentOperatingMode);
                        pc.PWMOutputEnable();
                    }

                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetFrequencyRange(currentOperatingMode, out minFreq, out maxFreq);
                    hostAccess.SendOperatingModeResponse(currentOperatingMode, minFreq, maxFreq);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveModeToTrigRatio)
            {
                float ratio;
                OperatingMode mode = (OperatingMode)command.Action.SubAction;

                if (command.Action.Action == ActionEnum.Set)
                {
                    ratio = BitConverter.ToSingle(command.Payload, 0);

                    pc.SetInputToOutputRatio(mode, ratio);

                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    pc.GetInputToOutputRatio(mode, out ratio);
                    hostAccess.SendAdaptiveModeToTrigRatioResponse(mode, ratio);
                }
            }
            else if (command.CommandAck.Command == CommandEnum.AdaptiveSpeedFeedbackConfig)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    adaptiveSpeedMsgFreq = BitConverter.ToSingle(command.Payload, 0);
                    speedMsgMode = (AdaptiveSpeedFeedbackConfig)command.Action.SubAction;

                    if ((speedMsgMode == AdaptiveSpeedFeedbackConfig.EnabledWithFreq) && (adaptiveSpeedMsgFreq > 0.0f))
                    {
                        int period = (int)(1000.0f / adaptiveSpeedMsgFreq);
                        adaptiveSpeedMsgTimer.Change(period, period);
                    }
                    else
                        adaptiveSpeedMsgTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                hostAccess.SendAdaptiveSpeedFeedbackConfigResponse(speedMsgMode, adaptiveSpeedMsgFreq);
            }
            else if (command.CommandAck.Command == CommandEnum.PWMOutput)
            {
                if (command.Action.Action == ActionEnum.Set)
                {
                    if ((PWMOutputConfig)command.Action.SubAction == PWMOutputConfig.OutputEnabled)
                        pc.PWMOutputEnable();
                    else
                        pc.PWMOutputDisable();

                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)command.Action.SubAction);
                }
                else if (command.Action.Action == ActionEnum.Get)
                {
                    hostAccess.SendPWMOutputStatus((PWMOutputConfig)pc.GetPWMRunStatus());
                }
            }
            else if (command.CommandAck.Command == CommandEnum.ResetBoard)
                ResetBoard();
        }