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.

748 lines
20 KiB

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: BoardReceiverDoc.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of BoardReceiverDoc.cpp
  13. //----------------------------------------------------------------------------
  14. // BoardReceiverDoc.cpp : implementation of the CBoardReceiverDoc class
  15. //
  16. #include "stdafx.h"
  17. #include "BoardReceiver.h"
  18. #include "MainFrm.h"
  19. #include "BoardReceiverDoc.h"
  20. #include "BoardReceiverDlg.h"
  21. #include "BoardReceiverView.h"
  22. #include "BoardReceiverList.h"
  23. #include "BoardReceiverParamDlg.h"
  24. #include "BoardReceiverVariableList.h"
  25. #include "BoardReceiverSeekDlg.h"
  26. /*
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. */
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CBoardReceiverDoc
  35. IMPLEMENT_DYNCREATE(CBoardReceiverDoc, CDocument)
  36. BEGIN_MESSAGE_MAP(CBoardReceiverDoc, CDocument)
  37. //{{AFX_MSG_MAP(CBoardReceiverDoc)
  38. ON_COMMAND(ID_OPTIONS_RESET, OnOptionsReset)
  39. ON_COMMAND(ID_OPTIONS_STEP, OnOptionsStep)
  40. ON_UPDATE_COMMAND_UI(ID_OPTIONS_STEP, OnUpdateOptionsStep)
  41. ON_COMMAND(ID_OPTIONS_PARAMETERS, OnOptionsParameters)
  42. ON_COMMAND(ID_OPTIONS_SEEK, OnOptionsSeek)
  43. ON_COMMAND(ID_OPTIONS_SOFTRESET, OnOptionsSoftreset)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CBoardReceiverDoc construction/destruction
  48. CBoardReceiverDoc::CBoardReceiverDoc()
  49. {
  50. m_bLgsMode = FALSE;
  51. m_liReadPos.QuadPart = 0;
  52. m_bFastProcessing = FALSE;
  53. m_pChannelName[0] = 0;
  54. m_nChannelID = -1;
  55. m_nLastAngles = 0;
  56. }
  57. CBoardReceiverDoc::~CBoardReceiverDoc()
  58. {
  59. // ((CBoardReceiverApp*)AfxGetApp())->UnregisterDocument( this );
  60. }
  61. static INT gChannelID = 0;
  62. BOOL CBoardReceiverDoc::OnNewDocument()
  63. {
  64. if (!CDocument::OnNewDocument())
  65. return FALSE;
  66. CBoardReceiverDlg dlg;
  67. if( dlg.DoModal() != IDOK )
  68. return FALSE;
  69. if( !m_Kernel.Create() )
  70. {
  71. AfxMessageBox( "Can't create Kernel", MB_OK );
  72. return FALSE;
  73. }
  74. m_strFileName = dlg.GetFileName();
  75. SetPathName( m_strFileName, FALSE );
  76. CBoardReceiverSwitcher *bs = new CBoardReceiverSwitcher;
  77. if( !bs->Switch( dlg.GetDevice(), dlg.GetPort() ) )
  78. {
  79. AfxMessageBox( "Can't open port for switch lgs mode", MB_OK );
  80. return FALSE;
  81. }
  82. for( INT nShadow = 0; nShadow < LGS_MAX_SHADOW_ANGLES; nShadow++ )
  83. {
  84. // range should be in the same system ( 0..2047 )
  85. CShadow::LPRAY_LINE pShadowLine = &m_Kernel.m_Shadow.m_pShadowLine[ (INT)nShadow ];
  86. CShadow::LPRAY pShadow = pShadowLine->lpShadow;
  87. for( INT i = 0; i < pShadowLine->nCount; i++, pShadow++ )
  88. {
  89. POINT p1 = { nShadow * LGS_MAX_DETECTOR_ANGLES / LGS_MAX_SHADOW_ANGLES, pShadow->nMin };
  90. POINT p2 = { (nShadow + 1 ) * LGS_MAX_DETECTOR_ANGLES / LGS_MAX_SHADOW_ANGLES, pShadow->nMax };
  91. AddHiddenZone( p1, p2 );
  92. }
  93. }
  94. if( !m_Connection.Create( dlg.GetPort(), 115200, 8, NOPARITY, ONESTOPBIT, 4096, 4096 ) )
  95. {
  96. AfxMessageBox( "Can't open port", MB_OK );
  97. return FALSE;
  98. }
  99. // store properties and place into server
  100. strcpy( m_pChannelName, m_strFileName );
  101. m_nChannelID = gChannelID++;
  102. // ((CBoardReceiverApp*)AfxGetApp())->RegisterDocument( this );
  103. m_bLgsMode = TRUE;
  104. return CLgThread::Start( FALSE );
  105. }
  106. BOOL CBoardReceiverDoc::OnOpenDocument(LPCTSTR lpszPathName)
  107. {
  108. if (!CDocument::OnOpenDocument(lpszPathName))
  109. return FALSE;
  110. m_strFileName = lpszPathName;
  111. m_bLgsMode = FALSE;
  112. if( !m_Kernel.Create() )
  113. {
  114. AfxMessageBox( "Can't create Kernel", MB_OK );
  115. return FALSE;
  116. }
  117. m_liReadPos.QuadPart = 0;
  118. OnOptionsStep();
  119. // store properties and place into server
  120. strcpy( m_pChannelName, m_strFileName );
  121. m_nChannelID = gChannelID++;
  122. // ((CBoardReceiverApp*)AfxGetApp())->RegisterDocument( this );
  123. return TRUE;
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CBoardReceiverDoc serialization
  127. void CBoardReceiverDoc::Serialize(CArchive& ar)
  128. {
  129. if (ar.IsStoring())
  130. {
  131. // TODO: add storing code here
  132. }
  133. else
  134. {
  135. // TODO: add loading code here
  136. }
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CBoardReceiverDoc diagnostics
  140. #ifdef _DEBUG
  141. void CBoardReceiverDoc::AssertValid() const
  142. {
  143. CDocument::AssertValid();
  144. }
  145. void CBoardReceiverDoc::Dump(CDumpContext& dc) const
  146. {
  147. CDocument::Dump(dc);
  148. }
  149. #endif //_DEBUG
  150. #define PACKET_SIZE (13*LGS_MAX_SEND_BOARDDATA_PART+1)
  151. #define READ_BUFFER_SIZE (PACKET_SIZE * 10)
  152. DWORD CBoardReceiverDoc::ThreadProc()
  153. {
  154. __try
  155. {
  156. // current angle
  157. int nAngle = 0;
  158. // buffer for receiveing data
  159. BYTE pReadBuffer[ READ_BUFFER_SIZE * 3 ];
  160. INT nCount = 0;
  161. BOARDDATAARRAY BoardDataArray;
  162. // until stop condition
  163. while( !CLgThread::IsStopping() )
  164. {
  165. // read from serial port
  166. __try
  167. {
  168. nCount += m_Connection.Read( pReadBuffer + nCount, READ_BUFFER_SIZE - nCount, 100UL );
  169. }
  170. __except( EXCEPTION_EXECUTE_HANDLER )
  171. {
  172. MessageBox( NULL, "","", 0 );
  173. }
  174. PBYTE pBuffer = pReadBuffer;
  175. // parse buffer
  176. while( nCount >= PACKET_SIZE )
  177. {
  178. // prepare ckecksum
  179. BYTE sum = 0;
  180. for( int i = 0; i < PACKET_SIZE-1; i++ )
  181. sum += pBuffer[i];
  182. // if check sum correct
  183. if( sum == pBuffer[PACKET_SIZE-1] )
  184. {
  185. m_Decoder.SetBuffer( pBuffer );
  186. BOOL bFront = TRUE;
  187. for( i = 0; i < LGS_MAX_SEND_BOARDDATA_PART; i++ )
  188. {
  189. BOOL bNextPart = FALSE;
  190. while( !bNextPart )
  191. {
  192. DWORD dwData;
  193. bNextPart = m_Decoder.Decode24( &dwData, 13 );
  194. BOOL bZero = dwData & (1 << 12);
  195. BOOL bSun = dwData & (1 << 11);
  196. INT nRange = (INT)(dwData & 0x7FF);
  197. if( bZero )
  198. {
  199. if( nAngle != (LGS_MAX_DETECTOR_ANGLES - 1) ) TRACE("Board data ok\n");
  200. else TRACE("Board data incomplete (%d)\n", nAngle );
  201. // __try
  202. {
  203. // __try
  204. {
  205. GetLocalTime( &BoardDataArray.Time );
  206. m_List.Lock();
  207. m_List.Add( BoardDataArray );
  208. m_List.Unlock();
  209. }
  210. // __except(1)
  211. {
  212. // MessageBox( NULL, "sdsd","sdsdds", MB_OK );
  213. }
  214. }
  215. // __except(1)
  216. {
  217. // MessageBox( NULL, "sdsd","sdsdds", MB_OK );
  218. }
  219. m_nLastAngles = nAngle + 1;
  220. nAngle = 0;
  221. }
  222. else nAngle++;
  223. if( nAngle < LGS_MAX_DETECTOR_ANGLES )
  224. {
  225. BoardDataArray.BoardData[nAngle].bSun = bSun ? 1 : 0;
  226. BoardDataArray.BoardData[nAngle].nRange = nRange;
  227. BoardDataArray.BoardData[nAngle].bFront = bFront ? 1 : 0;
  228. }
  229. bFront = FALSE;
  230. }
  231. }
  232. pBuffer += PACKET_SIZE;
  233. nCount -= PACKET_SIZE;
  234. }
  235. else
  236. {
  237. pBuffer ++;
  238. nCount --;
  239. }
  240. }
  241. // copy remainig part into begin of buffer
  242. if( pReadBuffer != pBuffer )
  243. memcpy( pReadBuffer, pBuffer, nCount );
  244. }
  245. }
  246. __except( 1 )
  247. {
  248. MessageBox( NULL, "", "", MB_OK );
  249. }
  250. return 0UL;
  251. }
  252. BOOL CBoardReceiverDoc::Get( PBOARDDATAARRAY pBoardDataArray )
  253. {
  254. if( !pBoardDataArray )
  255. return FALSE;
  256. CLgLocker Lock( &m_List );
  257. if( !m_List.GetCount() )
  258. return FALSE;
  259. *pBoardDataArray = m_List[0];
  260. m_List.Remove(0);
  261. return TRUE;
  262. }
  263. void CBoardReceiverDoc::OnCloseDocument()
  264. {
  265. CLgThread::Stop( TRUE );
  266. m_Connection.Destroy();
  267. CDocument::OnCloseDocument();
  268. }
  269. void CBoardReceiverDoc::OnIdle()
  270. {
  271. if( Get( &m_BoardData ) )
  272. {
  273. if( m_bLgsMode )
  274. {
  275. // write data to file
  276. HANDLE hFile = ::CreateFile( m_strFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL );
  277. if( hFile != INVALID_HANDLE_VALUE )
  278. {
  279. LONG lMoveHigh = 0;
  280. DWORD dwWritten = 0;
  281. ::SetFilePointer( hFile, 0, &lMoveHigh, FILE_END );
  282. ::WriteFile( hFile, &m_BoardData, sizeof(m_BoardData), &dwWritten, NULL );
  283. ::CloseHandle( hFile );
  284. }
  285. }
  286. // actual processing
  287. for( int i = 0; i < LGS_MAX_DETECTOR_ANGLES; i++ )
  288. m_Kernel.Invalidate( i == 0, m_BoardData.BoardData[i].bSun, m_BoardData.BoardData[i].nRange );
  289. // update views
  290. UpdateView();
  291. }
  292. else
  293. {
  294. if( !m_bLgsMode && m_bFastProcessing )
  295. {
  296. if( m_liFastProcessingStopPos.QuadPart > m_liReadPos.QuadPart )
  297. ReadData();
  298. else
  299. {
  300. // stop fastr processing
  301. m_bFastProcessing = FALSE;
  302. // update idle mode
  303. ((CBoardReceiverApp*)AfxGetApp())->SetIdleMode( m_bFastProcessing );
  304. // update views
  305. UpdateView();
  306. }
  307. }
  308. }
  309. CMainFrame *pMainFrame = (CMainFrame*)AfxGetMainWnd();
  310. if( pMainFrame )
  311. {
  312. CString str;
  313. str.Format( _T("%04d"), m_nLastAngles );
  314. pMainFrame->ShowLastAngles( str );
  315. }
  316. }
  317. void CBoardReceiverDoc::UpdateView()
  318. {
  319. LARGE_INTEGER liStep;
  320. liStep.QuadPart = m_liReadPos.QuadPart / sizeof(m_BoardData);
  321. // update all document view representations
  322. POSITION posV = GetFirstViewPosition();
  323. while( posV )
  324. {
  325. CView *pView = GetNextView( posV );
  326. if( pView->IsKindOf( RUNTIME_CLASS(CBoardReceiverView) ) )
  327. {
  328. CBoardReceiverView *pBRV = (CBoardReceiverView*)pView;
  329. if( (!m_bFastProcessing) || (liStep.QuadPart%100==0) )
  330. pBRV->Update( &m_Kernel, m_BoardData.BoardData, m_bLgsMode );
  331. }
  332. else
  333. if( pView->IsKindOf( RUNTIME_CLASS(CBoardReceiverList) ) )
  334. {
  335. CBoardReceiverList *pBRL = (CBoardReceiverList*)pView;
  336. if( m_Kernel.GetTracker()->GetLastErrorOverflow() )
  337. pBRL->Update( _T("OVERFLOW") );
  338. if( m_Kernel.GetTracker()->GetLastErrorOverflowSST() )
  339. pBRL->Update( _T("SST OVERFLOW") );
  340. if( m_Kernel.GetDetector()->GetLastErrorSun() )
  341. pBRL->Update( _T("SUN BIT ERROR") );
  342. CTracker::TARGET target;
  343. while( m_Kernel.GetTracker()->GetTarget( &target ) )
  344. {
  345. pBRL->Update( target.bType, target.nAngle, target.nRange, target.nWidth );
  346. }
  347. }
  348. else
  349. if( pView->IsKindOf( RUNTIME_CLASS(CBoardReceiverVariableList) ) )
  350. {
  351. CBoardReceiverVariableList *pBRVL = (CBoardReceiverVariableList*)pView;
  352. TCHAR pText[1000];
  353. #define INT_VARIABLE( v, d ) _sntprintf( pText, 1000, "%d", v ); pBRVL->SetVariable( d, pText );
  354. #define LARGE_INT_VARIABLE( v, d ) _sntprintf( pText, 1000, "%ld", v ); pBRVL->SetVariable( d, pText );
  355. #define INT_DETECTOR_VARIABLE( v ) INT_VARIABLE( m_Kernel.GetDetector()->v, #v )
  356. // _sntprintf( pText, 100, "%d", m_dwReadPos / sizeof(m_BoardDataArray.BoardData) );
  357. // pBRVL->SetVariable( "STEP", pText );
  358. if( 1 )
  359. {
  360. LARGE_INT_VARIABLE( liStep.QuadPart, "STEP" );
  361. _sntprintf( pText, 1000, "%02d/%02d/%04d %02d:%02d:%02d",
  362. m_BoardData.Time.wDay, m_BoardData.Time.wMonth, m_BoardData.Time.wYear,
  363. m_BoardData.Time.wHour, m_BoardData.Time.wMinute, m_BoardData.Time.wSecond );
  364. pBRVL->SetVariable( "TIME", pText );
  365. }
  366. if( (!m_bFastProcessing) || (liStep.QuadPart%100==0) )
  367. {
  368. // show flip info
  369. INT_DETECTOR_VARIABLE( m_nFlipWaitHistory );
  370. INT_DETECTOR_VARIABLE( m_nFlip );
  371. INT_DETECTOR_VARIABLE( m_nFlipWaitHistory );
  372. INT_DETECTOR_VARIABLE( m_nFloatFlip );
  373. INT_DETECTOR_VARIABLE( m_nFlipCounter );
  374. // INT_DETECTOR_VARIABLE( m_nSpikeWaitLoop );
  375. INT_DETECTOR_VARIABLE( m_nSpikeCount );
  376. INT_DETECTOR_VARIABLE( m_nSpikeTempCount );
  377. // INT_DETECTOR_VARIABLE( m_nSpikeLastLoop );
  378. INT_DETECTOR_VARIABLE( m_nSpikeHistoryPosition );
  379. INT_DETECTOR_VARIABLE( m_nSpikeHistoryCount );
  380. INT_DETECTOR_VARIABLE( m_nSpikeHistoryMax );
  381. // fog spikes
  382. INT_DETECTOR_VARIABLE( m_nSpikeFogCount );
  383. INT_DETECTOR_VARIABLE( m_nSpikeFogTempCount );
  384. // INT_DETECTOR_VARIABLE( m_nSpikeFogCountLast );
  385. /*
  386. INT nSize = 0;
  387. for( INT i = 0; i < LGS_MAX_SPIKE_HISTORY; i++ )
  388. {
  389. INT pos = (m_Kernel.GetDetector()->m_nSpikeHistoryPosition + i) % LGS_MAX_SPIKE_HISTORY;
  390. nSize += _sntprintf( pText + nSize, 1000-nSize, i ? ",%d" : "%d", m_Kernel.GetDetector()->m_pSpikeHistory[pos] );
  391. }
  392. pBRVL->SetVariable( "m_pSpikeHistory", pText );
  393. */
  394. #define INT_DETECTOR_ARRAY_VARIABLE( v, p, m ) \
  395. { \
  396. INT nSize = 0; \
  397. for( INT i = 0; i < m; i++ ) \
  398. { \
  399. INT pos = (m_Kernel.GetDetector()->p + i) % m; \
  400. nSize += _sntprintf( pText + nSize, 1000-nSize, i ? ",%d" : "%d", m_Kernel.GetDetector()->v[pos] ); \
  401. } \
  402. pBRVL->SetVariable( #v, pText ); \
  403. }
  404. INT_DETECTOR_ARRAY_VARIABLE( m_pSpikeHistory, m_nSpikeHistoryPosition, LGS_MAX_SPIKE_HISTORY );
  405. /*
  406. INT_DETECTOR_VARIABLE( m_FilterDRD.m_nDRDCalculateLoop );
  407. // INT_DETECTOR_VARIABLE( m_FilterDRD.m_bDRDCalculate );
  408. // INT_DETECTOR_VARIABLE( m_FilterDRD.m_nDRDCount );
  409. INT_DETECTOR_VARIABLE( m_FilterDRD.m_bDRDMode );
  410. INT_DETECTOR_VARIABLE( m_FilterDRD.m_nDRDHistoryCount );
  411. // INT_DETECTOR_VARIABLE( m_FilterDRD.m_pDRDHistoryPosition );
  412. INT_DETECTOR_VARIABLE( m_FilterDRD.m_nDRDHistoryIndex );
  413. INT_DETECTOR_VARIABLE( m_FilterDRD.m_nDRDHistoryMedium );
  414. for( int j = 0; j < LGS_DETECTOR_DRD_SECTOR_COUNT; j++ )
  415. {
  416. nSize = 0;
  417. for( i = 0; i < LGS_DETECTOR_DRD_HISTORY_LENGTH; i++ )
  418. {
  419. INT pos = (m_Kernel.GetDetector()->m_FilterDRD.m_pDRDHistoryPosition[j] + i) % LGS_DETECTOR_DRD_HISTORY_LENGTH;
  420. nSize += _sntprintf( pText + nSize, 1000-nSize, i ? ",%d" : "%d", m_Kernel.GetDetector()->m_FilterDRD.m_ppDRDHistory[j][pos] );
  421. }
  422. CHAR pVariable[MAX_PATH];
  423. sprintf( pVariable, "m_FilterDRD.m_pDRDHistory[%d]", j );
  424. pBRVL->SetVariable( pVariable, pText );
  425. sprintf( pVariable, "m_FilterDRD.m_pSectorDRDCount[%d]", j );
  426. _sntprintf( pText, 1000, "%d", m_Kernel.GetDetector()->m_FilterDRD.m_pSectorDRDCount[j] );
  427. pBRVL->SetVariable( pVariable, pText );
  428. sprintf( pVariable, "m_FilterDRD.m_pSectorDRDMode[%d]", j );
  429. _sntprintf( pText, 1000, "%d", m_Kernel.GetDetector()->m_FilterDRD.m_pSectorDRDMode[j] );
  430. pBRVL->SetVariable( pVariable, pText );
  431. // pBRVL->SetVariable( "m_FilterDRD.m_pDRDHistory", pText );
  432. }
  433. */
  434. // show middle
  435. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_nMedium );
  436. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_nMediumCalculateLoop );
  437. /*
  438. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_nHistoryCount );
  439. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_nHistoryPosition );
  440. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_nHistoryIndex );
  441. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_nHistoryMedium );
  442. */
  443. INT_DETECTOR_ARRAY_VARIABLE( m_FilterMediumRange.m_MediumHistory.m_pHistory, m_FilterMediumRange.m_MediumHistory.m_nHead, (1 << LGS_DETECTOR_MEDIUM_RANGE_HISTORY_LENGTH) );
  444. INT_DETECTOR_VARIABLE( m_FilterMediumRange.m_bBlind );
  445. /*
  446. nSize = 0;
  447. for( i = 0; i < LGS_DETECTOR_MEDIUM_RANGE_HISTORY_LENGTH; i++ )
  448. {
  449. INT pos = (m_Kernel.GetDetector()->m_FilterMediumRange.m_nHistoryPosition + i) % LGS_DETECTOR_MEDIUM_RANGE_HISTORY_LENGTH;
  450. nSize += _sntprintf( pText + nSize, 1000-nSize, i ? ",%d" : "%d", m_Kernel.GetDetector()->m_FilterMediumRange.m_pHistory[pos] );
  451. }
  452. pBRVL->SetVariable( "m_FilterMediumRange.m_pHistory", pText );
  453. */
  454. // INT_DETECTOR_ARRAY_VARIABLE( m_FilterMediumRange.m_pHistory, m_FilterMediumRange.m_nHistoryPosition, LGS_DETECTOR_MEDIUM_RANGE_HISTORY_LENGTH );
  455. INT_DETECTOR_VARIABLE( m_FilterPD.m_nMediumLastPD );
  456. // INT_DETECTOR_VARIABLE( m_FilterPD.m_nMediumHistory );
  457. // INT_DETECTOR_ARRAY_VARIABLE( m_FilterPD.m_pMediumHistory, m_FilterPD.m_nMediumHistoryHead, LGS_DETECTOR_PD_HISTORY_LENGTH );
  458. INT_DETECTOR_VARIABLE( m_FilterPD.m_MediumHistory.m_nSum );
  459. INT_DETECTOR_ARRAY_VARIABLE( m_FilterPD.m_MediumHistory.m_pHistory, m_FilterPD.m_MediumHistory.m_nHead, (1 << LGS_DETECTOR_PD_HISTORY_LENGTH) );
  460. }
  461. }
  462. }
  463. }
  464. void CBoardReceiverDoc::OnOptionsReset()
  465. {
  466. Reset();
  467. return;
  468. }
  469. void CBoardReceiverDoc::OnOptionsStep()
  470. {
  471. if( m_bLgsMode )
  472. return;
  473. if( !m_bFastProcessing )
  474. {
  475. ReadData();
  476. }
  477. else
  478. {
  479. m_bFastProcessing = FALSE;
  480. // update idle mode
  481. ((CBoardReceiverApp*)AfxGetApp())->SetIdleMode( m_bFastProcessing );
  482. // update view
  483. UpdateView();
  484. }
  485. }
  486. void CBoardReceiverDoc::OnUpdateOptionsStep( CCmdUI* pCmdUI )
  487. {
  488. pCmdUI->Enable( !m_bLgsMode );
  489. }
  490. void CBoardReceiverDoc::OnOptionsParameters()
  491. {
  492. CBoardReceiverParamDlg dlg;
  493. LGS::LGS_PARAMETERS params;
  494. m_Kernel.GetDetector()->GetParameters( &params );
  495. dlg.SetParameters( &params );
  496. if( dlg.DoModal() == IDOK )
  497. {
  498. dlg.GetParameters( &params );
  499. m_Kernel.GetDetector()->SetParameters( &params );
  500. // OnOptionsReset();
  501. Reset();
  502. }
  503. }
  504. void CBoardReceiverDoc::OnOptionsSeek()
  505. {
  506. CBoardReceiverSeekDlg dlg;
  507. dlg.m_nStep.QuadPart = m_liReadPos.QuadPart / sizeof(BOARDDATAARRAY);
  508. if( dlg.DoModal() == IDOK )
  509. {
  510. switch( dlg.m_nRadio )
  511. {
  512. case 0:
  513. {
  514. // open file
  515. HANDLE hFile = ::CreateFile( m_strFileName, GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
  516. if( hFile != INVALID_HANDLE_VALUE )
  517. {
  518. // get file size
  519. LARGE_INTEGER liSize;
  520. liSize.LowPart = ::GetFileSize( hFile, (LPDWORD)&liSize.HighPart );
  521. // update seek position
  522. dlg.m_nStep.QuadPart *= (__int64)sizeof(BOARDDATAARRAY);
  523. // depend on action
  524. if( dlg.m_bRuntoOrGoto )
  525. {
  526. // validate step
  527. if( liSize.QuadPart > dlg.m_nStep.QuadPart &&
  528. m_liReadPos.QuadPart < dlg.m_nStep.QuadPart )
  529. {
  530. m_bFastProcessing = TRUE;
  531. m_liFastProcessingStopPos.QuadPart = dlg.m_nStep.QuadPart;
  532. // update idle mode
  533. ((CBoardReceiverApp*)AfxGetApp())->SetIdleMode( m_bFastProcessing );
  534. }
  535. }
  536. else
  537. {
  538. m_liReadPos.QuadPart = dlg.m_nStep.QuadPart - sizeof(BOARDDATAARRAY);
  539. if( m_liReadPos.QuadPart < 0i64 )
  540. m_liReadPos.QuadPart = 0i64;
  541. ReadData();
  542. OnIdle();
  543. Reset();
  544. }
  545. ::CloseHandle( hFile );
  546. }
  547. }
  548. break;
  549. }
  550. }
  551. }
  552. BOOL CBoardReceiverDoc::ReadData()
  553. {
  554. BOOL bResult = FALSE;
  555. HANDLE hFile = ::CreateFile( m_strFileName, GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
  556. if( hFile != INVALID_HANDLE_VALUE )
  557. {
  558. m_liReadPos.LowPart = ::SetFilePointer( hFile, m_liReadPos.LowPart, &m_liReadPos.HighPart, FILE_BEGIN );
  559. DWORD dwRead = 0;
  560. if( ::ReadFile( hFile, &m_BoardData, sizeof(m_BoardData), &dwRead, NULL ) &&
  561. dwRead == sizeof(m_BoardData) )
  562. {
  563. bResult = TRUE;
  564. m_liReadPos.QuadPart = 0;
  565. m_liReadPos.LowPart = ::SetFilePointer( hFile, m_liReadPos.LowPart, &m_liReadPos.HighPart, FILE_CURRENT );
  566. CLgLocker Lock( &m_List );
  567. m_List.Add( m_BoardData );
  568. }
  569. ::CloseHandle( hFile );
  570. }
  571. return bResult;
  572. }
  573. void CBoardReceiverDoc::Reset()
  574. {
  575. m_Kernel.Reset( FALSE );
  576. // update all document view representations
  577. POSITION posV = GetFirstViewPosition();
  578. while( posV )
  579. {
  580. CView *pView = GetNextView( posV );
  581. if( pView->IsKindOf( RUNTIME_CLASS(CBoardReceiverList) ) )
  582. {
  583. CBoardReceiverList *pBRL = (CBoardReceiverList*)pView;
  584. pBRL->ClearInfo();
  585. }
  586. }
  587. UpdateView();
  588. }
  589. // perform full reset
  590. void CBoardReceiverDoc::OnOptionsSoftreset()
  591. {
  592. m_Kernel.Reset( TRUE );
  593. // update all document view representations
  594. POSITION posV = GetFirstViewPosition();
  595. while( posV )
  596. {
  597. CView *pView = GetNextView( posV );
  598. if( pView->IsKindOf( RUNTIME_CLASS(CBoardReceiverList) ) )
  599. {
  600. CBoardReceiverList *pBRL = (CBoardReceiverList*)pView;
  601. pBRL->ClearInfo();
  602. }
  603. }
  604. UpdateView();
  605. }
  606. BOOL CBoardReceiverDoc::AddHiddenZone( POINT p1, POINT p2 )
  607. {
  608. CRect rect( p1, p2 );
  609. rect.NormalizeRect();
  610. return m_HiddenZoneArray.Add( rect );
  611. }
  612. BOOL CBoardReceiverDoc::RemoveHiddenZone( POINT p )
  613. {
  614. for( INT i = 0; i < m_HiddenZoneArray.GetCount(); i++ )
  615. {
  616. if( PtInRect( &m_HiddenZoneArray[i], p ) )
  617. {
  618. m_HiddenZoneArray.Remove( i );
  619. return TRUE;
  620. }
  621. }
  622. return FALSE;
  623. }