/*Camera control initial*/ int CameraCtrlInit(int com) { int ret = -1; int fd; int baudrate = 9600, databits = 8; int stopbits = 1, parity = 'N'; baudrate = gRemote.comm.baud; databits = gRemote.comm.databits; parity = gRemote.comm.parity; stopbits = gRemote.comm.stopbits; fd = InitPort(com, baudrate, databits, stopbits, parity); if(fd <= 0) { return -1; } ret = InitCamera(fd); if(ret != 0) { return -1; } return fd; }
// --------------------------------------------------------------------------- // Constructs a listener object for this plugin // --------------------------------------------------------------------------- // TInt CDunIrPlugin::ConstructListener() { FTRACE(FPrint(_L("CDunIrPlugin::ConstructListenerL()"))); if ( PluginState() != EDunStateLoaded ) { FTRACE(FPrint(_L("CDunIrPlugin::ConstructListenerL() (not ready) complete"))); return KErrNotReady; } ReportStateChangeUp( EDunStateTryListen ); TInt retTemp = InitPort(); if ( retTemp != KErrNone ) { FTRACE(FPrint(_L("CDunIrPlugin::ConstructListenerL() (ERROR) complete"))); return retTemp; } ReportStateChangeUp( EDunStateListening ); ReportStateChangeUp( EDunStateTryChannel ); TRAPD( retTrap, AllocateChannelL() ); if ( retTrap != KErrNone ) { iTransporter->FreeChannel( &iIrPort ); FTRACE(FPrint(_L("CDunIrPlugin::ConstructListenerL() (trapped!) complete"))); return retTrap; } ReportStateChangeUp( EDunStateChanneled ); FTRACE(FPrint(_L("CDunIrPlugin::ConstructListenerL() complete"))); return KErrNone; }
int main(int argc, char *argv[]) { if(argc == 1) { printf("!!!1!1!!AL9RM!!!!111! port missing \n"); return 0; } int sock, client; int port = InitPort(argv[1]); socklen_t fromlen; struct sockaddr_in server; struct sockaddr_in from; char buf[1024]; sock=socket(AF_INET, SOCK_STREAM,0); if (sock < 0) { perror("socket error"); exit(1); } memset(&server,0,sizeof(server)); server.sin_family=AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port=htons(port); if (bind(sock,(struct sockaddr *)&server,sizeof(server))<0) { perror("bind error"); exit(2); } fromlen = sizeof(struct sockaddr_in); while(1) { listen(sock, 5); client = accept(sock, (struct sockaddr *) &from, &fromlen); if (client < 0) { perror("accept error"); exit(2); } while (1) { memset(buf,0,1024); int s = read(client,buf,1024); if(s == 0) break; write(client,"server response: ",strlen("server response: ")); write(client,buf,strlen(buf)); printf("%s: %s", inet_ntoa(from.sin_addr),buf); } close(client); } return 0; }
//============================================================================================ MArduinoConnector::MArduinoConnector(QObject *parent) : QObject(parent) { PPort = NULL; // PStrValues = new QString(); PStringMessage = new QString(); IsTypeModeReadiness = false; IsTypeModeTelemetry = false; IsTakeTelemetryStrValues = false; // ICurrentReadinessParam = -1; // ICurrentTelemetryParam = -1; // IsToReadAllChannelsValues = false; // connect(this, SIGNAL(destroyed(QObject*)), SLOT(SlotDestroyed(QObject*))); connect(this, SIGNAL(SignalMessage(QString*)), GetPMainWnd(), SLOT(SlotMessage(QString*))); InitPort(); }
BOOL UploadGAR (void) { FILE *GAR; char filename[MAX_PATH]; int i; if (!PromptFile(topHWnd,"Game Action Replay RAM file (gar.bin)\0gar.bin\0\0",filename,NULL,Path_PLUG,"Please select a valid Game Action Replay data file...","gar.bin",FALSE)) return FALSE; if ((GAR = fopen(filename,"rb")) == NULL) { MessageBox(topHWnd,"Unable to open GAR data file!",MSGBOX_TITLE,MB_OK | MB_ICONERROR); return FALSE; } OpenStatus(topHWnd); InitPort(); StatusText("Resetting CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading initialization plugin..."); if (!LoadPlugin("garset.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running initialization plugin..."); RunCode(); Sleep(SLEEP_LONG); StatusText("Loading upload plugin..."); if (!LoadPlugin("garup.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running upload plugin..."); RunCode(); StatusText("Uploading from data file..."); BYTE a[256]; for (i = 0; i < 8; i++) { fread(&a,256,1,GAR); if (!WriteBlock(a, 256)) { fclose(GAR); CloseStatus(); return FALSE; } StatusPercent((i*100)/8); } StatusPercent(100); StatusText("...done!"); fclose(GAR); StatusText("Upload complete!"); StatusOK(); ResetNES(RESET_COPYMODE); return TRUE; }
BOOL DownloadGAR (void) { FILE *GAR; char filename[MAX_PATH]; int i; if (!PromptFile(topHWnd,"Game Action Replay RAM file (gar_d.bin)\0gar_d.bin\0\0",filename,NULL,Path_PLUG,"Please specify where to save Game Action Replay RAM data...","gar_d.bin",TRUE)) return FALSE; if ((GAR = fopen(filename,"wb")) == NULL) { MessageBox(topHWnd,"Unable to open file for output!",MSGBOX_TITLE,MB_OK | MB_ICONERROR); return FALSE; } OpenStatus(topHWnd); InitPort(); StatusText("Resetting CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading initialization plugin..."); if (!LoadPlugin("garset.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running initialization plugin..."); RunCode(); Sleep(SLEEP_LONG); StatusText("Loading download plugin..."); if (!LoadPlugin("gardn.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running download plugin..."); RunCode(); StatusText("Saving to file..."); for (i = 0; i < 0x800; i++) { BYTE n; if (!ReadByte(n)) { fclose(GAR); CloseStatus(); return FALSE; } fwrite(&n,1,1,GAR); if (!(i & 0x7)) StatusPercent((i*100)/2048); } fclose(GAR); StatusText("Download complete!"); StatusOK(); ResetNES(RESET_COPYMODE); return TRUE; }
int main(void) { InitPort(); InitTimer0(); StartTimer0(); while(1) { //doing nothing } }
void main(void) { u8 TxFlag=0; u8 RxFlag=0; InitSfr(); //PIC16 Register Initialization PowerUpDelay(); //Power on delay InitPort(); //PIC16 IO port Initialization timer1_init(); timer2_init(); LCD_Init(); //LCD initialize BeepOff(); //Close buzzer ModuleSelectModeEntryCheck(); //Confirm whether you can enter module select mode Uart_init(); PowerOnMusic(); //Power on music while(1) { MenuConfig(); //Menu config & display if(gb_ModuleWorkEnableFlag) { RFM22B_Running(gb_SystemMode,gb_ModuleWorkMode,gb_ParameterChangeFlag,&TxFlag,&RxFlag,&gb_RF_RSSI); if(TxFlag==1) //Sent successfully { TxFlag=0; gw_SendDataCount++; if(gw_SendDataCount>9999){gw_SendDataCount=0;} } if(RxFlag==1) //Successfully received { RxFlag=0; gw_ReceiveDataCount++; if(gw_ReceiveDataCount>9999){gw_ReceiveDataCount=0;} } if(gb_ParameterChangeFlag==1){gb_ParameterChangeFlag=0;} //clear parameter flag if(gb_ModuleWorkMode!=C_ModuleWorkMode_FSK && gb_ModuleWorkMode!=C_ModuleWorkMode_OOK && gb_ModuleWorkMode!=C_ModuleWorkMode_LoRa) { gb_StatusTx=0; gb_StatusRx=0; } } else { gb_StatusTx=0; gb_StatusRx=0; } if(gb_ErrorFlag!=1) { TxLED_Deal(); //Tx LED display deal RxLED_Deal(); //Rx LED display deal } } }
//Initialize system void Init() { unsigned int i; IFG1 &= ~OFIFG; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; //Adjust DCO frequency // //DCOCTL = DCO0 + DOC1 +DOC2; // DCOCTL = 0x80; // BCSCTL1 = XT2OFF + RSEL0 + RSEL1 + RSEL2; // BCSCTL2 = 0; //调整DCO的频率 DCOCTL = 0xE0; //切换MCLK到外部高速晶振(需要检测是否起振) //BCSCTL1 &= ~XT2OFF; //启动高速晶振 BCSCTL1 = RSEL0 + RSEL1 + RSEL2; do { //清除振荡器失效标志位,再延迟检查 IFG1 &= ~OFIFG; for (i = 0; i < 1000; i++) { __no_operation(); } } while (IFG1 & OFIFG); //使用XT2, SMCLK = MCLK = 8MHz BCSCTL2 = SELM1 + SELS; //允许外部振荡器失效后,重启系统 IE1 |= OFIE; InitPort(); InitUART(); InitADC(); InitSPI(); InitRF(); InitSensors(); InitTimer(); ShutdownModule(); }
void Init(void) { InitPort(); InitTris(); InitAnsel(); InitMiscellaneous(); InitTransmission(); InitADC(); InitVar(); InitInterrupt(); }
void InitSystem() { // General init InitOsc(); InitPort(); // Peripheral init AdcInit(); I2cInit(); // Interrupt init InterruptInit(); }
/*摄像头的控制*/ int CameraControl() { int ret = -1; int fd; int baudrate = 9600, databits = 8; int stopbits = 1, parity = 'N'; baudrate = gRemote.comm.baud; databits = gRemote.comm.databits; parity = gRemote.comm.parity; stopbits = gRemote.comm.stopbits; Printf("Initial succeed\n"); fd = InitPort(PORT_COM2, baudrate, databits, stopbits, parity); ret = InitCamera(fd); if(ret != 0) { return -1; } /* sleep(1); CCtrlUpStart(fd,1,10); sleep(10); CCtrlUpStop(fd,1); usleep(100); CCtrlDownStart(fd,1,10); sleep(10); CCtrlDownStop(fd,1); usleep(100); */ CCtrlLeftStart(fd, 1, 10); sleep(10); CCtrlLeftStop(fd, 1); /* usleep(100); CCtrlRightStart(fd,1,10); sleep(20); CCtrlRightStop(fd,1); usleep(100); CCtrlZoomAddStart(fd,1); sleep(10); CCtrlZoomAddStop(fd,1); usleep(100); CCtrlZoomDecStart(fd,1); sleep(20); CCtrlZoomDecStop(fd,1); usleep(100);*/ return 0; }
int LCDCtrlComInit(int com) { int baudrate = 9600, databits = 8; int stopbits = 1, parity = 'N'; int fd; fd = InitPort(com, baudrate, databits, stopbits, parity); if(fd <= 0) { return -1; } return fd; }
BOOL CMD_NESINFO (void) { char Version[256]; int i; OpenStatus(topHWnd); InitPort(); if (HWVer == 1) { if (ParPort == -1) { StatusText("CopyNES did not return a version reply!"); StatusOK(); return FALSE; } else { StatusText("CopyNES did not return a version reply, assuming version 1"); StatusOK(); return TRUE; } } StatusText("Retrieving internal version string..."); if (!WriteByteEx(0xA1,3,FALSE)) { StatusText("Failed to request version string!"); StatusOK(); return FALSE; } for (i = 0; i < 256; i++) { if (!ReadByteEx(&Version[i],1,FALSE)) { StatusText("Error reading version string!"); StatusOK(); return FALSE; } if (!Version[i]) break; } StatusText(Version); StatusOK(); return TRUE; }
CCmdHandler::CCmdHandler() : m_hEventExit(INVALID_HANDLE_VALUE) , m_hThreadDeal(INVALID_HANDLE_VALUE) , m_pRecvBuffer(NULL) , m_ucKeyboardAddr(MY_SERIAL_NDX) { m_pRecvBuffer = new CGenericBuffer(); ASSERT(m_pRecvBuffer); m_hEventExit = CreateEvent(NULL, TRUE, FALSE, NULL); m_hThreadDeal = CreateThread(NULL, 0, ThreadDeal, this, 0, NULL); if (InitPort(NULL, 1, 9600)) { StartMonitoring(); } else { AfxMessageBox(L"NO COM"); ::PostQuitMessage(0); } }
OMX_ERRORTYPE UniaDecoder::InitComponent() { OMX_ERRORTYPE ret = OMX_ErrorNone; LOG_DEBUG("UniaDecoder::InitComponent"); memOps.Calloc = appLocalCalloc; memOps.Malloc = appLocalMalloc; memOps.Free= appLocalFree; memOps.ReAlloc= appLocalReAlloc; errorCount = 0; inputFrameCount = 0; consumeFrameCount= 0; profileErrorCount = 0; IDecoder = NULL; libMgr = NULL; hLib = NULL; if(decoderLibName == NULL || outputPortBufferSize == 0 || nPushModeInputLen == 0){ LOG_ERROR("audio decoder param not inited!"); return OMX_ErrorInsufficientResources; } LOG_DEBUG("nPushModeInputLen=%d,outputPortBufferSize=%d,codingType=%d"\ ,nPushModeInputLen,outputPortBufferSize,codingType); ret = InitPort(); if(ret != OMX_ErrorNone){ return ret; } libMgr = FSL_NEW(ShareLibarayMgr, ()); if(libMgr == NULL){ ret = OMX_ErrorInsufficientResources; return ret; } ret = CreateDecoderInterface(); return ret; }
LONG CCardIssuer::Connect(DWORD dwPort, DWORD dwBaudRate, BYTE bAddress) { LONG lResult = InitPort(dwPort, dwBaudRate); if ( lResult != 0 ) return lResult; m_bAddress = bAddress; lResult = ExecCommand('R', 'S', NULL, NULL, NULL, NULL); if ( lResult != 0 ) return F1_E_DEVICE_UNRECOGNIZED; if (! _objmgr.Add(this)) { Disconnect(); return F1_E_NO_MEMORY; } return 0; }
// returns 0 if OK int DecosSensorRing::openPort() { int result = 1; ROS_INFO("Opening sensorring at /dev/ttyACM0..."); fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY ); // Open port for read and write not making it a controlling terminal if (fd == P_ERROR) { ROS_ERROR("openPort: Unable to open /dev/ttyACM0 - "); // If open() returns an error } else { result = InitPort(fd, B115200, 8, 'N', 1); if (result==0) ROS_INFO("Port opened & configured"); else ROS_INFO("Port init went wrong!"); } return result; }
int main() { pinbits=1;//set pin 1 as output InitPort();//call subroutine from assembler file while(1)//repeat for ever { pinbits=1;//Pin High sendpinbits();//call subroutine from assembler file pinbits=0;//Pin Low sendpinbits();//call subroutine from assembler file } }
void ResetNES (int rtype) { if (ParPort == -1) { if (rtype & RESET_PLAYMODE) { //clr /RTS=1 ftStatus = FT_ClrRts(ftHandleB); if (ftStatus != FT_OK) { MessageBox(topHWnd, "USB Error: ClrRts Failed!", "ResetNES", MB_OK | MB_ICONERROR); return; } } else { //set /RTS=0 ftStatus = FT_SetRts(ftHandleB); if (ftStatus != FT_OK) { MessageBox(topHWnd, "USB Error: SetRts Failed!", "ResetNES", MB_OK | MB_ICONERROR); return; } } if (!(rtype & RESET_NORESET)) { // pull /RESET low clear D2 //set /dtr=0 ftStatus = FT_ClrDtr(ftHandleB); if (ftStatus != FT_OK) { MessageBox(topHWnd, "USB Error: ClrDtr Failed!", "ResetNES", MB_OK | MB_ICONERROR); return; } Sleep(SLEEP_SHORT); } // pull /RESET high set D2 //clr /dtr=1 ftStatus = FT_SetDtr(ftHandleB); if (ftStatus != FT_OK) { MessageBox(topHWnd, "USB Error: SetDtr Failed!", "ResetNES", MB_OK | MB_ICONERROR); return; } Sleep(SLEEP_SHORT); InitPort(); Sleep(SLEEP_SHORT); } else { if (rtype & RESET_ALTPORT) shadow &= 0xF7; else shadow |= 0x08; if (rtype & RESET_PLAYMODE) shadow &= 0xFE; else shadow |= 0x01; if (!(rtype & RESET_NORESET)) { shadow &= 0xFB; pwControl(shadow); // pull /RESET low Sleep(SLEEP_SHORT); } shadow |= 0x04; // pull /RESET high pwControl(shadow); Sleep(SLEEP_SHORT); } }
int main(int argc, char *argv[]) { char *infile = NULL, fullName[FILENAME_MAX]; int runFlags = 0; int terminalMode = FALSE; BoardConfig *config; char *port, *board; System sys; int i; /* get the environment settings */ if (!(port = getenv("PORT"))) port = DEF_PORT; if (!(board = getenv("BOARD"))) board = DEF_BOARD; /* get the arguments */ for(i = 1; i < argc; ++i) { /* handle switches */ if(argv[i][0] == '-') { switch(argv[i][1]) { case 'b': // select a target board if (argv[i][2]) board = &argv[i][2]; else if (++i < argc) board = argv[i]; else Usage(); break; case 'd': runFlags |= RUN_PAUSE; break; case 'p': if(argv[i][2]) port = &argv[i][2]; else if(++i < argc) port = argv[i]; else Usage(); if (isdigit((int)port[0])) { #if defined(CYGWIN) || defined(WIN32) static char buf[10]; sprintf(buf, "COM%d", atoi(port)); port = buf; #endif #ifdef LINUX static char buf[10]; sprintf(buf, "/dev/ttyUSB%d", atoi(port)); port = buf; #endif } break; case 's': runFlags |= RUN_STEP; break; case 't': terminalMode = TRUE; break; default: Usage(); break; } } /* handle the input filename */ else { if (infile) Usage(); infile = argv[i]; } } sys.ops = &myOps; ParseConfigurationFile(&sys, "xbasic.cfg"); /* make sure an input file was specified */ if (!infile) Usage(); ConstructFileName(infile, fullName, ".bai"); /* setup for the selected board */ if (!(config = GetBoardConfig(board))) Usage(); /* initialize the serial port */ if (!InitPort(port)) { fprintf(stderr, "error: opening serial port\n"); return 1; } /* load the compiled image */ if (!LoadImage(&sys, config, port, fullName)) { fprintf(stderr, "error: load failed\n"); return 1; } /* run the loaded image */ if (!RunLoadedProgram(runFlags)) { fprintf(stderr, "error: run failed\n"); return 1; } /* enter terminal mode if requested */ if (terminalMode) TerminalMode(); return 0; }
void ZoomRect (Rect *smallrect, Rect *bigrect, Boolean zoomup) { #if USE_DRAG_MANAGER_FOR_ZOOMS if (gZoomOn) { if (zoomup) ZoomRects(smallrect,bigrect,10,kZoomNoAcceleration); else ZoomRects(bigrect,smallrect,10,kZoomNoAcceleration); } #else Fixed factor; Rect rect1, rect2, rect3, rect4; GrafPtr savePort, deskPort; int i; long tm; if (gZoomOn) { GetPort (&savePort); OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort))); InitPort (deskPort); SetPort (deskPort); PenPat (&qd.gray); //¥ Original, comment for black zoom. // PenPat (&qd.black); //¥ Uncomment for black zoom. PenMode (notPatXor); //¥ Original, comment for black zoom. // PenMode (patXor); //¥ Uncomment for black zoom. if (zoomup) { rect1 = *smallrect; factor = FixRatio (6, 5); fract = FixRatio (541, 10000); } else { rect1 = *bigrect; factor = FixRatio (5, 6); fract = ONE; } rect2 = rect1; rect3 = rect1; FrameRect (&rect1); for (i = 1; i <= ZOOMSTEPS; i++) { rect4.left = Blend (smallrect->left, bigrect->left); rect4.right = Blend (smallrect->right, bigrect->right); rect4.top = Blend (smallrect->top, bigrect->top); rect4.bottom = Blend (smallrect->bottom, bigrect->bottom); FrameRect (&rect4); FrameRect (&rect1); rect1 = rect2; rect2 = rect3; rect3 = rect4; fract = FixMul (fract, factor); tm = TickCount (); // These two lines are a crude waitvbl while (tm == TickCount ()); } FrameRect (&rect1); FrameRect (&rect2); FrameRect (&rect3); ClosePort (deskPort); DisposePtr ((Ptr) deskPort); PenNormal (); SetPort (savePort); } #endif }
void main(void) { int p; // // set network characteristics // doomcom.ticdup = 1; doomcom.extratics = 0; doomcom.numnodes = 2; doomcom.numplayers = 2; doomcom.drone = 0; printf("\n" "---------------------------------\n" #ifdef DOOM2 STR_DOOMSERIAL"\n" #else "DOOM SERIAL DEVICE DRIVER v1.4\n" #endif "---------------------------------\n"); myargc = _argc; myargv = _argv; FindResponseFile(); // // allow override of automatic player ordering to allow a slower computer // to be set as player 1 allways // // // establish communications // baudbits = 0x08; // default to 9600 if not specified on cmd line // or in modem.cfg if (CheckParm ("-dial") || CheckParm ("-answer") ) ReadModemCfg (); // may set baudbits // // allow command-line override of modem.cfg baud rate // if (CheckParm ("-9600")) baudbits = 0x0c; else if (CheckParm ("-14400")) baudbits = 0x08; else if (CheckParm ("-19200")) baudbits = 0x06; else if (CheckParm ("-38400")) baudbits = 0x03; else if (CheckParm ("-57600")) baudbits = 0x02; else if (CheckParm ("-115200")) baudbits = 0x01; InitPort (); if (CheckParm ("-dial")) Dial (); else if (CheckParm ("-answer")) Answer (); Connect (); // // launch DOOM // LaunchDOOM (); Error (NULL); }
int main(int argc, char *argv[]) { char actualport[PATH_MAX]; char *infile = NULL, *p, *p2; int terminalMode = FALSE; BoardConfig *config, *configSettings; char *port, *board, *subtype, *value; System sys; int baud = 115200; int portFlags = 0; int flags = 0; int i; int terminalBaud = 0; int check_for_exit = 0; /* flag to terminal_mode to check for a certain sequence to indicate program exit */ int showPorts = FALSE; int showAll = TRUE; int pstMode = FALSE; /* make sure that the serial port gets closed on exit */ atexit(serial_done); /* just display a usage message if no arguments are supplied */ if (argc <= 1) Usage(); /* get the environment settings */ port = getenv("PROPELLER_LOAD_PORT"); board = getenv("PROPELLER_LOAD_BOARD"); /* setup a configuration to collect command line -D settings */ configSettings = NewBoardConfig(NULL, ""); /* get the arguments */ for(i = 1; i < argc; ++i) { /* handle switches */ if(argv[i][0] == '-') { switch(argv[i][1]) { case 'b': // select a target board if (argv[i][2]) board = &argv[i][2]; else if (++i < argc) board = argv[i]; else Usage(); break; case 'p': if(argv[i][2]) port = &argv[i][2]; else if(++i < argc) port = argv[i]; else Usage(); #if defined(CYGWIN) || defined(WIN32) || defined(LINUX) if (isdigit((int)port[0])) { #if defined(CYGWIN) || defined(WIN32) static char buf[10]; sprintf(buf, "COM%d", atoi(port)); port = buf; #endif #if defined(LINUX) static char buf[64]; sprintf(buf, "/dev/ttyUSB%d", atoi(port)); port = buf; #endif } #endif #if defined(MACOSX) if (port[0] != '/') { static char buf[64]; sprintf(buf, "/dev/cu.usbserial-%s", port); port = buf; } #endif break; case 'P': showPorts = TRUE; showAll = FALSE; break; case 'Q': showPorts = TRUE; showAll = TRUE; break; case 'e': flags |= LFLAG_WRITE_EEPROM; break; case 'l': flags |= LFLAG_WRITE_SDLOADER; break; case 'z': flags |= LFLAG_WRITE_SDCACHELOADER; break; case 'r': flags |= LFLAG_RUN; break; case 's': flags |= LFLAG_WRITE_BINARY; break; case 'x': flags |= LFLAG_WRITE_PEX; break; case 'T': pstMode = TRUE; // fall through case 't': terminalMode = TRUE; if (argv[i][2]) terminalBaud = atoi(&argv[i][2]); break; case 'q': check_for_exit = 1; break; case 'g': flags |= LFLAG_DEBUG; break; case 'D': if(argv[i][2]) p = &argv[i][2]; else if(++i < argc) p = argv[i]; else Usage(); if ((p2 = strchr(p, '=')) == NULL) Usage(); *p2++ = '\0'; SetConfigField(configSettings, p, p2); break; case 'I': if(argv[i][2]) p = &argv[i][2]; else if(++i < argc) p = argv[i]; else Usage(); xbAddPath(p); break; case 'v': portFlags = IFLAG_VERBOSE; break; case 'S': psetdelay(argv[i][2] ? atoi(&argv[i][2]) : 5); break; case 'f': flags |= LFLAG_WRITE_SDFILE; break; case '?': /* fall through */ default: Usage(); break; } } /* handle the input filename */ else { if (infile) Usage(); infile = argv[i]; } } /* make sure an input file was specified if needed */ if (infile && !flags) { printf("error: must specify -e, -r, or -s when an image file is specified\n"); return 1; } /* 1) look in the directory specified by the -I command line option (added above) 2) look in the directory where the elf file resides 3) look in the directory pointed to by the environment variable PROPELLER_ELF_LOAD 4) look in the directory where the loader executable resides if possible 5) look in /usr/local/propeller/propeller-load */ /* finish the include path */ if (infile) xbAddFilePath(infile); xbAddEnvironmentPath("PROPELLER_LOAD_PATH"); xbAddProgramPath(argv); #if defined(LINUX) || defined(MACOSX) || defined(CYGWIN) xbAddPath("/opt/parallax/propeller-load"); #endif sys.ops = &myOps; /* parse the board option */ if (board) { /* split the board type from the subtype */ if ((p = strchr(board, ':')) != NULL) { *p++ = '\0'; subtype = p; } /* no subtype */ else subtype = DEF_SUBTYPE; } else { board = DEF_BOARD; subtype = DEF_SUBTYPE; } /* setup for the selected board */ if (!(config = ParseConfigurationFile(&sys, board))) { printf("error: can't find board configuration '%s'\n", board); return 1; } /* select the subtype */ if (subtype) { if (!(config = GetConfigSubtype(config, subtype))) { printf("error: can't find board configuration subtype '%s'\n", subtype); return 1; } } /* override with any command line settings */ config = MergeConfigs(config, configSettings); /* use the baud rate from the configuration */ GetNumericConfigField(config, "baudrate", &baud); /* Use reset method from configuration */ if ((value = GetConfigField(config, "reset")) != NULL) { if (use_reset_method (value)) { printf("error: no reset type '%s'\n", value); return 1; } } else { use_reset_method ("dtr"); } /* check for being asked to show ports */ if (showPorts) { if (showAll) ShowPorts(PORT_PREFIX); else ShowConnectedPorts(PORT_PREFIX, baud, portFlags); return 0; } /* initialize the serial port */ if ((flags & NEED_PORT) != 0 || terminalMode) { int sts = InitPort(PORT_PREFIX, port, baud, portFlags, actualport); switch (sts) { case PLOAD_STATUS_OK: // port initialized successfully break; case PLOAD_STATUS_OPEN_FAILED: printf("error: opening serial port '%s'\n", port); perror("Error is "); return 1; case PLOAD_STATUS_NO_PROPELLER: if (port) printf("error: no propeller chip on port '%s'\n", port); else printf("error: can't find a port with a propeller chip\n"); return 1; } } /* load the image file */ if (infile) { if (flags & LFLAG_WRITE_SDFILE) WriteFileToSDCard(config, infile, NULL); else { if (!LoadImage(&sys, config, infile, flags)) { printf("error: load failed\n"); return 1; } } } /* check for loading the sd loader */ else if (flags & LFLAG_WRITE_SDLOADER) { if (!LoadSDLoader(&sys, config, "sd_loader.elf", flags)) { printf("error: load failed\n"); return 1; } } /* check for loading the sd cache loader */ else if (flags & LFLAG_WRITE_SDCACHELOADER) { if (!LoadSDCacheLoader(&sys, config, "sd_cache_loader.elf", flags)) { printf("error: load failed\n"); return 1; } } /* enter terminal mode if requested */ if (terminalMode) { printf("[ Entering terminal mode. Type ESC or Control-C to exit. ]\n"); fflush(stdout); if (terminalBaud && terminalBaud != baud) { serial_done(); serial_init(actualport, terminalBaud); } terminal_mode(check_for_exit, pstMode); } return 0; }
LRESULT CALLBACK CopyNES_Menu(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { BOOL success = TRUE; switch (message) { case WM_INITDIALOG: if (!Startup()) { Shutdown(); DestroyWindow(hDlg); return FALSE; } ShowWindow(hDlg,SW_SHOWNORMAL); EnableMenus(hDlg); return TRUE; break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_MAIN_MAKENES: success = CMD_MAKENES(); break; case IDC_MAIN_MAKEUNIF: success = CMD_MAKEUNIF(); break; case IDC_MAIN_SPLITNES: success = CMD_SPLITNES(); break; case IDC_MAIN_SPLITUNIF: success = CMD_SPLITUNIF(); break; case IDC_MAIN_BREAKBANK: success = CMD_BREAKBANK(); break; case IDC_MAIN_DISASM: success = CMD_DISASM(); break; case IDC_MAIN_OPTIONS: success = CMD_OPTIONS(); break; case IDC_MAIN_NESINFO: InitPort(); success = CMD_NESINFO(); break; case IDC_MAIN_PLAYCART: InitPort(); success = CMD_PLAYCART(); break; case IDC_MAIN_RAMCART: InitPort(); success = CMD_RAMCART(); break; case IDC_MAIN_PLAYNSF: InitPort(); success = CMD_PLAYNSF(); break; case IDC_MAIN_PLAYLOG: InitPort(); success = CMD_PLAYLOG(); break; case IDC_MAIN_DUMPCART: InitPort(); success = CMD_DUMPCART(); break; case IDC_MAIN_WRITEWRAM: InitPort(); success = CMD_WRITEWRAM(); break; case IDC_MAIN_RUNPLUG: InitPort(); success = CMD_RUNPLUG(); break; case IDC_MAIN_FIXGAR: InitPort(); success = CMD_FIXGAR(); break; case IDC_MAIN_BANKWATCH: InitPort(); success = CMD_BANKWATCH(); break; case IDC_MAIN_MICROBUG: InitPort(); success = CMD_MICROBUG(); break; case IDC_MAIN_VRC7REGS: InitPort(); success = CMD_VRC7REGS(); break; case IDC_MAIN_RECONNECT: success = CMD_RECONNECT(); EnableMenus(hDlg); break; } if (!success) MessageBox(topHWnd,"An error occurred during the previous operation!","USB CopyNES",MB_OK | MB_ICONERROR); return TRUE; break; case WM_CLOSE: Shutdown(); DestroyWindow(hDlg); return 0; break; case WM_DESTROY: PostQuitMessage(0); return 0; break; } return FALSE; }
/****************************************************************************** * Name: CCommDevice::Open * * Purpose: open a connection to the device on the com port ******************************************************************************/ BOOL CCommDevice::Open( INT port, DWORD baud, CHAR parity, INT data, INT stop) { // clear any previous errors m_dwCommState = ERR_NOERROR; // close any open port and terminate any open thread if( !Close()) return FALSE; // open the port m_hPort = OpenPort( port); if( m_hPort == INVALID_HANDLE_VALUE) { m_dwCommState = ERR_NOPORT; return FALSE; } // initialize the com port to read and write to the device. if( !InitPort( m_hPort, baud, parity, data, stop)) { m_dwCommState = ERR_NOPORT; CloseHandle( m_hPort); m_hPort = INVALID_HANDLE_VALUE; return FALSE; } // set the port timeouts COMMTIMEOUTS comTime; comTime.ReadIntervalTimeout = m_dwReadIntervalTimeout; comTime.ReadTotalTimeoutMultiplier = m_dwReadTotalTimeoutMultiplier; comTime.ReadTotalTimeoutConstant = m_dwReadTotalTimeoutConstant; comTime.WriteTotalTimeoutMultiplier = m_dwWriteTotalTimeoutMultiplier; comTime.WriteTotalTimeoutConstant = m_dwWriteTotalTimeoutConstant; if( !SetCommTimeouts( m_hPort, &comTime)) { m_dwCommState = ERR_PORTERROR; CloseHandle( m_hPort); m_hPort = INVALID_HANDLE_VALUE; return FALSE; } // create a mutex to control access to the port if( !(m_hPortMutex = CreateMutex( NULL, FALSE, NULL))) { m_dwCommState = ERR_NOTHREAD; CloseHandle( m_hPort); m_hPort = INVALID_HANDLE_VALUE; return FALSE; } // initialize the terminate and cancel flags m_bTerminate = FALSE; m_bCancel = FALSE; // create an event to signal when requests are received if( !(m_hEvent = CreateEvent( NULL, TRUE, FALSE, NULL))) { m_dwCommState = ERR_NOTHREAD; CloseHandle( m_hPort); CloseHandle( m_hPortMutex); m_hPort = INVALID_HANDLE_VALUE; m_hPortMutex = 0; return FALSE; } // create a thread to process port requests m_pThread = AfxBeginThread( ProcessCommRequests, this, THREAD_PRIORITY_HIGHEST, 0, CREATE_SUSPENDED); if( !m_pThread) { m_dwCommState = ERR_NOTHREAD; CloseHandle( m_hPort); CloseHandle( m_hPortMutex); m_hPort = INVALID_HANDLE_VALUE; m_hPortMutex = 0; return FALSE; } if(!::DuplicateHandle(::GetCurrentProcess(), m_pThread->m_hThread, ::GetCurrentProcess(), &m_hThread, 0, FALSE, DUPLICATE_SAME_ACCESS)) { m_bTerminate = TRUE; m_pThread->ResumeThread(); Sleep(40); // turn processor over to thread for termination m_dwCommState = ERR_NOTHREAD; CloseHandle( m_hPort); CloseHandle( m_hPortMutex); m_hPort = INVALID_HANDLE_VALUE; m_hPortMutex = 0; return FALSE; } m_pThread->ResumeThread(); return TRUE; }