Skip to content

Commit

Permalink
Merge branch 'new_features_24-2' into device_data_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
shining-man committed Jul 28, 2024
2 parents 47dd4ce + 641c526 commit 7ea2f26
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 50 deletions.
2 changes: 2 additions & 0 deletions include/ModbusRTU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace modbusrtu
int16_t getI16ValueByOffset(uint16_t offset);
uint32_t getU32ValueByOffset(uint16_t offset);
int32_t getI32ValueByOffset(uint16_t offset);
bool getBitValueByOffset(uint16_t offset, uint8_t b);


private:
Expand All @@ -61,6 +62,7 @@ namespace modbusrtu

void buildSendMsg(uint8_t addr, fCode cmd, uint16_t startRegister, uint16_t len);
bool readSerialData();
void errorNoData(uint16_t offset);
};

} // namespace modbusrtu
Expand Down
2 changes: 1 addition & 1 deletion include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "params_dt.h"
#include "bscTime.h"

#define BSC_SW_VERSION "V0.6.1_T2"
#define BSC_SW_VERSION "V0.6.1_T5"

static const char COMPILE_DATE_TIME[] = "";

Expand Down
4 changes: 2 additions & 2 deletions include/params.h

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions include/webpages.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const char htmlPageRoot[] PROGMEM = "<!DOCTYPE HTML>"
"</head>"
"<body>"
"<div class='topnav'>"
"<span class='hl'>Battery Safety Controller&nbsp;&nbsp;&nbsp;V0.6.1_T2</span>"
"<span class='hl'>Battery Safety Controller&nbsp;&nbsp;&nbsp;V0.6.1_T5</span>"
"</div>"
"<div style='background-color: #BFEFFF; padding: 10px; margin-top: 10px;'>Gefällt dir das Projekt? Zeige deine Wertschätzung doch einfach mit einer Spende! Weitere Infos unter "
"<a href='./support/'>Unterst&uuml;tzung</a></div>"
Expand Down Expand Up @@ -661,7 +661,6 @@ const char htmlPageSupport[] PROGMEM = "<!DOCTYPE HTML>"
"<p>Eure großzügige Unterstützung ermöglicht es mir, weiterhin neue Funktionen zu entwickeln und Bugs zu bekämpfen. Nur so kann das Projekt auch in der Zukunft erfolgreich sein.</p>"
"<p>Vielen Dank im Voraus für eure Großzügigkeit und eure Unterstützung!</p>"
"<p>Mit elektrischen Grüßen,<br>shiningman</p>"
"<p>Paypal: <a href=\"javascript:window.open('https://www.paypal.me/shiningman11');\">https://www.paypal.me/shiningman11</a></p>"
"<p>GitHub Sponsor: <a href=\"javascript:window.open('https://github.com/sponsors/shining-man');\">https://github.com/sponsors/shining-man</a></p>"

"<p>Mit elektrischen Grüßen,<br>shiningman</p>"
Expand Down
2 changes: 1 addition & 1 deletion src/BleHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ClientCallbacks : public NimBLEClientCallbacks
break;
case ID_BT_DEVICE_JKBMS_JK02:
case ID_BT_DEVICE_JKBMS_JK02_32S:
pClient->updateConnParams(120,120,0,60);
pClient->updateConnParams(20,20,0,60);
jkBmsBtDevInit(i);
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/BmsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ bool isMultiple485bms(uint8_t bms)
case ID_SERIAL_DEVICE_BPN:
case ID_SERIAL_DEVICE_GOBELBMS:
case ID_SERIAL_DEVICE_GOBEL_PC200:
case ID_SERIAL_DEVICE_JKINVERTERBMS:
return true;
break;

Expand Down
3 changes: 2 additions & 1 deletion src/BscSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "devices/GobelBms_PC200.h"
#include "devices/SeplosBmsV3.h"
#include "devices/NeeySerial.h"
#include "devices/JkInverterBms.h"
#ifdef BPN
#include "devices/bpnSerial.h"
#endif
Expand Down Expand Up @@ -295,7 +296,7 @@ void BscSerial::setReadBmsFunktion(uint8_t u8_devNr, uint8_t funktionsTyp)
case ID_SERIAL_DEVICE_JKINVERTERBMS:
BSC_LOGI(TAG,"setReadBmsFunktion JK Inverter");
setSerialBaudrate(u8_devNr, 115200);
serialDeviceData[u8_devNr].readBms = &SeplosBmsV3_readBmsData;
serialDeviceData[u8_devNr].readBms = &JkInverterBms_readBmsData;
break;

case ID_SERIAL_DEVICE_PYLONTECH:
Expand Down
56 changes: 55 additions & 1 deletion src/ModbusRTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ ModbusRTU::~ModbusRTU()
;
}

/*static void message2Log(uint8_t * t_message, uint8_t len, uint8_t address)
{
String recvBytes="";
uint8_t u8_logByteCount=0;
BSC_LOGI(TAG,"Dev=%i, RecvBytes=%i",address, len);
for(uint8_t x=0;x<len;x++)
{
u8_logByteCount++;
recvBytes+="0x";
recvBytes+=String(t_message[x],16);
recvBytes+=" ";
if(u8_logByteCount==20)
{
BSC_LOGI(TAG,"%s",recvBytes.c_str());
recvBytes="";
u8_logByteCount=0;
}
}
BSC_LOGI(TAG,"%s",recvBytes.c_str());
//log_print_buf(p_lRecvBytes, u8_lRecvBytesCnt);
}*/

