Skip to content

Commit d0ff4a1

Browse files
authored
Merge branch 'master' into reenable_ti_ci
2 parents 1a9e798 + 84ee115 commit d0ff4a1

10 files changed

+154
-116
lines changed

examples/energy-management-app/energy-management-common/energy-evse/src/EVSEManufacturerImpl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ CHIP_ERROR EVSEManufacturer::Init()
7070

7171
/* For Device Energy Management we need the ESA to be Online and ready to accept commands */
7272
dem->SetESAState(ESAStateEnum::kOnline);
73+
dem->SetESAType(ESATypeEnum::kEvse);
7374

7475
// Set the abs min and max power
7576
dem->SetAbsMinPower(1200000); // 1.2KW

examples/energy-management-app/energy-management-common/water-heater/src/WaterHeaterMain.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void FullWhmApplicationInit()
7373
/* For Device Energy Management we need the ESA to be Online and ready to accept commands */
7474

7575
GetDEMDelegate()->SetESAState(ESAStateEnum::kOnline);
76+
GetDEMDelegate()->SetESAType(ESATypeEnum::kWaterHeating);
7677
GetDEMDelegate()->SetDEMManufacturerDelegate(*GetWhmManufacturer());
7778

7879
// Set the abs min and max power

src/darwin/Framework/CHIP/MTRBaseDevice.mm

+46-6
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
576576
}
577577
}
578578

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)
580580
{
581581
if (![object isKindOfClass:[NSDictionary class]]) {
582582
MTR_LOG_ERROR("Error: Unsupported object to encode: %@", [object class]);
@@ -585,7 +585,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
585585
NSString * typeName = ((NSDictionary *) object)[MTRTypeKey];
586586
id value = ((NSDictionary *) object)[MTRValueKey];
587587
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);
589589
return CHIP_ERROR_INVALID_ARGUMENT;
590590
}
591591

