Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/ble/ctrlm_ble_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,33 @@ void ctrlm_obj_network_ble_t::power_state_change(gboolean waking_up) {
}

void ctrlm_obj_network_ble_t::rfc_retrieved_handler(const ctrlm_rfc_attr_t &attr) {
// TODO - No RFC parameters as of now
XLOGD_INFO("process BLE RFC values");

// Process options object
bool disable_voice = false;
if(attr.get_rfc_value(JSON_OBJ_NAME_NETWORK_BLE_OPTIONS JSON_PATH_SEPERATOR JSON_BOOL_NAME_NETWORK_BLE_OPTIONS_DISABLE_VOICE, disable_voice)) {
voice_disabled_ = disable_voice;
XLOGD_INFO("BLE voice support is %s by config", voice_disabled_ ? "disabled" : "enabled");
}

auto config = getConfigSettings();
if (config == nullptr) {
XLOGD_ERROR("config not available");
return;
}

json_t *obj = nullptr;
if(!attr.get_rfc_json_value(&obj)) {
XLOGD_ERROR("failed to get RFC json object");
return;
}

// Update config settings from RFC json object
bool updated = config->updateFromJson(obj);
if(!updated) {
XLOGD_WARN("no BLE config updates found in RFC");
}
Comment thread
dwolaver marked this conversation as resolved.
json_decref(obj);
}

std::vector<ctrlm_obj_controller_t *> ctrlm_obj_network_ble_t::get_controller_obj_list() const {
Expand Down
28 changes: 15 additions & 13 deletions src/ble/hal/blercu/blercupairingstatemachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ BleRcuPairingStateMachine::BleRcuPairingStateMachine(const shared_ptr<const Conf
, m_isAutoPairing(false)
, m_pairingCode(-1)
, m_pairingMacHash(-1)
, m_config(config)
, m_discoveryTimeout(config->discoveryTimeout())
, m_discoveryTimeoutDefault(config->discoveryTimeout())
, m_pairingTimeout(config->pairingTimeout())
, m_setupTimeout(config->setupTimeout())
, m_unpairingTimeout(config->upairingTimeout())
, m_pairingAttempts(0)
, m_pairingSuccesses(0)
, m_pairingSucceeded(false)
Expand Down Expand Up @@ -287,6 +284,7 @@ void BleRcuPairingStateMachine::startAutoWithTimeout(int timeoutMs)
m_pairingAttempts++;
m_pairingSucceeded = false;
XLOGD_INFO("Started auto pairing procedure");
XLOGD_DEBUG("timeouts - discovery <%d ms> pairing <%d ms> setup <%d ms> unpairing <%d ms>", m_discoveryTimeout, m_config->pairingTimeout(), m_config->setupTimeout(), m_config->upairingTimeout());
}


Expand All @@ -304,7 +302,7 @@ void BleRcuPairingStateMachine::startWithCode(uint8_t pairingCode)
return;
}

m_discoveryTimeout = m_discoveryTimeoutDefault;
m_discoveryTimeout = m_config->discoveryTimeout(); // use the default discovery timeout for this pairing method
m_isAutoPairing = false;

// clear the target device
Expand Down Expand Up @@ -345,6 +343,7 @@ void BleRcuPairingStateMachine::startWithCode(uint8_t pairingCode)
m_pairingAttempts++;
m_pairingSucceeded = false;
XLOGD_INFO("started pairing, searching for device with prefix code %03d or MAC hash 0x%02X", m_pairingCode, m_pairingMacHash);
XLOGD_DEBUG("timeouts - discovery <%d ms> pairing <%d ms> setup <%d ms> unpairing <%d ms>", m_discoveryTimeout, m_config->pairingTimeout(), m_config->setupTimeout(), m_config->upairingTimeout());
}

// -----------------------------------------------------------------------------
Expand All @@ -360,6 +359,8 @@ void BleRcuPairingStateMachine::startWithMacList(const std::vector<BleAddress> &
return;
}

m_discoveryTimeout = m_config->discoveryTimeout(); // use the default discovery timeout for this pairing method
Comment thread
egalla204 marked this conversation as resolved.

// clear the target device
m_targetAddress.clear();

Expand Down Expand Up @@ -389,7 +390,7 @@ void BleRcuPairingStateMachine::startWithMacList(const std::vector<BleAddress> &
for (const auto &address : macList) {
XLOGD_INFO("<%s>", address.toString().c_str());
}

XLOGD_DEBUG("timeouts - discovery <%d ms> pairing <%d ms> setup <%d ms> unpairing <%d ms>", m_discoveryTimeout, m_config->pairingTimeout(), m_config->setupTimeout(), m_config->upairingTimeout());
}


