Skip to content

Commit

Permalink
code cleanup. removed commented code for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MoleBre committed Sep 8, 2024
1 parent 4ae8884 commit 018e048
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
4 changes: 0 additions & 4 deletions include/JbdBmsSerialMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class SerialMessage {
template<typename It> int16_t getTemperature(It&& pos) const;
template<typename It> std::string getString(It&& pos, size_t len, bool replaceZeroes = false) const;
template<typename It> std::string getProductionDate(It&& pos) const;
void processBatteryCurrent(tData::const_iterator& pos);
template<typename T> void set(tData::iterator const& pos, T val);
uint16_t calcChecksum() const;
void updateChecksum();
Expand All @@ -58,7 +57,6 @@ class SerialMessage {

class SerialResponse : public SerialMessage {
public:

enum class Status : uint8_t {
Ok = 0x00,
Error = 0x80
Expand All @@ -77,8 +75,6 @@ class SerialResponse : public SerialMessage {

class SerialCommand : public SerialMessage {
public:
//using Command = SerialMessage::Command;

enum class Status : uint8_t {
Read = 0xA5,
Write = 0x5A,
Expand Down
42 changes: 0 additions & 42 deletions src/JbdBmsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ void Controller::sendRequest(uint8_t pollInterval)
digitalWrite(_txEnablePin, HIGH); // enable transmission
}

//readCmd.printMessage(); // TODO: Only for testing. Comment out
_upSerial->write(readCmd.data(), readCmd.size());

if (Interface::Transceiver == getInterface()) {
Expand Down Expand Up @@ -179,84 +178,43 @@ void Controller::rxData(uint8_t inbyte)
{
_buffer.push_back(inbyte);

/* Print inbyte
if (inbyte == 0xDD) {MessageOutput.printf("[%11.3f] JBD BMS: Byte received: %02x", static_cast<double>(millis())/1000, inbyte);}
MessageOutput.printf(" %02x", inbyte);
if (inbyte == 0x77) {MessageOutput.println();}
*/

switch(_readState) {
case ReadState::Idle: // unsolicited message from BMS
case ReadState::WaitingForFrameStart:
if (inbyte == SerialMessage::startMarker) {
//MessageOutput.printf("[JBD BMS] Byte received: startMarker received: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::FrameStartReceived);
}
break;
case ReadState::FrameStartReceived:
//MessageOutput.printf("[JBD BMS] Byte received: FrameStartReceived: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::StateReceived);
break;
case ReadState::StateReceived:
//MessageOutput.printf("[JBD BMS] Byte received: StateReceived: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::CommandCodeReceived);
break;
case ReadState::CommandCodeReceived:
_dataLength = inbyte;
if (_dataLength == 0) {
//MessageOutput.printf("[JBD BMS] Byte received: CommandCodeReceived with dataLength == 0: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::DataContentReceived);
}
else {
//MessageOutput.printf("[JBD BMS] Byte received: CommandCodeReceived with dataLength > 0: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::ReadingDataContent);
}
break;
case ReadState::ReadingDataContent:
//MessageOutput.printf("[JBD BMS] Byte received: ReadingDataContent:%02x, remaining datalength %i.", inbyte, _dataLength);
//MessageOutput.println();
_dataLength--;
if (_dataLength == 0) {
return setReadState(ReadState::DataContentReceived);
}
return setReadState(ReadState::ReadingDataContent);
break;
case ReadState::DataContentReceived:
//MessageOutput.printf("[JBD BMS] Byte received: DataContentReceived. First Checksum byte: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::ReadingCheckSum);
break;
case ReadState::ReadingCheckSum:
//MessageOutput.printf("[JBD BMS] Byte received: DataContentReceived. Second Checksum byte: %02x.", inbyte);
//MessageOutput.println();
return setReadState(ReadState::CheckSumReceived);
break;
case ReadState::CheckSumReceived:
//MessageOutput.printf("[JBD BMS] Byte received: CheckSumReceived. Next byte: %02x\n.", inbyte);
//MessageOutput.println();
if (inbyte == SerialMessage::endMarker) {
//MessageOutput.printf("[JBD BMS] Byte received: endMarker received.");
//MessageOutput.println();

/*
// Test with Dummy Messages
if (_buffer[1] == 0x03) {
// test AlarmBitMask with FFFF
_buffer[20] = uint8_t (0xFF);
_buffer[21] = uint8_t (0xFF);
// _buffer = {0xdd, 0x03, 0x00, 0x26, 0x0a, 0x4a, 0x00, 0x00, 0x20, 0xc5, 0x4e, 0x20, 0x00, 0x00, 0x2f, 0x9d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x2a, 0x03, 0x08, 0x03, 0x0b, 0x93, 0x0b, 0x88, 0x0b, 0x88, 0x00, 0x00, 0x00, 0x4e, 0x20, 0x20, 0xc5, 0x00, 0x00, 0xf9, 0xf3, 0x77};
}
uint16_t checksumUpdate = (~std::accumulate(_buffer.cbegin()+2, _buffer.cend()-3, 0) + 0x01);
*(_buffer.end()-3) = uint8_t (checksumUpdate >> 8);
*(_buffer.end()-2) = uint8_t (checksumUpdate);
*/

return frameComplete();
}
else {
Expand Down

0 comments on commit 018e048

Please sign in to comment.