int DRV_regTestMain(int argc, char **argv) { int status; Uint32 regAddr; Uint32 regValue; Uint32 numRegs=8; Uint32 numCols=0; Bool regDump; if(argc<2) { DRV_regTestShowUsage(argv[0]); return OSA_EFAIL; } if(strcmp(argv[1], "-w")==0) { regDump=FALSE; if(argc < 4) { DRV_regTestShowUsage(argv[0]); return OSA_EFAIL; } regAddr = xstrtoi(argv[2]); regValue = xstrtoi(argv[3]); } else { regDump=TRUE; if(argc<2) { DRV_regTestShowUsage(argv[0]); return OSA_EFAIL; } regAddr = xstrtoi(argv[1]); if(argc>2) numRegs = atoi(argv[2]); if(argc==5) { if(strcmp(argv[3], "-c")==0) numCols = atoi(argv[4]); } } status = CSL_vpssOpen(&gCSL_vpssHndl); if(status!=OSA_SOK) { OSA_ERROR("CSL_sysInit()\n"); return status; } if(regDump) { DRV_regDump(regAddr, numRegs, numCols); } else { DRV_regWrite(regAddr, regValue); } status = CSL_vpssClose(&gCSL_vpssHndl); return status; }
main() { char *input; unsigned long i; i = xstrtoi(test); printf("i is %ld %lx\n", i, i); for (i=0; i<sizeof(test); i++) { } }
//------------------------------------------------------------------------------------- // This is the init callback function. You should load and create your in-game // resources here. // //------------------------------------------------------------------------------------- void GameApp::Create() { JLOG("GameApp:Create 1"); JFileSystem::init("./"); //to avoid having subfolders JLOG("GameApp:Create 2"); JRenderer* renderer = JRenderer::GetInstance(); JLOG("GameApp:Create 3"); loadWalls("."); if (wallpapers.size()) { JLOG("GameApp:Create 4"); int rnd = (rand() % wallpapers.size()); backTex=renderer->LoadTexture(wallpapers[rnd].c_str()); if (backTex) backQuad = new JQuad(backTex, 0, 0, 480, 272); } JLOG("GameApp:Create 5"); // Load a font mFont=new JLBFont("font", 11); JLOG("GameApp:Create 6"); scroller = new TextScroller(mFont, SCREEN_WIDTH/2 - 190 , SCREEN_HEIGHT-20,380); const char * const CreditsText[] = { "Thanks to n00b81, Tyranid, devs of the PSPSDK, Hitmen, Fanjita & Noobz, psp-hacks.com", "wMenu uses the JGE++ library ( http://code.google.com/p/wagic )" }; menu = NULL; #ifdef WIN32 strcpy(dummy, "D:/Stuff/Programming/wmenu/projects/wmenu/bin/samples"); #else strcpy(dummy, "ms0:/PSP/GAME"); #endif ebootPath = dummy; JLOG("GameApp:Create 7"); JGE* engine = JGE::GetInstance(); vector<string>argv = engine->GetARGV(); int settingsAddr = 0; JLOG("GameApp:Create 8"); if (argv.size() > 1) { string hex = argv[1]; hex[8] = 0; //bug in HBL ? fprintf(stderr, "Location: 0x %s\n", hex.c_str()); settingsAddr = xstrtoi(hex.c_str(), 8); } fprintf(stderr, " settingsAddr : %d\n", settingsAddr); if (settingsAddr) { settings = (tMenuApi *) settingsAddr; ebootPath = (void *) settings->filename; } int size = sizeof(CreditsText) / sizeof(CreditsText[0]); string scroll = "wMenu 0.4 by Wololo http://wololo.net "; stringCode(scroll); scroll.append("--- HBL Info ---"); if (settings) { scroll.append(settings->VersionName); scroll.append(" by "); scroll.append(settings->Credits); scroll.append(" "); } for (int i = 0; i < size; i++) { scroll.append(CreditsText[i]); scroll.append(" "); } scroller->Add(scroll); JLOG("GameApp:Create 9"); loadFiles((char *)ebootPath); if (fileExists("menu.wav")) { menuSfx = JSoundSystem::GetInstance()->LoadSample("menu.wav"); //runSfx = JSoundSystem::GetInstance()->LoadSample("run.wav"); JSoundSystem::GetInstance()->SetSfxVolume(100); } JLOG("GameApp:Create 10"); currentGameState = GAME_STATE_NONE; }
int ioctl_main(int argc, char* argv[]) { int read_only = 0; int length = -1; int arg_size = 4; int direct_arg = 0; void *ioctl_args = NULL; uint8_t *ioctl_argp; uint8_t *ioctl_argp_save = NULL; int rem; int c; while ((c = getopt(argc, argv, "rdl:a:h")) != -1) { switch (c) { case 'r': read_only = 1; break; case 'd': direct_arg = 1; break; case 'l': length = xstrtoi(optarg, "length"); break; case 'a': arg_size = xstrtoi(optarg, "argument size"); break; case 'h': usage(); break; default: error(1, 0, "invalid option -%c", optopt); } } if (optind + 2 > argc) { usage(); } const char* device = argv[optind]; int fd; if (strcmp(device, "-") == 0) { fd = STDIN_FILENO; } else { fd = open(device, read_only ? O_RDONLY : (O_RDWR | O_SYNC)); if (fd == -1) { error(1, errno, "cannot open %s", argv[optind]); } } optind++; // IOCTL(2) wants second parameter as a signed int. // Let's let the user specify either negative numbers or large positive // numbers, for the case where ioctl number is larger than INT_MAX. errno = 0; char* endp; int ioctl_nr = UINT_MAX & strtoll(argv[optind], &endp, 0); if (errno != 0 || *endp != '\0') { error(1, errno, "couldn't parse ioctl number '%s'", argv[optind]); } optind++; if(direct_arg) { arg_size = 4; length = 4; } if(length < 0) { length = (argc - optind) * arg_size; } if(length) { ioctl_args = calloc(1, length); ioctl_argp_save = ioctl_argp = ioctl_args; rem = length; while (optind < argc) { uint64_t tmp = strtoull(argv[optind], NULL, 0); if (rem < arg_size) { error(1, 0, "too many arguments"); } memcpy(ioctl_argp, &tmp, arg_size); ioctl_argp += arg_size; rem -= arg_size; optind++; } } printf("sending ioctl 0x%x", ioctl_nr); rem = length; while(rem--) { printf(" 0x%02x", *ioctl_argp_save++); } printf(" to %s\n", device); int res; if(direct_arg) res = ioctl(fd, ioctl_nr, *(uint32_t*)ioctl_args); else if(length) res = ioctl(fd, ioctl_nr, ioctl_args); else res = ioctl(fd, ioctl_nr, 0); if (res < 0) { free(ioctl_args); error(1, errno, "ioctl 0x%x failed (returned %d)", ioctl_nr, res); } if (length) { printf("return buf:"); ioctl_argp = ioctl_args; rem = length; while(rem--) { printf(" %02x", *ioctl_argp++); } printf("\n"); } free(ioctl_args); close(fd); return 0; }
static __inline__ void do_cmd(char * s) { static char * cmd = do_cmdbuf; uint8_t index; char * args, * p; static char * can_addr; int8_t rc; int16_t value=0; char * raw_byte; short * raw_short; if (s[0] == 0) return; /* parse the command line, seperating the command from arguments */ cmd[0] = 0; index = 0; while ((index < sizeof(do_cmdbuf)) && s[index] && (s[index] != '=')) { cmd[index] = s[index]; index++; } if (index < sizeof(do_cmdbuf)) { cmd[index] = 0; args = &s[index]; while (*args && (*args == '=')) args++; if (*args == 0) args = NULL; } else { cmd[sizeof(do_cmdbuf)-1] = 0; args = NULL; } if (cmd[0] == 0) { return; } // 11bit CAN frame ? if (strcmp(cmd[0],'t') == 0) { //char *pnew = malloc(4); char *pnew = MEM_ALLOC(4); can_addr = substr(cmd, 1, 3, pnew); // printf("pnew: %s\n", pnew); // printf("CMD: %s\n", cmd); // printf("CAN ADDR: %s\n", can_addr); MEM_FREE(pnew); //can_addr = substring(1, 4, cmd, can_addr, sizeof can_addr); //can_addr = sort_of_works_substr(cmd, 1, 3); //free(pnew); // Layout of normal driving screen: // // |----------------|---------| // | BIG NUMBERS | BATTERY | // |--------|-------| ICON | // |3.45 V | 31 C | | // |--------------------------| // // All this information is extracted right here from single CAN-frame with address 630h // // Summary values of interest @ CAN ID 630h // // Byte Type Desc Units per lsb // 0 unsigned char Pack State of Charge 0.5% // 1 unsigned char Pack State of Function (not in use) n/a // 2 unsigned char Pack State of Health 0.5% // 3 unsigned char Max Pack Temperature 1 deg C // 4-5 short Min Pack Voltage 1mV // 6-7 short Max Pack Voltage 1mV if (strcmp(can_addr, "630") == 0) { wdt_reset(); // SOC is byte 0 in 0.5% per LSB // CAN-message is formatted as // t63080011223344556677 // --------------------- // 111111111122 // 123456789012345678901 // //printf("630!\n"); //char *pnew2 = malloc(3); //raw_byte = substring(5, 7, cmd, raw_byte, sizeof raw_byte); *pnew = MEM_ALLOC(3); // SOC, byte 0 raw_byte = substr(cmd, 5, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); value = value/2; // 0.5 % per LSB LCD_UpdateSOC(value); // Max Pack temp, byte 3 raw_byte = substr(cmd, 11, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); LCD_UpdateMaxTemp(value); char *spnew = MEM_ALLOC(6); // Min Pack Voltage, byte 4-5 raw_short = substr(cmd, 13, 4,spnew); MEM_FREE(spnew); value = xstrtoi(raw_short); LCD_UpdateMinVolt(value); // Small status line for each frame received. Since ID 630 should // be transmitted once per second, there should be small but visible // blinking of few pixels in one of the corners of the display. if (la == 0) { LCD_ClrLine(1,63,2,63); la = 1; } else { LCD_SetLine(1,63,2,63); la = 0; } } // Summary values end // Screen contrast and color if (strcmp(can_addr, "7DD") == 0) { // CAN-message is formatted as // t88050011223344 // --------------- // 11111 // 012345678901234 // byte 0 contrast // byte 1 red // byte 2 green // byte 3 blue // byte 4 intensity // byte 0 contrast *pnew = MEM_ALLOC(3); raw_byte = substr(cmd, 5, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); eeprom_write_word(8, value); // byte 1 red *pnew = MEM_ALLOC(3); raw_byte = substr(cmd, 7, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); eeprom_write_word(10, value); // byte 2 green *pnew = MEM_ALLOC(3); raw_byte = substr(cmd, 9, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); eeprom_write_word(12, value); // byte 3 blue *pnew = MEM_ALLOC(3); raw_byte = substr(cmd, 11, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); eeprom_write_word(14, value); // byte 3 blue *pnew = MEM_ALLOC(3); raw_byte = substr(cmd, 13, 2,pnew); MEM_FREE(pnew); value = xstrtoi(raw_byte); eeprom_write_word(16, value); Contrast = eeprom_read_word((uint16_t*)8); Red = eeprom_read_word((uint16_t*)10); Green = eeprom_read_word((uint16_t*)12); Blue = eeprom_read_word((uint16_t*)14); Intensity = eeprom_read_word((uint16_t*)16); BACKLIGHT_SetRGB( Red, Green, Blue ); BACKLIGHT_SetIntensity(Intensity); TERMFONT_DisplayString(".Display adjusted.", 7, 0); DELAY_MS(500); LCD_ClrBox(0,0,128,64); } // Summary values end } return; }