/
cen-electronic-console.c
108 lines (90 loc) · 4.29 KB
/
cen-electronic-console.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "common/delay/cenDelay.h"
#include "main/mainBoard/mainBoardPc.h"
#include "main/motorboard/motorBoardPc.h"
#include "main/meca1/mechanicalMainBoard1Pc.h"
#include "test/allTests.h"
#include "common/pc/process/processHelper.h"
void printUsage(void) {
printf("ROBOT EMULATOR for cen-electronic projects : \r\n");
printf("cen-electronic-console.exe [BOARD_NAME] [OPTION]\r\n");
// MainBoard
printf("\t[BOARD_NAME]\t Select the board that you want to launch by providing name in the following list\r\n");
printf("\t\t\t");
printf(MAIN_BOARD_PC_NAME);
printf(" \t : run the main Board Emulator\r\n");
printf("\t\t\t\t [OPTION] robotManager : launch the mainBoard with a connection to RobotManager\r\n");
// MotorBoard
printf("\t\t\t");
printf(MOTOR_BOARD_PC_NAME);
printf("\t : run the motor Board Emulator\r\n");
printf("\t\t\t\t [OPTION] single : just launch motorBoard without initializing I2C to connect it to a master\r\n");
// All Tests
printf("\t\t\t");
printf(ALL_TESTS_NAME);
printf("\t : run All Tests\r\n");
}
int main(int argumentCount, char* arguments[]) {
char* applicationNameAsChar = arguments[0];
if (argumentCount <= 1) {
// Run the Motor Board
char motorBoardOptionCommand[255];
strcpy_s(motorBoardOptionCommand, _countof(motorBoardOptionCommand), MOTOR_BOARD_PC_NAME);
strcat_s(motorBoardOptionCommand, _countof(motorBoardOptionCommand), " ");
strcat_s(motorBoardOptionCommand, _countof(motorBoardOptionCommand), MOTOR_BOARD_PC_RUN_STANDARD);
runProcess(applicationNameAsChar, motorBoardOptionCommand);
// Run the Mecanical Board 1
char mechanical1OptionCommand[255];
strcpy_s(mechanical1OptionCommand, _countof(mechanical1OptionCommand), MECHANICAL_BOARD_1_PC_NAME);
strcat_s(mechanical1OptionCommand, _countof(mechanical1OptionCommand), " ");
strcat_s(mechanical1OptionCommand, _countof(mechanical1OptionCommand), MECHANICAL_BOARD_1_PC_RUN_STANDARD);
runProcess(applicationNameAsChar, mechanical1OptionCommand);
// And After the main Board
runMainBoardPC(false, false);
delayMilliSecs(10);
} else {
char* boardName = arguments[1];
if (strcmp(boardName, MAIN_BOARD_PC_NAME) == 0) {
bool robotManager = false;
bool singleMode = false;
if (argumentCount > 2) {
char* mainBoardRunMode = arguments[2];
robotManager = (strcmp(mainBoardRunMode, MAIN_BOARD_PC_ROBOT_MANAGER) == 0);
singleMode = (strcmp(mainBoardRunMode, MOTOR_BOARD_PC_RUN_SINGLE) == 0);
/*
char motorBoardOptionCommand[255];
strcpy_s(motorBoardOptionCommand, _countof(motorBoardOptionCommand), MOTOR_BOARD_PC_NAME);
strcat_s(motorBoardOptionCommand, _countof(motorBoardOptionCommand), " ");
strcat_s(motorBoardOptionCommand, _countof(motorBoardOptionCommand), MOTOR_BOARD_PC_RUN_STANDARD);
runProcess(applicationNameAsChar, motorBoardOptionCommand);
*/
}
// In all cases
runMainBoardPC(robotManager, singleMode);
} else if (strcmp(boardName, MOTOR_BOARD_PC_NAME) == 0) {
bool singleMode = false;
if (argumentCount > 2) {
char* motorBoardRunMode = arguments[2];
singleMode = (strcmp(motorBoardRunMode, MOTOR_BOARD_PC_RUN_SINGLE) == 0);
}
runMotorBoardPC(singleMode);
} else if (strcmp(boardName, MECHANICAL_BOARD_1_PC_NAME) == 0) {
bool singleMode = false;
if (argumentCount > 2) {
char* mechanicalBoard1RunMode = arguments[2];
singleMode = (strcmp(mechanicalBoard1RunMode, MOTOR_BOARD_PC_RUN_SINGLE) == 0);
}
runMechanicalBoard1PC(singleMode);
} else if (strcmp(boardName, ALL_TESTS_NAME) == 0) {
runAllTests();
} else {
printUsage();
return EXIT_FAILURE;
}
}
char c = getchar();
return EXIT_SUCCESS;
}