mirror of
https://github.com/afska/gba-link-connection.git
synced 2026-10-02 13:56:42 -05:00
Adding isConfigurationValid()
This commit is contained in:
@@ -449,6 +449,7 @@ Name | Return type | Description
|
||||
`readConfiguration(configurationData)` | **bool** | Retrieves the adapter configuration, and puts it in the `configurationData` struct. If the adapter has an active session, the data is already loaded, so it's instantaneous.
|
||||
`getState()` | **LinkMobile::State** | Returns the current state (one of `LinkMobile::State::NEEDS_RESET`, `LinkMobile::State::PINGING`, `LinkMobile::State::WAITING_TO_START`, `LinkMobile::State::STARTING_SESSION`, `LinkMobile::State::ACTIVATING_SIO32`, `LinkMobile::State::WAITING_32BIT_SWITCH`, `LinkMobile::State::READING_CONFIGURATION`, `LinkMobile::State::SESSION_ACTIVE`, `LinkMobile::State::CALL_REQUESTED`, `LinkMobile::State::CALLING`, `LinkMobile::State::CALL_ESTABLISHED`, `LinkMobile::State::SESSION_ACTIVE_ISP`, `LinkMobile::State::SHUTDOWN_REQUESTED`, `LinkMobile::State::ENDING_SESSION`, `LinkMobile::State::WAITING_8BIT_SWITCH`, or `LinkMobile::State::SHUTDOWN`).
|
||||
`getRole()` | **LinkMobile::Role** | Returns the current role in the P2P connection (one of `LinkMobile::Role::NO_P2P_CONNECTION`, `LinkMobile::Role::CALLER`, or `LinkMobile::Role::RECEIVER`).
|
||||
`isConfigurationValid()` | **int** | Returns whether the adapter has been configured or not. Returns `1` = yes, `0` = no, `-1` = unknown (no session active).
|
||||
`isConnected()` | **bool** | Returns `true` if a P2P call is established (the state is `CALL_ESTABLISHED`).
|
||||
`isSessionActive()` | **bool** | Returns `true` if the session is active.
|
||||
`canShutdown()` | **bool** | Returns `true` if there's an active session and there's no previous shutdown requests.
|
||||
|
||||
@@ -217,8 +217,8 @@ std::string readConfiguration() {
|
||||
if (!linkMobile->readConfiguration(data))
|
||||
return "Read failed :(";
|
||||
|
||||
return ("Magic:\n " + toStr(data.magic, 2) + "\nIsRegistering:\n " +
|
||||
(data.isRegistering ? "Yes" : "No") + "\nPrimary DNS:\n " +
|
||||
return ("Magic:\n " + toStr(data.magic, 2) + "\nRegistered:\n $" +
|
||||
toHex(data.registrationState) + "\nPrimary DNS:\n " +
|
||||
std::to_string(data.primaryDNS[0]) + "." +
|
||||
std::to_string(data.primaryDNS[1]) + "." +
|
||||
std::to_string(data.primaryDNS[2]) + "." +
|
||||
@@ -229,7 +229,8 @@ std::string readConfiguration() {
|
||||
std::to_string(data.secondaryDNS[3]) + "\nLoginID:\n " +
|
||||
toStr(data.loginID, 10) + "\nEmail:\n " + toStr(data.email, 24) +
|
||||
"\nSMTP Server:\n " + toStr(data.smtpServer, 20) +
|
||||
"\nPOP Server:\n " + toStr(data.popServer, 19) + "\n\nMode: " +
|
||||
"\nPOP Server:\n " + toStr(data.popServer, 19) + "\nIs Valid:\n " +
|
||||
std::to_string(linkMobile->isConfigurationValid()) + "\n\nMode: " +
|
||||
(linkMobile->getDataSize() == LinkSPI::DataSize::SIZE_32BIT
|
||||
? "SIO32"
|
||||
: "SIO8"));
|
||||
|
||||
@@ -179,7 +179,7 @@ class LinkMobile {
|
||||
|
||||
struct ConfigurationData {
|
||||
char magic[2];
|
||||
bool isRegistering;
|
||||
u8 registrationState;
|
||||
u8 _unused1_;
|
||||
u8 primaryDNS[4];
|
||||
u8 secondaryDNS[4];
|
||||
@@ -356,6 +356,17 @@ class LinkMobile {
|
||||
*/
|
||||
[[nodiscard]] Role getRole() { return role; }
|
||||
|
||||
/**
|
||||
* @brief Returns whether the adapter has been configured or not.
|
||||
* @return 1 = yes, 0 = no, -1 = unknown (no session active).
|
||||
*/
|
||||
[[nodiscard]] int isConfigurationValid() {
|
||||
if (!isSessionActive())
|
||||
return -1;
|
||||
|
||||
return (int)adapterConfiguration.isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns `true` if a P2P call is established (the state is
|
||||
* `CALL_ESTABLISHED`).
|
||||
@@ -497,7 +508,11 @@ class LinkMobile {
|
||||
ConfigurationData fields;
|
||||
char bytes[CONFIGURATION_DATA_SIZE];
|
||||
|
||||
bool isValid() { return calculatedChecksum() == reportedChecksum(); }
|
||||
bool isValid() {
|
||||
return fields.magic[0] == 'M' && fields.magic[1] == 'A' &&
|
||||
(fields.registrationState & 1) == 1 &&
|
||||
calculatedChecksum() == reportedChecksum();
|
||||
}
|
||||
|
||||
u16 calculatedChecksum() {
|
||||
u16 result = 0;
|
||||
|
||||
Reference in New Issue
Block a user