diff --git a/src/config.cpp b/src/config.cpp index 42f39c8f4..ddc323a86 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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); } @@ -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; +} diff --git a/src/config.h b/src/config.h index b6d0dc1b9..8902a5098 100644 --- a/src/config.h +++ b/src/config.h @@ -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; @@ -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 diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 4ec0ad08a..3a6ac5c3a 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -2276,6 +2276,8 @@ void CMiniDexed::UpdateNetwork() CString IPString; m_pNet->GetConfig()->GetIPAddress()->Format(&IPString); + m_UI.InitUDP (); + if (m_UDPMIDI) { m_UDPMIDI->Initialize(); @@ -2339,6 +2341,7 @@ void CMiniDexed::UpdateNetwork() { LOGNOTE ("Syslog server is not enabled in configuration"); } + m_bNetworkReady = true; } diff --git a/src/net/ftpworker.cpp b/src/net/ftpworker.cpp index a19cfde04..34c65223a 100644 --- a/src/net/ftpworker.cpp +++ b/src/net/ftpworker.cpp @@ -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; diff --git a/src/userinterface.cpp b/src/userinterface.cpp index 43a94ff46..57b8cd464 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include LOGMODULE ("ui"); @@ -50,6 +52,44 @@ CUserInterface::~CUserInterface (void) delete m_pLCD; } +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); @@ -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 @@ -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); @@ -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) { @@ -274,6 +316,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const } LCDWrite (Msg); + UDPWrite (Msg); } void CUserInterface::LCDWrite (const char *pString) @@ -284,6 +327,18 @@ void CUserInterface::LCDWrite (const char *pString) } } +void CUserInterface::UDPWrite (const char *pString) +{ + 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) diff --git a/src/userinterface.h b/src/userinterface.h index 6290d865b..91df87216 100644 --- a/src/userinterface.h +++ b/src/userinterface.h @@ -31,6 +31,8 @@ #include #include #include +#include +#include class CMiniDexed; @@ -42,6 +44,8 @@ class CUserInterface bool Initialize (void); + bool InitUDP (void); + void Process (void); void ParameterChanged (void); @@ -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); @@ -89,6 +94,10 @@ class CUserInterface bool m_bSwitchPressed; CUIMenu m_Menu; + + CSocket* m_pUDPSendSocket = nullptr; + CIPAddress m_UDPDestAddress; + unsigned m_UDPDestPort = 1306; }; #endif