LinkRawWireless: Implementing SignalLevel (0x11) command

This commit is contained in:
Rodrigo Alfonso 2025-01-13 00:06:58 -03:00
parent 5d8544b28f
commit 6b740f3616
6 changed files with 70 additions and 12 deletions

View File

@ -296,6 +296,7 @@ https://github.com/afska/gba-link-connection/assets/1631752/9a648bff-b14f-4a85-9
- `getSystemStatus` = `0x13`
- `broadcast` = `0x16`
- `startHost` = `0x19`
- `getSignalLevel` = `0x11`
- `getSlotStatus` = `0x14`
- `acceptConnections` = `0x1a`
- `endHost` = `0x1b`

View File

@ -474,6 +474,20 @@ void DebugScene::processCommand(u32 selectedCommandIndex) {
switch (command) {
case 0x10:
case 0x11:
return logOperation("sending " + name, []() {
LinkRawWireless::SignalLevelResponse response;
bool success = linkRawWireless->getSignalLevel(response);
if (success) {
log("< [levelH] " + std::to_string(response.signalLevels[0]));
log("< [levelC0] " + std::to_string(response.signalLevels[1]));
log("< [levelC1] " + std::to_string(response.signalLevels[2]));
log("< [levelC2] " + std::to_string(response.signalLevels[3]));
log("< [levelC3] " + std::to_string(response.signalLevels[4]));
}
return success;
});
case 0x12:
goto simple;
case 0x13: {

View File

@ -10,6 +10,7 @@
// - `getSystemStatus` = `0x13`
// - `broadcast` = `0x16`
// - `startHost` = `0x19`
// - `getSignalLevel` = `0x11`
// - `getSlotStatus` = `0x14`
// - `acceptConnections` = `0x1a`
// - `endHost` = `0x1b`
@ -101,9 +102,10 @@ class LinkRawWireless {
LINK_RAW_WIRELESS_MAX_COMMAND_RESPONSE_LENGTH / BROADCAST_RESPONSE_LENGTH;
static constexpr int COMMAND_HELLO = 0x10;
static constexpr int COMMAND_SETUP = 0x17;
static constexpr int COMMAND_SYSTEM_STATUS = 0x13;
static constexpr int COMMAND_BROADCAST = 0x16;
static constexpr int COMMAND_START_HOST = 0x19;
static constexpr int COMMAND_SYSTEM_STATUS = 0x13;
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_END_HOST = 0x1b;
@ -168,6 +170,10 @@ class LinkRawWireless {
bool isServerClosed = false;
};
struct SignalLevelResponse {
u8 signalLevels[LINK_RAW_WIRELESS_MAX_PLAYERS] = {};
};
struct SlotStatusResponse {
u8 nextClientNumber = 0;
ConnectedClient connectedClients[LINK_RAW_WIRELESS_MAX_PLAYERS] = {};
@ -304,7 +310,9 @@ class LinkRawWireless {
bool getSystemStatus(SystemStatusResponse& response) {
auto result = sendCommand(COMMAND_SYSTEM_STATUS);
if (!result.success || result.dataSize != 1) {
if (!result.success || result.dataSize == 0) {
if (result.dataSize == 0)
_LRWLOG_("! empty response");
_resetState();
return false;
}
@ -424,6 +432,28 @@ class LinkRawWireless {
return true;
}
/**
* @brief Calls the SignalLevel (`0x11`) command.
* @param response A structure that will be filled with the response data.
*/
bool getSignalLevel(SignalLevelResponse& response) {
auto result = sendCommand(COMMAND_SIGNAL_LEVEL);
if (!result.success || result.dataSize == 0) {
if (result.dataSize == 0)
_LRWLOG_("! empty response");
_resetState();
return false;
}
u32 levels = result.data[0];
for (u32 i = 1; i < LINK_RAW_WIRELESS_MAX_PLAYERS; i++)
response.signalLevels[i] = (levels >> ((i - 1) * 8)) & 0xff;
return true;
}
/**
* @brief Calls the SlotStatus (`0x14`) command.
* @param response A structure that will be filled with the response data.

View File

@ -26,8 +26,7 @@ void C_LinkPS2Mouse_deactivate(C_LinkPS2MouseHandle handle) {
void C_LinkPS2Mouse_report(C_LinkPS2MouseHandle handle, int data[3]) {
int d[3];
static_cast<LinkPS2Mouse*>(handle)->report(d);
for (u32 i = 0; i < 3; i++) {
for (u32 i = 0; i < 3; i++)
data[i] = d[i];
}
}
}

View File

@ -70,6 +70,17 @@ bool C_LinkRawWireless_startHost(C_LinkRawWirelessHandle handle) {
return static_cast<LinkRawWireless*>(handle)->startHost();
}
bool C_LinkRawWireless_getSignalLevel(
C_LinkRawWirelessHandle handle,
C_LinkRawWireless_SignalLevelResponse* response) {
LinkRawWireless::SignalLevelResponse cppResponse;
bool success =
static_cast<LinkRawWireless*>(handle)->getSignalLevel(cppResponse);
for (u32 i = 0; i < LINK_RAW_WIRELESS_MAX_PLAYERS; i++)
response->signalLevels[i] = cppResponse.signalLevels[i];
return success;
}
bool C_LinkRawWireless_getSlotStatus(
C_LinkRawWirelessHandle handle,
C_LinkRawWireless_SlotStatusResponse* response) {
@ -235,13 +246,11 @@ bool C_LinkRawWireless_getReceiveDataResponse(
LinkRawWireless::ReceiveDataResponse cppResponse;
bool success = static_cast<LinkRawWireless*>(handle)->getReceiveDataResponse(
toCppResult(result), cppResponse);
for (u32 i = 0; i < cppResponse.dataSize; i++) {
for (u32 i = 0; i < cppResponse.dataSize; i++)
response->data[i] = cppResponse.data[i];
}
response->dataSize = cppResponse.dataSize;
for (u32 i = 0; i < LINK_RAW_WIRELESS_MAX_PLAYERS; i++) {
for (u32 i = 0; i < LINK_RAW_WIRELESS_MAX_PLAYERS; i++)
response->sentBytes[i] = cppResponse.sentBytes[i];
}
return success;
}
@ -322,9 +331,8 @@ C_LinkRawWireless_CommandResult fromCppResult(
C_LinkRawWireless_CommandResult result;
result.success = cppResult.success;
result.commandId = cppResult.commandId;
for (u32 i = 0; i < cppResult.dataSize; i++) {
for (u32 i = 0; i < cppResult.dataSize; i++)
result.data[i] = cppResult.data[i];
}
result.dataSize = cppResult.dataSize;
return result;
}
@ -333,9 +341,8 @@ LinkRawWireless::CommandResult toCppResult(
LinkRawWireless::CommandResult cppResult;
cppResult.success = cppResult.success;
cppResult.commandId = result.commandId;
for (u32 i = 0; i < result.dataSize; i++) {
for (u32 i = 0; i < result.dataSize; i++)
cppResult.data[i] = result.data[i];
}
cppResult.dataSize = result.dataSize;
return cppResult;
}

View File

@ -62,6 +62,10 @@ typedef struct {
bool isServerClosed;
} C_LinkRawWireless_SystemStatusResponse;
typedef struct {
u8 signalLevels[C_LINK_RAW_WIRELESS_MAX_PLAYERS];
} C_LinkRawWireless_SignalLevelResponse;
typedef struct {
u8 nextClientNumber;
C_LinkRawWireless_ConnectedClient
@ -119,6 +123,9 @@ bool C_LinkRawWireless_broadcast(C_LinkRawWirelessHandle handle,
const char* userName,
u16 gameId);
bool C_LinkRawWireless_startHost(C_LinkRawWirelessHandle handle);
bool C_LinkRawWireless_getSignalLevel(
C_LinkRawWirelessHandle handle,
C_LinkRawWireless_SignalLevelResponse* response);
bool C_LinkRawWireless_getSlotStatus(
C_LinkRawWirelessHandle handle,
C_LinkRawWireless_SlotStatusResponse* response);