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.

616 lines
17 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: Shadow.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Shadow.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "shadow.h"
  16. #include "detector.h"
  17. #include "..\LgLib\version.h"
  18. BOOL CShadow::AddShadow( INT nAngle, BYTE bType, INT nMin, INT nMax )
  19. {
  20. if( LGS_MAX_SHADOW_ANGLES <= nAngle )
  21. return FALSE;
  22. // range should be in the same system ( 0..2047 )
  23. LPRAY_LINE pShadowLine = &m_pShadowLine[ (INT)nAngle ];
  24. // realloc memory for shadows
  25. pShadowLine->lpShadow = (LPRAY)farrealloc( pShadowLine->lpShadow,
  26. sizeof( RAY ) * ( pShadowLine->nCount + 1 ) );
  27. if( !pShadowLine->lpShadow )
  28. {
  29. pShadowLine->nCount = 0;
  30. return FALSE;
  31. }
  32. // store shadow
  33. pShadowLine->lpShadow[ pShadowLine->nCount ].bType = bType;
  34. pShadowLine->lpShadow[ pShadowLine->nCount ].nMin = nMin;
  35. pShadowLine->lpShadow[ pShadowLine->nCount ].nMax = nMax;
  36. pShadowLine->nCount++;
  37. return TRUE;
  38. }
  39. void CShadow::Destroy()
  40. {
  41. for( INT i = 0; i < LGS_MAX_SHADOW_ANGLES; i++ )
  42. {
  43. if( m_pShadowLine[i].lpShadow )
  44. {
  45. farfree( m_pShadowLine[i].lpShadow );
  46. m_pShadowLine[i].lpShadow = NULL;
  47. }
  48. m_pShadowLine[i].nCount = 0;
  49. }
  50. for( i = 0; i < m_nPolygon; i++ )
  51. if( m_lpPolygon[i].lpPoint )
  52. farfree( m_lpPolygon[i].lpPoint );
  53. m_nPolygon = 0;
  54. if( m_lpPolygon )
  55. {
  56. farfree( m_lpPolygon );
  57. m_lpPolygon = NULL;
  58. }
  59. }
  60. BOOL CShadow::LoadRays( PCHAR pFileName )
  61. {
  62. FILE *pFile = fopen( pFileName, "rt" );
  63. if( !pFile )
  64. return TRUE;
  65. // while not end-of-file
  66. while( !feof( pFile ) )
  67. {
  68. const INT nMaxLineLength = 128;
  69. CHAR pBuffer[ nMaxLineLength ];
  70. // get line string from file
  71. if( fgets( pBuffer, nMaxLineLength, pFile ) )
  72. {
  73. INT nAngle;
  74. INT bType;
  75. INT nMin;
  76. INT nMax;
  77. // load shadow from line
  78. if( sscanf( pBuffer, "%d %d %d %d", &nAngle, &bType, &nMin, &nMax ) == 4 )
  79. // add shadow
  80. AddShadow( nAngle, bType, nMin, nMax );
  81. }
  82. }
  83. fclose( pFile );
  84. return TRUE;
  85. }
  86. BOOL CShadow::LoadPolygons( PCHAR pFileName )
  87. {
  88. FILE *pFile = fopen( pFileName, "rt" );
  89. if( !pFile )
  90. return TRUE;
  91. INT nPolygon = 0;
  92. INT nPolygonPoint = 0;
  93. // while not end-of-file
  94. while( !feof( pFile ) )
  95. {
  96. const INT nMaxLineLength = 1024;
  97. CHAR pBuffer[ nMaxLineLength ];
  98. // get line string from file
  99. if( fgets( pBuffer, nMaxLineLength, pFile ) )
  100. {
  101. // load shadow from line
  102. if( strstr( pBuffer, "type" ) )
  103. {
  104. DWORD dwTypeOn;
  105. if( sscanf( pBuffer, "type %lu", &dwTypeOn ) == 1 )
  106. {
  107. m_dwTypeOn = dwTypeOn;
  108. for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
  109. {
  110. DWORD bBit = 1 << i;
  111. m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
  112. }
  113. }
  114. }
  115. else
  116. // load shadow from line
  117. if( strstr( pBuffer, "polygon" ) )
  118. {
  119. INT nType;
  120. if( sscanf( pBuffer, "polygon %d", &nType ) == 1 )
  121. {
  122. nPolygon++;
  123. nPolygonPoint = 0;
  124. if( m_nPolygon < nPolygon )
  125. {
  126. m_lpPolygon = (LPHZ_POLYGON)farrealloc( m_lpPolygon, nPolygon * sizeof(HZ_POLYGON) );
  127. if( !m_lpPolygon )
  128. {
  129. m_nPolygon = 0;
  130. fclose( pFile );
  131. return TRUE;
  132. }
  133. m_lpPolygon[nPolygon-1].lpPoint = NULL;
  134. m_lpPolygon[nPolygon-1].wCount = 0;
  135. m_lpPolygon[nPolygon-1].bType = nType;
  136. m_nPolygon = nPolygon;
  137. }
  138. }
  139. }
  140. else
  141. if( nPolygon )
  142. {
  143. INT nX,nY;
  144. if( sscanf( pBuffer, "%d %d", &nX, &nY ) == 2 )
  145. {
  146. nPolygonPoint++;
  147. if( m_lpPolygon[nPolygon-1].wCount < nPolygonPoint )
  148. {
  149. m_lpPolygon[nPolygon-1].lpPoint = (LGS::LPHZ_POINT)farrealloc( m_lpPolygon[nPolygon-1].lpPoint, nPolygonPoint * sizeof(LGS::HZ_POINT) );
  150. if( !m_lpPolygon[nPolygon-1].lpPoint )
  151. {
  152. m_lpPolygon[nPolygon-1].wCount = 0;
  153. fclose( pFile );
  154. return TRUE;
  155. }
  156. m_lpPolygon[nPolygon-1].lpPoint[nPolygonPoint-1].wX = nX;
  157. m_lpPolygon[nPolygon-1].lpPoint[nPolygonPoint-1].wY = nY;
  158. m_lpPolygon[nPolygon-1].wCount = nPolygonPoint;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. fclose( pFile );
  165. return TRUE;
  166. }
  167. BOOL CShadow::SaveRays( PCHAR pFileName )
  168. {
  169. FILE *pFile = fopen( pFileName, "wt" );
  170. if( !pFile )
  171. return TRUE;
  172. // while not end-of-file
  173. for( INT i = 0; i < LGS_MAX_SHADOW_ANGLES; i++ )
  174. {
  175. for( INT j = 0; j < m_pShadowLine[i].nCount; j++ )
  176. {
  177. // load shadow from line
  178. fprintf( pFile, "%d %d %d %d\n", i, m_pShadowLine[i].lpShadow[j].bType, m_pShadowLine[i].lpShadow[j].nMin, m_pShadowLine[i].lpShadow[j].nMax );
  179. }
  180. }
  181. fclose( pFile );
  182. return TRUE;
  183. }
  184. BOOL CShadow::SavePolygons( PCHAR pFileName )
  185. {
  186. FILE *pFile = fopen( pFileName, "wt" );
  187. if( !pFile )
  188. return TRUE;
  189. // save shadow from line
  190. fprintf( pFile, "type %lu\n", m_dwTypeOn );
  191. // while not end-of-file
  192. for( INT i = 0; i < m_nPolygon; i++ )
  193. {
  194. // save shadow from line
  195. fprintf( pFile, "polygon %d\n", m_lpPolygon[i].bType );
  196. for( INT j = 0; j < m_lpPolygon[i].wCount; j++ )
  197. {
  198. // load shadow from line
  199. fprintf( pFile, "%d %d\n", m_lpPolygon[i].lpPoint[j].wX, m_lpPolygon[i].lpPoint[j].wY );
  200. }
  201. }
  202. fclose( pFile );
  203. return TRUE;
  204. }
  205. BOOL CShadow::Load()
  206. {
  207. Destroy();
  208. if( !LoadRays( "hidden.txt" ) )
  209. return FALSE;
  210. if( !LoadPolygons( "polygons.txt" ) )
  211. return FALSE;
  212. return TRUE;
  213. }
  214. BOOL CShadow::Save()
  215. {
  216. if( !SaveRays( "hidden.txt" ) )
  217. return FALSE;
  218. if( !SavePolygons( "polygons.txt" ) )
  219. return FALSE;
  220. return TRUE;
  221. }
  222. BOOL CShadow::IsOutside( INT nAngle, INT nRange )
  223. {
  224. LONG nShadow = nAngle;
  225. // convert angle to shadow system
  226. #ifdef LGS_MIRROR
  227. nShadow <<= 1;
  228. nShadow = ( nShadow * LGS_MAX_SHADOW_ANGLES ) / (LGS_MAX_DETECTOR_ANGLES * LGS_MIRROR );
  229. #else
  230. nShadow = ( nShadow * LGS_MAX_SHADOW_ANGLES ) / LGS_MAX_DETECTOR_ANGLES;
  231. #endif
  232. // range should be in the same system ( 0..2047 )
  233. LPRAY_LINE pShadowLine = &m_pShadowLine[ (INT)nShadow ];
  234. if( !pShadowLine->nCount )
  235. return TRUE;
  236. LPRAY pShadow = pShadowLine->lpShadow;
  237. for( INT i = 0; i < pShadowLine->nCount; i++ )
  238. {
  239. if( m_pTypeOn[pShadow->bType] && nRange >= pShadow->nMin && nRange <= pShadow->nMax )
  240. return FALSE;
  241. pShadow++;
  242. }
  243. return TRUE;
  244. }
  245. void CShadow::OnCmdGetHzData( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  246. {
  247. union
  248. {
  249. LGS::PHZ_PACKET pPacket;
  250. LGS::PHZ_CMD_GET_HEADER pHzCmdHeader;
  251. LGS::PHZ_CMD_GET_POLYGON pHzCmdPolygon;
  252. LGS::PHZ_CMD_GET_POLYGON_POINT pHzCmdPolygonPoint;
  253. LGS::PHZ_CMD_GET_RAY pHzCmdRay;
  254. LGS::PHZ_CMD_GET_RAY_LINE pHzCmdRayLine;
  255. };
  256. union
  257. {
  258. LGS::HZ_PACKET HzPacket;
  259. LGS::HZ_EVT_GET_HEADER HzEvtHeader;
  260. LGS::HZ_EVT_GET_POLYGON HzEvtPolygon;
  261. LGS::HZ_EVT_GET_POLYGON_POINT HzEvtPolygonPoint;
  262. LGS::HZ_EVT_GET_RAY HzEvtRay;
  263. LGS::HZ_EVT_GET_RAY_LINE HzEvtRayLine;
  264. LGS::HZ_EVT_ERROR HzEvtError;
  265. };
  266. // read packet
  267. nReadCount -= LGS::GetCmdHzGetData( pReadBufferPtr, &pPacket );
  268. // set sequence
  269. HzPacket.bSequence = pPacket->bSequence;
  270. BYTE bError = LGS::HZER_NONE;
  271. switch( pPacket->bType )
  272. {
  273. case LGS::HZIT_CMD_GET_HEADER:
  274. HzEvtHeader.bType = LGS::HZIT_EVT_GET_HEADER;
  275. HzEvtHeader.bSubSize = sizeof(LGS::HZ_EVT_GET_HEADER) - sizeof(LGS::HZ_PACKET);
  276. HzEvtHeader.wPolygonCount = m_nPolygon;
  277. HzEvtHeader.wRayCount = LGS_MAX_SHADOW_ANGLES;
  278. HzEvtHeader.dwTypeOn = m_dwTypeOn;
  279. break;
  280. case LGS::HZIT_CMD_GET_POLYGON:
  281. if( pHzCmdPolygon->wPolygonIndex >= m_nPolygon )
  282. {
  283. bError = LGS::HZER_POLYGON_INDEX;
  284. break;
  285. }
  286. HzEvtPolygon.bType = LGS::HZIT_EVT_GET_POLYGON;
  287. HzEvtPolygon.bSubSize = sizeof(LGS::HZ_EVT_GET_POLYGON) - sizeof(LGS::HZ_PACKET);
  288. HzEvtPolygon.bPolygonType = m_lpPolygon[pHzCmdPolygon->wPolygonIndex].bType;
  289. HzEvtPolygon.wPointCount = m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount;
  290. break;
  291. case LGS::HZIT_CMD_GET_POLYGON_POINT:
  292. if( pHzCmdPolygonPoint->wPolygonIndex >= m_nPolygon )
  293. {
  294. bError = LGS::HZER_POLYGON_INDEX;
  295. break;
  296. }
  297. if( pHzCmdPolygonPoint->wPointIndex >= m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].wCount )
  298. {
  299. bError = LGS::HZER_POLYGON_POINT_INDEX;
  300. break;
  301. }
  302. HzEvtPolygonPoint.bType = LGS::HZIT_EVT_GET_POLYGON_POINT;
  303. HzEvtPolygonPoint.bSubSize = sizeof(LGS::HZ_EVT_GET_POLYGON_POINT) - sizeof(LGS::HZ_PACKET);
  304. HzEvtPolygonPoint.Point = m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].lpPoint[pHzCmdPolygonPoint->wPointIndex];
  305. break;
  306. case LGS::HZIT_CMD_GET_RAY:
  307. if( pHzCmdRay->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  308. {
  309. bError = LGS::HZER_RAY_INDEX;
  310. break;
  311. }
  312. HzEvtRay.bType = LGS::HZIT_EVT_GET_RAY;
  313. HzEvtRay.bSubSize = sizeof(LGS::HZ_EVT_GET_RAY) - sizeof(LGS::HZ_PACKET);
  314. HzEvtRay.wLineCount = m_pShadowLine[pHzCmdRay->wRayIndex].nCount;
  315. break;
  316. case LGS::HZIT_CMD_GET_RAY_LINE:
  317. if( pHzCmdRayLine->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  318. {
  319. bError = LGS::HZER_RAY_INDEX;
  320. break;
  321. }
  322. if( pHzCmdRayLine->wLineIndex >= m_pShadowLine[pHzCmdRayLine->wRayIndex].nCount )
  323. {
  324. bError = LGS::HZER_RAY_LINE_INDEX;
  325. break;
  326. }
  327. HzEvtRayLine.bType = LGS::HZIT_EVT_GET_RAY_LINE;
  328. HzEvtRayLine.bSubSize = sizeof(LGS::HZ_EVT_GET_RAY_LINE) - sizeof(LGS::HZ_PACKET);
  329. HzEvtRayLine.Line.bType = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].bType;
  330. HzEvtRayLine.Line.wMin = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMin;
  331. HzEvtRayLine.Line.wMax = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMax;
  332. break;
  333. }
  334. // fill error
  335. if( bError != LGS::HZER_NONE )
  336. {
  337. HzEvtError.bType = LGS::HZIT_EVT_ERROR;
  338. HzEvtError.bSubSize = sizeof(LGS::HZ_EVT_ERROR) - sizeof(LGS::HZ_PACKET);
  339. HzEvtError.bCmdType = pPacket->bType;
  340. HzEvtError.bErrorId = bError;
  341. }
  342. // build CMD_SET_WIDHT_TABLE command
  343. *pSendBufferPtr++ = LGS::CMD_GET_HZ_DATA;
  344. // write command
  345. nSendCount += LGS::BuildEvtHzGetData( pSendBufferPtr, &HzPacket );
  346. }
  347. BOOL CShadow::OnCmdSetHzData( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  348. {
  349. union
  350. {
  351. LGS::PHZ_PACKET pPacket;
  352. LGS::PHZ_CMD_SET_HEADER pHzCmdHeader;
  353. LGS::PHZ_CMD_SET_POLYGON pHzCmdPolygon;
  354. LGS::PHZ_CMD_SET_POLYGON_POINT pHzCmdPolygonPoint;
  355. LGS::PHZ_CMD_SET_RAY pHzCmdRay;
  356. LGS::PHZ_CMD_SET_RAY_LINE pHzCmdRayLine;
  357. LGS::PHZ_CMD_SET_DONE pHzCmdDone;
  358. };
  359. union
  360. {
  361. LGS::HZ_PACKET HzPacket;
  362. LGS::HZ_EVT_SET_HEADER HzEvtHeader;
  363. LGS::HZ_EVT_SET_POLYGON HzEvtPolygon;
  364. LGS::HZ_EVT_SET_POLYGON_POINT HzEvtPolygonPoint;
  365. LGS::HZ_EVT_SET_RAY HzEvtRay;
  366. LGS::HZ_EVT_SET_RAY_LINE HzEvtRayLine;
  367. LGS::HZ_EVT_SET_DONE HzEvtDone;
  368. LGS::HZ_EVT_ERROR HzEvtError;
  369. };
  370. //
  371. BOOL bPendingSave = FALSE;
  372. // read packet
  373. nReadCount -= LGS::GetCmdHzSetData( pReadBufferPtr, &pPacket );
  374. // set sequence
  375. HzPacket.bSequence = pPacket->bSequence;
  376. BYTE bError = LGS::HZER_NONE;
  377. switch( pPacket->bType )
  378. {
  379. case LGS::HZIT_CMD_SET_HEADER:
  380. // destroy old content
  381. Destroy();
  382. // check shadow rays count
  383. if( pHzCmdHeader->wRayCount != LGS_MAX_SHADOW_ANGLES )
  384. {
  385. bError = LGS::HZER_RAY_COUNT;
  386. break;
  387. }
  388. // create empty polygons
  389. m_lpPolygon = (LPHZ_POLYGON)farmalloc( pHzCmdHeader->wPolygonCount * sizeof(HZ_POLYGON) );
  390. if( pHzCmdHeader->wPolygonCount && !m_lpPolygon )
  391. {
  392. bError = LGS::HZER_OUT_OF_MEMORY;
  393. break;
  394. }
  395. _fmemset( m_lpPolygon, 0, pHzCmdHeader->wPolygonCount * sizeof(HZ_POLYGON) );
  396. m_nPolygon = pHzCmdHeader->wPolygonCount;
  397. m_dwTypeOn = pHzCmdHeader->dwTypeOn;
  398. {
  399. for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
  400. {
  401. DWORD bBit = 1 << i;
  402. m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
  403. }
  404. }
  405. // prepare reply
  406. HzEvtHeader.bType = LGS::HZIT_EVT_SET_HEADER;
  407. HzEvtHeader.bSubSize = sizeof(LGS::HZ_EVT_SET_HEADER) - sizeof(LGS::HZ_PACKET);
  408. break;
  409. case LGS::HZIT_CMD_SET_POLYGON:
  410. // check index
  411. if( pHzCmdPolygon->wPolygonIndex >= m_nPolygon )
  412. {
  413. bError = LGS::HZER_POLYGON_INDEX;
  414. break;
  415. }
  416. // reallocate memory
  417. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount = 0;
  418. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint = (LGS::LPHZ_POINT)farrealloc( m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint, sizeof(LGS::HZ_POINT) * pHzCmdPolygon->wPointCount );
  419. if( pHzCmdPolygon->wPointCount && !m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint )
  420. {
  421. bError = LGS::HZER_OUT_OF_MEMORY;
  422. break;
  423. }
  424. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount = pHzCmdPolygon->wPointCount;
  425. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].bType = pHzCmdPolygon->bPolygonType;
  426. // prepare reply
  427. HzEvtPolygon.bType = LGS::HZIT_EVT_SET_POLYGON;
  428. HzEvtPolygon.bSubSize = sizeof(LGS::HZ_EVT_SET_POLYGON) - sizeof(LGS::HZ_PACKET);
  429. break;
  430. case LGS::HZIT_CMD_SET_POLYGON_POINT:
  431. // check indexes
  432. if( pHzCmdPolygonPoint->wPolygonIndex >= m_nPolygon )
  433. {
  434. bError = LGS::HZER_POLYGON_INDEX;
  435. break;
  436. }
  437. if( pHzCmdPolygonPoint->wPointIndex >= m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].wCount )
  438. {
  439. bError = LGS::HZER_POLYGON_POINT_INDEX;
  440. break;
  441. }
  442. m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].lpPoint[pHzCmdPolygonPoint->wPointIndex] = pHzCmdPolygonPoint->Point;
  443. // prepare reply
  444. HzEvtPolygonPoint.bType = LGS::HZIT_EVT_SET_POLYGON_POINT;
  445. HzEvtPolygonPoint.bSubSize = sizeof(LGS::HZ_EVT_SET_POLYGON_POINT) - sizeof(LGS::HZ_PACKET);
  446. break;
  447. case LGS::HZIT_CMD_SET_RAY:
  448. // check indexes
  449. if( pHzCmdRay->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  450. {
  451. bError = LGS::HZER_RAY_INDEX;
  452. break;
  453. }
  454. m_pShadowLine[pHzCmdRay->wRayIndex].nCount = 0;
  455. m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow = (LPRAY)farrealloc( m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow, pHzCmdRay->wLineCount * sizeof(RAY) );
  456. if( pHzCmdRay->wLineCount && !m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow )
  457. {
  458. bError = LGS::HZER_OUT_OF_MEMORY;
  459. break;
  460. }
  461. m_pShadowLine[pHzCmdRay->wRayIndex].nCount = pHzCmdRay->wLineCount;
  462. // prepare reply
  463. HzEvtRay.bType = LGS::HZIT_EVT_SET_RAY;
  464. HzEvtRay.bSubSize = sizeof(LGS::HZ_EVT_SET_RAY) - sizeof(LGS::HZ_PACKET);
  465. break;
  466. case LGS::HZIT_CMD_SET_RAY_LINE:
  467. if( pHzCmdRayLine->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  468. {
  469. bError = LGS::HZER_RAY_INDEX;
  470. break;
  471. }
  472. if( pHzCmdRayLine->wLineIndex >= m_pShadowLine[pHzCmdRayLine->wRayIndex].nCount )
  473. {
  474. bError = LGS::HZER_RAY_LINE_INDEX;
  475. break;
  476. }
  477. m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].bType = pHzCmdRayLine->Line.bType;
  478. m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMin = pHzCmdRayLine->Line.wMin;
  479. m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMax = pHzCmdRayLine->Line.wMax;
  480. HzEvtRayLine.bType = LGS::HZIT_EVT_SET_RAY_LINE;
  481. HzEvtRayLine.bSubSize = sizeof(LGS::HZ_EVT_SET_RAY_LINE) - sizeof(LGS::HZ_PACKET);
  482. break;
  483. case LGS::HZIT_CMD_SET_DONE:
  484. HzEvtDone.bType = LGS::HZIT_EVT_SET_DONE;
  485. HzEvtDone.bSubSize = sizeof(LGS::HZ_EVT_SET_DONE) - sizeof(LGS::HZ_PACKET);
  486. bPendingSave = TRUE;
  487. break;
  488. }
  489. // fill error
  490. if( bError != LGS::HZER_NONE )
  491. {
  492. HzEvtError.bType = LGS::HZIT_EVT_ERROR;
  493. HzEvtError.bSubSize = sizeof(LGS::HZ_EVT_ERROR) - sizeof(LGS::HZ_PACKET);
  494. HzEvtError.bCmdType = pPacket->bType;
  495. HzEvtError.bErrorId = bError;
  496. }
  497. // build CMD_SET_WIDHT_TABLE command
  498. *pSendBufferPtr++ = LGS::CMD_SET_HZ_DATA;
  499. // write command
  500. nSendCount += LGS::BuildEvtHzSetData( pSendBufferPtr, &HzPacket );
  501. return bPendingSave;
  502. }
  503. void CShadow::OnCmdGetHzEnable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  504. {
  505. // build CMD_SET_WIDHT_TABLE command
  506. *pSendBufferPtr++ = LGS::CMD_GET_HZ_ENABLE;
  507. // write command
  508. nSendCount += LGS::BuildEvtGetHzEnable( pSendBufferPtr, m_dwTypeOn );
  509. }
  510. BOOL CShadow::OnCmdSetHzEnable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  511. {
  512. // read packet
  513. nReadCount -= LGS::GetCmdSetHzEnable( pReadBufferPtr, &m_dwTypeOn );
  514. for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
  515. {
  516. DWORD bBit = 1 << i;
  517. m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
  518. }
  519. // build CMD_SET_WIDHT_TABLE command
  520. *pSendBufferPtr++ = LGS::CMD_SET_HZ_ENABLE;
  521. // write command
  522. nSendCount += LGS::BuildEvtSetHzEnable( pSendBufferPtr, m_dwTypeOn );
  523. return TRUE;
  524. }