123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #include "plt.h"
- #include "mdl.h"
- int sys_timer = 0;
- int canAddr = 1;
- int chanidx = 1;
- void mdl_sim()
- {
- while (chan_socketcan_rxrb_num_items(chanidx) > 0)
- {
- chan_socketcan_ringbuffer_element_t e;//
- if (chan_socketcan_rxrb_dequeue(chanidx, &e) > 0)
- {
- if(e.frame.can_id&0xffffffff == 0x04904000)
- {
- MDL.runMode = (e.frame.data[0] & 0x3); //0停机 1 制冷 2加热 3自动
- if (MDL.runMode > 0)
- {
- MDL.temp_setting = e.frame.data[4];
- }
- }
- }
- }
- if (sys_timer++ >= 100) // 10 means 1s
- {
- sys_timer = 0;
- //发送帧2
- chan_socketcan_ringbuffer_element_t send;//
- memset((void *)&send,0,sizeof(chan_socketcan_ringbuffer_element_t));
- send.frame.can_id = 0x18008040;
- send.frame.can_id |= CAN_EFF_FLAG;
- send.frame.can_dlc = 8; //数据长度
- send.frame.data[0] = (char)MDL.runMode;
- send.frame.data[1] = (char)MDL.out_water_temp;
- send.frame.data[2] = (char)MDL.in_water_temp;
- send.frame.data[3] = (char)MDL.ev_temp;
- send.frame.data[4] = (char)MDL.in_water_press;
- send.frame.data[5] = (char)MDL.out_water_press;
- send.frame.data[6] = 0;
- send.frame.data[7] = (char)(MDL.err_lvl<<6 & MDL.err_code);
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, send);
- chan_unlock(chanidx);
-
- //发送帧3
- memset((void *)&send,0,sizeof(chan_socketcan_ringbuffer_element_t));
- send.frame.can_id = 0x18018040;
- send.frame.can_id |= CAN_EFF_FLAG;
- send.frame.can_dlc = 8;
- send.frame.data[0] = (char)(MDL.comp_state | MDL.comp_heat_state<<1 | MDL.elec_heat_state<<2 | MDL.comp_state<<3 | MDL.fan1_state<<4 | MDL.fan2_state<<5 | MDL.fan3_state<<6);
- send.frame.data[1] = (char)MDL.comp_rpm/100;
- send.frame.data[2] = (char)MDL.pump_rpm/100;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, send);
- chan_unlock(chanidx);
- //发送帧4
- memset((void *)&send,0,sizeof(chan_socketcan_ringbuffer_element_t));
- send.frame.can_id = 0x18068040;
- send.frame.can_id |= CAN_EFF_FLAG;
- send.frame.can_dlc = 8;
- send.frame.data[0] = (char)(MDL.in_out_water_press_sensor_err | MDL.ov_err<<1 | MDL.uv_err<<2 | MDL.lack_water_err<<3 | MDL.pump_err<<4 | MDL.pump_err_lock<<5);
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, send);
- chan_unlock(chanidx);
-
- //发送帧5
- memset((void *)&send,0,sizeof(chan_socketcan_ringbuffer_element_t));
- send.frame.can_id = 0x18078040;
- send.frame.can_id |= CAN_EFF_FLAG;
- send.frame.can_dlc = 8;
- send.frame.data[0] = (char)(MDL.out_water_press_sensor_err | MDL.in_water_press_sensor_err<<1 | MDL.up_sensor_err<<2
- | MDL.out_water_temp_sensor_err<<3 | MDL.sys_low_pressure_err<<4 | MDL.in_air_over_temp_err<<5
- | MDL.out_air_over_temp_err<<6 | MDL.can_comm_err<<7);
- send.frame.data[1] = (char)(MDL.in_air_temp_sensor_err | MDL.cooling_sys_err<<1 | MDL.up_sensor_err<<2
- | MDL.comp_VFD_ov_err<<3 | MDL.comp_VFD_uv_err<<4 | MDL.comp_VFD_oc_err<<5
- | MDL.comp_VFD_ot_err<<6 | MDL.comp_VFD_comm_err<<7);
- send.frame.data[2] = (char)(MDL.comp_VFD_miss_phrase_err | MDL.comp_VFD_others_err<<1 | MDL.pump_press_diff_low_err<<2
- | MDL.out_air_over_temp_lock<<3 | MDL.sys_high_pressure_lock<<4 | MDL.sys_low_pressure_lock<<5);
-
- send.frame.data[3] = (char)(MDL.comp_VFD_over_current_lock | MDL.comp_VFD_over_voltage_lock<<1 | MDL.comp_VFD_under_voltage_lock<<2
- | MDL.comp_VFD_over_temp_lock<<3 | MDL.comp_VFD_comm_lock<<4 | MDL.comp_VFD_miss_phrase_lock<<5
- | MDL.comp_VFD_others_lock<<6);
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, send);
- chan_unlock(chanidx);
- //发送帧6
- send.frame.can_id = 0x18088040;
- send.frame.can_id |= CAN_EFF_FLAG;
- send.frame.can_dlc = 8;
- send.frame.data[0] = (char)(MDL.high_press_sensor_err | MDL.env_temp_sensor_err<<1 | MDL.in_water_temp_sensor_err<<2 \
- | MDL.out_air_temp_sensor_err<<3 | MDL.condensate_sensor_err<<4 | MDL.unexpected_power_off_err<<5 \
- | MDL.out_water_low_temp_err<<6 | MDL.out_water_high_temp_err<<7);
- send.frame.data[1] = (char) MDL.out_water_over_press_err;
- chan_lock(chanidx);
- chan_socketcan_txrb_queue(chanidx, send);
- chan_unlock(chanidx);
- }
- }
- static void *mdl_thrd_main(void *param)
- {
- while (1)
- {
- mdl_sim();
- usleep(10000); /* 10ms */
- }
- return NULL;
- }
- int mdl_init()
- {
- log_dbg("%s, ++", __func__);
- int ret = 0;
- pthread_t xthrd;
- if (pthread_create(&xthrd, NULL, mdl_thrd_main, NULL) != 0)
- {
- log_dbg("%s, pthread_create fail", __func__);
- ret = -1;
- }
- log_dbg("%s, --, ret: %d", __func__, ret);
- return ret;
- }
|