diff --git a/examples/lighting-app/nrf5/BUILD.gn b/examples/lighting-app/nrf5/BUILD.gn index 5fcf9d6662f7b5..05787e6c1dfb24 100644 --- a/examples/lighting-app/nrf5/BUILD.gn +++ b/examples/lighting-app/nrf5/BUILD.gn @@ -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", diff --git a/examples/lighting-app/nrf5/main/AppTask.cpp b/examples/lighting-app/nrf5/main/AppTask.cpp index 34488b7f4ecc18..d6e50b2f51d1fe 100644 --- a/examples/lighting-app/nrf5/main/AppTask.cpp +++ b/examples/lighting-app/nrf5/main/AppTask.cpp @@ -41,6 +41,9 @@ #include #include +#include +#include + APP_TIMER_DEF(sFunctionTimer); namespace { @@ -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; @@ -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; } diff --git a/examples/lock-app/nrf5/BUILD.gn b/examples/lock-app/nrf5/BUILD.gn index 1511bad3dabe4f..2f8daa5f9bc238 100644 --- a/examples/lock-app/nrf5/BUILD.gn +++ b/examples/lock-app/nrf5/BUILD.gn @@ -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", diff --git a/examples/lock-app/nrf5/main/AppTask.cpp b/examples/lock-app/nrf5/main/AppTask.cpp index 45fa6c709fe0a1..c3eb93be76e5be 100644 --- a/examples/lock-app/nrf5/main/AppTask.cpp +++ b/examples/lock-app/nrf5/main/AppTask.cpp @@ -42,11 +42,15 @@ #include #include +#include +#include + #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); @@ -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; } diff --git a/examples/platform/nrf528xx/app/support/CXXExceptionStubs.cpp b/examples/platform/nrf528xx/app/support/CXXExceptionStubs.cpp index a4ef5137758023..0f8795191330cf 100644 --- a/examples/platform/nrf528xx/app/support/CXXExceptionStubs.cpp +++ b/examples/platform/nrf528xx/app/support/CXXExceptionStubs.cpp @@ -63,18 +63,18 @@ void __cxa_rethrow() abort(); } -void * __cxa_begin_catch(void *) -{ - abort(); -} +// void * __cxa_begin_catch(void *) +// { +// 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(); +// } } diff --git a/src/setup_payload/ManualSetupPayloadGenerator.cpp b/src/setup_payload/ManualSetupPayloadGenerator.cpp index 90c3c0848ccba4..f0b149f46895c5 100644 --- a/src/setup_payload/ManualSetupPayloadGenerator.cpp +++ b/src/setup_payload/ManualSetupPayloadGenerator.cpp @@ -23,6 +23,8 @@ #include "ManualSetupPayloadGenerator.h" +#include + #include #include @@ -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); }