void
goto_line(int new_line)
{
  char c;
  while (ln < new_line) {
    if (read(entry, &c, 1) != 1 || c == '\0') notif_error("[EOF]");
    if (c == '\n') ln++;
  }
  store_line();
  ln = new_line;
}
void
copy_lines(int m)
{
  int cnt = ln;
  char c;
  if (m < ln) notif_error("Cannot copy previous line(s)");
  do {
    if (read(entry, &c, 1) != 1) notif_error("Error reading entry");
    if (c == '\n') cnt++;
    if (write(outfile, &c, 1) != 1) notif_error("Error writing outfile");
  } while (cnt <= m);
  store_line();
  ln = m + 1;
}
示例#3
0
void process_test_stream(void)

{

  int forever = TRUE;
  char *callsign;
  double lat, lon, alt;

  date_time_t wall_time;
  time_t last_store = 0;

  init_test_data();

  while (forever) {
    
    PMU_auto_register("Got data");
    
    get_test_data(&callsign, &lat, &lon, &alt);
    
    /*
     * substitute wall clock time for gps time
     */
    
    wall_time.unix_time = time(NULL);
    uconvert_from_utime(&wall_time);

    if((wall_time.unix_time - last_store) >= Glob->params.data_interval) {

      store_line(&wall_time, lat, lon, alt, callsign,
		 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0);

      if (Glob->params.use_spdb) {
	if (Glob->params.single_database) {
	  store_single_spdb(&wall_time, lat, lon, alt, callsign);
	} else {
	  store_mult_spdb(&wall_time, lat, lon, alt, callsign);
	}
      } /* if (Glob->params.use_spdb) */
      
      last_store = wall_time.unix_time;

    } /* if((wall_time.unix_time - last_store) ... */
    
    sleep(1);
    
  } /* while (forever) */

  free_test_data();

}
示例#4
0
void ConfParser::parse_file(std::string filename)
{
	std::ifstream infile (filename.c_str());
	
	bool in_domains = false;
	
	std::string line;
	std::string key;
	std::string value;
	
	while( std::getline(infile, line) ) {
		if (line.size() != 0) {
			//Remove comments if necessary
			int eol = line.find("#");
			if (eol != -1) {
				line = line.substr(eol,line.size()-eol);
			}
		
			std::istringstream is_line(line);
			
			//Handle the DOMAINS array
			if (in_domains) {
				this->m_domains.push_back(this->handle_array_line(line));
				if (line.find("]") != std::string::npos) {
					in_domains = false;
				}
			}
			//Else look for the key=value structure
			else if( std::getline(is_line, key, '=') ) {
				if( std::getline(is_line, value) ) {
					if (key.compare("DOMAINS")==0) {
						in_domains = true;
						this->m_domains.push_back(this->handle_array_line(value));
					}
					else {
						store_line(key, value);
					}
				}
			}
			else {
				std::cerr << "Non-valid line in conf file: "<<line<<std::endl;
				exit(EXIT_FAILURE);
			}
		}
	}
}
void
main(int argc, char** argv)
{
  if (argc < 3)
    notif_error("Missing argument(s)\n");

  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
  if ((entry = open(argv[1], O_RDONLY)) == -1)
    notif_error("Cannot open entry file");
  if ((outfile = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, mode)) == -1)
    notif_error("Cannot open output file");

  ln = 1;
  store_line();

  while (1) {
    read_instr();
    inter_instr();
  }

  close(entry);
  close(outfile);
}
/* Does the actual processing of the frame */
static void do_work(ppu_data_t ppu_data) {
	struct image input;
	struct image big_image;

	dprintf("SPU[%d] ppu_data.input:%p ppu_big_img:%p sizeof(struct image):%lu\n",
		ppu_data.spe_id, (void *)ppu_data.input,
		(void *)ppu_data.big_image, sizeof(struct image));

	/* Get input image and big_image details */
	mfc_get((void *)(&input), (uint32_t)(ppu_data.input),
			(uint32_t)(sizeof(struct image)), tag_id, 0, 0);
	mfc_get((void *)(&big_image), (uint32_t)(ppu_data.big_image),
			(uint32_t)(sizeof(struct image)), tag_id, 0, 0);

	waittag(tag_id);
	dprintf("SPU[%d] got structs\n"\
			"input.width=%u\tinput.height=%u\n"\
			"big_image.width=%u\tbig_image.height=%u\n"\
			"input.data=%p\tbig_image.data=%p\n",
			ppu_data.spe_id, input.width, input.height, big_image.width,
			big_image.height, (void *)input.data, (void *)big_image.data);

	struct image img_chunk;
	unsigned int buf_line_sz = input.width * NUM_CHANNELS;
	int transfer_sz = 4 * buf_line_sz;

	img_chunk.width = input.width;
	img_chunk.height = 4;
	alloc_image(&img_chunk);

	struct image img_scaled_line;
	img_scaled_line.width = input.width / SCALE_FACTOR;
	img_scaled_line.height = 1;

	/* Hack for memory align of local image data to have the same 4 bits in its
	 * address as the remote corresponding address in PPU
	 */
	int left_padding = (ppu_data.spe_id % 4) * 4;
	unsigned char* addr_to_free = malloc_align(NUM_CHANNELS * 3 * sizeof(char) +
												left_padding, 4);

	img_scaled_line.data = addr_to_free + left_padding;

	unsigned int i;
	/* Process 4 lines from the initial image at a time */
	for (i = 0; i < input.height / img_chunk.height; ++i) {

		/* Get the image chunk from PPU through DMA transfer */
		dprintf("SPU[%d] getting image_chunk %d of size %d\n",
				ppu_data.spe_id, i, transfer_sz);

		dprintf("SPU[%d] input.data=%p img_chunk.data=%p "\
				"start_addr=%p\n", ppu_data.spe_id, (void *)input.data,
				(void *)img_chunk.data, (void *)((uint32_t)(input.data) + i * transfer_sz));

		mfc_get((void *)(img_chunk.data), (uint32_t)(input.data) + i * transfer_sz,
				(uint32_t)(transfer_sz), tag_id, 0, 0);

		waittag(tag_id);
		dprintf("SPU[%d] got image_chunk %d\n", ppu_data.spe_id, i);

		compute_lines_average(&img_chunk, buf_line_sz);

		/* Make average for column. avg = (c0.r + c1.r) / 2 etc*/
		compute_columns_average(&img_chunk, &img_scaled_line);

		store_line(&img_scaled_line, ppu_data, &big_image, i);
	}

	free_image(&img_chunk);
	free_align(addr_to_free);
}
示例#7
0
void process_realtime_stream(FILE *tty_file)

