Cross-platform data transfer protocol

I need to implement a fairly simple network protocol: there is a device with a microcontroller (C language) and a Java application, they need to communicate: I need to implement a firmware update and, possibly, some other things.

At least I need to pass some data structures as headers.

Only the ugly way comes to mind:

I can declare a packed structure on the C side and somehow process the same data stream on the Java side. So, if my structure is changed, I need to make changes on both sides: C and Java. I really don't like it.

Is there a better way to do this? Perhaps something like this: I have to write the protocol structures in some special format, and then some utility can generate code for the C and Java sides.

Or maybe something else.

I would be glad to see the offers.

+4
source share
3 answers

Perhaps you should take a look at using standardized notation for data transfer such as JSON. Here is some information about parsing JSON in c.

JSON parsing using C

If this were my project, I would probably do just packed data structures. We hope that when your project matures, changes in data structures are minimal and occur only during major releases. You can save the version tag in the data structure to handle legacy data formats, if necessary.

+3
source

One common solution to this problem would be to use Google protobuf . However, since what you need is for it to work in a microcontroller environment, I think you could look into protobuf-c , which is a pure C-version of protobuf.

+3
source

Could you describe the details of the protocol? Is statefull or stateless? If your protocol does not have a status, look at web services (especially REST-WS). This is a well-known cross-platform communication practice.

0
source

Source: https://habr.com/ru/post/1480352/


All Articles