From 9dd1bc06b9da4bbc62f5b42666f9b48d93564013 Mon Sep 17 00:00:00 2001 From: Nathaniel Delgado Date: Sat, 30 Sep 2023 12:03:41 -0500 Subject: [PATCH] Proof of concept for 4 indentation --- .clang-format | 2 +- Apps/Src/ReadTritium.c | 126 +++++++++++++++++++++-------------------- 2 files changed, 65 insertions(+), 63 deletions(-) diff --git a/.clang-format b/.clang-format index b1392af5..26651a2c 100644 --- a/.clang-format +++ b/.clang-format @@ -108,7 +108,7 @@ IndentGotoLabels: true IndentPPDirectives: None IndentExternBlock: AfterExternBlock IndentRequires: false -IndentWidth: 2 +IndentWidth: 4 IndentWrappedFunctionNames: false InsertTrailingCommas: None JavaScriptQuotes: Leave diff --git a/Apps/Src/ReadTritium.c b/Apps/Src/ReadTritium.c index 310029e8..7e84b13c 100644 --- a/Apps/Src/ReadTritium.c +++ b/Apps/Src/ReadTritium.c @@ -13,7 +13,7 @@ // status limit flag masks #define MASK_MOTOR_TEMP_LIMIT \ - (1 << 6) // check if motor temperature is limiting the motor 6 + (1 << 6) // check if motor temperature is limiting the motor 6 #define MAX_CAN_LEN 8 uint16_t Motor_FaultBitmap = T_NONE; @@ -25,13 +25,13 @@ static float Motor_Velocity = CAR_STOPPED; //^^^^ * */ tritium_error_code_t MotorController_getTritiumError(void) { - // TODO: implement for loop to parse this - for (int i = 0; i < NUM_TRITIUM_ERRORS; ++i) { - if (Motor_FaultBitmap & (1 << i)) { - return ((tritium_error_code_t)(1 << i)); + // TODO: implement for loop to parse this + for (int i = 0; i < NUM_TRITIUM_ERRORS; ++i) { + if (Motor_FaultBitmap & (1 << i)) { + return ((tritium_error_code_t)(1 << i)); + } } - } - return T_NONE; + return T_NONE; } /** @@ -40,12 +40,12 @@ tritium_error_code_t MotorController_getTritiumError(void) { * @param motor_err Bitmap which has motor error codes */ static void assertTritiumError(uint16_t motor_err) { - OS_ERR err; - if (motor_err != T_NONE) { - FaultBitmap |= FAULT_TRITIUM; - OSSemPost(&FaultState_Sem4, OS_OPT_POST_1, &err); - assertOSError(0, err); - } + OS_ERR err; + if (motor_err != T_NONE) { + FaultBitmap |= FAULT_TRITIUM; + OSSemPost(&FaultState_Sem4, OS_OPT_POST_1, &err); + assertOSError(0, err); + } } /* OBJECTIVES: @@ -70,65 +70,67 @@ Objective 2: */ void Task_ReadTritium(void *p_arg) { - OS_ERR err; - CANDATA_t dataBuf = {0}; - - while (1) { - ErrorStatus status = CANbus_Read(&dataBuf, true, MOTORCAN); - - if (status == SUCCESS) { - switch (dataBuf.ID) { - case MOTOR_STATUS: { - // motor status error flags is in bytes 4-5 - Motor_FaultBitmap = - *((uint16_t *)(&dataBuf.data[4])); // Storing error flags into - // Motor_FaultBitmap - assertTritiumError(Motor_FaultBitmap); - break; - } - - case VELOCITY: { - memcpy(&Motor_RPM, &dataBuf.data[0], sizeof(float)); - memcpy(&Motor_Velocity, &dataBuf.data[4], sizeof(float)); - - // Motor RPM is in bytes 0-3 - Motor_RPM = *((float *)(&dataBuf.data[0])); - - // Car Velocity (in m/s) is in bytes 4-7 - Motor_Velocity = *((float *)(&dataBuf.data[4])); - uint32_t Car_Velocity = Motor_Velocity; - - Car_Velocity = - ((Car_Velocity * 100) * 3600); // Converting from m/s to m/h, - // using fixed point factor of 100 - Car_Velocity = ((Car_Velocity / 160934) * - 10); // Converting from m/h to mph, multiplying by 10 - // to make value "larger" for displaying - - UpdateDisplay_SetVelocity(Car_Velocity); + OS_ERR err; + CANDATA_t dataBuf = {0}; + + while (1) { + ErrorStatus status = CANbus_Read(&dataBuf, true, MOTORCAN); + + if (status == SUCCESS) { + switch (dataBuf.ID) { + case MOTOR_STATUS: { + // motor status error flags is in bytes 4-5 + Motor_FaultBitmap = *( + (uint16_t *)(&dataBuf + .data[4])); // Storing error flags + // into Motor_FaultBitmap + assertTritiumError(Motor_FaultBitmap); + break; + } + + case VELOCITY: { + memcpy(&Motor_RPM, &dataBuf.data[0], sizeof(float)); + memcpy(&Motor_Velocity, &dataBuf.data[4], sizeof(float)); + + // Motor RPM is in bytes 0-3 + Motor_RPM = *((float *)(&dataBuf.data[0])); + + // Car Velocity (in m/s) is in bytes 4-7 + Motor_Velocity = *((float *)(&dataBuf.data[4])); + uint32_t Car_Velocity = Motor_Velocity; + + Car_Velocity = ((Car_Velocity * 100) * + 3600); // Converting from m/s to m/h, + // using fixed point factor of 100 + Car_Velocity = + ((Car_Velocity / 160934) * + 10); // Converting from m/h to mph, multiplying by 10 + // to make value "larger" for displaying + + UpdateDisplay_SetVelocity(Car_Velocity); + } + + default: { + break; // for cases not handled currently + } + } } - default: { - break; // for cases not handled currently - } - } + OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err); + assertOSError(OS_READ_TRITIUM_LOC, err); } - - OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err); - assertOSError(OS_READ_TRITIUM_LOC, err); - } } void MotorController_Restart(void) { - CANDATA_t resetmsg = {0}; - resetmsg.ID = MOTOR_RESET; - CANbus_Send(resetmsg, true, MOTORCAN); + CANDATA_t resetmsg = {0}; + resetmsg.ID = MOTOR_RESET; + CANbus_Send(resetmsg, true, MOTORCAN); } float Motor_RPM_Get() { // getter function for motor RPM - return Motor_RPM; + return Motor_RPM; } float Motor_Velocity_Get() { // getter function for motor velocity - return Motor_Velocity; + return Motor_Velocity; }