|
|
@@ -32,15 +32,62 @@ void bms_message_update_insert(int is_hall_detect){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void response_base_info(can_frame_t *frame) {
|
|
|
+ uint8_t *data = NULL;
|
|
|
+ int data_len = 0;
|
|
|
+ binfo_cmd_resp_t bresp;
|
|
|
+ bresp.capacity = get_soc()->capacity;
|
|
|
+ if (get_soc()->coulomb_now >= get_soc()->coulomb_min) {
|
|
|
+ bresp.energy = get_soc()->coulomb_now - get_soc()->coulomb_min;
|
|
|
+ }else{
|
|
|
+ bresp.energy = 0;
|
|
|
+ }
|
|
|
+ bresp.pack_current = measure_value()->load_current;
|
|
|
+ bresp.pack_voltage = bms_state_get()->pack_voltage;
|
|
|
+ bresp.max_temp = -100;
|
|
|
+ for (int i = 0; i < PACK_TEMPS_NUM; i ++){
|
|
|
+ if (bresp.max_temp < measure_value()->pack_temp[i]){
|
|
|
+ bresp.max_temp = measure_value()->pack_temp[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bresp.health = bms_health()->i_status;
|
|
|
+ if (bms_is_ps_charger_in()) {/*如果在底座或者车上(有充电器),提前置位过高/低温充电标志*/
|
|
|
+ bresp.health |= (bms_health()->lower_temp_deny_charger << 12 | bms_health()->over_temp_deny_charger << 14);
|
|
|
+ }
|
|
|
+ bresp.health &= ~(1 << 8);
|
|
|
+ bresp.health |= ((get_soc()->flags & SOC_FLAG_CALIBRATED) != 0) << 8;
|
|
|
+ stat_cmd_resp_t sresp;
|
|
|
+ sresp.insert = bms_insert;
|
|
|
+ sresp.is_charging = bms_state_get()->charging;
|
|
|
+ sresp.discharger_fet = ml5238_is_discharging();
|
|
|
+ sresp.charger_fet = ml5238_is_charging();
|
|
|
+ sresp.small_power = AUX_VOL_IS_OPEN();
|
|
|
+ sresp.is_balancing = bms_state_get()->pack_balancing;
|
|
|
+ sresp.health = (((uint16_t )(bms_health()->i_status)) != 0);
|
|
|
+ sresp.is_charger_in = io_state()->charger_detect_irq;
|
|
|
+ bresp.state = *((uint8_t*)&sresp);
|
|
|
+ data = (uint8_t *)&bresp;
|
|
|
+ data_len = sizeof(bresp);
|
|
|
+ if (frame->key == CAN_KEY_BMS_SET_POWER) {
|
|
|
+ u8 response[sizeof(bresp) + 1];
|
|
|
+ response[0] = 0;
|
|
|
+ memcpy(response + 1, data, data_len);
|
|
|
+ data = response;
|
|
|
+ data_len += 1;
|
|
|
+ }
|
|
|
+ protocol_send_bms_info(frame->head.can_addr, frame->key, data, data_len);
|
|
|
+}
|
|
|
+
|
|
|
void process_bms_message(can_frame_t *frame, int len){
|
|
|
int result = 0;
|
|
|
uint8_t *data = NULL;
|
|
|
int data_len = 0;
|
|
|
// set_log_all(L_debug);
|
|
|
switch(frame->key) {
|
|
|
- case CAN_KEY_BMS_SET_POWER:
|
|
|
+ case CAN_KEY_BMS_SET_POWER:
|
|
|
if (len != sizeof(pwr_cmd_t) || frame->head.can_addr != 0x42){//开关大电必须42发过来
|
|
|
result = 1;
|
|
|
+ protocol_send_ack(frame->head.can_addr, frame->key, result);
|
|
|
}else {
|
|
|
pwr_cmd_t *cmd = (pwr_cmd_t *)frame->data;
|
|
|
uint32_t user_request = USER_REQUEST_PENDING;
|
|
|
@@ -66,49 +113,15 @@ void process_bms_message(can_frame_t *frame, int len){
|
|
|
}
|
|
|
}
|
|
|
bms_state_get()->user_request = user_request;
|
|
|
+ response_base_info(frame);
|
|
|
}
|
|
|
- protocol_send_ack(frame->head.can_addr, frame->key, result);
|
|
|
break;
|
|
|
case CAN_KEY_BMS_BASE_INFO:{
|
|
|
if (len >= 1) {
|
|
|
uint8_t env = frame->data[0];
|
|
|
bms_set_ps_charger_in(1, (env == CW_CHE_SHANG_CHARGER || env == CW_CHONG_DIAN_ZUO));
|
|
|
}
|
|
|
-
|
|
|
- binfo_cmd_resp_t bresp;
|
|
|
- bresp.capacity = get_soc()->capacity;
|
|
|
- if (get_soc()->coulomb_now >= get_soc()->coulomb_min) {
|
|
|
- bresp.energy = get_soc()->coulomb_now - get_soc()->coulomb_min;
|
|
|
- }else{
|
|
|
- bresp.energy = 0;
|
|
|
- }
|
|
|
- bresp.pack_current = measure_value()->load_current;
|
|
|
- bresp.pack_voltage = bms_state_get()->pack_voltage;
|
|
|
- bresp.max_temp = -100;
|
|
|
- for (int i = 0; i < PACK_TEMPS_NUM; i ++){
|
|
|
- if (bresp.max_temp < measure_value()->pack_temp[i]){
|
|
|
- bresp.max_temp = measure_value()->pack_temp[i];
|
|
|
- }
|
|
|
- }
|
|
|
- bresp.health = bms_health()->i_status;
|
|
|
- if (bms_is_ps_charger_in()) {/*如果在底座或者车上(有充电器),提前置位过高/低温充电标志*/
|
|
|
- bresp.health |= (bms_health()->lower_temp_deny_charger << 12 | bms_health()->over_temp_deny_charger << 14);
|
|
|
- }
|
|
|
- bresp.health &= ~(1 << 8);
|
|
|
- bresp.health |= ((get_soc()->flags & SOC_FLAG_CALIBRATED) != 0) << 8;
|
|
|
- stat_cmd_resp_t sresp;
|
|
|
- sresp.insert = bms_insert;
|
|
|
- sresp.is_charging = bms_state_get()->charging;
|
|
|
- sresp.discharger_fet = ml5238_is_discharging();
|
|
|
- sresp.charger_fet = ml5238_is_charging();
|
|
|
- sresp.small_power = AUX_VOL_IS_OPEN();
|
|
|
- sresp.is_balancing = bms_state_get()->pack_balancing;
|
|
|
- sresp.health = (((uint16_t )(bms_health()->i_status)) != 0);
|
|
|
- sresp.is_charger_in = io_state()->charger_detect_irq;
|
|
|
- bresp.state = *((uint8_t*)&sresp);
|
|
|
- data = (uint8_t *)&bresp;
|
|
|
- data_len = sizeof(bresp);
|
|
|
- protocol_send_bms_info(frame->head.can_addr, frame->key, data, data_len);
|
|
|
+ response_base_info(frame);
|
|
|
break;
|
|
|
}
|
|
|
case CAN_KEY_BMS_CHARG_INFO:{
|