dev
This commit is contained in:
parent
8f9e256c64
commit
9f562d5569
3
BLE.ino
3
BLE.ino
@ -121,7 +121,8 @@ void handleBLE(){
|
||||
if(ble_packets_received == BLE_PACKETSRECEIVED_BEFORE_STANDBY){
|
||||
debug("BLE: all packets received");
|
||||
bms_status=true; // BMS was connected, data up-to-date
|
||||
|
||||
printBasicInfo();
|
||||
printCellInfo();
|
||||
}else{
|
||||
debug("BLE: connection timeout");
|
||||
bms_status=false; // BMS not (fully) connected
|
||||
|
@ -28,7 +28,7 @@ bool isPacketValid(byte *packet) //check if packet is valid
|
||||
if (checksum != packet[offset + checksumPos + 1]){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ bool processCellInfo(packCellInfoStruct *output, byte *data, unsigned int dataLe
|
||||
_cellMin = output->CellVolt[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
output->CellMin = _cellMin;
|
||||
output->CellMax = _cellMax;
|
||||
output->CellDiff = _cellMax - _cellMin;
|
||||
@ -117,7 +117,7 @@ bool bmsProcessPacket(byte *packet)
|
||||
ble_packets_received |= 0b01;
|
||||
bms_last_update_time=millis();
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -144,29 +144,29 @@ bool bleCollectPacket(char *data, uint32_t dataSize) // reconstruct packet, call
|
||||
{
|
||||
static uint8_t packetstate = 0; //0 - empty, 1 - first half of packet received, 2- second half of packet received
|
||||
|
||||
// packet sizes:
|
||||
// packet sizes:
|
||||
// (packet ID 03) = 4 (header) + 23 + 2*N_NTCs + 2 (checksum) + 1 (stop)
|
||||
// (packet ID 04) = 4 (header) + 2*NUM_CELLS + 2 (checksum) + 1 (stop)
|
||||
static uint8_t packetbuff[4 + 2*25 + 2 + 1] = {0x0}; // buffer size suitable for up to 25 cells
|
||||
|
||||
|
||||
static uint32_t totalDataSize = 0;
|
||||
bool retVal = false;
|
||||
//hexDump(data,dataSize);
|
||||
|
||||
|
||||
if(totalDataSize + dataSize > sizeof(packetbuff)){
|
||||
Serial.printf("ERROR: datasize is overlength.");
|
||||
|
||||
|
||||
debug(
|
||||
String("ERROR: datasize is overlength. ") +
|
||||
String("ERROR: datasize is overlength. ") +
|
||||
String("allocated=") +
|
||||
String(sizeof(packetbuff)) +
|
||||
String(sizeof(packetbuff)) +
|
||||
String(", size=") +
|
||||
String(totalDataSize + dataSize)
|
||||
);
|
||||
|
||||
|
||||
totalDataSize = 0;
|
||||
packetstate = 0;
|
||||
|
||||
|
||||
retVal = false;
|
||||
}
|
||||
else if (data[0] == 0xdd && packetstate == 0) // probably got 1st half of packet
|
||||
@ -189,7 +189,7 @@ bool bleCollectPacket(char *data, uint32_t dataSize) // reconstruct packet, call
|
||||
totalDataSize += dataSize;
|
||||
retVal = true;
|
||||
}
|
||||
|
||||
|
||||
if (packetstate == 2) //got full packet
|
||||
{
|
||||
uint8_t packet[totalDataSize];
|
||||
@ -217,7 +217,6 @@ bool bmsRequestCellInfo(){
|
||||
return sendCommand(data, sizeof(data));
|
||||
}
|
||||
|
||||
/*
|
||||
void printBasicInfo() //debug all data to uart
|
||||
{
|
||||
Serial.printf("Total voltage: %f\n", (float)packBasicInfo.Volts / 1000);
|
||||
@ -246,32 +245,6 @@ void printCellInfo() //debug all data to uart
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void constructBigString() //debug all data to uart
|
||||
{
|
||||
stringBuffer[0] = '\0'; //clear old data
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Total voltage: %f\n", (float)packBasicInfo.Volts / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Amps: %f\n", (float)packBasicInfo.Amps / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "CapacityRemainAh: %f\n", (float)packBasicInfo.CapacityRemainAh / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "CapacityRemainPercent: %d\n", packBasicInfo.CapacityRemainPercent);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Temp1: %f\n", (float)packBasicInfo.Temp1 / 10);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Temp2: %f\n", (float)packBasicInfo.Temp2 / 10);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Balance Code Low: 0x%x\n", packBasicInfo.BalanceCodeLow);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Balance Code High: 0x%x\n", packBasicInfo.BalanceCodeHigh);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Mosfet Status: 0x%x\n", packBasicInfo.MosfetStatus);
|
||||
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Number of cells: %u\n", packCellInfo.NumOfCells);
|
||||
for (byte i = 1; i <= packCellInfo.NumOfCells; i++)
|
||||
{
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Cell no. %u", i);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, " %f\n", (float)packCellInfo.CellVolt[i - 1] / 1000);
|
||||
}
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Max cell volt: %f\n", (float)packCellInfo.CellMax / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Min cell volt: %f\n", (float)packCellInfo.CellMin / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Difference cell volt: %f\n", (float)packCellInfo.CellDiff / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "Average cell volt: %f\n", (float)packCellInfo.CellAvg / 1000);
|
||||
snprintf(stringBuffer, STRINGBUFFERSIZE, "\n");
|
||||
}
|
||||
|
||||
void hexDump(const char *data, uint32_t dataSize) //debug function
|
||||
{
|
||||
Serial.println("HEX data:");
|
||||
@ -282,7 +255,6 @@ void hexDump(const char *data, uint32_t dataSize) //debug function
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
*/
|
||||
|
||||
int16_t two_ints_into16(int highbyte, int lowbyte) // turns two bytes into a single long integer
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user