For DOS Protected Mode version of sensor core software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

632 lines
16 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: 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. #ifdef ALS_300
  178. if ( m_pShadowLine[i].lpShadow[j].bType < 5 )
  179. #endif
  180. 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 );
  181. }
  182. }
  183. fclose( pFile );
  184. return TRUE;
  185. }
  186. BOOL CShadow::SavePolygons( PCHAR pFileName )
  187. {
  188. FILE *pFile = fopen( pFileName, "wt" );
  189. if( !pFile )
  190. return TRUE;
  191. // save shadow from line
  192. fprintf( pFile, "type %lu\n", m_dwTypeOn );
  193. // while not end-of-file
  194. for( INT i = 0; i < m_nPolygon; i++ )
  195. {
  196. // save shadow from line
  197. fprintf( pFile, "polygon %d\n", m_lpPolygon[i].bType );
  198. for( INT j = 0; j < m_lpPolygon[i].wCount; j++ )
  199. {
  200. // load shadow from line
  201. fprintf( pFile, "%d %d\n", m_lpPolygon[i].lpPoint[j].wX, m_lpPolygon[i].lpPoint[j].wY );
  202. }
  203. }
  204. fclose( pFile );
  205. return TRUE;
  206. }
  207. BOOL CShadow::Load()
  208. {
  209. Destroy();
  210. if( !LoadRays( "hidden.txt" ) )
  211. return FALSE;
  212. #ifdef ALS_300
  213. if( m_bIsSlave ){
  214. LoadRays( "hiddens.txt" );
  215. } else {
  216. LoadRays( "hiddenm.txt" );
  217. };
  218. #endif
  219. if( !LoadPolygons( "polygons.txt" ) )
  220. return FALSE;
  221. return TRUE;
  222. }
  223. BOOL CShadow::Save()
  224. {
  225. if( !SaveRays( "hidden.txt" ) )
  226. return FALSE;
  227. if( !SavePolygons( "polygons.txt" ) )
  228. return FALSE;
  229. return TRUE;
  230. }
  231. BOOL CShadow::IsOutside( INT nAngle, INT nRange ){
  232. #ifdef COMPILE_AS_SICK_PROXY
  233. return TRUE;
  234. #endif
  235. LONG nShadow = nAngle;
  236. // convert angle to shadow system
  237. #ifdef LGS_MIRROR
  238. nShadow <<= 1;
  239. nShadow = ( nShadow * LGS_MAX_SHADOW_ANGLES ) / (LGS_MAX_DETECTOR_ANGLES * LGS_MIRROR );
  240. #else
  241. nShadow = ( nShadow * LGS_MAX_SHADOW_ANGLES ) / LGS_MAX_DETECTOR_ANGLES;
  242. #endif
  243. // range should be in the same system ( 0..2047 )
  244. LPRAY_LINE pShadowLine = &m_pShadowLine[ (INT)nShadow ];
  245. if( !pShadowLine->nCount )
  246. return TRUE;
  247. LPRAY pShadow = pShadowLine->lpShadow;
  248. for( INT i = 0; i < pShadowLine->nCount; i++ )
  249. {
  250. #ifdef SHADOW_ALWAYS_ON
  251. if( nRange >= pShadow->nMin && nRange <= pShadow->nMax ) return FALSE;
  252. #else
  253. if( pShadow->bType < 6 ){
  254. if( m_pTypeOn[pShadow->bType] && nRange >= pShadow->nMin && nRange <= pShadow->nMax ) return FALSE;
  255. } else {
  256. if( nRange >= pShadow->nMin && nRange <= pShadow->nMax ) return FALSE;
  257. };
  258. #endif
  259. pShadow++;
  260. }
  261. return TRUE;
  262. }
  263. void CShadow::OnCmdGetHzData( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  264. {
  265. union
  266. {
  267. LGS::PHZ_PACKET pPacket;
  268. LGS::PHZ_CMD_GET_HEADER pHzCmdHeader;
  269. LGS::PHZ_CMD_GET_POLYGON pHzCmdPolygon;
  270. LGS::PHZ_CMD_GET_POLYGON_POINT pHzCmdPolygonPoint;
  271. LGS::PHZ_CMD_GET_RAY pHzCmdRay;
  272. LGS::PHZ_CMD_GET_RAY_LINE pHzCmdRayLine;
  273. };
  274. union
  275. {
  276. LGS::HZ_PACKET HzPacket;
  277. LGS::HZ_EVT_GET_HEADER HzEvtHeader;
  278. LGS::HZ_EVT_GET_POLYGON HzEvtPolygon;
  279. LGS::HZ_EVT_GET_POLYGON_POINT HzEvtPolygonPoint;
  280. LGS::HZ_EVT_GET_RAY HzEvtRay;
  281. LGS::HZ_EVT_GET_RAY_LINE HzEvtRayLine;
  282. LGS::HZ_EVT_ERROR HzEvtError;
  283. };
  284. // read packet
  285. nReadCount -= LGS::GetCmdHzGetData( pReadBufferPtr, &pPacket );
  286. // set sequence
  287. HzPacket.bSequence = pPacket->bSequence;
  288. BYTE bError = LGS::HZER_NONE;
  289. switch( pPacket->bType )
  290. {
  291. case LGS::HZIT_CMD_GET_HEADER:
  292. HzEvtHeader.bType = LGS::HZIT_EVT_GET_HEADER;
  293. HzEvtHeader.bSubSize = sizeof(LGS::HZ_EVT_GET_HEADER) - sizeof(LGS::HZ_PACKET);
  294. HzEvtHeader.wPolygonCount = m_nPolygon;
  295. HzEvtHeader.wRayCount = LGS_MAX_SHADOW_ANGLES;
  296. HzEvtHeader.dwTypeOn = m_dwTypeOn;
  297. break;
  298. case LGS::HZIT_CMD_GET_POLYGON:
  299. if( pHzCmdPolygon->wPolygonIndex >= m_nPolygon )
  300. {
  301. bError = LGS::HZER_POLYGON_INDEX;
  302. break;
  303. }
  304. HzEvtPolygon.bType = LGS::HZIT_EVT_GET_POLYGON;
  305. HzEvtPolygon.bSubSize = sizeof(LGS::HZ_EVT_GET_POLYGON) - sizeof(LGS::HZ_PACKET);
  306. HzEvtPolygon.bPolygonType = m_lpPolygon[pHzCmdPolygon->wPolygonIndex].bType;
  307. HzEvtPolygon.wPointCount = m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount;
  308. break;
  309. case LGS::HZIT_CMD_GET_POLYGON_POINT:
  310. if( pHzCmdPolygonPoint->wPolygonIndex >= m_nPolygon )
  311. {
  312. bError = LGS::HZER_POLYGON_INDEX;
  313. break;
  314. }
  315. if( pHzCmdPolygonPoint->wPointIndex >= m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].wCount )
  316. {
  317. bError = LGS::HZER_POLYGON_POINT_INDEX;
  318. break;
  319. }
  320. HzEvtPolygonPoint.bType = LGS::HZIT_EVT_GET_POLYGON_POINT;
  321. HzEvtPolygonPoint.bSubSize = sizeof(LGS::HZ_EVT_GET_POLYGON_POINT) - sizeof(LGS::HZ_PACKET);
  322. HzEvtPolygonPoint.Point = m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].lpPoint[pHzCmdPolygonPoint->wPointIndex];
  323. break;
  324. case LGS::HZIT_CMD_GET_RAY:
  325. if( pHzCmdRay->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  326. {
  327. bError = LGS::HZER_RAY_INDEX;
  328. break;
  329. }
  330. HzEvtRay.bType = LGS::HZIT_EVT_GET_RAY;
  331. HzEvtRay.bSubSize = sizeof(LGS::HZ_EVT_GET_RAY) - sizeof(LGS::HZ_PACKET);
  332. HzEvtRay.wLineCount = m_pShadowLine[pHzCmdRay->wRayIndex].nCount;
  333. break;
  334. case LGS::HZIT_CMD_GET_RAY_LINE:
  335. if( pHzCmdRayLine->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  336. {
  337. bError = LGS::HZER_RAY_INDEX;
  338. break;
  339. }
  340. if( pHzCmdRayLine->wLineIndex >= m_pShadowLine[pHzCmdRayLine->wRayIndex].nCount )
  341. {
  342. bError = LGS::HZER_RAY_LINE_INDEX;
  343. break;
  344. }
  345. HzEvtRayLine.bType = LGS::HZIT_EVT_GET_RAY_LINE;
  346. HzEvtRayLine.bSubSize = sizeof(LGS::HZ_EVT_GET_RAY_LINE) - sizeof(LGS::HZ_PACKET);
  347. HzEvtRayLine.Line.bType = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].bType;
  348. HzEvtRayLine.Line.wMin = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMin;
  349. HzEvtRayLine.Line.wMax = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMax;
  350. break;
  351. }
  352. // fill error
  353. if( bError != LGS::HZER_NONE )
  354. {
  355. HzEvtError.bType = LGS::HZIT_EVT_ERROR;
  356. HzEvtError.bSubSize = sizeof(LGS::HZ_EVT_ERROR) - sizeof(LGS::HZ_PACKET);
  357. HzEvtError.bCmdType = pPacket->bType;
  358. HzEvtError.bErrorId = bError;
  359. }
  360. // build CMD_SET_WIDHT_TABLE command
  361. *pSendBufferPtr++ = LGS::CMD_GET_HZ_DATA;
  362. // write command
  363. nSendCount += LGS::BuildEvtHzGetData( pSendBufferPtr, &HzPacket );
  364. }
  365. BOOL CShadow::OnCmdSetHzData( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  366. {
  367. union
  368. {
  369. LGS::PHZ_PACKET pPacket;
  370. LGS::PHZ_CMD_SET_HEADER pHzCmdHeader;
  371. LGS::PHZ_CMD_SET_POLYGON pHzCmdPolygon;
  372. LGS::PHZ_CMD_SET_POLYGON_POINT pHzCmdPolygonPoint;
  373. LGS::PHZ_CMD_SET_RAY pHzCmdRay;
  374. LGS::PHZ_CMD_SET_RAY_LINE pHzCmdRayLine;
  375. LGS::PHZ_CMD_SET_DONE pHzCmdDone;
  376. };
  377. union
  378. {
  379. LGS::HZ_PACKET HzPacket;
  380. LGS::HZ_EVT_SET_HEADER HzEvtHeader;
  381. LGS::HZ_EVT_SET_POLYGON HzEvtPolygon;
  382. LGS::HZ_EVT_SET_POLYGON_POINT HzEvtPolygonPoint;
  383. LGS::HZ_EVT_SET_RAY HzEvtRay;
  384. LGS::HZ_EVT_SET_RAY_LINE HzEvtRayLine;
  385. LGS::HZ_EVT_SET_DONE HzEvtDone;
  386. LGS::HZ_EVT_ERROR HzEvtError;
  387. };
  388. //
  389. BOOL bPendingSave = FALSE;
  390. // read packet
  391. nReadCount -= LGS::GetCmdHzSetData( pReadBufferPtr, &pPacket );
  392. // set sequence
  393. HzPacket.bSequence = pPacket->bSequence;
  394. BYTE bError = LGS::HZER_NONE;
  395. switch( pPacket->bType )
  396. {
  397. case LGS::HZIT_CMD_SET_HEADER:
  398. // destroy old content
  399. Destroy();
  400. // check shadow rays count
  401. if( pHzCmdHeader->wRayCount != LGS_MAX_SHADOW_ANGLES )
  402. {
  403. bError = LGS::HZER_RAY_COUNT;
  404. break;
  405. }
  406. // create empty polygons
  407. m_lpPolygon = (LPHZ_POLYGON)farmalloc( pHzCmdHeader->wPolygonCount * sizeof(HZ_POLYGON) );
  408. if( pHzCmdHeader->wPolygonCount && !m_lpPolygon )
  409. {
  410. bError = LGS::HZER_OUT_OF_MEMORY;
  411. break;
  412. }
  413. _fmemset( m_lpPolygon, 0, pHzCmdHeader->wPolygonCount * sizeof(HZ_POLYGON) );
  414. m_nPolygon = pHzCmdHeader->wPolygonCount;
  415. m_dwTypeOn = pHzCmdHeader->dwTypeOn;
  416. {
  417. for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
  418. {
  419. DWORD bBit = 1 << i;
  420. m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
  421. }
  422. }
  423. // prepare reply
  424. HzEvtHeader.bType = LGS::HZIT_EVT_SET_HEADER;
  425. HzEvtHeader.bSubSize = sizeof(LGS::HZ_EVT_SET_HEADER) - sizeof(LGS::HZ_PACKET);
  426. break;
  427. case LGS::HZIT_CMD_SET_POLYGON:
  428. // check index
  429. if( pHzCmdPolygon->wPolygonIndex >= m_nPolygon )
  430. {
  431. bError = LGS::HZER_POLYGON_INDEX;
  432. break;
  433. }
  434. // reallocate memory
  435. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount = 0;
  436. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint = (LGS::LPHZ_POINT)farrealloc( m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint, sizeof(LGS::HZ_POINT) * pHzCmdPolygon->wPointCount );
  437. if( pHzCmdPolygon->wPointCount && !m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint )
  438. {
  439. bError = LGS::HZER_OUT_OF_MEMORY;
  440. break;
  441. }
  442. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount = pHzCmdPolygon->wPointCount;
  443. m_lpPolygon[pHzCmdPolygon->wPolygonIndex].bType = pHzCmdPolygon->bPolygonType;
  444. // prepare reply
  445. HzEvtPolygon.bType = LGS::HZIT_EVT_SET_POLYGON;
  446. HzEvtPolygon.bSubSize = sizeof(LGS::HZ_EVT_SET_POLYGON) - sizeof(LGS::HZ_PACKET);
  447. break;
  448. case LGS::HZIT_CMD_SET_POLYGON_POINT:
  449. // check indexes
  450. if( pHzCmdPolygonPoint->wPolygonIndex >= m_nPolygon )
  451. {
  452. bError = LGS::HZER_POLYGON_INDEX;
  453. break;
  454. }
  455. if( pHzCmdPolygonPoint->wPointIndex >= m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].wCount )
  456. {
  457. bError = LGS::HZER_POLYGON_POINT_INDEX;
  458. break;
  459. }
  460. m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].lpPoint[pHzCmdPolygonPoint->wPointIndex] = pHzCmdPolygonPoint->Point;
  461. // prepare reply
  462. HzEvtPolygonPoint.bType = LGS::HZIT_EVT_SET_POLYGON_POINT;
  463. HzEvtPolygonPoint.bSubSize = sizeof(LGS::HZ_EVT_SET_POLYGON_POINT) - sizeof(LGS::HZ_PACKET);
  464. break;
  465. case LGS::HZIT_CMD_SET_RAY:
  466. // check indexes
  467. if( pHzCmdRay->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  468. {
  469. bError = LGS::HZER_RAY_INDEX;
  470. break;
  471. }
  472. m_pShadowLine[pHzCmdRay->wRayIndex].nCount = 0;
  473. m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow = (LPRAY)farrealloc( m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow, pHzCmdRay->wLineCount * sizeof(RAY) );
  474. if( pHzCmdRay->wLineCount && !m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow )
  475. {
  476. bError = LGS::HZER_OUT_OF_MEMORY;
  477. break;
  478. }
  479. m_pShadowLine[pHzCmdRay->wRayIndex].nCount = pHzCmdRay->wLineCount;
  480. // prepare reply
  481. HzEvtRay.bType = LGS::HZIT_EVT_SET_RAY;
  482. HzEvtRay.bSubSize = sizeof(LGS::HZ_EVT_SET_RAY) - sizeof(LGS::HZ_PACKET);
  483. break;
  484. case LGS::HZIT_CMD_SET_RAY_LINE:
  485. if( pHzCmdRayLine->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
  486. {
  487. bError = LGS::HZER_RAY_INDEX;
  488. break;
  489. }
  490. if( pHzCmdRayLine->wLineIndex >= m_pShadowLine[pHzCmdRayLine->wRayIndex].nCount )
  491. {
  492. bError = LGS::HZER_RAY_LINE_INDEX;
  493. break;
  494. }
  495. m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].bType = pHzCmdRayLine->Line.bType;
  496. m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMin = pHzCmdRayLine->Line.wMin;
  497. m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMax = pHzCmdRayLine->Line.wMax;
  498. HzEvtRayLine.bType = LGS::HZIT_EVT_SET_RAY_LINE;
  499. HzEvtRayLine.bSubSize = sizeof(LGS::HZ_EVT_SET_RAY_LINE) - sizeof(LGS::HZ_PACKET);
  500. break;
  501. case LGS::HZIT_CMD_SET_DONE:
  502. HzEvtDone.bType = LGS::HZIT_EVT_SET_DONE;
  503. HzEvtDone.bSubSize = sizeof(LGS::HZ_EVT_SET_DONE) - sizeof(LGS::HZ_PACKET);
  504. bPendingSave = TRUE;
  505. break;
  506. }
  507. // fill error
  508. if( bError != LGS::HZER_NONE )
  509. {
  510. HzEvtError.bType = LGS::HZIT_EVT_ERROR;
  511. HzEvtError.bSubSize = sizeof(LGS::HZ_EVT_ERROR) - sizeof(LGS::HZ_PACKET);
  512. HzEvtError.bCmdType = pPacket->bType;
  513. HzEvtError.bErrorId = bError;
  514. }
  515. // build CMD_SET_WIDHT_TABLE command
  516. *pSendBufferPtr++ = LGS::CMD_SET_HZ_DATA;
  517. // write command
  518. nSendCount += LGS::BuildEvtHzSetData( pSendBufferPtr, &HzPacket );
  519. return bPendingSave;
  520. }
  521. void CShadow::OnCmdGetHzEnable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  522. {
  523. // build CMD_SET_WIDHT_TABLE command
  524. *pSendBufferPtr++ = LGS::CMD_GET_HZ_ENABLE;
  525. // write command
  526. nSendCount += LGS::BuildEvtGetHzEnable( pSendBufferPtr, m_dwTypeOn );
  527. }
  528. BOOL CShadow::OnCmdSetHzEnable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
  529. {
  530. // read packet
  531. nReadCount -= LGS::GetCmdSetHzEnable( pReadBufferPtr, &m_dwTypeOn );
  532. for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ ){
  533. DWORD bBit = 1 << i;
  534. m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
  535. }
  536. // build CMD_SET_WIDHT_TABLE command
  537. *pSendBufferPtr++ = LGS::CMD_SET_HZ_ENABLE;
  538. // write command
  539. nSendCount += LGS::BuildEvtSetHzEnable( pSendBufferPtr, m_dwTypeOn );
  540. return TRUE;
  541. }