background
ADAS engineers in OEM use Matlab/Simulink(model based design) to develop the adas algorithms, e.g. aeb. Simulink way is enough for fuction verification in L2 and below; for L2+ scenario, often need to test these adas functions in system level, basically test it in scenarios as much as possible, kind of L3 requirements.
one way to do sytem level verification is through replay, basically the test vehicle fleet can collect large mount of data, then feed in a test pipeline, to check if these adas functions are triggered well or missed.
for replay system test, we handle large mount of data, e.g. Pb, so the Simulink model run is too slow. the adas test pipeline with the ability to run massively is required.
the previous blog high concurrent ws server mentioned about the archetecture of this massively adas test pipeline: with each adas model integrated with a websocket client, and all of these ws clients talk to a websocekt server, which has api to write database.
encode in C
the adas simulink model can be encode in c, which of course can encode as c++, while not powerful yet. as in C is more scalable then simulink/matlab.
matlab/simulink encode has a few choices, massively run is mostly in Linux-like os, here we choose ert
env to encode the model, after we can build and test as:
|
|
json-c
as all messages in adas model in c
is stored in program memory, first thing is to serialize these to json. here we choose json-c:
- install on local Ubuntu
|
|
then the json-c header is at:
/usr/local/include/json-c
and the libs at:
/usr/local/lib/libjson-c.so *.al
when using we can add the following flags:
|
|
the json object can be created as:
|
|
modern c++ json libs are more pretty, e.g. jsoncpp, rapidJSON, json for modern c++
wsclient-c
the first ws client I tried is: wsclient in c, with default install, can find the headers and libs, separately at:
|
|
when using:
|
|
onopen()
as we need send custom message through this client, and the default message was sent inside onopen()
, I have to add additionaly argument char\*
into the default function pointer onopen
|
|
and the onopen callback is actually excuted inside handshake thread, in which is not legacy to pass char* message. further as there is no global alive status to tell the client-server channel is alive, to call libwsclient_send()
in another thread sounds trouble-possible.
looks wsclient-c is limited, I transfer to wsclient c++. but need make sure model in c
workable with g++
.
wsclient c++
websocketpp is a header only C++ library, there is no libs
after built, but it is depends on boost
, so to use this lib, we can add header and libs as following:
|
|
I am using the wsclient from sample, and define a public method as the client process:
|
|
there is more elegent retry client solution.
to build our wsclient:
|
|
the simple orm db_writer
is from sqlalchemy model.
in makefile
|
|
so now we have encode adas simulink model to C code, and integrate this model C with a websocket client, which can talk to a ws server, which further write to database, which further can be used an data analysis model.
we can add front-end web UI and system monitor UI if needed, but so far this adas test pipeline can support a few hundred adas test cores to run concurrently.