Refactor some logging

This commit is contained in:
Theo Arends 2022-11-11 14:34:58 +01:00
parent 3d6bc2f842
commit 9b64c4eb4c
7 changed files with 16 additions and 22 deletions

View File

@ -2750,15 +2750,13 @@ void AddLog(uint32_t loglevel, PGM_P formatP, ...) {
}
}
void AddLogBuffer(uint32_t loglevel, uint8_t *buffer, uint32_t count)
{
void AddLogBuffer(uint32_t loglevel, uint8_t *buffer, uint32_t count) {
char hex_char[(count * 3) + 2];
AddLog(loglevel, PSTR("DMP: %s"), ToHex_P(buffer, count, hex_char, sizeof(hex_char), ' '));
}
void AddLogSerial(uint32_t loglevel)
{
AddLogBuffer(loglevel, (uint8_t*)TasmotaGlobal.serial_in_buffer, TasmotaGlobal.serial_in_byte_counter);
void AddLogSerial() {
AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)TasmotaGlobal.serial_in_buffer, TasmotaGlobal.serial_in_byte_counter);
}
void AddLogMissed(const char *sensor, uint32_t misses)

View File

@ -197,7 +197,7 @@ void SonoffBridgeReceived(void)
char rfkey[8];
char stemp[16];
AddLogSerial(LOG_LEVEL_DEBUG);
AddLogSerial();
if (0xA2 == TasmotaGlobal.serial_in_buffer[0]) { // Learn timeout
SonoffBridgeLearnFailed();

View File

@ -174,7 +174,7 @@ bool SonoffIfanSerialInput(void)
// AA 55 01 04 00 01 04 0A - Light
// AA 55 01 06 00 01 01 09 - Buzzer
// AA 55 01 07 00 01 01 0A - Rf long press - forget RF codes
AddLogSerial(LOG_LEVEL_DEBUG);
AddLogSerial();
uint8_t crc = 0;
for (uint32_t i = 2; i < 7; i++) {
crc += TasmotaGlobal.serial_in_buffer[i];
@ -244,8 +244,7 @@ void SonoffIfanUpdate(void)
* Interface
\*********************************************************************************************/
bool Xdrv22(uint32_t function)
{
bool Xdrv22(uint32_t function) {
bool result = false;
if (IsModuleIfan()) {

View File

@ -99,7 +99,7 @@ bool SonoffD1SerialInput(void)
// aa 55 01 04 00 0a 00 64 ff ff ff ff ff ff ff ff 6b - Power Off (with last dimmer 100%)
// aa 55 01 04 00 0a 01 64 ff ff ff ff ff ff ff ff 6c - Power On (with last dimmer 100%)
AddLogSerial(LOG_LEVEL_DEBUG);
AddLogSerial();
uint8_t crc = 0;
for (uint32_t i = 2; i < SnfD1.receive_len -1; i++) {
crc += TasmotaGlobal.serial_in_buffer[i];

View File

@ -614,7 +614,7 @@ bool CLLFlashFirmware(uint8_t* data, uint32_t size)
uint32_t block = 0;
unsigned int addr = 0x0000;
AddLog(LOG_LEVEL_INFO,PSTR("CCL: will flash ...."));
AddLog(LOG_LEVEL_DEBUG,PSTR("CCL: data %16_H"), data); // quick check to compare with a hex editor
AddLogBuffer(LOG_LEVEL_DEBUG,data,16); // quick check to compare with a hex editor
while((block*512)<size)
{

View File

@ -452,11 +452,9 @@ void MESHevery50MSecond(void) {
// // pass the packets
// }
if (MESH.packetToConsume.size() > 0) {
// AddLog(LOG_LEVEL_DEBUG, PSTR("_"));
// AddLogBuffer(LOG_LEVEL_DEBUG,(uint8_t *)&MESH.packetToConsume.front(), 15);
// AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: _ %15_H"), (uint8_t *)&MESH.packetToConsume.front());
for (auto &_headerBytes : MESH.packetsAlreadyReceived) {
// AddLog(LOG_LEVEL_DEBUG, PSTR("."));
// AddLogBuffer(LOG_LEVEL_DEBUG,(uint8_t *)_headerBytes.raw, 15);
// AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: . %15_H"), (uint8_t *)_headerBytes.raw);
if (memcmp(MESH.packetToConsume.front().sender, _headerBytes.raw, 15) == 0) {
MESH.packetToConsume.pop();
return;
@ -465,21 +463,20 @@ void MESHevery50MSecond(void) {
mesh_first_header_bytes _bytes;
memcpy(_bytes.raw, &MESH.packetToConsume.front(), 15);
MESH.packetsAlreadyReceived.push_back(_bytes);
// AddLog(LOG_LEVEL_DEBUG, PSTR("..."));
// AddLogBuffer(LOG_LEVEL_DEBUG,(uint8_t *)_bytes.raw, 15);
// AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: ... %15_H"), (uint8_t *)_bytes.raw);
if (MESH.packetsAlreadyReceived.size() > MESH_MAX_PACKETS) {
MESH.packetsAlreadyReceived.erase(MESH.packetsAlreadyReceived.begin());
// AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: Erase received data"));
}
// do something on the node
// AddLogBuffer(LOG_LEVEL_DEBUG,(uint8_t *)&MESH.packetToConsume.front(), 30);
// AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: %30_H), (uint8_t *)&MESH.packetToConsume.front());
MESHencryptPayload(&MESH.packetToConsume.front(), 0);
switch (MESH.packetToConsume.front().type) {
// case PACKET_TYPE_REGISTER_NODE:
// AddLog(LOG_LEVEL_INFO, PSTR("MSH: received topic: %s"), (char*)MESH.packetToConsume.front().payload + 6);
// // AddLogBuffer(LOG_LEVEL_INFO,(uint8_t *)&MESH.packetToConsume.front().payload,MESH.packetToConsume.front().chunkSize+5);
// // AddLog(LOG_LEVEL_INFO, PSTR("MSH: %*_H), MESH.packetToConsume.front().chunkSize+5, (uint8_t *)&MESH.packetToConsume.front().payload);
// for(auto &_peer : MESH.peers){
// if(memcmp(_peer.MAC,MESH.packetToConsume.front().sender,6)==0){
// strcpy(_peer.topic,(char*)MESH.packetToConsume.front().payload+6);
@ -532,7 +529,7 @@ void MESHevery50MSecond(void) {
}
} else {
// AddLog(LOG_LEVEL_INFO, PSTR("MSH: chunk: %u size: %u"), MESH.packetToConsume.front().chunk, MESH.packetToConsume.front().chunkSize);
// if (MESH.packetToConsume.front().chunk==0) AddLogBuffer(LOG_LEVEL_INFO,(uint8_t *)&MESH.packetToConsume.front().payload,MESH.packetToConsume.front().chunkSize);
// if (MESH.packetToConsume.front().chunk==0) AddLog(LOG_LEVEL_INFO, PSTR("MSH: %*_H), MESH.packetToConsume.front().chunkSize, (uint8_t *)&MESH.packetToConsume.front().payload);
char * _data = (char*)MESH.packetToConsume.front().payload + strlen((char*)MESH.packetToConsume.front().payload) +1;
// AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: Publish packet"));
MqttPublishPayload((char*)MESH.packetToConsume.front().payload, _data);
@ -546,7 +543,7 @@ void MESHevery50MSecond(void) {
}
idx++;
}
// AddLogBuffer(LOG_LEVEL_INFO,(uint8_t *)&MESH.packetToConsume.front().payload,MESH.packetToConsume.front().chunkSize);
// AddLog(LOG_LEVEL_INFO, PSTR("MSH: %*_H), MESH.packetToConsume.front().chunkSize, (uint8_t *)&MESH.packetToConsume.front().payload);
}
break;
default:

View File

@ -64,7 +64,7 @@ bool VindriktningReadData(void) {
VindriktningSerial->readBytes(buffer, VINDRIKTNING_DATASET_SIZE);
VindriktningSerial->flush(); // Make room for another burst
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("VDN: %*_H"), VINDRIKTNING_DATASET_SIZE, buffer);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, VINDRIKTNING_DATASET_SIZE);
uint8_t crc = 0;
for (uint32_t i = 0; i < VINDRIKTNING_DATASET_SIZE; i++) {