@@ -632,14 +632,14 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
632632
MTR_LOG_ERROR("Error: Object to encode has corrupt UTF8 string type: %@", [value class]);
633633
return CHIP_ERROR_INVALID_ARGUMENT;
634634
}
635-
return writer.PutString(tag, [value UTF8String]);
635+
return writer.PutString(tag, AsCharSpan(value));
636636
}
637637
if ([typeName isEqualToString:MTROctetStringValueType]) {
638638
if (![value isKindOfClass:[NSData class]]) {
639639
MTR_LOG_ERROR("Error: Object to encode has corrupt octet string type: %@", [value class]);
640640
return CHIP_ERROR_INVALID_ARGUMENT;
641641
}
642-
return writer.Put(tag, chip::ByteSpan(static_cast<const uint8_t *>([value bytes]), [value length]));
642+
return writer.Put(tag, AsByteSpan(value));
643643
}
644644
if ([typeName isEqualToString:MTRStructureValueType]) {
645645
if (![value isKindOfClass:[NSArray class]]) {
@@ -674,7 +674,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
674674
tag = TLV::ContextTag(static_cast<uint8_t>(tagValue));
675675
}
676676
ReturnErrorOnFailure(
677-
MTREncodeTLVFromDataValueDictionary(elementValue, writer, tag));
677+
MTREncodeTLVFromDataValueDictionaryInternal(elementValue, writer, tag));
678678
}
679679
ReturnErrorOnFailure(writer.EndContainer(outer));
680680
return CHIP_NO_ERROR;
@@ -696,7 +696,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
696696
MTR_LOG_ERROR("Error: Array element to encode has corrupt value: %@", element);
697697
return CHIP_ERROR_INVALID_ARGUMENT;
698698
}
699-
ReturnErrorOnFailure(MTREncodeTLVFromDataValueDictionary(elementValue, writer, chip::TLV::AnonymousTag()));
699+
ReturnErrorOnFailure(MTREncodeTLVFromDataValueDictionaryInternal(elementValue, writer, chip::TLV::AnonymousTag()));
700700
}
701701
ReturnErrorOnFailure(writer.EndContainer(outer));
702702
return CHIP_NO_ERROR;
@@ -705,6 +705,15 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
705705
return CHIP_ERROR_INVALID_ARGUMENT;
706706
}
707707

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+
708717
NSData * _Nullable MTREncodeTLVFromDataValueDictionary(NSDictionary<NSString *, id> * value, NSError * __autoreleasing * error)
709718
{
710719
// 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
9911000
queue:(dispatch_queue_t)queue
9921001
completion:(MTRDeviceResponseHandler)completion
9931002
{
1003+
MTR_LOG("%@ readAttributePaths: %@, eventPaths: %@", self, attributePaths, eventPaths);
1004+
9941005
[self readAttributePaths:attributePaths eventPaths:eventPaths params:params includeDataVersion:NO queue:queue completion:completion];
9951006
}
9961007

@@ -1001,6 +1012,9 @@ - (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attri
10011012
queue:(dispatch_queue_t)queue
10021013
completion:(MTRDeviceResponseHandler)completion
10031014
{
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.
10041018
if ((attributePaths == nil || [attributePaths count] == 0) && (eventPaths == nil || [eventPaths count] == 0)) {
10051019
// No paths, just return an empty array.
10061020
dispatch_async(queue, ^{
@@ -1157,6 +1171,19 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
11571171
timedWriteTimeout:(NSNumber * _Nullable)timeoutMs
11581172
queue:(dispatch_queue_t)queue
11591173
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
11601187
{
11611188
auto * bridge = new MTRDataValueDictionaryCallbackBridge(queue, completion,
11621189
^(ExchangeManager & exchangeManager, const SessionHandle & session, MTRDataValueDictionaryCallback successCb,
@@ -1337,6 +1364,7 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
13371364
commandFields:commandFields
13381365
timedInvokeTimeout:timeoutMs
13391366
serverSideProcessingTimeout:nil
1367+
logCall:YES
13401368
queue:queue
13411369
completion:completion];
13421370
}
@@ -1347,6 +1375,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
13471375
commandFields:(id)commandFields
13481376
timedInvokeTimeout:(NSNumber * _Nullable)timeoutMs
13491377
serverSideProcessingTimeout:(NSNumber * _Nullable)serverSideProcessingTimeout
1378+
logCall:(BOOL)logCall
13501379
queue:(dispatch_queue_t)queue
13511380
completion:(MTRDeviceResponseHandler)completion
13521381
{
@@ -1367,6 +1396,10 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
13671396
timeoutMs = MTRClampedNumber(timeoutMs, @(1), @(UINT16_MAX));
13681397
}
13691398

1399+
if (logCall) {
1400+
MTR_LOG("%@ invoke %@ 0x%llx 0x%llx: %@", self, endpointID, clusterID.unsignedLongLongValue, commandID.unsignedLongLongValue, commandFields);
1401+
}
1402+
13701403
auto * bridge = new MTRDataValueDictionaryCallbackBridge(queue, completion,
13711404
^(ExchangeManager & exchangeManager, const SessionHandle & session, MTRDataValueDictionaryCallback successCb,
13721405
MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) {
@@ -1490,6 +1523,7 @@ - (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID
14901523
commandFields:commandFields
14911524
timedInvokeTimeout:timeout
14921525
serverSideProcessingTimeout:serverSideProcessingTimeout
1526+
logCall:YES
14931527
queue:queue
14941528
completion:responseHandler];
14951529
}
@@ -2148,6 +2182,12 @@ - (void)downloadLogOfType:(MTRDiagnosticLogType)type
21482182
completion:completion];
21492183
}
21502184

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+
21512191
@end
21522192

21532193
@implementation MTRBaseDevice (Deprecated)

src/darwin/Framework/CHIP/MTRBaseDevice_Internal.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@ static inline MTRTransportType MTRMakeTransportType(chip::Transport::Type type)
116116

117117
/**
118118
* Like the public invokeCommandWithEndpointID but allows passing through a
119-
* serverSideProcessingTimeout.
119+
* serverSideProcessingTimeout and controlling whether we log the call (so we
120+
* can not log when the call is not actually originating with MTRBaseDevice).
120121
*/
121122
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
122123
clusterID:(NSNumber *)clusterID
123124
commandID:(NSNumber *)commandID
124125
commandFields:(id)commandFields
125126
timedInvokeTimeout:(NSNumber * _Nullable)timeoutMs
126127
serverSideProcessingTimeout:(NSNumber * _Nullable)serverSideProcessingTimeout
128+
logCall:(BOOL)logCall
127129
queue:(dispatch_queue_t)queue
128130
completion:(MTRDeviceResponseHandler)completion;
129131

@@ -195,6 +197,17 @@ static inline MTRTransportType MTRMakeTransportType(chip::Transport::Type type)
195197
queue:(dispatch_queue_t)queue
196198
completion:(MTRDeviceResponseHandler)completion;
197199

200+
/**
201+
* Same as the public version, except for logging. For use from MTRDevice only.
202+
*/
203+
- (void)_writeAttributeWithEndpointID:(NSNumber *)endpointID
204+
clusterID:(NSNumber *)clusterID
205+
attributeID:(NSNumber *)attributeID
206+
value:(id)value
207+
timedWriteTimeout:(NSNumber * _Nullable)timeoutMs
208+
queue:(dispatch_queue_t)queue
209+
completion:(MTRDeviceResponseHandler)completion;
210+
198211
@end
199212

200213
@interface MTRClusterPath ()

0 commit comments

Comments
 (0)