cancel
Showing results for 
Search instead for 
Did you mean: 

Json for c Arm

arsalan_elec
Associate II
Posted on September 20, 2016 at 09:42

Hello all,

im going to parse json string in my project, i found jansson library for keil, there is an example for cortex-m3 that run just fine in simulator. but the problem is when run the code on stm32f103 the output is worng, please see below: the example code:

void
add_2array_to_json( json_t* obj, 
const
char
* name, 
const
int
*
marr, 
size_t
dim1, 
size_t
dim2 )
{
size_t
i, j;
json_t* jarr1 = json_array();
for
( i=0; i<dim1; ++i ) {
json_t* jarr2 = json_array();
for
( j=0; j<dim2; ++j ) {
int
val = marr[ i*dim2 + j ];
json_t* jval = json_integer( val );
json_array_append_new( jarr2, jval );
}
json_array_append_new( jarr1, jarr2 );
}
json_object_set_new( obj, name, jarr1 );
return
;
}
void
SystemClock_Config(
void
);
int
main()
{
json_t* jdata;
char
* s;
int
arr1[2][3] = { {1,2,3}, {4,5,6} };
int
arr2[4][4] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16} };
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
MX_TIM2_Init();
MX_USART2_UART_Init();
jdata = json_object();
add_2array_to_json( jdata, 
''arr1''
, &arr1[0][0], 2, 3 );
add_2array_to_json( jdata, 
''arr2''
, &arr2[0][0], 4, 4 );
s = json_dumps( jdata, 0 );
HAL_UART_Transmit(&huart1,(uint8_t*)s,
strlen
(s),1000);
HAL_UART_Transmit(&huart1,
''Hello''
,5,1000);
// puts( s );
free
( s );
json_decref( jdata );
while
(1);
}

the out put i get is just:

{}

correct simulator output is:

{''arr1'': [[1, 2, 3], [4, 5, 6]], ''arr2'': [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]}

#json-keil-uvision-stm32f-parse
10 REPLIES 10
slimen
Senior
Posted on September 20, 2016 at 12:03

Hi,

Please which firmware version and example are you using?

Regards

AvaTar
Lead
Posted on September 20, 2016 at 12:21

>...there is an example for cortex-m3 that run just fine in simulator. but the problem is when run the code on stm32f103 the output is worng, ...

 

And what is wrong with using a debugger ?

arsalan_elec
Associate II
Posted on September 20, 2016 at 15:20

hi, it seems there is only one pack in keil pack installer-> keil::jansson 1.0.0 that containt jansson v2.7

arsalan_elec
Associate II
Posted on September 20, 2016 at 15:24

I mean it only runs in simulator, not real device.

arsalan_elec
Associate II
Posted on September 20, 2016 at 23:02

the problem solved by increasing heap size.

thank you!

davidworden9
Associate II
Posted on October 04, 2016 at 23:02

Where did you find the example for the M3? Is it in the Keil Directory?

Posted on November 29, 2017 at 18:40

 ,

 ,

hi,

Heap size in startup_stm32fxxx.s?

i have a problem with jansson_CM3LE.lib with stm32f401RB.

This is my fucntion:

char buf[512],

json_t * root,* data, ,

 ,

const char *strText,

json_error_t error,

//for test:

sprintf(buf,'{\'ssid\':\'LE SSID\',\'hostname\':\'mqtt.system.loc\',\'port\':9883}'), ,

 ,

root = json_loadb((const char *)buf,strlen(buf),JSON_DISABLE_EOF_CHECK,&,error),

//root = json_loads((const char *)buf,JSON_DISABLE_EOF_CHECK,&,error),

 ,

if(json_is_object(root))

 ,

{

 ,

 , ,data = json_object_get(root,'ssid'), , , , , ,

 ,

 , ,if(json_is_string(data))

 ,

 , , ,{

 ,

 , , , ,strText = json_string_value(data),

 ,

 , , , ,strcpy((char *)(wifi_ssid_generic),strText),

 ,

 , , ,} , , , , , , , , ,

in this example, root equal zero!!!

Before that i had a HardFault_Handler. i modified jansson.h to fix it

♯ define JSON_ERROR_TEXT_LENGTH , , , 512//160

 ,

♯ define JSON_ERROR_SOURCE_LENGTH , , 256//80

i don't understand!

help!

yoann

Posted on November 29, 2017 at 20:48

Remember this post is from over 1 year ago, to a prior instance of the forum, no indication user has visited since.

Yes, for Keil heap size is defined in startup_xyz.s, make sure it is sufficient for the task.

Perhaps break point malloc() to understand the usage, or create an instrumented version.

What code do you get from 'error' variable? Does that provide insight into the problem?

If root can be zero, try doing a NULL check before using it.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on December 05, 2017 at 10:51

hi,

jansson_CM3LE.lib too greedy in memory for the embedded c software I migrated on a parser ligth 'jsmn' (2 file .c, .h) and it works well.

tks. Yoann