Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
6.1 KiB

4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: Main.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Main.cpp
  13. //----------------------------------------------------------------------------
  14. #include <dos.h>
  15. #include <stdio.h>
  16. #include <conio.h>
  17. #include <string.h>
  18. #include <ctype.h>
  19. #include "Board.h"
  20. #include "Comm485.h"
  21. #include "Kernel.h"
  22. #include "Shadow.h"
  23. #include "Screen.h"
  24. #include "..\lglib\version.h"
  25. DECLARE_VARIABLE( CBoard, g_Board );
  26. DECLARE_VARIABLE( CComm485, g_LgsComm485 );
  27. DECLARE_VARIABLE( CComm485, g_CameraComm485 );
  28. CKernel g_Kernel;
  29. CShadow g_Shadow;
  30. void StartAfterExit( PCHAR );
  31. #ifdef COMPILE_AS_ANGLES
  32. void AnglesProc();
  33. #endif
  34. #if 0
  35. void CheckHeap( LPCTSTR pText )
  36. {
  37. printf( "%s\n", pText );
  38. if( farheapcheck() < 0 )
  39. {
  40. printf( "far heap is corrupted\n" );
  41. return;
  42. }
  43. unsigned long free_size = 0;
  44. unsigned long free_count = 0;
  45. unsigned long in_use_size = 0;
  46. unsigned long in_use_count = 0;
  47. struct farheapinfo fhi;
  48. fhi.ptr = NULL;
  49. while( farheapwalk( &fhi ) == _HEAPOK )
  50. {
  51. if( fhi.in_use )
  52. {
  53. in_use_count ++;
  54. in_use_size += (unsigned long)fhi.size;
  55. }
  56. else
  57. {
  58. free_count ++;
  59. free_size += (unsigned long)fhi.size;
  60. }
  61. }
  62. printf( "far heap:\n"
  63. "free %ld blocks, size %ld\n"
  64. "in-use %ld blocks, size %ld\n", free_count, free_size, in_use_count, in_use_size );
  65. }
  66. #else
  67. #define CheckHeap
  68. #endif
  69. BOOL g_bShowErrors = TRUE;
  70. void main(int argc, char * argv[] )
  71. {
  72. CheckHeap( "Start" );
  73. // printf software version
  74. if( argc > 1 )
  75. {
  76. switch( argv[1][0] )
  77. {
  78. case '-': case '\\': case '/':
  79. switch( argv[1][1] )
  80. {
  81. case 'h': case 'H': case 'v': case 'V': case '?':
  82. printf( "Software version <%s>\n", g_Kernel.s_pSoftwareVersion );
  83. return;
  84. case 'u': case 'U':
  85. g_bShowErrors = FALSE;
  86. break;
  87. // case 'b':
  88. /*
  89. {
  90. for( long i = 0x000F0000; i < 1024L*1024L; )
  91. {
  92. printf( "MEMORY [%08lX..%08lX]\n", i, i + 0x700 );
  93. for( long j = 0; j < 0x700; j++ )
  94. {
  95. long a = ((i&0xFFFF0000L)<<12) | (i&0x0000FFFFL);
  96. char c = *(char far*)a;
  97. c = ( isascii(c) && !iscntrl(c) ) ? c : ' ';
  98. printf( "%c", c );
  99. i++;
  100. }
  101. printf( "\n" );
  102. getch();
  103. }
  104. }
  105. return;
  106. {
  107. for( long i = 0x000F0000; i < 1024L*1024L; i++ )
  108. {
  109. char far *pPtr = (char far*)( ((i&0xFFFF0000L)<<12) | (i&0x0000FFFFL) );
  110. if( !_fmemcmp( pPtr, "ZFx86", 5 ) )
  111. printf( "%08lX <%ls>\n", i, pPtr );
  112. }
  113. }
  114. return;
  115. */
  116. }
  117. break;
  118. }
  119. }
  120. #ifdef DEBUG_SHOW_COMMUNICATION
  121. g_LgsComm485.ShowCommunication( FALSE );
  122. g_CameraComm485.ShowCommunication( TRUE );
  123. #endif
  124. #ifndef COMPILE_AS_ANGLES
  125. LONG nSpeed = LGS_COMM_BAUDRATE;
  126. #ifndef COMPILE_AS_GETFILE
  127. // load comm speed
  128. FILE *pFile = fopen( "SERIAL.INI", "rt" );
  129. if( pFile )
  130. {
  131. fscanf( pFile, "%ld\n", &nSpeed );
  132. fclose( pFile );
  133. }
  134. #endif // #ifndef COMPILE_AS_GETFILE
  135. if( !g_LgsComm485.Create( CComm485::_COM2, nSpeed, 8, CComm485::_NOPARITY ) )
  136. {
  137. printf( "Can't create commport for LGS\n" );
  138. return;
  139. }
  140. #endif // #ifndef COMPILE_AS_ANGLES
  141. // load user settings
  142. AUTO_RESET AutoReset;
  143. BOARD_SETTINGS BoardSettings;
  144. SWITCHER_SETTINGS SwitcherSettings;
  145. CKernel::LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
  146. if( !g_Board.Create( &BoardSettings ) )
  147. {
  148. printf( "Can't access board\n" );
  149. return;
  150. }
  151. #ifdef COMPILE_AS_ANGLES
  152. AnglesProc();
  153. #endif
  154. if( !g_Shadow.Create() )
  155. {
  156. printf( "Can't create shadow\n" );
  157. return;
  158. }
  159. #ifdef DEBUG_GRAPH_SCREEN
  160. if( !g_Screen.Create() )
  161. {
  162. printf( "Can't create screen\n" );
  163. return;
  164. }
  165. #endif
  166. if( !g_Kernel.Create( &g_Board, &g_LgsComm485, &g_Shadow, &g_CameraComm485, CComm485::_COM1 ) )
  167. {
  168. printf( "Can't create kernel\n" );
  169. return;
  170. }
  171. CheckHeap( "Before run" );
  172. BOOL bRestart = g_Kernel.Run();
  173. CheckHeap( "After run" );
  174. g_Kernel.Destroy();
  175. g_Shadow.Destroy();
  176. #ifdef DEBUG_GRAPH_SCREEN
  177. g_Screen.Destroy();
  178. #endif
  179. g_Board.Destroy();
  180. g_LgsComm485.Destroy();
  181. g_CameraComm485.Destroy();
  182. if( bRestart && argc )
  183. StartAfterExit( argv[0] );
  184. CheckHeap( "Done" );
  185. }
  186. void WriteToKeyboardBuffer( CHAR a );
  187. void StartAfterExit( PCHAR pFileName )
  188. {
  189. // "type"
  190. for( INT i = 0; i < strlen( pFileName ); i++ )
  191. WriteToKeyboardBuffer( pFileName[i] );
  192. // "press enter"
  193. WriteToKeyboardBuffer( '\n' );
  194. WriteToKeyboardBuffer( '\r' );
  195. }
  196. void WriteToKeyboardBuffer( CHAR a )
  197. {
  198. unsigned far *bufbegin;
  199. unsigned far *bufend;
  200. unsigned far *buftail;
  201. unsigned far *buffer;
  202. // set up buffer pointers
  203. FP_SEG(bufbegin)=FP_SEG(bufend)=FP_SEG(buftail)=FP_SEG(buffer)=0x40;
  204. FP_OFF(bufbegin)=0x80;
  205. FP_OFF(bufend)=0x82;
  206. FP_OFF(buftail)=0x1c;
  207. disable();
  208. FP_OFF(buffer)=*buftail;
  209. *buffer++=a;
  210. if ( FP_OFF(buffer) >= *bufend )
  211. FP_OFF(buffer)=*bufbegin;
  212. *buftail=FP_OFF(buffer);
  213. enable();
  214. }
  215. #ifdef COMPILE_AS_ANGLES
  216. void AnglesProc()
  217. {
  218. INT nAngle = 0;
  219. BOOL bFirstAngle = TRUE;
  220. INT nZeroCount = 0;
  221. BOOL bZeroFirst = TRUE;
  222. INT nZeroErrorCount = 0;
  223. INT nAngleErrorCount = 0;
  224. while( TRUE )
  225. {
  226. BOOL bZero;
  227. BOOL pSun[2];
  228. INT pRange[2];
  229. if( g_Board.GetData( &bZero, pSun, pRange ) )
  230. {
  231. if( bZero )
  232. {
  233. if( bFirstAngle )
  234. bFirstAngle = FALSE;
  235. else
  236. {
  237. g_CRT.IntOut( 0, 0, nAngle + 1 );
  238. if( (nAngle + 1) != LGS_MAX_DETECTOR_ANGLES )
  239. g_CRT.IntOut( 10, 0, ++nAngleErrorCount );
  240. }
  241. if( bZeroFirst ) nZeroCount = 1;
  242. else
  243. {
  244. nZeroCount++;
  245. g_CRT.IntOut( 10, 1, ++nZeroErrorCount );
  246. }
  247. g_CRT.IntOut( 0, 1, nZeroCount );
  248. bZeroFirst = FALSE;
  249. nAngle = 0;
  250. }
  251. else
  252. {
  253. bZeroFirst = TRUE;
  254. nAngle++;
  255. }
  256. }
  257. }
  258. }
  259. #endif