diff --git a/include/BatteryStats.h b/include/BatteryStats.h index 0bf957766..204690f9d 100644 --- a/include/BatteryStats.h +++ b/include/BatteryStats.h @@ -106,20 +106,19 @@ class DalyBatteryStats : public BatteryStats { float _minCellmV; uint8_t _minCellVNum; float _cellDiff; - std::string _dischargechargemosstate; + std::string _state; uint8_t _numberOfCells; uint8_t _numOfTempSensors; uint8_t _chargeState; uint8_t _loadState; - uint8_t _chargeFetState; - uint8_t _dischargeFetState; + bool _chargeFetState; + bool _dischargeFetState; int _bmsHeartBeat; float _resCapacityAh; int _bmsCycles; float _cellVmV[48]; bool _cellBalanceActive; bool _connectionState; - String _failCodeString; }; class JkBmsBatteryStats : public BatteryStats { diff --git a/include/DalyBms.h b/include/DalyBms.h index 847d2b5f9..37764235d 100644 --- a/include/DalyBms.h +++ b/include/DalyBms.h @@ -55,66 +55,6 @@ class DalyBms : public BatteryProvider { //after request the pc soft hangs a 0xD8 as last request, its empty, dont know what it means? }; - /** - * @brief get struct holds all the data collected from the BMS and is populated using the update() API - */ - struct - { - // data from 0x59 - float maxCellThreshold1; // Level-1 alarm threshold for High Voltage in Millivolts - float minCellThreshold1; // Level-1 alarm threshold for low Voltage in Millivolts - float maxCellThreshold2; // Level-2 alarm threshold for High Voltage in Millivolts - float minCellThreshold2; // Level-2 alarm threshold for low Voltage in Millivolts - - // data from 0x5A - float maxPackThreshold1; // Level-1 alarm threshold for high voltage in decivolts - float minPackThreshold1; // Level-1 alarm threshold for low voltage in decivolts - float maxPackThreshold2; // Level-2 alarm threshold for high voltage in decivolts - float minPackThreshold2; // Level-2 alarm threshold for low voltage in decivolts - - // data from 0x90 - float packVoltage; // pressure (0.1 V) - float packCurrent; // acquisition (0.1 V) - float packSOC; // State Of Charge - - // data from 0x91 - float maxCellmV; // maximum monomer voltage (mV) - int maxCellVNum; // Maximum Unit Voltage cell No. - float minCellmV; // minimum monomer voltage (mV) - int minCellVNum; // Minimum Unit Voltage cell No. - int cellDiff; // difference betwen cells - - // data from 0x92 - int tempAverage; // Avergae Temperature - - // data from 0x93 - const char *chargeDischargeStatus; // charge/discharge status (0 stationary ,1 charge ,2 discharge) - bool chargeFetState; // charging MOS tube status - bool disChargeFetState; // discharge MOS tube state - int bmsHeartBeat; // BMS life(0~255 cycles) - float resCapacityAh; // residual capacity mAH - - // data from 0x94 - unsigned int numberOfCells; // amount of cells - unsigned int numOfTempSensors; // amount of temp sensors - bool chargeState; // charger status 0=disconnected 1=connected - bool loadState; // Load Status 0=disconnected 1=connected - int bmsCycles; // charge / discharge cycles - - // data from 0x95 - float cellVmV[48]; // Store Cell Voltages in mV - - // data from 0x96 - int cellTemperature[16]; // array of cell Temperature sensors - - // data from 0x97 - bool cellBalanceState[48]; // bool array of cell balance states - bool cellBalanceActive; // bool is cell balance active - - // get a state of the connection - bool connectionState; - - } get; /** * @brief Gets Voltage, Current, and SOC measurements from the BMS @@ -122,18 +62,6 @@ class DalyBms : public BatteryProvider { */ bool getPackMeasurements(); - /** - * @brief Gets Voltage thresholds - * @return True on successful aquisition, false otherwise - */ - bool getVoltageThreshold(); - - /** - * @brief Gets pack voltage thresholds - * @return True on successful aquisition, false otherwise - */ - bool getPackVoltageThreshold(); - /** * @brief Gets the pack temperature from the min and max of all the available temperature sensors * @details Populates tempMax, tempMax, and tempAverage in the "get" struct @@ -160,32 +88,6 @@ class DalyBms : public BatteryProvider { */ bool getCellVoltages(); - /** - * @brief Each temperature accounts for 1 byte, according to the - actual number of temperature send, the maximum 21 - byte, send in 3 frames - Byte0:frame number, starting at 0 - Byte1~byte7:cell temperature(40 Offset ,℃) - * - */ - bool getCellTemperature(); - - /** - * @brief 0: Closed 1: Open - Bit0: Cell 1 balance state - ... - Bit47:Cell 48 balance state - Bit48~Bit63:reserved - * - */ - bool getCellBalanceState(); - - /** - * @brief Get the Failure Codes - * - */ - bool getFailureCodes(); - /** * @brief * set the Discharging MOS State diff --git a/src/BatteryStats.cpp b/src/BatteryStats.cpp index a06c3e713..2e8e455b5 100644 --- a/src/BatteryStats.cpp +++ b/src/BatteryStats.cpp @@ -103,18 +103,22 @@ void DalyBatteryStats::getLiveViewData(JsonVariant& root) const { BatteryStats::getLiveViewData(root); + if (_connectionState==true){ // values go into the "Status" card of the web application - addLiveViewValue(root, "voltage", _voltage, "V", 2); - addLiveViewValue(root, "current", _current, "A", 1); - addLiveViewValue(root, "temperature", _temperature, "°C", 1); - addLiveViewTextValue(root, "status", _dischargechargemosstate); - addLiveViewValue(root, "cellMaxVoltage", _maxCellmV, "mV", 0); - addLiveViewValue(root, "cellMinVoltage", _minCellmV, "mV", 0); - addLiveViewValue(root, "cellDiffVoltage", _cellDiff, "mV", 0); - addLiveViewValue(root, "chargeEnabled", _chargeFetState, "", 0); - addLiveViewValue(root, "dischargeEnabled", _dischargeFetState, "", 0); - addLiveViewValue(root, "chargeCycles", _bmsCycles,"",0); - addLiveViewValue(root, "remainingAh", _resCapacityAh,"Ah",1); + addLiveViewValue(root, "voltage", _voltage, "V", 2); + addLiveViewValue(root, "current", _current, "A", 1); + addLiveViewValue(root, "temperature", _temperature, "°C", 1); + addLiveViewTextValue(root, "status", _state); + addLiveViewValue(root, "cellMaxVoltage", _maxCellmV, "mV", 0); + addLiveViewValue(root, "cellMinVoltage", _minCellmV, "mV", 0); + addLiveViewValue(root, "cellDiffVoltage", _cellDiff, "mV", 0); + addLiveViewTextValue(root, "chargeEnabled", (_chargeFetState?"yes":"no")); + addLiveViewTextValue(root, "dischargeEnabled", (_dischargeFetState?"yes":"no")); + addLiveViewValue(root, "chargeCycles", _bmsCycles,"",0); + addLiveViewValue(root, "remainingAh", _resCapacityAh,"Ah",1); + } else { + + } } void JkBmsBatteryStats::getJsonData(JsonVariant& root, bool verbose) const @@ -281,7 +285,7 @@ void DalyBatteryStats::mqttPublish() const MqttSettings.publish(F("battery/maxCellmV"), String(_maxCellmV)); MqttSettings.publish(F("battery/maxCellmVNum"), String(_maxCellVNum)); MqttSettings.publish(F("battery/cellmVDrift"), String(_cellDiff)); - //MqttSettings.publish(F("battery/status"), String(_dischargechargemosstate)); + MqttSettings.publish(F("battery/status"), _state.c_str()); MqttSettings.publish(F("battery/chargeFetState"), String(_chargeFetState)); MqttSettings.publish(F("battery/dischargeFetState"), String(_dischargeFetState)); MqttSettings.publish(F("battery/numberOfCells"), String(_numberOfCells)); @@ -289,7 +293,6 @@ void DalyBatteryStats::mqttPublish() const MqttSettings.publish(F("battery/chargeState"), String(_cellDiff)); MqttSettings.publish(F("battery/loadState"), String(_loadState)); MqttSettings.publish(F("battery/cycles"), String(_bmsCycles)); - MqttSettings.publish(F("battery/failures"), _failCodeString); MqttSettings.publish(F("battery/remainingAh"), String(_resCapacityAh)); MqttSettings.publish(F("battery/bmsHeartBeat"), String(_bmsHeartBeat)); for (uint8_t c = 0; c<_numberOfCells;c++){ diff --git a/src/DalyBms.cpp b/src/DalyBms.cpp index cfb01b00e..5bb2695a6 100644 --- a/src/DalyBms.cpp +++ b/src/DalyBms.cpp @@ -24,14 +24,15 @@ bool DalyBms::init(bool verboseLogging) memset(this->my_txBuffer, 0x00, XFER_BUFFER_LENGTH); clearGet(); - get.chargeDischargeStatus = "DalyOffline"; + _stats->_state = "DalyOffline"; + _stats->_connectionState = false; return true; } void DalyBms::deinit() { - + DalyHwSerial.end(); } void DalyBms::loop() @@ -51,12 +52,9 @@ void DalyBms::loop() case 1: if (getPackMeasurements()) { - get.connectionState = true; + _stats->_connectionState = true; errorCounter = 0; requestCounter++; - _stats->_voltage = get.packVoltage; - _stats->_current = get.packCurrent; - _stats->setSoC(get.packSOC); _stats->setLastUpdate(millis()); } else @@ -71,54 +69,28 @@ void DalyBms::loop() errorCounter = 0; //requestCallback(); clearGet(); - get.connectionState = false; - get.chargeDischargeStatus = "DalyOffline"; + _stats -> _connectionState = false; + _stats -> _state = "DalyOffline"; } } break; case 2: requestCounter = getMinMaxCellVoltage() ? (requestCounter + 1) : 0; - _stats->_minCellmV = get.minCellmV; - _stats->_maxCellmV = get.maxCellmV; - _stats->_minCellVNum = get.minCellVNum; - _stats->_maxCellVNum = get.maxCellVNum; - _stats->_cellDiff = get.cellDiff; break; case 3: requestCounter = getPackTemp() ? (requestCounter + 1) : 0; - _stats->_temperature = get.tempAverage; break; case 4: requestCounter = getDischargeChargeMosStatus() ? (requestCounter + 1) : 0; - _stats->_dischargechargemosstate = get.chargeDischargeStatus; - _stats->_resCapacityAh = get.resCapacityAh; - _stats->_bmsHeartBeat=get.bmsHeartBeat; break; case 5: requestCounter = getStatusInfo() ? (requestCounter + 1) : 0; - _stats->_numberOfCells = get.numberOfCells; - _stats->_numOfTempSensors = get.numOfTempSensors; - _stats->_loadState = get.loadState; - _stats->_chargeState = get.chargeState; break; case 6: requestCounter = getCellVoltages() ? (requestCounter + 1) : 0; - std::copy(get.cellVmV, get.cellVmV+get.numberOfCells, _stats->_cellVmV); - break; - case 7: - requestCounter = getCellTemperature() ? (requestCounter + 1) : 0; - break; - case 8: - requestCounter = getCellBalanceState() ? (requestCounter + 1) : 0; - _stats->_cellBalanceActive = get.cellBalanceState; break; - case 9: - requestCounter = getFailureCodes() ? (requestCounter + 1) : 0; - _lastRequest = millis(); - requestCounter = 0; - break; - default: + requestCounter = 1; break; } previousTime = millis(); @@ -126,38 +98,6 @@ void DalyBms::loop() } } -bool DalyBms::getVoltageThreshold() // 0x59 -{ - if (!this->requestData(COMMAND::CELL_THRESHOLDS, 1)) - { - MessageOutput.printf(" Receive failed, min/max cell thresholds won't be modified!\n"); - return false; - } - - get.maxCellThreshold1 = (float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]); - get.maxCellThreshold2 = (float)((this->frameBuff[0][6] << 8) | this->frameBuff[0][7]); - get.minCellThreshold1 = (float)((this->frameBuff[0][8] << 8) | this->frameBuff[0][9]); - get.minCellThreshold2 = (float)((this->frameBuff[0][10] << 8) | this->frameBuff[0][11]); - - return true; -} - -bool DalyBms::getPackVoltageThreshold() // 0x5A -{ - if (!this->requestData(COMMAND::PACK_THRESHOLDS, 1)) - { - MessageOutput.printf(" Receive failed, min/max pack voltage thresholds won't be modified!\n"); - return false; - } - - get.maxPackThreshold1 = (float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]); - get.maxPackThreshold2 = (float)((this->frameBuff[0][6] << 8) | this->frameBuff[0][7]); - get.minPackThreshold1 = (float)((this->frameBuff[0][8] << 8) | this->frameBuff[0][9]); - get.minPackThreshold2 = (float)((this->frameBuff[0][10] << 8) | this->frameBuff[0][11]); - - return true; -} - bool DalyBms::getPackMeasurements() // 0x90 { if (!this->requestData(COMMAND::VOUT_IOUT_SOC, 1)) @@ -182,9 +122,9 @@ bool DalyBms::getPackMeasurements() // 0x90 } // Pull the relevent values out of the buffer - get.packVoltage = ((float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]) / 10.0f); - get.packCurrent = ((float)(((this->frameBuff[0][8] << 8) | this->frameBuff[0][9]) - 30000) / 10.0f); - get.packSOC = ((float)((this->frameBuff[0][10] << 8) | this->frameBuff[0][11]) / 10.0f); + _stats->_voltage = ((float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]) / 10.0f); + _stats->_current = ((float)(((this->frameBuff[0][8] << 8) | this->frameBuff[0][9]) - 30000) / 10.0f); + _stats->_SoC = ((float)((this->frameBuff[0][10] << 8) | this->frameBuff[0][11]) / 10.0f); //MessageOutput.println(" " + (String)get.packVoltage + "V, " + (String)get.packCurrent + "A, " + (String)get.packSOC + "SOC"); return true; } @@ -197,11 +137,11 @@ bool DalyBms::getMinMaxCellVoltage() // 0x91 return false; } - get.maxCellmV = (float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]); - get.maxCellVNum = this->frameBuff[0][6]; - get.minCellmV = (float)((this->frameBuff[0][7] << 8) | this->frameBuff[0][8]); - get.minCellVNum = this->frameBuff[0][9]; - get.cellDiff = (get.maxCellmV - get.minCellmV); + _stats -> _maxCellmV = (float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]); + _stats -> _maxCellVNum = this->frameBuff[0][6]; + _stats -> _minCellmV = (float)((this->frameBuff[0][7] << 8) | this->frameBuff[0][8]); + _stats -> _minCellVNum = this->frameBuff[0][9]; + _stats -> _cellDiff = ( _stats -> _maxCellmV - _stats -> _minCellmV); return true; } @@ -213,7 +153,7 @@ bool DalyBms::getPackTemp() // 0x92 MessageOutput.printf(" Receive failed, Temp values won't be modified!\n"); return false; } - get.tempAverage = ((this->frameBuff[0][4] - 40) + (this->frameBuff[0][6] - 40)) / 2; + _stats -> _temperature = ((this->frameBuff[0][4] - 40) + (this->frameBuff[0][6] - 40)) / 2; return true; } @@ -229,23 +169,31 @@ bool DalyBms::getDischargeChargeMosStatus() // 0x93 switch (this->frameBuff[0][4]) { case 0: - get.chargeDischargeStatus = "DalyStationary"; + _stats -> _state = "DalyStationary"; break; case 1: - get.chargeDischargeStatus = "DalyCharge"; + _stats -> _state = "DalyCharge"; break; case 2: - get.chargeDischargeStatus = "DalyDischarge"; + _stats -> _state = "DalyDischarge"; break; } - get.chargeFetState = this->frameBuff[0][5]; - get.disChargeFetState = this->frameBuff[0][6]; - get.bmsHeartBeat = this->frameBuff[0][7]; + if (this->frameBuff[0][5]==0){ + _stats -> _chargeFetState = true; + } else { + _stats -> _chargeFetState = false; + } + if (this->frameBuff[0][6]==0){ + _stats -> _dischargeFetState = true; + } else { + _stats -> _dischargeFetState = true; + } + _stats -> _bmsHeartBeat = this->frameBuff[0][7]; char msgbuff[16]; float tmpAh = (((uint32_t)frameBuff[0][8] << 0x18) | ((uint32_t)frameBuff[0][9] << 0x10) | ((uint32_t)frameBuff[0][10] << 0x08) | (uint32_t)frameBuff[0][11]) * 0.001; dtostrf(tmpAh, 3, 1, msgbuff); - get.resCapacityAh = atof(msgbuff); + _stats -> _resCapacityAh = atof(msgbuff); return true; } @@ -258,11 +206,11 @@ bool DalyBms::getStatusInfo() // 0x94 return false; } - get.numberOfCells = this->frameBuff[0][4]; - get.numOfTempSensors = this->frameBuff[0][5]; - get.chargeState = this->frameBuff[0][6]; - get.loadState = this->frameBuff[0][7]; - get.bmsCycles = ((uint16_t)this->frameBuff[0][9] << 0x08) | (uint16_t)this->frameBuff[0][10]; + _stats -> _numberOfCells = this->frameBuff[0][4]; + _stats -> _numOfTempSensors = this->frameBuff[0][5]; + _stats -> _chargeState = this->frameBuff[0][6]; + _stats -> _loadState = this->frameBuff[0][7]; + _stats -> _bmsCycles = ((uint16_t)this->frameBuff[0][9] << 0x08) | (uint16_t)this->frameBuff[0][10]; return true; } @@ -272,50 +220,20 @@ bool DalyBms::getCellVoltages() // 0x95 unsigned int cellNo = 0; // start with cell no. 1 // Check to make sure we have a valid number of cells - if (get.numberOfCells < MIN_NUMBER_CELLS && get.numberOfCells >= MAX_NUMBER_CELLS) + if (_stats -> _numberOfCells < MIN_NUMBER_CELLS && _stats -> _numberOfCells >= MAX_NUMBER_CELLS) { return false; } - if (this->requestData(COMMAND::CELL_VOLTAGES, (unsigned int)ceil(get.numberOfCells / 3.0))) + if (this->requestData(COMMAND::CELL_VOLTAGES, (unsigned int)ceil(_stats -> _numberOfCells / 3.0))) { - for (size_t k = 0; k < (unsigned int)ceil(get.numberOfCells / 3.0); k++) // test for bug #67 + for (size_t k = 0; k < (unsigned int)ceil(_stats -> _numberOfCells / 3.0); k++) // test for bug #67 { for (size_t i = 0; i < 3; i++) { - get.cellVmV[cellNo] = (this->frameBuff[k][5 + i + i] << 8) | this->frameBuff[k][6 + i + i]; + _stats -> _cellVmV[cellNo] = (this->frameBuff[k][5 + i + i] << 8) | this->frameBuff[k][6 + i + i]; cellNo++; - if (cellNo >= get.numberOfCells) - break; - } - } - return true; - } - else - { - return false; - } -} - -bool DalyBms::getCellTemperature() // 0x96 -{ - unsigned int sensorNo = 0; - // Check to make sure we have a valid number of temp sensors - if ((get.numOfTempSensors < MIN_NUMBER_TEMP_SENSORS) && (get.numOfTempSensors >= MAX_NUMBER_TEMP_SENSORS)) - { - return false; - } - - // for testing - if (this->requestData(COMMAND::CELL_TEMPERATURE, 1)) - { - for (size_t k = 0; k < ceil(get.numOfTempSensors / 7.0); k++) - { - for (size_t i = 0; i < 7; i++) - { - get.cellTemperature[sensorNo] = (this->frameBuff[k][5 + i] - 40); - sensorNo++; - if (sensorNo >= get.numOfTempSensors) + if (cellNo >= _stats -> _numberOfCells) break; } } @@ -327,231 +245,6 @@ bool DalyBms::getCellTemperature() // 0x96 } } -bool DalyBms::getCellBalanceState() // 0x97 -{ - int cellBalance = 0; - int cellBit = 0; - - // Check to make sure we have a valid number of cells - if (get.numberOfCells < MIN_NUMBER_CELLS && get.numberOfCells >= MAX_NUMBER_CELLS) - { - return false; - } - - if (!this->requestData(COMMAND::CELL_BALANCE_STATE, 1)) - { - MessageOutput.println(" Receive failed, Cell Balance State won't be modified!\n"); - return false; - } - - // We expect 6 bytes response for this command - for (size_t i = 0; i < 6; i++) - { - // For each bit in the byte, pull out the cell balance state boolean - for (size_t j = 0; j < 8; j++) - { - get.cellBalanceState[cellBit] = bitRead(this->frameBuff[0][i + 4], j); - cellBit++; - if (bitRead(this->frameBuff[0][i + 4], j)) - { - cellBalance++; - } - if (cellBit >= 47) - { - break; - } - } - } - - if (cellBalance > 0) - { - get.cellBalanceActive = true; - } - else - { - get.cellBalanceActive = false; - } - - return true; -} - -bool DalyBms::getFailureCodes() // 0x98 -{ - - if (!this->requestData(COMMAND::FAILURE_CODES, 1)) - { - MessageOutput.printf(" Receive failed, Failure Flags won't be modified!\n"); - return false; - } - failCodeArr = ""; - /* 0x00 */ - // need renaming - // https://github.com/all-solutions/DALY-docs-soft-firm/blob/main/docs/Daly%20UART_485%20Communications%20Protocol%20V1.2.pdf - // level two is more important, check it first - - // alarm.levelOneCellVoltageTooHigh = bitRead(this->frameBuff[0][4], 0); - // alarm.levelTwoCellVoltageTooHigh = bitRead(this->frameBuff[0][4], 1); - if (bitRead(this->frameBuff[0][4], 1)) - failCodeArr += "Cell volt high level 2,"; - else if (bitRead(this->frameBuff[0][4], 0)) - failCodeArr += "Cell volt high level 1,"; - // alarm.levelOneCellVoltageTooLow = bitRead(this->frameBuff[0][4], 2); - // alarm.levelTwoCellVoltageTooLow = bitRead(this->frameBuff[0][4], 3); - if (bitRead(this->frameBuff[0][4], 3)) - failCodeArr += "Cell volt low level 2,"; - else if (bitRead(this->frameBuff[0][4], 2)) - failCodeArr += "Cell volt low level 1,"; - // alarm.levelOnePackVoltageTooHigh = bitRead(this->frameBuff[0][4], 4); - // alarm.levelTwoPackVoltageTooHigh = bitRead(this->frameBuff[0][4], 5); - if (bitRead(this->frameBuff[0][4], 5)) - failCodeArr += "Sum volt high level 2,"; - else if (bitRead(this->frameBuff[0][4], 4)) - failCodeArr += "Sum volt high level 1,"; - // alarm.levelOnePackVoltageTooLow = bitRead(this->frameBuff[0][4], 6); - // alarm.levelTwoPackVoltageTooLow = bitRead(this->frameBuff[0][4], 7); - if (bitRead(this->frameBuff[0][4], 7)) - failCodeArr += "Sum volt low level 2,"; - else if (bitRead(this->frameBuff[0][4], 6)) - failCodeArr += "Sum volt low level 1,"; - - /* 0x01 */ - // alarm.levelOneChargeTempTooHigh = bitRead(this->frameBuff[0][5], 0); - // alarm.levelTwoChargeTempTooHigh = bitRead(this->frameBuff[0][5], 1); - if (bitRead(this->frameBuff[0][5], 1)) - failCodeArr += "Chg temp high level 2,"; - else if (bitRead(this->frameBuff[0][5], 0)) - failCodeArr += "Chg temp high level 1,"; - // alarm.levelOneChargeTempTooLow = bitRead(this->frameBuff[0][5], 2); - //>alarm.levelTwoChargeTempTooLow = bitRead(this->frameBuff[0][5], 3); - if (bitRead(this->frameBuff[0][5], 3)) - failCodeArr += "Chg temp low level 2,"; - else if (bitRead(this->frameBuff[0][5], 2)) - failCodeArr += "Chg temp low level 1,"; - // alarm.levelOneDischargeTempTooHigh = bitRead(this->frameBuff[0][5], 4); - // alarm.levelTwoDischargeTempTooHigh = bitRead(this->frameBuff[0][5], 5); - if (bitRead(this->frameBuff[0][5], 5)) - failCodeArr += "Dischg temp high level 2,"; - else if (bitRead(this->frameBuff[0][5], 4)) - failCodeArr += "Dischg temp high level 1,"; - // alarm.levelOneDischargeTempTooLow = bitRead(this->frameBuff[0][5], 6); - // alarm.levelTwoDischargeTempTooLow = bitRead(this->frameBuff[0][5], 7); - if (bitRead(this->frameBuff[0][5], 7)) - failCodeArr += "Dischg temp low level 2,"; - else if (bitRead(this->frameBuff[0][5], 6)) - failCodeArr += "Dischg temp low level 1,"; - /* 0x02 */ - // alarm.levelOneChargeCurrentTooHigh = bitRead(this->frameBuff[0][6], 0); - // alarm.levelTwoChargeCurrentTooHigh = bitRead(this->frameBuff[0][6], 1); - if (bitRead(this->frameBuff[0][6], 1)) - failCodeArr += "Chg overcurrent level 2,"; - else if (bitRead(this->frameBuff[0][6], 0)) - failCodeArr += "Chg overcurrent level 1,"; - // alarm.levelOneDischargeCurrentTooHigh = bitRead(this->frameBuff[0][6], 2); - // alarm.levelTwoDischargeCurrentTooHigh = bitRead(this->frameBuff[0][6], 3); - if (bitRead(this->frameBuff[0][6], 3)) - failCodeArr += "Dischg overcurrent level 2,"; - else if (bitRead(this->frameBuff[0][6], 2)) - failCodeArr += "Dischg overcurrent level 1,"; - // alarm.levelOneStateOfChargeTooHigh = bitRead(this->frameBuff[0][6], 4); - // alarm.levelTwoStateOfChargeTooHigh = bitRead(this->frameBuff[0][6], 5); - if (bitRead(this->frameBuff[0][6], 5)) - failCodeArr += "SOC high level 2,"; - else if (bitRead(this->frameBuff[0][6], 4)) - failCodeArr += "SOC high level 1,"; - // alarm.levelOneStateOfChargeTooLow = bitRead(this->frameBuff[0][6], 6); - // alarm.levelTwoStateOfChargeTooLow = bitRead(this->frameBuff[0][6], 7); - if (bitRead(this->frameBuff[0][6], 7)) - failCodeArr += "SOC Low level 2,"; - else if (bitRead(this->frameBuff[0][6], 6)) - failCodeArr += "SOC Low level 1,"; - - /* 0x03 */ - // alarm.levelOneCellVoltageDifferenceTooHigh = bitRead(this->frameBuff[0][7], 0); - // alarm.levelTwoCellVoltageDifferenceTooHigh = bitRead(this->frameBuff[0][7], 1); - if (bitRead(this->frameBuff[0][7], 1)) - failCodeArr += "Diff volt level 2,"; - else if (bitRead(this->frameBuff[0][7], 0)) - failCodeArr += "Diff volt level 1,"; - // alarm.levelOneTempSensorDifferenceTooHigh = bitRead(this->frameBuff[0][7], 2); - // alarm.levelTwoTempSensorDifferenceTooHigh = bitRead(this->frameBuff[0][7], 3); - if (bitRead(this->frameBuff[0][7], 3)) - failCodeArr += "Diff temp level 2,"; - else if (bitRead(this->frameBuff[0][7], 2)) - failCodeArr += "Diff temp level 1,"; - /* 0x04 */ - // alarm.chargeFETTemperatureTooHigh = bitRead(this->frameBuff[0][8], 0); - if (bitRead(this->frameBuff[0][8], 0)) - failCodeArr += "Chg MOS temp high alarm,"; - // alarm.dischargeFETTemperatureTooHigh = bitRead(this->frameBuff[0][8], 1); - if (bitRead(this->frameBuff[0][8], 1)) - failCodeArr += "Dischg MOS temp high alarm,"; - // alarm.failureOfChargeFETTemperatureSensor = bitRead(this->frameBuff[0][8], 2); - if (bitRead(this->frameBuff[0][8], 2)) - failCodeArr += "Chg MOS temp sensor err,"; - // alarm.failureOfDischargeFETTemperatureSensor = bitRead(this->frameBuff[0][8], 3); - if (bitRead(this->frameBuff[0][8], 3)) - failCodeArr += "Dischg MOS temp sensor err,"; - // alarm.failureOfChargeFETAdhesion = bitRead(this->frameBuff[0][8], 4); - if (bitRead(this->frameBuff[0][8], 4)) - failCodeArr += "Chg MOS adhesion err,"; - // alarm.failureOfDischargeFETAdhesion = bitRead(this->frameBuff[0][8], 5); - if (bitRead(this->frameBuff[0][8], 5)) - failCodeArr += "Dischg MOS adhesion err,"; - // alarm.failureOfChargeFETTBreaker = bitRead(this->frameBuff[0][8], 6); - if (bitRead(this->frameBuff[0][8], 6)) - failCodeArr += "Chg MOS open circuit err,"; - // alarm.failureOfDischargeFETBreaker = bitRead(this->frameBuff[0][8], 7); - if (bitRead(this->frameBuff[0][8], 7)) - failCodeArr += " Discrg MOS open circuit err,"; - - /* 0x05 */ - // alarm.failureOfAFEAcquisitionModule = bitRead(this->frameBuff[0][9], 0); - if (bitRead(this->frameBuff[0][9], 0)) - failCodeArr += "AFE collect chip err,"; - // alarm.failureOfVoltageSensorModule = bitRead(this->frameBuff[0][9], 1); - if (bitRead(this->frameBuff[0][9], 1)) - failCodeArr += "Voltage collect dropped,"; - // alarm.failureOfTemperatureSensorModule = bitRead(this->frameBuff[0][9], 2); - if (bitRead(this->frameBuff[0][9], 2)) - failCodeArr += "Cell temp sensor err,"; - // alarm.failureOfEEPROMStorageModule = bitRead(this->frameBuff[0][9], 3); - if (bitRead(this->frameBuff[0][9], 3)) - failCodeArr += "EEPROM err,"; - // alarm.failureOfRealtimeClockModule = bitRead(this->frameBuff[0][9], 4); - if (bitRead(this->frameBuff[0][9], 4)) - failCodeArr += "RTC err,"; - // alarm.failureOfPrechargeModule = bitRead(this->frameBuff[0][9], 5); - if (bitRead(this->frameBuff[0][9], 5)) - failCodeArr += "Precharge failure,"; - // alarm.failureOfVehicleCommunicationModule = bitRead(this->frameBuff[0][9], 6); - if (bitRead(this->frameBuff[0][9], 6)) - failCodeArr += "Communication failure,"; - // alarm.failureOfIntranetCommunicationModule = bitRead(this->frameBuff[0][9], 7); - if (bitRead(this->frameBuff[0][9], 7)) - failCodeArr += "Internal communication failure,"; - - /* 0x06 */ - // alarm.failureOfCurrentSensorModule = bitRead(this->frameBuff[0][10], 0); - if (bitRead(this->frameBuff[0][10], 0)) - failCodeArr += "Current module fault,"; - // alarm.failureOfMainVoltageSensorModule = bitRead(this->frameBuff[0][10], 1); - if (bitRead(this->frameBuff[0][10], 1)) - failCodeArr += "Sum voltage detect fault,"; - // alarm.failureOfShortCircuitProtection = bitRead(this->frameBuff[0][10], 2); - if (bitRead(this->frameBuff[0][10], 2)) - failCodeArr += "Short circuit protect fault,"; - // alarm.failureOfLowVoltageNoCharging = bitRead(this->frameBuff[0][10], 3); - if (bitRead(this->frameBuff[0][10], 3)) - failCodeArr += "Low volt forbidden chg fault,"; - - // remove the last character - if (!failCodeArr.isEmpty()) - { - failCodeArr.remove(failCodeArr.length() - 1, 1); - } - return true; -} - bool DalyBms::setDischargeMOS(bool sw) // 0xD9 0x80 First Byte 0x01=ON 0x00=OFF { if (sw) @@ -665,7 +358,7 @@ bool DalyBms::setSOC(float val) // 0x21 last two byte is SOC bool DalyBms::getState() // Function to return the state of connection { - return get.connectionState; + return _stats->_connectionState; } //---------------------------------------------------------------------- @@ -844,44 +537,6 @@ void DalyBms::barfRXBuffer(void) void DalyBms::clearGet(void) { - // data from 0x90 - // get.packVoltage = 0; // pressure (0.1 V) - // get.packCurrent = 0; // acquisition (0.1 V) - // get.packSOC = 0; // State Of Charge - - // data from 0x91 - // get.maxCellmV = 0; // maximum monomer voltage (mV) - // get.maxCellVNum = 0; // Maximum Unit Voltage cell No. - // get.minCellmV = 0; // minimum monomer voltage (mV) - // get.minCellVNum = 0; // Minimum Unit Voltage cell No. - // get.cellDiff = 0; // difference betwen cells - - // data from 0x92 - // get.tempAverage = 0; // Avergae Temperature - - // data from 0x93 - get.chargeDischargeStatus = "DalyOffline"; // charge/discharge status (0 stationary ,1 charge ,2 discharge) - - // get.chargeFetState = false; // charging MOS tube status - // get.disChargeFetState = false; // discharge MOS tube state - // get.bmsHeartBeat = 0; // BMS life(0~255 cycles) - // get.resCapacityAh = 0; // residual capacity mAH - - // data from 0x94 - // get.numberOfCells = 0; // amount of cells - // get.numOfTempSensors = 0; // amount of temp sensors - // get.chargeState = 0; // charger status 0=disconnected 1=connected - // get.loadState = 0; // Load Status 0=disconnected 1=connected - // memset(get.dIO, false, sizeof(get.dIO)); // No information about this - // get.bmsCycles = 0; // charge / discharge cycles - - // data from 0x95 - // memset(get.cellVmV, 0, sizeof(get.cellVmV)); // Store Cell Voltages in mV - - // data from 0x96 - // memset(get.cellTemperature, 0, sizeof(get.cellTemperature)); // array of cell Temperature sensors - - // data from 0x97 - // memset(get.cellBalanceState, false, sizeof(get.cellBalanceState)); // bool array of cell balance states - // get.cellBalanceActive = false; // bool is cell balance active + _stats -> _connectionState = false; + _stats -> _state = "DalyOffline"; // charge/discharge status (0 stationary ,1 charge ,2 discharge) }