static int main_thread(SceSize args, void *argp) { char cmdbuf[128]; int cpos; int retv; cpos = 0; while(1){ if(usbAsyncRead(ASYNC_STDOUT, (unsigned char*)&cmdbuf[cpos], 1)<1){ sceKernelDelayThread(250000); continue; } if(cmdbuf[cpos]=='\n'){ cmdbuf[cpos] = 0; retv = parse_cmd(cmdbuf); cpos = 0; }else{ if(cpos<127) cpos++; } } sceKernelExitDeleteThread(0); return 0; }
int getDebugChar(unsigned char *ch) { int ret = 0; *ch = 0; do { ret = usbAsyncRead(ASYNC_GDB, ch, 1); } while(ret < 1); return ret; }
int usbStdinRead(char *data, int size) { int ret = 0; while(1) { ret = usbAsyncRead(ASYNC_STDOUT, (unsigned char*) data, size); if(ret < 0) { sceKernelDelayThread(250000); continue; } break; } return ret; }
int main(int argc, char *argv[]) { int chan; int running = 1; pspDebugScreenInit(); chan = usbAsyncRegister(ASYNC_ALLOC_CHAN, &g_endp); if(chan < 0) { printf("Could not allocate async channel\n"); return 0; } usbWaitForConnect(); printf("Allocated channel %d, connect to localhost port %d and start typing\n", chan, 10000 + chan); while(running) { unsigned char buf[512]; int len; len = usbAsyncRead(chan, buf, sizeof(buf)); if(len < 0) { /* Error, most likely shutdown */ break; } if(len > 0) { pspDebugScreenPrintf("Read: %.*s\n", len, buf); usbAsyncWrite(chan, buf, len); } } usbAsyncUnregister(chan); return 0; }
int usbShellReadInput(unsigned char *cli, char **argv, int max_cli, int max_arg) { int cli_pos = 0; int argc = 0; unsigned char *argstart = cli; while(1) { if(usbAsyncRead(ASYNC_SHELL, &cli[cli_pos], 1) < 1) { sceKernelDelayThread(250000); continue; } if(cli[cli_pos] == 1) { cli[cli_pos] = 0; break; } else { if(cli_pos < (max_cli-1)) { if(cli[cli_pos] == 0) { if(argc < max_arg) { argv[argc++] = (char*) argstart; argstart = &cli[cli_pos+1]; } } cli_pos++; } } } return argc; }
int main_thread(SceSize args, void *argp) { unsigned char cli[MAX_CLI]; int cli_pos = 0; usbAsyncRegister(ASYNC_SHELL, &g_endp); ttySetUsbHandler(usbShellPrint, usbStdoutPrint, usbStderrPrint); usbWaitForConnect(); psplinkPrintPrompt(); while(1) { if(usbAsyncRead(ASYNC_SHELL, &cli[cli_pos], 1) < 1) { sceKernelDelayThread(250000); continue; } if(cli[cli_pos] == '\n') { cli[cli_pos] = 0; if(psplinkParseCommand(cli) == 1) { psplinkExitShell(); } cli_pos = 0; } else { if(cli_pos < (MAX_CLI-1)) { cli_pos++; } } } return 0; }