Skip to content

Commit

Permalink
wip(protocol): identified error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp committed Nov 11, 2024
1 parent 84e58f0 commit 385cd25
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
27 changes: 13 additions & 14 deletions AquaMQTT/include/message/MessageConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace aquamqtt
{
namespace message
{
constexpr uint8_t HEATPUMP_MAX_FRAME_LENGTH = 50;
constexpr uint8_t HEATPUMP_MAX_FRAME_LENGTH = 70;

constexpr uint8_t MESSAGE_PERIOD_MS = 100;

Expand All @@ -20,22 +20,21 @@ enum ProtocolVersion
PROTOCOL_NEXT = 1
};

constexpr uint8_t HMI_MESSAGE_IDENTIFIER = 194;
constexpr uint8_t HMI_MESSAGE_LENGTH_NEXT = 34;
constexpr uint8_t HMI_MESSAGE_LENGTH_LEGACY = 35;
constexpr uint8_t HMI_MESSAGE_IDENTIFIER = 194;
constexpr uint8_t HMI_MESSAGE_LENGTH_NEXT = 34;
constexpr uint8_t HMI_MESSAGE_LENGTH_LEGACY = 35;

constexpr uint8_t MAIN_MESSAGE_IDENTIFIER = 193;
constexpr uint8_t MAIN_MESSAGE_LENGTH_NEXT = 35;
constexpr uint8_t MAIN_MESSAGE_LENGTH_LEGACY = 37;
constexpr uint8_t MAIN_MESSAGE_IDENTIFIER = 193;
constexpr uint8_t MAIN_MESSAGE_LENGTH_NEXT = 35;
constexpr uint8_t MAIN_MESSAGE_LENGTH_LEGACY = 37;

constexpr uint8_t ENERGY_MESSAGE_IDENTIFIER = 67;
constexpr uint8_t ENERGY_MESSAGE_LENGTH_NEXT = 45;
constexpr uint8_t ENERGY_MESSAGE_LENGTH_LEGACY = 31;
constexpr uint8_t ENERGY_MESSAGE_IDENTIFIER = 67;
constexpr uint8_t ENERGY_MESSAGE_LENGTH_NEXT = 45;
constexpr uint8_t ENERGY_MESSAGE_LENGTH_LEGACY = 31;

constexpr uint8_t ERROR_MESSAGE_IDENTIFIER = 74;
// TODO: analyze serial protocol for error messages
constexpr uint8_t ERROR_MESSAGE_LENGTH_NEXT = 0;
constexpr uint8_t ERROR_MESSAGE_LENGTH_LEGACY = 35;
constexpr uint8_t ERROR_MESSAGE_IDENTIFIER = 74;
constexpr uint8_t ERROR_MESSAGE_LENGTH_NEXT = 65;
constexpr uint8_t ERROR_MESSAGE_LENGTH_LEGACY = 35;

// this will work as long as they will always differ in length
static ProtocolVersion getVersionByIdentifier(uint8_t identifier, uint8_t length)
Expand Down
6 changes: 2 additions & 4 deletions AquaMQTT/src/buffer/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ bool FrameBuffer::isSync()
return ((mBuffer[0] == HMI_MESSAGE_IDENTIFIER && mBuffer[1] == HMI_MESSAGE_LENGTH_NEXT)
|| (mBuffer[0] == MAIN_MESSAGE_IDENTIFIER && mBuffer[1] == MAIN_MESSAGE_LENGTH_NEXT)
|| (mBuffer[0] == ENERGY_MESSAGE_IDENTIFIER && mBuffer[1] == ENERGY_MESSAGE_LENGTH_NEXT)
// TODO: reenable as soon as we know the length of the NEXT error message
/*|| (mBuffer[0] == ERROR_MESSAGE_IDENTIFIER && mBuffer[1] == ERROR_MESSAGE_LENGTH_NEXT)*/);
|| (mBuffer[0] == ERROR_MESSAGE_IDENTIFIER && mBuffer[1] == ERROR_MESSAGE_LENGTH_NEXT));
default:
case PROTOCOL_UNKNOWN:
return ((mBuffer[0] == HMI_MESSAGE_IDENTIFIER && mBuffer[1] == HMI_MESSAGE_LENGTH_NEXT)
Expand All @@ -206,8 +205,7 @@ bool FrameBuffer::isSync()
|| (mBuffer[0] == HMI_MESSAGE_IDENTIFIER && mBuffer[1] == HMI_MESSAGE_LENGTH_LEGACY)
|| (mBuffer[0] == MAIN_MESSAGE_IDENTIFIER && mBuffer[1] == MAIN_MESSAGE_LENGTH_LEGACY)
|| (mBuffer[0] == ENERGY_MESSAGE_IDENTIFIER && mBuffer[1] == ENERGY_MESSAGE_LENGTH_LEGACY)
// TODO: reenable as soon as we know the length of the NEXT error message
//|| (mBuffer[0] == ERROR_MESSAGE_IDENTIFIER && mBuffer[1] == ENERGY_MESSAGE_LENGTH_LEGACY)
|| (mBuffer[0] == ERROR_MESSAGE_IDENTIFIER && mBuffer[1] == ERROR_MESSAGE_LENGTH_LEGACY)
);
}
}
Expand Down
11 changes: 7 additions & 4 deletions AquaMQTT/src/task/MQTTTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,17 +874,20 @@ void MQTTTask::updateErrorStatus(message::ProtocolVersion& version)
if (version == ProtocolVersion::PROTOCOL_NEXT)
{
message = std::make_unique<message::next::ErrorMessage>(mTransferBuffer);

// there are no empty error messages in next protocol
}
else
{
message = std::make_unique<message::legacy::ErrorMessage>(mTransferBuffer);
}

