Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Debug] - Add timer start/stop notices #143

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define FAULT_CANID 0x703
#define NOISE_CANID 0x88
#define DEBUG_CANID 0x702
#define FAULT_TIMER_CANID 0x701

typedef struct {
uint32_t prev_tick;
Expand All @@ -45,6 +46,7 @@ typedef enum {
FAULT,
NOISE,
DEBUG,
FAULT_TIMER,
RL_MSG_COUNT
} rate_lim_t;

Expand Down
3 changes: 3 additions & 0 deletions Core/Inc/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ void compute_send_segment_temp_message(acc_data_t *bmsdata);

void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl);

void compute_send_fault_timer_message(uint8_t start_stop, uint16_t fault_code,
uint16_t data_1);

/**
* @brief Send CAN message for debugging the car on the fly.
*
Expand Down
8 changes: 8 additions & 0 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void init_can_msg_config()
debug_msg.id = DEBUG_CANID;
debug_msg.len = 8; // yaml decodes this to 8 bytes

can_msg_t fault_timer_msg;
fault_timer_msg.id = FAULT_TIMER_CANID;
fault_timer_msg.len = 5;

// rl_data_t rl_discharge_data = { .msg_rate = 5000 };
// rl_data_t rl_charge_data = { .msg_rate = 0 };

Expand All @@ -112,6 +116,7 @@ void init_can_msg_config()
bms_can_msgs[FAULT] = fault_msg;
bms_can_msgs[NOISE] = noise_msg;
bms_can_msgs[DEBUG] = debug_msg;
bms_can_msgs[FAULT_TIMER] = fault_timer_msg;

// rl_data[DISCHARGE] = rl_discharge_data;
// rl_data[CHARGE] = rl_charge_data;
Expand Down Expand Up @@ -159,6 +164,9 @@ rl_data_t *get_rl_msg(uint32_t can_id)
case DEBUG_CANID:
return &rl_data[DEBUG];
break;
case FAULT_TIMER_CANID:
return &rl_data[FAULT_TIMER];
break;
default:
break;
}
Expand Down
24 changes: 24 additions & 0 deletions Core/Src/compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,30 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl)
queue_can_msg(bms_can_msgs[FAULT]);
}

void compute_send_fault_timer_message(uint8_t start_stop, uint16_t fault_code,
uint16_t data_1)
{
struct __attribute__((__packed__)) {
uint8_t start_stop;
uint16_t fault_code;
jr1221 marked this conversation as resolved.
Show resolved Hide resolved
int16_t data_1;
} fault_timer_msg_data;

fault_timer_msg_data.start_stop = start_stop;
fault_timer_msg_data.fault_code = fault_code;
jr1221 marked this conversation as resolved.
Show resolved Hide resolved
fault_timer_msg_data.data_1 = data_1;

endian_swap(&fault_timer_msg_data.fault_code,
sizeof(fault_timer_msg_data.fault_code));
endian_swap(&fault_timer_msg_data.data_1,
sizeof(fault_timer_msg_data.data_1));

memcpy(bms_can_msgs[FAULT_TIMER].data, &fault_timer_msg_data,
sizeof(fault_timer_msg_data));

queue_can_msg(bms_can_msgs[FAULT_TIMER]);
}

void compute_send_voltage_noise_message(acc_data_t *bmsdata)
{
struct __attribute__((__packed__)) {
Expand Down
3 changes: 3 additions & 0 deletions Core/Src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ uint32_t sm_fault_eval(fault_eval_t *index)
if (!fault_present) {
printf("\t\t\t*******Fault cleared: %s\r\n", index->id);
cancel_timer(&index->timer);
compute_send_fault_timer_message(0, index->code,
index->data_1);
return 0;
}

Expand All @@ -321,6 +323,7 @@ uint32_t sm_fault_eval(fault_eval_t *index)
else if (!is_timer_active(&index->timer) && fault_present) {
printf("\t\t\t*******Starting fault timer: %s\r\n", index->id);
start_timer(&index->timer, index->timeout);
compute_send_fault_timer_message(1, index->code, index->data_1);
if (index->code == DISCHARGE_LIMIT_ENFORCEMENT_FAULT) {
compute_send_fault_message(1, index->data_1,
index->lim_1);
Expand Down