Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ void CConfig::Load (void)
if (const u8 *pIP = m_Properties.GetIPAddress ("NetworkSyslogServerIPAddress")) m_INetworkSyslogServerIPAddress.Set (pIP);
m_bUDPMIDIEnabled = m_Properties.GetNumber("UDPMIDIEnabled", 0) != 0;
if (const u8 *pIP = m_Properties.GetIPAddress("UDPMIDIIPAddress")) m_IUDPMIDIIPAddress.Set (pIP);
m_bUDPDisplayEnabled = m_Properties.GetNumber("UDPDisplayEnabled", 0) != 0;
if (const u8 *pIP = m_Properties.GetIPAddress("UDPDisplayIPAddress")) m_IUDPDisplayIPAddress.Set (pIP);

m_nMasterVolume = m_Properties.GetNumber ("MasterVolume", 64);
}
Expand Down Expand Up @@ -848,3 +850,13 @@ const CIPAddress& CConfig::GetUDPMIDIIPAddress (void) const
{
return m_IUDPMIDIIPAddress;
}

bool CConfig::GetUDPDisplayEnabled (void) const
{
return m_bUDPDisplayEnabled;
}

const CIPAddress& CConfig::GetUDPDisplayIPAddress (void) const
{
return m_IUDPDisplayIPAddress;
}
4 changes: 4 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class CConfig // Configuration for MiniDexed
bool GetNetworkFTPEnabled (void) const;
bool GetUDPMIDIEnabled (void) const;
const CIPAddress& GetUDPMIDIIPAddress (void) const;
bool GetUDPDisplayEnabled (void) const;
const CIPAddress& GetUDPDisplayIPAddress (void) const;

private:
CPropertiesFatFsFile m_Properties;
Expand Down Expand Up @@ -396,6 +398,8 @@ class CConfig // Configuration for MiniDexed
bool m_bNetworkFTPEnabled;
bool m_bUDPMIDIEnabled;
CIPAddress m_IUDPMIDIIPAddress;
bool m_bUDPDisplayEnabled;
CIPAddress m_IUDPDisplayIPAddress;
};

#endif
3 changes: 3 additions & 0 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,8 @@ void CMiniDexed::UpdateNetwork()
CString IPString;
m_pNet->GetConfig()->GetIPAddress()->Format(&IPString);

m_UI.InitUDP ();

if (m_UDPMIDI)
{
m_UDPMIDI->Initialize();
Expand Down Expand Up @@ -2339,6 +2341,7 @@ void CMiniDexed::UpdateNetwork()
{
LOGNOTE ("Syslog server is not enabled in configuration");
}

m_bNetworkReady = true;
}

Expand Down
10 changes: 9 additions & 1 deletion src/net/ftpworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,15 @@ bool CFTPWorker::RenameTo(const char* pArgs)

bool CFTPWorker::Bye(const char* pArgs)
{
SendStatus(TFTPStatus::ClosingControl, "Goodbye.");
if (!CheckLoggedIn())
{
SendStatus(TFTPStatus::ClosingControl, "Goodbye.");
delete m_pControlSocket;
m_pControlSocket = nullptr;
return true;
}

SendStatus(TFTPStatus::ClosingControl, "Goodbye. Rebooting");
delete m_pControlSocket;
m_pControlSocket = nullptr;

Expand Down
57 changes: 56 additions & 1 deletion src/userinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <circle/startup.h>
#include <string.h>
#include <assert.h>
#include <circle/net/netsubsystem.h>
#include <circle/net/in.h>

LOGMODULE ("ui");

Expand All @@ -50,6 +52,44 @@ CUserInterface::~CUserInterface (void)
delete m_pLCD;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The UDP socket allocated in InitUDP is not released in the destructor, leading to a leak.

Please also delete m_pUDPSendSocket in the destructor (with a null check if needed) so the UDP socket is properly released.

}

