Replace magic numbers by some constants
This commit is contained in:
parent
4859259248
commit
54b7673f1a
@ -85,7 +85,7 @@ void HoymilesRadio::loop()
|
||||
|
||||
if (nullptr != inv) {
|
||||
uint8_t verifyResult = inv->verifyAllFragments();
|
||||
if (verifyResult == 255) {
|
||||
if (verifyResult == FRAGMENT_ALL_MISSING) {
|
||||
if (currentTransaction.sendCount < MAX_RESEND_COUNT) {
|
||||
Serial.println(F("Nothing received, resend whole request"));
|
||||
sendLastPacketAgain();
|
||||
@ -94,11 +94,11 @@ void HoymilesRadio::loop()
|
||||
_busyFlag = false;
|
||||
}
|
||||
|
||||
} else if (verifyResult == 254) {
|
||||
} else if (verifyResult == FRAGMENT_RETRANSMIT_TIMEOUT) {
|
||||
Serial.println(F("Retransmit timeout"));
|
||||
_busyFlag = false;
|
||||
|
||||
} else if (verifyResult == 253) {
|
||||
} else if (verifyResult == FRAGMENT_CRC_ERROR) {
|
||||
Serial.println(F("Packet CRC error"));
|
||||
_busyFlag = false;
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ uint8_t InverterAbstract::verifyAllFragments()
|
||||
// All missing
|
||||
if (_rxFragmentLastPacketId == 0) {
|
||||
Serial.println(F("All missing"));
|
||||
return 255;
|
||||
return FRAGMENT_ALL_MISSING;
|
||||
}
|
||||
|
||||
// Last fragment is missing (thte one with 0x80)
|
||||
@ -70,7 +70,7 @@ uint8_t InverterAbstract::verifyAllFragments()
|
||||
if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) {
|
||||
return _rxFragmentLastPacketId + 1;
|
||||
} else {
|
||||
return 254;
|
||||
return FRAGMENT_RETRANSMIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ uint8_t InverterAbstract::verifyAllFragments()
|
||||
if (_rxFragmentRetransmitCnt++ < MAX_RETRANSMIT_COUNT) {
|
||||
return i + 1;
|
||||
} else {
|
||||
return 254;
|
||||
return FRAGMENT_RETRANSMIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,7 +101,7 @@ uint8_t InverterAbstract::verifyAllFragments()
|
||||
}
|
||||
|
||||
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)
|
||||
@ -114,7 +114,7 @@ uint8_t InverterAbstract::verifyAllFragments()
|
||||
}
|
||||
_lastStatsUpdate = millis();
|
||||
|
||||
return 0;
|
||||
return FRAGMENT_OK;
|
||||
}
|
||||
|
||||
uint32_t InverterAbstract::getLastStatsUpdate()
|
||||
|
||||
@ -8,18 +8,21 @@
|
||||
#define MAX_NAME_LENGTH 32
|
||||
|
||||
// units
|
||||
enum { UNIT_V = 0,
|
||||
enum {
|
||||
UNIT_V = 0,
|
||||
UNIT_A,
|
||||
UNIT_W,
|
||||
UNIT_WH,
|
||||
UNIT_KWH,
|
||||
UNIT_HZ,
|
||||
UNIT_C,
|
||||
UNIT_PCT };
|
||||
UNIT_PCT
|
||||
};
|
||||
const char* const units[] = { "V", "A", "W", "Wh", "kWh", "Hz", "°C", "%" };
|
||||
|
||||
// field types
|
||||
enum { FLD_UDC = 0,
|
||||
enum {
|
||||
FLD_UDC = 0,
|
||||
FLD_IDC,
|
||||
FLD_PDC,
|
||||
FLD_YD,
|
||||
@ -31,25 +34,37 @@ enum { FLD_UDC = 0,
|
||||
FLD_T,
|
||||
FLD_PCT,
|
||||
FLD_EFF,
|
||||
FLD_IRR };
|
||||
FLD_IRR
|
||||
};
|
||||
const char* const fields[] = { "Voltage", "Current", "Power", "YieldDay", "YieldTotal",
|
||||
"Voltage", "Current", "Power", "Frequency", "Temperature", "PowerFactor", "Effiency", "Irradiation" };
|
||||
|
||||
// indices to calculation functions, defined in hmInverter.h
|
||||
enum { CALC_YT_CH0 = 0,
|
||||
enum {
|
||||
CALC_YT_CH0 = 0,
|
||||
CALC_YD_CH0,
|
||||
CALC_UDC_CH,
|
||||
CALC_PDC_CH0,
|
||||
CALC_EFF_CH0,
|
||||
CALC_IRR_CH };
|
||||
CALC_IRR_CH
|
||||
};
|
||||
enum { CMD_CALC = 0xffff };
|
||||
|
||||
// CH0 is default channel (freq, ac, temp)
|
||||
enum { CH0 = 0,
|
||||
enum {
|
||||
CH0 = 0,
|
||||
CH1,
|
||||
CH2,
|
||||
CH3,
|
||||
CH4 };
|
||||
CH4
|
||||
};
|
||||
|
||||
enum {
|
||||
FRAGMENT_ALL_MISSING = 255,
|
||||
FRAGMENT_RETRANSMIT_TIMEOUT = 254,
|
||||
FRAGMENT_CRC_ERROR = 253,
|
||||
FRAGMENT_OK = 0
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t fieldId; // field id
|
||||
|
||||
Loading…
Reference in New Issue
Block a user