Skip to content

Commit

Permalink
Added big data information processing
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Dec 22, 2023
1 parent 2005c57 commit eda897a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tools/hon_simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void preloop(haier_protocol::ProtocolHandler* handler) {
}
if (_trigger_random_alarm) {
_trigger_random_alarm = false;
size_t r = std::rand() % (ALARM_BUF_SIZE * 8);
size_t r = esphome::haier::hon_protocol::HON_ALARM_COUNT - std::rand() % (esphome::haier::hon_protocol::HON_ALARM_COUNT);
HAIER_LOGI("Random alarm triggered. Alarm code %d", r);
start_alarm(r);
}
Expand Down
56 changes: 56 additions & 0 deletions tools/utils/hon_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,62 @@ enum class SubcommandsControl : uint16_t {
// content: all values like in status packet)
};

const std::string HON_ALARM_MESSAGES[] = {
"Outdoor module failure",
"Outdoor defrost sensor failure",
"Outdoor compressor exhaust sensor failure",
"Outdoor EEPROM abnormality",
"Indoor coil sensor failure",
"Indoor-outdoor communication failure",
"Power supply overvoltage protection",
"Communication failure between panel and indoor unit",
"Outdoor compressor overheat protection",
"Outdoor environmental sensor abnormality",
"Full water protection",
"Indoor EEPROM failure",
"Outdoor out air sensor failure",
"CBD and module communication failure",
"Indoor DC fan failure",
"Outdoor DC fan failure",
"Door switch failure",
"Dust filter needs cleaning reminder",
"Water shortage protection",
"Humidity sensor failure",
"Indoor temperature sensor failure",
"Manipulator limit failure",
"Indoor PM2.5 sensor failure",
"Outdoor PM2.5 sensor failure",
"Indoor heating overload/high load alarm",
"Outdoor AC current protection",
"Outdoor compressor operation abnormality",
"Outdoor DC current protection",
"Outdoor no-load failure",
"CT current abnormality",
"Indoor cooling freeze protection",
"High and low pressure protection",
"Compressor out air temperature is too high",
"Outdoor evaporator sensor failure",
"Outdoor cooling overload",
"Water pump drainage failure",
"Three-phase power supply failure",
"Four-way valve failure",
"External alarm/scraper flow switch failure",
"Temperature cutoff protection alarm",
"Different mode operation failure",
"Electronic expansion valve failure",
"Dual heat source sensor Tw failure",
"Communication failure with the wired controller",
"Indoor unit address duplication failure",
"50Hz zero crossing failure",
"Outdoor unit failure",
"Formaldehyde sensor failure",
"VOC sensor failure",
"CO2 sensor failure",
"Firewall failure",
};

constexpr size_t HON_ALARM_COUNT = sizeof(HON_ALARM_MESSAGES) / sizeof(HON_ALARM_MESSAGES[0]);

} // namespace hon_protocol
} // namespace haier
} // namespace esphome
44 changes: 31 additions & 13 deletions tools/utils/hon_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ bool alarm_stopped;
constexpr size_t SHORT_ALARM_REPORT_INTERVAL_MS = 300;
constexpr size_t LONG_ALARM_REPORT_INTERVAL_MS = 5000;

