mirror of
https://github.com/afska/gba-link-connection.git
synced 2026-04-25 16:23:41 -05:00
Adding broadcast packet to debugger
This commit is contained in:
parent
90118826d4
commit
85bf89ec20
|
|
@ -31,6 +31,14 @@ static std::vector<std::string> logLines;
|
|||
static u32 currentLogLine = 0;
|
||||
static bool useVerboseLog = true;
|
||||
|
||||
static const std::string CHARACTERS[] = {
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c",
|
||||
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
|
||||
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C",
|
||||
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
|
||||
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
|
||||
static const u32 CHARACTERS_LEN = 62;
|
||||
|
||||
#define MAX_LINES 18
|
||||
#define DRAW_LINE 2
|
||||
|
||||
|
|
@ -145,6 +153,10 @@ void DebugScene::tick(u16 keys) {
|
|||
|
||||
processKeys(keys);
|
||||
processButtons();
|
||||
|
||||
__qran_seed += keys;
|
||||
__qran_seed += REG_RCNT;
|
||||
__qran_seed += REG_SIOCNT;
|
||||
}
|
||||
|
||||
void DebugScene::addCommandMenuOptions() {
|
||||
|
|
@ -290,6 +302,53 @@ int DebugScene::selectOption(std::string title,
|
|||
}
|
||||
}
|
||||
|
||||
std::string DebugScene::selectString(u32 maxCharacters) {
|
||||
std::vector<std::string> options = {"<end>"};
|
||||
for (u32 i = 0; i < CHARACTERS_LEN; i++)
|
||||
options.push_back(CHARACTERS[i]);
|
||||
|
||||
again:
|
||||
std::string str;
|
||||
for (u32 i = 0; i < maxCharacters; i++) {
|
||||
int characterIndex = -1;
|
||||
if ((characterIndex =
|
||||
selectOption("Next character? (" + str + ")", options)) == -1)
|
||||
goto again;
|
||||
if (characterIndex == 0)
|
||||
break;
|
||||
str += CHARACTERS[characterIndex - 1];
|
||||
}
|
||||
|
||||
if (str == "")
|
||||
goto again;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
u16 DebugScene::selectU16() {
|
||||
again:
|
||||
int lsB = selectU8("Choose lsB (0x00XX)");
|
||||
if (lsB == -1)
|
||||
goto again;
|
||||
int msB = selectU8("Choose msB (0xXX" + linkRawWireless->toHex(lsB, 2) + ")");
|
||||
if (msB == -1)
|
||||
goto again;
|
||||
|
||||
u16 number = linkRawWireless->buildU16((u8)msB, (u8)lsB);
|
||||
if (selectOption(linkRawWireless->toHex(number, 4) + "?",
|
||||
std::vector<std::string>{"yes", "no"}) == 1)
|
||||
goto again;
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
int DebugScene::selectU8(std::string title) {
|
||||
std::vector<std::string> options;
|
||||
for (u32 i = 0; i < 1 << 8; i++)
|
||||
options.push_back(linkRawWireless->toHex(i, 2));
|
||||
return selectOption(title, options);
|
||||
}
|
||||
|
||||
void DebugScene::processCommand(u32 selectedCommandIndex) {
|
||||
std::string selectedCommand = commandMenuOptions[selectedCommandIndex];
|
||||
|
||||
|
|
@ -306,14 +365,67 @@ void DebugScene::processCommand(u32 selectedCommandIndex) {
|
|||
LinkRawWireless::SlotStatusResponse response;
|
||||
bool success = linkRawWireless->getSlotStatus(response);
|
||||
log("< [next slot] " +
|
||||
linkRawWireless->toHex(response.nextClientNumber, 1));
|
||||
linkRawWireless->toHex(response.nextClientNumber, 2));
|
||||
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));
|
||||
linkRawWireless->toHex(response.connectedClients[i].deviceId, 4));
|
||||
}
|
||||
return success;
|
||||
});
|
||||
} else if (selectedCommand == "0x15 (ConfigStatus)") {
|
||||
logSimpleCommand(selectedCommand, 0x15);
|
||||
} else if (selectedCommand == "0x16 (Broadcast)") {
|
||||
u16 gameId = selectGameId();
|
||||
std::string gameName = selectGameName();
|
||||
std::string userName = selectUserName();
|
||||
|
||||
logOperation("sending " + selectedCommand, [gameName, userName, gameId]() {
|
||||
return linkRawWireless->broadcast(gameName, userName, gameId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
u16 DebugScene::selectGameId() {
|
||||
switch (selectOption(
|
||||
"GameID?",
|
||||
std::vector<std::string>{"0x7FFF", "0x1234", "<random>", "<pick>"})) {
|
||||
case 0: {
|
||||
return 0x7fff;
|
||||
}
|
||||
case 1: {
|
||||
return 0x1234;
|
||||
}
|
||||
case 2: {
|
||||
return linkRawWireless->buildU16(qran_range(0, 256), qran_range(0, 256));
|
||||
}
|
||||
default: {
|
||||
return selectU16();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string DebugScene::selectGameName() {
|
||||
switch (selectOption("Game name?",
|
||||
std::vector<std::string>{"LinkConnection", "<pick>"})) {
|
||||
case 0: {
|
||||
return "LinkConnection";
|
||||
}
|
||||
default: {
|
||||
return selectString(LINK_RAW_WIRELESS_MAX_GAME_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string DebugScene::selectUserName() {
|
||||
switch (
|
||||
selectOption("User name?", std::vector<std::string>{"Demo", "<pick>"})) {
|
||||
case 0: {
|
||||
return "Demo";
|
||||
}
|
||||
default: {
|
||||
return selectString(LINK_RAW_WIRELESS_MAX_USER_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,13 @@ class DebugScene : public Scene {
|
|||
void processButtons();
|
||||
void toggleLogLevel();
|
||||
int selectOption(std::string title, std::vector<std::string> options);
|
||||
std::string selectString(u32 maxCharacters);
|
||||
u16 selectU16();
|
||||
int selectU8(std::string title);
|
||||
void processCommand(u32 selectedCommandIndex);
|
||||
u16 selectGameId();
|
||||
std::string selectGameName();
|
||||
std::string selectUserName();
|
||||
void logSimpleCommand(std::string name, u32 id);
|
||||
void logOperation(std::string name, std::function<bool()> operation);
|
||||
void resetAdapter();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// TODO: LOGGING BUILD OPTION
|
||||
|
||||
#define LINK_RAW_WIRELESS_MAX_PLAYERS 5
|
||||
#define LINK_RAW_WIRELESS_MIN_PLAYERS 2
|
||||
#define LINK_RAW_WIRELESS_END 0
|
||||
|
|
@ -59,8 +61,6 @@ static volatile char LINK_RAW_WIRELESS_VERSION[] = "LinkRawWireless/v6.0.3";
|
|||
|
||||
const u16 LINK_RAW_WIRELESS_LOGIN_PARTS[] = {
|
||||
0x494e, 0x494e, 0x544e, 0x544e, 0x4e45, 0x4e45, 0x4f44, 0x4f44, 0x8001};
|
||||
const u16 LINK_RAW_WIRELESS_TIMER_IRQ_IDS[] = {IRQ_TIMER0, IRQ_TIMER1,
|
||||
IRQ_TIMER2, IRQ_TIMER3};
|
||||
|
||||
class LinkRawWireless {
|
||||
typedef void (*Logger)(std::string);
|
||||
|
|
@ -138,9 +138,9 @@ class LinkRawWireless {
|
|||
.success;
|
||||
}
|
||||
|
||||
bool serve(std::string gameName = "",
|
||||
std::string userName = "",
|
||||
u16 gameId = LINK_RAW_WIRELESS_MAX_GAME_ID) {
|
||||
bool broadcast(std::string gameName = "",
|
||||
std::string userName = "",
|
||||
u16 gameId = LINK_RAW_WIRELESS_MAX_GAME_ID) {
|
||||
if (gameName.length() > LINK_RAW_WIRELESS_MAX_GAME_NAME_LENGTH) {
|
||||
lastError = GAME_NAME_TOO_LONG;
|
||||
return false;
|
||||
|
|
@ -154,7 +154,7 @@ class LinkRawWireless {
|
|||
userName.append(LINK_RAW_WIRELESS_MAX_USER_NAME_LENGTH - userName.length(),
|
||||
0);
|
||||
|
||||
auto broadcast =
|
||||
auto broadcastData =
|
||||
std::vector<u32>{buildU32(buildU16(gameName[1], gameName[0]),
|
||||
gameId & LINK_RAW_WIRELESS_MAX_GAME_ID),
|
||||
buildU32(buildU16(gameName[5], gameName[4]),
|
||||
|
|
@ -169,11 +169,10 @@ class LinkRawWireless {
|
|||
buildU16(userName[5], userName[4]))};
|
||||
|
||||
bool success =
|
||||
sendCommand(LINK_RAW_WIRELESS_COMMAND_BROADCAST, broadcast).success;
|
||||
sendCommand(LINK_RAW_WIRELESS_COMMAND_BROADCAST, broadcastData).success;
|
||||
|
||||
if (!success) {
|
||||
reset();
|
||||
lastError = COMMAND_FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -190,6 +189,7 @@ class LinkRawWireless {
|
|||
}
|
||||
|
||||
wait(LINK_RAW_WIRELESS_TRANSFER_WAIT);
|
||||
logger("state = SERVING");
|
||||
state = SERVING;
|
||||
|
||||
return true;
|
||||
|
|
@ -249,6 +249,7 @@ class LinkRawWireless {
|
|||
return false;
|
||||
}
|
||||
|
||||
logger("state = SEARCHING");
|
||||
state = SEARCHING;
|
||||
|
||||
return true;
|
||||
|
|
@ -297,6 +298,7 @@ class LinkRawWireless {
|
|||
servers.push_back(server);
|
||||
}
|
||||
|
||||
logger("state = AUTHENTICATED");
|
||||
state = AUTHENTICATED;
|
||||
|
||||
return true;
|
||||
|
|
@ -313,6 +315,7 @@ class LinkRawWireless {
|
|||
return false;
|
||||
}
|
||||
|
||||
logger("state = CONNECTING");
|
||||
state = CONNECTING;
|
||||
|
||||
return true;
|
||||
|
|
@ -344,6 +347,7 @@ class LinkRawWireless {
|
|||
}
|
||||
|
||||
sessionState.currentPlayerId = assignedPlayerId;
|
||||
logger("state = CONNECTED");
|
||||
state = CONNECTED;
|
||||
|
||||
return true;
|
||||
|
|
@ -533,6 +537,7 @@ class LinkRawWireless {
|
|||
}
|
||||
|
||||
void resetState() {
|
||||
logger("state = NEEDS_RESET");
|
||||
this->state = NEEDS_RESET;
|
||||
this->sessionState.playerCount = 1;
|
||||
this->sessionState.currentPlayerId = 0;
|
||||
|
|
@ -556,6 +561,7 @@ class LinkRawWireless {
|
|||
|
||||
logger("setting SPI to 2Mbps");
|
||||
linkSPI->activate(LinkSPI::Mode::MASTER_2MBPS);
|
||||
logger("state = AUTHENTICATED");
|
||||
state = AUTHENTICATED;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user