Skip to content

Commit

Permalink
Hopefully Did Fan Batt Box Control Code
Browse files Browse the repository at this point in the history
  • Loading branch information
dnakhooda committed Jan 16, 2025
1 parent 134f199 commit 57a0d60
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Core/Inc/control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "pdu.h"

// TODO: replace this temp value with real value
#define CONTROL_CANID_FANBATTBOX = 0xA

extern osThreadId_t control_handle;
extern const osThreadAttr_t control_attributes;

typedef struct {
pdu_t *pdu;
} control_args_t;

void vEval_fanbattbox_state(void *param);

void control_fanbattbox_record(can_msg_t args);

int eval_fanbattbox_state();
4 changes: 4 additions & 0 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "fault.h"
#include "stdio.h"
#include "steeringio.h"
#include "control.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -163,6 +164,9 @@ void vCanReceive(void *pv_params)
case STEERING_CANID_IO:
steeringio_update(msg);
break;
case CONTROL_CANID_FANBATTBOX:
control_fanbattbox_record(msg);
break;
default:
break;
}
Expand Down
35 changes: 35 additions & 0 deletions Core/Src/control.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "control.h"
#include "pdu.h"

osThreadId_t control_handle;
const osThreadAttr_t control_attributes = {
.name = "Control",
.stack_size = 128 * 8,
.priority = (osPriority_t)osPriorityRealtime,
};

static int fanBattBoxState = 0;

void vEval_fanbattbox_state(void *param)
{
control_args_t args = (control_args_t *)param;
pdu_t *pdu = args->pdu;

write_fan_battbox(pdu, eval_fanbattbox_state());

osDelay(1000);
}

void control_fanbattbox_record(can_msg_t msg)
{
if (msg.data > 0) {
fanBattBoxState = 1;
} else {
fanBattBoxState = 0;
}
}

int eval_fanbattbox_state()
{
return fanBattBoxState;
}
9 changes: 9 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "dti.h"
#include "steeringio.h"
#include "pedals.h"
#include "control.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -248,6 +249,14 @@ int main(void)
sm_args->mpu = mpu;
sm_director_handle = osThreadNew(vStateMachineDirector, sm_args, &sm_director_attributes);
assert(sm_director_handle);

/* Control File Thread */
control_args_t *control_args = malloc(sizeof(control_args_t));
control_args->pdu = pdu;
control_handle =
osThreadNew(vEval_fanbattbox_state, control_args, &control_attributes);
assert(control_handle);

/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_EVENTS */
Expand Down

0 comments on commit 57a0d60

Please sign in to comment.