Exemple #1
0
void read_extra(uint16_t address, CPU* cpu)
{
	uint16_t temp_addr = address;
	if (address >= 0x3000 && address <= 0x3EFF)
	{
		temp_addr = address - 0x1000;
	}
	if (temp_addr == 0x2007)
	{
		uint8_t oldbuff = cpu->vram_buff;
		if (cpu->ppu->regV <= 0x2FFF)
		{
			cpu->vram_buff = cpu->ppu->memory[cpu->ppu->regV];
			cpu->memory[0x2007] = oldbuff;
		}
		read_vram_data(cpu->ppu);
	}
	if (temp_addr == 0x2002)
	{
		status_read(cpu->ppu);
		//cpu->memory[0x2002] &= 0x7F;
	}
	if (temp_addr == 0x2001)
	{
		printf("SO.... %x\n", cpu->memory[0x2001]);
	}
}
Exemple #2
0
void
ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool)
{
    const int buf_size = 128;

    update_time();
    if (persist && persist->file && pool)
    {
        struct gc_arena gc = gc_new();
        struct buffer in = alloc_buf_gc(256, &gc);
        char *cn_buf;
        char *ip_buf;
        int line = 0;

        ALLOC_ARRAY_CLEAR_GC(cn_buf, char, buf_size, &gc);
        ALLOC_ARRAY_CLEAR_GC(ip_buf, char, buf_size, &gc);

        while (true)
        {
            ASSERT(buf_init(&in, 0));
            if (!status_read(persist->file, &in))
            {
                break;
            }
            ++line;
            if (BLEN(&in))
            {
                int c = *BSTR(&in);
                if (c == '#' || c == ';')
                {
                    continue;
                }
                msg( M_INFO, "ifconfig_pool_read(), in='%s', TODO: IPv6",
                     BSTR(&in) );

                if (buf_parse(&in, ',', cn_buf, buf_size)
                    && buf_parse(&in, ',', ip_buf, buf_size))
                {
                    bool succeeded;
                    const in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, 0, &succeeded, NULL);
                    if (succeeded)
                    {
                        msg( M_INFO, "succeeded -> ifconfig_pool_set()");
                        ifconfig_pool_set(pool, cn_buf, addr, persist->fixed);
                    }
                }
            }
        }

        ifconfig_pool_msg(pool, D_IFCONFIG_POOL);

        gc_free(&gc);
    }
}
extern int dpkg_main(int argc, char **argv)
{
	char opt = 0;
	char *s;
	package_t *p, *packages = NULL;
	char *cwd = getcwd(0, 0);
	void *status = NULL;

	while (*++argv) {
		if (**argv == '-') {
			/* Nasty little hack to "parse" long options. */
			s = *argv;
			while (*s == '-') {
				s++;
			}
			opt=s[0];
		} else {
			p = (package_t *)xmalloc(sizeof(package_t));
			memset(p, 0, sizeof(package_t));

			if (**argv == '/') {
				p->file = *argv;
			} else
				if (opt != 'c') {
					p->file = xmalloc(strlen(cwd) + strlen(*argv) + 2);
					sprintf(p->file, "%s/%s", cwd, *argv);
			} else {
				p->package = strdup(*argv);
			}

			p->next = packages;
			packages = p;
		}		
	}

	status = status_read();

	switch (opt) {
		case 'i':
			return dpkg_install(packages, status);
		case 'r':
			return dpkg_remove(packages, status);
		case 'u':
			return dpkg_unpack(packages, status);
		case 'c':
			return dpkg_configure(packages, status);
		default :
			show_usage();
			return EXIT_FAILURE;
	}
}
Exemple #4
0
/*****************************************************************************
 Perform rtkgps list command.
 *****************************************************************************/
