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.

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