{

  int forever = TRUE;
  char line[BUFSIZ];
  char spaced_line[BUFSIZ];

  char callsign[8];

  int ilat, ilon;
  int itas, igps_alt, ipres_alt;
  int itdry, ilwjw, idewpt;
  int ice_count;
  int left_burn, right_burn, flare_state, snowmax_state;
  int igps_var, igps_err, iarnav_warn;

  date_time_t gps_time, wall_time;
  time_t last_store = 0;
  
  while (forever) {
    
    /*
     * wait for data, registering once per second while waiting
     */

    while (ta_read_select(tty_file, 1000) != 1) {
      PMU_auto_register("Waiting for data");
    }

    PMU_auto_register("Got data");

    if (fgets(line, BUFSIZ, tty_file) == NULL) {
      fprintf(stderr, "ERROR - %s:process_stream\n", Glob->prog_name);
      perror(Glob->params.input_device);
      return;
    }

    add_spaces(line, spaced_line);

    if (Glob->params.debug) {
      fprintf(stderr, "Input line:\n%s", line);
      fprintf(stderr, "Spaced line:\n%s\n", spaced_line);
    }
    
    if (sscanf(spaced_line,
	       "%s %d %d %d %d %d %d %d %d %d"
	       "%d %d %d %d %2d %2d %2d %d %d %d",
	       callsign, &ilat, &ilon, &itas, &igps_alt, &ipres_alt,
	       &itdry, &ilwjw, &idewpt, &ice_count,
	       &left_burn, &right_burn, &flare_state, &snowmax_state,
	       &gps_time.hour, &gps_time.min, &gps_time.sec,
	       &igps_var, &igps_err, &iarnav_warn) == 20) {

      if (Glob->params.debug) {

	fprintf(stderr, "Decoding   : %s", line);
	fprintf(stderr, "Callsign   : %s\n", callsign);
	fprintf(stderr, "lat        : %g\n", ilat / 10000.0);
	fprintf(stderr, "lon        : %g\n", ilon / 10000.0);
	fprintf(stderr, "tas        : %d\n", itas);
	fprintf(stderr, "gps_alt    : %g\n", igps_alt / 100.0);
	fprintf(stderr, "pres_alt   : %g\n", ipres_alt / 100.0);
	fprintf(stderr, "tdry       : %g\n", itdry / 10.0);
	fprintf(stderr, "lwJW       : %g\n", ilwjw / 100.0);
	fprintf(stderr, "dewpt      : %g\n", idewpt / 10.0);
	fprintf(stderr, "left burn  : %d\n", left_burn);
	fprintf(stderr, "right burn : %d\n", right_burn);
	fprintf(stderr, "flare state: %d\n", flare_state);
	fprintf(stderr, "snow state : %d\n", snowmax_state);
	fprintf(stderr, "time       : %.2d:%.2d:%.2d\n",
		gps_time.hour, gps_time.min, gps_time.sec);
	fprintf(stderr, "gps var    : %d\n", igps_var);
	fprintf(stderr, "gps err    : %d\n", igps_err);
	fprintf(stderr, "arnav code : %d\n", iarnav_warn);
	
      }

      /*
       * substitute wall clock time for gps time
       */

      wall_time.unix_time = time(NULL);
      uconvert_from_utime(&wall_time);

      if((wall_time.unix_time - last_store) >= Glob->params.data_interval) {

	store_line(&wall_time,
		   (double) ilat / 10000.0,
		   (double) ilon / 10000.0,
		   (double) ipres_alt / 100.0,
		   callsign,
		   itas,
		   (double) itdry / 10.0,
		   (double) ilwjw / 100.0,
		   (double) idewpt / 10.0,
		   left_burn,
		   right_burn,
		   flare_state,
		   snowmax_state);

	if (Glob->params.use_spdb) {

	  if (Glob->params.single_database) {

	    store_single_spdb(&wall_time,
			      (double) ilat / 10000.0,
			      (double) ilon / 10000.0,
			      (double) ipres_alt / 100.0,
			      callsign);
	    
	  } else {

	    store_mult_spdb(&wall_time,
			    (double) ilat / 10000.0,
			    (double) ilon / 10000.0,
			    (double) ipres_alt / 100.0,
			    callsign);

	  }

	} /* if (Glob->params.use_spdb) */

	last_store = wall_time.unix_time;

      } /* if((wall_time.unix_time - last_store) ... */

    } else {
      
      if (Glob->params.debug) {
	fprintf(stderr, "WARNING - %s:process_stream\n", Glob->prog_name);
	fprintf(stderr, "Cannot decode: %s\n", (char *) spaced_line);
      }
      
    }

  } /* while (forever) */

}