2016-09-20 12:42 AM
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
2016-09-20 03:03 AM
Hi,
Please which firmware version and example are you using?Regards2016-09-20 03:21 AM
>...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 ?
2016-09-20 06:20 AM
hi, it seems there is only one pack in keil pack installer-> keil::jansson 1.0.0 that containt jansson v2.7
2016-09-20 06:24 AM
I mean it only runs in simulator, not real device.
2016-09-20 02:02 PM
the problem solved by increasing heap size.
thank you!2016-10-04 02:02 PM
Where did you find the example for the M3? Is it in the Keil Directory?
2017-11-29 10:40 AM
,
,
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//80i don't understand!
help!
yoann
2017-11-29 12:48 PM
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.
2017-12-05 02:51 AM
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