For DOS Protected Mode version of sensor core software
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.

703 lines
16 KiB

3 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. /*!
  20. \arg \c idx number of 32x port.
  21. \details Reads North bridge register. The \a idx is port number to read 32 bit value from.
  22. */
  23. unsigned long read_nb(unsigned char idx){
  24. unsigned long retval;
  25. _asm mov dx, 0cf8h
  26. __emit__(0x66); __emit__(0xb8);
  27. __emit__(0x00); __emit__(0x00); __emit__(0x00); __emit__(0x80);
  28. _asm mov al, idx
  29. __emit__(0x66); _asm out dx, ax
  30. _asm mov dx, 0cfch
  31. __emit__(0x66); _asm in ax, dx
  32. __emit__(0x66); _asm mov WORD PTR retval, ax
  33. return retval;
  34. };
  35. // Write north bridge register
  36. void write_nb(unsigned char idx, unsigned long val){
  37. _asm mov dx, 0cf8h
  38. __emit__(0x66); __emit__(0xb8);
  39. __emit__(0x00); __emit__(0x00); __emit__(0x00); __emit__(0x80);
  40. _asm mov al, idx
  41. __emit__(0x66); __emit__(0xef);
  42. _asm mov dx, 0cfch
  43. __emit__(0x66); __emit__(0x8b); __emit__(0x46); __emit__(0x08);
  44. __emit__(0x66); __emit__(0xef);
  45. };
  46. // Read south bridge register
  47. unsigned long read_sb(unsigned char idx){
  48. unsigned long retval;
  49. _asm mov dx, 0cf8h
  50. //80009000h
  51. // mov eax, 80003800h
  52. __emit__(0x66); __emit__(0xb8);
  53. //__emit__(0x00); __emit__(0x38); __emit__(0x00); __emit__(0x80);
  54. __emit__(0x00); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  55. _asm mov al, idx
  56. // out edx, eax
  57. __emit__(0x66); _asm out dx, ax
  58. _asm mov dx, 0cfch
  59. // in eax, edx
  60. __emit__(0x66); _asm in ax, dx
  61. // mov retval, eax
  62. __emit__(0x66); _asm mov WORD PTR retval, ax
  63. return retval;
  64. };
  65. // Write south bridge register
  66. /*void write_sb(unsigned char idx, unsigned long val){
  67. __asm{
  68. mov dx, 0cf8h
  69. mov eax, 80009000h
  70. mov al, idx
  71. out dx, eax
  72. mov dx, 0cfch
  73. mov eax, DWORD PTR val
  74. out dx, eax
  75. }
  76. };*/
  77. void make_ws8( void ){
  78. unsigned long retval;
  79. _asm mov dx, 0cf8h
  80. __emit__(0x66); __emit__(0xb8);
  81. __emit__(0x50); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  82. __emit__(0x66); _asm out dx, ax
  83. _asm mov dx, 0cfch
  84. __emit__(0x66); _asm in ax, dx
  85. __emit__(0x66); _asm mov WORD PTR retval, ax
  86. retval = retval | 0x0000F000UL;
  87. _asm mov dx, 0cf8h
  88. __emit__(0x66); __emit__(0xb8);
  89. __emit__(0x50); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  90. __emit__(0x66); _asm out dx, ax
  91. _asm mov dx, 0cfch
  92. __emit__(0x66); _asm mov ax, WORD PTR retval
  93. __emit__(0x66); _asm out dx, ax
  94. };
  95. // Write south bridge register
  96. void write_sb( unsigned char idx, unsigned long val ){
  97. _asm mov dx, 0cf8h
  98. //80009000h
  99. // mov eax, 80003800h
  100. __emit__(0x66); __emit__(0xb8);
  101. //__emit__(0x00); __emit__(0x38); __emit__(0x00); __emit__(0x80);
  102. __emit__(0x00); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  103. _asm mov al, idx
  104. // out dx, eax
  105. __emit__(0x66); __emit__(0xef);
  106. _asm mov dx, 0cfch
  107. // mov eax, val
  108. __emit__(0x66); __emit__(0x8b); __emit__(0x46); __emit__(0x08);
  109. // out dx, eax
  110. __emit__(0x66); __emit__(0xef);
  111. };
  112. unsigned char read_sbb( unsigned char idx ){
  113. unsigned char retval;
  114. _asm mov dx, 0cf8h
  115. // mov eax, 80009000h
  116. __emit__(0x66); __emit__(0xb8);
  117. __emit__(0x00); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  118. _asm mov al, idx
  119. // out edx, eax
  120. //__emit__(0x66); __emit__(0xef);
  121. __emit__(0x66); _asm out dx, ax
  122. /*_asm mov dx, 0cfch
  123. // in eax, edx
  124. __emit__(0x66); _asm in al, dx
  125. // mov retval, eax
  126. __emit__(0x66); _asm mov BYTE PTR retval, al
  127. */
  128. retval = inportb( 0x0CFC );
  129. return retval;
  130. };
  131. unsigned int read_sbw( unsigned char idx ){
  132. unsigned int retval;
  133. _asm mov dx, 0cf8h
  134. // mov eax, 80009000h
  135. __emit__(0x66); __emit__(0xb8);
  136. __emit__(0x00); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  137. _asm mov al, idx
  138. // out edx, eax
  139. //__emit__(0x66); __emit__(0xef);
  140. __emit__(0x66); _asm out dx, ax
  141. /*_asm mov dx, 0cfch
  142. // in eax, edx
  143. __emit__(0x66); _asm in al, dx
  144. // mov retval, eax
  145. __emit__(0x66); _asm mov BYTE PTR retval, al
  146. */
  147. retval = inport( 0x0CFC );
  148. return retval;
  149. };
  150. // Write south bridge register
  151. void write_sbb( unsigned char idx, unsigned char val ){
  152. _asm mov dx, 0cf8h
  153. //80009000h
  154. // mov eax, 80003800h
  155. __emit__(0x66); __emit__(0xb8);
  156. //__emit__(0x00); __emit__(0x38); __emit__(0x00); __emit__(0x80);
  157. __emit__(0x00); __emit__(0x90); __emit__(0x00); __emit__(0x80);
  158. _asm mov al, idx
  159. // out dx, eax
  160. __emit__(0x66); __emit__(0xef);
  161. outportb( 0x0CFC, val );
  162. /*_asm mov dx, 0cfch
  163. // mov eax, val
  164. __emit__(0x66); __emit__(0x8b); __emit__(0x46); __emit__(0x08);
  165. // out dx, eax
  166. __emit__(0x66); __emit__(0xef);*/
  167. };
  168. #ifndef NO_WDT2_INIT
  169. #include "clock.h"
  170. #endif
  171. #include "Board.h"
  172. #include "Comm485.h"
  173. #include "Kernel.h"
  174. #include "Shadow.h"
  175. #include "Screen.h"
  176. #include "..\lglib\version.h"
  177. DECLARE_VARIABLE( CBoard, g_Board );
  178. DECLARE_VARIABLE( CComm485, g_LgsComm485 );
  179. DECLARE_VARIABLE( CComm485, g_CameraComm485 );
  180. DECLARE_VARIABLE( CKernel, g_Kernel );
  181. //CKernel g_Kernel;
  182. CShadow g_Shadow;
  183. #ifdef ALS_300
  184. // Shadow for second LRF
  185. CShadow g_ShadowS( TRUE );
  186. #endif
  187. void StartAfterExit( PCHAR );
  188. #ifdef COMPILE_AS_ANGLES
  189. void AnglesProc();
  190. #endif
  191. #if 0
  192. void CheckHeap( LPCTSTR pText )
  193. {
  194. printf( "%s\n", pText );
  195. if( farheapcheck() < 0 )
  196. {
  197. printf( "far heap is corrupted\n" );
  198. return;
  199. }
  200. unsigned long free_size = 0;
  201. unsigned long free_count = 0;
  202. unsigned long in_use_size = 0;
  203. unsigned long in_use_count = 0;
  204. struct farheapinfo fhi;
  205. fhi.ptr = NULL;
  206. while( farheapwalk( &fhi ) == _HEAPOK )
  207. {
  208. if( fhi.in_use )
  209. {
  210. in_use_count ++;
  211. in_use_size += (unsigned long)fhi.size;
  212. }
  213. else
  214. {
  215. free_count ++;
  216. free_size += (unsigned long)fhi.size;
  217. }
  218. }
  219. printf( "far heap:\n"
  220. "free %ld blocks, size %ld\n"
  221. "in-use %ld blocks, size %ld\n", free_count, free_size, in_use_count, in_use_size );
  222. }
  223. #else
  224. #define CheckHeap
  225. #endif
  226. /*!
  227. Checks type of PC-104 Board
  228. Reading BSR into \a CHID then
  229. if \a CHID one of following:
  230. \b 0x31504d44 then board is \b Vortex86SX
  231. \b 0x32504d44 then board is \b Vortex86DX
  232. \b 0x33504d44 then board is \b Vortex86MX
  233. in any match returning \b TRUE
  234. */
  235. BOOL IsVortex( void ){
  236. unsigned long CHID;
  237. unsigned int CC;
  238. CHID = read_nb(0x90);
  239. if( CHID == 0x31504d44L ) return TRUE;
  240. if( CHID == 0x32504d44L ) return TRUE;
  241. if( CHID == 0x33504d44L ) return TRUE;
  242. /*! Returnung \b FALSE if no Board ID is matched */
  243. // Old PC - Wait State long
  244. //make_ws8();
  245. return FALSE;
  246. };
  247. BOOL g_bShowErrors = TRUE;
  248. BOOL g_bDelayErrors = TRUE;
  249. BOOL g_bHideFogError = TRUE;
  250. BOOL g_bIsVortex = FALSE;
  251. BOOL g_UI_Debug = FALSE;
  252. BOOL g_bWorkEnable = FALSE;
  253. BOOL g_bIsDMABoard = FALSE;
  254. #if defined( COMPILE_3DSCANER ) | defined( COMPILE_RTSCANER )
  255. BOOL g_bBoardReceiverMode = TRUE;
  256. #else
  257. BOOL g_bBoardReceiverMode = FALSE;
  258. #endif
  259. #ifdef COMPILE_AS_GETFILE
  260. BOOL g_bWatchDogEnable = FALSE;
  261. #else
  262. #ifdef ALS_300
  263. BOOL g_bWatchDogEnable = TRUE; // ALS 300 is too slow for board reset TO DO: change Watchdog init for ALS_300
  264. #else
  265. #ifdef NO_WDT2_INIT
  266. #ifdef WATCHDOG_ENABLED
  267. BOOL g_bWatchDogEnable = FALSE;
  268. #else
  269. BOOL g_bWatchDogEnable = FALSE;
  270. #endif
  271. #else
  272. #ifdef WATCHDOG_ENABLED
  273. BOOL g_bWatchDogEnable = TRUE;
  274. #else
  275. BOOL g_bWatchDogEnable = FALSE;
  276. #endif
  277. #endif
  278. #endif
  279. #endif
  280. BYTE g_bNoBlackTargets = 0;
  281. DWORD g_dwStartupTime = 0;
  282. #ifdef LGS_REDUCED_PRF
  283. INT LGS_PRF_REDUCE_RATIO = 1;
  284. INT LGS_MAX_DETECTOR_DISTANCE = 30;
  285. #endif
  286. /*!
  287. \arg argc Passed agruments count.
  288. \arg argv Array of strings vith arguments passed to the Application.
  289. \details The parameters that may be passed:
  290. \li \b h, \b h, \b v, \b V or \b ? Version output and return from Application
  291. \li \b u or \b U Hide all errors
  292. \li \b f or \b F UnHide Fog errors
  293. \li \b z or \b Z Disable delay error output
  294. \li \b u or \b D Debug output enabled
  295. All parameters to be passed mast have prefix \b / or \b - or \b \\ and space between combined parameters
  296. */
  297. void main( int argc, char * argv[] ){
  298. #ifndef NO_VORTEX_CHECK
  299. g_bIsVortex = IsVortex();
  300. #else
  301. g_bIsVortex = FALSE;
  302. #endif
  303. #ifndef NO_WDT2_INIT
  304. if( g_bIsVortex ) init_sys_clock();
  305. #endif
  306. CheckHeap( "Start" );
  307. #ifdef COMPILE_AS_GETFILE // Startup delay for PLS
  308. //#ifndef LGS_MIRROR //After bootloader all version have delay
  309. BOOL BoardCommOK = FALSE;
  310. #ifdef LGS_STEPPER
  311. delay( 15000 );// Wait 15 seconds anyway
  312. #endif
  313. //printf( "SpinUp Motor " );
  314. #ifdef LGS_PLS_1
  315. INT nono = 600; // 1.5 minute
  316. #else // ALS LGS4S
  317. INT nono = 60; // 6 seconds
  318. #endif
  319. BYTE TestBYTE = inportb( NEW_ID_ADDRESS );
  320. while ( nono && TestBYTE!= 0x5A && TestBYTE!= 0xA5 && TestBYTE != 0xAA ){
  321. nono--;
  322. TestBYTE = inportb( NEW_ID_ADDRESS );
  323. delay( 100 );
  324. //printf( "." );
  325. };
  326. BoardCommOK = ( TestBYTE== 0x5A || TestBYTE== 0xA5 || TestBYTE == 0xAA );
  327. //#endif
  328. #endif
  329. #ifdef DEBUG_PRINTOUT_MSGS
  330. textmode(64);
  331. if ( argc > 1 ) printf("Checking Command Line Parameters ...");
  332. #endif
  333. // printf software version
  334. if ( argc > 1 )
  335. {
  336. switch( argv[1][0] )
  337. {
  338. case '-': case '\\': case '/':
  339. switch( argv[1][1] )
  340. {
  341. case 'h': case 'H': case 'v': case 'V': case '?':
  342. printf( "Software version <%s>\n", g_Kernel.s_pSoftwareVersion );
  343. return;
  344. case 'u': case 'U':
  345. g_bShowErrors = FALSE;
  346. break;
  347. case 'f': case 'F':
  348. g_bHideFogError = FALSE;
  349. break;
  350. case 'z': case 'Z':
  351. g_bShowErrors = TRUE;
  352. g_bHideFogError = FALSE;
  353. g_bDelayErrors = FALSE;
  354. break;
  355. case 'd': case 'D':
  356. g_UI_Debug = TRUE;
  357. break;
  358. case 'b': case 'B':
  359. g_bBoardReceiverMode = TRUE;
  360. break;
  361. case 'w': case 'W':
  362. g_bWatchDogEnable = FALSE;
  363. break;
  364. }
  365. break;
  366. }
  367. }
  368. #ifdef DEBUG_PRINTOUT_MSGS
  369. if ( argc > 1 ) printf("Done\n");
  370. #endif
  371. #ifdef DEBUG_SHOW_COMMUNICATION
  372. g_LgsComm485.ShowCommunication( FALSE );
  373. g_CameraComm485.ShowCommunication( TRUE );
  374. #endif
  375. #ifndef COMPILE_AS_ANGLES
  376. LONG nSpeed = LGS_COMM_BAUDRATE;
  377. #ifndef COMPILE_AS_GETFILE
  378. // load comm speed
  379. FILE *pFile = fopen( "SERIAL.INI", "rt" );
  380. if( pFile ){
  381. fscanf( pFile, "%ld\n", &nSpeed );
  382. fclose( pFile );
  383. }
  384. #endif // #ifndef COMPILE_AS_GETFILE
  385. #ifdef DEBUG_PRINTOUT_MSGS
  386. debugProcBegin( "Creating COM port");
  387. #endif
  388. if( !g_LgsComm485.Create( CComm485::_COM2, nSpeed, 8, CComm485::_NOPARITY ) ){
  389. #ifdef DEBUG_PRINTOUT_MSGS
  390. debugProcEnd( 0 );
  391. #endif
  392. return;
  393. } else {
  394. #ifdef DEBUG_PRINTOUT_MSGS
  395. debugProcEnd();
  396. #endif
  397. }
  398. #endif // #ifndef COMPILE_AS_ANGLES
  399. // assume that no camera
  400. LGS::CAMERA_PARAMETERS cp;
  401. cp.eType = LGS::CAMERA_TYPE_NONE;
  402. cp.nShift = 0;
  403. cp.bAuto = FALSE;
  404. cp.nAutoDelay = 0;
  405. // assume that no relay
  406. LGS::RELAY_PARAMETERS rp;
  407. rp.bAuto = FALSE;
  408. rp.nAutoDelay = 0;
  409. rp.bNormallyClose = FALSE;
  410. // no voltage control by default
  411. LGS::VOLTAGE_PARAMETERS vp;
  412. vp.bControl = FALSE;
  413. // both lasers enabled
  414. LGS::LRF_DISABLE m_LRFDisable;
  415. m_LRFDisable.bMaster = FALSE;
  416. m_LRFDisable.bSlave = FALSE;
  417. // load settings
  418. #ifdef DEBUG_PRINTOUT_MSGS
  419. debugProcBegin( "MAIN:Load General Settings" );
  420. #endif
  421. BYTE *m_pSerialNumber, m_nSerialNumber, m_nAddress;
  422. g_Kernel.LoadSettings( (PCHAR)m_pSerialNumber, &m_nSerialNumber, &m_nAddress, &cp, &rp, &vp, &m_LRFDisable );
  423. // load user settings
  424. AUTO_RESET AutoReset;
  425. BOARD_SETTINGS BoardSettings;
  426. BoardSettings.nHID = 255;
  427. SWITCHER_SETTINGS SwitcherSettings;
  428. #ifdef DEBUG_PRINTOUT_MSGS
  429. debugProcEnd();
  430. debugProcBegin("MAIN:Loading User Settings");
  431. #endif
  432. g_Kernel.LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, &g_LgsComm485, &g_CameraComm485 );
  433. #ifdef DEBUG_PRINTOUT_MSGS
  434. debugProcEnd();
  435. debugProcBegin("MAIN:Loading HWR Settings");
  436. #endif
  437. g_Kernel.LoadFSSettings( &AutoReset, &BoardSettings, &SwitcherSettings, &g_LgsComm485, &g_CameraComm485);
  438. #ifdef DEBUG_PRINTOUT_MSGS
  439. debugProcEnd();
  440. debugProcBegin("MAIN:Board Init");
  441. #endif
  442. //Telling the board of Relay Default mode
  443. if( rp.bAuto ){
  444. BoardSettings.RelayDefaultMode = rp.bNormallyClose;
  445. } else {
  446. BoardSettings.RelayDefaultMode = FALSE;
  447. };
  448. //g_CameraComm485.SetRTS( TRUE );
  449. //delay(1);
  450. //g_CameraComm485.SetRTS( FALSE );
  451. if( !g_Board.Create( &BoardSettings ) ){
  452. #ifdef DEBUG_PRINTOUT_MSGS
  453. debugProcEnd( 0 );
  454. #endif
  455. return;
  456. } else {
  457. #ifdef DEBUG_PRINTOUT_MSGS
  458. debugProcEnd();
  459. #endif
  460. };
  461. #ifdef COMPILE_AS_GETFILE // Startup delay for PLS
  462. //#ifndef LGS_MIRROR //After Boot-loader all version have small delay of startup
  463. if( BoardCommOK ){
  464. // printf( "ChangeSpeed Motor" );
  465. #ifdef LGS_PLS_1
  466. INT nono = 600; // 1 minute
  467. #else // ALS
  468. INT nono = 60; // 6 seconds
  469. #endif
  470. BYTE TestBYTE = inportb( NEW_ID_ADDRESS );
  471. while ( nono && TestBYTE!= 0x5A && TestBYTE!= 0xA5 && TestBYTE != 0xAA ){
  472. nono--;
  473. TestBYTE = inportb( NEW_ID_ADDRESS );
  474. delay( 100 );
  475. //printf( "." );
  476. };
  477. };
  478. //#endif //LGS_MIRROR
  479. #endif
  480. #ifdef COMPILE_AS_ANGLES
  481. AnglesProc();
  482. #endif
  483. #ifdef DEBUG_PRINTOUT_MSGS
  484. debugProcBegin("Target Shadowing");
  485. #endif
  486. if( !g_Shadow.Create() ){
  487. #ifdef DEBUG_PRINTOUT_MSGS
  488. debugProcEnd( 0 );
  489. #endif
  490. return;
  491. } else {
  492. #ifdef DEBUG_PRINTOUT_MSGS
  493. debugProcEnd();
  494. #endif
  495. };
  496. #ifdef ALS_300
  497. if( !g_ShadowS.Create() ){
  498. #ifdef DEBUG_PRINTOUT_MSGS
  499. debugProcEnd( 0 );
  500. #endif
  501. return;
  502. } else {
  503. #ifdef DEBUG_PRINTOUT_MSGS
  504. debugProcEnd();
  505. #endif
  506. };
  507. #endif
  508. #ifdef DEBUG_GRAPH_SCREEN
  509. if( !g_Screen.Create() ){
  510. printf( "Can't create screen\n" );
  511. return;
  512. } else if (g_UI_Debug) printf("Done\n");
  513. #endif
  514. #ifdef DEBUG_PRINTOUT_MSGS
  515. debugProcBegin("Create Kernel");
  516. #endif
  517. #ifdef ALS_300
  518. if( !g_Kernel.Create( &g_Board, &g_LgsComm485, &g_Shadow, &g_ShadowS, &g_CameraComm485, CComm485::_COM1 ) ){
  519. #else
  520. if( !g_Kernel.Create( &g_Board, &g_LgsComm485, &g_Shadow, &g_CameraComm485, CComm485::_COM1 ) ){
  521. #endif
  522. #ifdef DEBUG_PRINTOUT_MSGS
  523. debugProcEnd( 0 );
  524. #endif
  525. return;
  526. } else {
  527. #ifdef DEBUG_PRINTOUT_MSGS
  528. debugProcEnd();
  529. #endif
  530. };
  531. #ifdef DEBUG_PRINTOUT_MSGS
  532. debugProcBegin("Working");
  533. #endif
  534. CheckHeap( "Before run" );
  535. BOOL bRestart = g_Kernel.Run();
  536. CheckHeap( "After run" );
  537. #ifdef DEBUG_PRINTOUT_MSGS
  538. debugProcEnd();
  539. #endif
  540. //g_Board.Destroy();
  541. g_Kernel.Destroy();
  542. g_Shadow.Destroy();
  543. #ifdef DEBUG_GRAPH_SCREEN
  544. g_Screen.Destroy();
  545. #endif
  546. g_Board.Destroy();
  547. g_LgsComm485.Destroy();
  548. g_CameraComm485.Destroy();
  549. //if( bRestart && argc )
  550. // StartAfterExit( argv[0] );
  551. CheckHeap( "Done" );
  552. #ifndef NO_WDT2_INIT
  553. if( g_bIsVortex ) stop_sys_clock();
  554. #endif
  555. }
  556. void WriteToKeyboardBuffer( CHAR a );
  557. void StartAfterExit( PCHAR pFileName )
  558. {
  559. // "type"
  560. for( INT i = 0; i < strlen( pFileName ); i++ )
  561. WriteToKeyboardBuffer( pFileName[i] );
  562. // "press enter"
  563. WriteToKeyboardBuffer( (char) 13 ); //'\n' );
  564. // WriteToKeyboardBuffer( '\r' );
  565. }
  566. void WriteToKeyboardBuffer( CHAR a )
  567. {
  568. unsigned far *bufbegin;
  569. unsigned far *bufend;
  570. unsigned far *buftail;
  571. unsigned far *buffer;
  572. // set up buffer pointers
  573. FP_SEG(bufbegin)=FP_SEG(bufend)=FP_SEG(buftail)=FP_SEG(buffer)=0x40;
  574. FP_OFF(bufbegin)=0x80;
  575. FP_OFF(bufend)=0x82;
  576. FP_OFF(buftail)=0x1c;
  577. disable();
  578. FP_OFF(buffer)=*buftail;
  579. *buffer++=a;
  580. if ( FP_OFF(buffer) >= *bufend )
  581. FP_OFF(buffer)=*bufbegin;
  582. *buftail=FP_OFF(buffer);
  583. enable();
  584. }
  585. #ifdef COMPILE_AS_ANGLES
  586. void AnglesProc()
  587. {
  588. INT nAngle = 0;
  589. BOOL bFirstAngle = TRUE;
  590. INT nZeroCount = 0;
  591. BOOL bZeroFirst = TRUE;
  592. INT nZeroErrorCount = 0;
  593. INT nAngleErrorCount = 0;
  594. while( TRUE )
  595. {
  596. BOOL bZero;
  597. BOOL pSun[2];
  598. INT pRange[2];
  599. if( g_Board.GetData( &bZero, pSun, pRange ) )
  600. {
  601. if( bZero )
  602. {
  603. if( bFirstAngle )
  604. bFirstAngle = FALSE;
  605. else
  606. {
  607. g_CRT.IntOut( 0, 0, nAngle + 1 );
  608. if( (nAngle + 1) != LGS_MAX_DETECTOR_ANGLES )
  609. g_CRT.IntOut( 10, 0, ++nAngleErrorCount );
  610. }
  611. if( bZeroFirst ) nZeroCount = 1;
  612. else
  613. {
  614. nZeroCount++;
  615. g_CRT.IntOut( 10, 1, ++nZeroErrorCount );
  616. }
  617. g_CRT.IntOut( 0, 1, nZeroCount );
  618. bZeroFirst = FALSE;
  619. nAngle = 0;
  620. }
  621. else
  622. {
  623. bZeroFirst = TRUE;
  624. nAngle++;
  625. }
  626. }
  627. }
  628. }
  629. #endif