mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-29 05:21:37 +03:00
@ -295,6 +295,12 @@ OPT_ARDUINO_LIBS ?= $(addprefix ../../libraries/,\
|
||||
LEAmDNS_Structs.cpp \
|
||||
LEAmDNS_Transfer.cpp \
|
||||
ESP8266mDNS.cpp \
|
||||
LEAmDNS2Host.cpp \
|
||||
LEAmDNS2Host_Control.cpp \
|
||||
LEAmDNS2Host_Debug.cpp \
|
||||
LEAmDNS2Host_Structs.cpp \
|
||||
LEAmDNS2Host_Transfer.cpp \
|
||||
LEAmDNS2_Backbone.cpp \
|
||||
) \
|
||||
ArduinoOTA/ArduinoOTA.cpp \
|
||||
DNSServer/src/DNSServer.cpp \
|
||||
|
@ -270,3 +270,10 @@ extern "C" void configTime(long timezone, int daylightOffset_sec,
|
||||
#include "pins_arduino.h"
|
||||
|
||||
#endif /* Arduino_h */
|
||||
|
||||
#if __cplusplus
|
||||
#include <WString.h>
|
||||
#include <map>
|
||||
#define MOCKARGS 1
|
||||
extern std::map<String,String> mockArgs;
|
||||
#endif
|
||||
|
@ -56,6 +56,8 @@ const char* fspath = nullptr;
|
||||
|
||||
static struct termios initial_settings;
|
||||
|
||||
std::map<String,String> mockArgs;
|
||||
|
||||
int mockverbose (const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -135,6 +137,8 @@ void help (const char* argv0, int exitcode)
|
||||
"\t-S - spiffs size in KBytes (default: %zd)\n"
|
||||
"\t-L - littlefs size in KBytes (default: %zd)\n"
|
||||
"\t (spiffs, littlefs: negative value will force mismatched size)\n"
|
||||
"\t-K - key\n"
|
||||
"\t-V - value\n"
|
||||
"\tgeneral:\n"
|
||||
"\t-c - ignore CTRL-C (send it via Serial)\n"
|
||||
"\t-f - no throttle (possibly 100%%CPU)\n"
|
||||
@ -158,6 +162,8 @@ static struct option options[] =
|
||||
{ "spiffskb", required_argument, NULL, 'S' },
|
||||
{ "littlefskb", required_argument, NULL, 'L' },
|
||||
{ "portshifter", required_argument, NULL, 's' },
|
||||
{ "key", required_argument, NULL, 'K' },
|
||||
{ "value", required_argument, NULL, 'V' },
|
||||
{ "once", no_argument, NULL, '1' },
|
||||
};
|
||||
|
||||
@ -209,10 +215,11 @@ int main (int argc, char* const argv [])
|
||||
mock_port_shifter = 0;
|
||||
else
|
||||
mock_port_shifter = MOCK_PORT_SHIFTER;
|
||||
String key;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:1", options, NULL);
|
||||
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:1K:V:", options, NULL);
|
||||
if (n < 0)
|
||||
break;
|
||||
switch (n)
|
||||
@ -253,6 +260,12 @@ int main (int argc, char* const argv [])
|
||||
case 'T':
|
||||
serial_timestamp = true;
|
||||
break;
|
||||
case 'K':
|
||||
key = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
mockArgs[key] = optarg;
|
||||
break;
|
||||
case '1':
|
||||
run_once = true;
|
||||
break;
|
||||
|
@ -29,11 +29,6 @@
|
||||
DEALINGS WITH THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/mem.h"
|
||||
#include <include/UdpContext.h>
|
||||
#include <poll.h>
|
||||
#include <map>
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include <AddrList.h>
|
||||
#include <lwip/netif.h>
|
||||
|
||||
#include "MocklwIP.h"
|
||||
|
||||
esp8266::AddressListImplementation::AddressList addrList;
|
||||
|
||||
|
15
tests/host/common/MocklwIP.h
Normal file
15
tests/host/common/MocklwIP.h
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef __MOCKLWIP_H
|
||||
#define __MOCKLWIP_H
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#include <user_interface.h>
|
||||
#include <lwip/netif.h>
|
||||
|
||||
extern netif netif0;
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // __MOCKLWIP_H
|
@ -1,28 +1,32 @@
|
||||
/*
|
||||
UdpContext.h - emulation of UDP connection handling on top of lwIP
|
||||
UdpContext.h - emulation of UDP connection handling on top of lwIP
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef UDPCONTEXT_H
|
||||
#define UDPCONTEXT_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <MocklwIP.h>
|
||||
#include <IPAddress.h>
|
||||
#include <PolledTimeout.h>
|
||||
|
||||
class UdpContext;
|
||||
|
||||
#define GET_IP_HDR(pb) reinterpret_cast<ip_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN - IP_HLEN);
|
||||
@ -52,12 +56,13 @@ public:
|
||||
|
||||
void unref()
|
||||
{
|
||||
if(--_refcnt == 0) {
|
||||
if (--_refcnt == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
bool connect (const ip_addr_t* addr, uint16_t port)
|
||||
bool connect(const ip_addr_t* addr, uint16_t port)
|
||||
{
|
||||
_dst = *addr;
|
||||
_dstport = port;
|
||||
@ -108,7 +113,8 @@ public:
|
||||
|
||||
// warning: handler is called from tcp stack context
|
||||
// esp_yield and non-reentrant functions which depend on it will fail
|
||||
void onRx(rxhandler_t handler) {
|
||||
void onRx(rxhandler_t handler)
|
||||
{
|
||||
_on_rx = handler;
|
||||
}
|
||||
|
||||
@ -132,11 +138,12 @@ public:
|
||||
mockUDPSwallow(pos, _inbuf, _inbufsize);
|
||||
}
|
||||
|
||||
bool isValidOffset(const size_t pos) const {
|
||||
bool isValidOffset(const size_t pos) const
|
||||
{
|
||||
return pos <= _inbufsize;
|
||||
}
|
||||
|
||||
uint32_t getRemoteAddress()
|
||||
IPAddress getRemoteAddress()
|
||||
{
|
||||
return _dst.addr;
|
||||
}
|
||||
@ -146,7 +153,7 @@ public:
|
||||
return _dstport;
|
||||
}
|
||||
|
||||
uint32_t getDestAddress()
|
||||
IPAddress getDestAddress()
|
||||
{
|
||||
mockverbose("TODO: implement UDP getDestAddress\n");
|
||||
return 0; //ip_hdr* iphdr = GET_IP_HDR(_rx_buf);
|
||||
@ -173,7 +180,7 @@ public:
|
||||
int read()
|
||||
{
|
||||
char c;
|
||||
return read(&c, 1)? c: -1;
|
||||
return read(&c, 1) ? c : -1;
|
||||
}
|
||||
|
||||
size_t read(char* dst, size_t size)
|
||||
@ -184,7 +191,7 @@ public:
|
||||
int peek()
|
||||
{
|
||||
char c;
|
||||
return mockUDPPeekBytes(_sock, &c, 1, _timeout_ms, _inbuf, _inbufsize)?: -1;
|
||||
return mockUDPPeekBytes(_sock, &c, 1, _timeout_ms, _inbuf, _inbufsize) ? : -1;
|
||||
}
|
||||
|
||||
void flush()
|
||||
@ -195,7 +202,7 @@ public:
|
||||
_inbufsize = 0;
|
||||
}
|
||||
|
||||
size_t append (const char* data, size_t size)
|
||||
size_t append(const char* data, size_t size)
|
||||
{
|
||||
if (size + _outbufsize > sizeof _outbuf)
|
||||
{
|
||||
@ -208,16 +215,40 @@ public:
|
||||
return size;
|
||||
}
|
||||
|
||||
bool send (ip_addr_t* addr = 0, uint16_t port = 0)
|
||||
err_t trySend(ip_addr_t* addr = 0, uint16_t port = 0, bool keepBuffer = true)
|
||||
{
|
||||
uint32_t dst = addr? addr->addr: _dst.addr;
|
||||
uint16_t dstport = port?: _dstport;
|
||||
size_t ret = mockUDPWrite(_sock, (const uint8_t*)_outbuf, _outbufsize, _timeout_ms, dst, dstport);
|
||||
_outbufsize = 0;
|
||||
return ret > 0;
|
||||
uint32_t dst = addr ? addr->addr : _dst.addr;
|
||||
uint16_t dstport = port ? : _dstport;
|
||||
size_t wrt = mockUDPWrite(_sock, (const uint8_t*)_outbuf, _outbufsize, _timeout_ms, dst, dstport);
|
||||
err_t ret = _outbufsize ? ERR_OK : ERR_ABRT;
|
||||
if (!keepBuffer || wrt == _outbufsize)
|
||||
cancelBuffer();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mock_cb (void)
|
||||
void cancelBuffer()
|
||||
{
|
||||
_outbufsize = 0;
|
||||
}
|
||||
|
||||
bool send(ip_addr_t* addr = 0, uint16_t port = 0)
|
||||
{
|
||||
return trySend(addr, port, false) == ERR_OK;
|
||||
}
|
||||
|
||||
bool sendTimeout(ip_addr_t* addr, uint16_t port,
|
||||
esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs)
|
||||
{
|
||||
err_t err;
|
||||
esp8266::polledTimeout::oneShotFastMs timeout(timeoutMs);
|
||||
while (((err = trySend(addr, port)) != ERR_OK) && !timeout)
|
||||
delay(0);
|
||||
if (err != ERR_OK)
|
||||
cancelBuffer();
|
||||
return err == ERR_OK;
|
||||
}
|
||||
|
||||
void mock_cb(void)
|
||||
{
|
||||
if (_on_rx) _on_rx();
|
||||
}
|
||||
@ -228,7 +259,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void translate_addr ()
|
||||
void translate_addr()
|
||||
{
|
||||
if (addrsize == 4)
|
||||
{
|
||||
@ -260,7 +291,7 @@ private:
|
||||
uint8_t addr[16];
|
||||
};
|
||||
|
||||
extern "C" inline err_t igmp_joingroup (const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
|
||||
extern "C" inline err_t igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
|
||||
{
|
||||
(void)ifaddr;
|
||||
UdpContext::staticMCastAddr = groupaddr->addr;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "MocklwIP.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -138,6 +139,7 @@ extern "C"
|
||||
|
||||
if (host_interface)
|
||||
mockverbose("host: looking for interface '%s':\n", host_interface);
|
||||
|
||||
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next)
|
||||
{
|
||||
mockverbose("host: interface: %s", ifa->ifa_name);
|
||||
|
Reference in New Issue
Block a user