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.

140 lines
2.9 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: DeviceLGSs.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DeviceLGSs.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "SensorLGS.h"
  16. #include "DeviceLGSs.h"
  17. #include "..\..\LgLib\Comm\Connect.h"
  18. #include "..\..\LgLib\Version.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[]=__FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24. CDeviceLGSs::CDeviceLGSs()
  25. {
  26. m_bEnable = FALSE;
  27. m_nCount = 0;
  28. m_bNeedReset = FALSE;
  29. m_bNeedRestart = FALSE;
  30. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceLGSs::CDeviceLGSs") );
  31. }
  32. CDeviceLGSs::~CDeviceLGSs()
  33. {
  34. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceLGSs::~CDeviceLGSs") );
  35. }
  36. DWORD CDeviceLGSs::CompleteIO( CConnection *pConnection )
  37. {
  38. if( !pConnection )
  39. return FALSE;
  40. BYTE pBuffer[10];
  41. DWORD dwCount = pConnection->Read( pBuffer, 8 - m_nCount, 500UL );
  42. BOOL bCommandReceived = FALSE;
  43. for( DWORD i = 0; i < dwCount; i++ )
  44. {
  45. if( m_nCount < 8 )
  46. {
  47. m_pBuffer[ m_nCount++ ] = pBuffer[ i ];
  48. }
  49. else
  50. {
  51. ::MoveMemory( m_pBuffer, m_pBuffer+1, 7 );
  52. m_pBuffer[ 7 ] = pBuffer[i];
  53. }
  54. if( m_nCount == 8 )
  55. {
  56. if( m_pBuffer[ 7 ] == 0 )
  57. {
  58. char command;
  59. int angle, range;
  60. if( sscanf( (LPSTR)m_pBuffer, "%c%03d%03d", &command, &angle, &range ) == 3 )
  61. {
  62. switch( command )
  63. {
  64. case 'a': m_pSensor->PostTarget( 0, LGS::TT_NORMAL, (double)angle, ((double)range)/5.12 ); break;
  65. case 'b': m_pSensor->PostTarget( 1, LGS::TT_NORMAL, (double)angle, ((double)range)/5.12 ); break;
  66. case 'f': m_pSensor->PostTarget( 0, LGS::TT_WIDE, (double)angle, ((double)range)/5.12 ); break;
  67. case 'w': m_pSensor->PostTarget( 0, LGS::TT_WIDE, (double)angle, ((double)range)/5.12 ); break;
  68. }
  69. }
  70. m_nCount = 0;
  71. bCommandReceived = TRUE; // packet has been read
  72. break;
  73. }
  74. else
  75. {
  76. ::MoveMemory( m_pBuffer, m_pBuffer + 1, 7 );
  77. m_nCount --;
  78. }
  79. }
  80. }
  81. // read new commands
  82. LGSEVENT event;
  83. while( m_Queue.Pop( event ) )
  84. {
  85. switch( event.id )
  86. {
  87. case LGSC_RESET:
  88. m_bNeedReset = TRUE;
  89. break;
  90. case LGSC_RESTART:
  91. m_bNeedRestart = TRUE;
  92. break;
  93. case LGSC_ENABLE:
  94. m_bEnable = event.bEnable;
  95. break;
  96. }
  97. }
  98. if( bCommandReceived )
  99. {
  100. if( m_bNeedRestart )
  101. {
  102. m_bNeedRestart = FALSE;
  103. pConnection->Write( (PBYTE)"qqq", 3, 200 );
  104. }
  105. else
  106. if( m_bNeedReset )
  107. {
  108. m_bNeedReset = FALSE;
  109. // needs to be done for LGS
  110. Sleep( 10 );
  111. pConnection->Write( (PBYTE)"rrr", 3, 200 );
  112. m_pSensor->PostReset();
  113. }
  114. }
  115. return TRUE;
  116. }