-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
86 lines (74 loc) · 2.49 KB
/
main.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
#include <pthread.h>
#include "board.h"
#include "cli.h"
#include "swsys.h"
#include "xml_inline.h"
swsys_t core_sys;
int catpilot(void);
#define SWSYS_COMMANDER_MAX_CMD_LENGTH 128
static char swsys_cmd[SWSYS_COMMANDER_MAX_CMD_LENGTH];
static char *swsys_cmd_offset;
static swsys_t *swsys_commander_ptr;
swsys_rv_t swsys_commander_init(swsys_t *swsys) {
if (swsys != NULL) {
swsys_commander_ptr = swsys;
return swsys_e_ok;
}
return swsys_e_invargs;
}
int swsys_commander(int argc, char **argv) {
if (argc < 3) {
dbg_msg("Usage: swsys [task] func_name=[func] [param_alias]=[value]");
return 0;
}
if (swsys_commander_ptr == NULL) {
dbg_msg("swsys_commander is not initialized");
return 0;
}
swsys_cmd_offset = swsys_cmd;
for (int i = 2; i < argc; i++) {
if (swsys_cmd_offset > swsys_cmd + SWSYS_COMMANDER_MAX_CMD_LENGTH) {
dbg_msg("Command exceeds max length");
return 0;
}
strncpy(swsys_cmd_offset, argv[i],
swsys_cmd + SWSYS_COMMANDER_MAX_CMD_LENGTH - swsys_cmd_offset);
swsys_cmd_offset += strnlen(argv[i], SWSYS_COMMANDER_MAX_CMD_LENGTH);
swsys_cmd_offset[0] = ' ';
swsys_cmd_offset++;
}
swsys_rv_t rv = swsys_set_params(swsys_commander_ptr, argv[1], swsys_cmd);
if (rv != swsys_e_ok) {
dbg_msg("Wrong command");
dbg_msg("Usage: swsys [task] func_name=[func] [param_alias]=[value]");
} else {
dbg_msg("Command accepted");
}
return 0;
}
int main(void) {
board_start(catpilot, 8192, CLI_PORT, CLI_BAUDRATE);
while (1) {
}
}
int catpilot(void) {
pthread_setname_np((char *)__func__);
xml_inline_mount("/cfg");
cli_cmd_reg("swsys", swsys_commander);
swsys_rv_t swsys_rv = swsys_load("/cfg/swsys.xml", "/cfg", &core_sys);
swsys_rv_t swsys_cmd_rv = swsys_commander_init(&core_sys);
if (swsys_rv == swsys_e_ok && swsys_cmd_rv == swsys_e_ok) {
printf("SWSYS \"%s\" loaded\n",
core_sys.name != NULL ? core_sys.name : "no name");
LOG_INFO("SYSTEM", "Configuration loading successful");
swsys_rv = swsys_top_module_start(&core_sys);
if (swsys_rv != swsys_e_ok) {
LOG_ERROR("SYSTEM", "Module start error");
printf("SWSYS \"%s\" failed to start\n",
core_sys.name != NULL ? core_sys.name : "no name");
}
} else {
LOG_ERROR("SYSTEM", "Configuration loading error");
}
return -1;
}