Skip to content

Commit f5e0731

Browse files
committed
[Ardrivo] Properly stub WiFiClass and WiFiClient
Signed-off-by: AeroStun <[email protected]>
1 parent 4851fb1 commit f5e0731

File tree

6 files changed

+127
-20
lines changed

6 files changed

+127
-20
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ target_sources (Ardrivo PRIVATE
102102

103103
include/Ardrivo/WiFi.h
104104
src/Ardrivo/WiFi.cpp
105-
)
105+
include/Ardrivo/WiFiClient.h
106+
)
106107
if (SMCE_ARDRIVO_MQTT)
107108
target_sources (Ardrivo PRIVATE include/Ardrivo/MQTT.h src/Ardrivo/MQTT.cpp)
108109
target_link_libraries(Ardrivo PRIVATE SMCE_mosquitto)

include/Ardrivo/IPAddress.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef IPAddress_h
2020
#define IPAddress_h
2121

22-
struct IPAddress {};
22+
class IPAddress {
23+
std::uint8_t m_bytes[4]{0, 0, 0, 0};
24+
};
2325

2426
#endif // IPAddress_h

include/Ardrivo/WiFi.h

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,74 @@
2020
#define WiFi_h
2121

2222
#include <cstdint>
23-
#include "Client.h"
2423
#include "IPAddress.h"
2524
#include "SMCE_dll.hpp"
25+
#include "WiFiClient.h"
2626

