Skip to content

Commit

Permalink
Merge branch 'master' into for-chip/python-reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
mspang authored Jul 5, 2022
2 parents dfa6fbe + a498673 commit 928b3a7
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 12 deletions.
4 changes: 3 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {

declare_args() {
# Enable building chip with clang.
enable_host_clang_build = enable_default_builds && host_os != "win"
# Disabled on Mac arm64 but note that the "gcc" build uses Apple clang.
enable_host_clang_build = enable_default_builds && host_os != "win" &&
(host_os != "mac" || host_cpu != "arm64")

# Enable building chip with gcc.
enable_host_gcc_build = enable_default_builds && host_os != "win"
Expand Down
26 changes: 26 additions & 0 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,29 @@ class SubscribeEvent : public SubscribeCommand
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<std::vector<bool>> mIsUrgents;
};

class ReadAll : public ReadCommand
{
public:
ReadAll(CredentialIssuerCommands * credsIssuerConfig) : ReadCommand("read-all", credsIssuerConfig)
{
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
ReadCommand::AddArguments();
}

~ReadAll() {}

void OnDone(chip::app::ReadClient * aReadClient) override
{
InteractionModelReports::CleanupReadClient(aReadClient);
SetCommandExitStatus(mError);
}

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReadCommand::ReadAll(device, endpointIds, mFabricFiltered);
}

private:
chip::Optional<bool> mFabricFiltered;
};
1 change: 1 addition & 0 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss
make_unique<SubscribeAttribute>(credsIssuerConfig), //
make_unique<ReadEvent>(credsIssuerConfig), //
make_unique<SubscribeEvent>(credsIssuerConfig), //
make_unique<ReadAll>(credsIssuerConfig), //
};

commands.Register(clusterName, clusterCommands);
Expand Down
104 changes: 104 additions & 0 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/on-off-server/on-off-server.h>

#include <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand Down Expand Up @@ -66,6 +69,107 @@ StaticQueue_t sAppEventQueueStruct;

StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;

EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;

/**********************************************************
* Identify Callbacks
*********************************************************/

namespace {
void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
}
} // namespace

void OnTriggerIdentifyEffect(Identify * identify)
{
sIdentifyEffect = identify->mCurrentEffectIdentifier;

if (identify->mCurrentEffectIdentifier == EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE)
{
ChipLogProgress(Zcl, "IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE - Not supported, use effect variant %d",
identify->mEffectVariant);
sIdentifyEffect = static_cast<EmberAfIdentifyEffectIdentifier>(identify->mEffectVariant);
}

switch (sIdentifyEffect)
{
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK:
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE:
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY:
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
identify);
break;
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted,
identify);
break;
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
break;
default:
ChipLogProgress(Zcl, "No identifier effect");
}
}

Identify gIdentify = {
chip::EndpointId{ 1 },
[](Identify *) { ChipLogProgress(Zcl, "onIdentifyStart"); },
[](Identify *) { ChipLogProgress(Zcl, "onIdentifyStop"); },
EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED,
OnTriggerIdentifyEffect,
};

/**********************************************************
* OffWithEffect Callbacks
*********************************************************/

void OnTriggerOffWithEffect(OnOffEffect * effect)
{
chip::app::Clusters::OnOff::OnOffEffectIdentifier effectId = effect->mEffectIdentifier;
uint8_t effectVariant = effect->mEffectVariant;

// Uses print outs until we can support the effects
if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF)
{
if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS)
{
ChipLogProgress(Zcl, "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS");
}
else if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE)
{
ChipLogProgress(Zcl, "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE");
}
else if (effectVariant ==
EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_IN_12_SECONDS)
{
ChipLogProgress(Zcl,
"EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_"
"IN_12_SECONDS");
}
}
else if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DYING_LIGHT)
{
if (effectVariant ==
EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND)
{
ChipLogProgress(
Zcl, "EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND");
}
}
}

OnOffEffect gEffect = {
chip::EndpointId{ 1 },
OnTriggerOffWithEffect,
EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF,
static_cast<uint8_t>(EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS),
};

} // namespace

AppTask AppTask::sAppTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,37 @@ void InteractionModelReports::CleanupReadClient(ReadClient * aReadClient)
std::remove_if(mReadClients.begin(), mReadClients.end(), [aReadClient](auto & item) { return item.get() == aReadClient; }),
mReadClients.end());
}

CHIP_ERROR InteractionModelReports::ReadAll(DeviceProxy * device, std::vector<EndpointId> endpointIds,
const Optional<bool> & fabricFiltered)
{
AttributePathParams attributePathParams[kMaxAllowedPaths];
EventPathParams eventPathParams[kMaxAllowedPaths];

auto pathsCount = endpointIds.size();
VerifyOrReturnError(pathsCount > 0 && pathsCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT);

for (size_t i = 0; i < pathsCount; i++)
{
auto endpointId = endpointIds.at(i);
attributePathParams[i].mEndpointId = endpointId;
eventPathParams[i].mEndpointId = endpointId;
}

ReadPrepareParams params(device->GetSecureSession().Value());
params.mpEventPathParamsList = eventPathParams;
params.mEventPathParamsListSize = pathsCount;
params.mpAttributePathParamsList = attributePathParams;
params.mAttributePathParamsListSize = pathsCount;

if (fabricFiltered.HasValue())
{
params.mIsFabricFiltered = fabricFiltered.Value();
}

auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
mBufferedReadAdapter, ReadClient::InteractionType::Read);
ReturnErrorOnFailure(client->SendRequest(params));
mReadClients.push_back(std::move(client));
return CHIP_NO_ERROR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class InteractionModelReports
const chip::Optional<bool> & keepSubscriptions = chip::NullOptional,
const chip::Optional<std::vector<bool>> & isUrgents = chip::NullOptional);

