Skip to content

Commit

Permalink
applications: Fixed assert on Matter bridge
Browse files Browse the repository at this point in the history
After the last Zephyr up-merge, getting rand number from the
timer callback leads to the crypto assert.
Added scheduling rand operation to the application event.

Signed-off-by: Kamil Kasperczyk <[email protected]>
  • Loading branch information
kkasperczyk-no committed Oct 23, 2024
1 parent 17445fa commit df87d74
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +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));
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);

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

void SimulatedHumiditySensorDataProvider::NotifyAttributeChange(intptr_t context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,23 @@ 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));
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);

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

void SimulatedTemperatureSensorDataProvider::NotifyAttributeChange(intptr_t context)
Expand Down

0 comments on commit df87d74

Please sign in to comment.