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.

589 lines
17 KiB

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