Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applications: Fixed assert on Matter bridge #18113

Merged
merged 1 commit into from
Oct 23, 2024
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
22 changes: 11 additions & 11 deletions applications/matter_bridge/doc/adding_bridged_matter_device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ The following steps show how to add support for a new Matter device type, using

.. code-block:: C++

static void NotifyAttributeChange(intptr_t context);

static constexpr uint16_t kMeasurementsIntervalMs = 10000;
static constexpr int16_t kMinRandomPressure = 95;
static constexpr int16_t kMaxRandomPressure = 101;
Expand Down Expand Up @@ -323,18 +321,20 @@ The following steps show how to add support for a new Matter device type, using
if (!timer || !timer->user_data) {
return;
}
SimulatedPressureSensorDataProvider *provider = reinterpret_cast<SimulatedPressureSensorDataProvider *>(timer->user_data);
/* Get some random data to emulate sensor measurements. */
provider->mPressure = chip::Crypto::GetRandU16() % (kMaxRandomPressure - kMinRandomPressure) + kMinRandomPressure;
DeviceLayer::PlatformMgr().ScheduleWork(NotifyAttributeChange, reinterpret_cast<intptr_t>(provider));
}

void SimulatedPressureSensorDataProvider::NotifyAttributeChange(intptr_t context)
{
SimulatedPressureSensorDataProvider *provider = reinterpret_cast<SimulatedPressureSensorDataProvider *>(context);
provider->NotifyUpdateState(Clusters::PressureMeasurement::Id,
DeviceLayer::PlatformMgr().ScheduleWork(
[](intptr_t p) {
SimulatedPressureSensorDataProvider *provider =
reinterpret_cast<SimulatedPressureSensorDataProvider *>(p);

/* Get some random data to emulate sensor measurements. */
provider->mPressure = chip::Crypto::GetRandU16() % (kMaxRandomPressure - kMinRandomPressure) + kMinRandomPressure;

provider->NotifyUpdateState(Clusters::PressureMeasurement::Id,
Clusters::PressureMeasurement::Attributes::MeasuredValue::Id,
&provider->mPressure, sizeof(provider->mPressure));
},
reinterpret_cast<intptr_t>(timer->user_data));
}

#. Implement the body of the :c:func:`NotifyUpdateState` method that shall be called after every data change related to the Pressure Sensor device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,23 @@ void SimulatedHumiditySensorDataProvider::TimerTimeoutCallback(k_timer *timer)
return;
}

SimulatedHumiditySensorDataProvider *provider =
reinterpret_cast<SimulatedHumiditySensorDataProvider *>(timer->user_data);

/* Get some random data to emulate sensor measurements. */
provider->mHumidity =
chip::Crypto::GetRandU16() % (kMaxRandomTemperature - kMinRandomTemperature) + kMinRandomTemperature;

LOG_INF("SimulatedHumiditySensorDataProvider: Updated humidity value to %d", provider->mHumidity);

DeviceLayer::PlatformMgr().ScheduleWork(NotifyAttributeChange, reinterpret_cast<intptr_t>(provider));
}

void SimulatedHumiditySensorDataProvider::NotifyAttributeChange(intptr_t context)
{
SimulatedHumiditySensorDataProvider *provider =
reinterpret_cast<SimulatedHumiditySensorDataProvider *>(context);

provider->NotifyUpdateState(Clusters::RelativeHumidityMeasurement::Id,
Clusters::RelativeHumidityMeasurement::Attributes::MeasuredValue::Id,
&provider->mHumidity, sizeof(provider->mHumidity));
DeviceLayer::PlatformMgr().ScheduleWork(
[](intptr_t p) {
SimulatedHumiditySensorDataProvider *provider =
reinterpret_cast<SimulatedHumiditySensorDataProvider *>(p);

/* Get some random data to emulate sensor measurements. */
provider->mHumidity =
chip::Crypto::GetRandU16() % (kMaxRandomTemperature - kMinRandomTemperature) +
kMinRandomTemperature;

LOG_INF("SimulatedHumiditySensorDataProvider: Updated humidity value to %d",
provider->mHumidity);

provider->NotifyUpdateState(
Clusters::RelativeHumidityMeasurement::Id,
Clusters::RelativeHumidityMeasurement::Attributes::MeasuredValue::Id,
&provider->mHumidity, sizeof(provider->mHumidity));
},
reinterpret_cast<intptr_t>(timer->user_data));
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class SimulatedHumiditySensorDataProvider : public Nrf::BridgedDeviceDataProvide
size_t dataSize) override;
CHIP_ERROR UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override;