bool alarm_active() {
if (alarm_stopped)
return false;
bool has_active_alarms() {
for (int i = 0; i < ALARM_BUF_SIZE; i++)
if (alarm_status_buf[i] != 0)
return true;
Expand Down Expand Up @@ -78,9 +76,27 @@ void init_ac_state(HvacFullStatus& state) {
state.sensors.ch2o_value = 0;
state.sensors.voc_value = 0;
state.sensors.co2_value = 0;
state.big_data.power[0] = 0;
state.big_data.power[0] = 0;
state.big_data.indoor_coil_temperature = state.sensors.room_temperature + 40;
state.big_data.outdoor_out_air_temperature = state.sensors.outdoor_temperature;
state.big_data.outdoor_coil_temperature = state.sensors.outdoor_temperature;
state.big_data.outdoor_in_air_temperature = state.sensors.outdoor_temperature;
state.big_data.outdoor_defrost_temperature = state.sensors.outdoor_temperature;
state.big_data.compressor_frequency = 0;
state.big_data.compressor_current[0] = 0;
state.big_data.compressor_current[1] = 0;
state.big_data.outdoor_fan_status = 0;
state.big_data.defrost_status = 0;
state.big_data.compressor_status = 0;
state.big_data.indoor_fan_status = 0;
state.big_data.four_way_valve_status = 0;
state.big_data.indoor_electric_heating_status = 0;
state.big_data.expansion_valve_open_degree[0] = 0;
state.big_data.expansion_valve_open_degree[1] = 0;
last_alarm_message = std::chrono::steady_clock::now();
alarm_paused = false;
alarm_stopped = false;
alarm_stopped = true;
}

bool is_in_configuration_mode() {
Expand All @@ -89,7 +105,7 @@ bool is_in_configuration_mode() {

void process_alarms(haier_protocol::ProtocolHandler* protocol_handler)
{
if (alarm_active() && !protocol_handler->is_waiting_for_answer() && (protocol_handler->get_outgoing_queue_size() == 0)) {
if (!alarm_stopped && !protocol_handler->is_waiting_for_answer() && (protocol_handler->get_outgoing_queue_size() == 0)) {
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
if (( alarm_paused && (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_alarm_message).count() > LONG_ALARM_REPORT_INTERVAL_MS)) ||
(!alarm_paused && (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_alarm_message).count() > SHORT_ALARM_REPORT_INTERVAL_MS))) {
Expand All @@ -110,17 +126,16 @@ HvacFullStatus& get_ac_state_ref() {
}

bool start_alarm(uint8_t alarm_id) {
if (alarm_id >= ALARM_BUF_SIZE * 8)
if (alarm_id >= esphome::haier::hon_protocol::HON_ALARM_COUNT)
return false;
alarm_paused = false;
alarm_stopped = false;
alarm_status_buf[(uint8_t)(alarm_id / 8)] |= (1 << (alarm_id % 8));
alarm_status_buf[ALARM_BUF_SIZE - 1 - (uint8_t)(alarm_id / 8)] |= (1 << (alarm_id % 8));
return true;
}

void reset_alarms() {
memset(alarm_status_buf, 0, sizeof(ALARM_BUF_SIZE));
alarm_stopped = false;
alarm_paused = false;
}

Expand Down Expand Up @@ -182,14 +197,14 @@ haier_protocol::HandlerError status_request_handler(haier_protocol::ProtocolHand
protocol_handler->send_answer(INVALID_MSG);
return haier_protocol::HandlerError::WRONG_MESSAGE_STRUCTURE;
}
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D01, (uint8_t*)&ac_status, sizeof(HvacFullStatus)));
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D01, (uint8_t*)&ac_status, USER_DATA_SIZE));
return haier_protocol::HandlerError::HANDLER_OK;
case (uint16_t)SubcommandsControl::GET_BIG_DATA:
if (size != 2) {
protocol_handler->send_answer(INVALID_MSG);
return haier_protocol::HandlerError::WRONG_MESSAGE_STRUCTURE;
}
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D01, (uint8_t*)&ac_status, sizeof(HvacFullStatus)));
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x7D01, (uint8_t*)&ac_status, BIG_DATA_SIZE));
return haier_protocol::HandlerError::HANDLER_OK;
case (uint16_t)SubcommandsControl::SET_GROUP_PARAMETERS:
if (size - 2 != sizeof(HaierPacketControl)) {
Expand All @@ -204,7 +219,7 @@ haier_protocol::HandlerError status_request_handler(haier_protocol::ProtocolHand
cbyte = buffer[2 + i];
}
}
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D5F, (uint8_t*)&ac_status, sizeof(HvacFullStatus)));
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D5F, (uint8_t*)&ac_status, USER_DATA_SIZE));
return haier_protocol::HandlerError::HANDLER_OK;
default:
if ((subcommand & 0xFF00) == (uint16_t)SubcommandsControl::SET_SINGLE_PARAMETER) {
Expand Down Expand Up @@ -308,7 +323,10 @@ haier_protocol::HandlerError alarm_status_report_answer_handler(haier_protocol::
if (request_type == haier_protocol::FrameType::ALARM_STATUS) {
if (message_type == haier_protocol::FrameType::CONFIRM) {
if (data_size == 0) {
alarm_paused = true;
if (!has_active_alarms())
alarm_stopped = true;
else
alarm_paused = true;
return haier_protocol::HandlerError::HANDLER_OK;
}
else
Expand Down Expand Up @@ -422,7 +440,7 @@ haier_protocol::HandlerError process_single_parameter(haier_protocol::ProtocolHa
break;
}
if (result == haier_protocol::HandlerError::HANDLER_OK) {
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D01, (uint8_t*)&ac_status, sizeof(HvacFullStatus)));
protocol_handler->send_answer(haier_protocol::HaierMessage(haier_protocol::FrameType::STATUS, 0x6D01, (uint8_t*)&ac_status, USER_DATA_SIZE));
}
else {
protocol_handler->send_answer(INVALID_MSG);
Expand Down
6 changes: 6 additions & 0 deletions tools/utils/hon_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
struct HvacFullStatus {
esphome::haier::hon_protocol::HaierPacketControl control;
esphome::haier::hon_protocol::HaierPacketSensors sensors;
uint8_t spare[4];
esphome::haier::hon_protocol::HaierPacketBigData big_data;
};

constexpr size_t ALARM_BUF_SIZE = 8;

constexpr size_t USER_DATA_SIZE = sizeof(esphome::haier::hon_protocol::HaierPacketControl) + sizeof(esphome::haier::hon_protocol::HaierPacketSensors);

constexpr size_t BIG_DATA_SIZE = sizeof(HvacFullStatus);

void process_alarms(haier_protocol::ProtocolHandler* protocol_handler);

HvacFullStatus& get_ac_state_ref();
Expand Down

0 comments on commit eda897a

Please sign in to comment.