diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c index 78670c125..0c25e226e 100644 --- a/src/httpserver/http_tcp_server.c +++ b/src/httpserver/http_tcp_server.c @@ -5,7 +5,17 @@ #include "lwip/inet.h" #include "../logging/logging.h" #include "new_http.h" +#if PLATFORM_XR809 + +#define kNoErr 0 //! No error occurred. +typedef void *beken_thread_arg_t; +typedef int OSStatus; + +static OS_Thread_t g_http_thread; + +#else #include "str_pub.h" +#endif static void tcp_server_thread( beken_thread_arg_t arg ); static void tcp_client_thread( beken_thread_arg_t arg ); @@ -16,11 +26,20 @@ void start_tcp_http() { OSStatus err = kNoErr; +#if PLATFORM_XR809 + err = OS_ThreadCreate(&g_http_thread, + "TCP_server", + tcp_server_thread, + NULL, + OS_THREAD_PRIO_CONSOLE, + 0x800); +#else err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY, "TCP_server", (beken_thread_function_t)tcp_server_thread, 0x800, (beken_thread_arg_t)0 ); +#endif if(err != kNoErr) { ADDLOG_ERROR(LOG_FEATURE_HTTP, "create \"TCP_server\" thread failed!\r\n"); @@ -93,8 +112,12 @@ exit: if ( reply != NULL ) os_free( reply ); - close( fd ); - rtos_delete_thread( NULL ); + close( fd );; +#if PLATFORM_XR809 + OS_ThreadDelete( NULL ); +#else + rtos_delete_thread( NULL ); +#endif } /* TCP server listener thread */ @@ -131,12 +154,24 @@ static void tcp_server_thread( beken_thread_arg_t arg ) { os_strcpy( client_ip_str, inet_ntoa( client_addr.sin_addr ) ); ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP Client %s:%d connected, fd: %d", client_ip_str, client_addr.sin_port, client_fd ); - if ( kNoErr - != rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY, + if ( kNoErr != +#if PLATFORM_XR809 + OS_ThreadCreate(&g_http_thread, + "TCP Clients", + tcp_client_thread, + client_fd, + OS_THREAD_PRIO_CONSOLE, + 0x800) + +#else + rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY, "TCP Clients", (beken_thread_function_t)tcp_client_thread, 0x800, - (beken_thread_arg_t)client_fd ) ) + (beken_thread_arg_t)client_fd ) + +#endif + ) { close( client_fd ); client_fd = -1; @@ -149,5 +184,9 @@ static void tcp_server_thread( beken_thread_arg_t arg ) ADDLOG_ERROR(LOG_FEATURE_HTTP, "Server listerner thread exit with err: %d", err ); close( tcp_listen_fd ); +#if PLATFORM_XR809 + OS_ThreadDelete( NULL ); +#else rtos_delete_thread( NULL ); +#endif } diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 552ffd635..4c5ca9788 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -2,13 +2,16 @@ #include "../new_common.h" #include "ctype.h" -#ifndef WINDOWS -#include "lwip/sockets.h" -#include "str_pub.h" -#else +#if WINDOWS //#include #include //#include +#elif PLATFORM_XR809 +#include + +#else +#include "lwip/sockets.h" +#include "str_pub.h" #endif #include "new_http.h" #include "../new_pins.h" @@ -16,6 +19,8 @@ #include "../ota/ota.h" #ifdef WINDOWS +#elif PLATFORM_XR809 + #elif defined(PLATFORM_BK7231N) // tuya-iotos-embeded-sdk-wifi-ble-bk7231n/sdk/include/tuya_hal_storage.h #include "tuya_hal_storage.h" @@ -658,6 +663,9 @@ int HTTP_ProcessPacket(http_request_t *request) { #ifdef WINDOWS poststr(request,"Not available on Windows
"); +#elif PLATFORM_XR809 + poststr(request,"TODO XR809
"); + #else AP_IF_S *ar; uint32_t num; diff --git a/src/httpserver/new_http.h b/src/httpserver/new_http.h index 635fc680a..d4a0b8b59 100644 --- a/src/httpserver/new_http.h +++ b/src/httpserver/new_http.h @@ -55,7 +55,7 @@ void misc_formatUpTimeString(int totalSeconds, char *o); // poststr with format - for results LESS THAN 128 int hprintf128(http_request_t *request, const char *fmt, ...); -enum { +typedef enum { HTTP_ANY = -1, HTTP_GET = 0, HTTP_PUT = 1, diff --git a/src/logging/logging.h b/src/logging/logging.h index 986b34e92..2a905bce2 100644 --- a/src/logging/logging.h +++ b/src/logging/logging.h @@ -30,7 +30,7 @@ extern int direct_serial_log; #define DEFAULT_DIRECT_SERIAL_LOG 0 //#define DEFAULT_DIRECT_SERIAL_LOG 1 -enum { +typedef enum { LOG_NONE = 0, LOG_ERROR = 1, LOG_WARN = 2, @@ -40,7 +40,7 @@ enum { LOG_MAX = 6 } log_levels; -enum { +typedef enum { LOG_FEATURE_HTTP = 0, LOG_FEATURE_MQTT = 1, LOG_FEATURE_CFG = 2, diff --git a/src/new_cfg.c b/src/new_cfg.c index 6f18716bf..43c19e6a7 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -5,6 +5,8 @@ #if WINDOWS +#elif PLATFORM_XR809 + #else #include "../../beken378/func/include/net_param_pub.h" #include "../../beken378/app/config/param_config.h" @@ -35,6 +37,8 @@ void CFG_CreateDeviceNameUnique() unsigned char mac[32]; #if WINDOWS +#elif PLATFORM_XR809 + mac[0] = 'A'; mac[1] = 'B'; mac[2] = 'A'; mac[3] = 'B'; mac[4] = 'A'; mac[5] = 'B'; #else wifi_get_mac_address((char *)mac, CONFIG_ROLE_STA); #endif @@ -94,6 +98,8 @@ void CFG_SetMQTTPass(const char *s) { void CFG_SaveWiFi() { #if WINDOWS +#elif PLATFORM_XR809 + #else ITEM_NEW_WIFI_CONFIG container; strcpy_safe(container.ssid, g_wifi_ssid, sizeof(container.ssid)); @@ -104,6 +110,8 @@ void CFG_SaveWiFi() { void CFG_LoadWiFi() { #if WINDOWS +#elif PLATFORM_XR809 + #else ITEM_NEW_WIFI_CONFIG container; if(get_info_item(NEW_WIFI_CONFIG,(UINT8 *)&container, 0, 0) != 0) { @@ -116,6 +124,8 @@ void CFG_LoadWiFi() { void CFG_SaveMQTT() { #if WINDOWS +#elif PLATFORM_XR809 + #else ITEM_NEW_MQTT_CONFIG container; strcpy_safe(container.userName, g_mqtt_userName, sizeof(container.userName)); @@ -130,6 +140,8 @@ void CFG_SaveMQTT() { void CFG_LoadMQTT() { #if WINDOWS +#elif PLATFORM_XR809 + #else ITEM_NEW_MQTT_CONFIG container; if(get_info_item(NEW_MQTT_CONFIG,(UINT8 *)&container, 0, 0) != 0) { diff --git a/src/new_common.h b/src/new_common.h index 416dc553b..afc8303de 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -17,6 +17,26 @@ typedef unsigned char u8; typedef unsigned char uint8_t; typedef unsigned int uint32_t; +#elif PLATFORM_XR809 + +typedef int bool; +#define true 1 +#define false 0 + +#define PR_NOTICE printf +typedef unsigned char u8; +typedef unsigned char uint8_t; +typedef unsigned int uint32_t; + +#include +#include +#include +#include + +#include "common/framework/platform_init.h" + +#include "kernel/os/os.h" + #else #define _TUYA_DEVICE_GLOBAL diff --git a/src/new_pins.c b/src/new_pins.c index 10b9f266a..4c9172a19 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -8,6 +8,8 @@ #if WINDOWS +#elif PLATFORM_XR809 + #else #include @@ -64,6 +66,8 @@ unsigned char g_channelValues[GPIO_MAX] = { 0 }; #ifdef WINDOWS +#elif PLATFORM_XR809 + #else BUTTON_S g_buttons[GPIO_MAX]; @@ -76,6 +80,9 @@ void (*g_doubleClickCallback)(int pinIndex) = 0; void PIN_SaveToFlash() { #if WINDOWS + +#elif PLATFORM_XR809 + #else save_info_item(NEW_PINS_CONFIG,(UINT8 *)&g_pins, 0, 0); #endif @@ -88,6 +95,9 @@ void PIN_LoadFromFlash() { PR_NOTICE("UART log breaking after that means that you changed the role of TX pin to digital IO or smth else.\r\n"); #if WINDOWS + +#elif PLATFORM_XR809 + #else get_info_item(NEW_PINS_CONFIG,(UINT8 *)&g_pins, 0, 0); #endif @@ -108,6 +118,8 @@ int PIN_GetPinChannelForPinIndex(int index) { void RAW_SetPinValue(int index, int iVal){ #if WINDOWS +#elif PLATFORM_XR809 + #else bk_gpio_output(index, iVal); #endif @@ -135,6 +147,8 @@ unsigned char button_generic_get_gpio_value(void *param) { #if WINDOWS return 0; +#elif PLATFORM_XR809 + return 0; #else int index = ((BUTTON_S*)param) - g_buttons; return bk_gpio_input(index); @@ -160,6 +174,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { case IOR_Button_n: #if WINDOWS +#elif PLATFORM_XR809 + #else { //BUTTON_S *bt = &g_buttons[index]; @@ -173,6 +189,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { case IOR_Relay_n: #if WINDOWS +#elif PLATFORM_XR809 + #else // TODO: disable? #endif @@ -186,6 +204,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { pwmIndex = PIN_GetPWMIndexForPinIndex(index); #if WINDOWS +#elif PLATFORM_XR809 + #elif PLATFORM_BK7231N #else @@ -207,6 +227,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { case IOR_Button_n: #if WINDOWS +#elif PLATFORM_XR809 + #else { BUTTON_S *bt = &g_buttons[index]; @@ -225,6 +247,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { case IOR_Relay_n: #if WINDOWS +#elif PLATFORM_XR809 + #else bk_gpio_config_output(index); bk_gpio_output(index, 0); @@ -240,6 +264,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { channelIndex = PIN_GetPinChannelForPinIndex(index); #if WINDOWS +#elif PLATFORM_XR809 + #elif PLATFORM_BK7231N #else @@ -293,6 +319,8 @@ void Channel_OnChanged(int ch) { #if WINDOWS +#elif PLATFORM_XR809 + #elif PLATFORM_BK7231N #else @@ -348,6 +376,8 @@ bool CHANNEL_Check(int ch) { #if WINDOWS +#elif PLATFORM_XR809 + #else #define EVENT_CB(ev) if(handle->cb[ev])handle->cb[ev]((BUTTON_S*)handle)