28
28
#include < app/ConcreteAttributePath.h>
29
29
#include < app/ConcreteCommandPath.h>
30
30
#include < app/server/Server.h>
31
+ #include < app/util/endpoint-config-api.h>
31
32
#include < lib/core/CHIPEncoding.h>
32
33
#include < platform/internal/CHIPDeviceLayerInternal.h>
33
34
@@ -117,8 +118,7 @@ void TimerExpiredCallback(System::Layer * systemLayer, void * callbackContext)
117
118
VerifyOrReturn (delegate != nullptr , ChipLogError (Zcl, " Delegate is null. Unable to handle timer expired" ));
118
119
119
120
delegate->ClearPendingPresetList ();
120
- gThermostatAttrAccess .SetAtomicWrite (endpoint, false );
121
- gThermostatAttrAccess .SetAtomicWriteScopedNodeId (endpoint, ScopedNodeId ());
121
+ gThermostatAttrAccess .SetAtomicWrite (endpoint, ScopedNodeId (), false );
122
122
}
123
123
124
124
/* *
@@ -206,8 +206,7 @@ void resetAtomicWrite(Delegate * delegate, EndpointId endpoint)
206
206
delegate->ClearPendingPresetList ();
207
207
}
208
208
ClearTimer (endpoint);
209
- gThermostatAttrAccess .SetAtomicWrite (endpoint, false );
210
- gThermostatAttrAccess .SetAtomicWriteScopedNodeId (endpoint, ScopedNodeId ());
209
+ gThermostatAttrAccess .SetAtomicWrite (endpoint, ScopedNodeId (), false );
211
210
}
212
211
213
212
/* *
@@ -633,14 +632,16 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate)
633
632
}
634
633
}
635
634
636
- void ThermostatAttrAccess::SetAtomicWrite (EndpointId endpoint, bool inProgress)
635
+ void ThermostatAttrAccess::SetAtomicWrite (EndpointId endpoint, ScopedNodeId originatorNodeId, bool inProgress)
637
636
{
638
637
uint16_t ep =
639
638
emberAfGetClusterServerEndpointIndex (endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);
640
639
641
- if (ep < ArraySize (mAtomicWriteState ))
640
+ if (ep < ArraySize (mAtomicWriteStates ))
642
641
{
643
- mAtomicWriteState [ep] = inProgress;
642
+ mAtomicWriteStates [ep].inProgress = inProgress;
643
+ mAtomicWriteStates [ep].endpointId = endpoint;
644
+ mAtomicWriteStates [ep].nodeId = originatorNodeId;
644
645
}
645
646
}
646
647
@@ -650,9 +651,9 @@ bool ThermostatAttrAccess::InAtomicWrite(EndpointId endpoint)
650
651
uint16_t ep =
651
652
emberAfGetClusterServerEndpointIndex (endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);
652
653
653
- if (ep < ArraySize (mAtomicWriteState ))
654
+ if (ep < ArraySize (mAtomicWriteStates ))
654
655
{
655
- inAtomicWrite = mAtomicWriteState [ep];
656
+ inAtomicWrite = mAtomicWriteStates [ep]. inProgress ;
656
657
}
657
658
return inAtomicWrite;
658
659
}
@@ -677,26 +678,15 @@ bool ThermostatAttrAccess::InAtomicWrite(CommandHandler * commandObj, EndpointId
677
678
return GetAtomicWriteScopedNodeId (endpoint) == sourceNodeId;
678
679
}
679
680
680
- void ThermostatAttrAccess::SetAtomicWriteScopedNodeId (EndpointId endpoint, ScopedNodeId originatorNodeId)
681
- {
682
- uint16_t ep =
683
- emberAfGetClusterServerEndpointIndex (endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);
684
-
685
- if (ep < ArraySize (mAtomicWriteNodeIds ))
686
- {
687
- mAtomicWriteNodeIds [ep] = originatorNodeId;
688
- }
689
- }
690
-
691
681
ScopedNodeId ThermostatAttrAccess::GetAtomicWriteScopedNodeId (EndpointId endpoint)
692
682
{
693
683
ScopedNodeId originatorNodeId = ScopedNodeId ();
694
684
uint16_t ep =
695
685
emberAfGetClusterServerEndpointIndex (endpoint, Thermostat::Id, MATTER_DM_THERMOSTAT_CLUSTER_SERVER_ENDPOINT_COUNT);
696
686
697
- if (ep < ArraySize (mAtomicWriteNodeIds ))
687
+ if (ep < ArraySize (mAtomicWriteStates ))
698
688
{
699
- originatorNodeId = mAtomicWriteNodeIds [ep];
689
+ originatorNodeId = mAtomicWriteStates [ep]. nodeId ;
700
690
}
701
691
return originatorNodeId;
702
692
}
@@ -981,13 +971,17 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * dele
981
971
982
972
void ThermostatAttrAccess::OnFabricRemoved (const FabricTable & fabricTable, FabricIndex fabricIndex)
983
973
{
984
- for (size_t i = 0 ; i < ArraySize (mAtomicWriteNodeIds ); ++i)
974
+ for (size_t i = 0 ; i < ArraySize (mAtomicWriteStates ); ++i)
985
975
{
986
- auto nodeId = mAtomicWriteNodeIds [i];
987
- if (nodeId.GetFabricIndex () == fabricIndex)
976
+ auto atomicWriteState = mAtomicWriteStates [i];
977
+ if (atomicWriteState. nodeId .GetFabricIndex () == fabricIndex)
988
978
{
989
- mAtomicWriteNodeIds [i] = ScopedNodeId ();
990
- mAtomicWriteState [i] = false ;
979
+ auto delegate = GetDelegate (atomicWriteState.endpointId );
980
+ if (delegate == nullptr )
981
+ {
982
+ continue ;
983
+ }
984
+ resetAtomicWrite (delegate, atomicWriteState.endpointId );
991
985
}
992
986
}
993
987
}
@@ -1457,8 +1451,7 @@ void handleAtomicBegin(CommandHandler * commandObj, const ConcreteCommandPath &
1457
1451
timeout = std::min (timeout, maxTimeout);
1458
1452
1459
1453
ScheduleTimer (endpoint, System::Clock::Milliseconds16 (timeout));
1460
- gThermostatAttrAccess .SetAtomicWrite (endpoint, true );
1461
- gThermostatAttrAccess .SetAtomicWriteScopedNodeId (endpoint, GetSourceScopedNodeId (commandObj));
1454
+ gThermostatAttrAccess .SetAtomicWrite (endpoint, GetSourceScopedNodeId (commandObj), true );
1462
1455
sendAtomicResponse (commandObj, commandPath, imcode::Success, imcode::Success, imcode::Success, MakeOptional (timeout));
1463
1456
}
1464
1457
@@ -1912,3 +1905,14 @@ void MatterThermostatPluginServerInitCallback()
1912
1905
Server::GetInstance ().GetFabricTable ().AddFabricDelegate (&gThermostatAttrAccess );
1913
1906
registerAttributeAccessOverride (&gThermostatAttrAccess );
1914
1907
}
1908
+
1909
+ void MatterThermostatClusterServerShutdownCallback (EndpointId endpoint)
1910
+ {
1911
+ ChipLogProgress (Zcl, " Shutting down thermostat server cluster on endpoint %d" , endpoint);
1912
+ auto delegate = GetDelegate (endpoint);
1913
+
1914
+ if (delegate != nullptr )
1915
+ {
1916
+ resetAtomicWrite (delegate, endpoint);
1917
+ }
1918
+ }
0 commit comments