xr809 support - initial version

This commit is contained in:
openshwprojects
2022-02-12 23:31:57 +01:00
parent 1e5c0bc7c7
commit ccc2f92f6e
3 changed files with 47 additions and 3 deletions

View File

@ -1,3 +1,8 @@
#if PLATFORM_XR809
#define LWIP_COMPAT_SOCKETS 1
#define LWIP_POSIX_SOCKETS_IO_NAMES 1
#endif
#include "../new_common.h"
#include "ctype.h"
#include "lwip/sockets.h"
@ -5,18 +10,26 @@
#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;
#define close lwip_close
static OS_Thread_t g_http_thread;
#else
#include "str_pub.h"
#endif
#if PLATFORM_XR809
#define DISABLE_SEPARATE_THREAD_FOR_EACH_TCP_CLIENT 1
#endif
static void tcp_server_thread( beken_thread_arg_t arg );
static void tcp_client_thread( beken_thread_arg_t arg );
@ -113,11 +126,15 @@ exit:
os_free( reply );
close( fd );;
#if DISABLE_SEPARATE_THREAD_FOR_EACH_TCP_CLIENT
#else
#if PLATFORM_XR809
OS_ThreadDelete( NULL );
#else
rtos_delete_thread( NULL );
#endif
#endif
}
/* TCP server listener thread */
@ -152,16 +169,25 @@ static void tcp_server_thread( beken_thread_arg_t arg )
client_fd = accept( tcp_listen_fd, (struct sockaddr *) &client_addr, &sockaddr_t_size );
if ( client_fd >= 0 )
{
#if PLATFORM_XR809
OS_Thread_t clientThreadUnused ;
#endif
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 DISABLE_SEPARATE_THREAD_FOR_EACH_TCP_CLIENT
// Use main server thread (blocking all other clients)
// right now, I am getting OS_ThreadCreate everytime on XR809 platform
tcp_client_thread(client_fd);
#else
// Create separate thread for client
if ( kNoErr !=
#if PLATFORM_XR809
OS_ThreadCreate(&g_http_thread,
OS_ThreadCreate(&clientThreadUnused,
"TCP Clients",
tcp_client_thread,
client_fd,
OS_THREAD_PRIO_CONSOLE,
0x800)
0x400)
#else
rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
@ -173,9 +199,11 @@ static void tcp_server_thread( beken_thread_arg_t arg )
#endif
)
{
ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP Client %s:%d thread creation failed! fd: %d", client_ip_str, client_addr.sin_port, client_fd );
close( client_fd );
client_fd = -1;
}
#endif
}
}
}

View File

@ -2,6 +2,7 @@
#include "../new_common.h"
#include "ctype.h"
#include "lwip/sockets.h"
#if WINDOWS
//#include <windows.h>
#include <winsock2.h>
@ -10,7 +11,6 @@
#include <stdarg.h>
#else
#include "lwip/sockets.h"
#include "str_pub.h"
#endif
#include "new_http.h"
@ -742,7 +742,13 @@ int HTTP_ProcessPacket(http_request_t *request) {
} else {
now = rem;
}
#if PLATFORM_XR809
res = 0;
now = 0;
rem = 0;
#else
res = tuya_hal_flash_read (nowOfs, buffer,now);
#endif
for(i = 0; i < now; i++) {
sprintf(tmpA,"%02X ",buffer[i]);
poststr(request,tmpA);
@ -1103,6 +1109,8 @@ int HTTP_ProcessPacket(http_request_t *request) {
poststr(request,tmpB);
#if WINDOWS
#elif PLATFORM_XR809
#else
otarequest(tmpA);
#endif