void cmd_list(cmdlnopts_t *cmdopt) {
  int fd;
  status_t status;
  logfile_t *lgflp;
  /*unsigned int mem = 0;*/
  int n;

  fd = coms_open(cmdopt);

  if (cmdopt->vflg)
    printf("Requesting logger status information\n");

  status_read(fd, &status, cmdopt);

  gpsmouse_disable(fd, status.gpsms, cmdopt);

  if ((lgflp = malloc(status.nfile*sizeof(logfile_t))) == NULL) {
    fprintf(stderr,"rtkgps: Error allocating memory\n");
    gpsmouse_enable(fd, status.gpsms, cmdopt);
    coms_close(fd, cmdopt);
    exit(2);
  }

  for (n = 0; n < status.nfile; n++) {
    if (cmdopt->vflg) {
      printf("Requesting metadata for file %4d\n", n);
    }
    if (get_file_info(fd, n, lgflp+n) < 0) {
      fprintf(stderr,"rtkgps: Error reading information for file %d [%s]\n",
	      n, gcstrerror(rcerrno));
      free(lgflp);
      gpsmouse_enable(fd, status.gpsms, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    }
  }

  printf("File num   Date      Fix type  Num fix  Mem ptr\n");
  for (n = 0; n < status.nfile; n++)
    printf("%8d   %8s  %8hd  %7d  %7d\n", n, lgflp[n].date, lgflp[n].fxtyp,
	   lgflp[n].nfix, lgflp[n].memp);

  free(lgflp);
  gpsmouse_enable(fd, status.gpsms, cmdopt);
  coms_close(fd, cmdopt);
}
Exemple #5
0
/*****************************************************************************
 Perform rtkgps read command.
 *****************************************************************************/
void cmd_read(cmdlnopts_t *cmdopt) {
  int fd;
  status_t status;
  geoid_height_t gdht = {0,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,NULL,NULL};
  FILE *strm = NULL;
  char *fnam = NULL;
  short int n;

#ifdef GEOIDCOR
  /* Set up geoid correction data structure */
  if (geoid_calc_open(GGRDPATH, &gdht) == -1) {
    fprintf(stderr, "rtkgps: Warning: could not access geoid correction "
	    "data\n");
  }
#endif

  /* Open communication with logger */
  fd = coms_open(cmdopt);

  /* Set up progress bar if requested */
  if (cmdopt->pflg) {
#ifdef HAVE_TIOCGWINSZ
     struct winsize ws;
     if (ioctl(1, TIOCGWINSZ, (void *)&ws) == 0)
       prgbrfp = 1;
     else if (ioctl(2, TIOCGWINSZ, (void *)&ws) == 0)
       prgbrfp = 2;
#else
     prgbrfp = 1;
#endif
     if (prgbrfp)
       gdpfp = get_data_progress;
  }

  if (cmdopt->vflg)
    printf("Requesting logger status information\n");

  /* Read logger status */
  status_read(fd, &status, cmdopt);

 /* Handle unspecified ends of file number range */
  if (cmdopt->fnmn == -1)
    cmdopt->fnmn = 0;
  if (cmdopt->fnmx == -1)
    cmdopt->fnmx = status.nfile-1;

  /* Check for minimum file number out of range */
  if (cmdopt->fnmn >= status.nfile) {
    fprintf(stderr,"rtkgps: Requested file number(s) all invalid\n");
    coms_close(fd, cmdopt);
    exit(1);
  }

  /* Check for maximum file number out of range */
  if (cmdopt->fnmx >= status.nfile) {
    cmdopt->fnmx = status.nfile-1;
    fprintf(stderr, "rtkgps:  Warning: reduced maximum requested file "
	    "number to valid range\n");
  }

  outlog_disable(fd, cmdopt);

  /* The complicated handling of output files, split between this function 
     and file_read, is due to the following output policy:
     • If no output file is specified, selected logfiles are written 
       to stdout
     • If the specified output file is a regular file, all selected logfiles
       are written to that file
     • If the specified output file is a directory, each selected logfile is
       written to a unique file within that directory  
  */
  if (cmdopt->dsts == NULL)
    strm = stdout; /* If output flag not specified, output stream is stdout */
  else {
    /* If output flag is specified, determine whether it is a directory */
    if (is_directory(cmdopt->dsts)) {
      /* If specified output path is a directory, allocate memory for
	 constructing the full output filename */
      if ((fnam = malloc(strlen(cmdopt->dsts) + 32)) == NULL) {
	fprintf(stderr,"rtkgps: Error allocating memory\n");
	outlog_enable(fd, status.gpsms, cmdopt);
	coms_close(fd, cmdopt);
	exit(2);
      }
    } else {
      /* If specified output path is not a directory, open the file
	 for writing after creating a backup if the file already exists. */
      if (file_backup(cmdopt->dsts) != 0) {
	fprintf(stderr,"rtkgps: Error creating backup of file %s\n",
		cmdopt->dsts);
	outlog_enable(fd, status.gpsms, cmdopt);
	coms_close(fd, cmdopt);
	exit(3);
      }
      if ((strm = fopen(cmdopt->dsts, "w")) == NULL) {
	fprintf(stderr,"rtkgps: Error opening output file %s [%s]\n",
		cmdopt->dsts, gcstrerror(rcerrno));
	outlog_enable(fd, status.gpsms, cmdopt);
	coms_close(fd, cmdopt);
	exit(3);
      }
    }
  }

  if (strm != NULL) {
    /* Write output file header */
    if (cmdopt->nflg)
      print_hdr_native(strm);
    else
      print_hdr_nmea(strm, cmdopt->btas);
  }

  /* Reset warning function message records */
  warning(NULL, 0, NULL);

  /* Read requested range of log files */
  for (n = cmdopt->fnmn; n <= cmdopt->fnmx; n++) {
    char nstr[8];

    /* If progress bar requested and verbose output not enabled, set
       up prefix displaying file number */
    if (cmdopt->pflg && !cmdopt->vflg) {
      sprintf(nstr, "%4d ", n);
      text_progress_bar(0.0, nstr);
    }
    file_read(fd, n, fnam, strm, &gdht, &status, cmdopt);

    /* Reset warning function message records */
    warning(NULL, 0, NULL);
  }

  /* Free memory allocated for file name */
  free(fnam);

  outlog_enable(fd, status.gpsms, cmdopt);

  /* Close ommunication with logger */
  coms_close(fd, cmdopt);

#ifdef GEOIDCOR
   /* Destroy geoid correction data structure */
  geoid_calc_close(&gdht);
#endif
}
Exemple #6
0
/*****************************************************************************
 Perform rtkgps set command.
 *****************************************************************************/
void cmd_set(cmdlnopts_t *cmdopt) {
  int fd;
  status_t status;
  unsigned char cflg = 0, fxtp = 0, mfow = 0, gpsm;

  fd = coms_open(cmdopt);

  if (cmdopt->vflg) {
    printf("Requesting logger status information\n");
  }
  status_read(fd, &status, cmdopt);

  gpsm = status.gpsms;
  if (cmdopt->cfls != NULL) {
    if (strcmp(cmdopt->cfls,"0") == 0)
      gpsm = 0;
    else if (strcmp(cmdopt->cfls,"1") == 0)
      gpsm = 1;
  }
  if (cmdopt->lgts != NULL) {
    if (strcmp(cmdopt->lgts,"tl") == 0)
      fxtp = 0;
    else if (strcmp(cmdopt->lgts,"tla") == 0)
      fxtp = 1;
    else if (strcmp(cmdopt->lgts,"tlav") == 0)
      fxtp = 2;
    if (fxtp != status.fxtyp) {
      status.fxtyp = fxtp;
      cflg = 1;
    }
  }
  if (cmdopt->mfos != NULL) {
    if (strcmp(cmdopt->mfos,"o") == 0)
      mfow = 0;
    else if (strcmp(cmdopt->mfos,"s") == 0)
      mfow = 1;
    if (mfow != status.mfowm) {
      status.mfowm = mfow;
      cflg = 1;
    }
  }
  if (cmdopt->snts != NULL && status.sntvl != cmdopt->sint) {
    status.sntvl = cmdopt->sint;
    cflg = 1;
  }

  if (cflg == 1) {
    gpsmouse_disable(fd, status.gpsms, cmdopt);
    if (cmdopt->vflg) {
      printf("Setting new logger parameters\n");
    }
    if (set_status(fd, &status) < 0) {
      fprintf(stderr,"rtkgps: Failed to set device status [%s]\n",
	      gcstrerror(rcerrno));
      gpsmouse_enable(fd, gpsm, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    }
    gpsmouse_enable(fd, gpsm, cmdopt);
  } else {
    if (gpsm && !status.gpsms)
      gpsmouse_enable(fd, gpsm, cmdopt);
    else if (!gpsm && status.gpsms)
      gpsmouse_disable(fd, status.gpsms, cmdopt);
  }

  coms_close(fd, cmdopt);

}
Exemple #7
0
/*****************************************************************************
 Perform rtkgps status command.
 *****************************************************************************/
void cmd_status(cmdlnopts_t *cmdopt) {
  int fd;
  unsigned int mu = 0;
  status_t status;
  logfile_t lgfl;
  log_bndry_t lgbd;
  memory_t mem;
  firmware_t frm;

  fd = coms_open(cmdopt);

  if (cmdopt->vflg)
    printf("Requesting logger status information\n");

  status_read(fd, &status, cmdopt);

  if (cmdopt->eflg) {
    if (cmdopt->vflg)
      printf("Requesting extended logger information\n");

    gpsmouse_disable(fd, status.gpsms, cmdopt);

    if (get_log_bndry(fd, &lgbd) < 0) {
      fprintf(stderr,"rtkgps: Failed to read log start/end details [%s]\n",
	      gcstrerror(rcerrno));
      gpsmouse_enable(fd, status.gpsms, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    }
    if (get_memory_info(fd, &mem) < 0) {
      fprintf(stderr,"rtkgps: Failed to read logger memory details [%s]\n",
	      gcstrerror(rcerrno));
      gpsmouse_enable(fd, status.gpsms, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    }
    if (get_firmware_info(fd, &frm) < 0) {
      fprintf(stderr,"rtkgps: Failed to read logger firmware details [%s]\n",
	      gcstrerror(rcerrno));
      gpsmouse_enable(fd, status.gpsms, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    }
     /* Get info for first logfile */
    if (get_file_info(fd, 0, &lgfl) < 0) {
      fprintf(stderr,"rtkgps: Error reading information for file %d [%s]\n",
	      0, gcstrerror(rcerrno));
      gpsmouse_enable(fd, status.gpsms, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    } 
    if (lgfl.memp == 0) { /* Memory has not wrapped around in overwrite mode */
      /* Get info for last logfile */
      if (get_file_info(fd, status.nfile-1, &lgfl) < 0) {
	fprintf(stderr,"rtkgps: Error reading information for file %d [%s]\n",
		status.nfile-1, gcstrerror(rcerrno));
	gpsmouse_enable(fd, status.gpsms, cmdopt);
	coms_close(fd, cmdopt);
	exit(5);
      }
      /* Memory used computed from last logfile pointer plus number of 
	 fixes in active logfile */
      mu = lgfl.memp + status.nfix*fix_size(status.fxtyp);
    } else { /* Memory has wrapped around in overwrite mode */
      int n;
      /* Need to compute memory used by adding up number of fixes in each 
	 log file */
      mu = lgfl.nfix*fix_size(lgfl.fxtyp);
      for (n = 1; n < status.nfile; n++) {
	if (get_file_info(fd, n, &lgfl) < 0) {
	  fprintf(stderr,"rtkgps: Error reading information for file "
                 "%d [%s]\n", n, gcstrerror(rcerrno));
	  gpsmouse_enable(fd, status.gpsms, cmdopt);
	  coms_close(fd, cmdopt);
	  exit(5);
	}
	mu += lgfl.nfix*fix_size(lgfl.fxtyp);
      }
    }

    gpsmouse_enable(fd, status.gpsms, cmdopt);
  }

  printf("GPS Fix:            %s\nGPS mouse mode:     %s\n"
	 "Record type:        %s\nMemory full:        %s\n"
	 "Sampling interval:  %hds\nNumber of files:    %hd\n"
	 "Fixes in last file: %d\n", gpsrx_string(status.gpsrx),
	 gpsms_string(status.gpsms), fxtyp_string(status.fxtyp),
	 mfowm_string(status.mfowm), status.sntvl, status.nfile,
	 status.nfix
	 );

  if (cmdopt->eflg) {
    printf("First log fix:      %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n"
	   "Last log fix:       %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n",
	   lgbd.first.date,lgbd.first.date+4,lgbd.first.date+6,
	   lgbd.first.time, lgbd.first.time+2, lgbd.first.time+4,
	   lgbd.last.date,lgbd.last.date+4,lgbd.last.date+6,
	   lgbd.last.time, lgbd.last.time+2, lgbd.last.time+4);
    printf("Device memory:      %7.2fkb\n"
	   "Memory used:        %7.2fkb (%.2f%%)\n",
	   mem.nbytes / 1024.0, mu / 1024.4, ((float)mu / mem.nbytes)*100.0);
    printf("Version:            %s\n"
	   "Firmware:           %s\n", frm.vrsnr, frm.frmwr);
  }

  coms_close(fd, cmdopt);
}