Adding getSlotStatus

This commit is contained in:
Rodrigo Alfonso 2024-01-14 07:32:56 -03:00
parent 88f6763863
commit bf3afdc9af
3 changed files with 49 additions and 4 deletions

View File

@ -221,7 +221,7 @@ Name | Return type | Description
--- | --- | ---
`isActive()` | **bool** | Returns whether the library is active or not.
`activate()` | **bool** | Activates the library. When an adapter is connected, it changes the state to `AUTHENTICATED`. It can also be used to disconnect or reset the adapter.
`deactivate()` | **bool** | Puts the adapter into a low consumption mode and then deactivates the library. It returns a boolean indicating whether the transition to low consumption mode was successful.
`deactivate()` | **bool** | Puts the adapter into a low consumption mode and then deactivates the library. It returns a boolean indicating whether the transition to low consumption mode was successful. To ensure that the transition works, before calling this, reset the adapter by calling `activate()` again, and then `deactivate()`.
`serve([gameName], [userName], [gameId])` | **bool** | Starts broadcasting a server and changes the state to `SERVING`. You can, optionally, provide a `gameName` (max `14` characters), a `userName` (max `8` characters), and a `gameId` *(0 ~ 0x7FFF)* that games will be able to read. If the adapter is already serving, this method only updates the broadcast data.
`getServers(servers, [onWait])` | **bool** | Fills the `servers` array with all the currently broadcasting servers. This action takes 1 second to complete, but you can optionally provide an `onWait()` function which will be invoked each time VBlank starts.
`getServersAsyncStart()` | **bool** | Starts looking for broadcasting servers and changes the state to `SEARCHING`. After this, call `getServersAsyncEnd(...)` 1 second later.

View File

@ -301,6 +301,19 @@ void DebugScene::processCommand(u32 selectedCommandIndex) {
logSimpleCommand(selectedCommand, 0x12);
} else if (selectedCommand == "0x13 (SystemStatus)") {
logSimpleCommand(selectedCommand, 0x13);
} else if (selectedCommand == "0x14 (SlotStatus)") {
logOperation("sending " + selectedCommand, []() {
LinkRawWireless::SlotStatusResponse response;
bool success = linkRawWireless->getSlotStatus(response);
log("< [next slot] " +
linkRawWireless->toHex(response.nextClientNumber, 1));
for (u32 i = 0; i < response.connectedClients.size(); i++) {
log("< [client" +
std::to_string(response.connectedClients[i].clientNumber) + "] " +
linkRawWireless->toHex(response.connectedClients[i].deviceId, 2));
}
return success;
});
}
}

View File

@ -43,6 +43,7 @@
#define LINK_RAW_WIRELESS_COMMAND_SETUP 0x17
#define LINK_RAW_WIRELESS_COMMAND_BROADCAST 0x16
#define LINK_RAW_WIRELESS_COMMAND_START_HOST 0x19
#define LINK_RAW_WIRELESS_COMMAND_SLOT_STATUS 0x14
#define LINK_RAW_WIRELESS_COMMAND_ACCEPT_CONNECTIONS 0x1a
#define LINK_RAW_WIRELESS_COMMAND_BROADCAST_READ_START 0x1c
#define LINK_RAW_WIRELESS_COMMAND_BROADCAST_READ_POLL 0x1d
@ -110,7 +111,7 @@ class LinkRawWireless {
lastError = NONE;
isEnabled = false;
bool success = reset();
bool success = reset(true);
isEnabled = true;
return success;
@ -194,6 +195,37 @@ class LinkRawWireless {
return true;
}
typedef struct {
u16 deviceId;
u8 clientNumber;
} ConnectedClient;
typedef struct {
u8 nextClientNumber;
std::vector<ConnectedClient> connectedClients;
} SlotStatusResponse;
bool getSlotStatus(SlotStatusResponse& response) {
auto result = sendCommand(LINK_RAW_WIRELESS_COMMAND_SLOT_STATUS);
if (!result.success) {
reset();
return false;
}
for (u32 i = 0; i < result.responses.size(); i++) {
if (i == 0) {
response.nextClientNumber = (u8)lsB32(result.responses[i]);
} else {
response.connectedClients.push_back(
ConnectedClient{.deviceId = lsB32(result.responses[i]),
.clientNumber = (u8)msB32(result.responses[i])});
}
}
return true;
}
bool acceptConnections() {
auto result = sendCommand(LINK_RAW_WIRELESS_COMMAND_ACCEPT_CONNECTIONS);
@ -494,10 +526,10 @@ class LinkRawWireless {
name.push_back(character);
}
bool reset() {
bool reset(bool initialize = false) {
resetState();
stop();
return start();
return initialize && start();
}
void resetState() {