-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmds-test.c
74 lines (58 loc) · 1.26 KB
/
cmds-test.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libmicro/can.h>
#include "cmds.h"
#define LOOPBACK_MSGCOUNT 100
void test_loopback(int argc, char **argv)
{
can_message *msg;
int i;
printf( "* Activating loopback mode\n" );
can_setmode(loopback);
for(i=0; i<LOOPBACK_MSGCOUNT; i++) {
// sending message
msg = can_buffer_get();
msg->addr_src = 0x00;
msg->port_src = 0x23;
msg->addr_dst = 0x00;
msg->port_dst = 0x23;
msg->dlc = 2;
msg->data[0] = 0x00;
msg->data[1] = i;
can_transmit(msg);
msg = can_get_nb();
if (msg) {
printf( " * got msg!\n" );
}
}
printf( "* Deactivating loopback mode\n" );
can_setmode(loopback);
}
cmd_t test_cmds[] = {
{ &test_loopback, "loopback", "loopback", "Loopback test" },
{ NULL, NULL, NULL, NULL }
};
void cmd_test(int argc, char **argv)
{
char *arg = argv[1];
cmd_t *cmd;
cmd = test_cmds;
while(argc > 1 && cmd->fkt) {
if (strcmp(arg, cmd->cmd) == 0) {
(*(cmd->fkt))(argc-1, &(argv[1]));
goto done;
}
}
/* show help */
printf( "\nUsage: lapcontrol [OPTIONS] test <SUBCOMMAND>\n\n" );
printf( "Available Subcommands:\n\n" );
cmd = test_cmds;
while(cmd->fkt) {
printf( " %-30s %s\n", cmd->sig, cmd->desc );
cmd++;
}
printf( "\n" );
done:
return;
}