示例#1
0
文件: sim_main.c 项目: duke1swd/HSIM
int
main(int argc, char **argv)
{
	FILE *datafile;

	grok_args(argc, argv);

	datafile = stdout;

	initialize();
	report_input(datafile);
	record_data_init(0., datafile);
	sim_loop();
	record_data_term();
	print_errors(stderr);
	fprintf(datafile, "SECTION,errors\n");
	print_errors(datafile);
	fprintf(datafile, "\n");
	exit(0);
}
示例#2
0
int main(int argc, char *argv[]) {
  uint32_t tick_rate=1;
  int positional_args=0;

  //defaults
  args.step_out_file = stderr;
  args.block_out_file = stdout;
  args.grbl_out_file = stdout;
  args.comment_char = '#';

  args.step_time = 0.0;
  // Get the minimum time step for printing stepper values.
  // If not given or the command line cannot be parsed to a float than
  // step_time= 0.0; This means to not print stepper values at all

  progname = argv[0];
  while (argc>1) {
	  argv++;argc--;
	  if (argv[0][0] == '-'){
		 switch(argv[0][1]){
		 case 'c':  //set Comment char 
			args.comment_char = argv[0][2];
			break;
		 case 'n': //No comment char on grbl responses
			args.comment_char = 0;
			break;
		 case 't': //Tick rate
			argv++;argc--;
			tick_rate = atof(*argv);
			break;
		 case 'b': //Block file
			argv++;argc--;
			args.block_out_file = fopen(*argv,"w");
			break;
		 case 's': //Step out file.
			argv++;argc--;
			args.step_out_file = fopen(*argv,"w");
			break;
		 case 'g': //Grbl output
			argv++;argc--;
			args.grbl_out_file = fopen(*argv,"w");
			break;
		 case 'r':  //step_time for Reporting
			argv++;argc--;
			args.step_time= atof(*argv);
			break;
		 case 'h':
			return usage(NULL);
		 default:
			return usage(*argv);
		 }
	  }
	  else { //handle old positional argument interface
		 positional_args++;
		 switch(positional_args){
		 case 1:
			args.step_time= atof(*argv);
			break;
		 case 2:  //block out and grbl out to same file, like before.
			args.block_out_file = fopen(*argv,"w");
			args.grbl_out_file = args.block_out_file;
			break;
		 default:
			return usage(*argv);
		 }
	  }
  }

  // Make sure the output streams are flushed immediately.
  // This is important when using the simulator inside another application in parallel
  // to the real grbl.
  // Theoretically flushing could be limited to complete lines. Unfortunately Windows
  // does not know line buffered streams. So for now we stick to flushing every character.
  //setvbuf(stdout, NULL, _IONBF, 1);
  //setvbuf(stderr, NULL, _IONBF, 1);
  //( Files are now closed cleanly when sim gets EOF or CTRL-F.)
  platform_init(); 

  init_simulator(tick_rate);

  //launch a thread with the original grbl code.
  plat_thread_t*th = platform_start_thread(avr_main_thread); 
  if (!th){
	 printf("Fatal: Unable to start hardware thread.\n");
	 exit(-5);
  }

  //All the stream io and interrupt happen in this thread.
  sim_loop();

  platform_kill_thread(th); //need force kill since original main has no return.

  // Graceful exit
  shutdown_simulator(0);
  platform_terminate();

  exit(EXIT_SUCCESS);
}