void i::base32::invoke(const char* function){ if(strcmp(function , "mov")==0){ if(isready()){ if(i::context::EIP->totype == TYPE_VAR){ if(i::context::EIP->fromtype==TYPE_VAR){ i::base32::vartovar(); } if(i::context::EIP->fromtype==TYPE_REG_EAX){ i::base32::regtovar(); } if(i::context::EIP->fromtype==TYPE_INST){ i::base32::insttovar(); } } if(i::context::EIP->totype==TYPE_REG_EAX || i::context::EIP->totype==TYPE_REG_EBX || i::context::EIP->totype==TYPE_REG_ECX || i::context::EIP->totype==TYPE_REG_EDX){ if(i::context::EIP->fromtype==TYPE_VAR){ i::base32::vartoreg(); } if(i::context::EIP->fromtype==TYPE_INST){ i::base32::insttoreg(); } if(i::context::EIP->fromtype==TYPE_REG_EAX || i::context::EIP->fromtype==TYPE_REG_EBX || i::context::EIP->fromtype==TYPE_REG_ECX || i::context::EIP->fromtype==TYPE_REG_EDX){ i::base32::regtoreg(); } } } } if(strcmp(function , "add")==0){ //TODO; } }
int keypressed( void ) { return isready( 0 ); }
int main(int argc, char ** argv) { int r; int handle; struct termios attr; char * device = 0; struct stat statbuf; int pid = 0; setProgName(argv[0]); while (argc > 1) { if (strcasecmp(argv[1], "-r") == 0) { readonly = 1; } else if (strcasecmp(argv[1], "-d") == 0) { setLogLevel(LOGLEVEL_DEBUG); } else if (strcasecmp(argv[1], "-?") == 0) { break; } else if (!device) { device = argv[1]; } else { device = 0; break; } argc--; argv++; } if (!device) { fprintf(stderr, "Usage: nmea0183-serial [-r] [-d] device\n\n" "-r : read-only, do not pass stdin to stdout\n" "-d : debug mode\n\n" "Example: nmea0183-serial /dev/ttyUSB0\n\n"COPYRIGHT); exit(1); } retry: logDebug("Opening %s\n", device); handle = open(device, O_RDWR | O_NOCTTY); logDebug("fd = %d\n", handle); if (handle < 0) { logAbort("NMEA-00001: Cannot open NMEA-0183 device %s\n", device); exit(1); } if (fstat(handle, &statbuf) < 0) { logAbort("NMEA-00002: Cannot determine device %s\n", device); exit(1); } isFile = S_ISREG(statbuf.st_mode); if (!isFile) { logDebug("Device is a serial port, set the attributes.\n"); memset(&attr, 0, sizeof(attr)); attr.c_cflag = B38400 | CS8 | CLOCAL | CREAD; attr.c_iflag = IGNPAR; attr.c_oflag = 0; attr.c_lflag = 0; attr.c_cc[VMIN] = 0; attr.c_cc[VTIME] = 1; tcflush(handle, TCIFLUSH); tcsetattr(handle, TCSANOW, &attr); } for (;;) { char msg[BUFFER_SIZE]; size_t msgLen; enum ReadyDescriptor r; int b; r = isready(handle, readonly ? -1 : 0); if ((r & FD1_Ready) > 0) { b = read(handle, msg, sizeof(msg)); if (b < 0) { break; } else if (b > 0) { if (write(1, msg, b) < b) { break; } } } if ((r & FD2_Ready) > 0) { b = read(0, msg, sizeof(msg)); if (b < 0) { break; } else if (b > 0) { if (write(1, msg, b) < b) { break; } if (write(handle, msg, b) < b) { break; } } } } close(handle); return 0; }
int main(int argc, char ** argv) { int r; int handle; struct termios attr; char * name = argv[0]; char * device = 0; struct stat statbuf; int pid = 0; setProgName(argv[0]); while (argc > 1) { if (strcasecmp(argv[1], "-w") == 0) { writeonly = 1; } else if (strcasecmp(argv[1], "-p") == 0) { passthru = 1; } else if (strcasecmp(argv[1], "-r") == 0) { readonly = 1; } else if (strcasecmp(argv[1], "-v") == 0) { verbose = 1; } else if (strcasecmp(argv[1], "-t") == 0 && argc > 2) { argc--; argv++; timeout = strtol(argv[1], 0, 10); logDebug("timeout set to %ld seconds\n", timeout); } else if (strcasecmp(argv[1], "-d") == 0) { debug = 1; setLogLevel(LOGLEVEL_DEBUG); } else if (!device) { device = argv[1]; } else { device = 0; break; } argc--; argv++; } if (!device) { fprintf(stderr, "Usage: %s [-w] -[-p] [-r] [-v] [-d] [-t <n>] device\n" "\n" "Options:\n" " -w writeonly mode, no data is read from device\n" " -r readonly mode, no data is sent to device\n" " -p passthru mode, data on stdin is sent to stdout but not to device\n" " -v verbose\n" " -d debug\n" " -t <n> timeout, if no message is received after <n> seconds the program quits\n" " <device> can be a serial device, a normal file containing a raw log,\n" " or the address of a TCP server in the format tcp://<host>[:<port>]\n" "\n" " Examples: %s /dev/ttyUSB0\n" " %s tcp://192.168.1.1:10001\n" "\n" COPYRIGHT, name, name, name); exit(1); } retry: if (debug) fprintf(stderr, "Opening %s\n", device); if (strncmp(device, "tcp:", STRSIZE("tcp:")) == 0) { handle = open_socket_stream(device); if (debug) fprintf(stderr, "socket = %d\n", handle); isFile = true; if (handle < 0) { fprintf(stderr, "Cannot open NGT-1-A TCP stream %s\n", device); exit(1); } } else { handle = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); if (debug) fprintf(stderr, "fd = %d\n", handle); if (handle < 0) { fprintf(stderr, "Cannot open NGT-1-A device %s\n", device); exit(1); } if (fstat(handle, &statbuf) < 0) { fprintf(stderr, "Cannot determine device %s\n", device); exit(1); } isFile = S_ISREG(statbuf.st_mode); } if (isFile) { if (debug) fprintf(stderr, "Device is a normal file, do not set the attributes.\n"); } else { if (debug) fprintf(stderr, "Device is a serial port, set the attributes.\n"); memset(&attr, 0, sizeof(attr)); cfsetispeed(&attr, B115200); cfsetospeed(&attr, B115200); attr.c_cflag |= CS8 | CLOCAL | CREAD; attr.c_iflag |= IGNPAR; attr.c_cc[VMIN] = 1; attr.c_cc[VTIME] = 0; tcflush(handle, TCIFLUSH); tcsetattr(handle, TCSANOW, &attr); if (debug) fprintf(stderr, "Device is a serial port, send the startup sequence.\n"); writeMessage(handle, NGT_MSG_SEND, NGT_STARTUP_SEQ, sizeof(NGT_STARTUP_SEQ)); sleep(2); } for (;;) { unsigned char msg[BUFFER_SIZE]; size_t msgLen; enum ReadyDescriptor r; r = isready(writeonly ? -1 : handle, readonly ? -1 : 0); if ((r & FD1_Ready) > 0) { if (!readNGT1(handle)) { break; } } if ((r & FD2_Ready) > 0) { if (!readIn(msg, sizeof(msg))) { break; } if (!passthru) { parseAndWriteIn(handle, msg); } fprintf(stdout, "%s", msg); fflush(stdout); } else if (writeonly) { break; } } close(handle); return 0; }