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.

402 lines
8.5 KiB

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. m_pBoard = NULL;
  19. m_pShadow = NULL;
  20. m_pCamera = NULL;
  21. LG=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) );
  31. memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow) );
  32. memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun) );
  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(CCRT_Log *CLG){
  119. m_pBoard = NULL;
  120. m_pShadow = NULL;
  121. m_pCamera = NULL;
  122. LG=CLG;
  123. #ifdef COMM_WITHOUT_INTERRUPTS
  124. m_pCameraComm = NULL;
  125. #endif
  126. m_bRun = TRUE;
  127. m_nSerialNumber = 0;
  128. memset( m_pSerialNumber, 0, sizeof(m_pSerialNumber) );
  129. m_nAddress = 0;
  130. // init error timing
  131. memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST) );
  132. memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow) );
  133. memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun) );
  134. m_dwTimePower = 0UL;
  135. m_LRFDisable.bMaster = m_LRFDisable.bSlave = FALSE;
  136. #ifndef LGS_DISABLE_FILE_SYSTEM
  137. // file system
  138. memset( &m_FileSystemPacket, 0, sizeof(m_FileSystemPacket) );
  139. #endif
  140. // prepare software version
  141. #ifdef LGS_MIRROR
  142. s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %dM,%s", CLgVersion::GetBuildTimeStr(), LGS_MIRROR,
  143. #else
  144. s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %s", CLgVersion::GetBuildTimeStr(),
  145. #endif
  146. #ifdef BOARD_A2D_FOUR_SAMPLES
  147. "4S"
  148. #else
  149. "1S"
  150. #endif
  151. #ifdef COMPILE_AS_ANGLES
  152. ",AN"
  153. #endif
  154. #ifdef COMPILE_AS_GETFILE
  155. ",GF"
  156. #endif
  157. #ifdef DEBUG_BOARD_SET_TEST_BIT
  158. ",TB"
  159. #endif
  160. #ifdef DEBUG_ENABLE_OLD_BOARD
  161. ",OB"
  162. #endif
  163. #ifdef DEBUG_ENABLE_SEND_BOARDDATA
  164. ",SD"
  165. #endif
  166. #ifdef COMM_RS485_PREVENT_ECHO
  167. ",PE"
  168. #endif
  169. #ifdef COMM_WITHOUT_INTERRUPTS
  170. ",NI"
  171. #endif
  172. #ifdef BOARD_DEFFERED_PROCESSING
  173. ",DP"
  174. #endif
  175. #ifdef BOARD_SUN_BIT_DISABLE
  176. ",NS"
  177. #endif
  178. #ifdef LGS_PROTOCOL_TRANSMIT_DELAY
  179. ",TD"
  180. #endif
  181. #ifdef BOARD_LINEARIZATION_ENABLE
  182. ",LE"
  183. #endif
  184. #ifdef WATCHDOG_ENABLED
  185. ",WD"
  186. #endif
  187. #ifdef BOARD_POWER_ENABLE
  188. ",PM"
  189. #endif
  190. #ifndef EMBEDDED_CAMERA_DISABLED
  191. ",C"
  192. #endif
  193. #ifdef EMBEDDED_CAMERA_MIGVAN
  194. "O"
  195. #endif
  196. #ifdef EMBEDDED_CAMERA_MIC
  197. "M"
  198. #endif
  199. #ifdef EMBEDDED_CAMERA_JVC
  200. "J"
  201. #endif
  202. #ifdef EMBEDDED_CAMERA_PHILIPS
  203. "B"
  204. #endif
  205. #ifdef EMBEDDED_CAMERA_VICON
  206. "V"
  207. #endif
  208. #ifdef EMBEDDED_CAMERA_PELCO
  209. "P"
  210. #endif
  211. #ifdef EMBEDDED_CAMERA_HEBRON
  212. "H"
  213. #endif
  214. #ifdef EMBEDDED_CAMERA_AMERICAN_DYNAMICS
  215. "A"
  216. #endif
  217. );
  218. }
  219. CKernel::~CKernel()
  220. {
  221. Destroy();
  222. }
  223. BOOL CKernel::Create( CBoard *pBoard, CComm485 *pCommPort, CShadow *pShadow, CComm485 *pCameraComm, CComm485::PORTS nCameraPort )
  224. {
  225. Destroy();
  226. m_pShadow = pShadow;
  227. m_pBoard = pBoard;
  228. m_pComm485 = pCommPort;
  229. // create transport protocol
  230. if( !m_Protocol.Create( pCommPort ) )
  231. return FALSE;
  232. // printf( "protocol created...\n" );
  233. // assume that no camera
  234. LGS::CAMERA_PARAMETERS cp;
  235. cp.eType = LGS::CAMERA_TYPE_NONE;
  236. cp.nShift = 0;
  237. cp.bAuto = FALSE;
  238. cp.nAutoDelay = 0;
  239. // assume that no relay
  240. LGS::RELAY_PARAMETERS rp;
  241. rp.bAuto = FALSE;
  242. rp.nAutoDelay = 0;
  243. rp.bNormallyClose = FALSE;
  244. // no voltage control by default
  245. LGS::VOLTAGE_PARAMETERS vp;
  246. vp.bControl = FALSE;
  247. // both lasers enabled
  248. m_LRFDisable.bMaster = FALSE;
  249. m_LRFDisable.bSlave = FALSE;
  250. // load settings
  251. LoadSettings( (PCHAR)m_pSerialNumber, &m_nSerialNumber, &m_nAddress, &cp, &rp, &vp, &m_LRFDisable );
  252. // load user settings
  253. AUTO_RESET AutoReset;
  254. BOARD_SETTINGS BoardSettings;
  255. SWITCHER_SETTINGS SwitcherSettings;
  256. LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
  257. // printf( "settings loaded...\n" );
  258. m_pCamera = new CCamera;
  259. // printf( "camera allocated...\n" );
  260. #ifdef COMM_WITHOUT_INTERRUPTS
  261. m_pCameraComm = pCameraComm;
  262. #endif
  263. if( !m_pCamera || !m_pCamera->Create( (LGS::E_CAMERA_TYPE)cp.eType, pCameraComm, nCameraPort, &cp, &SwitcherSettings ) )
  264. {
  265. printf( "Can't create camera\n" );
  266. return FALSE;
  267. }
  268. // printf( "camera created...\n" );
  269. if( !m_Relay.Create( m_pBoard, &rp ) )
  270. {
  271. printf( "Can't create relay\n" );
  272. return FALSE;
  273. }
  274. // printf( "relay created...\n" );
  275. if( !m_Voltage.Create( &vp ) )
  276. {
  277. printf( "Can't create voltage control\n" );
  278. return FALSE;
  279. }
  280. // printf( "voltage created...\n" );
  281. if( !m_Tracker[0].Create( m_LRFDisable.bMaster, m_pCamera, &m_Relay, &m_AutoReset ) )
  282. return FALSE;
  283. // printf( "tracker 1 created...\n" );
  284. if( !m_Tracker[1].Create( m_LRFDisable.bSlave, m_pCamera, &m_Relay, &m_AutoReset ) )
  285. return FALSE;
  286. // printf( "tracker 2 created...\n" );
  287. #ifdef DEBUG_GRAPH_SCREEN_SST
  288. m_Tracker[0].SetIndex(0);
  289. m_Tracker[1].SetIndex(1);
  290. #endif
  291. if( !m_Detector[0].Create( m_LRFDisable.bMaster, &m_Tracker[0], pShadow, 0, "init_m.ini" ) )
  292. return FALSE;
  293. // printf( "detector 1 created...\n" );
  294. #ifdef LGS_MIRROR
  295. if( !m_Detector[1].Create( m_LRFDisable.bSlave, &m_Tracker[0], pShadow, 0, "init_s.ini" ) )
  296. return FALSE;
  297. #else
  298. if( !m_Detector[1].Create( m_LRFDisable.bSlave, &m_Tracker[1], pShadow, LGS_MAX_DETECTOR_ANGLES / 2, "init_s.ini" ) )
  299. return FALSE;
  300. #endif
  301. // printf( "detector 2 created...\n" );
  302. if( !m_GetFile.Create() )
  303. return FALSE;
  304. // printf( "get file created...\n" );
  305. if( !m_Calibrator[0].Create( "lt0.ini" ) )
  306. {
  307. printf( "Can't create linearization filter for master\n" ) ;
  308. return FALSE;
  309. }
  310. // printf( "calibration 1 created...\n" );
  311. if( !m_Calibrator[1].Create( "lt1.ini" ) )
  312. {
  313. printf( "Can't create linearization filter for slave\n" ) ;
  314. return FALSE;
  315. }
  316. // printf( "calibration 2 created...\n" );
  317. m_pBoard->Reset();
  318. #ifdef WATCHDOG_ENABLED
  319. // start watchdog
  320. if( !m_WatchDog.Create() )
  321. {
  322. printf( "Can't create watchdog\n" ) ;
  323. return FALSE;
  324. }
  325. // printf( "watchdog created...\n" );
  326. #endif
  327. #ifdef LGS_MIRROR
  328. m_bWaitFirstZero = TRUE;
  329. #endif
  330. m_AutoReset.Create( &AutoReset );
  331. return TRUE;
  332. }
  333. void CKernel::Destroy()
  334. {
  335. if( m_pCamera )
  336. {
  337. delete m_pCamera;
  338. m_pCamera = NULL;
  339. }
  340. #ifdef COMM_WITHOUT_INTERRUPTS
  341. m_pCameraComm = NULL;
  342. #endif
  343. m_GetFile.Destroy();
  344. m_Protocol.Destroy();
  345. m_Detector[0].Destroy();
  346. m_Detector[1].Destroy();
  347. m_Tracker[0].Destroy();
  348. m_Tracker[1].Destroy();
  349. m_Voltage.Destroy();
  350. m_Relay.Destroy();
  351. m_Calibrator[0].Destroy();
  352. m_Calibrator[1].Destroy();
  353. m_AutoReset.Destroy();
  354. m_pBoard = NULL;
  355. m_pShadow = NULL;
  356. m_bRun = TRUE;
  357. }