27-
struct WiFiClass : Client {
28-
inline int connect([[maybe_unused]] IPAddress ip, [[maybe_unused]] std::uint16_t port) override { return 0; }
29-
int connect([[maybe_unused]] const char* host, [[maybe_unused]] std::uint16_t port) override { return 0; }
30-
std::size_t write([[maybe_unused]] std::uint8_t) override { return 0; }
31-
std::size_t write([[maybe_unused]] const std::uint8_t* buf, [[maybe_unused]] std::size_t size) override {
32-
return 0;
27+
enum {
28+
WL_SSID_MAX_LENGTH = 32,
29+
WL_WPA_KEY_MAX_LENGTH = 63,
30+
WL_WEP_KEY_MAX_LENGTH = 13,
31+
WL_MAC_ADDR_LENGTH = 6,
32+
WL_IPV4_LENGTH = 4,
33+
WL_NETWORKS_LIST_MAXNUM = 10,
34+
MAX_SOCK_NUM = 4,
35+
SOCK_NOT_AVAIL = 255,
36+
NA_STATE = -1,
37+
WL_MAX_ATTEMPT_CONNECTION = 10,
38+
};
39+
40+
enum wl_status_t {
41+
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
42+
WL_IDLE_STATUS = 0,
43+
WL_NO_SSID_AVAIL = 1,
44+
WL_SCAN_COMPLETED = 2,
45+
WL_CONNECTED = 3,
46+
WL_CONNECT_FAILED = 4,
47+
WL_CONNECTION_LOST = 5,
48+
WL_DISCONNECTED = 6,
49+
};
50+
51+
enum wl_enc_type {
52+
ENC_TYPE_WEP = 5,
53+
ENC_TYPE_TKIP = 2,
54+
ENC_TYPE_CCMP = 4,
55+
ENC_TYPE_NONE = 7,
56+
ENC_TYPE_AUTO = 8,
57+
};
58+
59+
struct WiFiClass {
60+
int begin() { return 0; }
61+
int begin([[maybe_unused]] const char* ssid) { return WL_NO_SHIELD; }
62+
int begin([[maybe_unused]] const char* ssid, [[maybe_unused]] const char* pass) { return WL_NO_SHIELD; }
63+
int begin([[maybe_unused]] const char* ssid, [[maybe_unused]] std::uint8_t key_idx,
64+
[[maybe_unused]] const char* key) {
65+
return WL_NO_SHIELD;
3366
}
34-
int available() override { return 0; }
35-
int read() override { return -1; }
36-
int read([[maybe_unused]] std::uint8_t* buf, [[maybe_unused]] std::size_t size) override { return 0; }
37-
int peek() override { return -1; }
38-
void flush() override {}
39-
void stop() override {}
40-
std::uint8_t connected() override { return 0; }
41-
operator bool() override { return false; }
67+
int disconnect() { return WL_NO_SHIELD; }
68+
void config([[maybe_unused]] IPAddress local_ip) {}
69+
void config([[maybe_unused]] IPAddress local_ip, [[maybe_unused]] IPAddress dns_server) {}
70+
void config([[maybe_unused]] IPAddress local_ip, [[maybe_unused]] IPAddress dns_server,
71+
[[maybe_unused]] IPAddress gateway) {}
72+
void config([[maybe_unused]] IPAddress local_ip, [[maybe_unused]] IPAddress dns_server,
73+
[[maybe_unused]] IPAddress gateway, [[maybe_unused]] IPAddress subnet) {}
74+
void setDNS([[maybe_unused]] IPAddress dns_server1) {}
75+
void setDNS([[maybe_unused]] IPAddress dns_server1, [[maybe_unused]] IPAddress dns_server2) {}
76+
/*[[nodiscard]]*/ char* SSID() const { return nullptr; }
77+
/*[[nodiscard]]*/ char* SSID([[maybe_unused]] std::uint8_t networkItem) const { return nullptr; }
78+
std::uint8_t* BSSID(std::uint8_t* bssid);
79+
/*[[nodiscard]]*/ std::int32_t RSSI() { return 0; }
80+
/*[[nodiscard]]*/ std::int32_t RSSI([[maybe_unused]] std::uint8_t networkItem) { return 0; }
81+
/*[[nodiscard]]*/ std::uint8_t encryptionType() { return ENC_TYPE_AUTO; }
82+
/*[[nodiscard]]*/ std::uint8_t encryptionType([[maybe_unused]] std::uint8_t networkItem) { return ENC_TYPE_AUTO; }
83+
std::int8_t scanNetworks() { return 0; }
84+
/*[[nodiscard]]*/ static std::uint8_t getSocket() { return 0; }
85+
std::uint8_t* macAddress(std::uint8_t* mac) const;
86+
/*[[nodiscard]]*/ int status() const { return WL_NO_SHIELD; }
87+
88+
/*[[nodiscard]]*/ IPAddress localIP() { return {}; }
89+
/*[[nodiscard]]*/ IPAddress subnetMask() { return {}; }
90+
/*[[nodiscard]]*/ IPAddress gatewayIP() { return {}; }
4291
};
4392

4493
SMCE__DLL_RT_API

include/Ardrivo/WiFiClient.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* WiFiClient.h
3+
* Copyright 2022 ItJustWorksTM
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#ifndef wificlient_h
20+
#define wificlient_h
21+
22+
#include <cstdint>
23+
#include "Client.h"
24+
#include "IPAddress.h"
25+
26+
struct WiFiClient : Client {
27+
inline int connect([[maybe_unused]] IPAddress ip, [[maybe_unused]] std::uint16_t port) override { return 0; }
28+
int connect([[maybe_unused]] const char* host, [[maybe_unused]] std::uint16_t port) override { return 0; }
29+
std::size_t write([[maybe_unused]] std::uint8_t) override { return 0; }
30+
std::size_t write([[maybe_unused]] const std::uint8_t* buf, [[maybe_unused]] std::size_t size) override {
31+
return 0;
32+
}
33+
int available() override { return 0; }
34+
int read() override { return -1; }
35+
int read([[maybe_unused]] std::uint8_t* buf, [[maybe_unused]] std::size_t size) override { return 0; }
36+
int peek() override { return -1; }
37+
void flush() override {}
38+
void stop() override {}
39+
/*[[nodiscard]]*/ std::uint8_t connected() override { return 0; }
40+
operator bool() override { return false; }
41+
42+
using Print::write;
43+
};
44+
45+
#endif // wificlient_h

src/Ardrivo/WiFi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@
1616
*
1717
*/
1818

19+
#include <algorithm>
1920
#include "SMCE_dll.hpp"
2021
#include "WiFi.h"
2122

2223
SMCE__DLL_API WiFiClass WiFi;
24+
25+
std::uint8_t* WiFiClass::BSSID(std::uint8_t* bssid) {
26+
std::fill_n(bssid, WL_MAC_ADDR_LENGTH, 0);
27+
return bssid;
28+
}
29+
30+
std::uint8_t* WiFiClass::macAddress(std::uint8_t* mac) const {
31+
std::fill_n(mac, WL_MAC_ADDR_LENGTH, 0);
32+
return mac;
33+
}

test/sketches/wifi/wifi.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#include <WiFi.h>
33

44
void setup() {
5-
#ifndef __SMCE__
65
WiFi.begin("foo", "bar");
7-
#endif
86
MQTTClient clt;
9-
clt.begin(WiFi);
7+
WiFiClient net;
8+
clt.begin(net);
109
}
1110

1211
void loop() { delay(1); }

0 commit comments

Comments
 (0)