/*
* Anfrage:
Expand Down Expand Up @@ -56,7 +77,7 @@ bool ModbusRTU::readData(uint8_t addr, fCode cmd, uint16_t startRegister, uint16

void ModbusRTU::buildSendMsg(uint8_t addr, fCode cmd, uint16_t startRegister, uint16_t len)
{
uint8_t lSendData[20];
uint8_t lSendData[8];

lSendData[0]=addr; // ADDR
lSendData[1]=(uint8_t)cmd; // CMD
Expand All @@ -70,6 +91,8 @@ void ModbusRTU::buildSendMsg(uint8_t addr, fCode cmd, uint16_t startRegister, ui
lSendData[6]=(u16_lCrc&0xff); // CRC
lSendData[7]=((u16_lCrc>>8)&0xff); // CRC

//message2Log(lSendData, 8, addr);

// RX-Buffer leeren
for(unsigned long clearRxBufTime = millis(); millis()-clearRxBufTime<100;)
{
Expand Down Expand Up @@ -194,6 +217,11 @@ int16_t ModbusRTU::getI16Value(uint16_t address)

uint8_t ModbusRTU::getU8ValueByOffset(uint16_t offset)
{
if(offset > retDataLen)
{
errorNoData(offset);
return 0;
}
return mRetData[offset];
}

Expand All @@ -204,6 +232,11 @@ int8_t ModbusRTU::getI8ValueByOffset(uint16_t offset)

uint16_t ModbusRTU::getU16ValueByOffset(uint16_t offset)
{
if(offset+1 > retDataLen)
{
errorNoData(offset+1);
return 0;
}
return (mRetData[offset]<<8) | mRetData[offset+1];
}

Expand All @@ -214,6 +247,11 @@ int16_t ModbusRTU::getI16ValueByOffset(uint16_t offset)

uint32_t ModbusRTU::getU32ValueByOffset(uint16_t offset)
{
if(offset+3 > retDataLen)
{
errorNoData(offset+3);
return 0;
}
return (mRetData[offset]<<24) | (mRetData[offset+1]<<16) | (mRetData[offset+2]<<8) | mRetData[offset+3];
}

Expand All @@ -222,4 +260,20 @@ int32_t ModbusRTU::getI32ValueByOffset(uint16_t offset)
return (int32_t)getU32ValueByOffset(offset);
}

bool ModbusRTU::getBitValueByOffset(uint16_t offset, uint8_t b)
{
if(offset > retDataLen)
{
errorNoData(offset);
return 0;
}

return isBitSet(mRetData[offset],b);
}

void ModbusRTU::errorNoData(uint16_t offset)
{
BSC_LOGE(TAG,"Keine Daten! Lese Byte %i von %i",offset, retDataLen);
}

} // namespace modbusrtu
20 changes: 16 additions & 4 deletions src/devices/GobelBms_PC200.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool GobelBmsPC200_readBmsData(Stream *port, uint8_t devNr, void (*callback)(uin
getDataFromBms(u8_lGobelAdr, 0x44); // Alarms
if (recvAnswer(response))
{
//parseMessage_Alarms(response, u8_lGobelAdrBmsData);
parseMessage_Alarms(response, u8_lGobelAdrBmsData);
}
else ret = false;
}
Expand All @@ -189,7 +189,7 @@ static void getDataFromBms(uint8_t address, uint8_t function)
u8_lData[3] = function; // CID2 (0x42)
u8_lData[4] = (lenid >> 8); // LCHKSUM (0xE0)
u8_lData[5] = (lenid >> 0); // LENGTH (0x02)
u8_lData[6] = 0xFF; // INFO
u8_lData[6] = address + 1; //0xFF; // INFO

convertByteToAsciiHex(&u8_lSendData[1], &u8_lData[0], frame_len);

Expand Down Expand Up @@ -448,7 +448,7 @@ Byte | Data

setBmsChargePercentage(address, (float)((float)u16_lBalanceCapacity / (float)u16_lFullCapacity * 100.0f));
#ifdef GOBELPC200_DEBUG
BSC_LOGD(TAG, "Capacity: %f, %f, soc=%i", u16_lBalanceCapacity, u16_lFullCapacity, getBmsChargePercentage(address));
BSC_LOGD(TAG, "Capacity: %i %i, soc=%i", u16_lBalanceCapacity, u16_lFullCapacity, getBmsChargePercentage(address));
#endif
u16_lBalanceCapacity /= 100;
u16_lFullCapacity /= 100;
Expand Down Expand Up @@ -605,6 +605,7 @@ Char A.25 Warn state2 explanation
uint32_t u32_alarm = 0;
boolean bo_lValue = false;

#if 0
uint8_t u8_lNumOfCells = convertAsciiHexToByte(t_message, 8); // Number of cells
#ifdef GOBELPC200_DEBUG
BSC_LOGD(TAG, "Number of cells: %d", u8_lNumOfCells);
Expand Down Expand Up @@ -690,7 +691,18 @@ Char A.25 Warn state2 explanation
if (warnstate2 & (1<<3))
u32_alarm |= BMS_ERR_STATUS_DSG_UTP;

setBmsErrors(address, u32_alarm);
setBmsErrors(BT_DEVICES_COUNT + address, u32_alarm);
#endif


// FET state
uint8_t FETstate = convertAsciiHexToByte(t_message, 37);
if(isBitSet(FETstate,1)) setBmsStateFETsCharge(address, true);
else setBmsStateFETsCharge(address, false);

if(isBitSet(FETstate,2)) setBmsStateFETsDischarge(address, true);
else setBmsStateFETsDischarge(address, false);

}

uint8_t convertAsciiHexToByte(char a, char b)
Expand Down
Loading

0 comments on commit 7ea2f26

Please # to comment.