1NCE-GmbH / blueprint-zephyr

1NCE Zephyr Blueprint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Element2byte_gen_t battery_level = { .type = E_INTEGER, .value.i = 256, .template_length = 4 }; only works for integers 0 - 255

zzasada opened this issue · comments

commented

Board type

nrf52840dk

Modem

No response

Describe the bug

Element2byte_gen_t battery_level = { .type = E_INTEGER, .value.i = 256, .template_length = 4 };

Result:
NCE_SDK: Conversion Error, Check template length.

This function only works for .value.i = (0 to 255) any values outside of that cause

nce_iot_c_sdk.c line 289 ( e.value.i != *(e.value.bytes))) to evaluate true and returns NCE_SDK_BINARY_PAYLOAD_ERROR;

so currently only uint8_t is supported.

Expected Behavior

Expect support for 8, 16, 32, and 64-bit signed and unsigned integers.

Current Behavior

Only supports 8-bit unsigned integers

Reproduction Steps

Element2byte_gen_t battery_level = { .type = E_INTEGER, .value.i = 256, .template_length = 4 };
Element2byte_gen_t battery_level = { .type = E_INTEGER, .value.i = -1, .template_length = 1 };

Other information

I believe the error is in nce_iot_c_sdk.c line 289-293

    if( ( e.type == E_INTEGER ) && ( e.value.i != *( e.value.bytes ) ) )
    {
        NceOSLogError( "Conversion Error, Check template length.\n" );
        return NCE_SDK_BINARY_PAYLOAD_ERROR;
    }

( e.value.i != *( e.value.bytes ) ) evaluates true for all values outside the range of 0-255 commenting out this section of code allows the code to work as expected; however; it is no longer checking then if the template_length is large enough to accommodate the correct integer.