|
26 | 26 | #include <app/InteractionModelEngine.h>
|
27 | 27 | #include <app/ReadClient.h>
|
28 | 28 | #include <app/WriteClient.h>
|
| 29 | +#include <controller/CHIPDeviceController.h> |
29 | 30 | #include <controller/python/chip/native/PyChipError.h>
|
30 | 31 | #include <lib/support/CodeUtils.h>
|
31 | 32 |
|
@@ -247,6 +248,8 @@ struct __attribute__((packed)) PyReadAttributeParams
|
247 | 248 | // Encodes n attribute write requests, follows 3 * n arguments, in the (AttributeWritePath*=void *, uint8_t*, size_t) order.
|
248 | 249 | PyChipError pychip_WriteClient_WriteAttributes(void * appContext, DeviceProxy * device, uint16_t timedWriteTimeoutMs,
|
249 | 250 | uint16_t interactionTimeoutMs, uint16_t busyWaitMs, size_t n, ...);
|
| 251 | +PyChipError pychip_WriteClient_WriteGroupAttributes(chip::GroupId groupId, chip::Controller::DeviceCommissioner * devCtrl, |
| 252 | + uint16_t busyWaitMs, size_t n, ...); |
250 | 253 | PyChipError pychip_ReadClient_ReadAttributes(void * appContext, ReadClient ** pReadClient, ReadClientCallback ** pCallback,
|
251 | 254 | DeviceProxy * device, uint8_t * readParamsBuf, size_t n, size_t total, ...);
|
252 | 255 | }
|
@@ -380,6 +383,64 @@ PyChipError pychip_WriteClient_WriteAttributes(void * appContext, DeviceProxy *
|
380 | 383 | return ToPyChipError(err);
|
381 | 384 | }
|
382 | 385 |
|
| 386 | +PyChipError pychip_WriteClient_WriteGroupAttributes(chip::GroupId groupId, chip::Controller::DeviceCommissioner * devCtrl, |
| 387 | + uint16_t busyWaitMs, size_t n, ...) |
| 388 | +{ |
| 389 | + CHIP_ERROR err = CHIP_NO_ERROR; |
| 390 | + |
| 391 | + chip::Messaging::ExchangeManager * exchangeManager = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); |
| 392 | + VerifyOrReturnError(exchangeManager != nullptr, ToPyChipError(CHIP_ERROR_INCORRECT_STATE)); |
| 393 | + |
| 394 | + std::unique_ptr<WriteClient> client = std::make_unique<WriteClient>( |
| 395 | + app::InteractionModelEngine::GetInstance()->GetExchangeManager(), nullptr /* callback */, Optional<uint16_t>::Missing()); |
| 396 | + |
| 397 | + va_list args; |
| 398 | + va_start(args, n); |
| 399 | + |
| 400 | + { |
| 401 | + for (size_t i = 0; i < n; i++) |
| 402 | + { |
| 403 | + void * path = va_arg(args, void *); |
| 404 | + void * tlv = va_arg(args, void *); |
| 405 | + int length = va_arg(args, int); |
| 406 | + |
| 407 | + python::AttributePath pathObj; |
| 408 | + memcpy(&pathObj, path, sizeof(python::AttributePath)); |
| 409 | + uint8_t * tlvBuffer = reinterpret_cast<uint8_t *>(tlv); |
| 410 | + |
| 411 | + TLV::TLVReader reader; |
| 412 | + reader.Init(tlvBuffer, static_cast<uint32_t>(length)); |
| 413 | + reader.Next(); |
| 414 | + Optional<DataVersion> dataVersion; |
| 415 | + if (pathObj.hasDataVersion == 1) |
| 416 | + { |
| 417 | + dataVersion.SetValue(pathObj.dataVersion); |
| 418 | + } |
| 419 | + // Using kInvalidEndpointId as that used when sending group write requests. |
| 420 | + SuccessOrExit( |
| 421 | + err = client->PutPreencodedAttribute( |
| 422 | + chip::app::ConcreteDataAttributePath(kInvalidEndpointId, pathObj.clusterId, pathObj.attributeId, dataVersion), |
| 423 | + reader)); |
| 424 | + } |
| 425 | + } |
| 426 | + |
| 427 | + { |
| 428 | + auto fabricIndex = devCtrl->GetFabricIndex(); |
| 429 | + |
| 430 | + chip::Transport::OutgoingGroupSession session(groupId, fabricIndex); |
| 431 | + SuccessOrExit(err = client->SendWriteRequest(chip::SessionHandle(session), System::Clock::kZero)); |
| 432 | + } |
| 433 | + |
| 434 | + if (busyWaitMs) |
| 435 | + { |
| 436 | + usleep(busyWaitMs * 1000); |
| 437 | + } |
| 438 | + |
| 439 | +exit: |
| 440 | + va_end(args); |
| 441 | + return ToPyChipError(err); |
| 442 | +} |
| 443 | + |
383 | 444 | void pychip_ReadClient_Abort(ReadClient * apReadClient, ReadClientCallback * apCallback)
|
384 | 445 | {
|
385 | 446 | VerifyOrDie(apReadClient != nullptr);
|
|
0 commit comments