Skip to content

Commit ed0a07e

Browse files
authored
Merge pull request #19 from zenaro147/dev-FixBufferSizeIssue
Dev fix buffer size issue
2 parents 498811a + 293b4d6 commit ed0a07e

File tree

9 files changed

+168
-24
lines changed

9 files changed

+168
-24
lines changed

README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
# PicoAdapterGB - A Mobile Adapter GB hardware emulator based on RaspberryPi Pico
22

3-
Based on: [Libmobile](https://github.com/REONTeam/libmobile) by [REON Team](https://github.com/REONTeam)
3+
<a href="https://www.buymeacoffee.com/zenaro147" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
44

5-
### Current implementations
5+
This is the first standalone implementation of [Mobile Adapter GB](https://bulbapedia.bulbagarden.net/wiki/Mobile_Game_Boy_Adapter)!
6+
<br>It's based on [Libmobile](https://github.com/REONTeam/libmobile) by [REON Team](https://github.com/REONTeam) and it's totally free from any kind of sofware. You just need to power the adapter with any power source that's provide 5v (like a power bank, a phone using an OTG, add a battery circuit, etc), and make the first configuration (using any Serial Monitor on PC/Smartphone, even the Serial Monitor from Arduino or VS Code).
7+
8+
It's possible to connect to any [REON project](https://github.com/REONTeam/reon) custom server as soon it releases.
9+
10+
## Development Status
11+
Latest Stable Release [![Release Version](https://img.shields.io/github/v/release/zenaro147/PicoAdapterGB?style=plastic)](https://github.com/zenaro147/PicoAdapterGB/releases/latest/) [![Release Date](https://img.shields.io/github/release-date/zenaro147/PicoAdapterGB?style=plastic)](https://github.com/zenaro147/PicoAdapterGB/releases/latest/)
12+
<br>Latest Development Release [![Release Version](https://img.shields.io/github/release/zenaro147/PicoAdapterGB/all.svg?style=plastic)](https://github.com/zenaro147/PicoAdapterGB/releases/) [![Release Date](https://img.shields.io/github/release-date-pre/zenaro147/PicoAdapterGB.svg?style=plastic)](https://github.com/zenaro147/PicoAdapterGB/releases/)
13+
14+
If you still have questions, ask us here or in the **REON Team Discord** [![Discord Group](https://img.shields.io/badge/chat-on%20Discord-738ADB)](https://discord.gg/mKT4pTfUqC)
15+
16+
# Current implementations
617
- `pico_esp8266_at`: A Raspberry Pi Pico implementation using an ESP8266 ESP-01 to provide WiFi connectivity.
718
- `picow`: A Raspberry Pi Pico W implementation using the internal WiFi connectivity. (recommended)
819

920
Refer to the implementation's README.md for more specific details.
1021

11-
# Link Cable Setup
22+
## Link Cable Setup
1223
```
1324
___________
1425
| 6 4 2 |
@@ -47,15 +58,18 @@ All commands are Case-Sensitive.
4758
| RELAYSERVER | Set a Relay Server that will be use during P2P communications. |
4859
| RELAYTOKEN | Set a Relay Token that will be used on Relay Server to receive a valid number to use during P2P communications. |
4960
| P2PPORT | Set a custom P2P port to use during P2P communications (Local Network only). |
50-
| UNMETERED | Set if the device will be Unmetered (useful for Pokemon Crystal). |
61+
| UNMETERED | Set if the device will be Unmetered (useful for Pokemon Crystal). Only accept 1 (true) or 0 (false). |
5162

5263
Special commands (just enter the command, without =<VALUE>):
5364
| Command | Effect |
5465
|---------------|-------------|
5566
| FORMAT_EEPROM | Format the eeprom, if necessary. |
67+
| SHOW_CONFIG | Show the actual device configuration. |
5668
| EXIT | Quit from Config Mode and Save the new values. If you change some value, the device will reboot. |
5769
| HELP | Show this command list on screen. |
5870

5971
-----------------------
60-
### What need to do:
72+
### Next steps:
6173
* Implement a native 32bits mode for GBA
74+
* Better/dynamic buffer to handle TCP data
75+

pico_esp8266_at/src/common.h

+31-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ bool isServerOpened = false;
5454
bool is32bitsMode = false;
5555

5656
//UART RX Buffer Config
57-
#define BUFF_AT_SIZE 2048 //2048 is the maximun you can receive from esp01
58-
uint8_t buffATrx[BUFF_AT_SIZE+1024+64] = {0}; // + extra bytes to hold the AT command answer echo
57+
#define BUFF_AT_SIZE 9000 //2048 is the maximun you can receive from esp01
58+
uint8_t buffATrx[BUFF_AT_SIZE+64] = {0}; // + extra bytes to hold the AT command answer echo
5959
int buffATrx_pointer = 0;
6060
uint8_t buffRecData[BUFF_AT_SIZE] = {0};
6161
int buffRecData_pointer = 0;
@@ -121,4 +121,33 @@ bool FindCommand(char * buf, char * target){
121121
return false;
122122
}
123123

124+
void parse_addr_string(struct mobile_addr *src, char *dest){
125+
struct mobile_addr4 *addr4 = (struct mobile_addr4 *)src;
126+
struct mobile_addr6 *addr6 = (struct mobile_addr6 *)src;
127+
128+
char tmpaddr[60] = {0};
129+
130+
switch (src->type) {
131+
case MOBILE_ADDRTYPE_IPV4:
132+
sprintf(tmpaddr,"%i.%i.%i.%i:%i\0", addr4->host[0], addr4->host[1], addr4->host[2], addr4->host[3], addr4->port);
133+
break;
134+
case MOBILE_ADDRTYPE_IPV6:
135+
sprintf(tmpaddr,"[%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx]:%i\0",
136+
addr6->host[0],addr6->host[1],
137+
addr6->host[2],addr6->host[3],
138+
addr6->host[4],addr6->host[5],
139+
addr6->host[6],addr6->host[7],
140+
addr6->host[8],addr6->host[9],
141+
addr6->host[10],addr6->host[11],
142+
addr6->host[12],addr6->host[13],
143+
addr6->host[14],addr6->host[15],
144+
addr6->port);
145+
break;
146+
default:
147+
sprintf(tmpaddr,"No server defined.");
148+
break;
149+
}
150+
memcpy(dest,tmpaddr,sizeof(tmpaddr));
151+
}
152+
124153
#endif

pico_esp8266_at/src/main.c

+39-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void main(){
168168
int haveRelaySrv = 0;
169169

170170
mobile_config_get_dns(mobile->adapter, &dns1, &dns2);
171+
mobile_config_get_relay(mobile->adapter, &relay);
171172

172173
while(1){
173174
printf("Enter a command: \n");
@@ -367,6 +368,41 @@ void main(){
367368
//Exit from Menu
368369
}else if(FindCommand(UserCMD,"EXIT")){
369370
break;
371+
372+
// Shows the actual device configuration
373+
}else if(FindCommand(UserCMD,"SHOW_CONFIG")){
374+
printf("NETWORK SETTINGS\n");
375+
printf("WiFi SSID: %s\n",WiFiSSID);
376+
printf("WiFi Password: %s\n",WiFiPASS);
377+
printf("\n");
378+
printf("ADAPTER SETTINGS\n");
379+
380+
char tmpSrv[60] = {0};
381+
parse_addr_string(&dns1,tmpSrv);
382+
printf("DNS Server 1: %s\n", tmpSrv);
383+
parse_addr_string(&dns2,tmpSrv);
384+
printf("DNS Server 2: %s\n", tmpSrv);
385+
parse_addr_string(&relay,tmpSrv);
386+
printf("Relay Server: %s\n", tmpSrv);
387+
388+
char tmpToken[16] = {0};
389+
mobile_config_get_relay_token(mobile->adapter,tmpToken);
390+
printf("Relay Token: ");
391+
for (int i = 0; i < sizeof(tmpToken); i++){
392+
printf("%02hhX", tmpToken[i]);
393+
}
394+
printf("\n");
395+
396+
unsigned tmpPort = 0;
397+
mobile_config_get_p2p_port(mobile->adapter,&tmpPort);
398+
printf("P2P Port: %i\n", tmpPort);
399+
400+
bool tmpUnmet = false;
401+
mobile_config_get_device(mobile->adapter,NULL,&tmpUnmet);
402+
printf("Is Unmetered: %s\n", tmpUnmet == true ? "Yes":"No");
403+
printf("\n");
404+
405+
370406
}else if(FindCommand(UserCMD,"HELP")){
371407
printf("Command Sintax: <COMMAND>=<VALUE>\n");
372408
printf("To reset/clear a parameter, leave the <VALUE> blank, for example: WIFISSID=\n");
@@ -380,9 +416,11 @@ void main(){
380416
printf("RELAYSERVER | Set a Relay Server that will be use during P2P communications.\n");
381417
printf("RELAYTOKEN | Set a Relay Token that will be used on Relay Server to receive a valid number to use during P2P communications.\n");
382418
printf("P2PPORT | Set a custom P2P port to use during P2P communications (Local Network only).\n");
383-
printf("UNMETERED | Set if the device will be Unmetered (useful for Pokemon Crystal).\n");
419+
printf("UNMETERED | Set if the device will be Unmetered (useful for Pokemon Crystal). Only accept 1 (true) or 0 (false).\n\n");
420+
384421
printf("Special commands (just enter the command, without =<VALUE>):\n");
385422
printf("FORMAT_EEPROM | Format the eeprom, if necessary.\n");
423+
printf("SHOW_CONFIG | Show the actual device configuration.\n");
386424
printf("EXIT | Quit from Config Mode and Save the new values. If you change some value, the device will reboot.\n");
387425
printf("HELP | Show this command list on screen.\n\n");
388426

picow/src/config_menu.c

+67-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ static bool main_parse_hex(unsigned char *buf, char *str, unsigned size){
6565
return true;
6666
}
6767

68+
void parse_addr_string(struct mobile_addr *src, char *dest){
69+
struct mobile_addr4 *addr4 = (struct mobile_addr4 *)src;
70+
struct mobile_addr6 *addr6 = (struct mobile_addr6 *)src;
71+
72+
char tmpaddr[60] = {0};
73+
74+
switch (src->type) {
75+
case MOBILE_ADDRTYPE_IPV4:
76+
sprintf(tmpaddr,"%i.%i.%i.%i:%i\0", addr4->host[0], addr4->host[1], addr4->host[2], addr4->host[3], addr4->port);
77+
break;
78+
case MOBILE_ADDRTYPE_IPV6:
79+
sprintf(tmpaddr,"[%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx]:%i\0",
80+
addr6->host[0],addr6->host[1],
81+
addr6->host[2],addr6->host[3],
82+
addr6->host[4],addr6->host[5],
83+
addr6->host[6],addr6->host[7],
84+
addr6->host[8],addr6->host[9],
85+
addr6->host[10],addr6->host[11],
86+
addr6->host[12],addr6->host[13],
87+
addr6->host[14],addr6->host[15],
88+
addr6->port);
89+
break;
90+
default:
91+
sprintf(tmpaddr,"No server defined.");
92+
break;
93+
}
94+
memcpy(dest,tmpaddr,sizeof(tmpaddr));
95+
}
96+
6897
// Find a string into a buffer
6998
bool FindCommand(char * buf, char * target){
7099
if(strstr(buf, target) != NULL){
@@ -104,6 +133,7 @@ void BootMenuConfig(void *user, char * wifissid, char * wifipass){
104133
unsigned char relay_token_buf[MOBILE_RELAY_TOKEN_SIZE];
105134

106135
mobile_config_get_dns(mobile->adapter, &dns1, &dns2);
136+
mobile_config_get_relay(mobile->adapter, &relay);
107137

108138
while(1){
109139
printf("Enter a command: \n");
@@ -303,6 +333,40 @@ void BootMenuConfig(void *user, char * wifissid, char * wifipass){
303333
//Exit from Menu
304334
}else if(FindCommand(UserCMD,"EXIT")){
305335
break;
336+
337+
// Shows the actual device configuration
338+
}else if(FindCommand(UserCMD,"SHOW_CONFIG")){
339+
printf("NETWORK SETTINGS\n");
340+
printf("WiFi SSID: %s\n",newSSID);
341+
printf("WiFi Password: %s\n",newPASS);
342+
printf("\n");
343+
printf("ADAPTER SETTINGS\n");
344+
345+
char tmpSrv[60] = {0};
346+
parse_addr_string(&dns1,tmpSrv);
347+
printf("DNS Server 1: %s\n", tmpSrv);
348+
parse_addr_string(&dns2,tmpSrv);
349+
printf("DNS Server 2: %s\n", tmpSrv);
350+
parse_addr_string(&relay,tmpSrv);
351+
printf("Relay Server: %s\n", tmpSrv);
352+
353+
char tmpToken[16] = {0};
354+
mobile_config_get_relay_token(mobile->adapter,tmpToken);
355+
printf("Relay Token: ");
356+
for (int i = 0; i < sizeof(tmpToken); i++){
357+
printf("%02hhX", tmpToken[i]);
358+
}
359+
printf("\n");
360+
361+
unsigned tmpPort = 0;
362+
mobile_config_get_p2p_port(mobile->adapter,&tmpPort);
363+
printf("P2P Port: %i\n", tmpPort);
364+
365+
bool tmpUnmet = false;
366+
mobile_config_get_device(mobile->adapter,NULL,&tmpUnmet);
367+
printf("Is Unmetered: %s\n", tmpUnmet == true ? "Yes":"No");
368+
printf("\n");
369+
306370
}else if(FindCommand(UserCMD,"HELP")){
307371
printf("Command Sintax: <COMMAND>=<VALUE>\n");
308372
printf("To reset/clear a parameter, leave the <VALUE> blank, for example: WIFISSID=\n");
@@ -316,9 +380,11 @@ void BootMenuConfig(void *user, char * wifissid, char * wifipass){
316380
printf("RELAYSERVER | Set a Relay Server that will be use during P2P communications.\n");
317381
printf("RELAYTOKEN | Set a Relay Token that will be used on Relay Server to receive a valid number to use during P2P communications.\n");
318382
printf("P2PPORT | Set a custom P2P port to use during P2P communications (Local Network only).\n");
319-
printf("UNMETERED | Set if the device will be Unmetered (useful for Pokemon Crystal).\n");
383+
printf("UNMETERED | Set if the device will be Unmetered (useful for Pokemon Crystal). Only accept 1 (true) or 0 (false).\n\n");
384+
320385
printf("Special commands (just enter the command, without =<VALUE>):\n");
321386
printf("FORMAT_EEPROM | Format the eeprom, if necessary.\n");
387+
printf("SHOW_CONFIG | Show the actual device configuration.\n");
322388
printf("EXIT | Quit from Config Mode and Save the new values. If you change some value, the device will reboot.\n");
323389
printf("HELP | Show this command list on screen.\n\n");
324390

@@ -388,10 +454,7 @@ void BootMenuConfig(void *user, char * wifissid, char * wifipass){
388454
busy_wait_ms(2*1000);
389455
RefreshConfigBuff(mobile->config_eeprom,newSSID,newPASS);
390456

391-
busy_wait_ms(1*1000);
392-
393457
printf("Please reboot the device...\n");
394-
cyw43_arch_init();
395458
while(true){
396459
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
397460
busy_wait_ms(300);

picow/src/main.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ void main(){
199199

200200
stdio_init_all();
201201
printf("Booting...\n");
202+
cyw43_arch_init();
203+
LED_ON;
202204
busy_wait_us(SEC(5));
203205

204206
#ifdef DEBUG_SIGNAL_PINS
@@ -243,10 +245,7 @@ void main(){
243245
mobile_config_load(mobile->adapter);
244246

245247
BootMenuConfig(mobile,WiFiSSID,WiFiPASS);
246-
247-
busy_wait_us(SEC(1));
248-
cyw43_arch_init();
249-
LED_ON;
248+
250249
busy_wait_us(SEC(2));
251250

252251
isConnectedWiFi = PicoW_Connect_WiFi(WiFiSSID, WiFiPASS, MS(10));
@@ -265,7 +264,7 @@ void main(){
265264
mobile->socket[i].udp_remote_port = 0;
266265
mobile->socket[i].client_status = false;
267266
memset(mobile->socket[i].buffer_rx,0x00,sizeof(mobile->socket[i].buffer_rx));
268-
memset(mobile->socket[i].buffer_tx,0x00,sizeof(mobile->socket[i].buffer_tx));
267+
//memset(mobile->socket[i].buffer_tx,0x00,sizeof(mobile->socket[i].buffer_tx));
269268
mobile->socket[i].buffer_rx_len = 0;
270269
mobile->socket[i].buffer_tx_len = 0;
271270
}

picow/src/picow_socket.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void socket_recv_udp(void * arg, struct udp_pcb *pcb, struct pbuf *p, const ip_a
2121
// p->len);
2222

2323
// Receive the buffer
24-
state->buffer_rx_len = pbuf_copy_partial(p, &state->buffer_rx, p->tot_len > BUFF_SIZE ? BUFF_SIZE : p->tot_len, 0);
24+
state->buffer_rx_len = pbuf_copy_partial(p, &state->buffer_rx, p->tot_len, 0);
2525
memset(state->udp_remote_srv,0x00,sizeof(state->udp_remote_srv));
2626
sprintf(state->udp_remote_srv, "%d.%d.%d.%d", addr->addr&0xff, (addr->addr>>8)&0xff, (addr->addr>>16)&0xff, addr->addr>>24);
2727
state->udp_remote_port = port;
@@ -86,12 +86,13 @@ err_t socket_recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
8686
if(p){
8787
if (p->tot_len > 0) {
8888
int recvsize = 0;
89-
uint8_t tmpbuff[BUFF_SIZE] ={0};
89+
// uint8_t tmpbuff[BUFF_SIZE] ={0};
9090
// printf("reading %d bytes\n", p->tot_len);
9191
// Receive the buffer
92-
recvsize = pbuf_copy_partial(p, &tmpbuff, p->tot_len, 0);
92+
recvsize = pbuf_copy_partial(p, state->buffer_rx + state->buffer_rx_len, p->tot_len, 0);
93+
9394
tcp_recved(pcb,recvsize);
94-
memcpy(state->buffer_rx + state->buffer_rx_len,tmpbuff,recvsize);
95+
// memcpy(state->buffer_rx + state->buffer_rx_len,tmpbuff,recvsize);
9596
state->buffer_rx_len = state->buffer_rx_len + recvsize;
9697
if (recvsize > 0){
9798
// printf("received %d bytes\n", recvsize);

picow/src/picow_socket.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define SOCK_TCP 1
99
#define SOCK_UDP 2
1010

11-
#define BUFF_SIZE 5632
11+
#define BUFF_SIZE 9000 //5632
1212

1313
// UDP functions
1414
// void socket_listen_udp(void *arg);

picow/src/socket_impl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void socket_impl_close(struct socket_impl *state){
8787
state->udp_remote_port = 0;
8888
state->client_status = false;
8989
memset(state->buffer_rx,0x00,sizeof(state->buffer_rx));
90-
memset(state->buffer_tx,0x00,sizeof(state->buffer_tx));
90+
//memset(state->buffer_tx,0x00,sizeof(state->buffer_tx));
9191
state->buffer_rx_len = 0;
9292
state->buffer_tx_len = 0;
9393
// printf("Socket Closed.\n");

picow/src/socket_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct socket_impl {
1111
char udp_remote_srv[46];
1212
uint8_t udp_remote_port;
1313
bool client_status;
14-
uint8_t buffer_tx[MOBILE_MAX_TRANSFER_SIZE];
14+
//uint8_t buffer_tx[MOBILE_MAX_TRANSFER_SIZE];
1515
uint8_t buffer_rx[BUFF_SIZE]; //Same as ESP-01
1616
int buffer_rx_len;
1717
int buffer_tx_len;

0 commit comments

Comments
 (0)