Skip to content. | Skip to navigation

Personal tools

ini.cpp

ini.cpp

ini.cpp

/////////////////////////////////////////////////////////////////////////////
// INI.CPP
//
//  Last updated: 1/11/2006
//
//  Part of the source code for the M3 Program
//
//  Contains routines for reading and editing M3.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 i,temp;

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

  // Read the parallel port address in hexadecimal (usually 378)
  if (ScanHex(&PARPORT,f)) return(2);

	// 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 mirror motion timeout
	if (ScanInt(&temp,f)) return(10);
	Mirror.MotionTimeout = 1000 * (dword)temp;
  // Read mirror latch full move time
	if (ScanInt(&temp,f)) return(11);
	Mirror.FullLatchMove = 1000 * (dword)temp;

	// Read the M3 Turret motion acceleration value (steps/sec/sec)
	if (ScanFloat(&M3Turret->Acceleration,f)) return(20);
	// Read the M3 Turret maximum motion velocity (steps/sec)
	if (ScanFloat(&M3Turret->MaxVelocity,f)) return(21);
	// Read the M3 Turret motion initial stepper pulse (ms)
	if (ScanInt(&M3Turret->InitialPulse,f)) return(22);
	// Read the M3 Turret motion emergency stop distance (steps)
	if (ScanInt(&M3Turret->EmergencyStopDistance,f)) return(23);
	// Minimum number of steps necessary to always get to the next M3 Turret index
	if (ScanInt(&M3Turret->MTMinIndexDistance,f)) return(24);
	// The approximate number of steps between an Aux index and a Nas index
	if (ScanInt(&M3Turret->MTAuxToNasDistance,f)) return(25);
	// The approximate number of steps between two Aux indices
	if (ScanInt(&M3Turret->MTAuxToAuxDistance,f)) return(26);
	// The minimum number of extra steps needed to actually get to an index
	if (ScanInt(&M3Turret->MTExtraDistance,f)) return(27);
	// Distance from the edge of an index to the center in the forward dir
	if (ScanInt(&M3Turret->MTHalfIndexWidthFwd,f)) return(28);
	// Distance from the edge of an index to the center in the reverse dir
	if (ScanInt(&M3Turret->MTHalfIndexWidthRev,f)) return(29);

	// Read the M3 Turret Pin motion timeout
	if (ScanInt(&temp,f)) return(30);
	M3TurretPin.MotionTimeout = 1000 * (dword)temp;

  // Don't think this is really needed
  // Flag to change default turning direction
  //if (ScanInt(&ADCTDir,f)) return(31);

	// Read the ADC Turret motion acceleration value (steps/sec/sec)
	if (ScanFloat(&ADCTurret->Acceleration,f)) return(40);
	// Read the ADC Turret maximum motion velocity (steps/sec)
	if (ScanFloat(&ADCTurret->MaxVelocity,f)) return(41);
	// Read the ADC Turret motion initial stepper pulse (ms)
	if (ScanInt(&ADCTurret->InitialPulse,f)) return(42);
	// Read the ADC Turret motion emergency stop distance (steps)
	if (ScanInt(&ADCTurret->EmergencyStopDistance,f)) return(43);
  // Minimum number of steps to go between the two ADC positions
	//if (ScanInt(&ATMinDistance,f)) return(105);
  // Slighlty fewer steps than necessary to go from one position to the next
	//if (ScanInt(&ATPosToPosDistance,f)) return(106);
  // The number of extra steps needed to actually get to a position
	//if (ScanInt(&ATExtraDistance,f)) return(107);
  // Distance from the edge of an index to the center
	//if (ScanInt(&ATHalfIndexWidth,f)) return(108);

	// Read the ADC Turret Pin motion timeout
	if (ScanInt(&temp,f)) return(50);
	ADCTurretPin.MotionTimeout = 1000 * (dword)temp;

	// Read the ADC A motion acceleration value (steps/sec/sec)
	if (ScanFloat(&ADCA.Acceleration,f)) return(60);
	// Read the ADC A maximum motion velocity (steps/sec)
	if (ScanFloat(&ADCA.MaxVelocity,f)) return(61);
	// Read the ADC A motion initial stepper pulse (ms)
	if (ScanInt(&ADCA.InitialPulse,f)) return(62);
	// Read the ADC A Steps per revolution (steps)
  if (ScanInt(&ADCA.StepsPerRevolution,f)) return(63);
  //if (ScanInt(&ADCA.StepsPerRevgt,f)) return(64);
  //if (ScanInt(&ADCA.StepsPerRevlt,f)) return(65);


	// Read the ADC B motion acceleration value (steps/sec/sec)
	if (ScanFloat(&ADCB.Acceleration,f)) return(70);
	// Read the ADC B maximum motion velocity (steps/sec)
	if (ScanFloat(&ADCB.MaxVelocity,f)) return(71);
	// Read the ADC B motion initial stepper pulse (ms)
	if (ScanInt(&ADCB.InitialPulse,f)) return(72);
	// Read the ADC B Steps per revolution (steps)
	if (ScanInt(&ADCB.StepsPerRevolution,f)) return(73);
  //if (ScanInt(&ADCB.StepsPerRevgt,f)) return(74);
  //if (ScanInt(&ADCB.StepsPerRevlt,f)) return(75);

	// Read the Tilt Stepper motion acceleration value (steps/sec/sec)
	if (ScanFloat(&Tilt.Acceleration,f)) return(80);
	// Read the Tilt Stepper maximum motion velocity (steps/sec)
	if (ScanFloat(&Tilt.MaxVelocity,f)) return(81);
	// Read the Tilt Stepper motion initial stepper pulse (ms)
	if (ScanInt(&Tilt.InitialPulse,f)) return(82);
	// Read the maximum amount of steps 
	if (ScanInt(&Tilt.TiltMax,f)) return(87);
  // Compound Tilt constants
	if (ScanFloat(&Tilt.Kstepmm,f)) return(83);
	if (ScanFloat(&Tilt.KKA,f)) return(84);
	if (ScanFloat(&Tilt.KKB,f)) return(85);
	if (ScanFloat(&Tilt.KKC,f)) return(86);

	// Read the Tilt value for different observing ports (volts)
  for (i=0;i<=2;i++)
    if (ScanFloat(&Tilt.TNASW[i],f)) return(90+i);
  for (i=0;i<=2;i++)
    if (ScanFloat(&Tilt.TNASE[i],f)) return(93+i);
  for (i=0;i<=2;i++)
    if (ScanFloat(&Tilt.TAUX1[i],f)) return(96+i);
  for (i=0;i<=2;i++)
    if (ScanFloat(&Tilt.TAUX2[i],f)) return(99+i);
  for (i=0;i<=2;i++)
    if (ScanFloat(&Tilt.TAUX3[i],f)) return(102+i);
  for (i=20;i<=90;i=i+5)
  {
    if (ScanFloat(&Tilt.TNaswA[i],f)) return(120+i);
    if (ScanFloat(&Tilt.TNaswB[i],f)) return(150+i);
    if (ScanFloat(&Tilt.TNaswC[i],f)) return(180+i);
  }
  for (i=0;i<=2;i++)
  {
    if (ScanFloat(&a[i],f)) return(103+i);
    if (ScanFloat(&b[i],f)) return(107+i);
  }

	// Pressure/Vacuum control constants (see manual)
	// Kp, Proportional PID control loop constant (~1-5)
	if (ScanFloat(&PresVac.Kp,f)) return(110);
	// Ki, Integral PID control loop constant (~0.01-0.1)
	if (ScanFloat(&PresVac.Ki,f)) return(111);
	// Kd, Derivative PID control loop constant (2~1)
	if (ScanFloat(&PresVac.Kd,f)) return(112);
	// PIl, Pressure Integral Limit (0.0-1.0)
	if (ScanFloat(&PresVac.PIl,f)) return(113);
	// VIl, Vacuum Integral Limit (0.0-1.0)
	if (ScanFloat(&PresVac.VIl,f)) return(114);
	// Integral Reset Threshold (~0.3-1.0)
	if (ScanFloat(&PresVac.IntegralThreshold,f)) return(115);
	// Minimum pulse in ms for pressure valve
	if (ScanInt(&PresVac.PressureMinPulseWidth,f)) return(116);
	// Minimum pulse in ms for vacuum valve
	if (ScanInt(&PresVac.VacuumMinPulseWidth,f)) return(117);
	// Cycle time between control variable updates in ms
	if (ScanInt(&temp,f)) return(118);
	PulseCycle = temp;

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


Generated by GNU Enscript 1.6.5.2.
Document Actions