Skip to content. | Skip to navigation

Personal tools

remote/remm3.cpp

remote/remm3.cpp

remote/remm3.cpp

/////////////////////////////////////////////////////////////////////////////
// Remote M3 Control Program
//
//  Last updated: 3 / 16 / 2005
//	by Jose M. Soto
//	The Observatories of the Carnegie Institution of Washington
//
//  Compile using Watcom C++ 11.0 using the CAUSEWAY DOS extender for Watcom
//    Compile command:
//                    wcl386 /e5 /l=causeway remm3.cpp fontdef.obj
//
//  Notes:-This program also uses the general-purpose source code files
//        SERCLOCK.CPP, and one of the video driver files such as
//        VIDEO2.CPP (for VESA 2.0 cards) or ET40002.CPP.
//
//        -We're using CauseWay DOS extender now, then we don't need DOS4GW.EXE
//        This means you have to use the compile command given above.
//        -File FONTDEF.OBJ defines packed arrays equivalent to the ones
//        defined in font files VIDEO8.FNT, VIDEO16.FNT and VIDEO32.FNT.
//        This means that you have to compile using command given above and
//        that you must use one of the modified video drivers:
//        video2.cpp or et40002.cpp that read tha packed fonts.
/////////////////////////////////////////////////////////////////////////////

#define Version 2.2

// Keep all structures byte-aligned, not dword aligned
#pragma pack(1)

/////////////////////////////////////////////////////////////////////////////
// LOG OF CHANGES
//
//   01/30/05: Updated for faster communications with SBC1190, which is running
//             now a faster clock interrupt (4KHz!)
//   05/23/02: Don't need DOS4GW.EXE to run program since we're using
//             CauseWay extender now.
//             Don't need .FNT files to run program, because
//             fontdef.obj now contains the fonts (packed).
//   05/11/02: Development begins
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Port Communication Control
//
//  Uncomment the "#define ENABLEIO" line to enable reading/writing
//  to all ports.  Comment it out to test the software on a computer without
//  the hardware.
//
#define ENABLEIO
//
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Video graphics driver usage
//
//  Select from one of the following video drivers
//#include "good/video2.cpp" // Fast VESA graphics routines
#include "../../libmag/et4002.cpp"   // Tseng ET-4000 graphics routines
/////////////////////////////////////////////////////////////////////////////

// Macros for easier-to-read source code
#define setvect _dos_setvect
#define getvect _dos_getvect
#define enable _enable
#define disable _disable
#define getdate _dos_getdate
#define time dostime_t
#define date dosdate_t
#define PI 3.14159265359
#define BRIEF 0
#define EXTRA 1
#define VERBOSE 2

// Global variables and constants
// Global quit flag
int Quit = 0;               // Set to 1 to quit from main loop
int ClockPPM = 0;           // Speed up or slow down clock in PPM (for accuracy)
#define M3ClockRate 2000    // Clock rate used in Hz
#define MainLogSize 1000    // Number of entries in the main log (memory limited)
#define InputLogSize 100    // Number of entries in the keyboard command log

// Includes
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <i86.h>
#include "../../libmag/serclock.cpp"  // Serial/Clock interrupt routines
#include "../../libmag/math.cpp"      // Various math routines
#include "../../libmag/log.cpp"       // Message logging routines
#include "../../libmag/chart.cpp"     // Data charting routines

// Global variables
// Dynamically allocates global variables
CLog * Log;
CLog * InputLog;

// Code
#include "io.h"       // Low level I/O routines
#include "ini.h"      // INI file manipulation
#include "display.h"  // Main on-screen display routines
#include "parse.h"    // Serial and keyboard command parsing
#include "tilt.h"     // M3 Mirror Tilt control and status
#include "dgh.h"      // Low level DGH module control and status
#include "edslog.h"   // Engineering data stream routines
#include "presvac.h"  // Pressure/vacuum control behind the mirror
#include "mstreds.h" //eds forwarding between slave and master

CEDSLog * MasterEDSLog;

#include "io.cpp"
#include "ini.cpp"
#include "display.cpp"
#include "parse.cpp"
#include "tilt.cpp"
#include "dgh.cpp"
#include "edslog.cpp"
#include "presvac.cpp"
#include "mstreds.cpp"

void main(int _argc,const char * _argv[])
{
  int i;
  int Step = 0; // Used to step through subsystem updates

  // Allocate memory for dynamic variables/objects
  Log = new CLog;
  InputLog = new CLog;

  MasterEDSLog = new CEDSLog;
  MasterEDSLog->Init(100); 

  // Read the INI file.
  if (i = ReadINI("REMM3.INI"))
  {
    printf("Error reading REMM3.INI! (Error %d)\n",i);
    return;
  }
  else
    Log->AddX("M3.INI read success",999,SHECGREEN,BRIEF);

  // First set Shec colors for this machine (colors vary with
  // monitor and video card)
  ShecDARKGRAY = 16;	// 16 by default
  ShecMEDGRAY = 38;		// 28 by default
  ShecLIGHTGRAY = 50;	// 40 by default
  ShecWHITE = 62;     // 52 by default
  ShecRED = 79;       // 78 by default
  ShecYELLOW = 95;    // 94 by default
  ShecGREEN = 109;    // 109 by default

  // Switch to 640x480x256 video mode
  if (i = InitVideo())
  {
    CloseVideo();
    printf("Error initializing graphics mode! (Error #%d)\n",i);
    return;
  }

  // Initialize running logs
  Log->Init(MainLogSize,12,430,384,5,1,1,140,364);
  InputLog->Init(InputLogSize,452,632,384,4,0,0,0,0);
  //EDSLog.Init(100);
  PresVacChart.Init(412,264,548,303,SHECYELLOW,BLACK,SHECGREEN,WHITE,0.0,0.3,5);

  // Set the log verbose level to maximum if any command-line arguments
  // were given.
  if (_argc > 1)
    Log->VerboseLevel = 2;

  // Initialize clock interrupt
  InitClock(M3ClockRate); // Enable clock interrupt control

  // Initialize serial port parameters
  InitPorts();

  // Speed up or slow down clock, based on INI file
  SetNewClockPPM(ClockPPM);

  // Initialize subsystems
  Tilt.Init();
  PresVac.Init();

  // Initialize static screen display
  InitDisplay();

  //Log->AddX("Program startup (v%0.2f)",998,SHECGREEN,0,Version);

  // Main loop
  do
  {
    // Update onscreen timers
    UpdateTime(0);

    // Keep the cursor blinking
    UpdateCursor(kbline);

    // Update periodic EDS entries
    UpdateEDS();

    // Keep the log displays up-to-date
    Log->Update();
    InputLog->Update();

    // Parse serial and keyboard input
    Parse();

    // Update pressure/vacuum control system
    PresVac.Update();

    // Update tip/tilt control system
    Tilt.Update();

  } while (!Quit);

  // Restore all interrupt vectors, and return to text mode
  CloseComPorts();
  CloseClock();
  CloseVideo();

  printf(" Clock Overruns: %d\n",Overruns);
  printf("Real Clock Rate: %0.2f Hz\n",RealClockRate);

}


Generated by GNU Enscript 1.6.5.2.
Document Actions