Hi,
I'm looking for a JSON library for XMOS devices.
I didn't find any library written in XC, and I started looking for a C/C++ library, but most of the ones I found are not compatible with XC since they use Object Oriented Programming and as far as I understood, Object Oriented Programming is not supported by XC (Is this right?)
I've found a list of C libraries on http://www.json.org/. I'm trying to evaluate if they can run on a XMOS XK-1A but I'm quite stuck. Most of them uses unsafe pointers or function pointers (function pointer are not supported by XC).
Do you have some suggestions about other libraries that are compatibles with XC?
Thanks
JSON library for XMOS
-
- Member++
- Posts: 19
- Joined: Tue Jun 16, 2015 10:50 pm
See the following links:(incase you haven't seen these yet)
https://github.com/json-c/json-c
https://bitbucket.org/yarosla/nxjson
https://bitbucket.org/zserge/jsmn/wiki/Home
https://github.com/json-c/json-c
https://bitbucket.org/yarosla/nxjson
https://bitbucket.org/zserge/jsmn/wiki/Home
-
- XCore Addict
- Posts: 158
- Joined: Thu Mar 20, 2014 8:04 am
Hi, what I am not clear is, we can retain the cpp/c based libraries as-is (as the tool chain supports cpp and c files), and develop a wrapper to interface with xc files, if needed. did you already try a similar approach as this?
-
- Member++
- Posts: 19
- Joined: Tue Jun 16, 2015 10:50 pm
Hi,
following your suggestions, I'm trying to wrap the library JSMN on XC. I added the files jsmn.c and jsmn.h on the src folder of a new project created with xTime Composer (Version: Community_14.0.1).
On the main file, called Lab10-JSON-JSMN.xe, I added the following code got from jsmn_test.c:
#include <xs1.h>
#include <platform.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "jsmn.h"
static int test_passed = 0;
static int test_failed = 0;
/* Terminate current test with error */
#define fail() return __LINE__
/* Successfull end of the test case */
#define done() return 0
/* Check single condition */
#define check(cond) do { if (!(cond)) fail(); } while (0)
#define TOKEN_EQ(t, tok_start, tok_end, tok_type) \
((t).start == tok_start \
&& (t).end == tok_end \
&& (t).type == (tok_type))
#define TOKEN_STRING(js, t, s) \
(strncmp(js+(t).start, s, (t).end - (t).start) == 0 \
&& strlen(s) == (t).end - (t).start)
#define TOKEN_PRINT(t) \
printf("start: %d, end: %d, type: %d, size: %d\n", \
(t).start, (t).end, (t).type, (t).size)
#define JSMN_STRICT
int main()
{
const char *js;
int r;
jsmn_parser p;
jsmntok_t tokens[10];
js = "{\"a\": 0}";
jsmn_init(&p);
// r = jsmn_parse(&p, js, strlen(js), tokens, 10);
// check(r >= 0);
// check(TOKEN_EQ(tokens[0], 0, 8, JSMN_OBJECT));
// check(TOKEN_EQ(tokens[1], 2, 3, JSMN_STRING));
// check(TOKEN_EQ(tokens[2], 6, 7, JSMN_PRIMITIVE));
//
// check(TOKEN_STRING(js, tokens[0], js));
// check(TOKEN_STRING(js, tokens[1], "a"));
// check(TOKEN_STRING(js, tokens[2], "0"));
//
// jsmn_init(&p);
// js = "[\"a\":{},\"b\":{}]";
// r = jsmn_parse(&p, js, strlen(js), tokens, 10);
// check(r >= 0);
//
// jsmn_init(&p);
// js = "{\n \"Day\": 26,\n \"Month\": 9,\n \"Year\": 12\n }";
// r = jsmn_parse(&p, js, strlen(js), tokens, 10);
// check(r >= 0);
return 0;
}
I get an error on the last line before the commented code: jsmn_init(&p);
The error is:
Creating Lab10-JSON-JSMN.xe
jsmn.c: Error: Type of symbol jsmn_init has mismatch with previous definition:
jsmn.c: Error: found: void jsmn_init(struct * /* C pointer */ )
../src/Lab10-JSON-JSMN.xc: Error: previous: void jsmn_init(struct * /* xC pointer */ )
xmake[1]: *** [bin//Lab10-JSON-JSMN.xe] Error 1
xmake: *** [bin//Lab10-JSON-JSMN.xe] Error 2
It seems thath XC interprets differently the struct pointer. On the manual it is written that a C pointer is different from an XC pointer, but I don't know how to manage it.
Can you give me some help?
For your reference, attached you can find a zip file containing the project made with xTime Composer.
Thank you
Bye,
Alex
following your suggestions, I'm trying to wrap the library JSMN on XC. I added the files jsmn.c and jsmn.h on the src folder of a new project created with xTime Composer (Version: Community_14.0.1).
On the main file, called Lab10-JSON-JSMN.xe, I added the following code got from jsmn_test.c:
#include <xs1.h>
#include <platform.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "jsmn.h"
static int test_passed = 0;
static int test_failed = 0;
/* Terminate current test with error */
#define fail() return __LINE__
/* Successfull end of the test case */
#define done() return 0
/* Check single condition */
#define check(cond) do { if (!(cond)) fail(); } while (0)
#define TOKEN_EQ(t, tok_start, tok_end, tok_type) \
((t).start == tok_start \
&& (t).end == tok_end \
&& (t).type == (tok_type))
#define TOKEN_STRING(js, t, s) \
(strncmp(js+(t).start, s, (t).end - (t).start) == 0 \
&& strlen(s) == (t).end - (t).start)
#define TOKEN_PRINT(t) \
printf("start: %d, end: %d, type: %d, size: %d\n", \
(t).start, (t).end, (t).type, (t).size)
#define JSMN_STRICT
int main()
{
const char *js;
int r;
jsmn_parser p;
jsmntok_t tokens[10];
js = "{\"a\": 0}";
jsmn_init(&p);
// r = jsmn_parse(&p, js, strlen(js), tokens, 10);
// check(r >= 0);
// check(TOKEN_EQ(tokens[0], 0, 8, JSMN_OBJECT));
// check(TOKEN_EQ(tokens[1], 2, 3, JSMN_STRING));
// check(TOKEN_EQ(tokens[2], 6, 7, JSMN_PRIMITIVE));
//
// check(TOKEN_STRING(js, tokens[0], js));
// check(TOKEN_STRING(js, tokens[1], "a"));
// check(TOKEN_STRING(js, tokens[2], "0"));
//
// jsmn_init(&p);
// js = "[\"a\":{},\"b\":{}]";
// r = jsmn_parse(&p, js, strlen(js), tokens, 10);
// check(r >= 0);
//
// jsmn_init(&p);
// js = "{\n \"Day\": 26,\n \"Month\": 9,\n \"Year\": 12\n }";
// r = jsmn_parse(&p, js, strlen(js), tokens, 10);
// check(r >= 0);
return 0;
}
I get an error on the last line before the commented code: jsmn_init(&p);
The error is:
Creating Lab10-JSON-JSMN.xe
jsmn.c: Error: Type of symbol jsmn_init has mismatch with previous definition:
jsmn.c: Error: found: void jsmn_init(struct * /* C pointer */ )
../src/Lab10-JSON-JSMN.xc: Error: previous: void jsmn_init(struct * /* xC pointer */ )
xmake[1]: *** [bin//Lab10-JSON-JSMN.xe] Error 1
xmake: *** [bin//Lab10-JSON-JSMN.xe] Error 2
It seems thath XC interprets differently the struct pointer. On the manual it is written that a C pointer is different from an XC pointer, but I don't know how to manage it.
Can you give me some help?
For your reference, attached you can find a zip file containing the project made with xTime Composer.
Thank you
Bye,
Alex
You do not have the required permissions to view the files attached to this post.
-
- Member++
- Posts: 19
- Joined: Tue Jun 16, 2015 10:50 pm
Hi,
I was able to write a wrapper function for the jsmn library - see attached.
However, now I'm concerned about performances.
Do you have some suggestions on the code I developed?
Bye,
Alex
I was able to write a wrapper function for the jsmn library - see attached.
However, now I'm concerned about performances.
Do you have some suggestions on the code I developed?
Bye,
Alex
You do not have the required permissions to view the files attached to this post.
-
- XCore Addict
- Posts: 158
- Joined: Thu Mar 20, 2014 8:04 am
Hi,
Good work!
Following may be helpful, if you ve not tried them yet.
https://www.xmos.com/node/15579?page=10
https://www.xmos.com/download/public/ap ... lator_exam...
https://www.xmos.com/download/private/a ... dware_exam...
Good work!
Following may be helpful, if you ve not tried them yet.
https://www.xmos.com/node/15579?page=10
https://www.xmos.com/download/public/ap ... lator_exam...
https://www.xmos.com/download/private/a ... dware_exam...