mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2025-10-30 03:54:40 +00:00
Port Simulator to Linux - p1
* intial makefile for windows sim * netdb * tr * fx * fxes * fxes * fxes f * fxes * fxes * fxes * fx * fx * fxes? * fxes * better? * stubs * more * fxes * fx? * comment out sleep * but only in self test * add assertion keyword --------- Co-authored-by: Alexandre Oliveira <rockytvbr@gmail.com>
This commit is contained in:
parent
5810db7ae1
commit
2d43185902
44
custom.mk
Normal file
44
custom.mk
Normal file
@ -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
|
||||
@ -2,6 +2,7 @@
|
||||
#include "../new_pins.h"
|
||||
#include "../logging/logging.h"
|
||||
#include "drv_local.h"
|
||||
#include <limits.h>
|
||||
|
||||
static byte g_secondsBetweenMeasurements = 1, g_secondsUntilNextMeasurement = 1;
|
||||
static int32_t g_temperature, g_calTemp = 0, g_calHum = 0, g_calPres = 0;
|
||||
|
||||
@ -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 <task.h>
|
||||
#define noInterrupts() taskENTER_CRITICAL()
|
||||
|
||||
@ -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 <lwip/dns.h>
|
||||
#include "lwip/netdb.h"
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
||||
@ -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++) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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 <timeapi.h>
|
||||
#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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#if WINDOWS
|
||||
#if WINDOWS && !LINUX
|
||||
#include <crtdbg.h>
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
@ -206,9 +206,42 @@ This platform is not supported, error!
|
||||
#if WINDOWS
|
||||
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef LINUX
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <netdb.h> // For gethostbyname and struct hostent
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#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 <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
@ -725,6 +760,19 @@ typedef unsigned char byte;
|
||||
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -10,8 +10,18 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#ifdef LINUX
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
|
||||
@ -1,10 +1,21 @@
|
||||
#ifndef _FLASH_PUB_H
|
||||
#define _FLASH_PUB_H
|
||||
|
||||
#ifndef LINUX
|
||||
|
||||
#include <conio.h>
|
||||
#include <BaseTsd.h>
|
||||
|
||||
#else
|
||||
|
||||
#define UINT8 uint8_t
|
||||
#define UINT16 uint16_t
|
||||
#define UINT32 uint32_t
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <BaseTsd.h>
|
||||
|
||||
#define FLASH_DEV_NAME ("flash")
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,28 @@
|
||||
#ifdef WINDOWS
|
||||
|
||||
#include "../../new_common.h"
|
||||
|
||||
#ifndef LINUX
|
||||
|
||||
#include <timeapi.h>
|
||||
|
||||
#define GETSOCKETERRNO() (WSAGetLastError())
|
||||
|
||||
#else
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
122
src/win_main.c
122
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 <crtdbg.h>
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <timeapi.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define Sleep sleep
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#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 <timeapi.h>
|
||||
|
||||
|
||||
#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 <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
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
|
||||
@ -23,8 +23,14 @@ char myIP[] = "127.0.0.1";
|
||||
char *getMyIp() {
|
||||
return myIP;
|
||||
}
|
||||
|
||||
#ifndef LINUX
|
||||
void __asm__(const char *s) {
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user