Improve gecko logging over WiFi

This commit is contained in:
wiidev 2021-02-04 16:27:18 +00:00
parent bd9e707e6c
commit 27bce4d461

View File

@ -23,16 +23,22 @@
*
* for WiiXplorer 2010
***************************************************************************/
#include <errno.h>
#include <network.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <network.h>
#define DESTINATION_IP "192.168.1.255"
#define DESTINATION_PORT 4405
#define GPRINTF_SIZE 256
#define WIFIGECKO_SIZE 1024
char wifigeckobuffer[WIFIGECKO_SIZE];
static int connection = -1;
void WifiGecko_Close()
@ -69,45 +75,31 @@ int WifiGecko_Connect()
int WifiGecko_Send(const char *data, int datasize)
{
if ((strlen(wifigeckobuffer) + datasize) < WIFIGECKO_SIZE)
strcat(wifigeckobuffer, data);
if (WifiGecko_Connect() < 0)
return connection;
int ret = 0, done = 0, blocksize = 1024;
u32 sendsize = strlen(wifigeckobuffer);
while (done < datasize)
{
if(blocksize > datasize-done)
blocksize = datasize-done;
ret = net_send(connection, data+done, blocksize, 0);
while (net_get_status() == -EBUSY)
usleep(10000);
int ret = net_send(connection, wifigeckobuffer, sendsize, 0);
if (ret < 0)
{
WifiGecko_Close();
return ret;
}
else if(ret == 0)
{
break;
}
done += ret;
usleep (1000);
}
memset(wifigeckobuffer, 0, WIFIGECKO_SIZE);
return ret;
}
void wifi_printf(const char *format, ...)
{
char * tmp = NULL;
char gprintfBuffer[GPRINTF_SIZE];
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
WifiGecko_Send(tmp, strlen(tmp));
}
size_t len = vsnprintf(gprintfBuffer, GPRINTF_SIZE - 1, format, va);
va_end(va);
if(tmp)
free(tmp);
if (len)
WifiGecko_Send(gprintfBuffer, len);
}