Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/k32w0 shell app #12153

Merged
merged 3 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/shell/nxp/k32w/k32w0/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern "C" void main_task(void const * argument)
}

// cmd_otcli_init();
cmd_ping_init();
// cmd_ping_init();
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
cmd_send_init();

shellTaskHandle = xTaskCreate(shell_task, "shell_task", shell_task_size / sizeof(StackType_t), NULL, shell_task_priority, NULL);
Expand Down
52 changes: 26 additions & 26 deletions src/lib/shell/commands/Dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ class DnsShellResolverDelegate : public Dnssd::ResolverDelegate
public:
void OnNodeIdResolved(const Dnssd::ResolvedNodeData & nodeData) override
{
streamer_printf(streamer_get(), "DNS resolve for " ChipLogFormatX64 "-" ChipLogFormatX64 " succeeded:\n",
streamer_printf(streamer_get(), "DNS resolve for " ChipLogFormatX64 "-" ChipLogFormatX64 " succeeded:\r\n",
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
ChipLogValueX64(nodeData.mPeerId.GetCompressedFabricId()), ChipLogValueX64(nodeData.mPeerId.GetNodeId()));
streamer_printf(streamer_get(), " Hostname: %s\n", nodeData.mHostName);
streamer_printf(streamer_get(), " IP address: %s\n", nodeData.mAddress.ToString(ipAddressBuf));
streamer_printf(streamer_get(), " Port: %" PRIu16 "\n", nodeData.mPort);
streamer_printf(streamer_get(), " Hostname: %s\r\n", nodeData.mHostName);
streamer_printf(streamer_get(), " IP address: %s\r\n", nodeData.mAddress.ToString(ipAddressBuf));
streamer_printf(streamer_get(), " Port: %" PRIu16 "\r\n", nodeData.mPort);

auto retryInterval = nodeData.GetMrpRetryIntervalIdle();

if (retryInterval.HasValue())
streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\n", retryInterval.Value());
streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\r\n", retryInterval.Value());

retryInterval = nodeData.GetMrpRetryIntervalActive();

if (retryInterval.HasValue())
streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\n", retryInterval.Value());
streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\r\n", retryInterval.Value());

streamer_printf(streamer_get(), " Supports TCP: %s\n", nodeData.mSupportsTcp ? "yes" : "no");
streamer_printf(streamer_get(), " Supports TCP: %s\r\n", nodeData.mSupportsTcp ? "yes" : "no");
}

void OnNodeIdResolutionFailed(const PeerId & peerId, CHIP_ERROR error) override {}
Expand All @@ -75,33 +75,33 @@ class DnsShellResolverDelegate : public Dnssd::ResolverDelegate
Encoding::BytesToUppercaseHexString(nodeData.rotatingId, nodeData.rotatingIdLen, rotatingId, sizeof(rotatingId));

streamer_printf(streamer_get(), "DNS browse succeeded: \n");
streamer_printf(streamer_get(), " Hostname: %s\n", nodeData.hostName);
streamer_printf(streamer_get(), " Vendor ID: %" PRIu16 "\n", nodeData.vendorId);
streamer_printf(streamer_get(), " Product ID: %" PRIu16 "\n", nodeData.productId);
streamer_printf(streamer_get(), " Long discriminator: %" PRIu16 "\n", nodeData.longDiscriminator);
streamer_printf(streamer_get(), " Hostname: %s\r\n", nodeData.hostName);
streamer_printf(streamer_get(), " Vendor ID: %" PRIu16 "\r\n", nodeData.vendorId);
streamer_printf(streamer_get(), " Product ID: %" PRIu16 "\r\n", nodeData.productId);
streamer_printf(streamer_get(), " Long discriminator: %" PRIu16 "\r\n", nodeData.longDiscriminator);
streamer_printf(streamer_get(), " Device type: %" PRIu16 "\n", nodeData.deviceType);
streamer_printf(streamer_get(), " Device name: %s\n", nodeData.deviceName);
streamer_printf(streamer_get(), " Commissioning mode: %d\n", static_cast<int>(nodeData.commissioningMode));
streamer_printf(streamer_get(), " Pairing hint: %" PRIu16 "\n", nodeData.pairingHint);
streamer_printf(streamer_get(), " Pairing instruction: %s\n", nodeData.pairingInstruction);
streamer_printf(streamer_get(), " Rotating ID %s\n", rotatingId);
streamer_printf(streamer_get(), " Device name: %s\r\n", nodeData.deviceName);
streamer_printf(streamer_get(), " Commissioning mode: %d\r\n", static_cast<int>(nodeData.commissioningMode));
streamer_printf(streamer_get(), " Pairing hint: %" PRIu16 "\r\n", nodeData.pairingHint);
streamer_printf(streamer_get(), " Pairing instruction: %s\r\n", nodeData.pairingInstruction);
streamer_printf(streamer_get(), " Rotating ID %s\r\n", rotatingId);

auto retryInterval = nodeData.GetMrpRetryIntervalIdle();

if (retryInterval.HasValue())
streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\n", retryInterval.Value());
streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\r\n", retryInterval.Value());

retryInterval = nodeData.GetMrpRetryIntervalActive();

if (retryInterval.HasValue())
streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\n", retryInterval.Value());
streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\r\n", retryInterval.Value());

streamer_printf(streamer_get(), " Supports TCP: %s\n", nodeData.supportsTcp ? "yes" : "no");
streamer_printf(streamer_get(), " IP addresses:\n");
streamer_printf(streamer_get(), " Supports TCP: %s\r\n", nodeData.supportsTcp ? "yes" : "no");
streamer_printf(streamer_get(), " IP addresses:\r\n");
for (uint8_t i = 0; i < nodeData.kMaxIPAddresses; i++)
{
if (nodeData.ipAddress[i] != Inet::IPAddress::Any)
streamer_printf(streamer_get(), " %s\n", nodeData.ipAddress[i].ToString(ipAddressBuf));
streamer_printf(streamer_get(), " %s\r\n", nodeData.ipAddress[i].ToString(ipAddressBuf));
}
}

