Skip to content

Commit

Permalink
Proof of concept for 4 indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielDelgado committed Sep 30, 2023
1 parent e357a69 commit 9dd1bc0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 2
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
Expand Down
126 changes: 64 additions & 62 deletions Apps/Src/ReadTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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:
Expand All @@ -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;
}

0 comments on commit 9dd1bc0

Please sign in to comment.