mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-11 09:20:34 +01:00
Hoymiles Lib: Replace lot of println by printf
This commit is contained in:
@@ -81,7 +81,7 @@ void HoymilesClass::loop()
|
||||
// Fetch limit
|
||||
if (((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
|
||||
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
|
||||
_messageOutput->println("Request SystemConfigPara");
|
||||
_messageOutput->printf("Request SystemConfigPara\r\n");
|
||||
iv->sendSystemConfigParaRequest();
|
||||
}
|
||||
|
||||
@@ -97,13 +97,13 @@ void HoymilesClass::loop()
|
||||
&& iv->DevInfo()->getLastUpdateSimple() > 0;
|
||||
|
||||
if (invalidDevInfo) {
|
||||
_messageOutput->println("DevInfo: No Valid Data");
|
||||
_messageOutput->printf("DevInfo: No Valid Data\r\n");
|
||||
}
|
||||
|
||||
if ((iv->DevInfo()->getLastUpdateAll() == 0)
|
||||
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|
||||
|| invalidDevInfo) {
|
||||
_messageOutput->println("Request device info");
|
||||
_messageOutput->printf("Request device info\r\n");
|
||||
iv->sendDevInfoRequest();
|
||||
}
|
||||
}
|
||||
@@ -111,13 +111,13 @@ void HoymilesClass::loop()
|
||||
|
||||
// Set limit if required
|
||||
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
|
||||
_messageOutput->println("Resend ActivePowerControl");
|
||||
_messageOutput->printf("Resend ActivePowerControl\r\n");
|
||||
iv->resendActivePowerControlRequest();
|
||||
}
|
||||
|
||||
// Set power status if required
|
||||
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
|
||||
_messageOutput->println("Resend PowerCommand");
|
||||
_messageOutput->printf("Resend PowerCommand\r\n");
|
||||
iv->resendPowerControlRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,18 +54,18 @@ void HoymilesRadio::sendLastPacketAgain()
|
||||
void HoymilesRadio::handleReceivedPackage()
|
||||
{
|
||||
if (_busyFlag && _rxTimeout.occured()) {
|
||||
Hoymiles.getMessageOutput()->println("RX Period End");
|
||||
Hoymiles.getMessageOutput()->printf("RX Period End\r\n");
|
||||
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterBySerial(_commandQueue.front().get()->getTargetAddress());
|
||||
|
||||
if (nullptr != inv) {
|
||||
CommandAbstract* cmd = _commandQueue.front().get();
|
||||
uint8_t verifyResult = inv->verifyAllFragments(*cmd);
|
||||
if (verifyResult == FRAGMENT_ALL_MISSING_RESEND) {
|
||||
Hoymiles.getMessageOutput()->println("Nothing received, resend whole request");
|
||||
Hoymiles.getMessageOutput()->printf("Nothing received, resend whole request\r\n");
|
||||
sendLastPacketAgain();
|
||||
|
||||
} else if (verifyResult == FRAGMENT_ALL_MISSING_TIMEOUT) {
|
||||
Hoymiles.getMessageOutput()->println("Nothing received, resend count exeeded");
|
||||
Hoymiles.getMessageOutput()->printf("Nothing received, resend count exeeded\r\n");
|
||||
// Statistics: Count RX Fail No Answer
|
||||
if (inv->RadioStats.TxRequestData > 0) {
|
||||
inv->RadioStats.RxFailNoAnswer++;
|
||||
@@ -75,7 +75,7 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
_busyFlag = false;
|
||||
|
||||
} else if (verifyResult == FRAGMENT_RETRANSMIT_TIMEOUT) {
|
||||
Hoymiles.getMessageOutput()->println("Retransmit timeout");
|
||||
Hoymiles.getMessageOutput()->printf("Retransmit timeout\r\n");
|
||||
// Statistics: Count RX Fail Partial Answer
|
||||
if (inv->RadioStats.TxRequestData > 0) {
|
||||
inv->RadioStats.RxFailPartialAnswer++;
|
||||
@@ -85,7 +85,7 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
_busyFlag = false;
|
||||
|
||||
} else if (verifyResult == FRAGMENT_HANDLE_ERROR) {
|
||||
Hoymiles.getMessageOutput()->println("Packet handling error");
|
||||
Hoymiles.getMessageOutput()->printf("Packet handling error\r\n");
|
||||
// Statistics: Count RX Fail Corrupt Data
|
||||
if (inv->RadioStats.TxRequestData > 0) {
|
||||
inv->RadioStats.RxFailCorruptData++;
|
||||
@@ -96,8 +96,7 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
|
||||
} else if (verifyResult > 0) {
|
||||
// Perform Retransmit
|
||||
Hoymiles.getMessageOutput()->print("Request retransmit: ");
|
||||
Hoymiles.getMessageOutput()->println(verifyResult);
|
||||
Hoymiles.getMessageOutput()->printf("Request retransmit: %" PRIu8 "\r\n", verifyResult);
|
||||
// Statistics: Count TX Re-Request Fragment
|
||||
inv->RadioStats.TxReRequestFragment++;
|
||||
|
||||
@@ -105,7 +104,7 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
|
||||
} else {
|
||||
// Successful received all packages
|
||||
Hoymiles.getMessageOutput()->println("Success");
|
||||
Hoymiles.getMessageOutput()->printf("Success\r\n");
|
||||
// Statistics: Count RX Success
|
||||
if (inv->RadioStats.TxRequestData > 0) {
|
||||
inv->RadioStats.RxSuccess++;
|
||||
@@ -116,7 +115,7 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
}
|
||||
} else {
|
||||
// If inverter was not found, assume the command is invalid
|
||||
Hoymiles.getMessageOutput()->println("RX: Invalid inverter found");
|
||||
Hoymiles.getMessageOutput()->printf("RX: Invalid inverter found\r\n");
|
||||
// Statistics: Count RX Fail Unknown Data
|
||||
_commandQueue.pop();
|
||||
_busyFlag = false;
|
||||
@@ -134,7 +133,7 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
|
||||
sendEsbPacket(*cmd);
|
||||
} else {
|
||||
Hoymiles.getMessageOutput()->println("TX: Invalid inverter found");
|
||||
Hoymiles.getMessageOutput()->printf("TX: Invalid inverter found\r\n");
|
||||
_commandQueue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,10 +95,10 @@ void HoymilesRadio_CMT::init(const int8_t pin_sdio, const int8_t pin_clk, const
|
||||
cmtSwitchDtuFreq(_inverterTargetFrequency); // start dtu at work freqency, for fast Rx if inverter is already on and frequency switched
|
||||
|
||||
if (!_radio->isChipConnected()) {
|
||||
Hoymiles.getMessageOutput()->println("CMT: Connection error!!");
|
||||
Hoymiles.getMessageOutput()->printf("CMT: Connection error!!\r\n");
|
||||
return;
|
||||
}
|
||||
Hoymiles.getMessageOutput()->println("CMT: Connection successful");
|
||||
Hoymiles.getMessageOutput()->printf("CMT: Connection successful\r\n");
|
||||
|
||||
if (pin_gpio2 >= 0) {
|
||||
attachInterrupt(digitalPinToInterrupt(pin_gpio2), std::bind(&HoymilesRadio_CMT::handleInt1, this), RISING);
|
||||
@@ -126,10 +126,10 @@ void HoymilesRadio_CMT::loop()
|
||||
}
|
||||
|
||||
if (_packetReceived) {
|
||||
Hoymiles.getMessageOutput()->println("Interrupt received");
|
||||
Hoymiles.getMessageOutput()->printf("Interrupt received\r\n");
|
||||
while (_radio->available()) {
|
||||
if (_rxBuffer.size() > FRAGMENT_BUFFER_SIZE) {
|
||||
Hoymiles.getMessageOutput()->println("CMT: Buffer full");
|
||||
Hoymiles.getMessageOutput()->printf("CMT: Buffer full\r\n");
|
||||
_radio->flush_rx();
|
||||
continue;
|
||||
}
|
||||
@@ -169,12 +169,12 @@ void HoymilesRadio_CMT::loop()
|
||||
|
||||
inv->addRxFragment(f.fragment, f.len, f.rssi);
|
||||
} else {
|
||||
Hoymiles.getMessageOutput()->println("Inverter Not found!");
|
||||
Hoymiles.getMessageOutput()->printf("Inverter Not found!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Hoymiles.getMessageOutput()->println("Frame kaputt"); // ;-)
|
||||
Hoymiles.getMessageOutput()->printf("Frame kaputt\r\n"); // ;-)
|
||||
}
|
||||
|
||||
// Remove paket from buffer even it was corrupted
|
||||
@@ -277,7 +277,7 @@ void HoymilesRadio_CMT::sendEsbPacket(CommandAbstract& cmd)
|
||||
cmd.dumpDataPayload(Hoymiles.getMessageOutput());
|
||||
|
||||
if (!_radio->write(cmd.getDataPayload(), cmd.getDataSize())) {
|
||||
Hoymiles.getMessageOutput()->println("TX SPI Timeout");
|
||||
Hoymiles.getMessageOutput()->printf("TX SPI Timeout\r\n");
|
||||
}
|
||||
cmtSwitchDtuFreq(_inverterTargetFrequency);
|
||||
_radio->startListening();
|
||||
|
||||
@@ -24,10 +24,10 @@ void HoymilesRadio_NRF::init(SPIClass* initialisedSpiBus, const uint8_t pinCE, c
|
||||
_radio->setRetries(0, 0);
|
||||
_radio->maskIRQ(true, true, false); // enable only receiving interrupts
|
||||
if (!_radio->isChipConnected()) {
|
||||
Hoymiles.getMessageOutput()->println("NRF: Connection error!!");
|
||||
Hoymiles.getMessageOutput()->printf("NRF: Connection error!!\r\n");
|
||||
return;
|
||||
}
|
||||
Hoymiles.getMessageOutput()->println("NRF: Connection successful");
|
||||
Hoymiles.getMessageOutput()->printf("NRF: Connection successful\r\n");
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(pinIRQ), std::bind(&HoymilesRadio_NRF::handleIntr, this), FALLING);
|
||||
|
||||
@@ -48,10 +48,10 @@ void HoymilesRadio_NRF::loop()
|
||||
}
|
||||
|
||||
if (_packetReceived) {
|
||||
Hoymiles.getMessageOutput()->println("Interrupt received");
|
||||
Hoymiles.getMessageOutput()->printf("Interrupt received\r\n");
|
||||
while (_radio->available()) {
|
||||
if (_rxBuffer.size() > FRAGMENT_BUFFER_SIZE) {
|
||||
Hoymiles.getMessageOutput()->println("NRF: Buffer full");
|
||||
Hoymiles.getMessageOutput()->printf("NRF: Buffer full\r\n");
|
||||
_radio->flush_rx();
|
||||
continue;
|
||||
}
|
||||
@@ -81,11 +81,11 @@ void HoymilesRadio_NRF::loop()
|
||||
|
||||
inv->addRxFragment(f.fragment, f.len, f.rssi);
|
||||
} else {
|
||||
Hoymiles.getMessageOutput()->println("Inverter Not found!");
|
||||
Hoymiles.getMessageOutput()->printf("Inverter Not found!\r\n");
|
||||
}
|
||||
|
||||
} else {
|
||||
Hoymiles.getMessageOutput()->println("Frame kaputt");
|
||||
Hoymiles.getMessageOutput()->printf("Frame kaputt\r\n");
|
||||
}
|
||||
|
||||
// Remove paket from buffer even it was corrupted
|
||||
|
||||
@@ -210,7 +210,7 @@ void InverterAbstract::addRxFragment(const uint8_t fragment[], const uint8_t len
|
||||
const uint8_t fragmentId = fragmentCount & 0b01111111; // fragmentId is 1 based
|
||||
|
||||
if (fragmentId == 0) {
|
||||
Hoymiles.getMessageOutput()->println("ERROR: fragment id zero received and ignored");
|
||||
Hoymiles.getMessageOutput()->printf("ERROR: fragment id zero received and ignored\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd)
|
||||
{
|
||||
// All missing
|
||||
if (_rxFragmentLastPacketId == 0) {
|
||||
Hoymiles.getMessageOutput()->println("All missing");
|
||||
Hoymiles.getMessageOutput()->printf("All missing\r\n");
|
||||
if (cmd.getSendCount() <= cmd.getMaxResendCount()) {
|
||||
return FRAGMENT_ALL_MISSING_RESEND;
|
||||
} else {
|
||||
@@ -250,7 +250,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd)
|
||||
|
||||
// Last fragment is missing (the one with 0x80)
|
||||
if (_rxFragmentMaxPacketId == 0) {
|
||||
Hoymiles.getMessageOutput()->println("Last missing");
|
||||
Hoymiles.getMessageOutput()->printf("Last missing\r\n");
|
||||
if (_rxFragmentRetransmitCnt++ < cmd.getMaxRetransmitCount()) {
|
||||
return _rxFragmentLastPacketId + 1;
|
||||
} else {
|
||||
@@ -262,7 +262,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd)
|
||||
// Middle fragment is missing
|
||||
for (uint8_t i = 0; i < _rxFragmentMaxPacketId - 1; i++) {
|
||||
if (!_rxFragmentBuffer[i].wasReceived) {
|
||||
Hoymiles.getMessageOutput()->println("Middle missing");
|
||||
Hoymiles.getMessageOutput()->printf("Middle missing\r\n");
|
||||
if (_rxFragmentRetransmitCnt++ < cmd.getMaxRetransmitCount()) {
|
||||
return i + 1;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user