0

I am working in Simulink on a TCP connection between client (my computer) and server. Through standard Ethernet blocks, I send an HTTP request like the following:

GET /status HTTP/1.1
Host:...
Accept: application/json

To send it, I convert it with the uint8('GET /status...') command. The server responds, always with a uint8 array (decimal bytes) like this :

resp=[72 84 80 47 49 32 50 48...] //(HTTP/1.1 200 OK... ).

In the reply "resp" content, always in decimal characters, there is a text in JSON format like {"VarA":1000, "VarB":2000,...}.

My purpose is to create an S-function (but more generally a code in C++) that taking in input the vector "resp" returns the values of VarA and VarB (1000 and 2000).

I know that there are a lot of single-header source code like nlohmann/json or PicoHTTPParser but I don't know how to use them in the specific case.

  1. My idea is to convert "resp" into a string and then pass it to the functions already written in the .h files for JSON/HTTP management. Is this correct? Can it be done? I ask myself this question because I don't know what format the parse functions of those .h files take in input.

  2. I also wonder if it is right to convert it into a string and then work on it...does anyone know if there is something that works directly on the uint_8 vector?

  3. Should I extract the body message from "resp" before I work on it?

Sorry for these questions but I'm little bit confused. I don't even know how to search this problem on Google! Actually, I'm looking for the easiest way to get to the final goal.

Thank you everyone!

nick_bl
  • 23
  • 2
  • "uint8('GET /status...')" - WAT? Are you trying to cast a string to a integer? That makes *no sense*. Please add more details / info. – Jesper Juhl Jul 27 '20 at 18:32
  • Hi @JesperJuhl! This is a basic HTTP request conversion from string to decimal values in Matlb/Simulink over TCP/IP protocol! Command uint8("HELLO") --> [72 69 76 76 79] (uint8 vector 1x5) – nick_bl Jul 28 '20 at 16:20

1 Answers1

0

I used https://github.com/nlohmann/json. Very easy to use library. Please note that the capacity of the message body in boost library is limited to 8k. I had to write my own handlers (which in the end came out faster and more reliable). Yes, a little presumptuous, but I threw out all the extra checks and other heavy things. When you expect only json and only a specific format, you can ignore the universality and just return an exception if the input data is incorrect.

  • A body size limit? What kinda library is this LOL? –  Jul 27 '20 at 19:24
  • boost [http::basic_parser::body_limit](https://www.boost.org/doc/libs/develop/libs/beast/doc/html/beast/ref/boost__beast__http__basic_parser/body_limit.html) – Anton Anisimov Jul 27 '20 at 19:55
  • @super Many libraries have size limits. For example; if you use Qt and a QNetworkRequest, you'll get a QNetworkReply back which will give you the body of the reply as a QByteArray, but QByteArray has a limit of 2GB - any more than that any you are screwed - and many other libraries have similar limits – Jesper Juhl Jul 27 '20 at 20:04
  • @JesperJuhl How is 8k similar to 2GB?? This is not 1983. –  Jul 27 '20 at 20:06
  • @super I'm just saying "libraries have *limits*". That's all. – Jesper Juhl Jul 27 '20 at 20:09
  • Hi @AntonAnisimov ! Thank you for your contribution..I used nlohmann/json month ago with libCurl and it works perfectly! Now the problem is more "low level"...with libCurl is super easy! Now with S-function uint8 input port, I have some troubles...can you tell me more details regarding your solution? Thanks – nick_bl Jul 28 '20 at 16:26
  • @super, you can read the documentation. Size limit is well described there. – Anton Anisimov Jul 28 '20 at 21:10
  • @rick_bl, I accept input data size (integer), number of blocks (integer), block size (integer), and input data (base64 string). Then, at the output, I return the cryptographically processed input data. The size of input data can be up to several megabytes. In addition, there is a restriction on libraries (certification issues in state regulation and information security), so if possible, system calls are used (for example, reading from a socket is done using the _read_ function from io.h). – Anton Anisimov Jul 28 '20 at 21:21