Expand All @@ -115,7 +115,7 @@ CHIP_ERROR ResolveHandler(int argc, char ** argv)
{
VerifyOrReturnError(argc == 2, CHIP_ERROR_INVALID_ARGUMENT);

streamer_printf(streamer_get(), "Resolving ...\n");
streamer_printf(streamer_get(), "Resolving ...\r\n");

PeerId peerId;
peerId.SetCompressedFabricId(strtoull(argv[0], NULL, 10));
Expand Down Expand Up @@ -175,11 +175,11 @@ CHIP_ERROR BrowseCommissionableHandler(int argc, char ** argv)

if (!ParseSubType(argc, argv, filter))
{
streamer_printf(streamer_get(), "Invalid argument\n");
streamer_printf(streamer_get(), "Invalid argument\r\n");
return CHIP_ERROR_INVALID_ARGUMENT;
}

streamer_printf(streamer_get(), "Browsing commissionable nodes...\n");
streamer_printf(streamer_get(), "Browsing commissionable nodes...\r\n");

return Dnssd::Resolver::Instance().FindCommissionableNodes(filter);
}
Expand All @@ -190,11 +190,11 @@ CHIP_ERROR BrowseCommissionerHandler(int argc, char ** argv)

if (!ParseSubType(argc, argv, filter))
{
streamer_printf(streamer_get(), "Invalid argument\n");
streamer_printf(streamer_get(), "Invalid argument\r\n");
return CHIP_ERROR_INVALID_ARGUMENT;
}

streamer_printf(streamer_get(), "Browsing commissioners...\n");
streamer_printf(streamer_get(), "Browsing commissioners...\r\n");

return Dnssd::Resolver::Instance().FindCommissioners(filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1971,8 +1971,6 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnDnsBrowseResult(otEr
return;
}

ThreadStackMgrImpl().LockThreadStack();

VerifyOrExit(aError == OT_ERROR_NONE, error = MapOpenThreadError(aError));

error = MapOpenThreadError(otDnsBrowseResponseGetServiceName(aResponse, type, sizeof(type)));
Expand Down Expand Up @@ -2005,8 +2003,6 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnDnsBrowseResult(otEr

exit:

ThreadStackMgrImpl().UnlockThreadStack();

// In case no service was found invoke callback to notify about failure. In other case it was already called before.
if (!wasAnythingBrowsed)
ThreadStackMgrImpl().mDnsBrowseCallback(aContext, nullptr, 0, error);
Expand Down Expand Up @@ -2059,8 +2055,6 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnDnsResolveResult(otE
return;
}

ThreadStackMgrImpl().LockThreadStack();

VerifyOrExit(aError == OT_ERROR_NONE, error = MapOpenThreadError(aError));

error = MapOpenThreadError(otDnsServiceResponseGetServiceName(aResponse, resolveResult.mMdnsService.mName,
Expand All @@ -2081,7 +2075,6 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnDnsResolveResult(otE

exit:

ThreadStackMgrImpl().UnlockThreadStack();
ThreadStackMgrImpl().mDnsResolveCallback(aContext, &(resolveResult.mMdnsService), error);
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1
#define CHIP_DEVICE_CONFIG_ENABLE_DNSSD 1
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1

#endif
42 changes: 42 additions & 0 deletions src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,30 @@ ConfigurationManagerImpl ConfigurationManagerImpl::sInstance;
CHIP_ERROR ConfigurationManagerImpl::Init()
{
CHIP_ERROR err;
uint32_t rebootCount;
bool failSafeArmed;

if (ConfigValueExists(kCounterKey_RebootCount))
{
err = GetRebootCount(rebootCount);
SuccessOrExit(err);

err = StoreRebootCount(rebootCount + 1);
SuccessOrExit(err);
}
else
{
// The first boot after factory reset of the Node.
err = StoreRebootCount(1);
SuccessOrExit(err);
}

if (!ConfigValueExists(kCounterKey_TotalOperationalHours))
{
err = StoreTotalOperationalHours(0);
SuccessOrExit(err);
}

// Initialize the generic implementation base class.
err = Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>::Init();
SuccessOrExit(err);
Expand All @@ -66,6 +88,26 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
return err;
}

CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount)
{
return ReadConfigValue(kCounterKey_RebootCount, rebootCount);
}

CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount)
{
return WriteConfigValue(kCounterKey_RebootCount, rebootCount);
}

CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours)
{
return ReadConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours);
}

CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
{
return WriteConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours);
}

