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