Skip to content

Commit abe9921

Browse files
committed
WiFi: Add *GetStateName, *SetState and WiFi station restart states
1 parent 3726e3b commit abe9921

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ static const char * wifiAuthorizationName[] =
3030
static const int wifiAuthorizationNameEntries =
3131
sizeof(wifiAuthorizationName) / sizeof(wifiAuthorizationName[0]);
3232

33+
enum WIFI_STATION_STATES
34+
{
35+
WIFI_STATION_STATE_OFF,
36+
WIFI_STATION_STATE_WAIT_NO_USERS,
37+
WIFI_STATION_STATE_RESTART,
38+
WIFI_STATION_STATE_STARTING,
39+
WIFI_STATION_STATE_ONLINE,
40+
WIFI_STATION_STATE_STABLE,
41+
// The following line must be the last in the list
42+
WIFI_STATION_STATE_MAX
43+
};
44+
uint8_t wifiStationState;
45+
46+
const char * wifiStationStateName[] =
47+
{
48+
"WIFI_STATION_STATE_OFF",
49+
"WIFI_STATION_STATE_WAIT_NO_USERS",
50+
"WIFI_STATION_STATE_RESTART",
51+
"WIFI_STATION_STATE_STARTING",
52+
"WIFI_STATION_STATE_ONLINE",
53+
"WIFI_STATION_STATE_STABLE",
54+
};
55+
const int wifiStationStateNameEntries = sizeof(wifiStationStateName) / sizeof(wifiStationStateName[0]);
56+
3357
//----------------------------------------------------------------------
3458
// ESP-NOW bringup from example 4_9_ESP_NOW
3559
// 1. Set station mode
@@ -767,6 +791,15 @@ void wifiStartThrottled(NetIndex_t index, uintptr_t parameter, bool debug)
767791
networkSequenceNextEntry(NETWORK_WIFI_STATION, debug);
768792
}
769793

794+
//*********************************************************************
795+
// Get the state name for WiFi station
796+
const char * wifiStationGetStateName(uint8_t state)
797+
{
798+
if (state < wifiStationStateNameEntries)
799+
return wifiStationStateName[state];
800+
return "Unknown WiFi Station state";
801+
}
802+
770803
//*********************************************************************
771804
// Stop the WiFi station
772805
// Inputs:
@@ -807,6 +840,44 @@ bool wifiStationOn(const char * fileName, uint32_t lineNumber)
807840
__FILE__, __LINE__);
808841
}
809842

843+
//*********************************************************************
844+
// Set the WiFi station state
845+
void wifiStationSetState(uint8_t newState)
846+
{
847+
// Display the state transition
848+
if (settings.debugWifiState)
849+
{
850+
const char * asterisk;
851+
const char * stateNew;
852+
const char * stateOld;
853+
const char * transition;
854+
855+
// Get the current state name
856+
stateOld = wifiStationGetStateName(wifiStationState);
857+
858+
// Check for a transition
859+
if (newState != wifiStationState)
860+
{
861+
asterisk = "";
862+
transition = " --> ";
863+
stateNew = wifiStationGetStateName(newState);
864+
}
865+
else
866+
{
867+
// No transition
868+
asterisk = "*";
869+
transition = "";
870+
stateNew = "";
871+
}
872+
873+
// Display the state transition
874+
systemPrintf("%s%s%s%s\r\n", asterisk, stateOld, transition, stateNew);
875+
}
876+
877+
// Set the new state
878+
wifiStationState = newState;
879+
}
880+
810881
//*********************************************************************
811882
// Handle WiFi station reconnection requests
812883
bool wifiStationReconnectionRequest()
@@ -966,6 +1037,13 @@ void wifiVerifyTables()
9661037
{
9671038
// Verify the RTK_WIFI tables
9681039
wifi.verifyTables();
1040+
1041+
// Verify the WiFi station state name table
1042+
if (WIFI_STATION_STATE_MAX != wifiStationStateNameEntries)
1043+
{
1044+
systemPrintf("ERROR: Fix wifiStationStateName list to match WIFI_STATION_STATES!\r\n");
1045+
reportFatalError("Fix wifiStationStateName list to match WIFI_STATION_STATES!");
1046+
}
9691047
}
9701048

9711049
//*********************************************************************

0 commit comments

Comments
 (0)