forked from EmbeddedRPC/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Cervenka Dusan <[email protected]>
- Loading branch information
Showing
17 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ mdk | |
lpcx | ||
mcux | ||
tags | ||
shim | ||
|
||
format-files-to-commit.rb | ||
language\.settings\.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#define ERPC_HOSTNAME "localhost" | ||
#define ERPC_PORT 8811 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/python3 | ||
|
||
def loadConfig(path: str = "config.h"): | ||
''' Load config macros from C header file''' | ||
retVal = {} | ||
|
||
with open(path, "r") as file: | ||
configContext = file.read().split("#define ")[1:] | ||
for c in configContext: | ||
cfg = c.split(" ") | ||
if len(cfg) > 1: | ||
val = cfg[1][:-1].replace("\"","") | ||
retVal[cfg[0]] = val | ||
|
||
return retVal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Hello world example | ||
|
||
This example shows basic usage of eRPC framework. | ||
|
||
## Prerequisites | ||
|
||
Run these commands in this folder based on needs with correct path to erpcgen application | ||
|
||
C/C++ shim code: | ||
|
||
```bash | ||
erpcgen -gc -o shim/py hello_world.erpc | ||
``` | ||
|
||
Python shim code: | ||
|
||
```bash | ||
erpcgen -gpy -o shim/py hello_world.erpc | ||
``` | ||
|
||
In case of C/C++ build application | ||
|
||
## Run example | ||
|
||
First run server, then client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "erpc_c/setup/erpc_client_setup.h" | ||
#include "erpc_c/setup/erpc_transport_setup.h" | ||
#include "erpc_c/setup/erpc_mbf_setup.h" | ||
#include "examples/hello_world/shim/c/c_hello_world_client.h" | ||
#include "examples/config.h" | ||
|
||
int main() | ||
{ | ||
erpc_transport_t transport; | ||
erpc_mbf_t message_buffer_factory; | ||
erpc_client_t client_manager; | ||
|
||
/* Init eRPC client infrastructure */ | ||
transport = erpc_transport_tcp_init(ERPC_HOSTNAME, ERPC_PORT, false); | ||
message_buffer_factory = erpc_mbf_dynamic_init(); | ||
client_manager = erpc_client_init(transport, message_buffer_factory); | ||
|
||
/* init eRPC client TextService service */ | ||
initTextService_client(client_manager); | ||
|
||
/* do eRPC call */ | ||
printText("Hello world!"); | ||
|
||
/* deinit objects */ | ||
deinitTextService_client(); | ||
erpc_client_deinit(client_manager); | ||
erpc_mbf_dynamic_deinit(message_buffer_factory); | ||
erpc_transport_tcp_deinit(transport); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "erpc_c/setup/erpc_client_setup.h" | ||
#include "erpc_c/setup/erpc_transport_setup.h" | ||
#include "erpc_c/setup/erpc_mbf_setup.h" | ||
#include "examples/hello_world/shim/c/hello_world_client.hpp" | ||
#include "examples/config.h" | ||
|
||
int main() | ||
{ | ||
erpc_transport_t transport; | ||
erpc_mbf_t message_buffer_factory; | ||
erpc_client_t client_manager; | ||
|
||
/* Init eRPC client infrastructure */ | ||
transport = erpc_transport_tcp_init(ERPC_HOSTNAME, ERPC_PORT, false); | ||
message_buffer_factory = erpc_mbf_dynamic_init(); | ||
client_manager = erpc_client_init(transport, message_buffer_factory); | ||
|
||
/* scope for client service */ | ||
{ | ||
/* init eRPC client TextService service */ | ||
TextService_client client(client_manager); | ||
|
||
/* do eRPC call */ | ||
client.printText("Hello world!"); | ||
} | ||
|
||
/* deinit objects */ | ||
erpc_client_deinit(client_manager); | ||
erpc_mbf_dynamic_deinit(message_buffer_factory); | ||
erpc_transport_tcp_deinit(transport); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "erpc_c/setup/erpc_server_setup.h" | ||
#include "erpc_c/setup/erpc_transport_setup.h" | ||
#include "erpc_c/setup/erpc_mbf_setup.h" | ||
#include "examples/hello_world/shim/c/c_hello_world_server.h" | ||
#include "examples/config.h" | ||
#include <cstdio> | ||
|
||
/* eRPC call definition */ | ||
void printText(const char *text) { printf("%s", text); } | ||
|
||
int main() | ||
{ | ||
erpc_transport_t transport; | ||
erpc_mbf_t message_buffer_factory; | ||
erpc_server_t server; | ||
erpc_service_t service = create_TextService_service(); | ||
|
||
/* Init eRPC server infrastructure */ | ||
transport = erpc_transport_tcp_init(ERPC_HOSTNAME, ERPC_PORT, true); | ||
message_buffer_factory = erpc_mbf_dynamic_init(); | ||
server = erpc_server_init(transport, message_buffer_factory); | ||
|
||
/* add custom service implementation to the server */ | ||
erpc_add_service_to_server(server, service); | ||
|
||
/* poll for requests */ | ||
erpc_status_t err = server.poll(); | ||
|
||
/* deinit objects */ | ||
destroy_TextService_service(service); | ||
erpc_server_deinit(server); | ||
erpc_mbf_dynamic_deinit(message_buffer_factory); | ||
erpc_transport_tcp_deinit(transport); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "erpc_c/setup/erpc_server_setup.h" | ||
#include "erpc_c/setup/erpc_transport_setup.h" | ||
#include "erpc_c/setup/erpc_mbf_setup.h" | ||
#include "examples/hello_world/shim/c/hello_world_server.hpp" | ||
#include "examples/config.h" | ||
#include <cstdio> | ||
|
||
class TextService : public TextService_interface | ||
{ | ||
/* eRPC call definition */ | ||
void printText(const char *text) override { printf("%s", text); } | ||
} | ||
|
||
int main() | ||
{ | ||
erpc_transport_t transport; | ||
erpc_mbf_t message_buffer_factory; | ||
erpc_server_t server; | ||
TextService textServiceImpl; | ||
TextService_service textService(&textServiceImpl); | ||
|
||
/* Init eRPC server infrastructure */ | ||
transport = erpc_transport_tcp_init(ERPC_HOSTNAME, ERPC_PORT, true); | ||
message_buffer_factory = erpc_mbf_dynamic_init(); | ||
server = erpc_server_init(transport, message_buffer_factory); | ||
|
||
/* add custom service implementation to the server */ | ||
erpc_add_service_to_server(server, &textService); | ||
|
||
/* poll for requests */ | ||
erpc_status_t err = server.poll(); | ||
|
||
/* deinit objects */ | ||
erpc_server_deinit(server); | ||
erpc_mbf_dynamic_deinit(message_buffer_factory); | ||
erpc_transport_tcp_deinit(transport); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface TextService | ||
{ | ||
oneway printText(string text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/python3 | ||
import sys | ||
|
||
sys.path.insert(1, '../../../erpc_python') # nopep8 | ||
sys.path.insert(2, '../../') # nopep8 | ||
sys.path.insert(3, '../') # nopep8 | ||
|
||
import erpc | ||
import config | ||
from shim.py import hello_world | ||
|
||
|
||
def main(): | ||
# load configuration macros from C header file | ||
cfg = config.loadConfig("../../config.h") | ||
|
||
# init eRPC client infrastructure | ||
transport = erpc.transport.TCPTransport(cfg["ERPC_HOSTNAME"], int(cfg["ERPC_PORT"]), False) | ||
clientManager = erpc.client.ClientManager(transport, erpc.basic_codec.BasicCodec) | ||
|
||
# init eRPC client | ||
client = hello_world.client.TextServiceClient(clientManager) | ||
|
||
# do eRPC call | ||
client.printText("Hello world!") | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/python3 | ||
import sys | ||
|
||
sys.path.insert(1, '../../../erpc_python') # nopep8 | ||
sys.path.insert(2, '../../') # nopep8 | ||
sys.path.insert(3, '../') # nopep8 | ||
|
||
import erpc | ||
import config | ||
from shim.py import hello_world | ||
|
||
class MatrixMultiplyServiceHandler(hello_world.interface.ITextService): | ||
def printText(self, text): | ||
'''eRPC call definition''' | ||
|
||
print(text) | ||
|
||
|
||
def main(): | ||
# load configuration macros from C header file | ||
cfg = config.loadConfig("../../config.h") | ||
|
||
# init service | ||
handler = MatrixMultiplyServiceHandler() | ||
service = hello_world.server.TextServiceService(handler) | ||
|
||
# init eRPC server infrastructure | ||
transport = erpc.transport.TCPTransport(cfg["ERPC_HOSTNAME"], int(cfg["ERPC_PORT"]), True) | ||
server = erpc.simple_server.SimpleServer(transport, erpc.basic_codec.BasicCodec) | ||
server.add_service(service) | ||
|
||
# run server | ||
try: | ||
server.run() | ||
except: | ||
pass | ||
|
||
main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.