Skip to content

Commit

Permalink
Fixing broadcast polling for more than 1 server
Browse files Browse the repository at this point in the history
  • Loading branch information
afska committed Feb 4, 2023
1 parent d33cfdc commit 91caddf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/wireless_adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Whenever either side expects something to be sent from the other (as SPI is alwa

⚠️ IDs are randomly generated. Each time you broadcast or connect, the adapter assigns you a new id.

⚠️ Reading broadcasts is a two-step process: First, you send `0x1c`. Then, wait until the adapter retrieves data (games usually wait 1 full second). Lastly, send a `0x1e` and it will return what's described above.
⚠️ Reading broadcasts is a three-step process: First, you send `0x1c` (you will get an ACK instantly), and start waiting until the adapter retrieves data (games usually wait 1 full second). Then, send a `0x1d` and it will return what's described above. Lastly, send a `0x1e` to finish the process (you can ignore what the adapter returns here). If you don't send that last `0x1e`, the next command will fail.

#### Setup - `0x17`

Expand Down
12 changes: 11 additions & 1 deletion lib/LinkWireless.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#define LINK_WIRELESS_COMMAND_START_HOST 0x19
#define LINK_WIRELESS_COMMAND_ACCEPT_CONNECTIONS 0x1a
#define LINK_WIRELESS_COMMAND_BROADCAST_READ_START 0x1c
#define LINK_WIRELESS_COMMAND_BROADCAST_READ_POLL 0x1d
#define LINK_WIRELESS_COMMAND_BROADCAST_READ_END 0x1e
#define LINK_WIRELESS_COMMAND_CONNECT 0x1f
#define LINK_WIRELESS_COMMAND_IS_FINISHED_CONNECT 0x20
Expand Down Expand Up @@ -254,7 +255,7 @@ class LinkWireless {

wait(LINK_WIRELESS_BROADCAST_SEARCH_WAIT);

auto result = sendCommand(LINK_WIRELESS_COMMAND_BROADCAST_READ_END);
auto result = sendCommand(LINK_WIRELESS_COMMAND_BROADCAST_READ_POLL);
bool success2 =
result.success &&
result.responses.size() % LINK_WIRELESS_BROADCAST_RESPONSE_LENGTH == 0;
Expand All @@ -265,6 +266,15 @@ class LinkWireless {
return false;
}

bool success3 =
sendCommand(LINK_WIRELESS_COMMAND_BROADCAST_READ_END).success;

if (!success3) {
reset();
lastError = COMMAND_FAILED;
return false;
}

u32 totalBroadcasts =
result.responses.size() / LINK_WIRELESS_BROADCAST_RESPONSE_LENGTH;

Expand Down

0 comments on commit 91caddf

Please sign in to comment.