Merge branch 'RenameFrequencyToDelay' into 'master'

Replace UpdateFrequency with UpdateDelay

See merge request C3/C3!134
dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Pawel Kurowski 2019-09-13 13:30:55 +01:00
commit a44f9ba632
8 changed files with 54 additions and 54 deletions

View File

@ -25,7 +25,7 @@ namespace MWR::C3::Interfaces::Channels
/// Values used as default for channel jitter. 30 ms if unset. Current jitter value can be changed at runtime.
/// Set long delay otherwise slack rate limit will heavily impact channel.
constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 3500ms, s_MaxUpdateFrequency = 6500ms;
constexpr static std::chrono::milliseconds s_MinUpdateDelay = 3500ms, s_MaxUpdateDelay = 6500ms;
protected:
/// The inbound direction name of data

View File

@ -58,7 +58,7 @@ namespace MWR::C3
InterfaceFactory::InterfaceData<AbstractType> ret;
ret.m_Builder = [](ByteView bv) { return std::shared_ptr<AbstractType>{ new Iface{ bv } }; };
ret.m_ClousureConnectorHash = clousureConnectorHash;
ret.m_StartupJitter = std::pair(Iface::s_MinUpdateFrequency, Iface::s_MaxUpdateFrequency);
ret.m_StartupJitter = std::pair(Iface::s_MinUpdateDelay, Iface::s_MaxUpdateDelay);
#ifdef C3_IS_GATEWAY
ret.m_Name = GetInterfaceName<Iface>();
ret.m_Capability = EnsureDefaultCapability<Iface>::GetCapability<EnsureDefaultCapability<Iface>::HasCustomCapability>(); // Simpler syntax should be available, but I've encountered MSVC bug with SFINAE.
@ -96,15 +96,15 @@ namespace MWR::C3
class Channel : public Register<Iface, AbstractChannel>
{
public:
constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 30ms;
constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 30ms;
constexpr static std::chrono::milliseconds s_MinUpdateDelay = 30ms;
constexpr static std::chrono::milliseconds s_MaxUpdateDelay = 30ms;
/// Constructor setting default update frequency for channel
Channel()
{
static_assert(Iface::s_MinUpdateFrequency >= 30ms && Iface::s_MinUpdateFrequency <= Iface::s_MaxUpdateFrequency, "The frequency is set incorrectly");
m_MinUpdateFrequency = Iface::s_MinUpdateFrequency;
m_MaxUpdateFrequency = Iface::s_MaxUpdateFrequency;
static_assert(Iface::s_MinUpdateDelay >= 30ms && Iface::s_MinUpdateDelay <= Iface::s_MaxUpdateDelay, "The frequency is set incorrectly");
m_MinUpdateDelay = Iface::s_MinUpdateDelay;
m_MaxUpdateDelay = Iface::s_MaxUpdateDelay;
}
/// Callback that is periodically called for every Device to update itself.
@ -186,8 +186,8 @@ namespace MWR::C3
{
public:
// connector in fact does not need those values. They are here to satisfy template requirements.
constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 0ms;
constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 0ms;
constexpr static std::chrono::milliseconds s_MinUpdateDelay = 0ms;
constexpr static std::chrono::milliseconds s_MaxUpdateDelay = 0ms;
};
#else
/// Don't register the connectors in node builds
@ -204,14 +204,14 @@ namespace MWR::C3
class Peripheral : public Register<Iface, AbstractPeripheral, Hash::Fnv1aType<Closure>()>
{
public:
constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 30ms;
constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 30ms;
constexpr static std::chrono::milliseconds s_MinUpdateDelay = 30ms;
constexpr static std::chrono::milliseconds s_MaxUpdateDelay = 30ms;
Peripheral()
{
static_assert(Iface::s_MinUpdateFrequency >= 30ms && Iface::s_MinUpdateFrequency <= Iface::s_MaxUpdateFrequency, "The frequency is set incorrectly");
m_MinUpdateFrequency = Iface::s_MinUpdateFrequency;
m_MaxUpdateFrequency = Iface::s_MaxUpdateFrequency;
static_assert(Iface::s_MinUpdateDelay >= 30ms && Iface::s_MinUpdateDelay <= Iface::s_MaxUpdateDelay, "The frequency is set incorrectly");
m_MinUpdateDelay = Iface::s_MinUpdateDelay;
m_MaxUpdateDelay = Iface::s_MaxUpdateDelay;
}
};
#pragma warning( pop )

View File

@ -102,14 +102,14 @@ namespace MWR::C3
/// @param message information to log.
virtual void Log(LogMessage const& message) = 0;
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateFrequencyInMs != maxUpdateFrequencyInMs then update frequency is randomized in range between those values.
/// @param minUpdateFrequencyInMs minimum update frequency.
/// @param maxUpdateFrequencyInMs maximum update frequency.
virtual void SetUpdateFrequency(std::chrono::milliseconds minUpdateFrequencyInMs, std::chrono::milliseconds maxUpdateFrequencyInMs) = 0;
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateDelayInMs != maxUpdateDelayInMs then update frequency is randomized in range between those values.
/// @param minUpdateDelayInMs minimum update frequency.
/// @param maxUpdateDelayInMs maximum update frequency.
virtual void SetUpdateDelay(std::chrono::milliseconds minUpdateDelayInMs, std::chrono::milliseconds maxUpdateDelayInMs) = 0;
/// Sets time span between OnReceive() calls to a fixed value.
/// @param frequencyInMs frequency of OnReceive() calls.
virtual void SetUpdateFrequency(std::chrono::milliseconds frequencyInMs) = 0;
virtual void SetUpdateDelay(std::chrono::milliseconds frequencyInMs) = 0;
virtual void SetErrorStatus(std::string_view errorMessage) = 0;
virtual std::string GetErrorStatus() = 0;

View File

@ -22,32 +22,32 @@ void MWR::C3::AbstractChannel::OnReceive()
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MWR::C3::Device::SetUpdateFrequency(std::chrono::milliseconds minUpdateFrequencyInMs, std::chrono::milliseconds maxUpdateFrequencyInMs)
void MWR::C3::Device::SetUpdateDelay(std::chrono::milliseconds minUpdateDelayInMs, std::chrono::milliseconds maxUpdateDelayInMs)
{
// Sanity checks.
if (minUpdateFrequencyInMs > maxUpdateFrequencyInMs)
throw std::invalid_argument{ OBF("maxUpdateFrequency must be greater or equal to minUpdateFrequency.") };
if (minUpdateFrequencyInMs < 30ms)
throw std::invalid_argument{ OBF("minUpdateFrequency must be greater or equal to 30ms.") };
if (minUpdateDelayInMs > maxUpdateDelayInMs)
throw std::invalid_argument{ OBF("maxUpdateDelay must be greater or equal to minUpdateDelay.") };
if (minUpdateDelayInMs < 30ms)
throw std::invalid_argument{ OBF("minUpdateDelay must be greater or equal to 30ms.") };
std::lock_guard<std::mutex> guard(m_UpdateFrequencyMutex);
m_MinUpdateFrequency = minUpdateFrequencyInMs;
m_MaxUpdateFrequency = maxUpdateFrequencyInMs;
std::lock_guard<std::mutex> guard(m_UpdateDelayMutex);
m_MinUpdateDelay = minUpdateDelayInMs;
m_MaxUpdateDelay = maxUpdateDelayInMs;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MWR::C3::Device::SetUpdateFrequency(std::chrono::milliseconds frequencyInMs)
void MWR::C3::Device::SetUpdateDelay(std::chrono::milliseconds frequencyInMs)
{
std::lock_guard<std::mutex> guard(m_UpdateFrequencyMutex);
m_MinUpdateFrequency = frequencyInMs;
m_MaxUpdateFrequency = m_MinUpdateFrequency;
std::lock_guard<std::mutex> guard(m_UpdateDelayMutex);
m_MinUpdateDelay = frequencyInMs;
m_MaxUpdateDelay = m_MinUpdateDelay;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::chrono::milliseconds MWR::C3::Device::GetUpdateFrequency() const
std::chrono::milliseconds MWR::C3::Device::GetUpdateDelay() const
{
std::lock_guard<std::mutex> guard(m_UpdateFrequencyMutex);
return m_MinUpdateFrequency != m_MaxUpdateFrequency ? MWR::Utils::GenerateRandomValue(m_MinUpdateFrequency, m_MaxUpdateFrequency) : m_MinUpdateFrequency;
std::lock_guard<std::mutex> guard(m_UpdateDelayMutex);
return m_MinUpdateDelay != m_MaxUpdateDelay ? MWR::Utils::GenerateRandomValue(m_MinUpdateDelay, m_MaxUpdateDelay) : m_MinUpdateDelay;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -60,7 +60,7 @@ MWR::ByteVector MWR::C3::Device::OnRunCommand(ByteView command)
case static_cast<uint16_t>(MWR::C3::Core::Relay::Command::UpdateJitter) :
{
auto [minVal, maxVal] = command.Read<float, float>();
return SetUpdateFrequency(MWR::Utils::ToMilliseconds(minVal), MWR::Utils::ToMilliseconds(maxVal)), ByteVector{};
return SetUpdateDelay(MWR::Utils::ToMilliseconds(minVal), MWR::Utils::ToMilliseconds(maxVal)), ByteVector{};
}
default:
throw std::runtime_error(OBF("Device received an unknown command"));

View File

@ -56,17 +56,17 @@ namespace MWR::C3
/// @return true if Device is a Channel.
virtual bool IsChannel() const { return false; }
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateFrequencyInMs != maxUpdateFrequencyInMs then update frequency is randomized in range between those values.
/// @param minUpdateFrequencyInMs minimum update frequency.
/// @param maxUpdateFrequencyInMs maximum update frequency.
virtual void SetUpdateFrequency(std::chrono::milliseconds minUpdateFrequencyInMs, std::chrono::milliseconds maxUpdateFrequencyInMs);
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateDelayInMs != maxUpdateDelayInMs then update frequency is randomized in range between those values.
/// @param minUpdateDelayInMs minimum update frequency.
/// @param maxUpdateDelayInMs maximum update frequency.
virtual void SetUpdateDelay(std::chrono::milliseconds minUpdateDelayInMs, std::chrono::milliseconds maxUpdateDelayInMs);
/// Sets time span between OnReceive() calls to a fixed value.
/// @param frequencyInMs frequency of OnReceive() calls.
virtual void SetUpdateFrequency(std::chrono::milliseconds frequencyInMs);
virtual void SetUpdateDelay(std::chrono::milliseconds frequencyInMs);
/// Gets update frequency. If min and max variables have different values then generates random value in their range.
virtual std::chrono::milliseconds GetUpdateFrequency() const;
virtual std::chrono::milliseconds GetUpdateDelay() const;
/// Processes internal (C3 API) Command.
/// @param command a buffer containing whole command and it's parameters.
@ -77,8 +77,8 @@ namespace MWR::C3
/// Close device.
virtual void Close();
mutable std::mutex m_UpdateFrequencyMutex; ///< Mutex to synchronize changes in frequency update members.
std::chrono::milliseconds m_MinUpdateFrequency, m_MaxUpdateFrequency; ///< Receive loop moderator (if m_MaxUpdateFrequencyJitter != m_MinUpdateFrequency. then update frequency is randomized in range between those values).
mutable std::mutex m_UpdateDelayMutex; ///< Mutex to synchronize changes in frequency update members.
std::chrono::milliseconds m_MinUpdateDelay, m_MaxUpdateDelay; ///< Receive loop moderator (if m_MaxUpdateDelayJitter != m_MinUpdateDelay. then update frequency is randomized in range between those values).
};
/// An abstract structure representing all Channels.

View File

@ -128,7 +128,7 @@ void MWR::C3::Core::DeviceBridge::StartUpdatingInSeparateThread()
while (m_IsAlive)
try
{
std::this_thread::sleep_for(GetDevice()->GetUpdateFrequency());
std::this_thread::sleep_for(GetDevice()->GetUpdateDelay());
OnReceive();
}
catch (std::exception const& exception)
@ -149,15 +149,15 @@ void MWR::C3::Core::DeviceBridge::StartUpdatingInSeparateThread()
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MWR::C3::Core::DeviceBridge::SetUpdateFrequency(std::chrono::milliseconds minUpdateFrequencyInMs, std::chrono::milliseconds maxUpdateFrequencyInMs)
void MWR::C3::Core::DeviceBridge::SetUpdateDelay(std::chrono::milliseconds minUpdateDelayInMs, std::chrono::milliseconds maxUpdateDelayInMs)
{
GetDevice()->SetUpdateFrequency(minUpdateFrequencyInMs, maxUpdateFrequencyInMs);
GetDevice()->SetUpdateDelay(minUpdateDelayInMs, maxUpdateDelayInMs);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MWR::C3::Core::DeviceBridge::SetUpdateFrequency(std::chrono::milliseconds frequencyInMs)
void MWR::C3::Core::DeviceBridge::SetUpdateDelay(std::chrono::milliseconds frequencyInMs)
{
GetDevice()->SetUpdateFrequency(frequencyInMs);
GetDevice()->SetUpdateDelay(frequencyInMs);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -102,14 +102,14 @@ namespace MWR::C3::Core
/// Creates the receiving thread.
virtual void StartUpdatingInSeparateThread();
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateFrequencyInMs != maxUpdateFrequencyInMs then update frequency is randomized in range between those values.
/// @param minUpdateFrequencyInMs minimum update frequency.
/// @param maxUpdateFrequencyInMs maximum update frequency.
void SetUpdateFrequency(std::chrono::milliseconds minUpdateFrequencyInMs, std::chrono::milliseconds maxUpdateFrequencyInMs) override;
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateDelayInMs != maxUpdateDelayInMs then update frequency is randomized in range between those values.
/// @param minUpdateDelayInMs minimum update frequency.
/// @param maxUpdateDelayInMs maximum update frequency.
void SetUpdateDelay(std::chrono::milliseconds minUpdateDelayInMs, std::chrono::milliseconds maxUpdateDelayInMs) override;
/// Sets time span between OnReceive() calls to a fixed value.
/// @param frequencyInMs frequency of OnReceive() calls.
void SetUpdateFrequency(std::chrono::milliseconds frequencyInMs) override;
void SetUpdateDelay(std::chrono::milliseconds frequencyInMs) override;
/// "Parent" Relay getter.
/// @return Relay this Device is attached to.

View File

@ -239,7 +239,7 @@ void MWR::C3::Core::Profiler::RestoreFromSnapshot()
);
auto jitter = std::pair{ MWR::Utils::ToMilliseconds(channel["jitter"][0].get<float>()), MWR::Utils::ToMilliseconds(channel["jitter"][1].get<float>()) };
device->SetUpdateFrequency(jitter.first, jitter.second);
device->SetUpdateDelay(jitter.first, jitter.second);
auto profile = Get(); // we need to take profile each time, as it is also taken in CreateAndAttachDevice and that would lead to deadlock.
auto channelProfile = profile.m_Gateway.m_Channels.Find(did);
channelProfile->m_StartupArguments = channel["startupCommand"];