bool ConfigurationManagerImpl::CanFactoryReset()
{
// TODO: query the application to determine if factory reset is allowed.
Expand Down
6 changes: 6 additions & 0 deletions src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ namespace DeviceLayer {
class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>,
private Internal::K32WConfig
{
public:
CHIP_ERROR GetRebootCount(uint32_t & rebootCount);
CHIP_ERROR StoreRebootCount(uint32_t rebootCount);
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours);
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours);

// Allow the GenericConfigurationManagerImpl base class to access helper methods and types
// defined on this class.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down
5 changes: 5 additions & 0 deletions src/platform/nxp/k32w/k32w0/K32W0Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ CHIP_ERROR K32WConfig::FactoryResetConfig(void)
if (err == CHIP_NO_ERROR)
{
err = FactoryResetConfigInternal(kMinConfigKey_KVS, kMaxConfigKey_KVS);

if (err == CHIP_NO_ERROR)
{
FactoryResetConfigInternal(kMinConfigKey_ChipCounter, kMaxConfigKey_ChipCounter);
}
}

return err;
Expand Down
25 changes: 4 additions & 21 deletions src/platform/nxp/k32w/k32w0/K32W0Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,10 @@ class K32WConfig
static constexpr Key kConfigKey_CountryCode = K32WConfigKey(kPDMId_ChipConfig, 0x08);
static constexpr Key kConfigKey_Breadcrumb = K32WConfigKey(kPDMId_ChipConfig, 0x09);

static constexpr Key kConfigKey_GroupKey = K32WConfigKey(kPDMId_ChipConfig, 0x0A);
static constexpr Key kConfigKey_GroupKey0 = K32WConfigKey(kPDMId_ChipConfig, 0x0B);
static constexpr Key kConfigKey_GroupKey1 = K32WConfigKey(kPDMId_ChipConfig, 0x0C);
static constexpr Key kConfigKey_GroupKey2 = K32WConfigKey(kPDMId_ChipConfig, 0x0D);
static constexpr Key kConfigKey_GroupKey3 = K32WConfigKey(kPDMId_ChipConfig, 0x0E);
static constexpr Key kConfigKey_GroupKey4 = K32WConfigKey(kPDMId_ChipConfig, 0x0F);
static constexpr Key kConfigKey_GroupKey5 = K32WConfigKey(kPDMId_ChipConfig, 0x10);
static constexpr Key kConfigKey_GroupKey6 = K32WConfigKey(kPDMId_ChipConfig, 0x11);
static constexpr Key kConfigKey_GroupKey7 = K32WConfigKey(kPDMId_ChipConfig, 0x12);
static constexpr Key kConfigKey_GroupKey8 = K32WConfigKey(kPDMId_ChipConfig, 0x13);
static constexpr Key kConfigKey_GroupKey9 = K32WConfigKey(kPDMId_ChipConfig, 0x14);
static constexpr Key kConfigKey_GroupKey10 = K32WConfigKey(kPDMId_ChipConfig, 0x15);
static constexpr Key kConfigKey_GroupKey11 = K32WConfigKey(kPDMId_ChipConfig, 0x16);
static constexpr Key kConfigKey_GroupKey12 = K32WConfigKey(kPDMId_ChipConfig, 0x17);
static constexpr Key kConfigKey_GroupKey13 = K32WConfigKey(kPDMId_ChipConfig, 0x18);
static constexpr Key kConfigKey_GroupKey14 = K32WConfigKey(kPDMId_ChipConfig, 0x19);
static constexpr Key kConfigKey_GroupKey15 = K32WConfigKey(kPDMId_ChipConfig, 0x1A);

static constexpr Key kConfigKey_GroupKeyBase = kConfigKey_GroupKey0;
static constexpr Key kConfigKey_GroupKeyMax = K32WConfigKey(kPDMId_ChipConfig, 0x1E);
; // Allows 16 Group Keys to be created.
// CHIP Counter Keys
static constexpr Key kCounterKey_RebootCount = K32WConfigKey(kPDMId_ChipConfig, 0x0A);
static constexpr Key kCounterKey_UpTime = K32WConfigKey(kPDMId_ChipConfig, 0x0B);
static constexpr Key kCounterKey_TotalOperationalHours = K32WConfigKey(kPDMId_ChipConfig, 0x0C);

// Set key id limits for each group.
static constexpr Key kMinConfigKey_ChipFactory = K32WConfigKey(kPDMId_ChipFactory, 0x00);
Expand Down
Loading