test on Windows

This commit is contained in:
proddy
2024-08-01 22:12:33 +02:00
parent dac033e962
commit 4ec5739b67
7 changed files with 138 additions and 110 deletions

View File

@@ -23,7 +23,10 @@ the LICENSE file.
#if EMC_ESP8266_MULTITHREADING #if EMC_ESP8266_MULTITHREADING
// This lib doesn't run use multithreading on ESP8266 // This lib doesn't run use multithreading on ESP8266
// _xSemaphore defined as std::atomic<bool> // _xSemaphore defined as std::atomic<bool>
#define EMC_SEMAPHORE_TAKE() while (_xSemaphore) { /*ESP.wdtFeed();*/ } _xSemaphore = true #define EMC_SEMAPHORE_TAKE() \
while (_xSemaphore) { /*ESP.wdtFeed();*/ \
} \
_xSemaphore = true
#define EMC_SEMAPHORE_GIVE() _xSemaphore = false #define EMC_SEMAPHORE_GIVE() _xSemaphore = false
#else #else
#define EMC_SEMAPHORE_TAKE() #define EMC_SEMAPHORE_TAKE()
@@ -44,6 +47,13 @@ the LICENSE file.
#include <mutex> // NOLINT [build/c++11] #include <mutex> // NOLINT [build/c++11]
#define EMC_SEMAPHORE_TAKE() mtx.lock(); #define EMC_SEMAPHORE_TAKE() mtx.lock();
#define EMC_SEMAPHORE_GIVE() mtx.unlock(); #define EMC_SEMAPHORE_GIVE() mtx.unlock();
#elif defined(_WIN32)
#include <Arduino.h>
#define EMC_SEMAPHORE_TAKE()
#define EMC_SEMAPHORE_GIVE()
#define EMC_YIELD()
#define EMC_GET_FREE_MEMORY() 1000
#define EMC_GENERATE_CLIENTID(x)
#else #else
#error Target platform not supported #error Target platform not supported
#endif #endif

View File

@@ -6,7 +6,7 @@ For a copy, see <https://opensource.org/licenses/MIT> or
the LICENSE file. the LICENSE file.
*/ */
#if defined(__linux__) #if defined(__linux__) || defined(_WIN32)
#include "ClientPosixIPAddress.h" #include "ClientPosixIPAddress.h"

View File

@@ -120,4 +120,9 @@ espMqttClient::espMqttClient()
, _client() { , _client() {
_transport = &_client; _transport = &_client;
} }
#elif defined(_WIN32)
// Windows
espMqttClient::espMqttClient()
: MqttClientSetup(espMqttClientTypes::UseInternalTask::NO) {
}
#endif #endif

View File

@@ -67,9 +67,8 @@ class espMqttClientSecure : public MqttClientSetup<espMqttClientSecure> {
protected: protected:
espMqttClientInternals::ClientSecureSync _client; espMqttClientInternals::ClientSecureSync _client;
}; };
#endif
#if defined(__linux__) #elif defined(__linux__)
class espMqttClient : public MqttClientSetup<espMqttClient> { class espMqttClient : public MqttClientSetup<espMqttClient> {
public: public:
espMqttClient(); espMqttClient();
@@ -77,4 +76,10 @@ class espMqttClient : public MqttClientSetup<espMqttClient> {
protected: protected:
espMqttClientInternals::ClientPosix _client; espMqttClientInternals::ClientPosix _client;
}; };
#elif defined(_WIN32)
class espMqttClient : public MqttClientSetup<espMqttClient> {
public:
espMqttClient();
};
#endif #endif

View File

@@ -17,7 +17,6 @@
#ifdef EMSESP_STANDALONE #ifdef EMSESP_STANDALONE
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <iostream> #include <iostream>
@@ -57,8 +56,11 @@ void ClientLoop(void * arg) {
} }
} }
#ifndef UNITY_INCLUDE_CONFIG_H
// we have another main that overrides this when using Unity in test_api.cpp
int main(int argc __attribute__((unused)), char * argv[] __attribute__((unused))) { int main(int argc __attribute__((unused)), char * argv[] __attribute__((unused))) {
setup(); setup();
std::thread t = std::thread(ClientLoop, nullptr); std::thread t = std::thread(ClientLoop, nullptr);
// while (millis() <= 10 * 1000) { // while (millis() <= 10 * 1000) {
while (1) { while (1) {
@@ -69,10 +71,7 @@ int main(int argc __attribute__((unused)), char * argv[] __attribute__((unused))
t.join(); t.join();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
#endif
// unsigned long millis() {
// return __millis;
// }
int64_t esp_timer_get_time() { int64_t esp_timer_get_time() {
return __millis; return __millis;

View File

@@ -32,6 +32,10 @@
#include <iostream> #include <iostream>
#include "WString.h" #include "WString.h"
#include "Network.h"
extern ETHClass ETH;
extern WiFiClass WiFi;
typedef double double_t; typedef double double_t;
@@ -86,6 +90,21 @@ int vsnprintf_P(char * str, size_t size, const char * format, va_list ap);
#define pgm_read_float(addr) (*(const float *)(addr)) #define pgm_read_float(addr) (*(const float *)(addr))
#define pgm_read_ptr(addr) (*(const void **)(addr)) #define pgm_read_ptr(addr) (*(const void **)(addr))
// #if defined(__linux__)
#include <chrono> // NOLINT [build/c++11]
#include <thread> // NOLINT [build/c++11] for yield()
#define millis() std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()
// #endif
int64_t esp_timer_get_time();
void delay(unsigned long millis);
void yield(void);
void setup(void);
void loop(void);
class Print; class Print;
class NativeConsole : public Stream { class NativeConsole : public Stream {
@@ -94,6 +113,11 @@ class NativeConsole : public Stream {
} }
int available() override { int available() override {
#if defined(_WIN32)
// added for EMS-ESP
return 1;
#else
if (peek_ != -1) if (peek_ != -1)
return 1; return 1;
@@ -107,6 +131,7 @@ class NativeConsole : public Stream {
timeout.tv_usec = 1000; timeout.tv_usec = 1000;
return ::select(STDIN_FILENO + 1, &rfds, NULL, NULL, &timeout) > 0 ? 1 : 0; return ::select(STDIN_FILENO + 1, &rfds, NULL, NULL, &timeout) > 0 ? 1 : 0;
#endif
} }
int read() override { int read() override {
@@ -163,27 +188,6 @@ class NativeConsole : public Stream {
int peek_ = -1; int peek_ = -1;
}; };
#include "Network.h"
extern NativeConsole Serial; extern NativeConsole Serial;
extern ETHClass ETH;
extern WiFiClass WiFi;
// unsigned long millis();
#if defined(__linux__)
#include <chrono> // NOLINT [build/c++11]
#include <thread> // NOLINT [build/c++11] for yield()
#define millis() std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()
#endif
int64_t esp_timer_get_time();
void delay(unsigned long millis);
void yield(void);
void setup(void);
void loop(void);
#endif #endif

View File

@@ -86,7 +86,12 @@ class Print {
return print(str); return print(str);
} }
size_t println() { size_t println() {
// added for EMS-ESP
#if defined(_WIN32)
return print("\n");
#else
return print("\r\n"); return print("\r\n");
#endif
} }
size_t println(const char * data) { size_t println(const char * data) {
return print(data) + println(); return print(data) + println();