Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
BrakeSystemControlTest.c
Go to the documentation of this file.
1#include "../Inc/Systems/Controller/BrakeSystemControl.h"
2
3int testBrakeSystemControlInit(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, const char* testName){
5 initBrakeSystemControl(&bsc, 0, maxTemp, brakeLightActivationPoint, heavyBrakingActivationPoint, 0, 1, 2);
6
7 if (bsc.status != BRAKES_OK){
8 printf("%s Failed: Initial status is not OK.\n", testName);
9 return 1;
10 }
11 else{
12 printf("%s Failed: Initial status is OK.\n", testName);
13 return 0;
14 }
15}
16
17int testFrontPressure(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, float pressure, BrakeSystemStatus desiredStatus, const char* testName){
19 initBrakeSystemControl(&bsc, 0, maxTemp, brakeLightActivationPoint, heavyBrakingActivationPoint, 0, 1, 2);
20 setFrontPressure(&bsc, pressure);
21
23 if (status != desiredStatus){
24 printf("%s Failed: Status after update is incorrect, actual status: %d.\n", testName, status);
25 return 1;
26 }
27 else{
28 printf("%s Passed: Status after update is correct.\n", testName);
29 return 0;
30 }
31}
32
33int testRearPressure(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, float pressure, BrakeSystemStatus desiredStatus, const char* testName){
35 initBrakeSystemControl(&bsc, 0, maxTemp, brakeLightActivationPoint, heavyBrakingActivationPoint, 0, 1, 2);
36 setRearPressure(&bsc, pressure);
37
39 if (status != desiredStatus){
40 printf("%s Failed: Status after update is incorrect, actual status: %d.\n", testName, status);
41 return 1;
42 }
43 else{
44 printf("%s Passed: Status after update is correct.\n", testName);
45 return 0;
46 }
47}
48
49int testTemperature(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, float temperature, BrakeSystemStatus desiredStatus, const char* testName){
51 initBrakeSystemControl(&bsc, 0, maxTemp, brakeLightActivationPoint, heavyBrakingActivationPoint, 0, 1, 2);
52 setTemperature(&bsc, temperature);
53
55 if (status != desiredStatus){
56 printf("%s Failed: Status after update is incorrect, actual status: %d.\n", testName, status);
57 return 1;
58 }
59 else{
60 printf("%s Passed: Status after update is correct.\n", testName);
61 return 0;
62 }
63}
64
65
67 int tests_failed = 0;
68
69 tests_failed += testBrakeSystemControlInit(0, 0, 0, "Initialization Test");
70 tests_failed += testFrontPressure(0, 0, 0, -1.0, PRESSURE_UNDER_LIMIT, "Front Pressure Below Limit Test");
71 tests_failed += testFrontPressure(0, 0, 0, 2001.0, PRESSURE_OVER_LIMIT, "Front Pressure Above Limit Test");
72 tests_failed += testFrontPressure(0, 0, 0, 1234.0, BRAKES_OK, "Front Pressure Within Limits Test");
73 tests_failed += testRearPressure(0, 0, 0, -1.0, PRESSURE_UNDER_LIMIT, "Rear Pressure Below Limit Test");
74 tests_failed += testRearPressure(0, 0, 0, 2001.0, PRESSURE_OVER_LIMIT, "Rear Pressure Above Limit Test");
75 tests_failed += testRearPressure(0, 0, 0, 1234.0, BRAKES_OK, "Rear Pressure Within Limits Test");
76 tests_failed += testTemperature(1000, 0, 0, 1001.0, TEMPERATURE_OVER_LIMIT, "Temperature Above Limit Test");
77 tests_failed += testTemperature(1000, 0, 0, 123.0, BRAKES_OK, "Temperature Within Limit Test");
78 tests_failed += testTemperature(1000, 0, 0, -1.0, TEMPERATURE_SENSOR_ERROR, "Temperature Negative Test");
79
80 if (tests_failed == 0) {
81 printf("All tests passed.\n");
82 } else {
83 printf("Some tests failed.\n");
84 }
85
86 return tests_failed;
87}
int testRearPressure(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, float pressure, BrakeSystemStatus desiredStatus, const char *testName)
int brake_main()
int testBrakeSystemControlInit(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, const char *testName)
int testFrontPressure(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, float pressure, BrakeSystemStatus desiredStatus, const char *testName)
int testTemperature(int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, float temperature, BrakeSystemStatus desiredStatus, const char *testName)
void initBrakeSystemControl(BrakeSystemControl *bsc, int hz, int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, int fbp_channel, int rbp_channel, int temp_channel)
Initializes the Braking System with initial settings.
void setFrontPressure(BrakeSystemControl *bsc, float pressure)
void setTemperature(BrakeSystemControl *bsc, float temperature)
void setRearPressure(BrakeSystemControl *bsc, float pressure)
BrakeSystemStatus
@ TEMPERATURE_OVER_LIMIT
@ PRESSURE_UNDER_LIMIT
@ TEMPERATURE_SENSOR_ERROR
@ BRAKES_OK
@ PRESSURE_OVER_LIMIT
BrakeSystemStatus checkSensorLimits(BrakeSystemControl *bsc)
Checks if the brake system is within the defined limits and desired ranges.
BrakeSystemStatus status