mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-11 01:10:20 +01:00
Hoymiles Lib: Move array dumping methods in separate method
This commit is contained in:
@@ -140,16 +140,6 @@ void HoymilesRadio::handleReceivedPackage()
|
||||
}
|
||||
}
|
||||
|
||||
void HoymilesRadio::dumpBuf(const uint8_t buf[], const uint8_t len, const bool appendNewline)
|
||||
{
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
Hoymiles.getMessageOutput()->printf("%02X ", buf[i]);
|
||||
}
|
||||
if (appendNewline) {
|
||||
Hoymiles.getMessageOutput()->println("");
|
||||
}
|
||||
}
|
||||
|
||||
bool HoymilesRadio::isInitialized() const
|
||||
{
|
||||
return _isInitialized;
|
||||
|
||||
@@ -72,7 +72,6 @@ public:
|
||||
|
||||
protected:
|
||||
static serial_u convertSerialToRadioId(const serial_u serial);
|
||||
static void dumpBuf(const uint8_t buf[], const uint8_t len, const bool appendNewline = true);
|
||||
|
||||
bool checkFragmentCrc(const fragment_t& fragment) const;
|
||||
virtual void sendEsbPacket(CommandAbstract& cmd) = 0;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
#include "HoymilesRadio_CMT.h"
|
||||
#include "Hoymiles.h"
|
||||
#include "Utils.h"
|
||||
#include "crc.h"
|
||||
#include <FunctionalInterrupt.h>
|
||||
#include <frozen/map.h>
|
||||
@@ -163,9 +164,8 @@ void HoymilesRadio_CMT::loop()
|
||||
|
||||
if (nullptr != inv) {
|
||||
// Save packet in inverter rx buffer
|
||||
Hoymiles.getMessageOutput()->printf("RX %.2f MHz --> ", getFrequencyFromChannel(f.channel) / 1000000.0);
|
||||
dumpBuf(f.fragment, f.len, false);
|
||||
Hoymiles.getMessageOutput()->printf("| %" PRId8 " dBm\r\n", f.rssi);
|
||||
Hoymiles.getMessageOutput()->printf("RX %.2f MHz --> %s | %" PRId8 " dBm\r\n",
|
||||
getFrequencyFromChannel(f.channel) / 1000000.0, Utils::dumpArray(f.fragment, f.len).c_str(), f.rssi);
|
||||
|
||||
inv->addRxFragment(f.fragment, f.len, f.rssi);
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
#include "HoymilesRadio_NRF.h"
|
||||
#include "Hoymiles.h"
|
||||
#include "Utils.h"
|
||||
#include "commands/RequestFrameCommand.h"
|
||||
#include <Every.h>
|
||||
#include <FunctionalInterrupt.h>
|
||||
@@ -75,9 +76,8 @@ void HoymilesRadio_NRF::loop()
|
||||
|
||||
if (nullptr != inv) {
|
||||
// Save packet in inverter rx buffer
|
||||
Hoymiles.getMessageOutput()->printf("RX Channel: %" PRIu8 " --> ", f.channel);
|
||||
dumpBuf(f.fragment, f.len, false);
|
||||
Hoymiles.getMessageOutput()->printf("| %" PRId8 " dBm\r\n", f.rssi);
|
||||
Hoymiles.getMessageOutput()->printf("RX Channel: %" PRIu8 " --> %s | %" PRId8 " dBm\r\n",
|
||||
f.channel, Utils::dumpArray(f.fragment, f.len).c_str(), f.rssi);
|
||||
|
||||
inv->addRxFragment(f.fragment, f.len, f.rssi);
|
||||
} else {
|
||||
|
||||
@@ -19,3 +19,22 @@ bool Utils::getTimeAvailable()
|
||||
struct tm timeinfo;
|
||||
return getLocalTime(&timeinfo, 5);
|
||||
}
|
||||
|
||||
String Utils::dumpArray(const uint8_t data[], const uint8_t len)
|
||||
{
|
||||
if (len == 0) {
|
||||
return String();
|
||||
}
|
||||
|
||||
// Each byte needs 2 hex chars + 1 space (except last byte)
|
||||
String result;
|
||||
result.reserve(len * 3);
|
||||
|
||||
char buf[4]; // Buffer for single hex value + space + null
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
snprintf(buf, sizeof(buf), "%02X%s", data[i], (i < len - 1) ? " " : "");
|
||||
result += buf;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <WString.h>
|
||||
|
||||
class Utils {
|
||||
public:
|
||||
static uint8_t getWeekDay();
|
||||
static bool getTimeAvailable();
|
||||
static String dumpArray(const uint8_t buf[], const uint8_t len);
|
||||
};
|
||||
|
||||
@@ -27,6 +27,7 @@ Source Address: 80 12 23 04
|
||||
Target Addr Source Addr CRC8
|
||||
*/
|
||||
#include "CommandAbstract.h"
|
||||
#include "../Utils.h"
|
||||
#include "../inverters/InverterAbstract.h"
|
||||
#include "crc.h"
|
||||
#include <string.h>
|
||||
@@ -53,10 +54,7 @@ const uint8_t* CommandAbstract::getDataPayload()
|
||||
void CommandAbstract::dumpDataPayload(Print* stream)
|
||||
{
|
||||
const uint8_t* payload = getDataPayload();
|
||||
for (uint8_t i = 0; i < getDataSize(); i++) {
|
||||
stream->printf("%02X ", payload[i]);
|
||||
}
|
||||
stream->println("");
|
||||
stream->printf("%s\r\n", Utils::dumpArray(payload, getDataSize()).c_str());
|
||||
}
|
||||
|
||||
uint8_t CommandAbstract::getDataSize() const
|
||||
|
||||
Reference in New Issue
Block a user