@@ -576,7 +576,7 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
576
576
}
577
577
}
578
578
579
- static CHIP_ERROR MTREncodeTLVFromDataValueDictionary (id object, chip::TLV::TLVWriter & writer, chip::TLV::Tag tag)
579
+ static CHIP_ERROR MTREncodeTLVFromDataValueDictionaryInternal (id object, chip::TLV::TLVWriter & writer, chip::TLV::Tag tag)
580
580
{
581
581
if (![object isKindOfClass: [NSDictionary class ]]) {
582
582
MTR_LOG_ERROR (" Error: Unsupported object to encode: %@" , [object class ]);
@@ -585,7 +585,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
585
585
NSString * typeName = ((NSDictionary *) object)[MTRTypeKey];
586
586
id value = ((NSDictionary *) object)[MTRValueKey];
587
587
if (![typeName isKindOfClass: [NSString class ]]) {
588
- MTR_LOG_ERROR (" Error: Object to encode is corrupt " );
588
+ MTR_LOG_ERROR (" Error: Object to encode has no MTRTypeKey: %@ " , object );
589
589
return CHIP_ERROR_INVALID_ARGUMENT;
590
590
}
591
591
@@ -632,14 +632,14 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
632
632
MTR_LOG_ERROR (" Error: Object to encode has corrupt UTF8 string type: %@" , [value class ]);
633
633
return CHIP_ERROR_INVALID_ARGUMENT;
634
634
}
635
- return writer.PutString (tag, [ value UTF8String ] );
635
+ return writer.PutString (tag, AsCharSpan ( value) );
636
636
}
637
637
if ([typeName isEqualToString: MTROctetStringValueType]) {
638
638
if (![value isKindOfClass: [NSData class ]]) {
639
639
MTR_LOG_ERROR (" Error: Object to encode has corrupt octet string type: %@" , [value class ]);
640
640
return CHIP_ERROR_INVALID_ARGUMENT;
641
641
}
642
- return writer.Put (tag, chip::ByteSpan ( static_cast < const uint8_t *>([ value bytes ]), [value length ] ));
642
+ return writer.Put (tag, AsByteSpan ( value));
643
643
}
644
644
if ([typeName isEqualToString: MTRStructureValueType]) {
645
645
if (![value isKindOfClass: [NSArray class ]]) {
@@ -674,7 +674,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
674
674
tag = TLV::ContextTag (static_cast <uint8_t >(tagValue));
675
675
}
676
676
ReturnErrorOnFailure (
677
- MTREncodeTLVFromDataValueDictionary (elementValue, writer, tag));
677
+ MTREncodeTLVFromDataValueDictionaryInternal (elementValue, writer, tag));
678
678
}
679
679
ReturnErrorOnFailure (writer.EndContainer (outer));
680
680
return CHIP_NO_ERROR;
@@ -696,7 +696,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
696
696
MTR_LOG_ERROR (" Error: Array element to encode has corrupt value: %@" , element);
697
697
return CHIP_ERROR_INVALID_ARGUMENT;
698
698
}
699
- ReturnErrorOnFailure (MTREncodeTLVFromDataValueDictionary (elementValue, writer, chip::TLV::AnonymousTag ()));
699
+ ReturnErrorOnFailure (MTREncodeTLVFromDataValueDictionaryInternal (elementValue, writer, chip::TLV::AnonymousTag ()));
700
700
}
701
701
ReturnErrorOnFailure (writer.EndContainer (outer));
702
702
return CHIP_NO_ERROR;
@@ -705,6 +705,15 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
705
705
return CHIP_ERROR_INVALID_ARGUMENT;
706
706
}
707
707
708
+ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary (id object, chip::TLV::TLVWriter & writer, chip::TLV::Tag tag)
709
+ {
710
+ CHIP_ERROR err = MTREncodeTLVFromDataValueDictionaryInternal (object, writer, tag);
711
+ if (err != CHIP_NO_ERROR) {
712
+ MTR_LOG_ERROR (" Failed to encode to TLV: %@" , object);
713
+ }
714
+ return err;
715
+ }
716
+
708
717
NSData * _Nullable MTREncodeTLVFromDataValueDictionary (NSDictionary <NSString *, id > * value, NSError * __autoreleasing * error)
709
718
{
710
719
// A single data item cannot be bigger than a packet, so just use 1200 bytes
@@ -991,6 +1000,8 @@ - (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attri
991
1000
queue : (dispatch_queue_t )queue
992
1001
completion : (MTRDeviceResponseHandler)completion
993
1002
{
1003
+ MTR_LOG (" %@ readAttributePaths: %@, eventPaths: %@" , self, attributePaths, eventPaths);
1004
+
994
1005
[self readAttributePaths: attributePaths eventPaths: eventPaths params: params includeDataVersion: NO queue: queue completion: completion];
995
1006
}
996
1007
@@ -1001,6 +1012,9 @@ - (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attri
1001
1012
queue : (dispatch_queue_t )queue
1002
1013
completion : (MTRDeviceResponseHandler)completion
1003
1014
{
1015
+ // NOTE: Do not log the read here. This is called ether from
1016
+ // readAttributePaths:eventPaths:params:queue:completion: or MTRDevice, both
1017
+ // of which already log, and we want to be able to tell the two codepaths apart.
1004
1018
if ((attributePaths == nil || [attributePaths count ] == 0 ) && (eventPaths == nil || [eventPaths count ] == 0 )) {
1005
1019
// No paths, just return an empty array.
1006
1020
dispatch_async (queue, ^{
@@ -1157,6 +1171,19 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
1157
1171
timedWriteTimeout : (NSNumber * _Nullable)timeoutMs
1158
1172
queue : (dispatch_queue_t )queue
1159
1173
completion : (MTRDeviceResponseHandler)completion
1174
+ {
1175
+ MTR_LOG (" %@ write %@ 0x%llx 0x%llx: %@" , self, endpointID, clusterID.unsignedLongLongValue , attributeID.unsignedLongLongValue , value);
1176
+
1177
+ [self _writeAttributeWithEndpointID: endpointID clusterID: clusterID attributeID: attributeID value: value timedWriteTimeout: timeoutMs queue: queue completion: completion];
1178
+ }
1179
+
1180
+ - (void )_writeAttributeWithEndpointID : (NSNumber *)endpointID
1181
+ clusterID : (NSNumber *)clusterID
1182
+ attributeID : (NSNumber *)attributeID
1183
+ value : (id )value
1184
+ timedWriteTimeout : (NSNumber * _Nullable)timeoutMs
1185
+ queue : (dispatch_queue_t )queue
1186
+ completion : (MTRDeviceResponseHandler)completion
1160
1187
{
1161
1188
auto * bridge = new MTRDataValueDictionaryCallbackBridge (queue, completion,
1162
1189
^(ExchangeManager & exchangeManager, const SessionHandle & session, MTRDataValueDictionaryCallback successCb,
@@ -1337,6 +1364,7 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
1337
1364
commandFields: commandFields
1338
1365
timedInvokeTimeout: timeoutMs
1339
1366
serverSideProcessingTimeout: nil
1367
+ logCall: YES
1340
1368
queue: queue
1341
1369
completion: completion];
1342
1370
}
@@ -1347,6 +1375,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
1347
1375
commandFields : (id )commandFields
1348
1376
timedInvokeTimeout : (NSNumber * _Nullable)timeoutMs
1349
1377
serverSideProcessingTimeout : (NSNumber * _Nullable)serverSideProcessingTimeout
1378
+ logCall : (BOOL )logCall
1350
1379
queue : (dispatch_queue_t )queue
1351
1380
completion : (MTRDeviceResponseHandler)completion
1352
1381
{
@@ -1367,6 +1396,10 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
1367
1396
timeoutMs = MTRClampedNumber (timeoutMs, @(1 ), @(UINT16_MAX));
1368
1397
}
1369
1398
1399
+ if (logCall) {
1400
+ MTR_LOG (" %@ invoke %@ 0x%llx 0x%llx: %@" , self, endpointID, clusterID.unsignedLongLongValue , commandID.unsignedLongLongValue , commandFields);
1401
+ }
1402
+
1370
1403
auto * bridge = new MTRDataValueDictionaryCallbackBridge (queue, completion,
1371
1404
^(ExchangeManager & exchangeManager, const SessionHandle & session, MTRDataValueDictionaryCallback successCb,
1372
1405
MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) {
@@ -1490,6 +1523,7 @@ - (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID
1490
1523
commandFields: commandFields
1491
1524
timedInvokeTimeout: timeout
1492
1525
serverSideProcessingTimeout: serverSideProcessingTimeout
1526
+ logCall: YES
1493
1527
queue: queue
1494
1528
completion: responseHandler];
1495
1529
}
@@ -2148,6 +2182,12 @@ - (void)downloadLogOfType:(MTRDiagnosticLogType)type
2148
2182
completion: completion];
2149
2183
}
2150
2184
2185
+ - (NSString *)description
2186
+ {
2187
+ return [NSString
2188
+ stringWithFormat: @" <%@ : %p , node: %016llX -%016llX (%llu )>" , NSStringFromClass (self .class ), self , _deviceController.compressedFabricID.unsignedLongLongValue, _nodeID, _nodeID];
2189
+ }
2190
+
2151
2191
@end
2152
2192
2153
2193
@implementation MTRBaseDevice (Deprecated)
0 commit comments