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.

1881 lines
59 KiB

4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
4 years ago
​
4 years ago
​
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
4 years ago
4 years ago
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
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: 17/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: KERNEL.CPP
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of KERNEL.CPP
  13. //----------------------------------------------------------------------------
  14. #include "StdAfx.h"
  15. #include <stdio.h>
  16. #include <conio.h>
  17. #include "kernel.h"
  18. #include "..\lglib\comm\lgsm.h"
  19. #include "..\lglib\lgbitcod.h"
  20. #include "..\lglib\version.h"
  21. #include "screen.h"
  22. #include "Camera.h"
  23. #include "CMigPTZ.h"
  24. #include "CMicPTZ.h"
  25. #include "CPG3AD.h"
  26. #include "CTKS576.h"
  27. #include "CVicon.h"
  28. #include "CPelco.h"
  29. #include "CHebron.h"
  30. CHAR CKernel::s_pSoftwareVersion[MAX_PATH] = "";
  31. INT CKernel::s_nSoftwareVersion = 0;
  32. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  33. #ifdef INCLUDE_WINDOWS_DEFINITIONS
  34. #define TIMER() *g_Timer
  35. #else
  36. #define TIMER() (GetTickCount() * 10 / 182)
  37. #endif
  38. void CKernel::Reset( BOOL bFullReset )
  39. {
  40. m_Detector[0].Reset( bFullReset );
  41. m_Detector[1].Reset( bFullReset );
  42. m_GetFile.Reset();
  43. #ifdef DEBUG_GRAPH_SCREEN
  44. g_Screen.Clear();
  45. #endif
  46. // reset error timings
  47. memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST)*4 );
  48. memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow)*4 );
  49. memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun)*4 );
  50. m_dwTimeErrorDelay_EA = 0UL;
  51. m_dwTimeErrorDelay_IQ = 0UL;
  52. m_dwTimePower = 0UL;
  53. // reset board
  54. m_pBoard->Reset();
  55. }
  56. BOOL CKernel::Run()
  57. {
  58. BYTE *pBuffer;
  59. INT nCount;
  60. BYTE nMode = LGS::MODE_DETECTOR;
  61. BOOL bRestart = FALSE;
  62. DWORD nBoardIrq = 0;
  63. DWORD nBoardTimer = TIMER();
  64. BOOL bBoardNoIrq = FALSE;
  65. #ifndef COMPILE_AS_GETFILE
  66. BOOL bFastTimerValid = FALSE;
  67. #endif
  68. BOOL bSetHzDataInProgress = FALSE;
  69. BOOL bSetCalibrationTableInProgress = FALSE;
  70. BOOL bPower, bZero, bSun[2];
  71. INT nRange[2];
  72. #ifdef COMPILE_AS_GETFILE
  73. DWORD dwStartTime = TIMER();
  74. BOOL bGetFileRun = FALSE;
  75. // send human readable information
  76. {
  77. // load user settings
  78. AUTO_RESET AutoReset;
  79. BOARD_SETTINGS BoardSettings;
  80. SWITCHER_SETTINGS SwitcherSettings;
  81. CKernel::LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
  82. CHAR pText[MAX_PATH];
  83. INT nText;
  84. nText = sprintf( pText, "SOFTWARE VERSION <%s>\r\n", s_pSoftwareVersion );
  85. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  86. nText = sprintf( pText, "ADDRESS <%d>\r\n", m_nAddress );
  87. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  88. nText = sprintf( pText, "SERIAL NUMBER <%s>\r\n", m_pSerialNumber );
  89. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  90. nText = sprintf( pText, "AUTORESET_ENABLE <%d>\r\n", AutoReset.bEnabled );
  91. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  92. nText = sprintf( pText, "AUTORESET_INTERLEAVE <%ld>\r\n", AutoReset.dwInterleave );
  93. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  94. nText = sprintf( pText, "AUTORESET_TIMEOUT <%ld>\r\n", AutoReset.dwTimeout );
  95. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  96. nText = sprintf( pText, "BOARD_TEMPERATURE <%d>\r\n", (INT)(CHAR)BoardSettings.nTemperature );
  97. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  98. nText = sprintf( pText, "BOARD_ZEROSHIFT <%d>\r\n", BoardSettings.nZeroShift );
  99. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  100. nText = sprintf( pText, "SWITCHER_TABLE <%d,%d,%d>\r\n", SwitcherSettings.pTable[0], SwitcherSettings.pTable[1], SwitcherSettings.pTable[2] );
  101. m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
  102. }
  103. #endif
  104. // update settings
  105. AUTO_RESET AutoReset;
  106. BOARD_SETTINGS BoardSettings;
  107. SWITCHER_SETTINGS SwitcherSettings;
  108. LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
  109. SaveUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings);
  110. while( m_bRun )
  111. {
  112. #ifndef INCLUDE_WINDOWS_DEFINITIONS
  113. Sleep(0);
  114. #endif
  115. #ifdef WATCHDOG_ENABLED
  116. // update watchdog timer
  117. m_WatchDog.Update( TIMER() );
  118. #endif
  119. #ifdef COMPILE_AS_GETFILE
  120. if( !bGetFileRun )
  121. {
  122. if( ( (TIMER()) - dwStartTime ) > LGS_GETFILE_WAIT_TIME )
  123. {
  124. // quit
  125. m_bRun = FALSE;
  126. }
  127. }
  128. #endif
  129. #ifndef COMPILE_AS_GETFILE
  130. // clear zero flag
  131. BOOL bInvalidateCamera = FALSE;
  132. // check fast timer
  133. static DWORD dwSlowTime = 0;
  134. if( !bFastTimerValid )
  135. {
  136. if( TIMER() != dwSlowTime )
  137. {
  138. dwSlowTime = TIMER();
  139. bInvalidateCamera = TRUE;
  140. }
  141. }
  142. #endif
  143. // perform work depend on work mode
  144. switch( nMode )
  145. {
  146. case LGS::MODE_BORDER:
  147. case LGS::MODE_DETECTOR:
  148. // check IRQ
  149. if( ( (TIMER()) - nBoardTimer ) > 18UL )
  150. {
  151. if( !nBoardIrq )
  152. {
  153. bBoardNoIrq = TRUE;
  154. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  155. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  156. #endif
  157. // reset board
  158. m_pBoard->Reset();
  159. #ifndef COMPILE_AS_GETFILE
  160. // fast timer is not valid
  161. bFastTimerValid = FALSE;
  162. #endif
  163. }
  164. nBoardTimer = TIMER();
  165. nBoardIrq = 0;
  166. }
  167. // check board
  168. if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
  169. {
  170. // perform linearization
  171. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  172. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  173. // update voltage state
  174. m_Voltage.Invalidate( bPower );
  175. nBoardIrq++;
  176. #ifndef COMPILE_AS_GETFILE
  177. // fast timer is valid
  178. bFastTimerValid = TRUE;
  179. #endif
  180. #ifdef DEBUG_BOARD_SET_TEST_BIT
  181. m_pBoard->SetTestBit( TRUE );
  182. #endif
  183. #ifdef LGS_MIRROR
  184. if( m_bWaitFirstZero && bZero )
  185. {
  186. m_bWaitFirstZero = FALSE;
  187. m_nDetector = 0;
  188. }
  189. if( !m_bWaitFirstZero )
  190. {
  191. if( bZero )
  192. m_nDetector = m_nAngle = 0;
  193. else
  194. {
  195. m_nAngle++;
  196. if( m_nAngle == LGS_MAX_DETECTOR_ANGLES )
  197. {
  198. m_nDetector ++;
  199. if ( m_nDetector > 3 ) m_nDetector=0;
  200. m_nAngle = 0;
  201. bZero = TRUE;
  202. }
  203. }
  204. m_Tracker[ 0 ].Invalidate();
  205. #ifdef COMM_WITHOUT_INTERRUPTS
  206. m_pComm485->Invalidate();
  207. m_pCameraComm->Invalidate();
  208. #endif
  209. m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], TRUE );
  210. }
  211. #else // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  212. m_Tracker[0].Invalidate();
  213. #ifdef COMM_WITHOUT_INTERRUPTS
  214. m_pComm485->Invalidate();
  215. m_pCameraComm->Invalidate();
  216. #endif
  217. m_Tracker[1].Invalidate();
  218. #ifdef COMM_WITHOUT_INTERRUPTS
  219. m_pComm485->Invalidate();
  220. m_pCameraComm->Invalidate();
  221. #endif
  222. m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], m_Detector[1].IsAllowFlip() );
  223. #ifdef COMM_WITHOUT_INTERRUPTS
  224. m_pComm485->Invalidate();
  225. m_pCameraComm->Invalidate();
  226. #endif
  227. m_Detector[1].Invalidate( bZero, bSun[1], nRange[1], m_Detector[0].IsAllowFlip() );
  228. #endif // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  229. #ifdef DEBUG_BOARD_SET_TEST_BIT
  230. m_pBoard->SetTestBit( FALSE );
  231. #endif
  232. #ifndef COMPILE_AS_GETFILE
  233. bInvalidateCamera = TRUE;
  234. #endif
  235. }
  236. break;
  237. default:
  238. case LGS::MODE_FILESYSTEM:
  239. case LGS::MODE_GETFILE:
  240. if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
  241. {
  242. // perform linearization
  243. nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
  244. nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
  245. // update voltage state
  246. m_Voltage.Invalidate( bPower );
  247. #ifndef COMPILE_AS_GETFILE
  248. bInvalidateCamera = TRUE;
  249. #endif
  250. nBoardIrq++;
  251. #ifndef COMPILE_AS_GETFILE
  252. // fast timer is valid
  253. bFastTimerValid = TRUE;
  254. #endif
  255. }
  256. break;
  257. }
  258. // try to work in windows
  259. #ifndef INCLUDE_WINDOWS_DEFINITIONS
  260. bFastTimerValid = FALSE;
  261. #endif
  262. #ifndef COMPILE_AS_GETFILE
  263. // process camera commands
  264. if( bInvalidateCamera )
  265. {
  266. #ifdef COMM_WITHOUT_INTERRUPTS
  267. m_pComm485->Invalidate();
  268. m_pCameraComm->Invalidate();
  269. #endif
  270. #ifdef DEBUG_BOARD_SET_TEST_BIT_2
  271. m_pBoard->SetTestBit2( TRUE );
  272. #endif
  273. // process camera commands
  274. m_pCamera->Invalidate( TIMER(), m_pBoard->GetTimer(), bFastTimerValid );
  275. #ifdef DEBUG_BOARD_SET_TEST_BIT_2
  276. m_pBoard->SetTestBit2( FALSE );
  277. #endif
  278. }
  279. // process relay commands
  280. m_Relay.Invalidate( m_pBoard->GetTimer(), TIMER() );
  281. #endif
  282. //process communication commands
  283. #ifdef COMM_WITHOUT_INTERRUPTS
  284. m_pComm485->Invalidate();
  285. m_pCameraComm->Invalidate();
  286. #endif
  287. // auto reset
  288. if( m_AutoReset.IsNeedToReset() )
  289. {
  290. bRestart = TRUE;
  291. m_bRun = FALSE;
  292. }
  293. // check for new commands from host
  294. if( m_Protocol.Read( &pBuffer, &nCount, 0, FALSE ) )
  295. {
  296. // check address
  297. BYTE bAddress = 0;
  298. if( nCount && ( (m_nAddress == *pBuffer) || (LGS_EXCLUSIVE_ADDRESS == *pBuffer) ) )
  299. {
  300. // store address
  301. bAddress = *pBuffer;
  302. // update pointers
  303. nCount--;
  304. pBuffer++;
  305. // check remainig count
  306. if( nCount )
  307. {
  308. BYTE pSendBuffer[1024];
  309. PBYTE pSendBufferPtr = pSendBuffer;
  310. int nSendCount = 2;
  311. // set address
  312. *pSendBufferPtr++ = bAddress;
  313. BYTE bHostCommand = *pBuffer++;
  314. // Restart if set hz data was not finished correctly
  315. if( ( bSetHzDataInProgress && bHostCommand != LGS::CMD_SET_HZ_DATA ) ||
  316. ( bSetCalibrationTableInProgress && bHostCommand != LGS::CMD_SET_CALIBRATION_TABLE ) )
  317. {
  318. bRestart = TRUE;
  319. m_bRun = FALSE;
  320. }
  321. // get command from buffer
  322. switch( bHostCommand )
  323. {
  324. #ifndef EMBEDDED_CAMERA_DISABLE
  325. case LGS::CMD_CAMERA:
  326. // build CMD_MODE command
  327. *pSendBufferPtr++ = LGS::CMD_CAMERA;
  328. // process command
  329. m_pCamera->OnProtocolLgsCameraCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
  330. // write command
  331. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  332. break;
  333. #endif
  334. case LGS::CMD_RELAY:
  335. // build CMD_MODE command
  336. *pSendBufferPtr++ = LGS::CMD_RELAY;
  337. // process command
  338. m_Relay.OnProtocolLgsRelayCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
  339. // write command
  340. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  341. break;
  342. case LGS::CMD_MODE:
  343. {
  344. // get command parameters
  345. BOOL bSetMode = FALSE;
  346. BYTE nNewMode = nMode;
  347. LGS::GetMode( pBuffer, &bSetMode, &nNewMode );
  348. // build CMD_MODE command
  349. *pSendBufferPtr++ = LGS::CMD_MODE;
  350. nSendCount += LGS::BuildMode( pSendBufferPtr, FALSE, nMode );
  351. // write command
  352. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  353. // if needs to switch mode
  354. if( bSetMode && nMode != nNewMode )
  355. {
  356. switch( nNewMode )
  357. {
  358. case LGS::MODE_GETFILE:
  359. #ifdef COMPILE_AS_GETFILE
  360. bGetFileRun = TRUE;
  361. #endif
  362. break;
  363. case LGS::MODE_BORDER:
  364. case LGS::MODE_DETECTOR:
  365. case LGS::MODE_FILESYSTEM:
  366. m_Detector[0].BorderEnable( nNewMode == LGS::MODE_BORDER );
  367. m_Detector[1].BorderEnable( nNewMode == LGS::MODE_BORDER );
  368. #ifdef COMPILE_AS_GETFILE
  369. bGetFileRun = FALSE;
  370. dwStartTime = TIMER();
  371. #endif
  372. break;
  373. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  374. case LGS::MODE_SENDBOARDDATA1:
  375. case LGS::MODE_SENDBOARDDATA2:
  376. DoSendBoardData( nNewMode - LGS::MODE_SENDBOARDDATA1 );
  377. break;
  378. #endif
  379. }
  380. // reset after switching mode
  381. if( nMode != LGS::MODE_BORDER && nMode != LGS::MODE_DETECTOR )
  382. Reset( TRUE );
  383. // store new mode
  384. nMode = nNewMode;
  385. // reset IRQ checking
  386. nBoardIrq = 0;
  387. nBoardTimer = TIMER();
  388. }
  389. }
  390. break;
  391. case LGS::CMD_BORDER:
  392. {
  393. // get command parameters
  394. BYTE bError;
  395. INT nAngle, nRange0, nRange1;
  396. LGS::GetBorder( pBuffer, &bError, &nAngle, &nRange0, &nRange1 );
  397. // build CMD_BORDER command
  398. *pSendBufferPtr++ = LGS::CMD_BORDER;
  399. if( nMode != LGS::MODE_BORDER )
  400. nSendCount += LGS::BuildBorder( pSendBufferPtr, LGS::BD_ERRORMODE, 0, 0, 0 );
  401. else
  402. {
  403. BYTE bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ||
  404. (!m_Detector[1].GetBorderRange( nAngle, &nRange1 )) ) ? LGS::BD_NOTREADY : 0;
  405. if( bError )
  406. nSendCount += LGS::BuildBorder( pSendBufferPtr, bError, 0, 0, 0 );
  407. else
  408. nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0 >> 1, nRange1 >> 1 );
  409. }
  410. // write command
  411. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  412. }
  413. break;
  414. case LGS::CMD_STATE:
  415. {
  416. // build CMD_STATE command
  417. *pSendBufferPtr++ = LGS::CMD_STATE;
  418. if( nMode != LGS::MODE_DETECTOR )
  419. nSendCount += LGS::BuildError( pSendBufferPtr, 0, LGS::ER_MODE, 0 );
  420. else
  421. {
  422. for( int i = 0; i < 2; i++ )
  423. {
  424. CDetector *pDetector = m_Detector + i;
  425. #ifdef LGS_MIRROR
  426. CTracker *pTracker = m_Tracker + 0;
  427. #else
  428. CTracker *pTracker = m_Tracker + i;
  429. #endif
  430. BYTE bDevice = i ? LGS::ID_DEVICE1 : LGS::ID_DEVICE0;
  431. // assume that no errors
  432. BYTE bErrorMask = LGS::ER_NONE;
  433. INT nErrorAngle = 0;
  434. // check for tracker overflow
  435. if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
  436. {
  437. m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  438. bErrorMask |= LGS::ER_OVERFLOW;
  439. }
  440. // check for tracker scan to scan overflow
  441. if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
  442. {
  443. m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  444. bErrorMask |= LGS::ER_SSTOVERFLOW;
  445. }
  446. // check for detector sun errors
  447. if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
  448. {
  449. m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  450. bErrorMask |= LGS::ER_SUNBIT;
  451. }
  452. // check for detector angle errors
  453. if( pDetector->GetLastErrorAngle() )
  454. {
  455. bErrorMask |= LGS::ER_ANGLE;
  456. nErrorAngle = pDetector->GetLastErrorAngleValue();
  457. }
  458. // check for kernel error
  459. if( bBoardNoIrq )
  460. {
  461. bErrorMask |= LGS::ER_NOIRQ;
  462. bBoardNoIrq = FALSE;
  463. }
  464. // if error exist
  465. if( bErrorMask )
  466. nSendCount += LGS::BuildError( pSendBufferPtr, bDevice, bErrorMask, nErrorAngle );
  467. // place target information
  468. CTracker::TARGET target;
  469. while( pTracker->GetTarget( &target ) )
  470. {
  471. #ifdef LGS_MIRROR
  472. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  473. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange, target.nWidth );
  474. #else
  475. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange );
  476. #endif
  477. #else
  478. #ifdef LGS_TEST_SEND_TARGET_WIDTH
  479. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange, target.nWidth );
  480. #else
  481. nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange );
  482. #endif
  483. #endif
  484. if( nSendCount >= 20 )
  485. break;
  486. }
  487. if( nSendCount >= 20 )
  488. break;
  489. }
  490. }
  491. #ifndef EMBEDDED_CAMERA_DISABLE
  492. // add camera tags
  493. m_pCamera->OnProtocolLgsStateCommand( pSendBufferPtr, nSendCount );
  494. #endif
  495. // write command
  496. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  497. }
  498. break;
  499. case LGS::CMD_STATE_2:
  500. // prepare response
  501. OnCmdState2( pBuffer, nCount, pSendBufferPtr, nSendCount, nMode, bBoardNoIrq );
  502. // write command
  503. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  504. break;
  505. case LGS::CMD_GET_WIDTH_TABLE:
  506. // prepare response
  507. OnCmdGetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  508. // write command
  509. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  510. break;
  511. case LGS::CMD_SET_WIDTH_TABLE:
  512. // prepare response
  513. OnCmdSetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  514. // write command
  515. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  516. break;
  517. case LGS::CMD_GET_ZOOM_TABLE:
  518. // prepare response
  519. OnCmdGetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  520. // write command
  521. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  522. break;
  523. case LGS::CMD_SET_ZOOM_TABLE:
  524. // prepare response
  525. OnCmdSetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  526. // write command
  527. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  528. // update camera settings
  529. m_pCamera->SaveZoomTable();
  530. // reset after file operation
  531. Reset( TRUE );
  532. // reset IRQ checking
  533. nBoardIrq = 0;
  534. nBoardTimer = TIMER();
  535. break;
  536. case LGS::CMD_GET_TILT_TABLE:
  537. // prepare response
  538. OnCmdGetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  539. // write command
  540. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  541. break;
  542. case LGS::CMD_SET_TILT_TABLE:
  543. // prepare response
  544. OnCmdSetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  545. // write command
  546. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  547. // update camera settings
  548. m_pCamera->SaveTiltTable();
  549. // reset after file operation
  550. Reset( TRUE );
  551. // reset IRQ checking
  552. nBoardIrq = 0;
  553. nBoardTimer = TIMER();
  554. break;
  555. case LGS::CMD_GET_LRF_DISABLE:
  556. // prepare response
  557. OnCmdGetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  558. // write command
  559. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  560. break;
  561. case LGS::CMD_SET_LRF_DISABLE:
  562. // prepare response
  563. OnCmdSetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  564. // write command
  565. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  566. // reset after file operation
  567. Reset( TRUE );
  568. // reset IRQ checking
  569. nBoardIrq = 0;
  570. nBoardTimer = TIMER();
  571. break;
  572. case LGS::CMD_GET_HZ_DATA:
  573. m_pShadow->OnCmdGetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
  574. // write command
  575. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  576. break;
  577. case LGS::CMD_SET_HZ_DATA:
  578. {
  579. BOOL bPendingSave = m_pShadow->OnCmdSetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
  580. // write command
  581. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  582. // save
  583. if( bPendingSave )
  584. {
  585. // save data
  586. m_pShadow->Save();
  587. // reset after file operation
  588. Reset( TRUE );
  589. // reset IRQ checking
  590. nBoardIrq = 0;
  591. nBoardTimer = TIMER();
  592. #ifdef LGS_MIRROR
  593. bRestart = TRUE;
  594. m_bRun = FALSE;
  595. #endif
  596. }
  597. }
  598. break;
  599. case LGS::CMD_GET_HZ_ENABLE:
  600. m_pShadow->OnCmdGetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  601. // write command
  602. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  603. break;
  604. case LGS::CMD_SET_HZ_ENABLE:
  605. {
  606. BOOL bPendingSave = m_pShadow->OnCmdSetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  607. // write command
  608. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  609. // save
  610. if( bPendingSave )
  611. {
  612. // save data
  613. m_pShadow->Save();
  614. // reset after file operation
  615. Reset( TRUE );
  616. // reset IRQ checking
  617. nBoardIrq = 0;
  618. nBoardTimer = TIMER();
  619. // set data finished correctly
  620. bSetHzDataInProgress = FALSE;
  621. }
  622. else
  623. bSetHzDataInProgress = TRUE;
  624. }
  625. break;
  626. case LGS::CMD_GET_CALIBRATION_TABLE:
  627. OnCmdGetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
  628. // write command
  629. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  630. break;
  631. case LGS::CMD_SET_CALIBRATION_TABLE:
  632. {
  633. INT nDevice = 0;
  634. BOOL bPendingSave = OnCmdSetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount, nDevice );
  635. // write command
  636. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  637. // save
  638. if( bPendingSave )
  639. {
  640. // save data
  641. switch( nDevice )
  642. {
  643. case 0: m_Calibrator[nDevice].Save( "lt0.ini" ); break;
  644. case 1: m_Calibrator[nDevice].Save( "lt1.ini" ); break;
  645. }
  646. // reset after file operation
  647. Reset( TRUE );
  648. // reset IRQ checking
  649. nBoardIrq = 0;
  650. nBoardTimer = TIMER();
  651. // set data finished correctly
  652. bSetCalibrationTableInProgress = FALSE;
  653. }
  654. else
  655. bSetCalibrationTableInProgress = TRUE;
  656. }
  657. break;
  658. case LGS::CMD_QUIT:
  659. *pSendBufferPtr++ = LGS::CMD_QUIT;
  660. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  661. m_bRun = FALSE;
  662. break;
  663. case LGS::CMD_RESTART:
  664. *pSendBufferPtr++ = LGS::CMD_RESTART;
  665. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  666. bRestart = TRUE;
  667. m_bRun = FALSE;
  668. break;
  669. case LGS::CMD_GET_SERIAL_NUMBER:
  670. // reply command
  671. *pSendBufferPtr++ = LGS::CMD_GET_SERIAL_NUMBER;
  672. // reply data
  673. nSendCount += LGS::BuildSerialNumber( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  674. // write into port
  675. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  676. break;
  677. case LGS::CMD_GET_SOFTWARE_VERSION:
  678. // reply command
  679. *pSendBufferPtr++ = LGS::CMD_GET_SOFTWARE_VERSION;
  680. // reply data
  681. nSendCount += LGS::BuildSoftwareVersion( pSendBufferPtr, (PBYTE)s_pSoftwareVersion, s_nSoftwareVersion );
  682. // write into port
  683. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  684. break;
  685. case LGS::CMD_GET_VOLTAGE:
  686. // reply command
  687. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE;
  688. // reply data
  689. nSendCount += LGS::BuildEvtVoltage( pSendBufferPtr, m_Voltage.GetVoltage() );
  690. // write into port
  691. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  692. break;
  693. #ifndef EMBEDDED_CAMERA_DISABLE
  694. case LGS::CMD_GET_CAMERA_PARAMETERS:
  695. {
  696. // reply command
  697. *pSendBufferPtr++ = LGS::CMD_GET_CAMERA_PARAMETERS;
  698. // reply data
  699. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &m_pCamera->GetParameters() );
  700. // write into port
  701. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  702. }
  703. break;
  704. case LGS::CMD_SET_CAMERA_PARAMETERS:
  705. {
  706. LGS::CAMERA_PARAMETERS cp;
  707. LGS::GetCameraParameters( pBuffer, &cp );
  708. // reply command
  709. *pSendBufferPtr++ = LGS::CMD_SET_CAMERA_PARAMETERS;
  710. // reply data
  711. nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &cp );
  712. // write into port
  713. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  714. // store serial number
  715. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &cp, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  716. // restart program
  717. m_bRun = FALSE;
  718. }
  719. break;
  720. #endif
  721. case LGS::CMD_GET_VOLTAGE_PARAMETERS:
  722. {
  723. // reply command
  724. *pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE_PARAMETERS;
  725. // reply data
  726. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &m_Voltage.GetParameters() );
  727. // write into port
  728. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  729. }
  730. break;
  731. case LGS::CMD_SET_VOLTAGE_PARAMETERS:
  732. {
  733. LGS::VOLTAGE_PARAMETERS vp;
  734. // store voltage parameters
  735. LGS::GetVoltageParameters( pBuffer, &vp );
  736. // reply command
  737. *pSendBufferPtr++ = LGS::CMD_SET_VOLTAGE_PARAMETERS;
  738. // reply data
  739. nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &vp );
  740. // write into port
  741. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  742. // store serial number
  743. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &vp, &m_LRFDisable );
  744. // update voltage prameters
  745. m_Voltage.SetParameters( &vp );
  746. // reset after file operation
  747. Reset( TRUE );
  748. // reset IRQ checking
  749. nBoardIrq = 0;
  750. nBoardTimer = TIMER();
  751. }
  752. break;
  753. case LGS::CMD_GET_RELAY_PARAMETERS:
  754. {
  755. // reply command
  756. *pSendBufferPtr++ = LGS::CMD_GET_RELAY_PARAMETERS;
  757. // reply data
  758. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &m_Relay.GetParameters() );
  759. // write into port
  760. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  761. }
  762. break;
  763. case LGS::CMD_SET_RELAY_PARAMETERS:
  764. {
  765. LGS::RELAY_PARAMETERS rp;
  766. LGS::GetRelayParameters( pBuffer, &rp );
  767. // reply command
  768. *pSendBufferPtr++ = LGS::CMD_SET_RELAY_PARAMETERS;
  769. // reply data
  770. nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &rp );
  771. // write into port
  772. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  773. // store serial number
  774. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
  775. // update relay parameters
  776. m_Relay.SetParameters( &rp );
  777. // reset after file operation
  778. Reset( TRUE );
  779. // reset IRQ checking
  780. nBoardIrq = 0;
  781. nBoardTimer = TIMER();
  782. }
  783. break;
  784. case LGS::CMD_SET_ADDRESS:
  785. {
  786. // reply command
  787. *pSendBufferPtr++ = LGS::CMD_SET_ADDRESS;
  788. // parse parameters
  789. BYTE pSerialNumber[MAX_PATH];
  790. BYTE nAddress, nCount;
  791. LGS::GetAddress( pBuffer, &nAddress, &nCount, pSerialNumber );
  792. // only if serial number is equal
  793. if( (nCount == m_nSerialNumber) && !memcmp( pSerialNumber, m_pSerialNumber, m_nSerialNumber ) )
  794. {
  795. // change address
  796. m_nAddress = nAddress;
  797. // prepare answer message
  798. nSendCount += LGS::BuildAddress( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
  799. // send reply
  800. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  801. // store serial number
  802. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  803. // reset after file operation
  804. Reset( TRUE );
  805. // reset IRQ checking
  806. nBoardIrq = 0;
  807. nBoardTimer = TIMER();
  808. }
  809. }
  810. break;
  811. case LGS::CMD_SET_COMM_SPEED:
  812. {
  813. // reply command
  814. *pSendBufferPtr++ = LGS::CMD_SET_COMM_SPEED;
  815. // parse parameters
  816. LONG nSpeed;
  817. LGS::GetCommSpeed( pBuffer, &nSpeed );
  818. // prepare answer message
  819. nSendCount += LGS::BuildCommSpeed( pSendBufferPtr, nSpeed );
  820. // send reply
  821. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  822. // reinitialize communication if nessessary
  823. #ifndef COMPILE_AS_GETFILE
  824. if( m_pComm485->GetBaudRate() != nSpeed )
  825. #endif
  826. {
  827. if( !m_pComm485->SetParameters( nSpeed, 8L, CComm485::_NOPARITY ) )
  828. return FALSE;
  829. // store new comm speed
  830. FILE *pFile = fopen( "SERIAL.INI", "wt" );
  831. if( pFile )
  832. {
  833. fprintf( pFile, "%ld\n", nSpeed );
  834. fclose( pFile );
  835. }
  836. // reset after file operation
  837. Reset( TRUE );
  838. // reset IRQ checking
  839. nBoardIrq = 0;
  840. nBoardTimer = TIMER();
  841. }
  842. }
  843. break;
  844. case LGS::CMD_PARAMETERS:
  845. {
  846. // reply command
  847. *pSendBufferPtr++ = LGS::CMD_PARAMETERS;
  848. // parse input command
  849. BYTE bSet, nDevice;
  850. LGS::LGS_PARAMETERS parameters;
  851. LGS::GetParameters( pBuffer, &bSet, &nDevice, &parameters );
  852. // return parameters
  853. if( bSet )
  854. {
  855. m_Detector[ nDevice ].SetParameters( &parameters );
  856. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  857. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  858. // reset after file operation
  859. Reset( TRUE );
  860. // reset IRQ checking
  861. nBoardIrq = 0;
  862. nBoardTimer = TIMER();
  863. }
  864. else
  865. {
  866. m_Detector[ nDevice ].GetParameters( &parameters );
  867. nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, &parameters );
  868. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  869. }
  870. }
  871. break;
  872. case LGS::CMD_RESET:
  873. *pSendBufferPtr++ = LGS::CMD_RESET;
  874. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  875. nMode = LGS::MODE_DETECTOR;
  876. Reset( FALSE );
  877. // reset IRQ checking
  878. nBoardIrq = 0;
  879. nBoardTimer = TIMER();
  880. #ifdef LGS_MIRROR
  881. bRestart = TRUE;
  882. m_bRun = FALSE;
  883. #endif
  884. break;
  885. case LGS::CMD_FULL_RESET:
  886. *pSendBufferPtr++ = LGS::CMD_FULL_RESET;
  887. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  888. nMode = LGS::MODE_DETECTOR;
  889. Reset( TRUE );
  890. // reset IRQ checking
  891. nBoardIrq = 0;
  892. nBoardTimer = TIMER();
  893. #ifdef LGS_MIRROR
  894. bRestart = TRUE;
  895. m_bRun = FALSE;
  896. #endif
  897. break;
  898. case LGS::CMD_FULL_BORDER:
  899. {
  900. *pSendBufferPtr++ = LGS::CMD_FULL_BORDER;
  901. // read command data
  902. INT nAngle;
  903. LGS::GetCmdFullBorder( pBuffer, &nAngle );
  904. // prepare answer
  905. INT nRange1 = 0;
  906. INT nRange2 = 0;
  907. BOOL bReady = m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
  908. m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
  909. if( bReady )
  910. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, TRUE, nAngle, nRange1, nRange2 );
  911. else
  912. // use percent from detector 2 because it always comes later
  913. nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, FALSE, nRange2, 0, 0 );
  914. // write back
  915. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  916. }
  917. break;
  918. case LGS::CMD_GETFILE:
  919. {
  920. // build CMD_GETFILE command
  921. *pSendBufferPtr++ = LGS::CMD_GETFILE;
  922. if( nMode != LGS::MODE_GETFILE )
  923. {
  924. nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORMODE, 0, 0, 0 );
  925. }
  926. else
  927. {
  928. // get command parameters
  929. BYTE bError, bOperation, pData[100];
  930. INT nData;
  931. LGS::GetGetFile( pBuffer, &bError, &bOperation, pData, &nData );
  932. // perform command
  933. if( m_GetFile.OnCommand( bOperation, pData, nData ) )
  934. nSendCount += LGS::BuildGetFile( pSendBufferPtr, 0, ( bOperation & LGS::GF_OP_INDEX ) | LGS::GF_OP_OK, NULL, 0 );
  935. else
  936. nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORFILE, bOperation, NULL, 0 );
  937. }
  938. // write unswer
  939. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  940. }
  941. break;
  942. #ifndef LGS_DISABLE_FILE_SYSTEM
  943. case LGS::CMD_FS_SUB_PACKET:
  944. {
  945. // get incoming sub packet
  946. LGS::FS_DATA_EX InFsData;
  947. LGS::GetFSSubPacket( pBuffer, &InFsData );
  948. switch( InFsData.nCommand )
  949. {
  950. case LGS::FS_CMD_SEND_CMD:
  951. // build CMD_GETFILE command
  952. *pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
  953. if( nMode != LGS::MODE_FILESYSTEM )
  954. {
  955. LGS::FS_DATA_EX OutFsData;
  956. OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
  957. OutFsData.sendevt.nError = LGS::FS_ERROR_MODE;
  958. OutFsData.sendevt.nOrder = InFsData.sendcmd.nOrder;
  959. nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
  960. }
  961. else
  962. {
  963. // perform action
  964. memcpy( ((PBYTE)&m_FileSystemPacket) + InFsData.sendcmd.nPosition, InFsData.sendcmd.pSubBuffer, InFsData.sendcmd.nSubSize );
  965. // if last sub packet of packet
  966. if( InFsData.sendcmd.nLast )
  967. {
  968. LG_FS_PACKET_EX PacketEx;
  969. memcpy( &PacketEx, &m_FileSystemPacket, sizeof( m_FileSystemPacket ) );
  970. memset( &m_FileSystemPacket, 0, sizeof( m_FileSystemPacket ) );
  971. CLgFileSystemServer::OnPacket( &PacketEx, &m_FileSystemPacket );
  972. }
  973. // prepare response
  974. LGS::FS_DATA_EX OutFsData;
  975. OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
  976. OutFsData.sendevt.nError = LGS::FS_ERROR_SUCCESS;
  977. OutFsData.sendevt.nOrder = InFsData.sendcmd.nOrder;
  978. nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
  979. }
  980. // write unswer
  981. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  982. break;
  983. case LGS::FS_CMD_RECEIVE_CMD:
  984. // build CMD_GETFILE command
  985. *pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
  986. if( nMode != LGS::MODE_FILESYSTEM )
  987. {
  988. LGS::FS_DATA_EX OutFsData;
  989. OutFsData.nCommand = LGS::FS_CMD_RECEIVE_EVT;
  990. OutFsData.receiveevt.nError = LGS::FS_ERROR_MODE;
  991. OutFsData.receiveevt.nOrder = InFsData.receivecmd.nOrder;
  992. nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
  993. }
  994. else
  995. {
  996. // prepare sub packet
  997. LGS::FS_DATA_EX OutFsData;
  998. OutFsData.nCommand = LGS::FS_CMD_RECEIVE_EVT;
  999. OutFsData.receiveevt.nError = LGS::FS_ERROR_SUCCESS;
  1000. OutFsData.receiveevt.nOrder = InFsData.receivecmd.nOrder;
  1001. OutFsData.receiveevt.nLast = ( m_FileSystemPacket.nSize - InFsData.receivecmd.nPosition ) <= 30;
  1002. OutFsData.receiveevt.nPosition = InFsData.receivecmd.nPosition;
  1003. OutFsData.receiveevt.nSubSize = OutFsData.receiveevt.nLast ? ( m_FileSystemPacket.nSize - InFsData.receivecmd.nPosition ) : 30;
  1004. memcpy( OutFsData.receiveevt.pSubBuffer, ((PBYTE)&m_FileSystemPacket) + InFsData.receivecmd.nPosition, OutFsData.receiveevt.nSubSize );
  1005. nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
  1006. }
  1007. // write unswer
  1008. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  1009. break;
  1010. default:
  1011. // command is wrong!!!
  1012. *pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
  1013. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  1014. break;
  1015. }
  1016. }
  1017. break;
  1018. #endif
  1019. default:
  1020. *pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
  1021. m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
  1022. break;
  1023. }
  1024. }
  1025. }
  1026. }
  1027. }
  1028. #ifdef COMPILE_AS_GETFILE
  1029. bRestart;
  1030. return FALSE;
  1031. #else
  1032. return bRestart;
  1033. #endif
  1034. }
  1035. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  1036. BOOL CKernel::DoSendBoardData( INT nDevice )
  1037. {
  1038. if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
  1039. return FALSE;
  1040. DWORD nBoardIrq = 0;
  1041. DWORD nBoardTimer = TIMER();
  1042. BOOL bPower, bZero, bSun[2];
  1043. INT nRange[2];
  1044. BYTE pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
  1045. CLgBitCode Encoder( pData );
  1046. INT nPart = 0;
  1047. nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
  1048. while( m_bRun )
  1049. {
  1050. #ifdef WATCHDOG_ENABLED
  1051. // update watchdog timer
  1052. m_WatchDog.Update( TIMER() );
  1053. #endif
  1054. // check timer
  1055. if( ( (TIMER()) - nBoardTimer ) > 18UL )
  1056. {
  1057. if( !nBoardIrq )
  1058. {
  1059. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1060. printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
  1061. #endif
  1062. // reset board
  1063. m_pBoard->Reset();
  1064. }
  1065. nBoardTimer = TIMER();
  1066. nBoardIrq = 0;
  1067. }
  1068. // get new data
  1069. if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
  1070. {
  1071. // increase IRQ counter
  1072. nBoardIrq++;
  1073. // add next 13 bits of data
  1074. DWORD dwData = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
  1075. if( Encoder.Encode24( dwData, 13 ) )
  1076. {
  1077. // increase part number
  1078. nPart++;
  1079. // if numbe rof partes exeed max partes
  1080. if( nPart >= LGS_MAX_SEND_BOARDDATA_PART )
  1081. {
  1082. // prepare check sum in 14th byte of packet
  1083. BYTE bCheckSum = 0;
  1084. for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
  1085. bCheckSum += pData[i];
  1086. pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
  1087. // write into stream
  1088. m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
  1089. // reset part
  1090. nPart = 0;
  1091. // zero memory
  1092. memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
  1093. }
  1094. // restart encoder
  1095. Encoder.SetBuffer( pData + ( nPart * 13 ) );
  1096. }
  1097. }
  1098. #ifdef COMM_WITHOUT_INTERRUPTS
  1099. m_pComm485->Invalidate();
  1100. m_pCameraComm->Invalidate();
  1101. #endif
  1102. }
  1103. return TRUE;
  1104. }
  1105. #endif
  1106. /////////////////////// FILE SYSTEM REQUESTS HANDLERS //////////////////////////
  1107. #ifndef LGS_DISABLE_FILE_SYSTEM
  1108. struct ffblk g_ffBlock;
  1109. LG_FS_RESULT CKernel::DoFindFirst( PDWORD pHandle, PLG_FS_PATH pPath, PLG_FS_FIND_DATA pFindData )
  1110. {
  1111. // add termination 0
  1112. TCHAR pPathWithNull[MAX_PATH];
  1113. memcpy( pPathWithNull, pPath->pBuffer, pPath->nSize );
  1114. pPathWithNull[ pPath->nSize ] = 0;
  1115. // open find first
  1116. if( findfirst( pPathWithNull, &g_ffBlock, FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_DIREC | FA_ARCH ) == 0 )
  1117. {
  1118. g_ffBlock.ff_attrib;
  1119. pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
  1120. ( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
  1121. ( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
  1122. ( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
  1123. ( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
  1124. pFindData->dwFileSizeHigh = 0;
  1125. pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
  1126. pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
  1127. memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
  1128. *pHandle = 0;
  1129. return LG_FS_RESULT_SUCCESS;
  1130. }
  1131. *pHandle = LG_FS_INVALID_HANDLE;
  1132. return LG_FS_RESULT_ERROR_NO_MORE_FILES;
  1133. }
  1134. LG_FS_RESULT CKernel::DoFindNext( DWORD dwHandle, PLG_FS_FIND_DATA pFindData )
  1135. {
  1136. dwHandle;
  1137. // open find first
  1138. if( findnext( &g_ffBlock ) == 0 )
  1139. {
  1140. pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
  1141. ( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
  1142. ( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
  1143. ( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
  1144. ( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
  1145. pFindData->dwFileSizeHigh = 0;
  1146. pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
  1147. pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
  1148. memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
  1149. return LG_FS_RESULT_SUCCESS;
  1150. }
  1151. return LG_FS_RESULT_ERROR_NO_MORE_FILES;
  1152. }
  1153. LG_FS_RESULT CKernel::DoFindClose( DWORD dwHandle )
  1154. {
  1155. dwHandle;
  1156. return LG_FS_RESULT_SUCCESS;
  1157. }
  1158. #endif
  1159. extern BOOL g_bShowErrors;
  1160. extern BOOL g_bHideFogError;
  1161. extern BOOL g_bDelayErrors;
  1162. void CKernel::OnCmdState2( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount, BYTE& nMode, BOOL& bBoardNoIrq )
  1163. {
  1164. // build CMD_STATE_2 command
  1165. *pSendBufferPtr++ = LGS::CMD_STATE_2;
  1166. // if mode is wrong
  1167. if( nMode != LGS::MODE_DETECTOR )
  1168. {
  1169. // build reply
  1170. nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, LGS::S2_ITF_ERROR_MODE );
  1171. return;
  1172. }
  1173. BYTE bRequestType = LGS::S2_RT_TARGET_POLAR;
  1174. if( nReadCount )
  1175. nReadCount -= LGS::GetCmdState2( pReadBufferPtr, &bRequestType );
  1176. // flags
  1177. BYTE bFlags = 0;
  1178. if (! m_dwTimeErrorDelay_EA ) m_dwTimeErrorDelay_EA = TIMER();
  1179. // check for ANGLE and ZERO MARK errors
  1180. if( g_bShowErrors && m_Detector[0].GetLastErrorAngle() )
  1181. {
  1182. INT nErrorAngle = m_Detector[0].GetLastErrorAngleValue();
  1183. if ( TIMER() - m_dwTimeErrorDelay_EA < 200UL || !g_bDelayErrors ) {
  1184. if( nErrorAngle == -1 )
  1185. bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
  1186. else
  1187. nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
  1188. m_dwTimeErrorDelay_EA = TIMER();
  1189. } else {
  1190. m_dwTimeErrorDelay_EA = TIMER();
  1191. };
  1192. }
  1193. if (! m_dwTimeErrorDelay_IQ ) m_dwTimeErrorDelay_IQ = TIMER();
  1194. // check for NO IRQ
  1195. if( g_bShowErrors && bBoardNoIrq )
  1196. {
  1197. if ( TIMER() - m_dwTimeErrorDelay_IQ < 200UL || !g_bDelayErrors ) {
  1198. bFlags |= LGS::S2_ITF_ERROR_NO_IRQ;
  1199. m_dwTimeErrorDelay_IQ = TIMER();
  1200. } else {
  1201. m_dwTimeErrorDelay_IQ = TIMER();
  1202. };
  1203. // clear no irq flag
  1204. bBoardNoIrq = FALSE;
  1205. }
  1206. // check for POWER changes
  1207. if( g_bShowErrors )
  1208. m_Voltage.OnProtocolLgsState2Command( bFlags );
  1209. #ifndef EMBEDDED_CAMERA_DISABLE
  1210. // add camera flags
  1211. m_pCamera->OnProtocolLgsState2Command( bFlags );
  1212. #endif
  1213. // apply flags
  1214. if( bFlags ) {
  1215. nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, bFlags );
  1216. }
  1217. for( int i = 0; i < 2; i++ )
  1218. {
  1219. CDetector *pDetector = m_Detector + i;
  1220. #ifdef LGS_MIRROR
  1221. CTracker *pTracker = m_Tracker + 0;
  1222. #else
  1223. CTracker *pTracker = m_Tracker + i;
  1224. #endif
  1225. // assume that no errors
  1226. BYTE bDeviceFlags = 0;
  1227. // check for tracker overflow
  1228. if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
  1229. {
  1230. m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  1231. bDeviceFlags |= LGS::S2_ITDF_ERROR_OVERFLOW;
  1232. }
  1233. // check for tracker scan to scan overflow
  1234. if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
  1235. {
  1236. m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  1237. bDeviceFlags |= LGS::S2_ITDF_ERROR_SST_OVERFLOW;
  1238. }
  1239. // check for detector sun errors
  1240. if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
  1241. {
  1242. m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
  1243. bDeviceFlags |= LGS::S2_ITDF_ERROR_SUN;
  1244. }
  1245. // apply device flags
  1246. if( g_bShowErrors && bDeviceFlags )
  1247. nSendCount += LGS::BuildEvtState2DeviceFlags( pSendBufferPtr, i, bDeviceFlags );
  1248. // place target information
  1249. CTracker::TARGET target;
  1250. while( pTracker->GetTarget( &target ) )
  1251. {
  1252. BYTE bType;
  1253. switch( target.bType )
  1254. {
  1255. case LGS::TT_WIDE:
  1256. case LGS::TT_NORMAL:
  1257. bType = ( target.bType == LGS::TT_NORMAL ) ? LGS::S2_ITT_NORMAL : LGS::S2_ITT_WIDE;
  1258. if( ( bRequestType & LGS::S2_RT_TARGET_MASK ) == LGS::S2_RT_TARGET_DEKART )
  1259. {
  1260. #ifdef LGS_MIRROR
  1261. const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
  1262. double a = ( target.nAngle << 1 ) * a2r;
  1263. #else
  1264. const double a2r = asin(1.0) * 4.0 / LGS_MAX_DETECTOR_ANGLES;
  1265. double a = target.nAngle * a2r;
  1266. #endif
  1267. INT x = target.nRange * cos( a );
  1268. INT y = target.nRange * sin( a );
  1269. #ifdef LGS_MIRROR
  1270. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  1271. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth ) :
  1272. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  1273. #else
  1274. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  1275. LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth << 1 ) :
  1276. LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
  1277. #endif
  1278. }
  1279. else
  1280. #ifdef LGS_MIRROR
  1281. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  1282. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange, target.nWidth << 1 ) :
  1283. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange );
  1284. #else
  1285. nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
  1286. LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
  1287. LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
  1288. #endif
  1289. break;
  1290. case LGS::TT_FLIP:
  1291. nSendCount += LGS::BuildEvtState2Flip( pSendBufferPtr, i, target.nAngle );
  1292. break;
  1293. case LGS::TT_BLIND:
  1294. if( !g_bShowErrors || g_bHideFogError )
  1295. break;
  1296. switch( target.nAngle )
  1297. {
  1298. case LGS_BLIND_TYPE_MR_ENTER:
  1299. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_MEDIUM_RANGE );
  1300. break;
  1301. case LGS_BLIND_TYPE_MR_EXIT:
  1302. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_MEDIUM_RANGE );
  1303. break;
  1304. case LGS_BLIND_TYPE_180_DEGRESE_ENTER:
  1305. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_180_DEGREE );
  1306. break;
  1307. case LGS_BLIND_TYPE_180_DEGRESE_EXIT:
  1308. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_180_DEGREE );
  1309. break;
  1310. case LGS_BLIND_TYPE_FS_ENTER:
  1311. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FOG_SPIKES );
  1312. break;
  1313. case LGS_BLIND_TYPE_FS_EXIT:
  1314. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FOG_SPIKES );
  1315. break;
  1316. case LGS_BLIND_TYPE_PD_ENTER:
  1317. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_PD );
  1318. break;
  1319. case LGS_BLIND_TYPE_PD_EXIT:
  1320. nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_PD );
  1321. break;
  1322. }
  1323. break;
  1324. // case LGS::TT_CAMERA:
  1325. // break;
  1326. // case LGS::TT_TEST:
  1327. // break;
  1328. }
  1329. if( nSendCount >= 20 )
  1330. break;
  1331. }
  1332. if( nSendCount >= 20 )
  1333. break;
  1334. }
  1335. }
  1336. void CKernel::OnCmdGetWidthTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1337. {
  1338. // unused variables
  1339. pReadBufferPtr; nReadCount;
  1340. // build CMD_GET_WIDHT_TABLE command
  1341. *pSendBufferPtr++ = LGS::CMD_GET_WIDTH_TABLE;
  1342. PLONG pNativeTable = m_Detector[0].GetFilterWidth()->GetTable();
  1343. // prepare table
  1344. LGS::WIDTH_TABLE table;
  1345. table.nCount = LGS::WIDTH_TABLE_SIZE;
  1346. for( INT i = 0; i < LGS::WIDTH_TABLE_SIZE; i++ )
  1347. table.pTable[i] = ( pNativeTable[i] * 100L ) >> 7;
  1348. // write command
  1349. nSendCount += LGS::BuildEvtGetWidthTable( pSendBufferPtr, &table );
  1350. }
  1351. void CKernel::OnCmdSetWidthTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1352. {
  1353. // build CMD_SET_WIDHT_TABLE command
  1354. *pSendBufferPtr++ = LGS::CMD_SET_WIDTH_TABLE;
  1355. // read table
  1356. LGS::WIDTH_TABLE table;
  1357. nReadCount -= LGS::GetCmdSetWidthTable( pReadBufferPtr, &table );
  1358. FILE *pFile = fopen( "width.ini", "wt" );
  1359. if( pFile )
  1360. {
  1361. for( INT i = 0; i < table.nCount; i++ )
  1362. fprintf( pFile, "%d ", table.pTable[i] );
  1363. fclose( pFile );
  1364. }
  1365. // write command
  1366. nSendCount += LGS::BuildEvtSetWidthTable( pSendBufferPtr, &table );
  1367. // restart program
  1368. m_bRun = FALSE;
  1369. }
  1370. void CKernel::OnCmdGetZoomTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1371. {
  1372. // unused variables
  1373. pReadBufferPtr; nReadCount;
  1374. // build CMD_GET_WIDHT_TABLE command
  1375. *pSendBufferPtr++ = LGS::CMD_GET_ZOOM_TABLE;
  1376. // write command
  1377. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  1378. }
  1379. void CKernel::OnCmdSetZoomTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1380. {
  1381. // build CMD_SET_WIDHT_TABLE command
  1382. *pSendBufferPtr++ = LGS::CMD_SET_ZOOM_TABLE;
  1383. // read table
  1384. nReadCount -= LGS::GetZoomTable( pReadBufferPtr, &m_pCamera->GetZoomTable() );
  1385. // write command
  1386. nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
  1387. }
  1388. void CKernel::OnCmdGetTiltTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1389. {
  1390. // unused variables
  1391. pReadBufferPtr; nReadCount;
  1392. // build CMD_GET_WIDHT_TABLE command
  1393. *pSendBufferPtr++ = LGS::CMD_GET_TILT_TABLE;
  1394. // write command
  1395. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  1396. }
  1397. void CKernel::OnCmdSetTiltTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1398. {
  1399. // build CMD_SET_WIDHT_TABLE command
  1400. *pSendBufferPtr++ = LGS::CMD_SET_TILT_TABLE;
  1401. // read table
  1402. nReadCount -= LGS::GetTiltTable( pReadBufferPtr, &m_pCamera->GetTiltTable() );
  1403. // write command
  1404. nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
  1405. }
  1406. void CKernel::OnCmdGetCalibrationTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1407. {
  1408. // read table
  1409. BYTE nDevice = *pReadBufferPtr++;
  1410. nReadCount --;
  1411. // build CMD_GET_LINEARIZATION_TABLE command
  1412. *pSendBufferPtr++ = LGS::CMD_GET_CALIBRATION_TABLE;
  1413. *pSendBufferPtr++ = nDevice;
  1414. nSendCount++;
  1415. // process command
  1416. m_Calibrator[nDevice?1:0].OnCmdGetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  1417. }
  1418. BOOL CKernel::OnCmdSetCalibrationTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount, INT& nDevice )
  1419. {
  1420. // read table
  1421. nDevice = *pReadBufferPtr++;
  1422. nReadCount --;
  1423. // build CMD_SET_LINEARIZATION_TABLE command
  1424. *pSendBufferPtr++ = LGS::CMD_SET_CALIBRATION_TABLE;
  1425. *pSendBufferPtr++ = nDevice;
  1426. nSendCount++;
  1427. // process command
  1428. return m_Calibrator[nDevice?1:0].OnCmdSetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
  1429. }
  1430. void CKernel::OnCmdGetLrfDisable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1431. {
  1432. // unused variables
  1433. pReadBufferPtr; nReadCount;
  1434. // build CMD_GET_LRF_DISABLE command
  1435. *pSendBufferPtr++ = LGS::CMD_GET_LRF_DISABLE;
  1436. // write command
  1437. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  1438. }
  1439. void CKernel::OnCmdSetLrfDisable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  1440. {
  1441. // read table
  1442. nReadCount -= LGS::GetLRFDisable( pReadBufferPtr, &m_LRFDisable );
  1443. // store serial number
  1444. SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
  1445. // build CMD_SET_LRF_DISABLE command
  1446. *pSendBufferPtr++ = LGS::CMD_SET_LRF_DISABLE;
  1447. // write command
  1448. nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
  1449. // restart program
  1450. m_bRun = FALSE;
  1451. }
  1452. typedef enum SETTING_TYPE
  1453. {
  1454. ST_NONE = -1,
  1455. ST_SN = 0,
  1456. ST_ADDRESS,
  1457. ST_CAMERA_TYPE,
  1458. ST_CAMERA_SHIFT,
  1459. ST_CAMERA_AUTO,
  1460. ST_CAMERA_DELAY,
  1461. ST_RELAY_NC,
  1462. ST_RELAY_AUTO,
  1463. ST_RELAY_DELAY,
  1464. ST_VOLTAGE_CONTROL,
  1465. ST_MASTER_DISABLED,
  1466. ST_SLAVE_DISABLED,
  1467. ST_AUTORESET_ENABLE,
  1468. ST_AUTORESET_INTERLEAVE,
  1469. ST_AUTORESET_TIMEOUT,
  1470. ST_BOARD_TEMPERATURE,
  1471. ST_BOARD_ZEROSHIFT,
  1472. ST_BOARD_ENCODERSTEPS,
  1473. ST_BOARD_GEARRATIO,
  1474. ST_BOARD_MAXRANGE,
  1475. ST_SWITCHER_TABLE,
  1476. ST_SWITCHER_REPLY_TIMEOUT,
  1477. ST_SWITCHER_COMMAND_TIMEOUT,
  1478. ST_SWITCHER_AUTO_MODE,
  1479. ST_SWITCHER_AUTO_ENTER_TIMEOUT,
  1480. ST_SWITCHER_AUTO_SWITCH_TIMEOUT,
  1481. }SETTING_TYPE;
  1482. LPCTSTR m_pSetting[] =
  1483. {
  1484. { "SN" },
  1485. { "ADDRESS" },
  1486. { "CAMERA_TYPE" },
  1487. { "CAMERA_SHIFT" },
  1488. { "CAMERA_AUTO" },
  1489. { "CAMERA_DELAY" },
  1490. { "RELAY_NC" },
  1491. { "RELAY_AUTO" },
  1492. { "RELAY_DELAY" },
  1493. { "VOLTAGE_CONTROL" },
  1494. { "MASTER_DISABLED" },
  1495. { "SLAVE_DISABLED" },
  1496. { "AUTORESET_ENABLE" },
  1497. { "AUTORESET_INTERLEAVE" },
  1498. { "AUTORESET_TIMEOUT" },
  1499. { "BOARD_TEMPERATURE" },
  1500. { "BOARD_ZEROSHIFT" },
  1501. { "BOARD_ENCODERSTEPS" },
  1502. { "BOARD_GEARRATIO" },
  1503. { "BOARD_MAXRANGE" },
  1504. { "SWITCHER_TABLE" },
  1505. { "SWITCHER_REPLY_TIMEOUT" },
  1506. { "SWITCHER_COMMAND_TIMEOUT" },
  1507. { "SWITCHER_AUTO_MODE" },
  1508. { "SWITCHER_AUTO_ENTER_TIMEOUT" },
  1509. { "SWITCHER_AUTO_SWITCH_TIMEOUT" }
  1510. };
  1511. BOOL CKernel::LoadSettings( LPTSTR pSerialNumber, PBYTE pSerialNumberSize, PBYTE pAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable )
  1512. {
  1513. // read serial number
  1514. FILE *pFile = fopen( "SN.INI", "rt" );
  1515. if( !pFile )
  1516. {
  1517. // fill with default sn
  1518. *pSerialNumberSize = 14;
  1519. memcpy( pSerialNumber, "NOSERIALNUMBER", *pSerialNumberSize );
  1520. return FALSE;
  1521. }
  1522. CHAR pLine[MAX_PATH];
  1523. while( fgets( pLine, MAX_PATH, pFile ) )
  1524. {
  1525. SETTING_TYPE eType = ST_NONE;
  1526. PCHAR pTemp = NULL;
  1527. for( INT i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  1528. {
  1529. pTemp = strstr( pLine, m_pSetting[i] );
  1530. if( pTemp )
  1531. {
  1532. eType = (SETTING_TYPE)i;
  1533. pTemp = strstr( pTemp, "=" );
  1534. if( pTemp )
  1535. pTemp = strtok( pTemp + 1, " \t\n\r" );
  1536. break;
  1537. }
  1538. }
  1539. if( eType == ST_NONE || !pTemp )
  1540. continue;
  1541. switch( eType )
  1542. {
  1543. case ST_SN: *pSerialNumberSize = strlen( pTemp ); memcpy( pSerialNumber, pTemp, *pSerialNumberSize ); break;
  1544. case ST_ADDRESS: *pAddress = atoi( pTemp ); break;
  1545. case ST_CAMERA_TYPE: pCameraParameters->eType = (LGS::E_CAMERA_TYPE)atoi( pTemp ); break;
  1546. case ST_CAMERA_SHIFT: pCameraParameters->nShift = (WORD)atoi( pTemp ); break;
  1547. case ST_CAMERA_AUTO: pCameraParameters->bAuto = (BOOL)atoi( pTemp ); break;
  1548. case ST_CAMERA_DELAY: pCameraParameters->nAutoDelay = (WORD)atoi( pTemp ); break;
  1549. case ST_RELAY_NC: pRelayParameters->bNormallyClose = (WORD)atoi( pTemp ); break;
  1550. case ST_RELAY_AUTO: pRelayParameters->bAuto = (BOOL)atoi( pTemp ); break;
  1551. case ST_RELAY_DELAY: pRelayParameters->nAutoDelay = (WORD)atoi( pTemp ); break;
  1552. case ST_VOLTAGE_CONTROL: pVoltageParameters->bControl = (BOOL)atoi( pTemp ); break;
  1553. case ST_MASTER_DISABLED: pLRFDisable->bMaster = (BOOL)atoi( pTemp ); break;
  1554. case ST_SLAVE_DISABLED: pLRFDisable->bSlave = (BOOL)atoi( pTemp ); break;
  1555. }
  1556. }
  1557. fclose( pFile );
  1558. return TRUE;
  1559. }
  1560. BOOL CKernel::SaveSettings( LPCTSTR pSerialNumber, INT nAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable )
  1561. {
  1562. FILE *pFile = fopen( "SN.INI", "wt" );
  1563. if( !pFile )
  1564. return FALSE;
  1565. LPCTSTR pFormatStr = "%s = %s\n";
  1566. LPCTSTR pFormatInt = "%s = %d\n";
  1567. fprintf( pFile, pFormatStr, m_pSetting[ST_SN], pSerialNumber );
  1568. fprintf( pFile, pFormatInt, m_pSetting[ST_ADDRESS], nAddress );
  1569. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_TYPE], pCameraParameters->eType );
  1570. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_SHIFT], pCameraParameters->nShift );
  1571. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_AUTO], pCameraParameters->bAuto );
  1572. fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_DELAY], pCameraParameters->nAutoDelay );
  1573. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_AUTO], pRelayParameters->bAuto );
  1574. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_DELAY], pRelayParameters->nAutoDelay );
  1575. fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_NC], pRelayParameters->bNormallyClose );
  1576. fprintf( pFile, pFormatInt, m_pSetting[ST_VOLTAGE_CONTROL], pVoltageParameters->bControl );
  1577. fprintf( pFile, pFormatInt, m_pSetting[ST_MASTER_DISABLED], pLRFDisable->bMaster );
  1578. fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], pLRFDisable->bSlave );
  1579. fclose( pFile );
  1580. return TRUE;
  1581. }
  1582. BOOL CKernel::LoadUserSettings( AUTO_RESET *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher )
  1583. {
  1584. pSwitcher->pTable[0] = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4;
  1585. pSwitcher->pTable[1] = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4;
  1586. pSwitcher->pTable[2] = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4;
  1587. pSwitcher->nReplyTimeout = 100L;
  1588. pSwitcher->nCommandTimeout = 500L;
  1589. pSwitcher->nAutoMode = 0;
  1590. pSwitcher->nAutoEnterTimeout = 60;
  1591. pSwitcher->nAutoSwitchTimeout = 3;
  1592. pAutoReset->bEnabled = FALSE;
  1593. pAutoReset->dwInterleave = 2000UL;
  1594. pAutoReset->dwTimeout = 60000UL;
  1595. pBoard->nZeroShift = 0;
  1596. pBoard->nTemperature = 20;
  1597. pBoard->nEncoderSteps = 6;
  1598. pBoard->nGearRatio = 61;
  1599. // pBoard->nMaxRange = 2048;
  1600. // read serial number
  1601. FILE *pFile = fopen( "USER.INI", "rt" );
  1602. if( !pFile )
  1603. return FALSE;
  1604. CHAR pLine[MAX_PATH];
  1605. while( fgets( pLine, MAX_PATH, pFile ) )
  1606. {
  1607. SETTING_TYPE eType = ST_NONE;
  1608. PCHAR pTemp = NULL;
  1609. for( INT i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
  1610. {
  1611. pTemp = strstr( pLine, m_pSetting[i] );
  1612. if( pTemp )
  1613. {
  1614. eType = (SETTING_TYPE)i;
  1615. pTemp = strstr( pTemp, "=" );
  1616. if( pTemp )
  1617. pTemp = strtok( pTemp + 1, " \t\n\r" );
  1618. break;
  1619. }
  1620. }
  1621. if( eType == ST_NONE || !pTemp )
  1622. continue;
  1623. switch( eType )
  1624. {
  1625. case ST_AUTORESET_ENABLE: pAutoReset->bEnabled = (BOOL)atoi( pTemp ); break;
  1626. case ST_AUTORESET_INTERLEAVE: pAutoReset->dwInterleave = atol( pTemp ); break;
  1627. case ST_AUTORESET_TIMEOUT: pAutoReset->dwTimeout = atol( pTemp ); break;
  1628. case ST_BOARD_TEMPERATURE: pBoard->nTemperature = atoi( pTemp ); break;
  1629. case ST_BOARD_ZEROSHIFT: pBoard->nZeroShift = atoi( pTemp ); break;
  1630. case ST_BOARD_ENCODERSTEPS: pBoard->nEncoderSteps = atoi( pTemp ); break;
  1631. case ST_BOARD_GEARRATIO: pBoard->nGearRatio = atoi( pTemp ); break;
  1632. // case ST_BOARD_MAXRANGE: pBoard->nMaxRange = atoi( pTemp ); break;
  1633. case ST_SWITCHER_TABLE: sscanf( pTemp, "%d,%d,%d", pSwitcher->pTable + 0, pSwitcher->pTable + 1, pSwitcher->pTable + 2 );
  1634. case ST_SWITCHER_REPLY_TIMEOUT: pSwitcher->nReplyTimeout = atol( pTemp ); break;
  1635. case ST_SWITCHER_COMMAND_TIMEOUT: pSwitcher->nCommandTimeout = atol( pTemp ); break;
  1636. case ST_SWITCHER_AUTO_MODE: pSwitcher->nAutoMode = atoi( pTemp ); break;
  1637. case ST_SWITCHER_AUTO_ENTER_TIMEOUT: pSwitcher->nAutoEnterTimeout = atoi( pTemp ); break;
  1638. case ST_SWITCHER_AUTO_SWITCH_TIMEOUT: pSwitcher->nAutoSwitchTimeout = atoi( pTemp ); break;
  1639. }
  1640. }
  1641. fclose( pFile );
  1642. return TRUE;
  1643. }
  1644. BOOL CKernel::SaveUserSettings( AUTO_RESET *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher )
  1645. {
  1646. FILE *pFile = fopen( "USER.INI", "wt" );
  1647. if( !pFile )
  1648. return FALSE;
  1649. LPCTSTR pFormatInt = "%s=%d\n";
  1650. LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
  1651. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (INT)pAutoReset->bEnabled );
  1652. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_INTERLEAVE], (INT)pAutoReset->dwInterleave );
  1653. fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_TIMEOUT], (INT)pAutoReset->dwTimeout );
  1654. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (INT)(CHAR)pBoard->nTemperature );
  1655. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (INT)pBoard->nZeroShift );
  1656. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (INT)pBoard->nEncoderSteps );
  1657. fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (INT)pBoard->nGearRatio );
  1658. fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
  1659. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
  1660. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
  1661. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
  1662. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
  1663. fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
  1664. fclose( pFile );
  1665. return TRUE;
  1666. }