-
Notifications
You must be signed in to change notification settings - Fork 126
WIP: UI can be sent over udp #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
penfold42
wants to merge
3
commits into
probonopd:main
Choose a base branch
from
penfold42:ui-udp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"); | ||
|
|
||
|
|
@@ -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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (bug_risk): UDPWrite re-computes strlen and uses Two small tweaks:
|
||
| { | ||
| 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) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_pUDPSendSocketin the destructor (with a null check if needed) so the UDP socket is properly released.