bool CUserInterface::InitUDP (void)
{

if (!m_pConfig->GetUDPDisplayEnabled())
{
LOGNOTE("UDP display disabled");
return TRUE;
}

// UDP Display send socket setup (default: broadcast 255.255.255.255:1306)
m_UDPDestAddress.Set(0xFFFFFFFF); // Broadcast by default
m_UDPDestPort = 1306;
if (m_pConfig->GetUDPDisplayIPAddress().IsSet())
{
m_UDPDestAddress.Set( m_pConfig->GetUDPDisplayIPAddress() );
}
CString IPAddressString;
m_UDPDestAddress.Format(&IPAddressString);
// address 0.0.0.0 also disables udp display
if (!m_UDPDestAddress.IsNull())
{
CNetSubSystem* pNet = CNetSubSystem::Get();
m_pUDPSendSocket = new CSocket(pNet, IPPROTO_UDP);
m_pUDPSendSocket->Connect(m_UDPDestAddress, m_UDPDestPort);
m_pUDPSendSocket->SetOptionBroadcast(TRUE);
LOGNOTE("UDP display initialized. target is %s",
(const char*)IPAddressString);
UDPWrite ("\x1B[H\x1B[J"); // cursor home and clear screen
UDPWrite ("\x1B[?25l\x1B""d+"); // cursor off, autopage mode
UDPWrite ("MiniDexed\nLoading...");
}
else
LOGNOTE("UDP display disabled. target was %s",
(const char*)IPAddressString);

return TRUE;
}

bool CUserInterface::Initialize (void)
{
assert (m_pConfig);
Expand Down Expand Up @@ -152,6 +192,7 @@ bool CUserInterface::Initialize (void)
}
assert (m_pLCD);


m_pLCDBuffered = new CWriteBufferDevice (m_pLCD);
assert (m_pLCDBuffered);
// clear sceen and go to top left corner
Expand Down Expand Up @@ -228,7 +269,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const
assert (pParam);
assert (pValue);

CString Msg ("\x1B[H\E[?25l"); // cursor home and off
CString Msg ("\x1B[H\E[?25l"); // cursor home and off

// first line
Msg.Append (pParam);
Expand All @@ -245,6 +286,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const
Msg.Append (pMenu);

// second line
Msg.Append ("\x1B[2;1H"); // cursor to row 2 column 1
CString Value (" ");
if (bArrowDown)
{
Expand Down Expand Up @@ -274,6 +316,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const
}

LCDWrite (Msg);
UDPWrite (Msg);
}

void CUserInterface::LCDWrite (const char *pString)
Expand All @@ -284,6 +327,18 @@ void CUserInterface::LCDWrite (const char *pString)
}
}

void CUserInterface::UDPWrite (const char *pString)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (bug_risk): UDPWrite re-computes strlen and uses %u with a size_t value, which can be tightened up.

Two small tweaks:

  • Cache strlen(pString) in a local size_t len and reuse it for both SendTo and logging.
  • Since strlen returns size_t, use %zu in the log (or cast to unsigned) to avoid a type/format mismatch on some platforms.

{
if (m_pUDPSendSocket) {
int res = m_pUDPSendSocket->SendTo(pString, strlen(pString), 0, m_UDPDestAddress, m_UDPDestPort);
if (res < 0) {
LOGERR("Failed to send %u bytes to UDP display", strlen(pString));
} else {
// LOGDBG("Sent %u bytes to UDP display", strlen(pString));
}
}
}

void CUserInterface::EncoderEventHandler (CKY040::TEvent Event)
{
switch (Event)
Expand Down
9 changes: 9 additions & 0 deletions src/userinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <circle/writebuffer.h>
#include <circle/i2cmaster.h>
#include <circle/spimaster.h>
#include <circle/net/ipaddress.h>
#include <circle/net/socket.h>

class CMiniDexed;

Expand All @@ -42,6 +44,8 @@ class CUserInterface

bool Initialize (void);

bool InitUDP (void);

void Process (void);

void ParameterChanged (void);
Expand All @@ -60,6 +64,7 @@ class CUserInterface

private:
void LCDWrite (const char *pString); // Print to optional HD44780 display
void UDPWrite (const char *pString); // Print to optional HD44780 display

void EncoderEventHandler (CKY040::TEvent Event);
static void EncoderEventStub (CKY040::TEvent Event, void *pParam);
Expand Down Expand Up @@ -89,6 +94,10 @@ class CUserInterface
bool m_bSwitchPressed;

CUIMenu m_Menu;

CSocket* m_pUDPSendSocket = nullptr;
CIPAddress m_UDPDestAddress;
unsigned m_UDPDestPort = 1306;
};

#endif
Loading