This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/LAUNCHXL-CC3235SF: Appropriate values for "maxValueSize" parameter of "Json_getValue" function

Part Number: LAUNCHXL-CC3235SF

Tool/software: TI-RTOS

Hi everybody!

Could you clarify me one point in your JSON library? My question relates the last parameter "uint16_t *maxValueSize" of this function:

int16_t Json_getValue(Json_Handle objHandle, const char *pKey, void *pValue, uint16_t *maxValueSize);

Which value should I pass by reference here?

As I understand, in case of string and raw data types I should pass pointer to a number of bytes, allocated for its value.
In case of "int32", "uint32", "real32", "ureal32" I should pass pointer to its type size in bytes, "sizeof(int32_t)", "sizeof(uint32_t)", "sizeof(real32_t)", "sizeof(ureal32_t)", respectively, as I understand.
But in case of "boolean" type,  why "maxValueSize" variable should be no less than 2? If I pass pointer to variable, equals 1, then the function returns error code "-101" ("JSON_RC__PARSING_BUFFER_SIZE_EXCEEDED"), althoug internal representation of boolean type is "uint8_t". And if to follow my logic, "maxValueSize" variable should be 1. So, I would like to clarify this point to pass correct values.

And if I understand correctly, your description of "__JSON_GetValue()" function in json_engine.h file is a bit outdated. In note section you forgot to mention about unsigned types ("uint32_t" and "ureal32_t"), which are supported, it seems.

And sorry, if I misunderstood something, since I've not found complete documentation with examples.

Best regards,
Roman

  • Roman,

    If we look at the code in __Json_GetValue, at line 1185 of json_engine.c all non-strings get MemCpy'd into the provided buffer. The number of bytes copied depends on value size. Like you say, booleans are given a value size of 2 bytes. The result is that two bytes will be copied from a temporary location (found_property->common +1). Since a sizeof(boolean) should be 1, this would only work correctly if somehow "true"/"false" are parsed as a uint16 value. Else, you could copy garbage data.

    Maybe since the boolean "true"/"false" must be first parsed as a string, maybe that's why the library reserves a 2 byte value for it. I don't have a JSON test program, but maybe you can step through the JSON library and see how it parses the true/false strings to see why the library needs 2 bytes. The results of that debug will help TI determine what is going on.

    -CE
  • Many thanks for your response, CE!

    I have figured out, that "DetermineValueSize()" function fills value size in this line "*value_size = sizeof(uint16_t);", so its value equals 2 for both "PROPERTY_TYPE__BOOLEAN_BASE" and "PROPERTY_TYPE__STRING_BASE". But in case of "PROPERTY_TYPE__STRING_BASE", it seems, that "value_size" isn't used in further code. Unfortunately, I don't have a lot of time to go into all details of JSON library source code, and at all it seems quite convoluted, so probably in case of other vague issues I will scrutinize it deeper, when other parts of my app are ready. At the moment it's enough for me to allocate 2 bytes for boolean value and don't care about lower-level functions realization. And I hope, that TI will finally provide exhaustive documentation ;-)
    But right now I faced with other unobvious things in JSON library. When a transmitted value of json variable is beyond borders, JSON library produces neither an error or it overflows the variable, it rounds to the nearest value (min or max). So, for example, if template has "uint32" type for variable and json text contain "-1" value for this variable, then JSON library won't produce any errors and it will round this value to "0", not "2^32-1" as usually C compiler does in case of "(uint32_t) -1" cast statement.
    Also if I modify json template in json_app example in such a way, that I substitute any type for "real32" or "ureal32", then "Json_createTemplate()" function returns "-25" ("JSON_RC__RECOVERED__ILLEGAL_Q_VALUES").
    So it would be better to have a more detailed description of this library.

    Regards,
    Roman

  • Hi Roman,

    The JSON library does have documentation in SDK. In the CC32xx 2.40 SDK, this is in the docs/ns folder, but it was moved to docs/tiutils in the 3.10 SDK. There is also a JSON example in the examples/<rtos>/<device-type>/ns (or tiutils) folder.

    I'll loop in an expert on the library anyway since I'm not sure your additional queries would be covered in the documentation. They should be able to answer the rest of your questions.

    Best regards,
    Sarah

  • Hi Sarah! Thank you for your answer!

    If I understood you correctly, you meant this page dev.ti.com/.../group__ti__utils__json__JSON.html, when you wrote about JSON documentation. I can't find "3.10 SDK" for CC32XX controllers. I understand, that this page looks like documentation, but it reveal required things not enough. I believe that TI specialists can write more complete documentation for the library to save users' time further. Because this documentation doesn't even cover allowed json value types.

    Regards,
    Roman
  • Hi Roman,

    The SimpleLink CC32XX 3.10 SDK has not been released yet, but it should be coming soon. Some of your issues with the documentation are addressed there, namely the following was added:

    The types available to specify in a JSON template are: int32, uint32, raw, string, and boolean. Usage examples are in the API Reference Guide.

    NOTE: Floating point values are not parsed correctly and should likely not be used. This will be fixed in a future release and is tracked by TIUTILS-8.

    Thanks,
    Gerardo

  • Hi Gerardo!

    All right, okay, I got it. Thank you. I have no choice but to wait for and hope on upcoming documentation and fixes.

    Best regards,
    Roman
  • Roman,

    Just a heads up, the SimpleLink CC32XX 3.10 SDK is available now, it can be found here:
    http://www.ti.com/tool/download/SIMPLELINK-CC32XX-SDK

    Regards,
    Gerardo

  • Thank you, Gerardo!

    I already hoped to see some promised additions there, but in fact there was added only one single remark about floating point values, nothing else. It wasn't worth waiting for.

    Regards,
    Roman