Exemplo n.º 1
0
TEST( ArgParserTest, DashIsAnArg )
{
  ArgParser parser;
  const char* args[] = { "test", "-" };
  parser.Parse( 2, args );

  ASSERT_EQ( 1ul, parser.Arguments().size() );
  ASSERT_EQ( "-", parser.Arguments()[0] );
}
Exemplo n.º 2
0
/**
* <summary>
* Main Program Entry Point.
* </summary>
*/
int main(int argc, const char** argv) 
{
	int retval = 0;
	WriteHeader();

	//Add all the arguments.
	s_args.AddMapEntries( s_argmap);
	s_s1.RegisterArgs( "s1", s_args);
	s_s2.RegisterArgs( "s2", s_args);

	//Parse the arguments.
	retval = s_args.Parse( argc, argv);
	if( retval > 0)
	{
		int addr = (int) s_args.GetLong( "address");
		try {
			addr = s_cfgDevice.Attach(addr);
			printf("Attached to ASR-2300 at address = %d\n", addr);

		} catch (std::runtime_error& re) {
			printf("Error:  %s0\n", re.what());
			return -1;
		}

		// Dump the device information
		DumpDeviceInformation();

		//Initialize the stream loggers.
		retval = s_s1.Init( s_args, &s_cfgDevice);
		if( retval == 0)
			retval = s_s2.Init( s_args, &s_cfgDevice);
	
		//Receive the data and store to disk.
		if( retval == 0)
		{
			s_s1.DisplayConfiguration();
			s_s2.DisplayConfiguration();

			s_cfgDevice.Dci0Transport().ClearReceiveQueue();

			retval = ReceiveData((size_t) (s_args.GetDouble("duration")*1000.0));
		}

		s_s1.Terminate();
		s_s2.Terminate();
		s_cfgDevice.Detach();
	}
	else //Arguments were not right.
	{
		PrintUsage();
	}
	return retval;
}
Exemplo n.º 3
0
TEST( ArgParserTest, LongArgsTest )
{
  ArgParser parser;
  parser.AddOption( 'h', "hello" );
  parser.AddOption( 'g', "goodbye" );

  const char* args[] = { "test", "--hello", "--goodbye", "foo" };
  parser.Parse( 4, args );

  EXPECT_TRUE( parser.HasOption( 'h' ) );
  EXPECT_TRUE( parser.HasOption( "hello" ) );

  EXPECT_TRUE( parser.HasOption( 'g' ) );
  EXPECT_TRUE( parser.HasOption( "goodbye" ) );

  ASSERT_EQ( 1ul, parser.Arguments().size() );
  ASSERT_EQ( "foo", parser.Arguments()[0] );
}
Exemplo n.º 4
0
TEST( ArgParserTest, ThrowsOnUnknownLongArgs )
{
  ArgParser parser;
  const char* args[] = { "test", "--hello" };
  EXPECT_THROW( parser.Parse( 2, args ), Error );
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
   using namespace std;  

   retVal_t returnvalue = rvOK;

   ArgParser AP;
   AP.AddFile(".mat"); /* sysmat */
   AP.AddFile(".rhs", false); /* rhsvec */
   AP.AddFile(".cfg"); /* params */
   AP.AddFile(".sol", false); /* solvec */
   AP.AddOption("-c"); /* cmpmat */
   AP.AddFlag("-h");
	
   if (!AP.Parse(argc, argv))
   {
      cout << "try " << argv[0] << " -h for help" << endl;
      return(rvArgumentError);
   }

   if (AP.FlagSet("-h"))
   {
      printUsageMessage(argv[0]);
      return(returnvalue);
   }

   if (!AP.FileSet(".mat") || !AP.FileSet(".rhs"))
   {
      cout << "system matrix file (.mat) and rhs vector file (.rhs) have to be specified !\n"
           << "try " << argv[0] << " -h for help" << endl;
      return(rvArgumentError);
   }
   

   cout << "Welcome to mattest4c!\n";

   /* Reading system matrix */
   /* ===================== */

   qqqMCSR<qqqComplex> A;
   qqqSolverParameters parms;
   qqqError error;

   cout << "Reading System Matrix (file \"" << AP.FileStr(".mat") << "\") ... " << flush;
   if (!A.readMatrix(AP.FileStr(".mat")))
   {
      cout << "not ok!" << endl;
      return(rvIOError);
   }
   else cout << "ok!\n";

   qqqIndex dimension = A.dimension();

   if (dimension < 1)
   {
      cout << "Error: dimension of system matrix is smaller than 1!" << endl;
      return(rvFormatError);
   }

   cout <<"Backwriting to \"" << (AP.OptionSet("-c") ? AP.OptionStr("-c") : "compare.mat") << "\"... " << flush;
   A.writeMatrix(AP.OptionSet("-c") ? AP.OptionStr("-c") : "compare.mat", true, true);
   cout << "ok!\n";

   /* Reading parameter file */
   /* ====================== */

   if (AP.FileSet(".cfg"))
   {
      cout << "Reading solver parameter file (file \"" << AP.FileStr(".cfg") << "\") ... " << flush;
      if (!parms.readParameters(AP.FileStr(".cfg")))
      {
         cout << "not ok (using default)!\n";
         parms.setDefaultSolverParameters();
      }
      else cout << "ok!\n";
   }   

   /* Allocating memory */
   /* ================= */

   cout << "Allocating memory (dimension = " << qqqIndexToLong(dimension) << ") ... " << flush;

   qqqComplex *x = new qqqComplex[parms.nrhs * dimension];
   qqqComplex *b = new qqqComplex[parms.nrhs * dimension];

#if 1
   qqqComplex **mB;
   qqqComplex **mX;
   if (parms.nrhs > 1)
   {
      mB = new qqqComplex*[parms.nrhs];
      mX = new qqqComplex*[parms.nrhs];

      for (qqqIndex ccirhs = 0; ccirhs < parms.nrhs; ccirhs++)
      {
	 mB[ccirhs] = &b[ccirhs * dimension];
	 mX[ccirhs] = &x[ccirhs * dimension];
      }
   }
   else
   {
      mB = &b; 
      mX = &x;
   }
#endif

   if ((x == NULL) || (b == NULL))
   {
      cout << "not ok [insufficient memory]!\n";
      returnvalue = rvAllocErr;
   }
   else cout << "ok!\n";

   /* Reading right hand side vector(s) */
   /* ================================= */

   //char filename[40];
   string filename;

   if (returnvalue == rvOK)
   {
      cout << "Reading " << parms.nrhs << " right hand side vector(s) (file series \"" << AP.FileStr(".rhs") << "\") ..." << endl; 
      returnvalue = rvIOError;

      for (qqqIndex ccirhs = 0; ccirhs < parms.nrhs; ccirhs++)
      {
         stringstream sbuf;
         sbuf << AP.FileStr(".rhs") << ccirhs << ends;
         sbuf >> filename;
	 qqqIndex readRetval = qqqReadVector(&b[ccirhs * dimension], dimension, filename.c_str());
	 if (readRetval == -1)
	    cout << "   " << filename << ": not ok [file not found]!\n";
	 else if (readRetval == -2)
	    cout << "   " << filename << ": not ok [header mismatch]!\n";
	 else if (readRetval == -3)
	    cout << "   " << filename << ": not ok [dimension mismatch]!\n";
	 else if (readRetval == -4)
            cout << "   " << filename << ": not ok [end of file error]!\n";
	 else if (readRetval != dimension)
            cout << "   " << filename << ": not ok [format error: row " << readRetval << "]!\n";
	 else
	 {
            cout << "   " << filename << ": ok!\n";
	    returnvalue = rvOK;     
	 }

	 if (returnvalue != rvOK)
	    break;
      }
   }
Exemplo n.º 6
0
int _tmain(int argc, _TCHAR* argv[])
{
	VectorReader myVectorReader;
	VectorRecord_t currentVector;
	ArgParser myArgParser;

	unsigned long seconds_counter = 0;
	unsigned long steps_counter = 0;
	bool update_vector = false;
	bool update_PID_control = false;
	bool last_iteration = false;
	
	float plantState;
	float processF;
	uint16_t processValue;
	float setPointF;
	uint16_t setPoint; 
	uint16_t setPoint_old = 0;
	float effect = 0;
	
	float k_norm = 0.446f;
	float offset_norm = 48.144f;

	float tempSetting;							// Temperature setting
	bool reg_enabled;								// Heater ON/OFF
	uint8_t pid_mode;
	
	char *input_fname;
	char *output_dir;
	char *tmp_arg_str;
	int simulation_mode;

	char tmp_buf_char[100];

	//--------------------------------------------//
	// Command line arguments parsing

	myArgParser.Parse(argc, (char **)argv);
	 //myArgParser.PrintOptions();
	 //std::cin.get();
	 //return 0;

	if (!(input_fname = myArgParser.GetOptionValue("-input")))
	{
		std::cout << "Expected test vector file (-input <file>)" << std::endl;
		std::cin.get();
		return 0;
	}
	
	if (!(output_dir = myArgParser.GetOptionValue("-outdir")))
	{
		std::cout << "Expected output directory (-outdir <directory>)" << std::endl;
		std::cin.get();
		return 0;
	}

	if (!(tmp_arg_str = myArgParser.GetOptionValue("-mode")))
	{
		std::cout << "Expected simulation mode (-mode <PLANT_STEP / NORMAL>)" << std::endl;
		std::cin.get();
		return 0;
	}
	simulation_mode = (strcmp(tmp_arg_str, "PLANT_STEP") == 0) ? SIM_PLANT_STEP_RESPONSE : SIM_NORMAL;

	//--------------------------------------------//



	//-----------------------------//
	// Reading test vector file
	if (myVectorReader.ReadVectorFile(input_fname) == false)
	{
		std::cout << "Cannot read test vector file. Press any key to exit." << std::endl;
		std::cin.get();
		return 0;
	}

	std::cout << "Test vector file OK. Starting simulation." << std::endl;


	//-----------------------------//
	// Initializing simulation
	
	if (!CreateDirectory(output_dir,NULL))
	{
		if (GetLastError() != ERROR_ALREADY_EXISTS)
		{
			std::cout << "Cannot create output log directory" << std::endl;
			std::cin.get();
			return 0;
		}
	}

	// Open LOG files
	FILE *f_state_float;
	FILE *f_state_int;
	FILE *f_setting;
	FILE *f_p_term;
	FILE *f_d_term;
	FILE *f_i_term;
	FILE *f_pid_output;

	// Create log data files:

	// Plant state float
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_0f.txt");
	fopen_s( &f_state_float, tmp_buf_char, "w" ); 
	// Plant state integer
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_0.txt");
	fopen_s( &f_state_int, tmp_buf_char, "w" ); 
	// Set value
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "setting.txt");
	fopen_s( &f_setting, tmp_buf_char, "w" ); 
	// P-term of PID controller
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_5.txt");
	fopen_s( &f_p_term, tmp_buf_char, "w" ); 
	// D-term of PID controller
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_6.txt");
	fopen_s( &f_d_term, tmp_buf_char, "w" ); 
	// I-term of PID controller
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_7.txt");
	fopen_s( &f_i_term, tmp_buf_char, "w" ); 
	// Output of PID controller
	sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_8.txt");
	fopen_s( &f_pid_output, tmp_buf_char, "w" ); 
	

	// Set ambient temperature and plant internal state
	if (!myVectorReader.StartConditions.AmbientValid)
		myVectorReader.StartConditions.Ambient = 25;
	if (!myVectorReader.StartConditions.StateValid)
		myVectorReader.StartConditions.SystemState = 25;
	initPlant((float)myVectorReader.StartConditions.Ambient, (float)myVectorReader.StartConditions.SystemState); 
	processPlant(0);

	// Initialize PID controller 
	setPIDIntegratorLimit(0);
	
	// Initial simulator state
	reg_enabled = false;		// heater OFF
	tempSetting = 25.0f;		// Temperature default setting
	myVectorReader.GetNextVector(&currentVector);
	
	//int32_t aaa;
	//aaa = INT32_MAX;
	//printf("%d",aaa);
	//std::cin.get();

	//-----------------------------//
	// Simulate

	while(true)
	{
		// Process time counters
		update_vector = false;
		update_PID_control = false;
		if (steps_counter % STEPS_PER_SECOND == 0)
		{
			if (seconds_counter == currentVector.TimeStamp)
			{
				update_vector = true;
			}
			if (seconds_counter % PID_CALL_INTERVAL == 0)
			{
				update_PID_control = true;
			}
			seconds_counter++;
		}
		steps_counter++;

		// Update setting using data from test vector file
		if (update_vector)
		{
			if (last_iteration)
			{
				printf("%10lu sec. Simulation finished.\n", currentVector.TimeStamp);
				break;
			}
			
			reg_enabled = currentVector.ProcessEnabled;
			if (reg_enabled)
			{
				tempSetting = (float)currentVector.ForceValue;		
				setPIDIntegratorLimit((int)tempSetting);
			}
			
			if (reg_enabled)
				printf("%10lu sec. New setting = %.2f\n", currentVector.TimeStamp, tempSetting);
			else
				printf("%10lu sec. New setting = %s\n", currentVector.TimeStamp, "OFF");
			
			last_iteration = !myVectorReader.GetNextVector(&currentVector);
			//std::cin.get();
		}


		// Process plant with TIMESTEP interval
		processPlant(effect);	
		
		// Process regulator 
		if (simulation_mode == SIM_PLANT_STEP_RESPONSE)
		{
				if (reg_enabled)
					effect = 100;
				else
					effect = 0;
				dbg_PID_output = (int16_t)effect;
		}
		else
		{
				if (update_PID_control)
				{	
					// Calculate process value
					plantState = (float)getPlantState();					
					processF = (plantState + offset_norm) / k_norm;	
					processF *= 4;
					//processF /= 2;
					processValue = (uint16_t)processF;
			
					// Calculate setpoint
					setPointF = (tempSetting + offset_norm) / k_norm;
					setPointF *= 4;
					//setPointF /= 2;
					setPoint = (uint16_t)setPointF;	
			
					// PID
					pid_mode = 0;
					if (reg_enabled)
						pid_mode |= PID_ENABLED;
					effect = processPID(setPoint, processValue,pid_mode);
				}
		}
		

		// LOG
		fprintf(f_state_float, "%f\r", getPlantState());
		fprintf(f_state_int, "%u\r", (uint16_t)getPlantState());		
		fprintf(f_setting, "%d\r", (int)tempSetting);
		fprintf(f_p_term, "%d\r", dbg_PID_p_term);
		fprintf(f_d_term, "%d\r", dbg_PID_d_term);
		fprintf(f_i_term, "%d\r", dbg_PID_i_term);
		fprintf(f_pid_output, "%d\r", dbg_PID_output);

	}

	//-------------------------------//


	
	fclose(f_state_float);
	fclose(f_state_int);
	fclose(f_setting);
	fclose(f_p_term);
	fclose(f_d_term);
	fclose(f_i_term);
	fclose(f_pid_output);
	
	std::cout << "Done. Press enter to exit." << std::endl;
	std::cin.get();

	return 0;
}