Skip to content

Commit

Permalink
Added new BMS counters
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Apr 8, 2021
1 parent 2848ec1 commit 101f293
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
30 changes: 30 additions & 0 deletions bms.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,30 @@ bool bms_process_can_frame(uint32_t can_id, uint8_t *data8, int len, bool is_ext
}
} break;

case CAN_PACKET_BMS_AH_WH_CHG_TOTAL: {
used_data = true;

if (id == m_values.can_id || UTILS_AGE_S(m_values.update_time) > MAX_CAN_AGE_SEC) {
int32_t ind = 0;
m_values.can_id = id;
m_values.update_time = chVTGetSystemTimeX();
m_values.ah_cnt_chg_total = buffer_get_float32_auto(data8, &ind);
m_values.wh_cnt_chg_total = buffer_get_float32_auto(data8, &ind);
}
} break;

case CAN_PACKET_BMS_AH_WH_DIS_TOTAL: {
used_data = true;

if (id == m_values.can_id || UTILS_AGE_S(m_values.update_time) > MAX_CAN_AGE_SEC) {
int32_t ind = 0;
m_values.can_id = id;
m_values.update_time = chVTGetSystemTimeX();
m_values.ah_cnt_dis_total = buffer_get_float32_auto(data8, &ind);
m_values.wh_cnt_dis_total = buffer_get_float32_auto(data8, &ind);
}
} break;

default:
break;
}
Expand Down Expand Up @@ -390,6 +414,12 @@ void bms_process_cmd(unsigned char *data, unsigned int len,
// CAN ID
send_buffer[ind++] = m_values.can_id;

// Total charge and discharge counters
buffer_append_float32_auto(send_buffer, m_values.ah_cnt_chg_total, &ind);
buffer_append_float32_auto(send_buffer, m_values.wh_cnt_chg_total, &ind);
buffer_append_float32_auto(send_buffer, m_values.ah_cnt_dis_total, &ind);
buffer_append_float32_auto(send_buffer, m_values.wh_cnt_dis_total, &ind);

reply_func(send_buffer, ind);
} break;

Expand Down
2 changes: 1 addition & 1 deletion conf_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define FW_VERSION_MAJOR 5
#define FW_VERSION_MINOR 03
// Set to 0 for building a release and iterate during beta test builds
#define FW_TEST_VERSION_NUMBER 17
#define FW_TEST_VERSION_NUMBER 18

#include "datatypes.h"

Expand Down
6 changes: 6 additions & 0 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ typedef struct {
float soc;
float soh;
int can_id;
float ah_cnt_chg_total;
float wh_cnt_chg_total;
float ah_cnt_dis_total;
float wh_cnt_dis_total;
systime_t update_time;
} bms_values;

Expand Down Expand Up @@ -1014,6 +1018,8 @@ typedef enum {
CAN_PACKET_BMS_HW_DATA_3,
CAN_PACKET_BMS_HW_DATA_4,
CAN_PACKET_BMS_HW_DATA_5,
CAN_PACKET_BMS_AH_WH_CHG_TOTAL,
CAN_PACKET_BMS_AH_WH_DIS_TOTAL,
} CAN_PACKET_ID;

// Logged fault data
Expand Down

0 comments on commit 101f293

Please sign in to comment.