Feature: UdpLog configurable. Fix: Avoid overflow error on big udp log messages.

This commit is contained in:
uhi22 2023-05-24 21:05:41 +02:00
parent 8cef89595b
commit 5c82af5dad
2 changed files with 18 additions and 2 deletions

View file

@ -88,4 +88,9 @@ exit_on_session_end = False
# Possible values: # Possible values:
# No: No testcases are executed. Normal function as Evse or Pev. # No: No testcases are executed. Normal function as Evse or Pev.
# Yes: Testcases are executed. The EvseMode will produce various errors for fault injection tests. # Yes: Testcases are executed. The EvseMode will produce various errors for fault injection tests.
testsuite_enable = Yes testsuite_enable = No
# Logging to UDP Syslog messages
# If this is activated, the pyPlc will send all logging messages also to the network interface,
# in form of UDP Syslog messages. For details see in udplog.py.
udp_syslog_enable = Yes

View file

@ -2,6 +2,7 @@
# This module "prints" log messages to UDP broadcasts to port 514. # This module "prints" log messages to UDP broadcasts to port 514.
from helpers import prettyMac from helpers import prettyMac
from configmodule import getConfigValue, getConfigValueBool
class udplog(): class udplog():
def fillMac(self, macbytearray, position=6): # position 6 is the source MAC def fillMac(self, macbytearray, position=6): # position 6 is the source MAC
@ -18,9 +19,14 @@ class udplog():
# Severity = 7 = "debug" # Severity = 7 = "debug"
# print("[UDPLOG] Logging " + s) # print("[UDPLOG] Logging " + s)
if (purpose==""): if (purpose==""):
return # here we filter, which kind of infos we want to provide to the UDP logging. if (not self.isUpdSyslogEnabled):
# If no special purpose, and the logging is disabled, we stop here.
return
# Logging is not suppressed, so continue to construct the message:
strLevel="<15>" strLevel="<15>"
# The String to be logged. Terminated by 00. # The String to be logged. Terminated by 00.
if (len(s)>700):
s = s[0:700] # Limit the length. Too long messages crash the transmit. Todo: Find out the real limit.
strMessage=s+"\0" strMessage=s+"\0"
lenPayLoad = 4 + len(strMessage) # length of level is 4 lenPayLoad = 4 + len(strMessage) # length of level is 4
@ -98,6 +104,11 @@ class udplog():
self.addressManager = addressManager self.addressManager = addressManager
self.ownMac = self.addressManager.getLocalMacAddress() self.ownMac = self.addressManager.getLocalMacAddress()
print("udplog started with ownMac " + prettyMac(self.ownMac)) print("udplog started with ownMac " + prettyMac(self.ownMac))
self.isUpdSyslogEnabled = getConfigValueBool("udp_syslog_enable")
if (self.isUpdSyslogEnabled):
print("logging to UDP Syslog is enabled")
else:
print("logging to UDP Syslog is disabled")
def udplog_init(transmitCallback, addressManager): def udplog_init(transmitCallback, addressManager):
global udplogger global udplogger