From d567eb3fddf84f54b273c5efcb9deec4e30f96e0 Mon Sep 17 00:00:00 2001 From: Rodrigo Alfonso Date: Wed, 22 Jan 2025 20:59:46 -0300 Subject: [PATCH] Renaming AcceptConnections => PollConnections --- README.md | 4 ++-- docs/wireless_adapter.md | 16 ++++++++-------- .../src/scenes/DebugScene.cpp | 8 ++++---- lib/LinkRawWireless.hpp | 14 +++++++------- lib/LinkWireless.hpp | 2 +- lib/LinkWirelessMultiboot.hpp | 9 ++++----- lib/c_bindings/C_LinkRawWireless.cpp | 12 ++++++------ lib/c_bindings/C_LinkRawWireless.h | 8 ++++---- 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 3d8ddaa..b030be9 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ This version is simpler and blocks the system thread until completion. It doesn' ## Async version -This version (`LinkCableMultiboot::Async`) allows more advanced use cases like displaying animations and/or audio during the transfers, probing the connections and marking the transfer as 'ready' to start. It requires adding the provided interrupt service routines. +This version (`LinkCableMultiboot::Async`) allows more advanced use cases like playing animations and/or audio during the transfers, probing the connections and marking the transfer as 'ready' to start. It requires adding the provided interrupt service routines. ### Compile-time constants @@ -333,7 +333,7 @@ https://github.com/afska/gba-link-connection/assets/1631752/9a648bff-b14f-4a85-9 - `startHost` = `0x19` - `getSignalLevel` = `0x11` - `getSlotStatus` = `0x14` - - `acceptConnections` = `0x1A` + - `pollConnections` = `0x1A` - `endHost` = `0x1B` - `broadcastReadStart` = `0x1C` - `broadcastReadPoll` = `0x1D` diff --git a/docs/wireless_adapter.md b/docs/wireless_adapter.md index 88a9421..550a45e 100644 --- a/docs/wireless_adapter.md +++ b/docs/wireless_adapter.md @@ -254,14 +254,14 @@ Both Pokemon games and the multiboot ROM that the adapter sends when no cartridg - Send length: 0, response length: 0 - This uses the broadcast data given by the broadcast command and actually does the broadcasting. -⏲ After calling this command, wait some time (~15 scanlines) before calling `AcceptConnections` or it will fail!. +⏲ After calling this command, wait some time (~15 scanlines) before calling `PollConnections` or it will fail!. #### EndHost - `0x1b` - Send length: 0, response length: 2+ - This command stops host broadcast. This allows to "close" the room and stop allowing new clients, but also **keeping the existing connections alive**. Sends and Receives still work, but: - Clients cannot connect, even if they already know the host ID (`FinishConnection` will fail). - - Calls to `AcceptConnections` on the host side will fail, unless `StartHost` is called again. + - Calls to `PollConnections` on the host side will fail, unless `StartHost` is called again. #### BroadcastRead - `0x1c`, `0x1d` and `0x1e` @@ -296,15 +296,15 @@ Let's call these `BroadcastReadStart`, `BroadcastReadPoll`, and `BroadcastReadEn ⏳ If a client sends a `0x1c` and then starts a `0x1d` loop (1 command per frame), and a console that was broadcasting is turned off, it disappears after 3 seconds. -#### AcceptConnections - `0x1a` +#### PollConnections - `0x1a` - Send length: 0, response length: 0+ -- Accepts new connections and returns a list with the connected adapters. The length of the response is zero if there are no connected adapters. +- Polls new connections and returns a list with the connected adapters. The length of the response is zero if there are no connected adapters. - It includes one value per connected client, in which the most significant byte is the `clientNumber` (see [IsConnectionComplete](#isconnectioncomplete---0x20)) and the least significant byte is the ID. 🔗 If this command reports 3 connected consoles, after turning off one of them, it will still report 3 consoles. Servers need to detect timeouts in another way. -❗ `0x19`, `0x1a` and `0x1b` behave like the 3 broadcast reading commands (`0x1c`, `0x1d` and `0x1e`), in the sense that `StartHost` puts the adapter in 'open host' mode, `AcceptConnections` polls new connections and `EndHost` exits the open host mode. +❗ `0x19`, `0x1a` and `0x1b` behave like the 3 broadcast reading commands (`0x1c`, `0x1d` and `0x1e`), in the sense that `StartHost` puts the adapter in 'open host' mode, `PollConnections` polls new connections and `EndHost` exits the open host mode. #### Connect - `0x1f` @@ -423,7 +423,7 @@ Let's call these `BroadcastReadStart`, `BroadcastReadPoll`, and `BroadcastReadEn [![Image without alt text or caption](img/wireless/0x30.png)](img/wireless/0x30.png) - Send length 1, reponse length: 0 -- This command disconnects clients. The argument is a bitmask of the client ID to disconnect. Sending `0x1` means "disconnect client number 0", sending `0x2` means "disconnect client number 1", and sending `0xF` would disconnect all the clients. After disconnecting a client, its ID won't appear on `AcceptConnection` calls and its `clientNumber` will be liberated, so other peers can connect. +- This command disconnects clients. The argument is a bitmask of the client ID to disconnect. Sending `0x1` means "disconnect client number 0", sending `0x2` means "disconnect client number 1", and sending `0xF` would disconnect all the clients. After disconnecting a client, its ID won't appear on `PollConnections` calls and its `clientNumber` will be liberated, so other peers can connect. ⚡ The clients also are able to disconnect themselves using this command, but they can only send its corresponding bit or `0xF`, other bits are ignored (they cannot disconnect other clients). Also, the host won't know if a client disconnects itself, so this feature is not very useful: @@ -471,10 +471,10 @@ Let's call these `BroadcastReadStart`, `BroadcastReadPoll`, and `BroadcastReadEn - Send length: 0, Response length: 1+ -- It's returns a list of the connected adapters, similar to what `AcceptConnections` responds, but also: +- It's returns a list of the connected adapters, similar to what `PollConnections` responds, but also: - `SlotStatus` has an extra word at the start of the response, indicating the `clientNumber` that the next connection will have (or `0xFF` if the room is not accepting new clients). - - `SlotStatus` can be called after `EndHost`, while `AcceptConnections` fails. + - `SlotStatus` can be called after `EndHost`, while `PollConnections` fails. #### ConfigStatus - `0x15` diff --git a/examples/LinkRawWireless_demo/src/scenes/DebugScene.cpp b/examples/LinkRawWireless_demo/src/scenes/DebugScene.cpp index f70587c..11a5374 100644 --- a/examples/LinkRawWireless_demo/src/scenes/DebugScene.cpp +++ b/examples/LinkRawWireless_demo/src/scenes/DebugScene.cpp @@ -213,7 +213,7 @@ void DebugScene::addCommandMenuOptions() { commandMenuOptions.push_back( CommandMenuOption{.name = "0x19 (StartHost)", .command = 0x19}); commandMenuOptions.push_back( - CommandMenuOption{.name = "0x1A (AcceptConnections)", .command = 0x1A}); + CommandMenuOption{.name = "0x1A (PollConnections)", .command = 0x1A}); commandMenuOptions.push_back( CommandMenuOption{.name = "0x1B (EndHost)", .command = 0x1B}); commandMenuOptions.push_back( @@ -584,8 +584,8 @@ void DebugScene::processCommand(u32 selectedCommandIndex) { } case 0x1A: { return logOperation("sending " + name, []() { - LinkRawWireless::AcceptConnectionsResponse response; - bool success = linkRawWireless->acceptConnections(response); + LinkRawWireless::PollConnectionsResponse response; + bool success = linkRawWireless->pollConnections(response); if (success) { for (u32 i = 0; i < response.connectedClientsSize; i++) { @@ -602,7 +602,7 @@ void DebugScene::processCommand(u32 selectedCommandIndex) { } case 0x1B: { return logOperation("sending " + name, []() { - LinkRawWireless::AcceptConnectionsResponse response; + LinkRawWireless::PollConnectionsResponse response; bool success = linkRawWireless->endHost(response); if (success) { diff --git a/lib/LinkRawWireless.hpp b/lib/LinkRawWireless.hpp index a2ae132..38a242a 100644 --- a/lib/LinkRawWireless.hpp +++ b/lib/LinkRawWireless.hpp @@ -12,7 +12,7 @@ // - `startHost` = `0x19` // - `getSignalLevel` = `0x11` // - `getSlotStatus` = `0x14` -// - `acceptConnections` = `0x1A` +// - `pollConnections` = `0x1A` // - `endHost` = `0x1B` // - `broadcastReadStart` = `0x1C` // - `broadcastReadPoll` = `0x1D` @@ -111,7 +111,7 @@ class LinkRawWireless { static constexpr int COMMAND_START_HOST = 0x19; static constexpr int COMMAND_SIGNAL_LEVEL = 0x11; static constexpr int COMMAND_SLOT_STATUS = 0x14; - static constexpr int COMMAND_ACCEPT_CONNECTIONS = 0x1A; + static constexpr int COMMAND_POLL_CONNECTIONS = 0x1A; static constexpr int COMMAND_END_HOST = 0x1B; static constexpr int COMMAND_BROADCAST_READ_START = 0x1C; static constexpr int COMMAND_BROADCAST_READ_POLL = 0x1D; @@ -184,7 +184,7 @@ class LinkRawWireless { u32 connectedClientsSize = 0; }; - struct AcceptConnectionsResponse { + struct PollConnectionsResponse { ConnectedClient connectedClients[LINK_RAW_WIRELESS_MAX_PLAYERS] = {}; u32 connectedClientsSize = 0; }; @@ -498,11 +498,11 @@ class LinkRawWireless { } /** - * @brief Calls the AcceptConnections (`0x1A`) command. + * @brief Calls the PollConnections (`0x1A`) command. * @param response A structure that will be filled with the response data. */ - bool acceptConnections(AcceptConnectionsResponse& response) { - auto result = sendCommand(COMMAND_ACCEPT_CONNECTIONS); + bool pollConnections(PollConnectionsResponse& response) { + auto result = sendCommand(COMMAND_POLL_CONNECTIONS); if (!result.success) { _resetState(); @@ -528,7 +528,7 @@ class LinkRawWireless { * @brief Calls the EndHost (`0x1B`) command. * @param response A structure that will be filled with the response data. */ - bool endHost(AcceptConnectionsResponse& response) { + bool endHost(PollConnectionsResponse& response) { auto result = sendCommand(COMMAND_END_HOST); if (!result.success) { diff --git a/lib/LinkWireless.hpp b/lib/LinkWireless.hpp index 46595bb..35c7d03 100644 --- a/lib/LinkWireless.hpp +++ b/lib/LinkWireless.hpp @@ -401,7 +401,7 @@ class LinkWireless { if (isAsyncCommandActive()) return badRequest(BUSY_TRY_AGAIN); - LinkRawWireless::AcceptConnectionsResponse response; + LinkRawWireless::PollConnectionsResponse response; bool success = linkRawWireless.endHost(response); if (!success) diff --git a/lib/LinkWirelessMultiboot.hpp b/lib/LinkWirelessMultiboot.hpp index 9f2c517..be7affd 100644 --- a/lib/LinkWirelessMultiboot.hpp +++ b/lib/LinkWirelessMultiboot.hpp @@ -267,7 +267,7 @@ class LinkWirelessMultiboot { template Result waitForClients(u8 players, C listener) { - LinkRawWireless::AcceptConnectionsResponse acceptResponse; + LinkRawWireless::PollConnectionsResponse pollResponse; u32 currentPlayers = 1; while ((linkRawWireless.playerCount() < players && !readyFlag) || @@ -275,7 +275,7 @@ class LinkWirelessMultiboot { if (listener(progress)) return CANCELED; - if (!linkRawWireless.acceptConnections(acceptResponse)) + if (!linkRawWireless.pollConnections(pollResponse)) return FAILURE; if (linkRawWireless.playerCount() > currentPlayers) { @@ -283,8 +283,7 @@ class LinkWirelessMultiboot { progress.connectedClients = currentPlayers - 1; u8 lastClientNumber = - acceptResponse - .connectedClients[acceptResponse.connectedClientsSize - 1] + pollResponse.connectedClients[pollResponse.connectedClientsSize - 1] .clientNumber; LINK_WIRELESS_MULTIBOOT_TRY_SUB( handshakeClient(lastClientNumber, listener)) @@ -293,7 +292,7 @@ class LinkWirelessMultiboot { readyFlag = true; - if (!linkRawWireless.endHost(acceptResponse)) + if (!linkRawWireless.endHost(pollResponse)) return FAILURE; return SUCCESS; diff --git a/lib/c_bindings/C_LinkRawWireless.cpp b/lib/c_bindings/C_LinkRawWireless.cpp index 3ed0fae..0a7e788 100644 --- a/lib/c_bindings/C_LinkRawWireless.cpp +++ b/lib/c_bindings/C_LinkRawWireless.cpp @@ -100,12 +100,12 @@ bool C_LinkRawWireless_getSlotStatus( return success; } -bool C_LinkRawWireless_acceptConnections( +bool C_LinkRawWireless_pollConnections( C_LinkRawWirelessHandle handle, - C_LinkRawWireless_AcceptConnectionsResponse* response) { - LinkRawWireless::AcceptConnectionsResponse cppResponse; + C_LinkRawWireless_PollConnectionsResponse* response) { + LinkRawWireless::PollConnectionsResponse cppResponse; bool success = - static_cast(handle)->acceptConnections(cppResponse); + static_cast(handle)->pollConnections(cppResponse); response->connectedClientsSize = cppResponse.connectedClientsSize; for (u32 i = 0; i < response->connectedClientsSize; i++) { response->connectedClients[i].deviceId = @@ -118,8 +118,8 @@ bool C_LinkRawWireless_acceptConnections( bool C_LinkRawWireless_endHost( C_LinkRawWirelessHandle handle, - C_LinkRawWireless_AcceptConnectionsResponse* response) { - LinkRawWireless::AcceptConnectionsResponse cppResponse; + C_LinkRawWireless_PollConnectionsResponse* response) { + LinkRawWireless::PollConnectionsResponse cppResponse; bool success = static_cast(handle)->endHost(cppResponse); response->connectedClientsSize = cppResponse.connectedClientsSize; for (u32 i = 0; i < response->connectedClientsSize; i++) { diff --git a/lib/c_bindings/C_LinkRawWireless.h b/lib/c_bindings/C_LinkRawWireless.h index efcfd4a..408d7d4 100644 --- a/lib/c_bindings/C_LinkRawWireless.h +++ b/lib/c_bindings/C_LinkRawWireless.h @@ -77,7 +77,7 @@ typedef struct { C_LinkRawWireless_ConnectedClient connectedClients[C_LINK_RAW_WIRELESS_MAX_PLAYERS]; u32 connectedClientsSize; -} C_LinkRawWireless_AcceptConnectionsResponse; +} C_LinkRawWireless_PollConnectionsResponse; typedef struct { C_LinkRawWireless_Server servers[C_LINK_RAW_WIRELESS_MAX_SERVERS]; @@ -130,12 +130,12 @@ bool C_LinkRawWireless_getSignalLevel( bool C_LinkRawWireless_getSlotStatus( C_LinkRawWirelessHandle handle, C_LinkRawWireless_SlotStatusResponse* response); -bool C_LinkRawWireless_acceptConnections( +bool C_LinkRawWireless_pollConnections( C_LinkRawWirelessHandle handle, - C_LinkRawWireless_AcceptConnectionsResponse* response); + C_LinkRawWireless_PollConnectionsResponse* response); bool C_LinkRawWireless_endHost( C_LinkRawWirelessHandle handle, - C_LinkRawWireless_AcceptConnectionsResponse* response); + C_LinkRawWireless_PollConnectionsResponse* response); bool C_LinkRawWireless_broadcastReadStart(C_LinkRawWirelessHandle handle); bool C_LinkRawWireless_broadcastReadPoll( C_LinkRawWirelessHandle handle,