Replace magic numbers by some constants

This commit is contained in:
Thomas Basler 2022-06-30 18:58:55 +02:00
parent 4859259248
commit 54b7673f1a
3 changed files with 31 additions and 16 deletions

View File

@ -85,7 +85,7 @@ void HoymilesRadio::loop()
if (nullptr != inv) { if (nullptr != inv) {
uint8_t verifyResult = inv->verifyAllFragments(); uint8_t verifyResult = inv->verifyAllFragments();
if (verifyResult == 255) { if (verifyResult == FRAGMENT_ALL_MISSING) {
if (currentTransaction.sendCount < MAX_RESEND_COUNT) { if (currentTransaction.sendCount < MAX_RESEND_COUNT) {
Serial.println(F("Nothing received, resend whole request")); Serial.println(F("Nothing received, resend whole request"));
sendLastPacketAgain(); sendLastPacketAgain();
@ -94,11 +94,11 @@ void HoymilesRadio::loop()
_busyFlag = false; _busyFlag = false;
} }
} else if (verifyResult == 254) { } else if (verifyResult == FRAGMENT_RETRANSMIT_TIMEOUT) {
Serial.println(F("Retransmit timeout")); Serial.println(F("Retransmit timeout"));
_busyFlag = false; _busyFlag = false;
} else if (verifyResult == 253) { } else if (verifyResult == FRAGMENT_CRC_ERROR) {
Serial.println(F("Packet CRC error")); Serial.println(F("Packet CRC error"));
_busyFlag = false; _busyFlag = false;

View File

@ -61,7 +61,7 @@ uint8_t InverterAbstract::verifyAllFragments()
// All missing // All missing
if (_rxFragmentLastPacketId == 0) { if (_rxFragmentLastPacketId == 0) {
Serial.println(F("All missing")); Serial.println(F("All missing"));
return 255; return FRAGMENT_ALL_MISSING;
} }
// Last fragment is missing (thte one with 0x80) // Last fragment is missing (thte one with 0x80)
@ -70,7 +70,7 @@ uint8_t InverterAbstract::verifyAllFragments()
if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) { if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) {
return _rxFragmentLastPacketId + 1; return _rxFragmentLastPacketId + 1;
} else { } else {
return 254; return FRAGMENT_RETRANSMIT_TIMEOUT;
} }
} }
@ -81,7 +81,7 @@ uint8_t InverterAbstract::verifyAllFragments()
if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) { if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) {
return i + 1; return i + 1;
} else { } else {
return 254; return FRAGMENT_RETRANSMIT_TIMEOUT;
} }
} }
} }
@ -101,7 +101,7 @@ uint8_t InverterAbstract::verifyAllFragments()
} }
if (crc != crcRcv) { if (crc != crcRcv) {
return 253; return FRAGMENT_CRC_ERROR;
} }
// todo: hier muss noch ein check bzgl. packet type usw rein (ist ja nicht alles statistik) // todo: hier muss noch ein check bzgl. packet type usw rein (ist ja nicht alles statistik)
@ -114,7 +114,7 @@ uint8_t InverterAbstract::verifyAllFragments()
} }
_lastStatsUpdate = millis(); _lastStatsUpdate = millis();
return 0; return FRAGMENT_OK;
} }
uint32_t InverterAbstract::getLastStatsUpdate() uint32_t InverterAbstract::getLastStatsUpdate()

View File

@ -8,18 +8,21 @@
#define MAX_NAME_LENGTH 32 #define MAX_NAME_LENGTH 32
// units // units
enum { UNIT_V = 0, enum {
UNIT_V = 0,
UNIT_A, UNIT_A,
UNIT_W, UNIT_W,
UNIT_WH, UNIT_WH,
UNIT_KWH, UNIT_KWH,
UNIT_HZ, UNIT_HZ,
UNIT_C, UNIT_C,
UNIT_PCT }; UNIT_PCT
};
const char* const units[] = { "V", "A", "W", "Wh", "kWh", "Hz", "°C", "%" }; const char* const units[] = { "V", "A", "W", "Wh", "kWh", "Hz", "°C", "%" };
// field types // field types
enum { FLD_UDC = 0, enum {
FLD_UDC = 0,
FLD_IDC, FLD_IDC,
FLD_PDC, FLD_PDC,
FLD_YD, FLD_YD,
@ -31,25 +34,37 @@ enum { FLD_UDC = 0,
FLD_T, FLD_T,
FLD_PCT, FLD_PCT,
FLD_EFF, FLD_EFF,
FLD_IRR }; FLD_IRR
};
const char* const fields[] = { "Voltage", "Current", "Power", "YieldDay", "YieldTotal", const char* const fields[] = { "Voltage", "Current", "Power", "YieldDay", "YieldTotal",
"Voltage", "Current", "Power", "Frequency", "Temperature", "PowerFactor", "Effiency", "Irradiation" }; "Voltage", "Current", "Power", "Frequency", "Temperature", "PowerFactor", "Effiency", "Irradiation" };
// indices to calculation functions, defined in hmInverter.h // indices to calculation functions, defined in hmInverter.h
enum { CALC_YT_CH0 = 0, enum {
CALC_YT_CH0 = 0,
CALC_YD_CH0, CALC_YD_CH0,
CALC_UDC_CH, CALC_UDC_CH,
CALC_PDC_CH0, CALC_PDC_CH0,
CALC_EFF_CH0, CALC_EFF_CH0,
CALC_IRR_CH }; CALC_IRR_CH
};
enum { CMD_CALC = 0xffff }; enum { CMD_CALC = 0xffff };
// CH0 is default channel (freq, ac, temp) // CH0 is default channel (freq, ac, temp)
enum { CH0 = 0, enum {
CH0 = 0,
CH1, CH1,
CH2, CH2,
CH3, CH3,
CH4 }; CH4
};
enum {
FRAGMENT_ALL_MISSING = 255,
FRAGMENT_RETRANSMIT_TIMEOUT = 254,
FRAGMENT_CRC_ERROR = 253,
FRAGMENT_OK = 0
};
typedef struct { typedef struct {
uint8_t fieldId; // field id uint8_t fieldId; // field id