12 file_handle_ = ::open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
31 cfsetispeed(&tty, (speed_t)BAUD_RATE);
32 tty.c_cflag |= (CLOCAL | CREAD);
33 tty.c_cflag &= ~CSIZE;
35 tty.c_cflag &= ~PARENB;
36 tty.c_cflag &= ~CSTOPB;
37 tty.c_cflag &= ~CRTSCTS;
40 tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
41 tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
42 tty.c_oflag &= ~OPOST;
69 int write_len, read_len;
70 unsigned char data_in;
74 bool first_read =
true;
83 indx + 1 < buff_size_limit)
102 buff[indx] = data_in;
132 if (pkg_data.
len != buff_size)
133 throw BMSWarnException(
"BMS pkg len doesn't mach incoming pkg length - corrupted pkg");
144 uint8_t calc_crc = 0;
149 if (pkg_crc != calc_crc)
175 pkg_data.
vbat = (float)raw_vbat * 2.0 / 1000.0;
186 for (uint8_t cell_indx = 0; cell_indx < pkg_data.
cell_num; cell_indx++)
190 pkg_data.
vcells.push_back((
float)raw_vcell / 1000.0);
212 for (uint8_t temp_indx = 0; temp_indx < pkg_data.
temp_num; temp_indx++)
218 pkg_data.
temps.push_back(temp);
306 char param[param_size + 1];
307 param[param_size] =
'\0';
308 strncpy(param, buff + param_indx, param_size);
#define BMS_PKG_START_DELIM_LEN
#define BMS_PKG_TEMP_NUM_SIZE
#define BMS_PKG_WARN_VUV_INDX
#define BMS_PKG_ADDR_SIZE
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
#define BMS_PKG_ALARM_INDX
#define BMS_PKG_DCHG_NUM_SIZE
#define BMS_PKG_BALANCE_STATE_INDX
#define BMS_PKG_NUM_WARN_VHIGH_INDX
#define BMS_PKG_VBAT_INDX
#define BMS_PKG_CELL_SIZE
#define BMS_PKG_CHG_NUM_INDX
std::vector< uint8_t > temps
#define BMS_PKG_NUM_WARN_VLOW_INDX
int readPkgFromBMS(char *buff, size_t buff_size_limit)
#define BMS_PKG_VSTATE_INDX
#define BMS_PKG_FET_STATE_INDX
#define BMS_PKG_CHRG_CURR_INDX
int fetchParam(char buff[], int param_indx, size_t param_size)
#define BMS_PKG_TIME_SIZE
uint8_t getBitInWord(uint16_t byte, uint8_t position)
#define BMS_PKG_NUM_WARN_VLOW_SIZE
#define BMS_PKG_CAP_FULL_SIZE
const std::string SEND_ME_DATA_
#define BMS_PKG_DCHG_NUM_INDX
#define BMS_PKG_CAP_NOW_SIZE
#define BMS_PKG_WARN_VOV_INDX
#define BMS_PKG_START_DELIM
std::vector< float > vcells
#define BMS_PKG_END_DELIM
#define BMS_PKG_CHG_NUM_SIZE
#define BMS_PKG_CSTATE_SIZE
#define BMS_PKG_CHRG_CURR_SIZE
#define BMS_PKG_TEMP_NUM_INDX
#define BMS_PKG_NUM_WARN_VHIGH_SIZE
#define BMS_PKG_ALARM_SIZE
#define BMS_PKG_ADDR_INDX
#define BMS_PKG_DCHRG_CURR_SIZE
void connect(std::string port)
#define BMS_PKG_TIME_INDX
#define BMS_PKG_TSTATE_SIZE
#define BMS_PKG_TEMP_SIZE
#define BMS_PKG_PROTOCOL_VERSION
#define BMS_PKG_CAP_NOW_INDX
#define BMS_PKG_VSTATE_SIZE
#define BMS_PKG_WARN_VOV_SIZE
#define BMS_PKG_CMD_SUCCESS
#define BMS_PKG_BALANCE_STATE_SIZE
#define BMS_PKG_WARN_VUV_SIZE
#define BMS_PKG_CELLS_ARR_INDX
#define BMS_PKG_VBAT_SIZE
#define BMS_PKG_TEMPS_ARRAY_INDX
#define BMS_PKG_CAP_FULL_INDX
#define BMS_PKG_CELL_NUM_SIZE
#define BMS_PKG_CELL_NUM_INDX
#define BMS_PKG_CSTATE_INDX
#define BMS_PKG_DCHRG_CURR_INDX
#define BMS_PKG_CRC_BACK_OFFSET
#define BMS_PKG_FET_STATE_SIZE
#define BMS_PKG_TSTATE_INDX
data decodePkg(char buff[], size_t buff_size)