CHIP_ERROR ReadAll(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
const chip::Optional<bool> & fabricFiltered = chip::Optional<bool>(true));

void Shutdown() { mReadClients.clear(); }

void CleanupReadClient(chip::app::ReadClient * aReadClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ CHIP_ERROR StorageAdapter::SyncGetKeyValue(const char * key, void * value, uint1
}

uint16_t tmpSize = size;
bool isFound = false;

mGetKeyCb(mContext, key, (char *) value, &tmpSize);
mGetKeyCb(mContext, key, (char *) value, &tmpSize, &isFound);

if (tmpSize == 0)
if (!isFound)
{
ChipLogDetail(Controller, "Key Not Found\n");
return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
Expand All @@ -107,8 +108,8 @@ CHIP_ERROR StorageAdapter::SyncGetKeyValue(const char * key, void * value, uint1

CHIP_ERROR StorageAdapter::SyncSetKeyValue(const char * key, const void * value, uint16_t size)
{
ReturnErrorCodeIf(((value == nullptr) && (size != 0)), CHIP_ERROR_INVALID_ARGUMENT);
ChipLogDetail(Controller, "StorageAdapter::SetKeyValue: Key = %s, Value = %p (%u)", key, value, size);
mStorage[key] = std::string(static_cast<const char *>(value), size);
mSetKeyCb(mContext, key, value, size);
return CHIP_NO_ERROR;
}
Expand Down
4 changes: 1 addition & 3 deletions src/controller/python/ChipDeviceController-StorageDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Python {
using PyObject = void;

using SyncSetKeyValueCb = void (*)(PyObject * appContext, const char * key, const void * value, uint16_t size);
using SetGetKeyValueCb = void (*)(PyObject * appContext, const char * key, char * value, uint16_t * size);
using SetGetKeyValueCb = void (*)(PyObject * appContext, const char * key, char * value, uint16_t * size, bool * isFound);
using SyncDeleteKeyValueCb = void (*)(PyObject * appContext, const char * key);

class StorageAdapter : public PersistentStorageDelegate
Expand All @@ -68,8 +68,6 @@ class StorageAdapter : public PersistentStorageDelegate
SetGetKeyValueCb mGetKeyCb;
SyncDeleteKeyValueCb mDeleteKeyCb;
PyObject * mContext;

std::map<std::string, std::string> mStorage;
};

} // namespace Python
Expand Down
15 changes: 10 additions & 5 deletions src/controller/python/chip/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
_SyncSetKeyValueCbFunct = CFUNCTYPE(
None, py_object, c_char_p, POINTER(c_char), c_uint16)
_SyncGetKeyValueCbFunct = CFUNCTYPE(
None, py_object, c_char_p, POINTER(c_char), POINTER(c_uint16))
None, py_object, c_char_p, POINTER(c_char), POINTER(c_uint16), POINTER(c_bool))
_SyncDeleteKeyValueCbFunct = CFUNCTYPE(None, py_object, c_char_p)


Expand All @@ -45,7 +45,7 @@ def _OnSyncSetKeyValueCb(storageObj, key: str, value, size):


@_SyncGetKeyValueCbFunct
def _OnSyncGetKeyValueCb(storageObj, key: str, value, size):
def _OnSyncGetKeyValueCb(storageObj, key: str, value, size, is_found):
''' This does not adhere to the API requirements of
PersistentStorageDelegate::SyncGetKeyValue, but that is okay since
the C++ storage binding layer is capable of adapting results from
Expand All @@ -57,7 +57,7 @@ def _OnSyncGetKeyValueCb(storageObj, key: str, value, size):
except Exception as ex:
keyValue = None

if (keyValue):
if (keyValue is not None):
sizeOfValue = size[0]
sizeToCopy = min(sizeOfValue, len(keyValue))

Expand All @@ -74,13 +74,15 @@ def _OnSyncGetKeyValueCb(storageObj, key: str, value, size):
# will use the value in size[0] to determine if it should
# return CHIP_ERROR_BUFFER_TOO_SMALL.
size[0] = len(keyValue)
is_found[0] = True
else:
is_found[0] = False
size[0] = 0


@_SyncDeleteKeyValueCbFunct
def _OnSyncDeleteKeyValueCb(storageObj, key):
storageObj.SetSdkKey(key.decode("utf-8"), None)
storageObj.DeleteSdkKey(key.decode("utf-8"))


class PersistentStorage:
Expand Down Expand Up @@ -151,7 +153,7 @@ def SetSdkKey(self, key: str, value: bytes):
raise ValueError("Invalid Key")

if (value is None):
del(self.jsonData['sdk-config'][key])
raise ValueError('value is not expected to be None')
else:
self.jsonData['sdk-config'][key] = base64.b64encode(
value).decode("utf-8")
Expand All @@ -161,6 +163,9 @@ def SetSdkKey(self, key: str, value: bytes):
def GetSdkKey(self, key: str):
return base64.b64decode(self.jsonData['sdk-config'][key])

def DeleteSdkKey(self, key: str):
del(self.jsonData['sdk-config'][key])

def GetUnderlyingStorageAdapter(self):
return self._storageAdapterObj

Expand Down
1 change: 1 addition & 0 deletions zzz_generated/chip-tool/zap-generated/cluster/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 928b3a7

Please sign in to comment.