Skip to content

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

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

Open
zzasada opened this issue Aug 11, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@zzasada
Copy link

zzasada commented Aug 11, 2023

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.

@zzasada zzasada added the bug Something isn't working label Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant