Skip to content. | Skip to navigation

Personal tools

remote/ini.cpp

remote/ini.cpp

remote/ini.cpp

/////////////////////////////////////////////////////////////////////////////
// INI.CPP
//
//  Last updated: 03/12/2002
//
//  Part of the source code for the remote M3 Program
//
//  Contains routines for reading and editing REMM3.INI
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// ScanFloat - Reads a float from M3.INI
int ScanFloat(float *data,FILE* f)
// This procedure reads a floating point value from a line in the M3.INI
// file. Lines that begin with a ";" are ignored as a comment.
// Characters on regular lines are ignored until an "=" is found, and all
// later characters on the line are read into a float.
// Example of a valid set of lines:
//
//
//              ;Meteors are very interesting!
//              Bacteria per meteor ratio = 34.7
//
// Pass it the file being read in "f", and a pointer to the variable that
// will be set with the read value in "*data".
// Returns a 0 on success, 1 on failure
{
	char line[80];
	int i;

	do
		fgets(line,80,f);
	while (!feof(f) && (line[0] == ';'));
	i = 0;
	while ((i < strlen(line)) && (line[i] != '='))
		i++;
	if (feof(f) || (i == strlen(line))) return(1);
	if (sscanf(&line[i+1],"%f",data) != 1) return(1);
	return(0);
}

/////////////////////////////////////////////////////////////////////////////
// ScanInt - Read an int from M3.INI
int ScanInt(int *data,FILE* f)
// This procedure reads an integer from a line in the M3.INI
// file. Lines that begin with a ";" are ignored as a comment.
// Characters on regular lines are ignored until an "=" is found, and all
// later characters on the line are read into an int.
// Example of a valid set of lines:
//
//
//              ;Always obey the speed limit.
//              Speed limit in the desert = 75
//
// Pass it the file being read in "f", and a pointer to the variable that
// will be set with the read value in "*data".
// Returns a 0 on success, 1 on failure
{
	char line[80];
	int i;

	do
		fgets(line,80,f);
	while (!feof(f) && (line[0] == ';'));
	i = 0;
	while ((i < strlen(line)) && (line[i] != '='))
		i++;
	if (feof(f) || (i == strlen(line))) return(1);
	if (sscanf(&line[i+1],"%d",data) != 1) return(1);
	return(0);
}

/////////////////////////////////////////////////////////////////////////////
// ScanHex - Read a hexadecimal int from M3.INI
int ScanHex(int *data,FILE* f)
// This procedure reads a hexadecimal integer from a line in the M3.INI
// file. Lines that begin with a ";" are ignored as a comment.
// Characters on regular lines are ignored until an "=" is found, and all
// later characters on the line are read into an int.
// Example of a valid set of lines:
//
//
//              ;Always obey the speed limit.  (48 is hex for 75)
//              Speed limit in the desert = 48
//
// Pass it the file being read in "f", and a pointer to the variable that
// will be set with the read value in "*data".
// Returns a 0 on success, 1 on failure
{
	char line[80];
	int i;

	do
		fgets(line,80,f);
	while (!feof(f) && (line[0] == ';'));
	i = 0;
	while ((i < strlen(line)) && (line[i] != '='))
		i++;
	if (feof(f) || (i == strlen(line))) return(1);
	if (sscanf(&line[i+1],"%x",data) != 1) return(1);
	return(0);
}

/////////////////////////////////////////////////////////////////////////////
// ScanChar - Read a single character form M3.INI
int ScanChar(char *data,FILE* f)
// This procedure reads a character from a line in the M3.INI
// file. Lines that begin with a ";" are ignored as a comment.
// Characters on regular lines are ignored until an "=" is found, and the
// character between quotes is read.
// Example of a valid set of lines:
//
//
//              ;What grade did you get
//              Grade = "F"
//
// Pass it the file being read in "f", and a pointer to the variable that
// will be set with the read value in "*data".
// Returns a 0 on success, 1 on failure
{
	char line[80];
	int i;

	do
		fgets(line,80,f);
	while (!feof(f) && (line[0] == ';'));
	i = 0;
	while ((i < strlen(line)) && (line[i] != '='))
		i++;
	while ((i < strlen(line)) && (line[i] != '"'))
		i++;
	i++;
	if (feof(f) || (i == strlen(line))) return(1);
	*data = line[i];
	return(0);
}

