123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- #include "evc_comm.h"
- #include "evc.h"
- #include "evc_sm.h"
- #include "plt.h"
- void evc_comm_dac(int idx)
- {
- struct evc_t *dev = &evc[idx];
- struct comm_t *comm = &dev->comm;
- int chanidx = comm->chanidx;
- int addr = comm->adr;
- int ret = 0;
- if (comm_get_state(comm) != COMMST_NORMAL)
- {
- return;
- }
- evc_dev_control_strategy_pack_temp(idx); // 控制帧每一轮都要发送
- // static int count = 0;
- // if (chan_socketcan_rxrb_num_items(chanidx) <= 0)
- // {
- // count++;
- // if (count >= 600) // 10 分钟超时
- // {
- // log_dbg("evc_comm_dac, idx:%d, there is no data for %d loop, can comm err", idx, count);
- // count = 0;
- // comm_set_state(comm, COMMST_ERR);
- // return;
- // }
- // if(count % 60 == 0)
- // {
- // log_dbg("evc_comm_dac, idx:%d, there is no data for %d loop", idx, count);
- // }
- // return;
- // }
- // else
- // {
- // count = 0; // reset, 直到真的满10次
- // }
- comm_start_cal_dac_timing(comm);
- chan_socketcan_ringbuffer_element_t e;
- static chan_socketcan_ringbuffer_element_t e_cache[128];
- int cache_count = 0;
- // log_dbg("evc_comm_dac, idx:%d", chanidx);
- chan_lock(chanidx);
- while (chan_socketcan_rxrb_num_items(chanidx) > 0)
- {
- chan_socketcan_rxrb_dequeue(chanidx, &e);
- // log_dbg("evc_comm_dac, idx:%d, canid:0x%x", chanidx, (e.frame.can_id & (~CAN_EFF_FLAG)));
- if ((e.frame.can_id & (~CAN_EFF_FLAG)) == 0x18008040) // 帧二,读取所有值
- {
- // log_dbg("evc_comm_dac, frame2");
- dev->runMode = e.frame.data[0] & 0x03;
- if (dev->runMode == 0x03)
- {
- strcpy(dev->runModeStr, "Self Circulation");
- }
- else if (dev->runMode == 0x02)
- {
- strcpy(dev->runModeStr, "Heating");
- }
- else if (dev->runMode == 0x01)
- {
- strcpy(dev->runModeStr, "Cooling");
- }
- else if (dev->runMode == 0x00)
- {
- strcpy(dev->runModeStr, "Stop");
- }
- dev->out_water_temp = e.frame.data[1] - 40;
- dev->in_water_temp = e.frame.data[2] - 40;
- dev->ev_temp = e.frame.data[3] - 40;
- dev->in_water_press = e.frame.data[4];
- dev->out_water_press = e.frame.data[5];
- dev->err_code = e.frame.data[7] & 0x3f;
- dev->err_lvl = (e.frame.data[7] & 0xC0) >> 6;
- if (dev->err_code != 0)
- {
- // log_dbg("evc has error, errCode : %d, errLevel :%d", dev->err_code, dev->err_lvl);
- if (dev->err_lvl == 1 || dev->err_lvl == 2) // 就是报1/2都要检查设备了,有些不用强行动作的不用动作
- {
- sm_set_state(&dev->sm, SMST_ERR, EVCERR_READY_COMMERR);
- }
- }
- }
- else if ((e.frame.can_id & (~CAN_EFF_FLAG)) == 0x18018040) // 帧三,读取所有状态
- {
- // log_dbg("evc_comm_dac, frame3");
- dev->comp_state = (e.frame.data[0] & 0x01) != 0 ? 1 : 0;
- dev->comp_heat_state = (e.frame.data[0] & 0x02) != 0 ? 1 : 0;
- dev->elec_heat_state = (e.frame.data[0] & 0x04) != 0 ? 1 : 0;
- dev->pump_state = (e.frame.data[0] & 0x08) != 0 ? 1 : 0;
- dev->fan1_state = (e.frame.data[0] & 0x10) != 0 ? 1 : 0;
- dev->fan2_state = (e.frame.data[0] & 0x20) != 0 ? 1 : 0;
- dev->fan3_state = (e.frame.data[0] & 0x40) != 0 ? 1 : 0;
- dev->comp_rpm = e.frame.data[1] * 100;
- dev->pump_rpm = e.frame.data[2] * 100;
- }
- else if ((e.frame.can_id & (~CAN_EFF_FLAG)) == 0x18068040) // 帧四,读取所有状态
- {
- // log_dbg("evc_comm_dac, frame4");
- dev->in_out_water_press_sensor_err = (e.frame.data[0] & 0x01) != 0 ? 1 : 0;
- dev->ov_err = (e.frame.data[0] & 0x02) != 0 ? 1 : 0;
- dev->uv_err = (e.frame.data[0] & 0x04) != 0 ? 1 : 0;
- dev->lack_water_err = (e.frame.data[0] & 0x08) != 0 ? 1 : 0;
- dev->pump_err = (e.frame.data[0] & 0x10) != 0 ? 1 : 0;
- dev->pump_err_lock = (e.frame.data[0] & 0x20) != 0 ? 1 : 0;
- }
- else if ((e.frame.can_id & (~CAN_EFF_FLAG)) == 0x18078040) // 帧五,读取所有状态
- {
- // log_dbg("evc_comm_dac, frame5");
- dev->out_water_press_sensor_err = (e.frame.data[0] & 0x01) != 0 ? 1 : 0;
- dev->in_water_press_sensor_err = (e.frame.data[0] & 0x02) != 0 ? 1 : 0;
- dev->up_sensor_err = (e.frame.data[0] & 0x04) != 0 ? 1 : 0;
- dev->out_water_temp_sensor_err = (e.frame.data[0] & 0x08) != 0 ? 1 : 0;
- dev->sys_low_pressure_err = (e.frame.data[0] & 0x10) != 0 ? 1 : 0;
- dev->sys_high_pressure_switch_err = (e.frame.data[0] & 0x20) != 0 ? 1 : 0;
- dev->out_air_over_temp_err = (e.frame.data[0] & 0x40) != 0 ? 1 : 0;
- dev->can_comm_err = (e.frame.data[0] & 0x80) != 0 ? 1 : 0;
- dev->in_air_temp_sensor_err = (e.frame.data[1] & 0x01) != 0 ? 1 : 0;
- dev->cooling_sys_err = (e.frame.data[1] & 0x02) != 0 ? 1 : 0;
- dev->in_air_over_temp_err = (e.frame.data[1] & 0x04) != 0 ? 1 : 0;
- dev->comp_VFD_ov_err = (e.frame.data[1] & 0x08) != 0 ? 1 : 0;
- dev->comp_VFD_uv_err = (e.frame.data[1] & 0x10) != 0 ? 1 : 0;
- dev->comp_VFD_oc_err = (e.frame.data[1] & 0x20) != 0 ? 1 : 0;
- dev->comp_VFD_ot_err = (e.frame.data[1] & 0x40) != 0 ? 1 : 0;
- dev->comp_VFD_comm_err = (e.frame.data[1] & 0x80) != 0 ? 1 : 0;
- dev->comp_VFD_miss_phrase_err = (e.frame.data[2] & 0x01) != 0 ? 1 : 0;
- dev->comp_VFD_others_err = (e.frame.data[2] & 0x02) != 0 ? 1 : 0;
- dev->pump_press_diff_low_err = (e.frame.data[2] & 0x04) != 0 ? 1 : 0;
- dev->out_air_over_temp_lock = (e.frame.data[2] & 0x08) != 0 ? 1 : 0;
- dev->sys_high_pressure_lock = (e.frame.data[2] & 0x10) != 0 ? 1 : 0;
- dev->sys_low_pressure_lock = (e.frame.data[2] & 0x20) != 0 ? 1 : 0;
- dev->comp_VFD_over_current_lock = (e.frame.data[2] & 0x40) != 0 ? 1 : 0;
- dev->comp_VFD_over_voltage_lock = (e.frame.data[2] & 0x80) != 0 ? 1 : 0;
- dev->comp_VFD_under_voltage_lock = (e.frame.data[3] & 0x01) != 0 ? 1 : 0;
- dev->comp_VFD_over_temp_lock = (e.frame.data[3] & 0x02) != 0 ? 1 : 0;
- dev->comp_VFD_miss_phrase_lock = (e.frame.data[3] & 0x04) != 0 ? 1 : 0;
- dev->comp_VFD_others_lock = (e.frame.data[3] & 0x08) != 0 ? 1 : 0;
- }
- else if ((e.frame.can_id & (~CAN_EFF_FLAG)) == 0x18088040) // 帧六,读取所有状态
- {
- // log_dbg("evc_comm_dac, frame6");
- dev->high_press_sensor_err = (e.frame.data[0] & 0x01) != 0 ? 1 : 0;
- dev->env_temp_sensor_err = (e.frame.data[0] & 0x02) != 0 ? 1 : 0;
- dev->in_water_temp_sensor_err = (e.frame.data[0] & 0x04) != 0 ? 1 : 0;
- dev->out_air_temp_sensor_err = (e.frame.data[0] & 0x08) != 0 ? 1 : 0;
- dev->condensate_sensor_err = (e.frame.data[0] & 0x10) != 0 ? 1 : 0;
- dev->unexpected_power_off_err = (e.frame.data[0] & 0x20) != 0 ? 1 : 0;
- dev->out_water_low_temp_err = (e.frame.data[0] & 0x40) != 0 ? 1 : 0;
- dev->out_water_high_temp_err = (e.frame.data[0] & 0x80) != 0 ? 1 : 0;
- dev->out_water_over_press_err = (e.frame.data[1] & 0x01) != 0 ? 1 : 0;
- }
- else
- {
- e_cache[cache_count++] = e;
- }
- }
- chan_socketcan_rxrb_queue_arr(chanidx, e_cache, cache_count); // 重新入队
- chan_unlock(chanidx);
- comm_stop_cal_dac_timing(comm);
- }
- int evc_dev_control_strategy_pack_temp(int idx)
- {
- chan_socketcan_ringbuffer_element_t e;
- int chanidx = evc[idx].comm.chanidx;
- static int cool_set = -1;
- static int heat_set = -1;
- // if (pack_get_state() != SMST_ERR && pack_get_celltmax() >= 25 || ac_get_state(1) != SMST_ERR && evc[idx].out_water_temp > 24) // 25 + 50% * 2
- if (pack_get_celltmax() >= 25) // 25 + 50% * 2
- {
- if (cool_set == -1)
- {
- cool_set = evc[idx].out_water_temp;
- if (ctn_get_state() == SMST_DHG || ctn_get_state() == SMST_CHG)
- {
- cool_set -= 4;
- }
- if (cool_set <= 16)
- cool_set = 16; // 保证最低温度在 15 以上,保护电芯
- }
- // log_dbg("evc_dev_control_strategy_pack_temp, idx:%d, temp:%d, cooling, cool set :%d", idx, pack_get_celltmax(), cool_set);
- e.frame.can_id = 0x04904000;
- e.frame.can_id |= CAN_EFF_FLAG;
- e.frame.can_dlc = 8;
- e.frame.data[0] = 0x01; // 制冷
- e.frame.data[1] = 0;
- e.frame.data[2] = 0;
- e.frame.data[3] = 0;
- e.frame.data[4] = cool_set + 40;
- e.frame.data[5] = 0;
- e.frame.data[6] = 0;
- e.frame.data[7] = 0;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, e);
- chan_unlock(chanidx);
- }
- else if (pack_get_celltmin() <= 16)
- {
- if (heat_set == -1)
- {
- heat_set = evc[idx].out_water_temp;
- if (heat_set >= 18)
- heat_set = 18;
- }
- // log_dbg("evc_dev_control_strategy_pack_temp, idx:%d, temp:%d, heating, heat set %d", idx, pack_get_celltmin(), heat_set);
- e.frame.can_id = 0x04904000;
- e.frame.can_id |= CAN_EFF_FLAG;
- e.frame.can_dlc = 8;
- e.frame.data[0] = 0x02; // 制热
- e.frame.data[1] = 0;
- e.frame.data[2] = 0;
- e.frame.data[3] = 0;
- e.frame.data[4] = heat_set + 40; // 制热点尽量高
- e.frame.data[5] = 0;
- e.frame.data[6] = 0;
- e.frame.data[7] = 0;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, e);
- chan_unlock(chanidx);
- }
- else
- {
- cool_set = -1;
- heat_set = -1;
- // log_dbg("evc_dev_control_strategy_pack_temp, idx:%d,cell temp max:%d, min:%d stop", idx, pack_get_celltmax(), pack_get_celltmin());
- // evc_dev_control_keep_can_communication(idx);
- // evc_set_dev_stop(idx);
- // log_dbg("evc_dev_control_strategy_pack_temp, idx:%d,cell temp max:%d, min:%d self circulation", idx, pack_get_celltmax(), pack_get_celltmin());
- evc_set_dev_self_circulation(idx);
- }
- // evc[idx].cool_set = cool_set;
- // evc[idx].heat_set = heat_set;
- }
- // 发送控制帧,不出现通信失败
- int evc_dev_control_keep_can_communication(int idx)
- {
- chan_socketcan_ringbuffer_element_t e;
- int chanidx = evc[idx].comm.chanidx;
- e.frame.can_id = 0x04904000;
- e.frame.can_id |= CAN_EFF_FLAG;
- e.frame.can_dlc = 8;
- e.frame.data[0] = 1;
- e.frame.data[1] = 0;
- e.frame.data[2] = 0;
- e.frame.data[3] = 0;
- e.frame.data[4] = 40; // 范围是 5~35,0会在范围外,超过范围就会设置失败,不会改变模式
- e.frame.data[5] = 0;
- e.frame.data[6] = 0;
- e.frame.data[7] = 0;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, e);
- chan_unlock(chanidx);
- return 0;
- }
- int evc_set_dev_stop(int idx)
- {
- chan_socketcan_ringbuffer_element_t e;
- int chanidx = evc[idx].comm.chanidx;
- e.frame.can_id = 0x04904000;
- e.frame.can_id |= CAN_EFF_FLAG;
- e.frame.can_dlc = 8;
- e.frame.data[0] = 0; // 1.2-1.1, 3 自循环
- e.frame.data[1] = 0;
- e.frame.data[2] = 0;
- e.frame.data[3] = 0;
- e.frame.data[4] = 0;
- e.frame.data[5] = 0;
- e.frame.data[6] = 0;
- e.frame.data[7] = 0;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, e);
- chan_unlock(chanidx);
- return 0;
- }
- int evc_set_dev_self_circulation(int idx)
- {
- chan_socketcan_ringbuffer_element_t e;
- int chanidx = evc[idx].comm.chanidx;
- e.frame.can_id = 0x04904000;
- e.frame.can_id |= CAN_EFF_FLAG;
- e.frame.can_dlc = 8;
- e.frame.data[0] = 3; // 1.2-1.1, 3 自循环
- e.frame.data[1] = 0;
- e.frame.data[2] = 0;
- e.frame.data[3] = 0;
- e.frame.data[4] = 0;
- e.frame.data[5] = 0;
- e.frame.data[6] = 0;
- e.frame.data[7] = 0;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, e);
- chan_unlock(chanidx);
- return 0;
- }
- int evc_comm_init(int idx)
- {
- struct evc_t *dev = &evc[idx];
- struct comm_t *comm = &dev->comm;
- comm_set_state(comm, COMMST_ERR);
- return 0;
- }
- int evc_comm_reset(int idx)
- {
- struct evc_t *dev = &evc[idx];
- struct comm_t *comm = &dev->comm;
- comm_set_state(comm, COMMST_NORMAL);
- return 0;
- }
|