-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathmain_client.c
114 lines (91 loc) · 2.92 KB
/
main_client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright 2024 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "erpc_client_setup.h"
#include "c_erpc_matrix_multiply_client.h"
#include "erpc_matrix_multiply_common.h"
#include "erpc_client_setup.h"
#include "erpc_transport_setup.h"
#include "erpc_mbf_setup.h"
#include "stdio.h"
#include "stdlib.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define MATRIX_ITEM_MAX_VALUE (50)
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Fill matrices by random values
*/
static void fill_matrices(Matrix matrix1_ptr, Matrix matrix2_ptr)
{
int32_t a, b;
/* Fill both matrices by random values */
for (a = 0; a < matrix_size; ++a)
{
for (b = 0; b < matrix_size; ++b)
{
matrix1_ptr[a][b] = rand() % MATRIX_ITEM_MAX_VALUE;
matrix2_ptr[a][b] = rand() % MATRIX_ITEM_MAX_VALUE;
}
}
}
/*!
* @brief Printing a matrix to the console
*/
static void print_matrix(Matrix matrix_ptr)
{
int32_t a, b;
for (a = 0; a < matrix_size; ++a)
{
for (b = 0; b < matrix_size; ++b)
{
printf("%4i ", matrix_ptr[a][b]);
}
printf("\r\n");
}
}
int main()
{
Matrix matrix1 = {0}, matrix2 = {0}, result_matrix = {0};
erpc_transport_t transport;
erpc_mbf_t message_buffer_factory;
erpc_client_t client_manager;
/* Init eRPC client infrastructure */
transport = erpc_transport_tcp_init(EXAMPLE_TCP_HOST, EXAMPLE_TCP_PORT, false);
message_buffer_factory = erpc_mbf_dynamic_init();
client_manager = erpc_client_init(transport, message_buffer_factory);
/* Init eRPC client TextService service */
initMatrixMultiplyService_client(client_manager);
char option;
do
{
/* Do eRPC call */
fill_matrices(matrix1, matrix2);
printf("\r\nMatrix #1");
printf("\r\n=========\r\n");
print_matrix(matrix1);
printf("\r\nMatrix #2");
printf("\r\n=========\r\n");
print_matrix(matrix2);
printf("\r\neRPC request is sent to the server\r\n");
erpcMatrixMultiply(matrix1, matrix2, result_matrix);
printf("\r\nResult matrix");
printf("\r\n=============\r\n");
print_matrix(result_matrix);
printf("Press Enter to initiate the next matrix multiplication or 'q' to quit\n");
option = getchar ();
while(option != '\n' && getchar() != '\n');
} while (option != 'q');
quitServer();
/* Deinit objects */
deinitMatrixMultiplyService_client();
erpc_client_deinit(client_manager);
erpc_mbf_dynamic_deinit(message_buffer_factory);
erpc_transport_tcp_close(transport);
erpc_transport_tcp_deinit(transport);
}