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.

319 lines
6.7 KiB

4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
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: kernel_.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of kernel_.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. #include "Kernel.h"
  17. CKernel::CKernel()
  18. {
  19. m_pBoard = NULL;
  20. m_pShadow = NULL;
  21. m_pCamera = NULL;
  22. #ifdef COMM_WITHOUT_INTERRUPTS
  23. m_pCameraComm = NULL;
  24. #endif
  25. m_bRun = TRUE;
  26. m_nSerialNumber = 0;
  27. memset( m_pSerialNumber, 0, sizeof(m_pSerialNumber) );
  28. m_nAddress = 0;
  29. // init error timing
  30. memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST)*4 );
  31. memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow)*4 );
  32. memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun)*4 );
  33. m_dwTimePower = 0UL;
  34. m_LRFDisable.bMaster = m_LRFDisable.bSlave = FALSE;
  35. #ifndef LGS_DISABLE_FILE_SYSTEM
  36. // file system
  37. memset( &m_FileSystemPacket, 0, sizeof(m_FileSystemPacket) );
  38. #endif
  39. // prepare software version
  40. #ifdef LGS_MIRROR
  41. s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %dM,%s", CLgVersion::GetBuildTimeStr(), LGS_MIRROR,
  42. #else
  43. s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %s", CLgVersion::GetBuildTimeStr(),
  44. #endif
  45. #ifdef BOARD_A2D_FOUR_SAMPLES
  46. "4S"
  47. #else
  48. "1S"
  49. #endif
  50. #ifdef COMPILE_AS_ANGLES
  51. ",AN"
  52. #endif
  53. #ifdef COMPILE_AS_GETFILE
  54. ",GF"
  55. #endif
  56. #ifdef DEBUG_BOARD_SET_TEST_BIT
  57. ",TB"
  58. #endif
  59. #ifdef DEBUG_ENABLE_OLD_BOARD
  60. ",OB"
  61. #endif
  62. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  63. ",SD"
  64. #endif
  65. #ifdef COMM_RS485_PREVENT_ECHO
  66. ",PE"
  67. #endif
  68. #ifdef COMM_WITHOUT_INTERRUPTS
  69. ",NI"
  70. #endif
  71. #ifdef BOARD_DEFFERED_PROCESSING
  72. ",DP"
  73. #endif
  74. #ifdef BOARD_SUN_BIT_DISABLE
  75. ",NS"
  76. #endif
  77. #ifdef LGS_PROTOCOL_TRANSMIT_DELAY
  78. ",TD"
  79. #endif
  80. #ifdef BOARD_LINEARIZATION_ENABLE
  81. ",LE"
  82. #endif
  83. #ifdef WATCHDOG_ENABLED
  84. ",WD"
  85. #endif
  86. #ifdef BOARD_POWER_ENABLE
  87. ",PM"
  88. #endif
  89. #ifndef EMBEDDED_CAMERA_DISABLED
  90. ",C"
  91. #endif
  92. #ifdef EMBEDDED_CAMERA_MIGVAN
  93. "O"
  94. #endif
  95. #ifdef EMBEDDED_CAMERA_MIC
  96. "M"
  97. #endif
  98. #ifdef EMBEDDED_CAMERA_JVC
  99. "J"
  100. #endif
  101. #ifdef EMBEDDED_CAMERA_PHILIPS
  102. "B"
  103. #endif
  104. #ifdef EMBEDDED_CAMERA_VICON
  105. "V"
  106. #endif
  107. #ifdef EMBEDDED_CAMERA_PELCO
  108. "P"
  109. #endif
  110. #ifdef EMBEDDED_CAMERA_HEBRON
  111. "H"
  112. #endif
  113. #ifdef EMBEDDED_CAMERA_AMERICAN_DYNAMICS
  114. "A"
  115. #endif
  116. );
  117. }
  118. CKernel::~CKernel()
  119. {
  120. Destroy();
  121. }
  122. BOOL CKernel::Create( CBoard *pBoard, CComm485 *pCommPort, CShadow *pShadow, CComm485 *pCameraComm, CComm485::PORTS nCameraPort )
  123. {
  124. Destroy();
  125. m_pShadow = pShadow;
  126. m_pBoard = pBoard;
  127. m_pComm485 = pCommPort;
  128. // create transport protocol
  129. if( !m_Protocol.Create( pCommPort ) )
  130. return FALSE;
  131. // printf( "protocol created...\n" );
  132. // assume that no camera
  133. LGS::CAMERA_PARAMETERS cp;
  134. cp.eType = LGS::CAMERA_TYPE_NONE;
  135. cp.nShift = 0;
  136. cp.bAuto = FALSE;
  137. cp.nAutoDelay = 0;
  138. // assume that no relay
  139. LGS::RELAY_PARAMETERS rp;
  140. rp.bAuto = FALSE;
  141. rp.nAutoDelay = 0;
  142. rp.bNormallyClose = FALSE;
  143. // no voltage control by default
  144. LGS::VOLTAGE_PARAMETERS vp;
  145. vp.bControl = FALSE;
  146. // both lasers enabled
  147. m_LRFDisable.bMaster = FALSE;
  148. m_LRFDisable.bSlave = FALSE;
  149. // load settings
  150. LoadSettings( (PCHAR)m_pSerialNumber, &m_nSerialNumber, &m_nAddress, &cp, &rp, &vp, &m_LRFDisable );
  151. // load user settings
  152. AUTO_RESET AutoReset;
  153. BOARD_SETTINGS BoardSettings;
  154. SWITCHER_SETTINGS SwitcherSettings;
  155. LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
  156. // printf( "settings loaded...\n" );
  157. m_pCamera = new CCamera;
  158. // printf( "camera allocated...\n" );
  159. #ifdef COMM_WITHOUT_INTERRUPTS
  160. m_pCameraComm = pCameraComm;
  161. #endif
  162. if( !m_pCamera || !m_pCamera->Create( (LGS::E_CAMERA_TYPE)cp.eType, pCameraComm, nCameraPort, &cp, &SwitcherSettings ) )
  163. {
  164. printf( "Can't create camera\n" );
  165. return FALSE;
  166. }
  167. // printf( "camera created...\n" );
  168. if( !m_Relay.Create( m_pBoard, &rp ) )
  169. {
  170. printf( "Can't create relay\n" );
  171. return FALSE;
  172. }
  173. // printf( "relay created...\n" );
  174. if( !m_Voltage.Create( &vp ) )
  175. {
  176. printf( "Can't create voltage control\n" );
  177. return FALSE;
  178. }
  179. // printf( "voltage created...\n" );
  180. if( !m_Tracker[0].Create( m_LRFDisable.bMaster, m_pCamera, &m_Relay, &m_AutoReset ) )
  181. return FALSE;
  182. // printf( "tracker 1 created...\n" );
  183. #ifndef LGS_MIRROR
  184. if( !m_Tracker[1].Create( m_LRFDisable.bSlave, m_pCamera, &m_Relay, &m_AutoReset ) )
  185. return FALSE;
  186. // printf( "tracker 2 created...\n" );
  187. #endif
  188. #ifdef DEBUG_GRAPH_SCREEN_SST
  189. m_Tracker[0].SetIndex(0);
  190. #ifndef LGS_MIRROR
  191. m_Tracker[1].SetIndex(1);
  192. #endif
  193. #endif
  194. if( !m_Detector[0].Create( m_LRFDisable.bMaster, &m_Tracker[0], pShadow, 0, "init_m.ini" ) )
  195. return FALSE;
  196. // printf( "detector 1 created...\n" );
  197. if( !m_Detector[1].Create( m_LRFDisable.bSlave, &m_Tracker[1], pShadow, LGS_MAX_DETECTOR_ANGLES / 2, "init_s.ini" ) )
  198. return FALSE;
  199. // printf( "detector 2 created...\n" );
  200. #ifdef LGS_MIRROR
  201. if( !m_Detector[2].Create( m_LRFDisable.bSlave, &m_Tracker[0], pShadow, 0, "init_s.ini" ) )
  202. return FALSE;
  203. // printf( "detector 3 created...\n" );
  204. if( !m_Detector[3].Create( m_LRFDisable.bSlave, &m_Tracker[0], pShadow, 0, "init_s.ini" ) )
  205. return FALSE;
  206. // printf( "detector 4 created...\n" );
  207. #endif
  208. if( !m_GetFile.Create() )
  209. return FALSE;
  210. // printf( "get file created...\n" );
  211. if( !m_Calibrator[0].Create( "lt0.ini" ) )
  212. {
  213. printf( "Can't create linearization filter for master\n" ) ;
  214. return FALSE;
  215. }
  216. // printf( "calibration 1 created...\n" );
  217. if( !m_Calibrator[1].Create( "lt1.ini" ) )
  218. {
  219. printf( "Can't create linearization filter for slave\n" ) ;
  220. return FALSE;
  221. }
  222. // printf( "calibration 2 created...\n" );
  223. m_pBoard->Reset();
  224. #ifdef WATCHDOG_ENABLED
  225. // start watchdog
  226. if( !m_WatchDog.Create() )
  227. {
  228. printf( "Can't create watchdog\n" ) ;
  229. return FALSE;
  230. }
  231. // printf( "watchdog created...\n" );
  232. #endif
  233. #ifdef LGS_MIRROR
  234. m_bWaitFirstZero = TRUE;
  235. #endif
  236. m_AutoReset.Create( &AutoReset );
  237. return TRUE;
  238. }
  239. void CKernel::Destroy()
  240. {
  241. if( m_pCamera )
  242. {
  243. delete m_pCamera;
  244. m_pCamera = NULL;
  245. }
  246. #ifdef COMM_WITHOUT_INTERRUPTS
  247. m_pCameraComm = NULL;
  248. #endif
  249. m_GetFile.Destroy();
  250. m_Protocol.Destroy();
  251. m_Detector[0].Destroy();
  252. m_Detector[1].Destroy();
  253. m_Tracker[0].Destroy();
  254. m_Tracker[1].Destroy();
  255. m_Voltage.Destroy();
  256. m_Relay.Destroy();
  257. m_Calibrator[0].Destroy();
  258. m_Calibrator[1].Destroy();
  259. m_AutoReset.Destroy();
  260. m_pBoard = NULL;
  261. m_pShadow = NULL;
  262. m_bRun = TRUE;
  263. }