Example #1
0
  void GRCsim::execute_vectors(std::istream &vf)
  {
    string line;

    // Enumerate the inputs to be read from the vector file

    vector<SignalSymbol*> inputs;

    for ( SymbolTable::const_iterator isym = sigs->begin() ;
  	isym != sigs->end() ; isym++ ) {
      SignalSymbol *ss = dynamic_cast<SignalSymbol*>(*isym);
      assert(ss);
      if ( ss->name != "tick" && (ss->kind == SignalSymbol::Input ||
  				ss->kind == SignalSymbol::Inputoutput ) ) {
        if ( debug & debugVectors ) std::cout << ss->name << '\n';
        inputs.push_back(ss);
      }
    }

    init();

    int ntick = 0;
    ISFinal = false;
    do {
      getline(vf, line);
      if (vf.fail()) break;

      if ( line.size() < inputs.size() ) {
        cerr << "Not enough inputs (" << line.size() << '<' << inputs.size()
  	   << ") in test vector file\n"
             << "Got \"" << line << "\"\n";
        exit(-2);
      }

      clear_inputs();
      string::const_iterator j = line.begin();
      for ( vector<SignalSymbol*>::const_iterator i = inputs.begin() ;
  	  i != inputs.end() ; j++ )
  	if ((*j) != ' ') {
            if ((*j) == '1')
              signals[*i] = 1;
            else if ((*j) == '0')
    	    signals[*i] = 0;
            else{ 
              signals[*i] = -1; //unknown
              ternary = true; //FIXME: may be wrong
            }
            i++;
  	}
      
      if (debug) cerr << "######## TICK " << ntick <<" TV :"<<line<< endl;
      char buf[5];
      sprintf(buf, "%4d ", ntick);
      outf << buf;
      ntick++;

      dotick();
    } while (!ISFinal);
  }
Example #2
0
  void GRCsim::execute_max(int maxticks)
  {
    int ntick;
    
    useold=0;
    
    init();
    ntick=0;
    ISFinal = false;

    do {
      if (debug) cerr << "######## TICK " << ntick << endl;
      char buf[5];
      sprintf(buf, "%4d ", ntick);
      outf << buf;
      ntick++;
      clear_inputs();
      dotick();
    } while ((!ISFinal) && (maxticks < 0 || (ntick < maxticks)));
  }
Example #3
0
int main(int argc, char *argv[]) {
  int notdone=1;
  char buf[1024];
  int val[9], i, ch, code;
  time_t starttime, curtime;
  struct timeval tv;
  struct timezone tz;
  struct tm *ltime;
  int interval = 1;

  setup_vars();
  
  printf("Hello, World!\n");
  if (get_args(argc, argv) != 0) {
    show_usage();
    exit(1);
  }
  for(ch=0;ch<CHMAX;ch++) {
    clear_reading_storage(ch);
  }
  clear_inputs(interval);
  make_line();
  if ((fd = open(dsrc, O_RDWR|O_NONBLOCK)) < 0) {
    printf("couldn't open data source file\n");
    exit(1);
  }
  start_serial_io(fd, baud);
  my_fgets(buf, 1000, fd);
  notdone = 0;
  printf("syncing time...\n");
  while (notdone < 2) {
    starttime = time(NULL);
    ltime = localtime(&starttime);
    if ((ltime->tm_sec % interval) == 0) {
      notdone++;
    } else {
      /* sleep(1); */
      my_fgets(buf, 1000, fd);
    }
    curday = ltime->tm_mday;
    set_curdatestring(ltime);
  }
  if (log_file_name != NULL) {
    start_log_file();
  }
  printf("starting at %010d\n", (int) starttime);
  notdone = 1;
  while (notdone) {
    /* take care of time first */
    curtime = time(NULL);
    if (curtime >= (starttime + interval)) {
      if (logfp != NULL) {
        fprintf(logfp, "%010d (%s)", (int) starttime, safe_ctime(&starttime));
      } else {
        printf("%010d (%s)", (int) starttime, safe_ctime(&starttime));
      }
      for (ch=0;ch<CHMAX;ch++) {
        dump_reading(ch);
        clear_reading_storage(ch);
      }
      /* dump_inputs(); */
      if (logfp != NULL) {
        fprintf(logfp, "\n");
      } else {
        printf("\n");
      }
      starttime = curtime;
      ltime = localtime(&curtime); /* ltime is needed here and ctime messes it up */
      /* check for the day change here so that the last second of yesterday
         ends up in *yesterday's* log and this days data ends up in this
         days log */
      if (ltime->tm_mday != curday) {
        set_curdatestring(ltime);
        if (log_file_name != NULL) {
          fclose(logfp);
          start_log_file();
        }
        curday = ltime->tm_mday;
      } else {
        /* flush whenever a line is written */
        if (logfp != NULL) {
          fflush(logfp);
        } else {
          fflush(stdout);
        }
      }
    }
    if (my_fgets(buf, 1000, fd) == 1) {
      if (strlen(buf) > 4) {
        /* printf("%s", buf); */
        buf[strlen(buf) - 1] = 0;
        chop_input(buf, val, &code);
        /* test_code_change(~code, curtime); */
        for (ch=0;ch<CHMAX;ch++) {
          add_reading(ch, val[ch+1]);
        }
      }
    } else { /* don't consume 100% of the processor. */
      usleep(1000);
    }
    fflush(stdout);
  }
  exit(0);
}