@@ -26,10 +26,14 @@ int router_start(void);
26
26
27
27
/* Server port, the port the server listens on for incoming connections from the client. */
28
28
#define SERVER_PORT 10
29
+ #define SERVER_TC_PORT 13
30
+ #define SERVER_ACK_PORT 14
31
+ #define SERVER_STATUS_PORT 15
29
32
30
33
/* Commandline options */
31
34
static uint8_t server_address = 0 ;
32
35
static uint8_t client_address = 0 ;
36
+ static uint8_t bridge_address = 10 ;
33
37
34
38
/* Test mode, check that server & client can exchange packets */
35
39
static bool test_mode = false;
@@ -60,7 +64,7 @@ enum DeviceType {
60
64
static struct option long_options [] = {
61
65
{"kiss-device" , required_argument , 0 , 'k' },
62
66
#if (CSP_HAVE_LIBSOCKETCAN )
63
- #define OPTION_c "cb :"
67
+ #define OPTION_c "c:b :"
64
68
{"can-device" , required_argument , 0 , 'c' },
65
69
{"can-bps" , required_argument , 0 , 'b' },
66
70
#else
@@ -71,6 +75,8 @@ static struct option long_options[] = {
71
75
{"zmq-device" , required_argument , 0 , 'z' },
72
76
#define OPTION_f "f:"
73
77
{"can2zmq" , required_argument , 0 , 'f' },
78
+ #define OPTION_B "B:"
79
+ {"bridge" , required_argument , 0 , 'B' },
74
80
#else
75
81
#define OPTION_z
76
82
#endif
@@ -85,6 +91,7 @@ static struct option long_options[] = {
85
91
{"test-mode" , no_argument , 0 , 't' },
86
92
{"test-mode-with-sec" , required_argument , 0 , 'T' },
87
93
{"help" , no_argument , 0 , 'h' },
94
+ {"verbose" , no_argument , 0 , 'v' },
88
95
{0 , 0 , 0 , 0 }
89
96
};
90
97
@@ -99,16 +106,18 @@ void print_help() {
99
106
}
100
107
if (CSP_HAVE_LIBZMQ ) {
101
108
csp_print (" -z <zmq-device> set ZeroMQ device\n" );
102
- csp_print (" -f <0|1|2> 0:disable forwarding 1:CAN 2:CCSDS to ZMQ\n" );
109
+ csp_print (" -f <0|1|2|3 > 0:disable forwarding 1:CAN-RAW 2:CCSDS to ZMQ 3: CAN-CSP \n" );
103
110
}
104
111
if (CSP_USE_RTABLE ) {
105
112
csp_print (" -R <rtable> set routing table\n" );
106
113
}
107
114
if (1 ) {
108
115
csp_print (" -a <address> set interface address\n"
109
116
" -C <address> connect to server at address\n"
117
+ " -B <address> bridge to server at address\n"
110
118
" -t enable test mode\n"
111
119
" -T <duration> enable test mode with running time in seconds\n"
120
+ " -v Verbose\n"
112
121
" -h print help\n" );
113
122
}
114
123
}
@@ -171,9 +180,12 @@ int main(int argc, char * argv[]) {
171
180
char frame_buff [32 ];
172
181
char buffer [4096 ];
173
182
size_t alen = 0 ;
183
+ csp_iface_t * bridge_iface ;
184
+ // csp_socket_t bridge_sock = {0};
185
+ // csp_conn_t * bridge_conn;
174
186
// const uint32_t HEADER_SIZE = (csp_conf.version == 2) ? 6 : 4;
175
187
176
- while ((opt = getopt_long (argc , argv , OPTION_c OPTION_z OPTION_f OPTION_R "k:a:C:tT:h " , long_options , NULL )) != -1 ) {
188
+ while ((opt = getopt_long (argc , argv , OPTION_c OPTION_z OPTION_f OPTION_B OPTION_R "k:a:C:tT:hv " , long_options , NULL )) != -1 ) {
177
189
switch (opt ) {
178
190
case 'c' :
179
191
device_name = optarg ;
@@ -194,6 +206,10 @@ int main(int argc, char * argv[]) {
194
206
forwarding = atoi (optarg );
195
207
csp_print ("Forwarding: %d\n" ,forwarding );
196
208
break ;
209
+ case 'B' :
210
+ bridge_address = atoi (optarg );
211
+ csp_print ("Bridging: %d\n" ,bridge_address );
212
+ break ;
197
213
#if (CSP_USE_RTABLE )
198
214
case 'R' :
199
215
rtable = optarg ;
@@ -212,6 +228,9 @@ int main(int argc, char * argv[]) {
212
228
test_mode = true;
213
229
run_duration_in_sec = atoi (optarg );
214
230
break ;
231
+ case 'v' :
232
+ csp_dbg_packet_print = true;
233
+ break ;
215
234
case 'h' :
216
235
print_help ();
217
236
exit (EXIT_SUCCESS );
@@ -265,12 +284,21 @@ int main(int argc, char * argv[]) {
265
284
ccsds_addr .sin_addr .s_addr = inet_addr (ip );
266
285
//#2 : binding the socket
267
286
268
- if (bind (sockfd , (struct sockaddr * )& ccsds_addr , sizeof (ccsds_addr ))< 0 )
287
+ if (bind (sockfd , (struct sockaddr * )& ccsds_addr , sizeof (ccsds_addr ))< 0 )
269
288
{
270
289
perror ("UDP binding" );
271
290
exit (EXIT_FAILURE );
272
291
}
273
292
293
+ break ;
294
+ case 3 :
295
+ int error = csp_can_socketcan_open_and_add_interface ("can0" , CSP_IF_CAN_DEFAULT_NAME , bridge_address , 125000 , true, 0xFFFF , 0x0000 , & bridge_iface );
296
+ if (error != CSP_ERR_NONE ) {
297
+ csp_print ("failed to add CAN interface [%s], error: %d\n" , "can0" , error );
298
+ exit (1 );
299
+ }
300
+ // bridge_iface->is_default = 1;
301
+ csp_rtable_set (client_address , 0 , bridge_iface , bridge_address );
274
302
break ;
275
303
default :
276
304
break ;
@@ -287,6 +315,8 @@ int main(int argc, char * argv[]) {
287
315
/* Add interface(s) */
288
316
default_iface = add_interface (device_type , device_name );
289
317
318
+ // csp_bridge_set_interfaces(bridge_iface , default_iface);
319
+
290
320
/* Setup routing table */
291
321
if (CSP_USE_RTABLE ) {
292
322
if (rtable ) {
@@ -321,17 +351,21 @@ int main(int argc, char * argv[]) {
321
351
322
352
usleep (test_mode ? 200000 : 1000000 );
323
353
324
- /* Send ping to server, timeout 1000 mS, ping size 100 bytes */
325
- int result = csp_ping (server_address , 1000 , 100 , CSP_O_NONE );
354
+ /* Send ping to server, timeout 1000 mS, ping size 10 bytes */
355
+ int result = csp_ping (server_address , 1000 , 10 , CSP_O_NONE );
326
356
csp_print ("Ping address: %u, result %d [mS]\n" , server_address , result );
327
357
// Increment successful_ping if ping was successful
328
358
if (result >= 0 ) {
329
359
++ successful_ping ;
330
- }
360
+ }
361
+ else
362
+ {
363
+ continue ;
364
+ }
331
365
332
366
/* Send reboot request to server, the server has no actual implementation of csp_sys_reboot() and fails to reboot */
333
- csp_reboot (server_address );
334
- csp_print ("reboot system request sent to address: %u\n" , server_address );
367
+ // csp_reboot(server_address);
368
+ // csp_print("reboot system request sent to address: %u\n", server_address);
335
369
336
370
/* Send data packet (string) to server */
337
371
@@ -381,6 +415,10 @@ int main(int argc, char * argv[]) {
381
415
csp_print ("%02X " , (uint8_t )buffer [i ]);
382
416
alen += sprintf (frame_buff + alen , "%02X" , (uint8_t ) buffer [i ]);
383
417
}
418
+ break ;
419
+ case 3 :
420
+ csp_bridge_work ();
421
+
384
422
break ;
385
423
default :
386
424
alen = sprintf (frame_buff , "%03X#" , 0x200 & 0xfff );
0 commit comments