This commit is contained in:
2023-08-21 20:26:38 +02:00
commit 9a4a8c2a7d
33 changed files with 5782 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
#include "udp_logger.h"
UDPLogger::UDPLogger()
{
}
UDPLogger::UDPLogger(IPAddress interface_addr, IPAddress multicast_addr, int port, String name)
{
_interfaceAddr = interface_addr;
_multicastAddr = multicast_addr;
_name = name;
_port = port;
_udp.beginMulticast(_interfaceAddr, _multicastAddr, _port);
}
void UDPLogger::set_name(String name)
{
_name = name;
}
void UDPLogger::log_string(String message)
{
// wait 5 milliseconds if last send was less than 5 milliseconds before
if (millis() < (_lastSend + 5))
{
delay(5);
}
message = _name + ": " + message;
Serial.println(message);
_udp.beginPacketMulticast(_multicastAddr, _port, _interfaceAddr);
message.toCharArray(_packetBuffer, 100);
_udp.print(_packetBuffer);
_udp.endPacket();
_lastSend = millis();
}
void UDPLogger::log_color_24bit(uint32_t color)
{
uint8_t result_red = color >> 16 & 0xff;
uint8_t result_green = color >> 8 & 0xff;
uint8_t result_blue = color & 0xff;
log_string(String(result_red) + ", " + String(result_green) + ", " + String(result_blue));
}