if (message->isEmpty())
{
return;
if (message->isEmpty())
{
return;
}
}


// sprintf(reinterpret_cast<char*>(mTopicBuffer),
// "%s%s%s%u/%s",
// config::mqttPrefix,
Expand Down
30 changes: 21 additions & 9 deletions prototypes/NextSimulator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ uint8_t msg194c[] = {


uint8_t msg194e[] = {
0xC2, 0x22, 0x32, 0x12, 0x00, 0x00, 0x00, 0x10,
0x00, 0x06, 0x2C, 0x01, 0xD0, 0x02, 0x00, 0x00,
0x00, 0x02, 0x21, 0x1E, 0x0D, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x4E, 0x45, 0x00, 0x00, 0x06, 0x04,
0x22, 0x01, 0x3E, 0xC3
0xC2, 0x22, 0x32, 0x12, 0x00, 0x00, 0x00, 0x10,
0x00, 0x06, 0x2C, 0x01, 0xD0, 0x02, 0x00, 0x00,
0x00, 0x02, 0x21, 0x1E, 0x0D, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x4E, 0x45, 0x00, 0x00, 0x06, 0x04,
0x22, 0x01, 0x3E, 0xC3
};

uint8_t msg67[] = {
Expand All @@ -68,6 +68,18 @@ uint8_t msg67[] = {
};
uint8_t msg67_len = 47;

uint8_t msg74[] = {0x4A, 0x41, 0x0D, 0x0F, 0x2D, 0x00, 0x27, 0x00,
0x15, 0x00, 0x18, 0x00, 0x13, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x67, 0x1D, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x45, 0x11, 0x00, 0x00, 0x58,
0x11, 0x00, 0x00, 0x7A, 0x22, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21,
0x1E, 0x00, 0x0C, 0x00, 0x32, 0x00, 0x00, 0x00,
0x08, 0x00, 0x6B};

uint8_t msg74_len = 67;

void loop() {
if (next194 == 0) {
Serial.write(msg194a, msg194_len);
Expand All @@ -78,8 +90,7 @@ void loop() {
} else if (next194 == 2) {
Serial.write(msg194c, msg194_len);
next194 = 3;
}
else if(next194 == 3) {
} else if (next194 == 3) {
Serial.write(msg194e, msg194_len);
next194 = 0;
}
Expand All @@ -91,6 +102,7 @@ void loop() {
delay(100);
Serial.write(msg193, msg193_len);
Serial.flush();
delay(200);
// TODO: error message not yet known
delay(100);
Serial.write(msg74, msg74_len);
delay(100);
}

0 comments on commit 385cd25

Please sign in to comment.