diff --git a/custom.mk b/custom.mk new file mode 100644 index 000000000..899f29f50 --- /dev/null +++ b/custom.mk @@ -0,0 +1,44 @@ +TARGET_EXEC ?= win_main + +BUILD_DIR ?= build +#SRC_DIRS ?= src/ src/bitmessage src/cJSON src/cmnds src/devicegroups src/driver src/hal/win32 src/httpclient src/httpserver src/jsmn src/libraries src/littlefs src/logging src/mqtt src/ota src/win32 + +SRC_DIRS ?= src/ + +EXCLUDED_FILES ?= src/httpserver/http_tcp_server.c src/ota/ota.c src/cmnds/cmd_tcp.c src/memory/memtest.c src/new_ping.c src/win_main_scriptOnly.c src/driver/drv_ir2.c src/driver/drv_ir.cpp + +SRCS := $(filter-out $(EXCLUDED_FILES), $(wildcard $(shell find $(SRC_DIRS) -not \( -path "src/hal/bl602" -prune \) -not \( -path "src/hal/xr809" -prune \) -not \( -path "src/hal/w800" -prune \) -not \( -path "src/hal/bk7231" -prune \) -name *.c | sort -k 1nr | cut -f2-))) + + +#OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +DEPS := $(OBJS:.o=.d) + +INC_DIRS := $(shell find $(SRC_DIRS) -type d) +INC_DIRS := $(filter-out src/hal/bl602 src/hal/xr809 src/hal/w800 src/hal/bk7231 src/memory, $(wildcard $(INC_DIRS))) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +LDLIBS := -lpthread -lm -lnsl + +CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -std=gnu99 -DWINDOWS -DLINUX + +CFLAGS ?= -std=gnu99 -W -Wall -Wextra -g + +$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) + @echo "Linking: $@" + $(CC) $(OBJS) -o $@ $(LDFLAGS) $(LDLIBS) + +# c source +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + @echo "Compiling: $< -> $@" + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +.PHONY: clean + +clean: + $(RM) -r $(BUILD_DIR) + +-include $(DEPS) + +MKDIR_P ?= mkdir -p \ No newline at end of file diff --git a/src/driver/drv_bmpi2c.c b/src/driver/drv_bmpi2c.c index 2eef3d1a7..5c680a22f 100644 --- a/src/driver/drv_bmpi2c.c +++ b/src/driver/drv_bmpi2c.c @@ -2,6 +2,7 @@ #include "../new_pins.h" #include "../logging/logging.h" #include "drv_local.h" +#include static byte g_secondsBetweenMeasurements = 1, g_secondsUntilNextMeasurement = 1; static int32_t g_temperature, g_calTemp = 0, g_calHum = 0, g_calPres = 0; diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index f24312c3d..2842dd01b 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -4,6 +4,9 @@ #include "freertos/task.h" #define noInterrupts() portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;taskENTER_CRITICAL(&mux) #define interrupts() taskEXIT_CRITICAL(&mux) +#elif LINUX +#define noInterrupts() +#define interrupts() #else #include #define noInterrupts() taskENTER_CRITICAL() diff --git a/src/driver/drv_openWeatherMap.c b/src/driver/drv_openWeatherMap.c index 0d0e2ed88..4f0181486 100644 --- a/src/driver/drv_openWeatherMap.c +++ b/src/driver/drv_openWeatherMap.c @@ -12,11 +12,11 @@ #include "lwip/sockets.h" #include "lwip/ip_addr.h" #include "lwip/inet.h" -#include "lwip/netdb.h" #include "../cJSON/cJSON.h" #ifndef WINDOWS #include +#include "lwip/netdb.h" #endif #ifdef WINDOWS diff --git a/src/driver/drv_spiLED.c b/src/driver/drv_spiLED.c index 77dd00fe6..e8f6ef0fa 100644 --- a/src/driver/drv_spiLED.c +++ b/src/driver/drv_spiLED.c @@ -85,7 +85,7 @@ void SPILED_InitDMA(int numBytes) { // Prepare buffer uint32_t buffer_size = spiLED.ofs + (numBytes * 4) + spiLED.padding; //Add `spiLED.ofs` bytes for "Reset" - spiLED.buf = (UINT8 *)os_malloc(sizeof(UINT8) * (buffer_size)); //18LEDs x RGB x 4Bytes + spiLED.buf = (byte *)os_malloc(sizeof(byte) * (buffer_size)); //18LEDs x RGB x 4Bytes // Fill `spiLED.ofs` slice of the buffer with zero for (i = 0; i < spiLED.ofs; i++) { diff --git a/src/driver/drv_spiLED.h b/src/driver/drv_spiLED.h index 11591804c..0066dbf9e 100644 --- a/src/driver/drv_spiLED.h +++ b/src/driver/drv_spiLED.h @@ -1,9 +1,9 @@ typedef struct spiLED_s { - UINT8 *buf; + byte *buf; struct spi_message *msg; - BOOLEAN ready; + byte ready; // Number of empty bytes to send before pixel data on each frame // Likely not needed as the data line should be LOW (reset) between frames anyway uint32_t ofs; diff --git a/src/driver/drv_spidma.h b/src/driver/drv_spidma.h index e4c64c1eb..ac8857ad5 100644 --- a/src/driver/drv_spidma.h +++ b/src/driver/drv_spidma.h @@ -19,11 +19,11 @@ struct spi_message { - UINT8*send_buf; - UINT32 send_len; + byte*send_buf; + unsigned int send_len; - UINT8*recv_buf; - UINT32 recv_len; + byte*recv_buf; + unsigned int recv_len; }; typedef int beken_semaphore_t; diff --git a/src/httpclient/utils_net.c b/src/httpclient/utils_net.c index 05e68b034..0c18c93e6 100644 --- a/src/httpclient/utils_net.c +++ b/src/httpclient/utils_net.c @@ -7,8 +7,10 @@ #include "utils_net.h" #include "errno.h" #include "lwip/sockets.h" -#include "lwip/netdb.h" #include "utils_timer.h" +#ifndef WINDOWS +#include "lwip/netdb.h" +#endif uintptr_t HAL_TCP_Establish(const char *host, uint16_t port) { diff --git a/src/httpserver/http_tcp_server_nonblocking.c b/src/httpserver/http_tcp_server_nonblocking.c index 5d8d474eb..9726e5ebe 100644 --- a/src/httpserver/http_tcp_server_nonblocking.c +++ b/src/httpserver/http_tcp_server_nonblocking.c @@ -1,14 +1,17 @@ #ifdef WINDOWS + #include "../new_common.h" #include "lwip/sockets.h" #include "lwip/ip_addr.h" #include "lwip/inet.h" #include "../logging/logging.h" #include "new_http.h" +#ifndef LINUX #include +#endif - SOCKET ListenSocket = INVALID_SOCKET; +SOCKET ListenSocket = INVALID_SOCKET; int g_httpPort = 80; @@ -19,7 +22,7 @@ int HTTPServer_Start() { struct addrinfo *result = NULL; struct addrinfo hints; - ZeroMemory(&hints, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; @@ -35,7 +38,7 @@ int HTTPServer_Start() { iResult = getaddrinfo(NULL, service, &hints, &result); if ( iResult != 0 ) { printf("getaddrinfo failed with error: %d\n", iResult); - WSACleanup(); + //WSACleanup(); return 1; } @@ -44,7 +47,7 @@ int HTTPServer_Start() { if (ListenSocket == INVALID_SOCKET) { printf("socket failed with error: %ld\n", WSAGetLastError()); freeaddrinfo(result); - WSACleanup(); + //WSACleanup(); return 1; } @@ -54,7 +57,7 @@ int HTTPServer_Start() { printf("bind failed with error: %d\n", WSAGetLastError()); freeaddrinfo(result); closesocket(ListenSocket); - WSACleanup(); + //WSACleanup(); return 1; } @@ -64,7 +67,7 @@ int HTTPServer_Start() { if (iResult == SOCKET_ERROR) { printf("listen failed with error: %d\n", WSAGetLastError()); closesocket(ListenSocket); - WSACleanup(); + //WSACleanup(); return 1; } @@ -95,7 +98,7 @@ void HTTPServer_RunQuickTick() { iResult = WSAGetLastError(); if(iResult != WSAEWOULDBLOCK) { if (iResult != g_prevHTTPResult) { - printf("accept failed with error: %d\n", iResult); + printf("HTTPServer_RunQuickTick: accept failed with error: %d\n", iResult); g_prevHTTPResult = iResult; } } @@ -205,3 +208,4 @@ void HTTPServer_RunQuickTick() { #endif + diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index 22aa6fc24..5fab08ef8 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -117,7 +117,7 @@ extern int ota_done(bool reset); #else -extern UINT32 flash_read(char* user_buf, UINT32 count, UINT32 address); +extern unsigned int flash_read(char* user_buf, unsigned int count, unsigned int address); #endif diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index 47e90ae4b..e0dcdf082 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -1268,6 +1268,7 @@ static int MQTT_do_connect(mqtt_client_t* client) // host name/ip if (NULL != hostEntry) { +#ifndef LINUX if (hostEntry->h_addr_list && hostEntry->h_addr_list[0]) { int len = hostEntry->h_length; if (len > 4) { @@ -1276,7 +1277,9 @@ static int MQTT_do_connect(mqtt_client_t* client) } memcpy(&mqtt_ip, hostEntry->h_addr_list[0], len); } - else { + else +#endif + { addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "mqtt_host resolves no addresses?\r\n"); snprintf(mqtt_status_message, sizeof(mqtt_status_message), "mqtt_host resolves no addresses?"); return 0; diff --git a/src/mqtt/new_mqtt.h b/src/mqtt/new_mqtt.h index b116c25c8..4f224a59a 100644 --- a/src/mqtt/new_mqtt.h +++ b/src/mqtt/new_mqtt.h @@ -10,7 +10,10 @@ #include "lwip/sockets.h" #include "lwip/ip_addr.h" #include "lwip/inet.h" +#ifndef WINDOWS #include "lwip/netdb.h" +#endif + #if PLATFORM_XR809 #include "my_lwip2_mqtt_replacement.h" #else diff --git a/src/new_common.h b/src/new_common.h index 22e579c32..34a5d5926 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -8,7 +8,7 @@ #include #include -#if WINDOWS +#if WINDOWS && !LINUX #include #define _CRTDBG_MAP_ALLOC #include @@ -206,9 +206,42 @@ This platform is not supported, error! #if WINDOWS #include -#include #include +#ifndef LINUX + +#include + +#else + +#include // For gethostbyname and struct hostent +#include +#include +#define closesocket close + +#endif + +#ifdef LINUX + +#define SOCKET int +#define closesocket close +#define ISVALIDSOCKET(s) ((s) >= 0) +#define GETSOCKETERRNO() (errno) +#define ioctlsocket ioctl +#define WSAEWOULDBLOCK EWOULDBLOCK +#define SOCKET_ERROR -1 +#define INVALID_SOCKET -1 +#define WSAGetLastError() (errno) +// TODO +#define SD_SEND 0 + +#elif WINDOWS + +#define ISVALIDSOCKET(s) ((s) != INVALID_SOCKET) +#define GETSOCKETERRNO() (WSAGetLastError()) + +#endif + #define portTICK_RATE_MS 1000 #define bk_printf printf @@ -717,6 +750,8 @@ typedef unsigned char byte; #define WIN32_LEAN_AND_MEAN +#ifndef LINUX + #include #include #include @@ -725,6 +760,19 @@ typedef unsigned char byte; #else +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + +#else + #include "lwip/sockets.h" #endif @@ -733,6 +781,11 @@ typedef unsigned char byte; // stricmp fix #if WINDOWS +#if LINUX + +#define stricmp strcasecmp + +#endif #else @@ -785,10 +838,12 @@ int PingWatchDog_GetTotalReceived(); int LWIP_GetMaxSockets(); int LWIP_GetActiveSockets(); +#ifndef LINUX #ifndef PLATFORM_ESPIDF //delay function do 10*r nops, because rtos_delay_milliseconds is too much void usleep(int r); #endif +#endif #define RESTARTS_REQUIRED_FOR_SAFE_MODE 4 diff --git a/src/obk_config.h b/src/obk_config.h index 6c7de5b0d..e08943570 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -71,6 +71,14 @@ #elif WINDOWS +#if LINUX + +#else + +#define ENABLE_SDL_WINDOW 1 + +#endif + #define ENABLE_HA_DISCOVERY 1 #define ENABLE_SEND_POSTANDGET 1 diff --git a/src/selftest/selftest_local.h b/src/selftest/selftest_local.h index 5e4eb40d6..2b70fa02b 100644 --- a/src/selftest/selftest_local.h +++ b/src/selftest/selftest_local.h @@ -60,37 +60,12 @@ void SelfTest_Failed(const char *file, const char *function, int line, const cha #define SELFTEST_ASSERT_HAS_UART_EMPTY() SELFTEST_ASSERT(SIM_UART_GetDataSize()==0); //#define FLOAT_EQUALS (a,b) (fabs(a-b)<0.001f) -inline float myFabs(float f) { - if (f < 0) - return -f; - return f; -} -inline bool Float_Equals(float a, float b) { - float res = myFabs(a - b); - return res < 0.001f; -} -inline bool Float_EqualsEpsilon(float a, float b, float epsilon) { - float res = myFabs(a - b); - return res < epsilon; -} +float myFabs(float f); +bool Float_Equals(float a, float b); +bool Float_EqualsEpsilon(float a, float b, float epsilon); -#define VA_BUFFER_SIZE 4096 -#define VA_COUNT 4 -inline const char *va(const char *fmt, ...) { - va_list argList; - static int whi = 0; - static char buffer[VA_COUNT][VA_BUFFER_SIZE]; - - whi++; - whi %= VA_COUNT; - char *p = buffer[whi]; - - va_start(argList, fmt); - vsnprintf(p, VA_BUFFER_SIZE, fmt, argList); - va_end(argList); - return p; -} +const char *va(const char *fmt, ...); void Test_Battery(); void Test_Flash_Search(); @@ -164,7 +139,7 @@ void Test_GetJSONValue_Setup(const char *text); void Test_FakeHTTPClientPacket_GET(const char *tg); void Test_FakeHTTPClientPacket_POST(const char *tg, const char *data); void Test_FakeHTTPClientPacket_POST_withJSONReply(const char *tg, const char *data); -void Test_FakeHTTPClientPacket_JSON(const char *tg, ...); +void Test_FakeHTTPClientPacket_JSON(const char *tg); const char *Test_GetLastHTMLReply(); bool SIM_HasHTTPTemperature(); diff --git a/src/selftest/selftest_main.c b/src/selftest/selftest_main.c index e983d9057..b00b20c8d 100644 --- a/src/selftest/selftest_main.c +++ b/src/selftest/selftest_main.c @@ -8,7 +8,7 @@ int g_selfTestsMode = 0; void SelfTest_Failed(const char *file, const char *function, int line, const char *exp) { g_selfTestErrors++; - printf("ERROR: SelfTest failed for %s\n", exp); + printf("ERROR: SelfTest assertion failed for %s\n", exp); printf("Check %s - %s - line %i\n", file, function, line); printf("Total SelfTest errors so far: %i\n", g_selfTestErrors); diff --git a/src/sim/sim_local.h b/src/sim/sim_local.h index 61367ecea..a6cd17fc9 100644 --- a/src/sim/sim_local.h +++ b/src/sim/sim_local.h @@ -10,8 +10,18 @@ #include #include #include + +#ifdef LINUX + +#include + +#else + #include #include + +#endif + #include #include diff --git a/src/win32/stubs/flash_pub.h b/src/win32/stubs/flash_pub.h index 2ff347a0a..e5c6cd022 100644 --- a/src/win32/stubs/flash_pub.h +++ b/src/win32/stubs/flash_pub.h @@ -1,10 +1,21 @@ #ifndef _FLASH_PUB_H #define _FLASH_PUB_H +#ifndef LINUX + #include +#include + +#else + +#define UINT8 uint8_t +#define UINT16 uint16_t +#define UINT32 uint32_t + +#endif + #include #include -#include #define FLASH_DEV_NAME ("flash") diff --git a/src/win32/stubs/lwip/netdb.h b/src/win32/stubs/lwip/netdb.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/win32/stubs/lwip/win_mqtt_stub.c b/src/win32/stubs/lwip/win_mqtt_stub.c index 8cb41dedd..e2ca89344 100644 --- a/src/win32/stubs/lwip/win_mqtt_stub.c +++ b/src/win32/stubs/lwip/win_mqtt_stub.c @@ -15,6 +15,8 @@ #define LWIP_ASSERT_CORE_LOCKED(); #define LWIP_ASSERT(a,b); + + typedef struct altcp_pcb { SOCKET sock; } altcp_pcb; @@ -458,9 +460,9 @@ err_t mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t //Create a socket - if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) + if (!ISVALIDSOCKET(s = socket(AF_INET, SOCK_STREAM, 0))) { - printf("Could not create socket : %d", WSAGetLastError()); + printf("Could not create socket : %d", GETSOCKETERRNO()); } printf("Socket created.\n"); @@ -474,7 +476,7 @@ err_t mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t unsigned long nonBlocking = 1; if (ioctlsocket(s, FIONBIO, &nonBlocking) != 0) { - printf("ioctlsocket failed with error: %d\n", WSAGetLastError()); + printf("ioctlsocket failed with error: %d\n", GETSOCKETERRNO()); return 1; } int aliveToggle = 1; @@ -1373,7 +1375,7 @@ void WIN_RunMQTTClient(mqtt_client_t *cl) { time.tv_usec = 0; if (select(0, NULL, &fd, NULL, &time) == 1) { int error = 0; - int len = sizeof(error); + unsigned int len = sizeof(error); getsockopt(cl->conn->sock, SOL_SOCKET, SO_ERROR, (char*)&error, &len); if (error == 0) { printf("MQTT: Connected!\n"); @@ -1399,7 +1401,7 @@ void WIN_RunMQTTClient(mqtt_client_t *cl) { mqtt_parse_incoming(cl, &buf); } else { - err = WSAGetLastError(); + err = GETSOCKETERRNO(); if (err == WSAEWOULDBLOCK) { } diff --git a/src/win32/stubs/inttypes.h b/src/win32/stubs/win_inttypes.h similarity index 100% rename from src/win32/stubs/inttypes.h rename to src/win32/stubs/win_inttypes.h diff --git a/src/win32/stubs/win_rtos_stub.c b/src/win32/stubs/win_rtos_stub.c index 272a421b8..0118fee34 100644 --- a/src/win32/stubs/win_rtos_stub.c +++ b/src/win32/stubs/win_rtos_stub.c @@ -1,8 +1,28 @@ #ifdef WINDOWS #include "../../new_common.h" + +#ifndef LINUX + #include +#define GETSOCKETERRNO() (WSAGetLastError()) + +#else + +#include + +#define timeGetTime() time(NULL) +#define DWORD uint + +#define SOCKET_ERROR SO_ERROR +#define Sleep sleep +#define ioctlsocket ioctl +#define closesocket close +#define GETSOCKETERRNO() (errno) + +#endif + DWORD startTime = 0; int xSemaphoreTake(int semaphore, int blockTime) { @@ -14,11 +34,16 @@ int xSemaphoreCreateMutex() { int xSemaphoreGive(int semaphore) { return 0; } +extern int g_selfTestsMode; int rtos_delay_milliseconds(int sec) { + if (g_selfTestsMode) + return; Sleep(sec); return 0; } int delay_ms(int sec) { + if (g_selfTestsMode) + return; Sleep(sec); return 0; } @@ -57,11 +82,20 @@ int hal_machw_time_past(int tt) { return 0; return 1; } + +#ifndef LINUX int rtos_create_thread(int *out, int prio, const char *name, LPTHREAD_START_ROUTINE function, int stackSize, void *arg) { int handle; handle = CreateThread(NULL, 0, function, arg, 0, NULL); return 0; } +#else +int rtos_create_thread(int *out, int prio, const char *name, void *function, int stackSize, void *arg) { + pthread_t handle; + pthread_create(&handle, NULL, function, (arg) != 0); + return 0; +} +#endif void rtos_delete_thread(int i) { } @@ -73,7 +107,7 @@ int lwip_fcntl(int s, int cmd, int val) { FIONBIO, &argp) == SOCKET_ERROR) { - printf("ioctlsocket() error %d\n", WSAGetLastError()); + printf("ioctlsocket() error %d\n", GETSOCKETERRNO()); return 1; } diff --git a/src/win32/stubs/stdint.h b/src/win32/stubs/win_stdint.h similarity index 100% rename from src/win32/stubs/stdint.h rename to src/win32/stubs/win_stdint.h diff --git a/src/win_main.c b/src/win_main.c index 25f804aae..8742d1e98 100644 --- a/src/win_main.c +++ b/src/win_main.c @@ -1,26 +1,45 @@ +#ifdef __GNUC__ +#define __cdecl __attribute__((__cdecl__)) +#endif + #ifdef WINDOWS #undef UNICODE #define WIN32_LEAN_AND_MEAN + +#ifndef LINUX + #include #define _CRTDBG_MAP_ALLOC #include #include #include #include +#include + +#else + +#include +#include +#include + +#define Sleep sleep + +#endif + #include #include #include "obk_config.h" #include "new_common.h" +#include "driver/drv_public.h" +#include "cmnds/cmd_public.h" +#include "httpserver/new_http.h" #include "quicktick.h" -#include "driver\drv_public.h" -#include "cmnds\cmd_public.h" -#include "httpserver\new_http.h" -#include "hal\hal_flashVars.h" -#include "selftest\selftest_local.h" +#include "hal/hal_flashVars.h" +#include "selftest/selftest_local.h" #include "new_pins.h" -#include + #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) @@ -36,6 +55,21 @@ int g_simulatedTimeNow = 0; extern int g_httpPort; #define DEFAULT_FRAME_TIME 5 +#if LINUX + +#include +#include + +uint32_t timeGetTime() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint32_t)((ts.tv_sec * 1000) + (ts.tv_nsec / 1000000)); +} + +void vTaskDelay(int x) { + +} +#endif void strcat_safe_test(){ char tmpA[16]; @@ -240,9 +274,60 @@ int g_bDoingUnitTestsNow = 0; int SelfTest_GetNumErrors(); extern int g_selfTestsMode; +float myFabs(float f) { + if (f < 0) + return -f; + return f; +} +bool Float_Equals(float a, float b) { + float res = myFabs(a - b); + return res < 0.001f; +} +bool Float_EqualsEpsilon(float a, float b, float epsilon) { + float res = myFabs(a - b); + return res < epsilon; +} +#define VA_BUFFER_SIZE 4096 +#define VA_COUNT 4 +const char *va(const char *fmt, ...) { + va_list argList; + static int whi = 0; + static char buffer[VA_COUNT][VA_BUFFER_SIZE]; + + whi++; + whi %= VA_COUNT; + char *p = buffer[whi]; + + va_start(argList, fmt); + vsnprintf(p, VA_BUFFER_SIZE, fmt, argList); + va_end(argList); + return p; +} + + +#ifdef LINUX +// fixes - temp +#endif + +#if !ENABLE_SDL_WINDOW +bool SIM_ReadDHT11(int pin, byte *data) { + return false; +} +void Sim_SendFakeBL0942Packet(float v, float c, float p) { + +} +void SIM_GeneratePowerStateDesc(char *o, int outLen) { + *o = 0; +} +#endif + int __cdecl main(int argc, char **argv) { - + bool bWantsUnitTests = 1; + +#ifndef LINUX + WSADATA wsaData; +#endif // clear debug data if (1) { FILE *f = fopen("sim_lastPublishes.txt", "wb"); @@ -251,6 +336,7 @@ int __cdecl main(int argc, char **argv) fclose(f); } } + printf("Argc: %i\n", argc); if (argc > 1) { int value; @@ -266,14 +352,18 @@ int __cdecl main(int argc, char **argv) i++; if (i < argc && sscanf(argv[i], "%d", &value) == 1) { +#if ENABLE_SDL_WINDOW SIM_SetWindowW(value); +#endif } } else if (wal_strnicmp(argv[i] + 1, "h", 1) == 0) { i++; if (i < argc && sscanf(argv[i], "%d", &value) == 1) { +#if ENABLE_SDL_WINDOW SIM_SetWindowH(value); +#endif } } else if (wal_strnicmp(argv[i] + 1, "runUnitTests", 12) == 0) { @@ -287,8 +377,8 @@ int __cdecl main(int argc, char **argv) } } } + printf("g_selfTestsMode %i\n", g_selfTestsMode); - WSADATA wsaData; int iResult; #if 0 @@ -300,12 +390,14 @@ int __cdecl main(int argc, char **argv) printf("Brightness %f with color %f gives %f\n", in, 255.0f, res); } #endif +#ifndef LINUX // Initialize Winsock iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); return 1; } +#endif printf("sizeof(short) = %d\n", (int)sizeof(short)); printf("sizeof(int) = %d\n", (int)sizeof(int)); printf("sizeof(long) = %d\n", (int)sizeof(long)); @@ -420,7 +512,9 @@ int __cdecl main(int argc, char **argv) // Test expansion //CMD_UART_Send_Hex(0,0,"FFAA$CH1$BB",0); +#ifndef LINUX _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF); +#endif if (g_selfTestsMode) { g_bDoingUnitTestsNow = 1; @@ -437,7 +531,10 @@ int __cdecl main(int argc, char **argv) } +#if ENABLE_SDL_WINDOW SIM_CreateWindow(argc, argv); +#endif + #if 1 CMD_ExecuteCommand("MQTTHost 192.168.0.113", 0); CMD_ExecuteCommand("MqttPassword ma1oovoo0pooTie7koa8Eiwae9vohth1vool8ekaej8Voohi7beif5uMuph9Diex", 0); @@ -456,7 +553,7 @@ int __cdecl main(int argc, char **argv) while (1) { Sleep(DEFAULT_FRAME_TIME); Sim_RunFrame(DEFAULT_FRAME_TIME); - SIM_RunWindow(); + //SIM_RunWindow(); } } else { @@ -467,7 +564,7 @@ int __cdecl main(int argc, char **argv) if (g_delta <= 0) continue; Sim_RunFrame(g_delta); - SIM_RunWindow(); + //SIM_RunWindow(); prev_time = cur_time; } } @@ -500,5 +597,8 @@ int ota_total_bytes() { return 0; } -#endif + + + +#endif \ No newline at end of file diff --git a/src/win_stubs.c b/src/win_stubs.c index a4d931043..8b7df8285 100644 --- a/src/win_stubs.c +++ b/src/win_stubs.c @@ -23,8 +23,14 @@ char myIP[] = "127.0.0.1"; char *getMyIp() { return myIP; } + +#ifndef LINUX void __asm__(const char *s) { } +#else + +#endif + #endif \ No newline at end of file