/////////////////////////////////////////////////////////////////////////////
// ReadINI - Loads an INI file
int ReadINI(char filename[12])
// Reads the file filename (typically M3.INI) to initialize global variables */
// Returns a 0 on success, >0 on failure
{
	FILE* f;
	int temp;

	if ((f = fopen(filename,"r")) == NULL) return(1);

	// Read the serial communication address, prompt, and response characters
	if (ScanChar(&Address,f)) return(3);
	if (ScanChar(&Prompt,f)) return(4);
	if (ScanChar(&Response,f)) return(5);

	// Read the clock adjustment (in ppm)
	if (ScanInt(&ClockPPM,f))	return(5);

	// Read the Tilt Stepper motion acceleration value (steps/sec/sec)
	if (ScanFloat(&Tilt.Acceleration,f)) return(25);
	// Read the Tilt Stepper maximum motion velocity (steps/sec)
	if (ScanFloat(&Tilt.MaxVelocity,f)) return(26);
	// Read the Tilt Stepper motion initial stepper pulse (ms)
	if (ScanInt(&Tilt.InitialPulse,f)) return(27);

  //Compound Tilt constants not this time for "too much var" compil problem
	//if (ScanFloat(&Tilt.Kstepmm,f)) return(28);
	//if (ScanFloat(&Tilt.KKA,f)) return(29);
	//if (ScanFloat(&Tilt.KKB,f)) return(30);
	//if (ScanFloat(&Tilt.KKC,f)) return(31);

	// Pressure/Vacuum control constants (see manual)
	// Kp, Proportional PID control loop constant (~1-5)
	if (ScanFloat(&PresVac.Kp,f)) return(32);
	// Ki, Integral PID control loop constant (~0.01-0.1)
	if (ScanFloat(&PresVac.Ki,f)) return(33);
	// Kd, Derivative PID control loop constant (~1)
	if (ScanFloat(&PresVac.Kd,f)) return(34);
	// PIl, Pressure Integral Limit (0.0-1.0)
	if (ScanFloat(&PresVac.PIl,f)) return(35);
	// VIl, Vacuum Integral Limit (0.0-1.0)
	if (ScanFloat(&PresVac.VIl,f)) return(36);
	// Integral Reset Threshold (~0.3-1.0)
	if (ScanFloat(&PresVac.IntegralThreshold,f)) return(37);
	// Minimum pulse in ms for pressure valve
	if (ScanInt(&PresVac.PressureMinPulseWidth,f)) return(38);
	// Minimum pulse in ms for vacuum valve
	if (ScanInt(&PresVac.VacuumMinPulseWidth,f)) return(39);
	// Cycle time between control variable updates in ms
	if (ScanInt(&temp,f)) return(40);
	PulseCycle = temp;

	// Minimum number of steps necessary to always get to the next M3 Turret index
	//if (ScanInt(&MTMinIndexDistance,f)) return(41);
	// The approximate number of steps between an Aux index and a Nas index
	//if (ScanInt(&MTAuxToNasDistance,f)) return(42);
	// The approximate number of steps between two Aux indices
	//if (ScanInt(&MTAuxToAuxDistance,f)) return(43);
	// The minimum number of extra steps needed to actually get to an index
	//if (ScanInt(&MTExtraDistance,f)) return(44);
	// Distance from the edge of an index to the center
	//if (ScanInt(&MTHalfIndexWidth,f)) return(45);

  // Minimum number of steps to go between the two ADC positions
	//if (ScanInt(&ATMinDistance,f)) return(46);
  // Slighlty fewer steps than necessary to go from one position to the next
	//if (ScanInt(&ATPosToPosDistance,f)) return(47);
  // The number of extra steps needed to actually get to a position
	//if (ScanInt(&ATExtraDistance,f)) return(48);
  // Distance from the edge of an index to the center
	//if (ScanInt(&ATHalfIndexWidth,f)) return(49);

	// Done; close file
	if (fclose(f)) return(50);
	return(0);
}


Generated by GNU Enscript 1.6.5.2.
Document Actions