//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: Main.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of Main.cpp //---------------------------------------------------------------------------- #include #include #include #include #include #include "Board.h" #include "Comm485.h" #include "Kernel.h" #include "Shadow.h" #include "Screen.h" #include "..\lglib\version.h" DECLARE_VARIABLE( CBoard, g_Board ); DECLARE_VARIABLE( CComm485, g_LgsComm485 ); DECLARE_VARIABLE( CComm485, g_CameraComm485 ); CKernel g_Kernel; CShadow g_Shadow; void StartAfterExit( PCHAR ); #ifdef COMPILE_AS_ANGLES void AnglesProc(); #endif #if 0 void CheckHeap( LPCTSTR pText ) { printf( "%s\n", pText ); if( farheapcheck() < 0 ) { printf( "far heap is corrupted\n" ); return; } unsigned long free_size = 0; unsigned long free_count = 0; unsigned long in_use_size = 0; unsigned long in_use_count = 0; struct farheapinfo fhi; fhi.ptr = NULL; while( farheapwalk( &fhi ) == _HEAPOK ) { if( fhi.in_use ) { in_use_count ++; in_use_size += (unsigned long)fhi.size; } else { free_count ++; free_size += (unsigned long)fhi.size; } } printf( "far heap:\n" "free %ld blocks, size %ld\n" "in-use %ld blocks, size %ld\n", free_count, free_size, in_use_count, in_use_size ); } #else #define CheckHeap #endif BOOL g_bShowErrors = TRUE; BOOL g_bDelayErrors = TRUE; BOOL g_bHideFogError = FALSE; void main( int argc, char * argv[] ) { CheckHeap( "Start" ); // printf software version if( argc > 1 ) { switch( argv[1][0] ) { case '-': case '\\': case '/': switch( argv[1][1] ) { case 'h': case 'H': case 'v': case 'V': case '?': printf( "Software version <%s>\n", g_Kernel.s_pSoftwareVersion ); return; case 'u': case 'U': g_bShowErrors = FALSE; break; case 'f': case 'F': g_bHideFogError = TRUE; break; case 'z': case 'Z': g_bDelayErrors = FALSE; break; // case 'b': /* { for( long i = 0x000F0000; i < 1024L*1024L; ) { printf( "MEMORY [%08lX..%08lX]\n", i, i + 0x700 ); for( long j = 0; j < 0x700; j++ ) { long a = ((i&0xFFFF0000L)<<12) | (i&0x0000FFFFL); char c = *(char far*)a; c = ( isascii(c) && !iscntrl(c) ) ? c : ' '; printf( "%c", c ); i++; } printf( "\n" ); getch(); } } return; { for( long i = 0x000F0000; i < 1024L*1024L; i++ ) { char far *pPtr = (char far*)( ((i&0xFFFF0000L)<<12) | (i&0x0000FFFFL) ); if( !_fmemcmp( pPtr, "ZFx86", 5 ) ) printf( "%08lX <%ls>\n", i, pPtr ); } } return; */ } break; } } #ifdef DEBUG_SHOW_COMMUNICATION g_LgsComm485.ShowCommunication( FALSE ); g_CameraComm485.ShowCommunication( TRUE ); #endif #ifndef COMPILE_AS_ANGLES LONG nSpeed = LGS_COMM_BAUDRATE; #ifndef COMPILE_AS_GETFILE // load comm speed FILE *pFile = fopen( "SERIAL.INI", "rt" ); if( pFile ) { fscanf( pFile, "%ld\n", &nSpeed ); fclose( pFile ); } #endif // #ifndef COMPILE_AS_GETFILE if( !g_LgsComm485.Create( CComm485::_COM2, nSpeed, 8, CComm485::_NOPARITY ) ) { printf( "Can't create commport for LGS\n" ); return; } #endif // #ifndef COMPILE_AS_ANGLES // load user settings AUTO_RESET AutoReset; BOARD_SETTINGS BoardSettings; SWITCHER_SETTINGS SwitcherSettings; CKernel::LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings ); if( !g_Board.Create( &BoardSettings ) ) { printf( "Can't access board\n" ); return; } #ifdef COMPILE_AS_ANGLES AnglesProc(); #endif if( !g_Shadow.Create() ) { printf( "Can't create shadow\n" ); return; } #ifdef DEBUG_GRAPH_SCREEN if( !g_Screen.Create() ) { printf( "Can't create screen\n" ); return; } #endif if( !g_Kernel.Create( &g_Board, &g_LgsComm485, &g_Shadow, &g_CameraComm485, CComm485::_COM1 ) ) { printf( "Can't create kernel\n" ); return; } CheckHeap( "Before run" ); BOOL bRestart = g_Kernel.Run(); CheckHeap( "After run" ); g_Kernel.Destroy(); g_Shadow.Destroy(); #ifdef DEBUG_GRAPH_SCREEN g_Screen.Destroy(); #endif g_Board.Destroy(); g_LgsComm485.Destroy(); g_CameraComm485.Destroy(); if( bRestart && argc ) StartAfterExit( argv[0] ); CheckHeap( "Done" ); } void WriteToKeyboardBuffer( CHAR a ); void StartAfterExit( PCHAR pFileName ) { // "type" for( INT i = 0; i < strlen( pFileName ); i++ ) WriteToKeyboardBuffer( pFileName[i] ); // "press enter" WriteToKeyboardBuffer( '\n' ); WriteToKeyboardBuffer( '\r' ); } void WriteToKeyboardBuffer( CHAR a ) { unsigned far *bufbegin; unsigned far *bufend; unsigned far *buftail; unsigned far *buffer; // set up buffer pointers FP_SEG(bufbegin)=FP_SEG(bufend)=FP_SEG(buftail)=FP_SEG(buffer)=0x40; FP_OFF(bufbegin)=0x80; FP_OFF(bufend)=0x82; FP_OFF(buftail)=0x1c; disable(); FP_OFF(buffer)=*buftail; *buffer++=a; if ( FP_OFF(buffer) >= *bufend ) FP_OFF(buffer)=*bufbegin; *buftail=FP_OFF(buffer); enable(); } #ifdef COMPILE_AS_ANGLES void AnglesProc() { INT nAngle = 0; BOOL bFirstAngle = TRUE; INT nZeroCount = 0; BOOL bZeroFirst = TRUE; INT nZeroErrorCount = 0; INT nAngleErrorCount = 0; while( TRUE ) { BOOL bZero; BOOL pSun[2]; INT pRange[2]; if( g_Board.GetData( &bZero, pSun, pRange ) ) { if( bZero ) { if( bFirstAngle ) bFirstAngle = FALSE; else { g_CRT.IntOut( 0, 0, nAngle + 1 ); if( (nAngle + 1) != LGS_MAX_DETECTOR_ANGLES ) g_CRT.IntOut( 10, 0, ++nAngleErrorCount ); } if( bZeroFirst ) nZeroCount = 1; else { nZeroCount++; g_CRT.IntOut( 10, 1, ++nZeroErrorCount ); } g_CRT.IntOut( 0, 1, nZeroCount ); bZeroFirst = FALSE; nAngle = 0; } else { bZeroFirst = TRUE; nAngle++; } } } } #endif