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

[nrf5-demo] Print QR code on boot #2233

Merged
merged 3 commits into from
Aug 19, 2020
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
1 change: 1 addition & 0 deletions examples/lighting-app/nrf5/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ executable("lighting_app") {
deps = [
":sdk",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
"${chip_root}/third_party/openthread/platforms/nrf528xx:libnordicsemi_nrf52840_radio_driver_softdevice",
"${chip_root}/third_party/openthread/platforms/nrf528xx:libopenthread-nrf52840-softdevice-sdk",
"${nrf5_platform_dir}/app/support:freertos_newlib_lock_support",
Expand Down
43 changes: 43 additions & 0 deletions examples/lighting-app/nrf5/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <support/ErrorStr.h>
#include <system/SystemClock.h>

#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

APP_TIMER_DEF(sFunctionTimer);

namespace {
Expand All @@ -50,6 +53,7 @@ constexpr int kFactoryResetCancelWindowTimeout = 3000;
constexpr size_t kAppTaskStackSize = 4096;
constexpr int kAppTaskPriority = 2;
constexpr int kAppEventQueueSize = 10;
constexpr int kExampleVenderID = 0xabcd;

SemaphoreHandle_t sCHIPEventLock;

Expand Down Expand Up @@ -155,6 +159,45 @@ int AppTask::Init()
APP_ERROR_HANDLER(NRF_ERROR_NULL);
}

{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::SetupPayload payload;
uint32_t setUpPINCode = 0;
uint32_t setUpDiscriminator = 0;

err = ConfigurationMgr().GetSetupPinCode(setUpPINCode);
if (err != CHIP_NO_ERROR)
{
NRF_LOG_INFO("ConfigurationMgr().GetSetupPinCode() failed: %s", chip::ErrorStr(err));
}

err = ConfigurationMgr().GetSetupDiscriminator(setUpDiscriminator);
if (err != CHIP_NO_ERROR)
{
NRF_LOG_INFO("ConfigurationMgr().GetSetupDiscriminator() failed: %s", chip::ErrorStr(err));
}

payload.version = 1;
payload.vendorID = kExampleVenderID;
payload.productID = 1;
payload.setUpPINCode = setUpPINCode;
payload.discriminator = setUpDiscriminator;
chip::QRCodeSetupPayloadGenerator generator(payload);

// TODO: Usage of STL will significantly increase the image size, this should be changed to more efficient method for
// generating payload
std::string result;
err = generator.payloadBase41Representation(result);
if (err != CHIP_NO_ERROR)
{
NRF_LOG_ERROR("Failed to generate QR Code");
}

NRF_LOG_INFO("SetupPINCode: [%" PRIu32 "]", setUpPINCode);
// There might be whitespace in setup QRCode, add brackets to make it clearer.
NRF_LOG_INFO("SetupQRCode: [%s]", result.c_str());
}

return ret;
}

Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrf5/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ executable("lock_app") {
deps = [
":sdk",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
"${chip_root}/third_party/openthread/platforms/nrf528xx:libnordicsemi_nrf52840_radio_driver_softdevice",
"${chip_root}/third_party/openthread/platforms/nrf528xx:libopenthread-nrf52840-softdevice-sdk",
"${nrf5_platform_dir}/app/support:freertos_newlib_lock_support",
Expand Down
43 changes: 43 additions & 0 deletions examples/lock-app/nrf5/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@
#include <support/ErrorStr.h>
#include <system/SystemClock.h>

#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
#define APP_TASK_STACK_SIZE (4096)
#define APP_TASK_PRIORITY 2
#define APP_EVENT_QUEUE_SIZE 10
#define EXAMPLE_VENDOR_ID 0xabcd

APP_TIMER_DEF(sFunctionTimer);

Expand Down Expand Up @@ -165,6 +169,45 @@ int AppTask::Init()
APP_ERROR_HANDLER(NRF_ERROR_NULL);
}

{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::SetupPayload payload;
uint32_t setUpPINCode = 0;
uint32_t setUpDiscriminator = 0;

err = ConfigurationMgr().GetSetupPinCode(setUpPINCode);
if (err != CHIP_NO_ERROR)
{
NRF_LOG_INFO("ConfigurationMgr().GetSetupPinCode() failed: %s", chip::ErrorStr(err));
}

err = ConfigurationMgr().GetSetupDiscriminator(setUpDiscriminator);
if (err != CHIP_NO_ERROR)
{
NRF_LOG_INFO("ConfigurationMgr().GetSetupDiscriminator() failed: %s", chip::ErrorStr(err));
}

payload.version = 1;
payload.vendorID = EXAMPLE_VENDOR_ID;
payload.productID = 1;
payload.setUpPINCode = setUpPINCode;
payload.discriminator = setUpDiscriminator;
chip::QRCodeSetupPayloadGenerator generator(payload);

// TODO: Usage of STL will significantly increase the image size, this should be changed to more efficient method for
// generating payload
std::string result;
err = generator.payloadBase41Representation(result);
if (err != CHIP_NO_ERROR)
{
NRF_LOG_ERROR("Failed to generate QR Code");
}

NRF_LOG_INFO("SetupPINCode: [%" PRIu32 "]", setUpPINCode);
// There might be whitespace in setup QRCode, add brackets to make it clearer.
NRF_LOG_INFO("SetupQRCode: [%s]", result.c_str());
}

return ret;
}

Expand Down
24 changes: 12 additions & 12 deletions examples/platform/nrf528xx/app/support/CXXExceptionStubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ void __cxa_rethrow()
abort();
}

void * __cxa_begin_catch(void *)
{
abort();
}
// void * __cxa_begin_catch(void *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.../chip/chip-demo-202008/third_party/pigweed/repo/.environment/cipd/pigweed/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++_nano.a(eh_catch.o): in function `__cxa_get_exception_ptr':
eh_catch.cc:(.text.__cxa_get_exception_ptr+0x0): multiple definition of `__cxa_get_exception_ptr'; obj/third_party/connectedhomeip/examples/platform/nrf528xx/app/support/chip-nrf52840-lock-example.CXXExceptionStubs.cpp.o:.../source/chip/chip-nrf5-qrcode/examples/lock-app/nrf5/out/debug/../../third_party/connectedhomeip/examples/platform/nrf528xx/app/support/CXXExceptionStubs.cpp:77: first defined here

This is caused by STL exceptions introduced by setup payload, which is also the reason of the huge size increase, this is expected to be removed after we have another setup payload implemtation without stl.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we delete instead of commenting out. I generally would try to avoid commented out code.

// {
// abort();
// }

void __cxa_end_catch()
{
abort();
}
// void __cxa_end_catch()
// {
// abort();
// }

void * __cxa_get_exception_ptr(void *)
{
abort();
}
// void * __cxa_get_exception_ptr(void *)
// {
// abort();
// }
}
4 changes: 3 additions & 1 deletion src/setup_payload/ManualSetupPayloadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "ManualSetupPayloadGenerator.h"

#include <inttypes.h>

#include <support/logging/CHIPLogging.h>
#include <support/verhoeff/Verhoeff.h>

Expand All @@ -41,7 +43,7 @@ static uint32_t shortPayloadRepresentation(const SetupPayload & payload)
static string decimalStringWithPadding(uint32_t number, int minLength)
{
char buf[minLength + 1];
snprintf(buf, sizeof(buf), "%0*u", minLength, number);
snprintf(buf, sizeof(buf), "%0*" PRIu32, minLength, number);
return string(buf);
}

Expand Down