Expand Down Expand Up @@ -511,9 +512,9 @@ void BleRcuPairingStateMachine::onStateTransition(int oldState, int newState)
}
} else if (newState == UnpairingState) {
if (oldState == EnablePairableState || oldState == PairingState) {
XLOGD_AUTOMATION_WARN("timed-out in pairing phase (rcu device didn't pair within %dms)", m_pairingTimeout);
XLOGD_AUTOMATION_WARN("timed-out in pairing phase (rcu device didn't pair within %dms)", m_config->pairingTimeout());
} else if (oldState == SetupState) {
XLOGD_AUTOMATION_WARN("timed-out in setup phase (rcu didn't response to all requests within %dms)", m_setupTimeout);
XLOGD_AUTOMATION_WARN("timed-out in setup phase (rcu didn't response to all requests within %dms)", m_config->setupTimeout());
Comment thread
dwolaver marked this conversation as resolved.
Comment thread
dwolaver marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -643,7 +644,7 @@ void BleRcuPairingStateMachine::onExitedDiscoverySuperState()
void BleRcuPairingStateMachine::onEnteredStoppingDiscoveryState()
{
// start the pairing timeout timer
m_stateMachine.postDelayedEvent(PairingTimeoutEvent, m_pairingTimeout);
m_stateMachine.postDelayedEvent(PairingTimeoutEvent, m_config->pairingTimeout());

Comment thread
dwolaver marked this conversation as resolved.
// if we've got to this state it means we have a target device
if (m_targetAddress.isNull()) {
Expand Down Expand Up @@ -708,7 +709,7 @@ void BleRcuPairingStateMachine::onEnteredEnablePairableState()
// in pairable mode because we don't know if the previous timeout is long enough for our purposes.
// The timeout is set to 5 seconds past the overall time we've given the state machine
// to pair with the rcu.
m_adapter->enablePairable(m_pairingTimeout + 5000);
m_adapter->enablePairable(m_config->pairingTimeout() + 5000);

if (m_adapter->isPairable()) {
// is already pairable so just post the 'enabled' event
Expand Down Expand Up @@ -748,8 +749,9 @@ void BleRcuPairingStateMachine::onEnteredPairingState()
void BleRcuPairingStateMachine::onEnteredSetupState()
{
// start the setup timeout timer
m_stateMachine.postDelayedEvent(SetupTimeoutEvent, m_setupTimeout);
XLOGD_DEBUG("starting setup timeout timer for %dms", m_setupTimeout);
int timeout = m_config->setupTimeout();
m_stateMachine.postDelayedEvent(SetupTimeoutEvent, timeout);
XLOGD_DEBUG("starting setup timeout timer for %dms", timeout);
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -781,7 +783,7 @@ void BleRcuPairingStateMachine::onExitedPairingSuperState()
void BleRcuPairingStateMachine::onEnteredUnpairingState()
{
// start the unpairing timeout timer
m_stateMachine.postDelayedEvent(UnpairingTimeoutEvent, m_unpairingTimeout);
m_stateMachine.postDelayedEvent(UnpairingTimeoutEvent, m_config->upairingTimeout());

// if we've got to this state it means we have a target device
if (m_targetAddress.isNull()) {
Expand Down
6 changes: 2 additions & 4 deletions src/ble/hal/blercu/blercupairingstatemachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,9 @@ class BleRcuPairingStateMachine

StateMachine m_stateMachine;

const std::shared_ptr<const ConfigSettings> m_config;

int m_discoveryTimeout;
int m_discoveryTimeoutDefault;
int m_pairingTimeout;
int m_setupTimeout;
int m_unpairingTimeout;

int m_pairingAttempts;
int m_pairingSuccesses;
Expand Down
39 changes: 39 additions & 0 deletions src/ble/hal/configsettings/configsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ std::shared_ptr<ConfigSettings> ConfigSettings::parseJson(json_t *jsonConfig)
return std::make_shared<ConfigSettings>(timeouts, std::move(models));
}

// -----------------------------------------------------------------------------
/*!
Parses a json config file and updates the existing object. Any unrecognized fields are ignored.

\see defaults()
*/
bool ConfigSettings::updateJson(json_t *jsonConfig)
{
bool updated = false;

if (jsonConfig == nullptr || !json_is_object(jsonConfig)) {
XLOGD_WARN("invalid json config");
return(updated);
}

// find the timeout params
json_t *timeoutsObj = json_object_get(jsonConfig, "timeouts");
if (timeoutsObj && json_is_object(timeoutsObj)) {
Comment thread
dwolaver marked this conversation as resolved.
m_timeOuts = parseTimeouts(timeoutsObj);
updated = true;
}

// find the model details array
json_t *modelArray = json_object_get(jsonConfig, "models");
if (modelArray && json_is_array(modelArray)) {
XLOGD_WARN("models cannot be updated");
}

return(updated);
}

// -----------------------------------------------------------------------------
/*!
Parses a json config file and returns a \l{std::shared_ptr} to a
Expand Down Expand Up @@ -378,3 +409,11 @@ int ConfigSettings::hidrawWaitLimitTimeout() const
return m_timeOuts.hidrawWaitLimitMSecs;
}

// -----------------------------------------------------------------------------
/*!
Returns true if any of the config fields are updated. Otherwise, returns false.
*/
Comment thread
dwolaver marked this conversation as resolved.
bool ConfigSettings::updateFromJson(json_t *jsonConfig)
{
return updateJson(jsonConfig);
}
6 changes: 3 additions & 3 deletions src/ble/hal/configsettings/configsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ConfigSettings
static std::shared_ptr<ConfigSettings> fromJsonFile(const std::string &filePath);
static std::shared_ptr<ConfigSettings> fromJsonBuffer(const char *jsonBuffer);
static std::shared_ptr<ConfigSettings> parseJson(json_t *jsonConfig);
bool updateJson(json_t *jsonConfig);

struct TimeOuts {
int discoveryMSecs;
Expand All @@ -65,6 +66,7 @@ class ConfigSettings
std::vector<ConfigModelSettings> &&modelDetails);

public:
bool updateFromJson(json_t *jsonConfig);
int discoveryTimeout() const;
int pairingTimeout() const;
int setupTimeout() const;
Expand All @@ -80,11 +82,9 @@ class ConfigSettings
static TimeOuts parseTimeouts(json_t *json);

private:
const TimeOuts m_timeOuts;
TimeOuts m_timeOuts;
const std::vector<ConfigModelSettings> m_modelDetails;
};

// QDebug operator<<(QDebug dbg, const ConfigSettings &settings);


#endif // !defined(CONFIGSETTINGS_H)
Loading