static void NotifyAttributeChange(intptr_t context);

private:
static void TimerTimeoutCallback(k_timer *timer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,22 @@ void SimulatedTemperatureSensorDataProvider::TimerTimeoutCallback(k_timer *timer
return;
}

SimulatedTemperatureSensorDataProvider *provider =
reinterpret_cast<SimulatedTemperatureSensorDataProvider *>(timer->user_data);

/* Get some random data to emulate sensor measurements. */
provider->mTemperature =
chip::Crypto::GetRandU16() % (kMaxRandomTemperature - kMinRandomTemperature) + kMinRandomTemperature;

LOG_INF("SimulatedTemperatureSensorDataProvider: Updated temperature value to %d", provider->mTemperature);

DeviceLayer::PlatformMgr().ScheduleWork(NotifyAttributeChange, reinterpret_cast<intptr_t>(provider));
}

void SimulatedTemperatureSensorDataProvider::NotifyAttributeChange(intptr_t context)
{
SimulatedTemperatureSensorDataProvider *provider =
reinterpret_cast<SimulatedTemperatureSensorDataProvider *>(context);

provider->NotifyUpdateState(Clusters::TemperatureMeasurement::Id,
Clusters::TemperatureMeasurement::Attributes::MeasuredValue::Id,
&provider->mTemperature, sizeof(provider->mTemperature));
DeviceLayer::PlatformMgr().ScheduleWork(
[](intptr_t p) {
SimulatedTemperatureSensorDataProvider *provider =
reinterpret_cast<SimulatedTemperatureSensorDataProvider *>(p);

/* Get some random data to emulate sensor measurements. */
provider->mTemperature =
chip::Crypto::GetRandU16() % (kMaxRandomTemperature - kMinRandomTemperature) +
kMinRandomTemperature;

LOG_INF("SimulatedTemperatureSensorDataProvider: Updated temperature value to %d",
provider->mTemperature);

provider->NotifyUpdateState(Clusters::TemperatureMeasurement::Id,
Clusters::TemperatureMeasurement::Attributes::MeasuredValue::Id,
&provider->mTemperature, sizeof(provider->mTemperature));
},
reinterpret_cast<intptr_t>(timer->user_data));
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

class SimulatedTemperatureSensorDataProvider : public Nrf::BridgedDeviceDataProvider {
public:
SimulatedTemperatureSensorDataProvider(UpdateAttributeCallback updateCallback, InvokeCommandCallback commandCallback) : Nrf::BridgedDeviceDataProvider(updateCallback, commandCallback)
SimulatedTemperatureSensorDataProvider(UpdateAttributeCallback updateCallback,
InvokeCommandCallback commandCallback)
: Nrf::BridgedDeviceDataProvider(updateCallback, commandCallback)
{
}
~SimulatedTemperatureSensorDataProvider() { k_timer_stop(&mTimer); }
Expand All @@ -23,8 +25,6 @@ class SimulatedTemperatureSensorDataProvider : public Nrf::BridgedDeviceDataProv
CHIP_ERROR UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override;

private:
static void NotifyAttributeChange(intptr_t context);

static constexpr uint16_t kMeasurementsIntervalMs = 10000;
static constexpr int16_t kMinRandomTemperature = -10;
static constexpr int16_t kMaxRandomTemperature = 10;
Expand Down
2 changes: 0 additions & 2 deletions samples/matter/common/src/bridge/matter_bridged_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class MatterBridgedDevice {
static constexpr uint16_t GetIdentifyClusterRevision() { return 4; }
static constexpr uint32_t GetIdentifyClusterFeatureMap() { return 0; }

static void NotifyAttributeChange(intptr_t context);

EmberAfEndpointType *mEp;
const EmberAfDeviceType *mDeviceTypeList;
size_t mDeviceTypeListSize;
Expand Down
Loading