DCC-EX Simple Throttle
Simple throttle for a DCC-EX CommandStation
Loading...
Searching...
No Matches
/home/runner/work/DCCEXSimpleThrottle/DCCEXSimpleThrottle/ConnectionManager.h
Go to the documentation of this file.
1/*
2 * © 2024 Peter Cole
3 * © 2023 Peter Cole
4 *
5 * This is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * It is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this code. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#ifndef CONNECTIONMANAGER_H
20#define CONNECTIONMANAGER_H
21
23#include "Defines.h"
24
25#ifdef WIFI_ENABLED
26#include <WiFi.h>
27#endif // WIFI_ENABLED
28
31public:
34
36 void update();
37
40 bool connected();
41
44 Stream *getConnectionStream();
45
46#ifdef WIFI_ENABLED
49 bool receivedUserSelection();
50
53 bool isConnecting();
54
57 const char *getConnectionName();
58
61 bool connectionError();
62
65 const char *getConnectionErrorMessage();
66
69 uint8_t getRetryCounter();
70
73 bool newAttempt();
74
78 void setCommandStationList(CommandStationDetails *commandStationList, uint8_t commandStationCount);
79
82 void selectCommandStation(uint8_t commandStationIndex);
83
84#endif // WIFI_ENABLED
85
86private:
88#ifdef WIFI_ENABLED
89 bool _receivedUserSelection;
90 uint8_t _selectedCommandStation;
91 uint8_t _commandStationCount;
92 CommandStationDetails *_commandStationList;
93 bool _wifiStarted;
94 unsigned long _wifiRetryDelay;
95 unsigned long _lastWifiRetry;
96 uint8_t _wifiMaxRetries;
97 uint8_t _wifiRetry;
98 unsigned long _serverRetryDelay;
99 unsigned long _lastServerRetry;
100 uint8_t _serverMaxRetries;
101 uint8_t _serverRetry;
102 bool _isConnecting;
103 const char *_connectionName;
104 bool _connectionError;
105 const char *_connectionErrorMessage;
106 uint8_t _retryCounter;
107 bool _newAttempt;
108
109 WiFiClient _wifiClient;
110
112 bool _connectWiFi(unsigned long currentMillis);
113
115 bool _connectServer(unsigned long currentMillis);
116#endif // WIFI_ENABLED
117};
118
119#endif // CONNECTIONMANAGER_H
Class to manage all WiFi and serial connections used to connect to a CommandStation.
Definition ConnectionManager.h:30
bool connected()
Check if connections are active.
Definition ConnectionManager.cpp:66
void update()
Ensure all connections are alive and retries are managed.
Definition ConnectionManager.cpp:48
ConnectionManager()
Constructor for the ConnectionManager.
Definition ConnectionManager.cpp:21
bool _connected
Definition ConnectionManager.h:87
Stream * getConnectionStream()
Get the connection stream managed by this ConnectionManager.
Definition ConnectionManager.cpp:68