diff --git a/.clang-format b/.clang-format index 4e72a65e..17e14d8f 100644 --- a/.clang-format +++ b/.clang-format @@ -90,10 +90,6 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left -RawStringFormats: - - Delimiter: pb - Language: TextProto - BasedOnStyle: google ReflowComments: true SortIncludes: true SortUsingDeclarations: true diff --git a/.gitignore b/.gitignore index 970a7701..52902cb0 100644 --- a/.gitignore +++ b/.gitignore @@ -267,3 +267,6 @@ cmake-build-debug/ # Autocoder Python *.pyc + +# c compile json +compile_commands.json diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index aa305cff..eedff312 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -3,6 +3,8 @@ project(testlib VERSION 1.0 LANGUAGES CXX) # Define sources +set(dependencies example/Test_GTest.cpp) +set(dependencies components/HV_Iox/Test_HV_Iox.cpp) set(dependencies example/Test_GTest.cpp run_profiles/Test_load_software_parameters.cpp) diff --git a/Test/components/HV_Iox/Test_HV_Iox.cpp b/Test/components/HV_Iox/Test_HV_Iox.cpp new file mode 100644 index 00000000..d89636e8 --- /dev/null +++ b/Test/components/HV_Iox/Test_HV_Iox.cpp @@ -0,0 +1,77 @@ +// Author: Marco +#include +#include + +TEST(HV_IOX, VerifyHVIox) +{ + HVIox hv_iox; + hv_iox.init(true); + EXPECT_EQ(hv_iox.setupIox(), 0); +// The expected output of the functions is generic +// when not connected to the I2C bus +#ifdef NOI2C + // expected to equal 1 + EXPECT_EQ(hv_iox.isHVIndicatorEnabled(), 1); +// The expected output of the functions is +// != -1 because the function returns +// the getState method when connected +// to the I2C bus +#else + // expected to not equal -1 + hv_iox.setMCUHVEnabled(false); + EXPECT_NE(hv_iox.isHVIndicatorEnabled(), -1); +#endif +} + +TEST(HV_IOX, HVIOX_MCU_LATCH) +{ + HVIox hv_iox; + hv_iox.init(true); +#ifdef NOI2C + EXPECT_EQ(hv_iox.setMCULatch(true), 0); + EXPECT_EQ(hv_iox.setMCULatch(false), 0); +#else + EXPECT_EQ(hv_iox.setMCULatch(true), 1); + EXPECT_EQ(hv_iox.setMCULatch(false), 1); +#endif +} + +TEST(HV_IOX, HVIOX_STATES) +{ + HVIox hv_iox; + hv_iox.init(true); +#ifdef NOI2C + EXPECT_EQ(hv_iox.getBMSMultiIn(), 1); + EXPECT_EQ(hv_iox.getIMDStatus(), 1); + EXPECT_EQ(hv_iox.getINRTStatus(), 1); + EXPECT_EQ(hv_iox.isHVEnabled(), 0); + EXPECT_EQ(hv_iox.getPsStatus(), 1); + EXPECT_EQ(hv_iox.getBMSStatus(), 1); + EXPECT_EQ(hv_iox.isEStopOn(), 0); + EXPECT_EQ(hv_iox.getMasterSwFeedback(), 1); +#else + EXPECT_NE(hv_iox.getBMSMultiIn(), -1); + EXPECT_EQ(hv_iox.getIMDStatus(), true); + EXPECT_NE(hv_iox.getINRTStatus(), -1); + EXPECT_NE(hv_iox.isHVEnabled(), -1); + EXPECT_NE(hv_iox.getPsStatus(), -1); + EXPECT_NE(hv_iox.getBMSStatus(), -1); + EXPECT_NE(hv_iox.isEStopOn(), -1); + EXPECT_NE(hv_iox.getMasterSwFeedback(), -1); +#endif +} + +TEST(HV_IOX, HVIOX_MCUHV) +{ + HVIox hv_iox; + hv_iox.init(true); +#ifdef NOI2C + EXPECT_EQ(hv_iox.setMCUHVEnabled(true), 1); + EXPECT_EQ(hv_iox.isMCUHVEnabled(), 1); + EXPECT_EQ(hv_iox.emergencyDisableMCU(), 1); +#else + EXPECT_NE(hv_iox.setMCUHVEnabled(true), -1); + EXPECT_NE(hv_iox.isMCUHVEnabled(), -1); + EXPECT_NE(hv_iox.emergencyDisableMCU(), -1); +#endif +} diff --git a/Test/run_all_tests.cpp b/Test/run_all_tests.cpp index 2f8768d5..0d486308 100644 --- a/Test/run_all_tests.cpp +++ b/Test/run_all_tests.cpp @@ -1,11 +1,15 @@ #include "gtest_globals.h" #include -char executable_path[128]; +extern "C" { +#include +} +char executable_path[128]; // Run all GTest Tests int main(int argc, char** argv) { + initData(); // Set executable path strcpy(executable_path, argv[0]); diff --git a/autocoding/templates/TelemetryLoop.template.cpp b/autocoding/templates/TelemetryLoop.template.cpp index c48f713a..f87ae63d 100644 --- a/autocoding/templates/TelemetryLoop.template.cpp +++ b/autocoding/templates/TelemetryLoop.template.cpp @@ -12,9 +12,8 @@ #include #include -extern "C" { -#include #include +extern "C" { #include } @@ -96,7 +95,7 @@ void* TelemetryLoop(void* arg) addToBuffer(&buffer, &time); // Write 1 byte IMD status - uint8_t imdStatus = getIMDStatus(); + uint8_t imdStatus = hv_iox.getIMDStatus(); addToBuffer(&buffer, &imdStatus); // Write 4 byte primary brake @@ -139,4 +138,4 @@ void* TelemetryLoop(void* arg) cerr << e.what() << endl; exit(1); } -} \ No newline at end of file +} diff --git a/embedded/app/CMakeLists.txt b/embedded/app/CMakeLists.txt index 84a6a3d0..c3c00961 100644 --- a/embedded/app/CMakeLists.txt +++ b/embedded/app/CMakeLists.txt @@ -7,14 +7,14 @@ project(applib VERSION 1.0 #and it's SUPER discouraged. set(dependecies src/bms_fault_checking.c src/nav.c - src/state_machine.c + src/state_machine.cpp src/init.c src/load_software_parameters.c src/pressure_fault_checking.c - src/states.c - src/motor.c + src/states.cpp + src/motor.cpp src/rms_fault_checking.c - src/transitions.c) + src/transitions.cpp) #required libraries for the main pod executables set(libraries middleware diff --git a/embedded/app/main/badgerloop.cpp b/embedded/app/main/badgerloop.cpp index bda8f891..0e70e064 100644 --- a/embedded/app/main/badgerloop.cpp +++ b/embedded/app/main/badgerloop.cpp @@ -1,42 +1,45 @@ // Includes #include "HVTCPSocket.h" #include "data_dump.h" +#include "hv_iox.h" +#include "motor.h" +#include "state_machine.h" #include #include #include #include #include +#include "hv_iox.h" +#include "state_machine.h" +#include "motor.h" // Temp #include #include #include -extern "C" -{ - #include "bbgpio.h" - #include "connStat.h" - #include - #include - #include "motor.h" - #include "hv_iox.h" - #include "motor.h" - #include "proc_iox.h" - #include "data.h" - #include "can_devices.h" - #include "state_machine.h" - #include "NCD9830DBR2G.h" - #include "nav.h" - - // Software Parameter Loading - #include "load_software_parameters.h" - #include "software_parameters.h" +extern "C" { +#include "NCD9830DBR2G.h" +#include "bbgpio.h" +#include "can_devices.h" +#include "connStat.h" +#include "data.h" +#include "nav.h" +#include "proc_iox.h" +#include +#include + +// Software Parameter Loading +#include "load_software_parameters.h" +#include "software_parameters.h" } +HVIox hv_iox; + void emergQuitter(int sig, siginfo_t* inf, void* nul) { printf("shutdown\n"); - setMCUHVEnabled(false); + hv_iox.setMCUHVEnabled(false); rmsCmdNoTorque(); sleep(1); rmsDischarge(); @@ -67,7 +70,7 @@ int init(char* directory) success_status = 1; } - if (initHVIox(true)) { + if (hv_iox.init(true)) { success_status = 1; } @@ -85,7 +88,7 @@ int init(char* directory) initNav(); - struct sigaction sig; + struct sigaction sig; sig.sa_sigaction = emergQuitter; sigaction(SIGINT, &sig, NULL); diff --git a/embedded/app/src/init.c b/embedded/app/src/init.c index 04817fcb..d4d5fc83 100644 --- a/embedded/app/src/init.c +++ b/embedded/app/src/init.c @@ -33,210 +33,190 @@ int isEarlyInit() data_t* data; -/* Autogenerated Code Begins */ -int initMetaData() -{ - if ((data = (data_t*)malloc(sizeof(data_t))) == NULL) { - return 1; - } - if ((data->pressure = (pressure_t*)malloc(sizeof(pressure_t))) == NULL) { - return 1; - } - if ((data->motion = (motion_t*)malloc(sizeof(motion_t))) == NULL) { - return 1; - } - if ((data->bms = (bms_t*)malloc(sizeof(bms_t))) == NULL) { - return 1; - } - if ((data->rms = (rms_t*)malloc(sizeof(rms_t))) == NULL) { - return 1; - } - if ((data->flags = (flags_t*)malloc(sizeof(flags_t))) == NULL) { - return 1; - } - if ((data->timers = (timers_t*)malloc(sizeof(timers_t))) == NULL) { - return 1; - } - return 0; +/* Autogenerated Code Begins */ +int initMetaData() { + if((data = (data_t*) malloc(sizeof(data_t))) == NULL) { return 1; } + if((data->pressure = (pressure_t*) malloc(sizeof(pressure_t))) == NULL) { return 1; } + if((data->motion = (motion_t*) malloc(sizeof(motion_t))) == NULL) { return 1; } + if((data->bms = (bms_t*) malloc(sizeof(bms_t))) == NULL) { return 1; } + if((data->rms = (rms_t*) malloc(sizeof(rms_t))) == NULL) { return 1; } + if((data->flags = (flags_t*) malloc(sizeof(flags_t))) == NULL) { return 1; } + if((data->timers = (timers_t*) malloc(sizeof(timers_t))) == NULL) { return 1; } + + return 0; } -int initData() -{ - // Initializes all data points - if (initMetaData() != 0) { - fprintf(stderr, "Failed to init meta data\n"); - return -1; - } - if (initPressureData() != 0) { - fprintf(stderr, "Failed to init pressure data\n"); - return -1; - } - if (initMotionData() != 0) { - fprintf(stderr, "Failed to init motion data\n"); - return -1; - } - if (initBmsData() != 0) { - fprintf(stderr, "Failed to init bms data\n"); - return -1; - } - if (initRmsData() != 0) { - fprintf(stderr, "Failed to init rms data\n"); - return -1; - } - if (initFlagData() != 0) { - fprintf(stderr, "Failed to init flags data\n"); - return -1; - } - if (initTimerData() != 0) { - fprintf(stderr, "Failed to init timers data\n"); - return -1; - } - - // Initialize mutex - if (pthread_mutex_init(&data->dataMutex, NULL) != 0) { - return 1; - } - - setDataState(0); - return 0; +int initData() { + // Initializes all data points + if (initMetaData() != 0) { + fprintf(stderr, "Failed to init meta data\n"); + return -1; + } + if (initPressureData() != 0) { + fprintf(stderr, "Failed to init pressure data\n"); + return -1; + } + if (initMotionData() != 0) { + fprintf(stderr, "Failed to init motion data\n"); + return -1; + } + if (initBmsData() != 0) { + fprintf(stderr, "Failed to init bms data\n"); + return -1; + } + if (initRmsData() != 0) { + fprintf(stderr, "Failed to init rms data\n"); + return -1; + } + if (initFlagData() != 0) { + fprintf(stderr, "Failed to init flags data\n"); + return -1; + } + if (initTimerData() != 0) { + fprintf(stderr, "Failed to init timers data\n"); + return -1; + } + + // Initialize mutex + if(pthread_mutex_init(&data->dataMutex, NULL) != 0) { + return 1; + } + + setDataState(0); + return 0; } -int initPressureData() -{ - // Initialize mutex - if (pthread_mutex_init(&data->pressure->pressureMutex, NULL) != 0) { - return 1; - } - - setPressurePrimTank(0.0); - setPressurePrimLine(0.0); - setPressurePrimAct(0.0); - setPressureSecTank(0.0); - setPressureSecLine(0.0); - setPressureSecAct(0.0); - setPressureAmb(0.0); - setPressurePv(0.0); - return 0; +int initPressureData() { + // Initialize mutex + if(pthread_mutex_init(&data->pressure->pressureMutex, NULL) != 0) { + return 1; + } + + setPressurePrimTank(0.0); + setPressurePrimLine(0.0); + setPressurePrimAct(0.0); + setPressureSecTank(0.0); + setPressureSecLine(0.0); + setPressureSecAct(0.0); + setPressureAmb(0.0); + setPressurePv(0.0); + return 0; } -int initMotionData() -{ - // Initialize mutex - if (pthread_mutex_init(&data->motion->motionMutex, NULL) != 0) { - return 1; - } - - setMotionPos(0.0f); - setMotionVel(0.0f); - setMotionAccel(0.0f); - setMotionRetroCount(0); - setMotionMissedRetro(0); - return 0; +int initMotionData() { + // Initialize mutex + if(pthread_mutex_init(&data->motion->motionMutex, NULL) != 0) { + return 1; + } + + setMotionPos(0.0f); + setMotionVel(0.0f); + setMotionAccel(0.0f); + setMotionRetroCount(0); + setMotionMissedRetro(0); + return 0; } -int initBmsData() -{ - // Initialize mutex - if (pthread_mutex_init(&data->bms->bmsMutex, NULL) != 0) { - return 1; - } - - setBmsPackCurrent(0.0f); - setBmsPackVoltage(0.0f); - setBmsImdStatus(0); - setBmsPackDCL(0); - setBmsPackCCL(0); - setBmsPackResistance(0); - setBmsPackHealth(0); - setBmsPackOpenVoltage(0.0f); - setBmsPackCycles(0); - setBmsPackAh(0); - setBmsInputVoltage(0.0f); - setBmsSoc(0); - setBmsRelayStatus(0); - setBmsHighTemp(0); - setBmsLowTemp(0); - setBmsAvgTemp(0); - setBmsCellMaxVoltage(0.0f); - setBmsCellMinVoltage(0.0f); - setBmsCellAvgVoltage(0); - setBmsMaxCells(0); - setBmsNumCells(0); - return 0; +int initBmsData() { + // Initialize mutex + if(pthread_mutex_init(&data->bms->bmsMutex, NULL) != 0) { + return 1; + } + + setBmsPackCurrent(0.0f); + setBmsPackVoltage(0.0f); + setBmsImdStatus(0); + setBmsPackDCL(0); + setBmsPackCCL(0); + setBmsPackResistance(0); + setBmsPackHealth(0); + setBmsPackOpenVoltage(0.0f); + setBmsPackCycles(0); + setBmsPackAh(0); + setBmsInputVoltage(0.0f); + setBmsSoc(0); + setBmsRelayStatus(0); + setBmsHighTemp(0); + setBmsLowTemp(0); + setBmsAvgTemp(0); + setBmsCellMaxVoltage(0.0f); + setBmsCellMinVoltage(0.0f); + setBmsCellAvgVoltage(0); + setBmsMaxCells(0); + setBmsNumCells(0); + return 0; } -int initRmsData() -{ - // Initialize mutex - if (pthread_mutex_init(&data->rms->rmsMutex, NULL) != 0) { - return 1; - } - - setRmsIgbtTemp(0); - setRmsGateDriverBoardTemp(0); - setRmsControlBoardTemp(0); - setRmsMotorTemp(0); - setRmsMotorSpeed(0); - setRmsPhaseACurrent(0); - setRmsPhaseBCurrent(0); - setRmsPhaseCCurrent(0); - setRmsDcBusVoltage(0); - setRmsLvVoltage(0); - setRmsCanCode1(0); - setRmsCanCode2(0); - setRmsFaultCode1(0); - setRmsFaultCode2(0); - setRmsCommandedTorque(0); - setRmsActualTorque(0); - setRmsRelayState(0); - setRmsElectricalFreq(0); - setRmsDcBusCurrent(0); - setRmsOutputVoltageLn(0); - setRmsVSMCode(0); - setRmsKeyMode(0); - return 0; +int initRmsData() { + // Initialize mutex + if(pthread_mutex_init(&data->rms->rmsMutex, NULL) != 0) { + return 1; + } + + setRmsIgbtTemp(0); + setRmsGateDriverBoardTemp(0); + setRmsControlBoardTemp(0); + setRmsMotorTemp(0); + setRmsMotorSpeed(0); + setRmsPhaseACurrent(0); + setRmsPhaseBCurrent(0); + setRmsPhaseCCurrent(0); + setRmsDcBusVoltage(0); + setRmsLvVoltage(0); + setRmsCanCode1(0); + setRmsCanCode2(0); + setRmsFaultCode1(0); + setRmsFaultCode2(0); + setRmsCommandedTorque(0); + setRmsActualTorque(0); + setRmsRelayState(0); + setRmsElectricalFreq(0); + setRmsDcBusCurrent(0); + setRmsOutputVoltageLn(0); + setRmsVSMCode(0); + setRmsKeyMode(0); + return 0; } -int initFlagData() -{ - // Initialize mutex - if (pthread_mutex_init(&data->flags->flagsMutex, NULL) != 0) { - return 1; - } - - setFlagsReadyPump(0); - setFlagsPumpDown(0); - setFlagsReadyCommand(0); - setFlagsReadyToBrake(false); - setFlagsPropulse(0); - setFlagsEmergencyBrake(0); - setFlagsShouldStop(0); - setFlagsShutdown(0); - setFlagsShouldBrake(false); - setFlagsIsConnected(false); - setFlagsBrakeInit(false); - setFlagsBrakePrimAct(false); - setFlagsBrakeSecAct(false); - setFlagsBrakePrimRetr(false); - setFlagsBrakeSecRetr(false); - setFlagsClrMotionData(false); - return 0; +int initFlagData() { + // Initialize mutex + if(pthread_mutex_init(&data->flags->flagsMutex, NULL) != 0) { + return 1; + } + + setFlagsReadyPump(0); + setFlagsPumpDown(0); + setFlagsReadyCommand(0); + setFlagsReadyToBrake(false); + setFlagsPropulse(0); + setFlagsEmergencyBrake(0); + setFlagsShouldStop(0); + setFlagsShutdown(0); + setFlagsShouldBrake(false); + setFlagsIsConnected(false); + setFlagsBrakeInit(false); + setFlagsBrakePrimAct(false); + setFlagsBrakeSecAct(false); + setFlagsBrakePrimRetr(false); + setFlagsBrakeSecRetr(false); + setFlagsClrMotionData(false); + return 0; } -int initTimerData() -{ - // Initialize mutex - if (pthread_mutex_init(&data->timers->timersMutex, NULL) != 0) { - return 1; - } - - setTimersStartTime(0); - setTimersOldRetro(0); - setTimersLastRetro(0); - for (int i = 0; i < 3; i++) - setTimersLastRetros(0, i); - setTimersCrawlTimer(0); - return 0; +int initTimerData() { + // Initialize mutex + if(pthread_mutex_init(&data->timers->timersMutex, NULL) != 0) { + return 1; + } + + setTimersStartTime(0); + setTimersOldRetro(0); + setTimersLastRetro(0); + for(int i = 0; i < 3; i++) + setTimersLastRetros(0, i); + setTimersCrawlTimer(0); + return 0; } /* Autogenerated Code Ends */ + diff --git a/embedded/app/src/motor.c b/embedded/app/src/motor.cpp similarity index 97% rename from embedded/app/src/motor.c rename to embedded/app/src/motor.cpp index fc9fae3a..0585de96 100644 --- a/embedded/app/src/motor.c +++ b/embedded/app/src/motor.cpp @@ -2,12 +2,16 @@ #include #include #include -#include #include #include #include #include #include + +extern "C" { +#include +#include +} /*** * The high level interface for the motor */ diff --git a/embedded/app/src/state_machine.c b/embedded/app/src/state_machine.cpp similarity index 95% rename from embedded/app/src/state_machine.c rename to embedded/app/src/state_machine.cpp index f805637d..addb2ed0 100644 --- a/embedded/app/src/state_machine.c +++ b/embedded/app/src/state_machine.cpp @@ -70,14 +70,14 @@ static void initState(state_t* state, char* name, stateTransition_t* (*action)() STATE_ERROR(); } - state->name = malloc(1 + (strlen(name) * sizeof(char))); + state->name = (char*)malloc(1 + (strlen(name) * sizeof(char))); strcpy(state->name, name); state->action = action; state->transitionCounter = 0; state->numTransitions = numTransitions; - state->transitions = malloc(numTransitions * (sizeof(stateTransition_t*))); + state->transitions = (stateTransition_t**)malloc(numTransitions * (sizeof(stateTransition_t*))); for (i = 0; i < numTransitions; i++) { - state->transitions[i] = malloc(sizeof(stateTransition_t)); + state->transitions[i] = (stateTransition_t*)malloc(sizeof(stateTransition_t)); } stateMachine.allStates[indexInAllStates++] = state; } @@ -292,10 +292,10 @@ void buildStateMachine(void) { /* Create all of the states*/ - stateMachine.allStates = malloc(sizeof(state_t*) * NUM_STATES); + stateMachine.allStates = (state_t**)malloc(sizeof(state_t*) * NUM_STATES); for (int i = 0; i < NUM_STATES; i++) { - stateMachine.allStates[i] = malloc(sizeof(state_t)); + stateMachine.allStates[i] = (state_t*)malloc(sizeof(state_t)); } initState(stateMachine.allStates[0], IDLE_NAME, idleAction, 1); @@ -323,7 +323,7 @@ void buildStateMachine(void) stateMachine.currState = stateMachine.allStates[0]; stateMachine.currState->begin(); - stateMachine.overrideStateName = malloc(21); // Longest state name is "readyForPropulsion" -- 18 char + stateMachine.overrideStateName = (char*)malloc(21); // Longest state name is "readyForPropulsion" -- 18 char strcpy(stateMachine.overrideStateName, BLANK_NAME); if (stateMachine.overrideStateName == NULL) { fprintf(stderr, "Malloc error -- state machine override state machine name\n"); diff --git a/embedded/app/src/states.cpp b/embedded/app/src/states.cpp new file mode 100644 index 00000000..1653459e --- /dev/null +++ b/embedded/app/src/states.cpp @@ -0,0 +1,469 @@ +/*** + * Filename: states.c + * + * Summary: All of the in-depth functionality of each state. Each state has its + * own actions and transitions and this is where all of the states actions are + * defined. It also has a number of helper functions to simplify the states + * actions. + * + */ + +/* Includes */ +#include +#include +#include +#include + +#include "motor.h" +#include "state_machine.h" +#include "states.h" +#include +#include + +extern "C" { +#include "bms_fault_checking.h" +#include "connStat.h" +#include "data.h" +#include "pressure_fault_checking.h" +#include "rms.h" +#include "rms_fault_checking.h" +} +/*#define NO_FAULT*/ + +#define NUM_FAIL 10 +#define LV_BATT_SOC_CALC(x) (pow(-1.1142 * (x), 6) + pow(78.334 * (x), 5) - pow(2280.5 * (x), 4) + pow(35181.0 * (x), 3) - pow(303240.0 * (x), 2) - (1000000.0 * (x))) + +#define MAX_RETRO 3 +#define MAX_PACKET_LOSS 500 +/* Imports/Externs */ +extern int internalCount; +extern stateMachine_t stateMachine; +extern stateTransition_t* findTransition(state_t* currState, char* name); +int bErrs, pErrs, rErrs; +int checkNetwork() +{ + static int errs = 0; + if (!checkUDPStat() || !checkTCPStat()) { + if (checkUDPStat() == 0) + fprintf(stderr, "UDP "); + if (checkTCPStat() == 0) + fprintf(stderr, "TCP "); + fprintf(stderr, "CONNECTION DROPPED\n"); + errs += 1; + } else { + errs = 0; + } + + if (errs >= MAX_PACKET_LOSS) { + return -1; + } + return 0; +} + +/*** + * checkStopped - checks a variety of values to make sure the pod is stopped. + * + * RETURNS: true if stopped, false if moving + */ +/* DEPRECATED +static bool checkStopped(void) { + return fabs(getMotionVel()) < MAX_STOPPED_VEL && (getuSTimestamp() - getTimersLastRetro()) > TIME_SINCE_LAST_RETRO; +} +*/ +/*** + * Actions for all the states. + * They perform transition and error condition + * checking and perform the functionality of the state: e.g. brake if in + * braking. + * + */ + +stateTransition_t* idleAction() +{ + setDataState(1); + + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + + return NULL; +} + +stateTransition_t* pumpdownAction() +{ + // First check for nominal values? + setDataState(2); + + /* Check IMD status */ + + if (getuSTimestamp() - stateMachine.start > 300000000) + return stateMachine.currState->fault; + + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + + // CHECK PRESSURE + if (!checkPrerunPressures()) { + fprintf(stderr, "Pressure failure\n"); + pErrs += 1; + } else + pErrs = 0; + + if (!checkPrerunBattery()) { + fprintf(stderr, "prerun batt fault\n"); + bErrs += 1; + } else + bErrs = 0; + + if (!checkPrerunRMS()) { + fprintf(stderr, "prerun rms fault\n"); + rErrs += 1; + } else + rErrs = 0; + /* FIXME, need to fix robust failure cases */ + if (pErrs >= NUM_FAIL || bErrs >= NUM_FAIL || rErrs >= NUM_FAIL) + return stateMachine.currState->fault; + + return NULL; +} + +stateTransition_t* propulsionAction() +{ + setDataState(3); + /* Check IMD status */ + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + + /* Check HV Indicator light */ + + if (checkNetwork() != 0) + return stateMachine.currState->fault; + + // CHECK FAULT CRITERIA + // CHECK PRESSURE -- PreRun function still valid here + if (!checkPrerunPressures()) { + fprintf(stderr, "Pressure failing\n"); + pErrs += 1; + } else + pErrs = 0; + + if (!checkRunBattery()) { + printf("Failed battery\n"); + bErrs += 1; + } + bErrs = 0; + + if (!checkRunRMS()) { + printf("run rms failed\n"); + rErrs += 1; + } + rErrs = 0; + + if (getuSTimestamp() - getTimersStartTime() > 30000000 /*MAX_RUN_TIME*/) { + fprintf(stderr, "Prop timeout\n"); + return stateMachine.currState->next; + } + + if (getMotionRetroCount() >= MAX_RETRO && getFlagsReadyToBrake()) { + printf("retro transition\n"); + return findTransition(stateMachine.currState, BRAKING_NAME); + } + + // CHECK TRANSITION CRITERIA + if (getFlagsShouldStop()) { + printf("Should Stop\n"); + return stateMachine.currState->next; + } + + if (bErrs >= NUM_FAIL || pErrs >= NUM_FAIL || rErrs >= NUM_FAIL) + return stateMachine.currState->fault; + + return NULL; +} + +stateTransition_t* brakingAction() +{ + setDataState(4); + // TODO Do we differenciate between primary and secondary braking systems? + // TODO Add logic to handle switches / actuate both + + if (getFlagsEmergencyBrake()) { + printf("EMERG BRAKE\n"); + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + if (!hv_iox.getIMDStatus()) { + fprintf(stderr, "getIMDStatus()"); + return stateMachine.currState->fault; + } + + if (checkNetwork() != 0) { + printf("lost connection\n"); + return stateMachine.currState->fault; + } + + // CHECK FAULT CRITERIA + + if (getuSTimestamp() - stateMachine.start > 5000000) { + if (!checkBrakingPressures()) { + printf("braking==================\n"); + pErrs += 1; + } else + pErrs = 0; + } + + if (!checkBrakingBattery()) { + printf("battery bad\n"); + bErrs += 1; + } else + bErrs = 0; + + if (getuSTimestamp() - stateMachine.start > 10000000) { + if (!checkBrakingRMS()) { + printf("rms bad\n"); + rErrs += 1; + } else + rErrs = 0; + } + + if ((getuSTimestamp() - stateMachine.start) > 15000000) { + printf("going to stopped\n"); + return findTransition(stateMachine.currState, STOPPED_NAME); + } + + if (pErrs >= NUM_FAIL || bErrs >= NUM_FAIL || rErrs >= NUM_FAIL) { + fprintf(stderr, "NUM FAILS: pErrs - %d | bErrs - %d | rErrs - %d\n", pErrs, bErrs, rErrs); + + return stateMachine.currState->fault; + } + + return NULL; +} + +stateTransition_t* stoppedAction() +{ + setDataState(5); + /* Check IMD status */ + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + + if (checkNetwork() != 0) + return stateMachine.currState->fault; + // CHECK FAULT CRITERIA + + if (!checkBrakingPressures()) { // Still unchanged + printf("Pressures failing\n"); + pErrs += 1; + } else + pErrs = 0; + + if (!checkBrakingBattery()) { // Still unchanged + fprintf(stderr, "Battery error\n"); + bErrs += 1; + } else + bErrs = 0; + + if (!checkStoppedRMS()) { // Still unchanged + printf("failrms\n"); + rErrs += 1; + } else + rErrs = 0; + + if (bErrs >= NUM_FAIL || pErrs >= NUM_FAIL || rErrs >= NUM_FAIL) + return stateMachine.currState->fault; + + return NULL; +} + +stateTransition_t* servPrechargeAction() +{ + setDataState(6); + if (!checkBrakingPressures()) { + fprintf(stderr, "Pressure failed\n"); + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } else + pErrs = 0; + + if (!hv_iox.getIMDStatus()) { + fprintf(stderr, "getIMDStatus()"); + return stateMachine.currState->fault; + } + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + if (checkNetwork() != 0) + return stateMachine.currState->fault; + return NULL; +} + +static int prevRet = 0; + +stateTransition_t* crawlAction() +{ + setDataState(7); + /* Check IMD status */ + prevRet = getMotionRetroCount(); + if (!hv_iox.getIMDStatus()) { + return stateMachine.currState->fault; + } + + if (checkNetwork() != 0) + return stateMachine.currState->fault; + + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + + if ((getMotionRetroCount() - internalCount) >= 2) { + printf("retro transition\n"); + return findTransition(stateMachine.currState, POST_RUN_NAME); + } + + if (!checkCrawlPostrunPressures()) { + printf("pres fail\n"); + pErrs += 1; + } else + pErrs = 0; + + if (!checkCrawlBattery()) { + printf("batt fail\n"); + bErrs += 1; + } else + bErrs = 0; + + if (!checkCrawlRMS()) { // Still unchanged + printf("rms fail\n"); + rErrs += 1; + } else + rErrs = 0; + + // CHECK TRANSITION CRITERIA + + if (getuSTimestamp() - stateMachine.start > 5000000) { + return findTransition(stateMachine.currState, POST_RUN_NAME); + } + + if (getFlagsShouldStop()) { + + return findTransition(stateMachine.currState, POST_RUN_NAME); + } + + printf("PRIM LINE: %f\n", getPressurePrimLine()); + if (bErrs >= NUM_FAIL || pErrs >= NUM_FAIL || rErrs >= NUM_FAIL) { + printf("fail\n"); + return stateMachine.currState->fault; + } + + return NULL; +} + +stateTransition_t* postRunAction() +{ + setDataState(8); + /* Check IMD status */ + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + // TODO fixme there is a seg fault around here lol + /* Check HV Indicator light */ + printf("FAILURE STATE: %p\n", stateMachine.currState); + + if (checkNetwork() != 0) + findTransition(stateMachine.currState, RUN_FAULT_NAME); + + if (!checkPostrunBattery()) { + printf("battfail\n"); + bErrs += 1; + } else + bErrs = 0; + + if (!checkPostRMS()) { + printf("rmsfail\n"); + rErrs += 1; + } else + rErrs = 0; + + if (bErrs >= NUM_FAIL || rErrs >= NUM_FAIL) { + printf("postFail\n"); + return findTransition(stateMachine.currState, RUN_FAULT_NAME); + } + return NULL; +} + +stateTransition_t* safeToApproachAction() +{ + /* if (isHVEnabled()) {*/ + /* return stateMachine.currState->fault;*/ + /* } */ + if (getPressurePrimTank() > 30 || getPressurePrimTank() < -15 || getPressurePrimLine() > 20 || getPressurePrimLine() < -10 || getPressurePrimAct() > 20 || getPressurePrimAct() < -10 || getPressureSecTank() > 30 || getPressureSecTank() < -15 || getPressureSecLine() > 20 || getPressureSecLine() < -10 || getPressureSecAct() > 20 || getPressureSecAct() < -10 || getPressurePv() > 20 || getPressurePv() < 13) { + fprintf(stderr, "Pressures are out of the safe range\n"); + return findTransition(stateMachine.currState, NON_RUN_FAULT_NAME); + } + + if (checkNetwork() != 0) + return findTransition(stateMachine.currState, NON_RUN_FAULT_NAME); + if (getFlagsEmergencyBrake()) { + return findTransition(stateMachine.currState, NON_RUN_FAULT_NAME); + } + setDataState(9); + return NULL; +} +// +// We're removing pre and post faults and making them non run faults. +// When you change this make 11 the non run fault action. Ty - EU +stateTransition_t* nonRunFaultAction() +{ + setFlagsEmergencyBrake(false); + fprintf(stderr, "NON RUN FAULT\n"); + static int mcuDisPulse = 0; + if (mcuDisPulse >= 50) { + clrMotorEn(); + usleep(1000); + rmsCmdNoTorque(); + usleep(1000); + rmsDischarge(); + usleep(1000); + rmsInvDis(); + usleep(1000); + hv_iox.setMCUHVEnabled(0); + mcuDisPulse = 0; + } else { + mcuDisPulse += 1; + } + setDataState(10); + return NULL; +} + +stateTransition_t* runFaultAction() +{ + printf("RUN FAULT\n"); + setFlagsEmergencyBrake(false); + static int mcuDisPulse = 0; + setDataState(11); + if (mcuDisPulse >= 50) { + hv_iox.setMCUHVEnabled(0); + clrMotorEn(); + usleep(1000); + + rmsCmdNoTorque(); + usleep(1000); + rmsDischarge(); + usleep(1000); + rmsInvDis(); + usleep(1000); + mcuDisPulse = 0; + } else { + mcuDisPulse += 1; + } + + return NULL; +} + +stateTransition_t* brakingFault() +{ + //TODO + setDataState(12); + return NULL; +} diff --git a/embedded/app/src/transitions.c b/embedded/app/src/transitions.cpp similarity index 90% rename from embedded/app/src/transitions.c rename to embedded/app/src/transitions.cpp index b16c3c7f..1e7e2e13 100644 --- a/embedded/app/src/transitions.c +++ b/embedded/app/src/transitions.cpp @@ -1,13 +1,17 @@ -#include -#include #include #include -#include #include #include #include #include +extern "C" { +#include +#include +#include + +} + extern stateMachine_t stateMachine; int internalCount = 0; /* If there is nothing special to do */ @@ -27,18 +31,18 @@ int genIdle() usleep(50000); if (rmsInvDis() != 0) fprintf(stderr, "Failed in genIdle, 3\n"); - setMCUHVEnabled(false); + hv_iox.setMCUHVEnabled(false); return 0; } int genPumpdown() { usleep(10000); - setMCULatch(true); + hv_iox.setMCULatch(true); usleep(10000); - setMCULatch(false); + hv_iox.setMCULatch(false); usleep(10000); - setMCUHVEnabled(true); + hv_iox.setMCUHVEnabled(true); sleep(1); if (rmsEnHeartbeat() != 0) printf("EEERR0\n"); @@ -78,7 +82,7 @@ int genBraking() rmsInvDis(); usleep(50000); } - setMCUHVEnabled(false); + hv_iox.setMCUHVEnabled(false); brakeHV(); stateMachine.start = getuSTimestamp(); @@ -119,7 +123,7 @@ int genPostRun() rmsInvDis(); usleep(1000); } - setMCUHVEnabled(0); + hv_iox.setMCUHVEnabled(0); brakeHV(); return 0; @@ -128,10 +132,10 @@ int genPostRun() int genServPrecharge() { printf("PRE CHARGE\n"); - setMCULatch(true); + hv_iox.setMCULatch(true); usleep(10000); - setMCULatch(false); - setMCUHVEnabled(true); + hv_iox.setMCULatch(false); + hv_iox.setMCUHVEnabled(true); sleep(1); if (rmsEnHeartbeat() != 0) printf("EEERR0\n"); @@ -156,7 +160,7 @@ int genRunFault() rmsInvDis(); usleep(1000); - setMCUHVEnabled(0); + hv_iox.setMCUHVEnabled(0); printf("Entering here4\n"); brakeHV(); printf("Entering here\n"); @@ -177,7 +181,7 @@ int genNonRunFault() usleep(1000); rmsInvDis(); usleep(1000); - setMCUHVEnabled(0); + hv_iox.setMCUHVEnabled(0); printf("non run0\n"); return 0; } diff --git a/embedded/data/include/data.h b/embedded/data/include/data.h index 9c2f6f27..94210085 100644 --- a/embedded/data/include/data.h +++ b/embedded/data/include/data.h @@ -23,6 +23,7 @@ int expFilterInt(int currVal, int prevVal, float weight); int initMetaData(void); int isEarlyInit(void); + /* Autogenerated Code Begins */ int initData(void); int initPressureData(void); @@ -34,131 +35,132 @@ int initTimerData(void); // Top of the great hierarchy of our descending data tree. typedef struct data_t { - pthread_mutex_t dataMutex; - int state; - // Pressure information from the braking system - struct pressure_t* pressure; - // Where all motion data goes. X-positive direction is assumed. All values should be assumed to be metr - // ic. - struct motion_t* motion; - // Data collected about the battery system - struct bms_t* bms; - // Collection of all the RMS (motor controller) data - struct rms_t* rms; - // Where information about the flags is held. - struct flags_t* flags; - // For making sure that our run happens in a timely manner - struct timers_t* timers; + pthread_mutex_t dataMutex; + int state; + // Pressure information from the braking system + struct pressure_t *pressure; + // Where all motion data goes. X-positive direction is assumed. All values should be assumed to be metr + // ic. + struct motion_t *motion; + // Data collected about the battery system + struct bms_t *bms; + // Collection of all the RMS (motor controller) data + struct rms_t *rms; + // Where information about the flags is held. + struct flags_t *flags; + // For making sure that our run happens in a timely manner + struct timers_t *timers; } data_t; // Pressure information from the braking system typedef struct pressure_t { - pthread_mutex_t pressureMutex; - double primTank; - double primLine; - double primAct; - double secTank; - double secLine; - double secAct; - double amb; - double pv; + pthread_mutex_t pressureMutex; + double primTank; + double primLine; + double primAct; + double secTank; + double secLine; + double secAct; + double amb; + double pv; } pressure_t; // Where all motion data goes. X-positive direction is assumed. All values should be assumed to be metr // ic. typedef struct motion_t { - pthread_mutex_t motionMutex; - float pos; - float vel; - float accel; - int retroCount; - int missedRetro; + pthread_mutex_t motionMutex; + float pos; + float vel; + float accel; + int retroCount; + int missedRetro; } motion_t; // Data collected about the battery system typedef struct bms_t { - pthread_mutex_t bmsMutex; - float packCurrent; - float packVoltage; - int imdStatus; - uint16_t packDCL; - int16_t packCCL; - uint16_t packResistance; - uint8_t packHealth; - float packOpenVoltage; - uint16_t packCycles; - uint16_t packAh; - float inputVoltage; - uint8_t Soc; - uint16_t relayStatus; - uint8_t highTemp; - uint8_t lowTemp; - uint8_t avgTemp; - float cellMaxVoltage; - float cellMinVoltage; - uint16_t cellAvgVoltage; - uint8_t maxCells; - uint8_t numCells; + pthread_mutex_t bmsMutex; + float packCurrent; + float packVoltage; + int imdStatus; + uint16_t packDCL; + int16_t packCCL; + uint16_t packResistance; + uint8_t packHealth; + float packOpenVoltage; + uint16_t packCycles; + uint16_t packAh; + float inputVoltage; + uint8_t Soc; + uint16_t relayStatus; + uint8_t highTemp; + uint8_t lowTemp; + uint8_t avgTemp; + float cellMaxVoltage; + float cellMinVoltage; + uint16_t cellAvgVoltage; + uint8_t maxCells; + uint8_t numCells; } bms_t; // Collection of all the RMS (motor controller) data typedef struct rms_t { - pthread_mutex_t rmsMutex; - uint16_t igbtTemp; - uint16_t gateDriverBoardTemp; - uint16_t controlBoardTemp; - uint16_t motorTemp; - int16_t motorSpeed; - int16_t phaseACurrent; - uint16_t phaseBCurrent; - uint16_t phaseCCurrent; - int16_t dcBusVoltage; - uint16_t lvVoltage; - uint64_t canCode1; - uint64_t canCode2; - uint64_t faultCode1; - uint64_t faultCode2; - int16_t commandedTorque; - int16_t actualTorque; - uint16_t relayState; - uint16_t electricalFreq; - int16_t dcBusCurrent; - uint16_t outputVoltageLn; - uint16_t VSMCode; - uint16_t keyMode; + pthread_mutex_t rmsMutex; + uint16_t igbtTemp; + uint16_t gateDriverBoardTemp; + uint16_t controlBoardTemp; + uint16_t motorTemp; + int16_t motorSpeed; + int16_t phaseACurrent; + uint16_t phaseBCurrent; + uint16_t phaseCCurrent; + int16_t dcBusVoltage; + uint16_t lvVoltage; + uint64_t canCode1; + uint64_t canCode2; + uint64_t faultCode1; + uint64_t faultCode2; + int16_t commandedTorque; + int16_t actualTorque; + uint16_t relayState; + uint16_t electricalFreq; + int16_t dcBusCurrent; + uint16_t outputVoltageLn; + uint16_t VSMCode; + uint16_t keyMode; } rms_t; // Where information about the flags is held. typedef struct flags_t { - pthread_mutex_t flagsMutex; - int readyPump; - int pumpDown; - int readyCommand; - bool readyToBrake; - int propulse; - int emergencyBrake; - int shouldStop; - int shutdown; - bool shouldBrake; - bool isConnected; - bool brakeInit; - bool brakePrimAct; - bool brakeSecAct; - bool brakePrimRetr; - bool brakeSecRetr; - bool clrMotionData; + pthread_mutex_t flagsMutex; + int readyPump; + int pumpDown; + int readyCommand; + bool readyToBrake; + int propulse; + int emergencyBrake; + int shouldStop; + int shutdown; + bool shouldBrake; + bool isConnected; + bool brakeInit; + bool brakePrimAct; + bool brakeSecAct; + bool brakePrimRetr; + bool brakeSecRetr; + bool clrMotionData; } flags_t; // For making sure that our run happens in a timely manner typedef struct timers_t { - pthread_mutex_t timersMutex; - uint64_t startTime; - uint64_t oldRetro; - uint64_t lastRetro; - uint64_t lastRetros[3]; - uint64_t crawlTimer; + pthread_mutex_t timersMutex; + uint64_t startTime; + uint64_t oldRetro; + uint64_t lastRetro; + uint64_t lastRetros[3]; + uint64_t crawlTimer; } timers_t; + int getDataState(); void setDataState(int val); @@ -394,6 +396,7 @@ uint64_t getTimersCrawlTimer(); void setTimersCrawlTimer(uint64_t val); /* Autogenerated Code Ends */ + static inline uint64_t convertTouS(struct timespec* currTime) { return (uint64_t)((currTime->tv_sec * 1000000) + (currTime->tv_nsec / 1000)); diff --git a/embedded/data/src/data.c b/embedded/data/src/data.c index 401e57b2..e06d1cab 100644 --- a/embedded/data/src/data.c +++ b/embedded/data/src/data.c @@ -5,1174 +5,1019 @@ #include "data.h" #include + /* Autogenerated Code Begins */ -int getDataState() -{ - pthread_mutex_lock(&data->dataMutex); - int val = data->state; - pthread_mutex_unlock(&data->dataMutex); - return val; +int getDataState() { + pthread_mutex_lock(&data->dataMutex); + int val = data->state; + pthread_mutex_unlock(&data->dataMutex); + return val; } -void setDataState(int val) -{ - pthread_mutex_lock(&data->dataMutex); - data->state = val; - pthread_mutex_unlock(&data->dataMutex); +void setDataState(int val) { + pthread_mutex_lock(&data->dataMutex); + data->state = val; + pthread_mutex_unlock(&data->dataMutex); } -double getPressurePrimTank() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->primTank; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressurePrimTank() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->primTank; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressurePrimTank(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->primTank = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressurePrimTank(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->primTank = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressurePrimLine() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->primLine; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressurePrimLine() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->primLine; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressurePrimLine(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->primLine = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressurePrimLine(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->primLine = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressurePrimAct() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->primAct; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressurePrimAct() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->primAct; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressurePrimAct(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->primAct = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressurePrimAct(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->primAct = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressureSecTank() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->secTank; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressureSecTank() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->secTank; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressureSecTank(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->secTank = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressureSecTank(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->secTank = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressureSecLine() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->secLine; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressureSecLine() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->secLine; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressureSecLine(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->secLine = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressureSecLine(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->secLine = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressureSecAct() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->secAct; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressureSecAct() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->secAct; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressureSecAct(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->secAct = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressureSecAct(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->secAct = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressureAmb() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->amb; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressureAmb() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->amb; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressureAmb(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->amb = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressureAmb(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->amb = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -double getPressurePv() -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - double val = data->pressure->pv; - pthread_mutex_unlock(&data->pressure->pressureMutex); - return val; +double getPressurePv() { + pthread_mutex_lock(&data->pressure->pressureMutex); + double val = data->pressure->pv; + pthread_mutex_unlock(&data->pressure->pressureMutex); + return val; } -void setPressurePv(double val) -{ - pthread_mutex_lock(&data->pressure->pressureMutex); - data->pressure->pv = val; - pthread_mutex_unlock(&data->pressure->pressureMutex); +void setPressurePv(double val) { + pthread_mutex_lock(&data->pressure->pressureMutex); + data->pressure->pv = val; + pthread_mutex_unlock(&data->pressure->pressureMutex); } -float getMotionPos() -{ - pthread_mutex_lock(&data->motion->motionMutex); - float val = data->motion->pos; - pthread_mutex_unlock(&data->motion->motionMutex); - return val; +float getMotionPos() { + pthread_mutex_lock(&data->motion->motionMutex); + float val = data->motion->pos; + pthread_mutex_unlock(&data->motion->motionMutex); + return val; } -void setMotionPos(float val) -{ - pthread_mutex_lock(&data->motion->motionMutex); - data->motion->pos = val; - pthread_mutex_unlock(&data->motion->motionMutex); +void setMotionPos(float val) { + pthread_mutex_lock(&data->motion->motionMutex); + data->motion->pos = val; + pthread_mutex_unlock(&data->motion->motionMutex); } -float getMotionVel() -{ - pthread_mutex_lock(&data->motion->motionMutex); - float val = data->motion->vel; - pthread_mutex_unlock(&data->motion->motionMutex); - return val; +float getMotionVel() { + pthread_mutex_lock(&data->motion->motionMutex); + float val = data->motion->vel; + pthread_mutex_unlock(&data->motion->motionMutex); + return val; } -void setMotionVel(float val) -{ - pthread_mutex_lock(&data->motion->motionMutex); - data->motion->vel = val; - pthread_mutex_unlock(&data->motion->motionMutex); +void setMotionVel(float val) { + pthread_mutex_lock(&data->motion->motionMutex); + data->motion->vel = val; + pthread_mutex_unlock(&data->motion->motionMutex); } -float getMotionAccel() -{ - pthread_mutex_lock(&data->motion->motionMutex); - float val = data->motion->accel; - pthread_mutex_unlock(&data->motion->motionMutex); - return val; +float getMotionAccel() { + pthread_mutex_lock(&data->motion->motionMutex); + float val = data->motion->accel; + pthread_mutex_unlock(&data->motion->motionMutex); + return val; } -void setMotionAccel(float val) -{ - pthread_mutex_lock(&data->motion->motionMutex); - data->motion->accel = val; - pthread_mutex_unlock(&data->motion->motionMutex); +void setMotionAccel(float val) { + pthread_mutex_lock(&data->motion->motionMutex); + data->motion->accel = val; + pthread_mutex_unlock(&data->motion->motionMutex); } -int getMotionRetroCount() -{ - pthread_mutex_lock(&data->motion->motionMutex); - int val = data->motion->retroCount; - pthread_mutex_unlock(&data->motion->motionMutex); - return val; +int getMotionRetroCount() { + pthread_mutex_lock(&data->motion->motionMutex); + int val = data->motion->retroCount; + pthread_mutex_unlock(&data->motion->motionMutex); + return val; } -void setMotionRetroCount(int val) -{ - pthread_mutex_lock(&data->motion->motionMutex); - data->motion->retroCount = val; - pthread_mutex_unlock(&data->motion->motionMutex); +void setMotionRetroCount(int val) { + pthread_mutex_lock(&data->motion->motionMutex); + data->motion->retroCount = val; + pthread_mutex_unlock(&data->motion->motionMutex); } -int getMotionMissedRetro() -{ - pthread_mutex_lock(&data->motion->motionMutex); - int val = data->motion->missedRetro; - pthread_mutex_unlock(&data->motion->motionMutex); - return val; +int getMotionMissedRetro() { + pthread_mutex_lock(&data->motion->motionMutex); + int val = data->motion->missedRetro; + pthread_mutex_unlock(&data->motion->motionMutex); + return val; } -void setMotionMissedRetro(int val) -{ - pthread_mutex_lock(&data->motion->motionMutex); - data->motion->missedRetro = val; - pthread_mutex_unlock(&data->motion->motionMutex); +void setMotionMissedRetro(int val) { + pthread_mutex_lock(&data->motion->motionMutex); + data->motion->missedRetro = val; + pthread_mutex_unlock(&data->motion->motionMutex); } -float getBmsPackCurrent() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - float val = data->bms->packCurrent; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +float getBmsPackCurrent() { + pthread_mutex_lock(&data->bms->bmsMutex); + float val = data->bms->packCurrent; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackCurrent(float val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packCurrent = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackCurrent(float val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packCurrent = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -float getBmsPackVoltage() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - float val = data->bms->packVoltage; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +float getBmsPackVoltage() { + pthread_mutex_lock(&data->bms->bmsMutex); + float val = data->bms->packVoltage; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackVoltage(float val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packVoltage = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackVoltage(float val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packVoltage = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -int getBmsImdStatus() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - int val = data->bms->imdStatus; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +int getBmsImdStatus() { + pthread_mutex_lock(&data->bms->bmsMutex); + int val = data->bms->imdStatus; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsImdStatus(int val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->imdStatus = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsImdStatus(int val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->imdStatus = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getBmsPackDCL() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint16_t val = data->bms->packDCL; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint16_t getBmsPackDCL() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint16_t val = data->bms->packDCL; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackDCL(uint16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packDCL = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackDCL(uint16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packDCL = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -int16_t getBmsPackCCL() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - int16_t val = data->bms->packCCL; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +int16_t getBmsPackCCL() { + pthread_mutex_lock(&data->bms->bmsMutex); + int16_t val = data->bms->packCCL; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackCCL(int16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packCCL = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackCCL(int16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packCCL = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getBmsPackResistance() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint16_t val = data->bms->packResistance; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint16_t getBmsPackResistance() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint16_t val = data->bms->packResistance; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackResistance(uint16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packResistance = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackResistance(uint16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packResistance = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsPackHealth() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->packHealth; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsPackHealth() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->packHealth; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackHealth(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packHealth = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackHealth(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packHealth = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -float getBmsPackOpenVoltage() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - float val = data->bms->packOpenVoltage; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +float getBmsPackOpenVoltage() { + pthread_mutex_lock(&data->bms->bmsMutex); + float val = data->bms->packOpenVoltage; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackOpenVoltage(float val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packOpenVoltage = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackOpenVoltage(float val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packOpenVoltage = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getBmsPackCycles() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint16_t val = data->bms->packCycles; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint16_t getBmsPackCycles() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint16_t val = data->bms->packCycles; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackCycles(uint16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packCycles = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackCycles(uint16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packCycles = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getBmsPackAh() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint16_t val = data->bms->packAh; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint16_t getBmsPackAh() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint16_t val = data->bms->packAh; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsPackAh(uint16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->packAh = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsPackAh(uint16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->packAh = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -float getBmsInputVoltage() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - float val = data->bms->inputVoltage; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +float getBmsInputVoltage() { + pthread_mutex_lock(&data->bms->bmsMutex); + float val = data->bms->inputVoltage; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsInputVoltage(float val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->inputVoltage = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsInputVoltage(float val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->inputVoltage = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsSoc() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->Soc; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsSoc() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->Soc; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsSoc(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->Soc = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsSoc(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->Soc = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getBmsRelayStatus() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint16_t val = data->bms->relayStatus; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint16_t getBmsRelayStatus() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint16_t val = data->bms->relayStatus; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsRelayStatus(uint16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->relayStatus = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsRelayStatus(uint16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->relayStatus = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsHighTemp() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->highTemp; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsHighTemp() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->highTemp; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsHighTemp(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->highTemp = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsHighTemp(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->highTemp = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsLowTemp() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->lowTemp; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsLowTemp() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->lowTemp; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsLowTemp(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->lowTemp = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsLowTemp(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->lowTemp = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsAvgTemp() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->avgTemp; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsAvgTemp() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->avgTemp; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsAvgTemp(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->avgTemp = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsAvgTemp(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->avgTemp = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -float getBmsCellMaxVoltage() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - float val = data->bms->cellMaxVoltage; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +float getBmsCellMaxVoltage() { + pthread_mutex_lock(&data->bms->bmsMutex); + float val = data->bms->cellMaxVoltage; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsCellMaxVoltage(float val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->cellMaxVoltage = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsCellMaxVoltage(float val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->cellMaxVoltage = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -float getBmsCellMinVoltage() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - float val = data->bms->cellMinVoltage; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +float getBmsCellMinVoltage() { + pthread_mutex_lock(&data->bms->bmsMutex); + float val = data->bms->cellMinVoltage; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsCellMinVoltage(float val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->cellMinVoltage = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsCellMinVoltage(float val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->cellMinVoltage = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getBmsCellAvgVoltage() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint16_t val = data->bms->cellAvgVoltage; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint16_t getBmsCellAvgVoltage() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint16_t val = data->bms->cellAvgVoltage; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsCellAvgVoltage(uint16_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->cellAvgVoltage = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsCellAvgVoltage(uint16_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->cellAvgVoltage = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsMaxCells() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->maxCells; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsMaxCells() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->maxCells; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsMaxCells(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->maxCells = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsMaxCells(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->maxCells = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint8_t getBmsNumCells() -{ - pthread_mutex_lock(&data->bms->bmsMutex); - uint8_t val = data->bms->numCells; - pthread_mutex_unlock(&data->bms->bmsMutex); - return val; +uint8_t getBmsNumCells() { + pthread_mutex_lock(&data->bms->bmsMutex); + uint8_t val = data->bms->numCells; + pthread_mutex_unlock(&data->bms->bmsMutex); + return val; } -void setBmsNumCells(uint8_t val) -{ - pthread_mutex_lock(&data->bms->bmsMutex); - data->bms->numCells = val; - pthread_mutex_unlock(&data->bms->bmsMutex); +void setBmsNumCells(uint8_t val) { + pthread_mutex_lock(&data->bms->bmsMutex); + data->bms->numCells = val; + pthread_mutex_unlock(&data->bms->bmsMutex); } -uint16_t getRmsIgbtTemp() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->igbtTemp; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsIgbtTemp() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->igbtTemp; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsIgbtTemp(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->igbtTemp = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsIgbtTemp(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->igbtTemp = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsGateDriverBoardTemp() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->gateDriverBoardTemp; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsGateDriverBoardTemp() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->gateDriverBoardTemp; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsGateDriverBoardTemp(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->gateDriverBoardTemp = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsGateDriverBoardTemp(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->gateDriverBoardTemp = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsControlBoardTemp() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->controlBoardTemp; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsControlBoardTemp() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->controlBoardTemp; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsControlBoardTemp(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->controlBoardTemp = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsControlBoardTemp(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->controlBoardTemp = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsMotorTemp() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->motorTemp; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsMotorTemp() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->motorTemp; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsMotorTemp(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->motorTemp = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsMotorTemp(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->motorTemp = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int16_t getRmsMotorSpeed() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - int16_t val = data->rms->motorSpeed; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +int16_t getRmsMotorSpeed() { + pthread_mutex_lock(&data->rms->rmsMutex); + int16_t val = data->rms->motorSpeed; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsMotorSpeed(int16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->motorSpeed = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsMotorSpeed(int16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->motorSpeed = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int16_t getRmsPhaseACurrent() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - int16_t val = data->rms->phaseACurrent; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +int16_t getRmsPhaseACurrent() { + pthread_mutex_lock(&data->rms->rmsMutex); + int16_t val = data->rms->phaseACurrent; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsPhaseACurrent(int16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->phaseACurrent = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsPhaseACurrent(int16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->phaseACurrent = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsPhaseBCurrent() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->phaseBCurrent; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsPhaseBCurrent() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->phaseBCurrent; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsPhaseBCurrent(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->phaseBCurrent = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsPhaseBCurrent(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->phaseBCurrent = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsPhaseCCurrent() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->phaseCCurrent; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsPhaseCCurrent() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->phaseCCurrent; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsPhaseCCurrent(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->phaseCCurrent = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsPhaseCCurrent(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->phaseCCurrent = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int16_t getRmsDcBusVoltage() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - int16_t val = data->rms->dcBusVoltage; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +int16_t getRmsDcBusVoltage() { + pthread_mutex_lock(&data->rms->rmsMutex); + int16_t val = data->rms->dcBusVoltage; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsDcBusVoltage(int16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->dcBusVoltage = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsDcBusVoltage(int16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->dcBusVoltage = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsLvVoltage() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->lvVoltage; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsLvVoltage() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->lvVoltage; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsLvVoltage(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->lvVoltage = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsLvVoltage(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->lvVoltage = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint64_t getRmsCanCode1() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint64_t val = data->rms->canCode1; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint64_t getRmsCanCode1() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint64_t val = data->rms->canCode1; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsCanCode1(uint64_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->canCode1 = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsCanCode1(uint64_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->canCode1 = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint64_t getRmsCanCode2() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint64_t val = data->rms->canCode2; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint64_t getRmsCanCode2() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint64_t val = data->rms->canCode2; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsCanCode2(uint64_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->canCode2 = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsCanCode2(uint64_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->canCode2 = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint64_t getRmsFaultCode1() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint64_t val = data->rms->faultCode1; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint64_t getRmsFaultCode1() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint64_t val = data->rms->faultCode1; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsFaultCode1(uint64_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->faultCode1 = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsFaultCode1(uint64_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->faultCode1 = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint64_t getRmsFaultCode2() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint64_t val = data->rms->faultCode2; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint64_t getRmsFaultCode2() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint64_t val = data->rms->faultCode2; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsFaultCode2(uint64_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->faultCode2 = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsFaultCode2(uint64_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->faultCode2 = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int16_t getRmsCommandedTorque() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - int16_t val = data->rms->commandedTorque; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +int16_t getRmsCommandedTorque() { + pthread_mutex_lock(&data->rms->rmsMutex); + int16_t val = data->rms->commandedTorque; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsCommandedTorque(int16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->commandedTorque = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsCommandedTorque(int16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->commandedTorque = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int16_t getRmsActualTorque() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - int16_t val = data->rms->actualTorque; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +int16_t getRmsActualTorque() { + pthread_mutex_lock(&data->rms->rmsMutex); + int16_t val = data->rms->actualTorque; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsActualTorque(int16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->actualTorque = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsActualTorque(int16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->actualTorque = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsRelayState() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->relayState; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsRelayState() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->relayState; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsRelayState(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->relayState = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsRelayState(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->relayState = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsElectricalFreq() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->electricalFreq; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsElectricalFreq() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->electricalFreq; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsElectricalFreq(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->electricalFreq = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsElectricalFreq(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->electricalFreq = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int16_t getRmsDcBusCurrent() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - int16_t val = data->rms->dcBusCurrent; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +int16_t getRmsDcBusCurrent() { + pthread_mutex_lock(&data->rms->rmsMutex); + int16_t val = data->rms->dcBusCurrent; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsDcBusCurrent(int16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->dcBusCurrent = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsDcBusCurrent(int16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->dcBusCurrent = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsOutputVoltageLn() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->outputVoltageLn; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsOutputVoltageLn() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->outputVoltageLn; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsOutputVoltageLn(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->outputVoltageLn = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsOutputVoltageLn(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->outputVoltageLn = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsVSMCode() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->VSMCode; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsVSMCode() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->VSMCode; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsVSMCode(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->VSMCode = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsVSMCode(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->VSMCode = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -uint16_t getRmsKeyMode() -{ - pthread_mutex_lock(&data->rms->rmsMutex); - uint16_t val = data->rms->keyMode; - pthread_mutex_unlock(&data->rms->rmsMutex); - return val; +uint16_t getRmsKeyMode() { + pthread_mutex_lock(&data->rms->rmsMutex); + uint16_t val = data->rms->keyMode; + pthread_mutex_unlock(&data->rms->rmsMutex); + return val; } -void setRmsKeyMode(uint16_t val) -{ - pthread_mutex_lock(&data->rms->rmsMutex); - data->rms->keyMode = val; - pthread_mutex_unlock(&data->rms->rmsMutex); +void setRmsKeyMode(uint16_t val) { + pthread_mutex_lock(&data->rms->rmsMutex); + data->rms->keyMode = val; + pthread_mutex_unlock(&data->rms->rmsMutex); } -int getFlagsReadyPump() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->readyPump; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsReadyPump() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->readyPump; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsReadyPump(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->readyPump = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsReadyPump(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->readyPump = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -int getFlagsPumpDown() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->pumpDown; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsPumpDown() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->pumpDown; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsPumpDown(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->pumpDown = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsPumpDown(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->pumpDown = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -int getFlagsReadyCommand() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->readyCommand; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsReadyCommand() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->readyCommand; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsReadyCommand(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->readyCommand = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsReadyCommand(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->readyCommand = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsReadyToBrake() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->readyToBrake; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsReadyToBrake() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->readyToBrake; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsReadyToBrake(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->readyToBrake = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsReadyToBrake(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->readyToBrake = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -int getFlagsPropulse() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->propulse; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsPropulse() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->propulse; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsPropulse(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->propulse = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsPropulse(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->propulse = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -int getFlagsEmergencyBrake() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->emergencyBrake; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsEmergencyBrake() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->emergencyBrake; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsEmergencyBrake(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->emergencyBrake = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsEmergencyBrake(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->emergencyBrake = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -int getFlagsShouldStop() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->shouldStop; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsShouldStop() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->shouldStop; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsShouldStop(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->shouldStop = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsShouldStop(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->shouldStop = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -int getFlagsShutdown() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - int val = data->flags->shutdown; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +int getFlagsShutdown() { + pthread_mutex_lock(&data->flags->flagsMutex); + int val = data->flags->shutdown; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsShutdown(int val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->shutdown = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsShutdown(int val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->shutdown = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsShouldBrake() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->shouldBrake; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsShouldBrake() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->shouldBrake; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsShouldBrake(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->shouldBrake = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsShouldBrake(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->shouldBrake = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsIsConnected() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->isConnected; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsIsConnected() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->isConnected; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsIsConnected(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->isConnected = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsIsConnected(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->isConnected = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsBrakeInit() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->brakeInit; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsBrakeInit() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->brakeInit; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsBrakeInit(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->brakeInit = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsBrakeInit(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->brakeInit = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsBrakePrimAct() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->brakePrimAct; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsBrakePrimAct() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->brakePrimAct; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsBrakePrimAct(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->brakePrimAct = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsBrakePrimAct(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->brakePrimAct = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsBrakeSecAct() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->brakeSecAct; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsBrakeSecAct() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->brakeSecAct; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsBrakeSecAct(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->brakeSecAct = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsBrakeSecAct(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->brakeSecAct = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsBrakePrimRetr() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->brakePrimRetr; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsBrakePrimRetr() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->brakePrimRetr; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsBrakePrimRetr(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->brakePrimRetr = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsBrakePrimRetr(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->brakePrimRetr = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsBrakeSecRetr() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->brakeSecRetr; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsBrakeSecRetr() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->brakeSecRetr; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsBrakeSecRetr(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->brakeSecRetr = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsBrakeSecRetr(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->brakeSecRetr = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -bool getFlagsClrMotionData() -{ - pthread_mutex_lock(&data->flags->flagsMutex); - bool val = data->flags->clrMotionData; - pthread_mutex_unlock(&data->flags->flagsMutex); - return val; +bool getFlagsClrMotionData() { + pthread_mutex_lock(&data->flags->flagsMutex); + bool val = data->flags->clrMotionData; + pthread_mutex_unlock(&data->flags->flagsMutex); + return val; } -void setFlagsClrMotionData(bool val) -{ - pthread_mutex_lock(&data->flags->flagsMutex); - data->flags->clrMotionData = val; - pthread_mutex_unlock(&data->flags->flagsMutex); +void setFlagsClrMotionData(bool val) { + pthread_mutex_lock(&data->flags->flagsMutex); + data->flags->clrMotionData = val; + pthread_mutex_unlock(&data->flags->flagsMutex); } -uint64_t getTimersStartTime() -{ - pthread_mutex_lock(&data->timers->timersMutex); - uint64_t val = data->timers->startTime; - pthread_mutex_unlock(&data->timers->timersMutex); - return val; +uint64_t getTimersStartTime() { + pthread_mutex_lock(&data->timers->timersMutex); + uint64_t val = data->timers->startTime; + pthread_mutex_unlock(&data->timers->timersMutex); + return val; } -void setTimersStartTime(uint64_t val) -{ - pthread_mutex_lock(&data->timers->timersMutex); - data->timers->startTime = val; - pthread_mutex_unlock(&data->timers->timersMutex); +void setTimersStartTime(uint64_t val) { + pthread_mutex_lock(&data->timers->timersMutex); + data->timers->startTime = val; + pthread_mutex_unlock(&data->timers->timersMutex); } -uint64_t getTimersOldRetro() -{ - pthread_mutex_lock(&data->timers->timersMutex); - uint64_t val = data->timers->oldRetro; - pthread_mutex_unlock(&data->timers->timersMutex); - return val; +uint64_t getTimersOldRetro() { + pthread_mutex_lock(&data->timers->timersMutex); + uint64_t val = data->timers->oldRetro; + pthread_mutex_unlock(&data->timers->timersMutex); + return val; } -void setTimersOldRetro(uint64_t val) -{ - pthread_mutex_lock(&data->timers->timersMutex); - data->timers->oldRetro = val; - pthread_mutex_unlock(&data->timers->timersMutex); +void setTimersOldRetro(uint64_t val) { + pthread_mutex_lock(&data->timers->timersMutex); + data->timers->oldRetro = val; + pthread_mutex_unlock(&data->timers->timersMutex); } -uint64_t getTimersLastRetro() -{ - pthread_mutex_lock(&data->timers->timersMutex); - uint64_t val = data->timers->lastRetro; - pthread_mutex_unlock(&data->timers->timersMutex); - return val; +uint64_t getTimersLastRetro() { + pthread_mutex_lock(&data->timers->timersMutex); + uint64_t val = data->timers->lastRetro; + pthread_mutex_unlock(&data->timers->timersMutex); + return val; } -void setTimersLastRetro(uint64_t val) -{ - pthread_mutex_lock(&data->timers->timersMutex); - data->timers->lastRetro = val; - pthread_mutex_unlock(&data->timers->timersMutex); +void setTimersLastRetro(uint64_t val) { + pthread_mutex_lock(&data->timers->timersMutex); + data->timers->lastRetro = val; + pthread_mutex_unlock(&data->timers->timersMutex); } -uint64_t getTimersLastRetros(int index) -{ - pthread_mutex_lock(&data->timers->timersMutex); - uint64_t val = data->timers->lastRetros[index]; - pthread_mutex_unlock(&data->timers->timersMutex); - return val; +uint64_t getTimersLastRetros(int index) { + pthread_mutex_lock(&data->timers->timersMutex); + uint64_t val = data->timers->lastRetros[index]; + pthread_mutex_unlock(&data->timers->timersMutex); + return val; } -void setTimersLastRetros(uint64_t val, int index) -{ - pthread_mutex_lock(&data->timers->timersMutex); - data->timers->lastRetros[index] = val; - pthread_mutex_unlock(&data->timers->timersMutex); +void setTimersLastRetros(uint64_t val, int index) { + pthread_mutex_lock(&data->timers->timersMutex); + data->timers->lastRetros[index] = val; + pthread_mutex_unlock(&data->timers->timersMutex); } -uint64_t getTimersCrawlTimer() -{ - pthread_mutex_lock(&data->timers->timersMutex); - uint64_t val = data->timers->crawlTimer; - pthread_mutex_unlock(&data->timers->timersMutex); - return val; +uint64_t getTimersCrawlTimer() { + pthread_mutex_lock(&data->timers->timersMutex); + uint64_t val = data->timers->crawlTimer; + pthread_mutex_unlock(&data->timers->timersMutex); + return val; } -void setTimersCrawlTimer(uint64_t val) -{ - pthread_mutex_lock(&data->timers->timersMutex); - data->timers->crawlTimer = val; - pthread_mutex_unlock(&data->timers->timersMutex); +void setTimersCrawlTimer(uint64_t val) { + pthread_mutex_lock(&data->timers->timersMutex); + data->timers->crawlTimer = val; + pthread_mutex_unlock(&data->timers->timersMutex); } /* Autogenerated Code Ends */ diff --git a/embedded/examples/CMakeLists.txt b/embedded/examples/CMakeLists.txt index 023e55b4..ef8a4fc4 100644 --- a/embedded/examples/CMakeLists.txt +++ b/embedded/examples/CMakeLists.txt @@ -4,10 +4,10 @@ add_executable(dashTest dashTest.cpp) add_executable(navTest navTest.cpp) add_executable(solenoidTest solenoidTest.c) add_executable(brakingTest brakingTest.cpp) -add_executable(gpioHvTest gpioHvTest.c) +add_executable(gpioHvTest gpioHvTest.cpp) add_executable(oldMotorTest oldMotorTest.c) add_executable(retroTest retroTest.c) -add_executable(stateTest stateTest.c) +add_executable(stateTest stateTest.cpp) add_executable(can_test can_test.c) add_executable(imu_test imu_test.c) add_executable(presTest presTest.c) diff --git a/embedded/examples/bmsDisplay.cpp b/embedded/examples/bmsDisplay.cpp index fac97232..0aaba82d 100644 --- a/embedded/examples/bmsDisplay.cpp +++ b/embedded/examples/bmsDisplay.cpp @@ -1,7 +1,7 @@ #include #include +#include #include -#include extern "C" { #include "NCD9830DBR2G.h" #include "bms.h" @@ -11,6 +11,7 @@ extern "C" { extern pthread_t CANThread; } +HVIox hv_iox; int main() { initData(); diff --git a/embedded/examples/brakingTest.cpp b/embedded/examples/brakingTest.cpp index cef618ec..3d474dda 100644 --- a/embedded/examples/brakingTest.cpp +++ b/embedded/examples/brakingTest.cpp @@ -3,6 +3,8 @@ #include #include #include +#include "hv_iox.h" + extern "C" { #include "braking.h" #include "data.h" @@ -12,6 +14,8 @@ extern "C" { #define NUM_LIM_SWITCHES 2 /* In test */ #define FOREVER while (1) +HVIox hv_iox; + void showBrakingInfo() { int i = 0; diff --git a/embedded/examples/dashTest.cpp b/embedded/examples/dashTest.cpp index 49b9d771..b0a49c2f 100644 --- a/embedded/examples/dashTest.cpp +++ b/embedded/examples/dashTest.cpp @@ -1,3 +1,4 @@ +#include "hv_iox.h" #include #include #include @@ -5,12 +6,13 @@ extern "C" { #include "can_devices.h" #include "data.h" -#include "hv_iox.h" #include "motor.h" #include "proc_iox.h" #include "state_machine.h" } +HVIox hv_iox; + int init() { initData(); diff --git a/embedded/examples/gpioHvTest.c b/embedded/examples/gpioHvTest.cpp similarity index 84% rename from embedded/examples/gpioHvTest.c rename to embedded/examples/gpioHvTest.cpp index 3b518c59..68ab715d 100644 --- a/embedded/examples/gpioHvTest.c +++ b/embedded/examples/gpioHvTest.cpp @@ -1,15 +1,18 @@ -#include #include + +extern "C" { +#include #include #include #include -#include +} +HVIox hv_iox; int main() { initData(); - initHVIox(false); - i2c_settings iox = getHVIoxDev(); + hv_iox.init(false); + i2c_settings iox = hv_iox.getHVIoxDev(); printf("---Showing HV IOX---\n"); for (int i = 0; i < 16; i++) { printf("PIN: %d, VAL: %d, DIR: %d\n", i, getState(&iox, i), getDir(&iox, i)); diff --git a/embedded/examples/navTest.cpp b/embedded/examples/navTest.cpp index 69b7d93c..6493a3f6 100644 --- a/embedded/examples/navTest.cpp +++ b/embedded/examples/navTest.cpp @@ -8,12 +8,13 @@ extern "C" { } #include "connStat.h" #include +#include #define ROLL "roll" #define EXP "exp" #define RAW "raw" extern void initNav(); - +HVIox hv_iox; int main(int argc, char* argv[]) { initData(); diff --git a/embedded/examples/stateTest.c b/embedded/examples/stateTest.cpp similarity index 98% rename from embedded/examples/stateTest.c rename to embedded/examples/stateTest.cpp index 4457e913..49e2f40b 100644 --- a/embedded/examples/stateTest.c +++ b/embedded/examples/stateTest.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -7,6 +7,10 @@ #include #include +extern "C" { +#include +} + #define PASS 0 #define FAIL 1 @@ -32,6 +36,7 @@ static pthread_t smThread; static sem_t smSem; +HVIox hv_iox; static void genericInit(char* name); static void goToState(char* name); @@ -233,7 +238,7 @@ int main() if (sem_init(&smSem, 0, 1) != 0) { return -1; } - if (pthread_create(&smThread, NULL, stateMachineLoop, NULL) != 0) + if (pthread_create(&smThread, NULL, (void* (*)(void*))stateMachineLoop, NULL) != 0) return -1; WAIT(.5); RUN_TEST(crawlTimerTest); diff --git a/embedded/peripherals/CMakeLists.txt b/embedded/peripherals/CMakeLists.txt index 1e27d199..876ce309 100644 --- a/embedded/peripherals/CMakeLists.txt +++ b/embedded/peripherals/CMakeLists.txt @@ -4,8 +4,6 @@ project(peripheralslib VERSION 1.0 #Define sources for library add_library(peripherals src/batt.c src/braking.c - src/hv_iox.c - src/lv_iox.c src/lv_iox.c src/NCD9830DBR2G.c src/retro.c @@ -14,7 +12,8 @@ add_library(peripherals src/batt.c src/imu.c src/mcp23017.c src/proc_iox.c - src/rms.c) + src/rms.c + src/hv_iox.cpp) # Run Autocoder add_dependencies(peripherals autocoder) diff --git a/embedded/peripherals/include/hv_iox.h b/embedded/peripherals/include/hv_iox.h index dd163e3d..cbf0c84c 100644 --- a/embedded/peripherals/include/hv_iox.h +++ b/embedded/peripherals/include/hv_iox.h @@ -1,9 +1,14 @@ #ifndef __HV_IOX_H__ #define __HV_IOX_H__ +#include + +extern "C" { +#include #include #include -#include +#include +} #define HV_IND_EN MCP_GPIOB_0 #define MCU_LATCH MCP_GPIOB_1 @@ -17,33 +22,41 @@ #define BMS_STAT_FDBK MCP_GPIOA_2 #define E_STOP_FDBK MCP_GPIOA_1 #define MSTR_SW_FDBK MCP_GPIOA_0 +class HVIox { +public: + HVIox(void); + + int init(bool); -int initHVIox(bool hardStart); + int setupIox(void); -i2c_settings getHVIoxDev(void); + i2c_settings getHVIoxDev(void); -int isHVIndicatorEnabled(void); + int isHVIndicatorEnabled(void); -int setMCULatch(bool val); + int setMCULatch(bool val); -int getBMSMultiIn(void); + int getBMSMultiIn(void); -int getIMDStatus(void); + int getIMDStatus(void); -int getINRTStatus(void); + int getINRTStatus(void); -int isHVEnabled(void); + int isHVEnabled(void); -int isMCUHVEnabled(void); + int isMCUHVEnabled(void); -int getPsStatus(void); + int getPsStatus(void); -int getBMSStatus(void); + int getBMSStatus(void); -int isEStopOn(void); + int isEStopOn(void); -int getMasterSwFeedback(void); + int getMasterSwFeedback(void); -int setMCUHVEnabled(int val); + int setMCUHVEnabled(int val); + int emergencyDisableMCU(void); +}; +extern HVIox hv_iox; #endif diff --git a/embedded/peripherals/src/hv_iox.c b/embedded/peripherals/src/hv_iox.c.deprecated similarity index 100% rename from embedded/peripherals/src/hv_iox.c rename to embedded/peripherals/src/hv_iox.c.deprecated diff --git a/embedded/peripherals/src/hv_iox.cpp b/embedded/peripherals/src/hv_iox.cpp new file mode 100644 index 00000000..d191b26a --- /dev/null +++ b/embedded/peripherals/src/hv_iox.cpp @@ -0,0 +1,174 @@ +#include +#include +#include +#include + +extern "C" { +#include +#include +#include +#include +} + +#define HV_IO_ADDR 0x24 + +#ifdef NOI2C +#define VI2C +#endif + +static i2c_settings iox; +static int setupIox(void); + +/*** + * initHVIox - Meant to be overly pedantic + * even if the values arent changing, + * just to make extremely clear the initial + * state of everything. + * + */ +HVIox::HVIox() +{ +} + +int HVIox::init(bool hardStart) +{ + if (setupMCP(&iox, HV_IO_ADDR) != 0) + return -1; + else if (hardStart) { + if (clearSettingsMCP(&iox) != 0) + return -1; + else if (this->setupIox() != 0) + return -1; + } + return 0; +} + +int HVIox::setupIox() +{ + // static int setupIox() moved into constructor: + setDir(&iox, HV_IND_EN, MCP_DIR_IN); + setDir(&iox, MCU_LATCH, MCP_DIR_OUT); + setDir(&iox, BMS_MULTI_IN, MCP_DIR_IN); + setDir(&iox, IMD_STAT_FDBK, MCP_DIR_IN); + setDir(&iox, INRT_STAT_FDBK, MCP_DIR_IN); + setDir(&iox, HV_EN_FDBK, MCP_DIR_IN); + setDir(&iox, MCU_HV_EN, MCP_DIR_IN); + setDir(&iox, PS_FDBK, MCP_DIR_IN); + setDir(&iox, BMS_STAT_FDBK, MCP_DIR_IN); + setDir(&iox, E_STOP_FDBK, MCP_DIR_IN); + setDir(&iox, MSTR_SW_FDBK, MCP_DIR_IN); + + return 0; +} + +i2c_settings HVIox::getHVIoxDev() +{ + return iox; +} + +int HVIox::isHVIndicatorEnabled() +{ +#ifdef NOI2C + return 1; +#endif + return getState(&iox, HV_IND_EN); +} + +int HVIox::setMCULatch(bool val) +{ +#ifdef NOI2C + return 0; +#endif + return setState(&iox, MCU_LATCH, val); +} + +int HVIox::getBMSMultiIn() +{ +#ifdef NOI2C + return 1; +#endif + return getState(&iox, BMS_MULTI_IN); +} + +int HVIox::getIMDStatus() +{ +#ifdef NOI2C + return 1; +#endif + return getBmsImdStatus() >= 4; //getState(&iox, IMD_STAT_FDBK); +} + +int HVIox::getINRTStatus() +{ +#ifdef NOI2C + return 1; +#endif + return getState(&iox, INRT_STAT_FDBK); +} + +int HVIox::isHVEnabled() +{ +#ifdef NOI2C + return 0; +#endif + return getState(&iox, HV_EN_FDBK); +} + +int HVIox::setMCUHVEnabled(int val) +{ +#ifdef NOI2C + return 0; +#endif + setDir(&iox, MCU_HV_EN, MCP_DIR_OUT); + return setState(&iox, MCU_HV_EN, val); +} + +int HVIox::isMCUHVEnabled() +{ +#ifdef NOI2C + return 1; +#endif + setDir(&iox, MCU_HV_EN, MCP_DIR_IN); + return getState(&iox, MCU_HV_EN); +} + +int HVIox::emergencyDisableMCU() +{ +#ifdef NOI2C + return 1; +#endif + setDir(&iox, MCU_HV_EN, MCP_DIR_OUT); + return setState(&iox, MCU_HV_EN, true); +} + +int HVIox::getPsStatus() +{ +#ifdef NOI2C + return 1; +#endif + return getState(&iox, PS_FDBK); +} + +int HVIox::getBMSStatus() +{ +#ifdef NOI2C + return 1; +#endif + return getState(&iox, BMS_STAT_FDBK); +} + +int HVIox::isEStopOn() +{ +#ifdef NOI2C + return 0; +#endif + return getState(&iox, E_STOP_FDBK); +} + +int HVIox::getMasterSwFeedback() +{ +#ifdef NOI2C + return 1; +#endif + return getState(&iox, MSTR_SW_FDBK); +} diff --git a/gen_compile_commands b/gen_compile_commands new file mode 100755 index 00000000..84e8f100 --- /dev/null +++ b/gen_compile_commands @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "WARNING THIS WILL DELETE ALL UNTRACKED FILES!!!" +read -n 1 -s -r -p "Press any key to continue or ctrl-c to quit..." +echo "making compile commands..." +cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON . +echo "done!" +echo "cleaning git tree..." +git clean -fd +echo "done!" diff --git a/middleware/examples/TelemetryLoopTest.cpp b/middleware/examples/TelemetryLoopTest.cpp index bef600fc..00103092 100644 --- a/middleware/examples/TelemetryLoopTest.cpp +++ b/middleware/examples/TelemetryLoopTest.cpp @@ -1,12 +1,16 @@ #include "TelemetryLoop.h" +#include #include #define LOCALHOST (char*)"0.0.0.0" -extern "C" { +extern "C" +{ #include "data.h" } +HVIox hv_iox; + int main() { diff --git a/middleware/libs/PracticalSocket/PracticalSocket.cpp b/middleware/libs/PracticalSocket/PracticalSocket.cpp index 992ebe92..e7980c17 100644 --- a/middleware/libs/PracticalSocket/PracticalSocket.cpp +++ b/middleware/libs/PracticalSocket/PracticalSocket.cpp @@ -255,7 +255,7 @@ unsigned short CommunicatingSocket::getForeignPort() TCPSocket::TCPSocket() : CommunicatingSocket(SOCK_STREAM, - IPPROTO_TCP) + IPPROTO_TCP) { } @@ -308,7 +308,7 @@ void TCPServerSocket::setListen(int queueLen) UDPSocket::UDPSocket() : CommunicatingSocket(SOCK_DGRAM, - IPPROTO_UDP) + IPPROTO_UDP) { setBroadcast(); } diff --git a/middleware/src/HVTCPSocket.cpp b/middleware/src/HVTCPSocket.cpp index f76d6448..60107eca 100644 --- a/middleware/src/HVTCPSocket.cpp +++ b/middleware/src/HVTCPSocket.cpp @@ -8,10 +8,16 @@ #include #include #include +#include "HVTCPSocket.h" +#include "motor.h" +#include "state_machine.h" +#include +#include +#include #define SA struct sockaddr -extern "C" { -#include "braking.h" +extern "C" +{ #include "connStat.h" #include "data.h" #include "hv_iox.h" @@ -144,10 +150,10 @@ void* TCPLoop(void* arg) setFlagsEmergencyBrake(1); } if (!strncmp(buffer, "mcuLatchOn", MAX_COMMAND_SIZE)) { - setMCULatch(true); + hv_iox.setMCULatch(true); } if (!strncmp(buffer, "mcuLatchOff", MAX_COMMAND_SIZE)) { - setMCULatch(false); + hv_iox.setMCULatch(false); } if (!strncmp(buffer, "enPrecharge", MAX_COMMAND_SIZE)) { /* pthread_create(&hbT, NULL, hbLoop, NULL);*/ @@ -163,11 +169,11 @@ void* TCPLoop(void* arg) if (!strncmp(buffer, "hvEnable", MAX_COMMAND_SIZE)) { /* Lets add a safety check here */ - setMCUHVEnabled(true); + hv_iox.setMCUHVEnabled(true); } if (!strncmp(buffer, "hvDisable", MAX_COMMAND_SIZE)) { - setMCUHVEnabled(false); + hv_iox.setMCUHVEnabled(false); } if (!strncmp(buffer, "override", 8)) { @@ -188,27 +194,25 @@ void* TCPLoop(void* arg) void signalLV(char* cmd) { - fprintf(stderr, "THERE IS NOTHING TO SIGNAL TO DO NOT SIGNAL LV\n"); - int srvFd; - - int opt = 1; - - struct sockaddr_in addr; - int addrlen = sizeof(addr); - - if ((srvFd = socket(AF_INET, SOCK_STREAM, 0)) == 0) - { - fprintf(stderr, "Error signalling\n"); - exit(1); - } - - if (setsockopt(srvFd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, - &opt, sizeof(opt))) - { - fprintf(stderr, "Signal error\n"); - exit(1); - } - + fprintf(stderr, "THERE IS NOTHING TO SIGNAL TO DO NOT SIGNAL LV\n"); + int srvFd; + + int opt = 1; + + struct sockaddr_in addr; + int addrlen = sizeof(addr); + + if ((srvFd = socket(AF_INET, SOCK_STREAM, 0)) == 0) { + fprintf(stderr, "Error signalling\n"); + exit(1); + } + + if (setsockopt(srvFd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, + &opt, sizeof(opt))) { + fprintf(stderr, "Signal error\n"); + exit(1); + } + addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(LV_SERVER_IP); addr.sin_port = htons(LV_SERVER_PORT); diff --git a/middleware/src/TelemetryLoop.cpp b/middleware/src/TelemetryLoop.cpp index b3ac0b2c..239181e7 100644 --- a/middleware/src/TelemetryLoop.cpp +++ b/middleware/src/TelemetryLoop.cpp @@ -16,9 +16,8 @@ #include #include -extern "C" { -#include #include +extern "C" { #include } @@ -100,7 +99,7 @@ void* TelemetryLoop(void* arg) addToBuffer(&buffer, &time); // Write 1 byte IMD status - uint8_t imdStatus = getIMDStatus(); + uint8_t imdStatus = hv_iox.getIMDStatus(); addToBuffer(&buffer, &imdStatus); // Write 4 byte primary brake @@ -117,6 +116,7 @@ void* TelemetryLoop(void* arg) #endif addToBuffer(&buffer, &secBrake); + /* Autogenerated Code Begins */ addToBuffer(&buffer, getDataState()); addToBuffer(&buffer, getPressurePrimTank()); @@ -194,10 +194,11 @@ void* TelemetryLoop(void* arg) addToBuffer(&buffer, getTimersStartTime()); addToBuffer(&buffer, getTimersOldRetro()); addToBuffer(&buffer, getTimersLastRetro()); - for (int i = 0; i < 3; i++) - addToBuffer(&buffer, getTimersLastRetros(i)); + for(int i = 0; i < 3; i++) + addToBuffer(&buffer, getTimersLastRetros(i)); addToBuffer(&buffer, getTimersCrawlTimer()); /* Autogenerated Code Ends */ + // Tail: Cyclic Redundancy Check (32 bit) uint32_t crc = CRC::Calculate(buffer.data(), buffer.size(), CRC::CRC_32()); @@ -223,4 +224,4 @@ void* TelemetryLoop(void* arg) cerr << e.what() << endl; exit(1); } -} \ No newline at end of file +}