2018-01-01 18:56:07 +00:00
|
|
|
/*
|
|
|
|
* Stairs
|
|
|
|
* Copyright 2017 (c) Mark van Renswoude
|
|
|
|
*
|
|
|
|
* https://git.x2software.net/pub/Stairs
|
|
|
|
*/
|
|
|
|
#ifndef __settingsconnection
|
|
|
|
#define __settingsconnection
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <IPAddress.h>
|
|
|
|
#include "../charproperties.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum ConnectionSettingsFlags
|
|
|
|
{
|
|
|
|
AccessPoint = 1,
|
|
|
|
StationMode = 2,
|
|
|
|
DHCP = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectionSettings : CharProperties
|
|
|
|
{
|
|
|
|
private:
|
2018-01-07 22:12:42 +00:00
|
|
|
char* mHostname = nullptr;
|
2018-01-01 18:56:07 +00:00
|
|
|
uint8_t mFlags = AccessPoint | DHCP;
|
2018-01-07 22:12:42 +00:00
|
|
|
char* mSSID = nullptr;
|
|
|
|
char* mPassword = nullptr;
|
2018-01-01 18:56:07 +00:00
|
|
|
IPAddress mIP = (uint32_t)0;
|
|
|
|
IPAddress mSubnetMask = (uint32_t)0;
|
|
|
|
IPAddress mGateway = (uint32_t)0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void read();
|
|
|
|
void write();
|
|
|
|
|
|
|
|
|
|
|
|
void toJson(Print &print);
|
|
|
|
bool fromJson(char* data);
|
|
|
|
bool fromJson(char* data, bool* changed);
|
|
|
|
|
|
|
|
|
|
|
|
char* hostname() { return mHostname; }
|
|
|
|
void hostname(const char* value) { assignChar(&mHostname, value); }
|
|
|
|
|
|
|
|
bool flag(ConnectionSettingsFlags flag) { return (mFlags & flag) != 0; }
|
|
|
|
void flag(ConnectionSettingsFlags flag, bool enabled)
|
|
|
|
{
|
|
|
|
if (enabled)
|
|
|
|
mFlags |= flag;
|
|
|
|
else
|
|
|
|
mFlags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* ssid() { return mSSID; }
|
|
|
|
void ssid(const char* value) { assignChar(&mSSID, value); }
|
|
|
|
|
|
|
|
char* password() { return mPassword; }
|
|
|
|
void password(const char* value) { assignChar(&mPassword, value); }
|
|
|
|
|
|
|
|
IPAddress ip() { return mIP; }
|
|
|
|
void ip(IPAddress value) { mIP = value; }
|
|
|
|
|
|
|
|
IPAddress subnetMask() { return mSubnetMask; }
|
|
|
|
void subnetMask(IPAddress value) { mSubnetMask = value; }
|
|
|
|
|
|
|
|
IPAddress gateway() { return mGateway; }
|
|
|
|
void gateway(IPAddress value) { mGateway = value; }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|