示例#1
0
void serieport_print_int(int num) {
	if (num == 0) {
		write_SCI(USART6, '0');
		return;
	} else if (num < 0) {
		write_SCI(USART6, '-');
		num = -num;
	}
	
	char buf[32];
	int i=0, j=0;
	while (num != 0 && i < 32) {
		int rem = num % 10;
		buf[i++] = '0' + rem;
		num /= 10;
	}
	for (j = i-1; j >= 0; j--) {
		write_SCI(USART6, buf[j]);
	}
}
示例#2
0
int serieport_getsettings(struct audio_settings *settings) {
	static int id = 0;
	static int value = 0;
	
	if (USART_GetFlagStatus(USART6, USART_FLAG_RXNE) != RESET) {
		unsigned char data = (unsigned char) USART_ReceiveData(USART6);
		write_SCI(USART6, data);
		if (id == 0 && data >= 'A' && data <= 'G') {
			id = data - 'A' + 1;
		} else if (id > 0 && data == 'Z') {
			switch (id) {
				case 1:
					settings->equ_freqA = value;
					break;
				case 2:
					settings->equ_freqB = value;
					break;
				case 3:
					settings->equ_band1_vol = value;
					break;
				case 4:
					settings->equ_band2_vol = value;
					break;
				case 5:
					settings->equ_band3_vol = value;
					break;
				case 6:
					settings->echo_delay = value;
					break;
				case 7:
					settings->echo_vol_decay = value;
					break;
			}
			id = 0;
			value = 0;
			return 1;
		} else if (id > 0 && data >= '0' && data <= '9') {
			value *= 10;
			value += data - '0';
		}
	}
	return 0;
}
示例#3
0
文件: demo.c 项目: farocean97/ffd1
///////////////////////////////////////////////////////////////////////////////
///\brief Main program
///
/// Initialize the simualtion and read input data from SCI,run the simulations, 
/// and write the results
///
///
///\return void No return needed
///////////////////////////////////////////////////////////////////////////////
int main() { 
  para.geom = &geom;
  para.outp = &outp1;
  para.prob = &prob;
  para.mytime = &mytime;
  para.bc     = &bc;
  para.solv   = &solv;

  initial(&para);

  if(!read_max(&para, var)) {
    printf("no file"); exit(1);
  }

  if(!allocate_data( ))    exit ( 1 );

  clear_data(&para,  var,BINDEX);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  if(!read_input(&para, var,BINDEX)) {
    printf("no file"); exit(1);
  }

  init_data(&para,  var,BINDEX);

  mark_cell(&para, var,BINDEX);

  if(para.solv->read_file==1) read_data(&para,var);
  
  FFD_solver(&para, var,BINDEX);
  write_SCI(&para,  var, "output");
  free_data(var);
  free_index(BINDEX);
  
  //getchar();  
  exit ( 0 );
} // End of main( )
示例#4
0
///////////////////////////////////////////////////////////////////////////////
/// Main routine of FFD
///
///\para coupled simulation Integer to identify the simulation type
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int ffd(int cosimulation) {
#ifndef _MSC_VER //Linux
  //Initialize glut library
  char fakeParam[] = "fake";
  char *fakeargv[] = { fakeParam, NULL };
  int fakeargc = 1;
  glutInit( &fakeargc, fakeargv );
#endif

  // Initialize the parameters
  para.geom = &geom;
  para.inpu = &inpu;
  para.outp = &outp1;
  para.prob = &prob;
  para.mytime = &mytime;
  para.bc     = &bc;
  para.solv   = &solv;
  para.sens   = &sens;
  para.init   = &init;
  // Stand alone simulation: 0; Cosimulaiton: 1
  para.solv->cosimulation = cosimulation; 

  if(initialize(&para)!=0) {
    ffd_log("ffd(): Could not initialize simulation parameters.", FFD_ERROR);
    return 1;
  }

  // Overwrite the mesh and simulation data using SCI generated file
  if(para.inpu->parameter_file_format == SCI) {
    if(read_sci_max(&para, var)!=0) {
      ffd_log("ffd(): Could not read SCI data.", FFD_ERROR);
      return 1;
    }
  }
  
  // Allocate memory for the variables
  if(allocate_memory(&para)!=0) {
    ffd_log("ffd(): Could not allocate memory for the simulation.", FFD_ERROR);
    return 1;
  }

  // Set the initial values for the simulation data
  if(set_initial_data(&para, var, BINDEX)) {
    ffd_log("ffd(): Could not set initial data.", FFD_ERROR);
    return 1;
  }

  // Read previous simulation data as initial values
  if(para.inpu->read_old_ffd_file==1) read_ffd_data(&para, var);

  ffd_log("ffd.c: Start FFD solver.", FFD_NORMAL);
  //write_tecplot_data(&para, var, "initial");

  // Solve the problem
  if(para.outp->version==DEMO) {
    open_glut_window();
    glutMainLoop();
  }
  else
    if(FFD_solver(&para, var, BINDEX)!=0) {
      ffd_log("ffd(): FFD solver failed.", FFD_ERROR);
      return 1;
    }

  /*---------------------------------------------------------------------------
  | Post Process
  ---------------------------------------------------------------------------*/
  // Calculate mean value
  if(para.outp->cal_mean == 1)
    average_time(&para, var);

  if(write_unsteady(&para, var, "unsteady")!=0) {
    ffd_log("FFD_solver(): Could not write the file unsteady.plt.", FFD_ERROR);
    return 1;
  }

  if(write_tecplot_data(&para, var, "result")!=0) {
    ffd_log("FFD_solver(): Could not write the file result.plt.", FFD_ERROR);
    return 1;
  }

  if(para.outp->version == DEBUG)
    write_tecplot_all_data(&para, var, "result_all");

  // Write the data in SCI format
  write_SCI(&para, var, "output");

  // Free the memory
  free_data(var);
  free_index(BINDEX);

  // End the simulation
  if(para.outp->version==DEBUG || para.outp->version==DEMO) {}//getchar();

  // Inform Modelica the stopping command has been received 
  if(para.solv->cosimulation==1) {
    para.cosim->para->flag = 2; 
    ffd_log("ffd(): Sent stopping signal to Modelica", FFD_NORMAL);
  }

  return 0;
} // End of ffd( )
示例#5
0
void serieport_print_str(char *str) {
	while (*str != '\0') {
		write_SCI(USART6, *str);
		str++;
	}
}