supla-device
Loading...
Searching...
No Matches
wifi_scan_result.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_NETWORK_WIFI_SCAN_RESULT_H_
20#define SRC_SUPLA_NETWORK_WIFI_SCAN_RESULT_H_
21
22#include <stdint.h>
23
24namespace Supla {
25
26constexpr uint8_t WifiScanMaxResults = 16;
27constexpr uint8_t WifiScanSsidMaxSize = 33;
28constexpr uint32_t WifiScanDefaultMaxAgeMs = 5 * 60 * 1000;
29
31 char ssid[WifiScanSsidMaxSize] = {};
32 int32_t rssi = 0;
33 int32_t channel = 0;
34};
35
36enum class WifiScanLookupStatus : uint8_t {
37 NotAvailable,
38 Found,
39 NotFound,
40 Stale,
41};
42
44 public:
45 static WifiScanResultCache *Instance();
46
47 void clear();
48 void beginUpdate();
49 void addOrUpdate(const char *ssid, int32_t rssi, int32_t channel);
50 void finishUpdate(uint32_t timestampMs);
51
52 WifiScanLookupStatus lookup(const char *ssid,
53 WifiScanResult *result,
54 uint32_t nowMs,
55 uint32_t maxAgeMs =
56 WifiScanDefaultMaxAgeMs) const;
57
58 uint8_t getCount() const;
59 uint32_t getTimestampMs() const;
60 bool hasScan() const;
61 bool getResult(uint8_t index, WifiScanResult *result) const;
62
63 private:
64 void sortByRssi();
65 int find(const char *ssid) const;
66 int findWeakest() const;
67
68 WifiScanResult entries[WifiScanMaxResults] = {};
69 uint8_t count = 0;
70 uint32_t timestampMs = 0;
71 bool scanAvailable = false;
72};
73
74} // namespace Supla
75
76#endif // SRC_SUPLA_NETWORK_WIFI_SCAN_RESULT_H_
Definition wifi_scan_result.h:43
Definition wifi_scan_result.h:30