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.

181 lines
4.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: DeviceMigvanPTZ.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DeviceMigvanPTZ.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "Device.h"
  16. #include "DeviceMigvanPTZ.h"
  17. #include "SocketMigvanPTZ.h"
  18. #include "..\..\LgLib\Version.h"
  19. #include "SensorArray.h"
  20. CDeviceMigvanPTZ::CDeviceMigvanPTZ()
  21. {
  22. m_bEnable = FALSE;
  23. // static DWORD nID = 0;
  24. // SetID( nID++ );
  25. // m_MessageDispatcher.SetID( nID++ );
  26. m_MessageDispatcher.CLgLinkP<CLgNetObject,CLgNetObject,CLgNetObjectChild>::Link( this );
  27. ::ZeroMemory( m_pHardwareID, sizeof( m_pHardwareID ) );
  28. m_bAutoInit = FALSE;
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceMigvanPTZ::CDeviceMigvanPTZ") );
  30. }
  31. CDeviceMigvanPTZ::~CDeviceMigvanPTZ()
  32. {
  33. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceMigvanPTZ::~CDeviceMigvanPTZ") );
  34. }
  35. BOOL CDeviceMigvanPTZ::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
  36. {
  37. // check for demo mode
  38. BOOL bDemo = FALSE;
  39. if( CDevice::GetSocket() )
  40. {
  41. CSensorArray *pSensorArray = CDevice::GetSocket()->GetSensorArray();
  42. if( pSensorArray )
  43. bDemo = pSensorArray->IsDemo();
  44. }
  45. // if demo mode to do emulation
  46. if( bDemo )
  47. {
  48. // "process" commands
  49. PTZEVENT event;
  50. while( m_Queue.Pop( event ) )
  51. {
  52. switch( event.id )
  53. {
  54. case PTZC_INIT:
  55. case PTZC_GET_PTZ:
  56. CDevicePTZ::SetPTZ( 0, 0, 0 );
  57. break;
  58. case PTZC_SET_PTZ:
  59. CDevicePTZ::SetPTZ( event.ptz.pan, event.ptz.tilt, event.ptz.zoom );
  60. break;
  61. case PTZC_RESET:
  62. case PTZC_PAN:
  63. case PTZC_TILT:
  64. case PTZC_ZOOM:
  65. case PTZC_IRIS:
  66. CDevicePTZ::SetReady();
  67. break;
  68. }
  69. }
  70. // to prevent processor overheating
  71. Sleep( 10 );
  72. return TRUE;
  73. }
  74. // to do normal processing
  75. // call actual DeviceProc
  76. CLgNetDeviceMigvanPTZ::DeviceProc( (CLgNetSocketMigvanPTZ*)GetSocket(), pProtocol );
  77. CLgNetMessageMigvanPTZ msg;
  78. msg.SetSenderID( m_MessageDispatcher.GetID() );
  79. msg.SetDistinationID( GetID() );
  80. // process commands
  81. PTZEVENT event;
  82. while( m_Queue.Pop( event ) )
  83. {
  84. switch( event.id )
  85. {
  86. case PTZC_INIT:
  87. if( m_bAutoInit )
  88. {
  89. msg.BuildCmdAutoInit();
  90. m_MessageDispatcher.SendMessageToChild( msg );
  91. }
  92. else
  93. {
  94. msg.BuildCmdSetAddress( GetAddress(), m_pHardwareID );
  95. m_MessageDispatcher.SendMessageToChild( msg );
  96. }
  97. break;
  98. case PTZC_GET_PTZ:
  99. msg.BuildCmdGetPTZ();
  100. m_MessageDispatcher.SendMessageToChild( msg );
  101. break;
  102. case PTZC_RESET:
  103. msg.BuildCmdWarmBoot();
  104. m_MessageDispatcher.SendMessageToChild( msg );
  105. break;
  106. case PTZC_SET_PTZ:
  107. msg.BuildCmdSetPTZ( event.ptz.pan, event.ptz.tilt, event.ptz.zoom * 100.0 );
  108. m_MessageDispatcher.SendMessageToChild( msg );
  109. break;
  110. case PTZC_PAN:
  111. msg.BuildCmdMovePan( event.move.nDir == PAN_RIGHT, ( event.move.nDir == PAN_STOP ) ? 0 : event.move.speed * 100 );
  112. m_MessageDispatcher.SendMessageToChild( msg );
  113. break;
  114. case PTZC_TILT:
  115. msg.BuildCmdMoveTilt( event.move.nDir == TILT_UP, ( event.move.nDir == TILT_STOP ) ? 0 : event.move.speed * 100 );
  116. m_MessageDispatcher.SendMessageToChild( msg );
  117. break;
  118. case PTZC_ZOOM:
  119. msg.BuildCmdMoveZoom( event.move.nDir == ZOOM_TELE, ( event.move.nDir == ZOOM_STOP ) ? 0 : event.move.speed * 100 );
  120. m_MessageDispatcher.SendMessageToChild( msg );
  121. break;
  122. case PTZC_IRIS:
  123. msg.BuildCmdSetIris( event.iris.value * 100 );
  124. m_MessageDispatcher.SendMessageToChild( msg );
  125. break;
  126. default:
  127. break;
  128. }
  129. }
  130. // read messages
  131. while( m_MessageDispatcher.PopMessage( msg ) )
  132. {
  133. BYTE bCommand;
  134. if( msg.GetCommand(&bCommand) )
  135. {
  136. CLgDevicePTZ::PTZ_POSITION position;
  137. switch( bCommand )
  138. {
  139. case CLgDevicePTZMigvan::EVT_AUTO_INIT:
  140. case CLgDevicePTZMigvan::EVT_ADDRESS:
  141. CDevicePTZ::SetPTZ( 0, 0, 0 );
  142. break;
  143. case CLgDevicePTZMigvan::EVT_GET_PTZ:
  144. if( msg.GetPTZ( &position ) )
  145. CDevicePTZ::SetPTZ( position.dPan, position.dTilt, position.dZoom / 100.0 );
  146. break;
  147. case CLgDevicePTZMigvan::EVT_WARM_BOOT:
  148. CDevicePTZ::SetPTZ( 0, 0, 0 );
  149. break;
  150. case CLgDevicePTZMigvan::EVT_SET_PTZ:
  151. if( msg.GetPTZ( &position ) )
  152. CDevicePTZ::SetPTZ( position.dPan, position.dTilt, position.dZoom / 100.0 );
  153. break;
  154. case CLgDevicePTZMigvan::EVT_MOVE_PAN:
  155. case CLgDevicePTZMigvan::EVT_MOVE_TILT:
  156. case CLgDevicePTZMigvan::EVT_MOVE_ZOOM:
  157. case CLgDevicePTZMigvan::EVT_SET_IRIS:
  158. case CLgDevicePTZMigvan::EVT_COMMAND_ERROR:
  159. default:
  160. CDevicePTZ::SetReady();
  161. break;
  162. }
  163. }
  164. }
  165. return TRUE;
  166. }