erpc icon indicating copy to clipboard operation
erpc copied to clipboard

Example on Linux

Open bhaktatejas922 opened this issue 5 years ago • 12 comments

Hi, I am pretty new to RPC/RPMsg and was wondering if you had any guidance on how to get a simple example setup on Linux?

I just wanted to send and receive a message through stdout/stdin and have been trying to get the example here to work: https://github.com/EmbeddedRPC/erpc/wiki/Getting-Started

Do you have any advice on how to handle the transport? Or are there any other examples/documentation somewhere. Apologies if this is a very simple question, I'm a bit of a beginner. Thanks!

bhaktatejas922 avatar Oct 05 '19 22:10 bhaktatejas922

Hi the link you provided has everything to create client/server application. For adding new transport you can read here: https://github.com/EmbeddedRPC/erpc/wiki/Porting-Guide. This second page is maybe not very descriptive but you can found examples here: https://github.com/EmbeddedRPC/erpc/tree/master/erpc_c/transports and setup functions here: https://github.com/EmbeddedRPC/erpc/tree/master/erpc_c/setup

It would be good to write which programming language are you using (python/C?).

Basically you need implement send/receive function (should be straightforward). Both need to be (at least in first implementation) blocking. So send will block application until message is send and receive until message is received. So you will need likely something like system mutex.

Other thing i can suggest are tests. Tests for eRPC are written for usage on Linux. Transport layer is tcp. You need only compile code and then run server app and then client app.

Hadatko avatar Oct 06 '19 06:10 Hadatko

Sorry I forgot to mention the language. I am using C. I'll look into the tests. Your response was very helpful, thank you!

bhaktatejas922 avatar Oct 06 '19 06:10 bhaktatejas922

Hi Hadatko,

Thanks for the advice, got the tests to work. Is there a way you know of to send a statically allocated struct? I saw your response here: https://github.com/EmbeddedRPC/erpc/issues/23 does this mean there is no way to send something statically allocated as of now?

bhaktatejas922 avatar Oct 07 '19 16:10 bhaktatejas922

Hi @bhaktatejas922 , please take a look here: #58. Is this suttisfying your question?

Hadatko avatar Oct 07 '19 20:10 Hadatko

Not exactly. I need to send a statically allocated struct (not an array), and I tried to do so with some modifications to the test_struct test. I tried to use TestString1 and statically allocate the primate struct on the client side as so in test_struct_client_impl.cpp

TEST(test_struct, TestString1)

{ static primate prim8; char str[] = "Ape"; prim8.species = &str[0]; prim8.is_ape = false; EXPECT_TRUE(checkString(&prim8) == 0); }

but the tests don't pass for this and it leaks on the server side and expects 2 values to be freed. I suspect there must be some internal erpc_malloc call I am missing that causes this.

Do you know of a better way to go about sending a statically allocated struct, or is it not possible at this time? I strictly need to send a statically allocated struct. Thanks!

bhaktatejas922 avatar Oct 08 '19 00:10 bhaktatejas922

I don't see reason why it would not work with only this modification. I did same and tests passed.

Hadatko avatar Oct 08 '19 06:10 Hadatko

image

Hadatko avatar Oct 08 '19 06:10 Hadatko

The checkString function in test_struct_server_impl.cpp calls erpc_free twice, and if you comment them out, you get the memory leak error

int32_t checkString(const primate *p) { int b = strcmp(p->species, "Ape"); printf("%s", p->species); //erpc_free(p->species); //erpc_free((void *)p); return b; } Screenshot from 2019-10-08 10-43-17

bhaktatejas922 avatar Oct 08 '19 15:10 bhaktatejas922

It doesn't matter how you are allocated space on client side. Server is always doing same allocation. It is based on IDL. Currently only dynamic i think.

Hadatko avatar Oct 08 '19 16:10 Hadatko

Any plans to have an implementation for statically allocated on server side? Embedded systems would have a good use for this.

bhaktatejas922 avatar Oct 15 '19 00:10 bhaktatejas922

@MichalPrincNXP I will let answer on you.

Hadatko avatar Oct 15 '19 04:10 Hadatko

Hi @bhaktatejas922 , you are correct that all struct allocations are dynamic in the generated server shim code. There is no option to change that unless you modify the shim code manually, which is not desired. I will put this requirement into the list of improvements but do not promise to implement it soon. If you would be willing to contribute to this project and prepare the pull request we would appreciate it. Thank you.

MichalPrincNXP avatar Oct 15 '19 11:10 MichalPrincNXP