Simulation Core
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.
 
 
 
 
 
 

564 lines
20 KiB

  1. module UnitySignalsModule
  2. use UnitySignalVariables
  3. use SimulationVariables
  4. use RedisInterface
  5. contains
  6. subroutine UnitySignalsToJson(parent)
  7. type(json_value),pointer :: parent
  8. type(json_value),pointer :: p
  9. type(json_core) :: jsoncore
  10. call jsoncore%create_object(p,'UnitySignals')
  11. call jsoncore%add(p,"MudBucket",data%State%unitySignals%MudBucket)
  12. call jsoncore%add(p,"Elevator",data%State%unitySignals%Elevator)
  13. call jsoncore%add(p,"FillupHead",data%State%unitySignals%FillupHead)
  14. call jsoncore%add(p,"Ibop",data%State%unitySignals%Ibop)
  15. call jsoncore%add(p,"Kelly",data%State%unitySignals%Kelly)
  16. call jsoncore%add(p,"MouseHole",data%State%unitySignals%MouseHole)
  17. call jsoncore%add(p,"OperationCondition",data%State%unitySignals%OperationCondition)
  18. call jsoncore%add(p,"SafetyValve",data%State%unitySignals%SafetyValve)
  19. call jsoncore%add(p,"operation",data%State%unitySignals%operation)
  20. call jsoncore%add(p,"Slips",data%State%unitySignals%Slips)
  21. call jsoncore%add(p,"Slips_S",data%State%unitySignals%Slips_S)
  22. call jsoncore%add(p,"Swing",data%State%unitySignals%Swing)
  23. call jsoncore%add(p,"Swing_S",data%State%unitySignals%Swing_S)
  24. call jsoncore%add(p,"TdsBackupClamp",data%State%unitySignals%TdsBackupClamp)
  25. call jsoncore%add(p,"TdsSpine",data%State%unitySignals%TdsSpine)
  26. call jsoncore%add(p,"TdsSwing",data%State%unitySignals%TdsSwing)
  27. call jsoncore%add(p,"TdsTong",data%State%unitySignals%TdsTong)
  28. call jsoncore%add(p,"Tong",data%State%unitySignals%Tong)
  29. call jsoncore%add(p,"Tong_S",data%State%unitySignals%Tong_S)
  30. call jsoncore%add(p,"TdsConnectionModes",data%State%unitySignals%TdsConnectionModes)
  31. call jsoncore%add(p,"TdsElevatorModes",data%State%unitySignals%TdsElevatorModes)
  32. call jsoncore%add(parent,p)
  33. end subroutine
  34. subroutine UnitySignalsFromJson(jsonfile)
  35. type(json_file)::jsonfile
  36. logical::found
  37. call jsonfile%get('UnitySignals.MudBucket',data%State%unitySignals%MudBucket,found)
  38. if ( .not. found ) call logg(4,"Not found: unitySignals%MudBucket")
  39. call jsonfile%get('UnitySignals.Elevator',data%State%unitySignals%Elevator,found)
  40. if ( .not. found ) call logg(4,"Not found: unitySignals%Elevator")
  41. call jsonfile%get('UnitySignals.FillupHead',data%State%unitySignals%FillupHead,found)
  42. if ( .not. found ) call logg(4,"Not found: unitySignals%FillupHead")
  43. call jsonfile%get('UnitySignals.Ibop',data%State%unitySignals%Ibop,found)
  44. if ( .not. found ) call logg(4,"Not found: unitySignals%Ibop")
  45. call jsonfile%get('UnitySignals.Kelly',data%State%unitySignals%Kelly,found)
  46. if ( .not. found ) call logg(4,"Not found: unitySignals%Kelly")
  47. call jsonfile%get('UnitySignals.MouseHole',data%State%unitySignals%MouseHole,found)
  48. if ( .not. found ) call logg(4,"Not found: unitySignals%MouseHole")
  49. call jsonfile%get('UnitySignals.OperationCondition',data%State%unitySignals%OperationCondition,found)
  50. if ( .not. found ) call logg(4,"Not found: unitySignals%OperationCondition")
  51. call jsonfile%get('UnitySignals.SafetyValve',data%State%unitySignals%SafetyValve,found)
  52. if ( .not. found ) call logg(4,"Not found: unitySignals%SafetyValve")
  53. call jsonfile%get('UnitySignals.operation',data%State%unitySignals%operation,found)
  54. if ( .not. found ) call logg(4,"Not found: unitySignals%operation")
  55. call jsonfile%get('UnitySignals.Slips',data%State%unitySignals%Slips,found)
  56. if ( .not. found ) call logg(4,"Not found: unitySignals%Slips")
  57. call jsonfile%get('UnitySignals.Slips_S',data%State%unitySignals%Slips_S,found)
  58. if ( .not. found ) call logg(4,"Not found: unitySignals%Slips_S")
  59. call jsonfile%get('UnitySignals.Swing',data%State%unitySignals%Swing,found)
  60. if ( .not. found ) call logg(4,"Not found: unitySignals%Swing")
  61. call jsonfile%get('UnitySignals.Swing_S',data%State%unitySignals%Swing_S,found)
  62. if ( .not. found ) call logg(4,"Not found: unitySignals%Swing_S")
  63. call jsonfile%get('UnitySignals.TdsBackupClamp',data%State%unitySignals%TdsBackupClamp,found)
  64. if ( .not. found ) call logg(4,"Not found: unitySignals%TdsBackupClamp")
  65. call jsonfile%get('UnitySignals.TdsSpine',data%State%unitySignals%TdsSpine,found)
  66. if ( .not. found ) call logg(4,"Not found: unitySignals%TdsSpine")
  67. call jsonfile%get('UnitySignals.TdsSwing',data%State%unitySignals%TdsSwing,found)
  68. if ( .not. found ) call logg(4,"Not found: unitySignals%TdsSwing")
  69. call jsonfile%get('UnitySignals.TdsTong',data%State%unitySignals%TdsTong,found)
  70. if ( .not. found ) call logg(4,"Not found: unitySignals%TdsTong")
  71. call jsonfile%get('UnitySignals.Tong',data%State%unitySignals%Tong,found)
  72. if ( .not. found ) call logg(4,"Not found: unitySignals%Tong")
  73. call jsonfile%get('UnitySignals.Tong_S',data%State%unitySignals%Tong_S,found)
  74. if ( .not. found ) call logg(4,"Not found: unitySignals%Tong_S")
  75. call jsonfile%get('UnitySignals.TdsConnectionModes',data%State%unitySignals%TdsConnectionModes,found)
  76. if ( .not. found ) call logg(4,"Not found: unitySignals%TdsConnectionModes")
  77. call jsonfile%get('UnitySignals.TdsElevatorModes',data%State%unitySignals%TdsElevatorModes,found)
  78. if ( .not. found ) call logg(4,"Not found: unitySignals%TdsElevatorModes")
  79. end subroutine
  80. subroutine Set_TdsElevatorModes(v)
  81. implicit none
  82. integer , intent(in) :: v
  83. #ifdef ExcludeExtraChanges
  84. if(data%State%unitySignals%TdsElevatorModes == v) return
  85. #endif
  86. data%State%unitySignals%TdsElevatorModes = v
  87. !**call TdsElevatorModesEnum%OnTdsElevatorModesChange%RunAll()
  88. end subroutine
  89. integer function Get_TdsElevatorModes()
  90. implicit none
  91. Get_TdsElevatorModes = data%State%unitySignals%TdsElevatorModes
  92. end function
  93. subroutine Set_Ibop_Install()
  94. implicit none
  95. call Set_Ibop(IBOP_INSTALL)
  96. end subroutine
  97. subroutine Set_Ibop_Remove()
  98. implicit none
  99. call Set_Ibop(IBOP_REMOVE)
  100. end subroutine
  101. subroutine Set_Tong(v)
  102. implicit none
  103. integer , intent(in) :: v
  104. if(data%State%unitySignals%Tong == v) return
  105. data%State%unitySignals%Tong = v
  106. if(print_log) print*, 'Tong=', data%State%unitySignals%Tong
  107. if(data%State%unitySignals%Tong==TONG_MAKEUP_BEGIN) call publishMessageToChannel("TONG_MAKEUP_BEGIN")
  108. if(data%State%unitySignals%Tong==TONG_BREAKOUT_BEGIN) call publishMessageToChannel("TONG_BREAKOUT_BEGIN")
  109. !**call data%State%unitySignals%OnTongChange%RunAll()
  110. end subroutine
  111. integer function Get_Tong()
  112. implicit none
  113. Get_Tong = data%State%unitySignals%Tong
  114. end function
  115. subroutine Set_TdsTong(v)
  116. implicit none
  117. integer , intent(in) :: v
  118. #ifdef ExcludeExtraChanges
  119. if(data%State%unitySignals%TdsTong == v) return
  120. #endif
  121. data%State%unitySignals%TdsTong = v
  122. #ifdef deb
  123. if(print_log) print*, 'TdsTong=', data%State%unitySignals%TdsTong
  124. #endif
  125. !**call data%State%unitySignals%OnTdsTongChange%RunAll()
  126. end subroutine
  127. integer function Get_TdsTong()
  128. implicit none
  129. Get_TdsTong = data%State%unitySignals%TdsTong
  130. end function
  131. subroutine Set_TdsSwing(v)
  132. implicit none
  133. integer , intent(in) :: v
  134. #ifdef ExcludeExtraChanges
  135. if(data%State%unitySignals%TdsSwing == v) return
  136. #endif
  137. data%State%unitySignals%TdsSwing = v
  138. #ifdef deb
  139. if(print_log) print*, 'TdsSwing=', data%State%unitySignals%TdsSwing
  140. #endif
  141. !**call data%State%unitySignals%OnTdsSwingChange%RunAll()
  142. end subroutine
  143. integer function Get_TdsSwing()
  144. implicit none
  145. Get_TdsSwing = data%State%unitySignals%TdsSwing
  146. end function
  147. subroutine Set_TdsSpine(v)
  148. implicit none
  149. integer , intent(in) :: v
  150. #ifdef ExcludeExtraChanges
  151. if(data%State%unitySignals%TdsSpine == v) return
  152. #endif
  153. data%State%unitySignals%TdsSpine = v
  154. #ifdef deb
  155. if(print_log) print*, 'TdsSpine=', data%State%unitySignals%TdsSpine
  156. #endif
  157. !**call data%State%unitySignals%OnTdsSpineChange%RunAll()
  158. end subroutine
  159. integer function Get_TdsSpine()
  160. implicit none
  161. Get_TdsSpine = data%State%unitySignals%TdsSpine
  162. end function
  163. subroutine Set_TdsBackupClamp(v)
  164. implicit none
  165. integer , intent(in) :: v
  166. #ifdef ExcludeExtraChanges
  167. if(data%State%unitySignals%TdsBackupClamp == v) return
  168. #endif
  169. data%State%unitySignals%TdsBackupClamp = v
  170. #ifdef deb
  171. if(print_log) print*, 'TdsBackupClamp=', data%State%unitySignals%TdsBackupClamp
  172. #endif
  173. !**call data%State%unitySignals%OnTdsBackupClampChange%RunAll()
  174. end subroutine
  175. integer function Get_TdsBackupClamp()
  176. implicit none
  177. Get_TdsBackupClamp = data%State%unitySignals%TdsBackupClamp
  178. end function
  179. subroutine Set_Swing(v)
  180. implicit none
  181. integer , intent(in) :: v
  182. #ifdef ExcludeExtraChanges
  183. if(data%State%unitySignals%Swing == v) return
  184. #endif
  185. data%State%unitySignals%Swing = v
  186. #ifdef deb
  187. if(print_log) print*, 'Swing=', data%State%unitySignals%Swing
  188. #endif
  189. !**call data%State%unitySignals%OnSwingChange%RunAll()
  190. end subroutine
  191. integer function Get_Swing()
  192. implicit none
  193. Get_Swing = data%State%unitySignals%Swing
  194. end function
  195. !//TODO: apparently every thing is started here for slips
  196. subroutine Set_Slips(v)
  197. implicit none
  198. integer , intent(in) :: v
  199. if(data%State%unitySignals%Slips == v) return
  200. data%State%unitySignals%Slips = v
  201. if(print_log) print*, 'Slips=', data%State%unitySignals%Slips
  202. if(v==SLIPS_SET_BEGIN) call publishMessageToChannel("SLIPS_SET_BEGIN")
  203. if(v==SLIPS_UNSET_BEGIN) call publishMessageToChannel("SLIPS_UNSET_BEGIN")
  204. !**call data%State%unitySignals%OnSlipsChange%RunAll()
  205. end subroutine
  206. integer function Get_Slips()
  207. implicit none
  208. Get_Slips = data%State%unitySignals%Slips
  209. end function
  210. subroutine Set_Operation(i)
  211. implicit none
  212. integer, intent (in) :: i
  213. data%State%unitySignals%operation = i
  214. end subroutine
  215. subroutine Set_SafetyValve(v)
  216. implicit none
  217. integer , intent(in) :: v
  218. #ifdef ExcludeExtraChanges
  219. if(data%State%unitySignals%SafetyValve == v) return
  220. #endif
  221. data%State%unitySignals%SafetyValve = v
  222. #ifdef deb
  223. if(data%State%unitySignals%SafetyValve == SAFETY_VALVE_NEUTRAL) then
  224. if(print_log) print*, 'SafetyValve=SAFETY_VALVE_NEUTRAL'
  225. else if (data%State%unitySignals%SafetyValve == SAFETY_VALVE_INSTALL) then
  226. if(print_log) print*, 'SafetyValve=SAFETY_VALVE_INSTALL'
  227. else if (data%State%unitySignals%SafetyValve == SAFETY_VALVE_INSTALL) then
  228. if(print_log) print*, 'SafetyValve=SAFETY_VALVE_REMOVE'
  229. endif
  230. #endif
  231. !**call data%State%unitySignals%OnSafetyValveChange%RunAll()
  232. end subroutine
  233. integer function Get_SafetyValve()
  234. implicit none
  235. Get_SafetyValve = data%State%unitySignals%SafetyValve
  236. end function
  237. subroutine Set_SafetyValve_Install()
  238. implicit none
  239. call Set_SafetyValve(SAFETY_VALVE_INSTALL)
  240. end subroutine
  241. subroutine Set_SafetyValve_Remove()
  242. implicit none
  243. call Set_SafetyValve(SAFETY_VALVE_REMOVE)
  244. end subroutine
  245. subroutine Set_OperationCondition(v)
  246. ! use CKellyEnumVariables
  247. implicit none
  248. integer , intent(in) :: v
  249. #ifdef ExcludeExtraChanges
  250. if(data%State%unitySignals%OperationCondition == v) return
  251. #endif
  252. data%State%unitySignals%OperationCondition = v
  253. #ifdef deb
  254. if(print_log) print*, 'OperationCondition=', data%State%unitySignals%OperationCondition
  255. #endif
  256. !**call data%State%unitySignals%OnOperationConditionChange%RunAll()
  257. !**call data%State%unitySignals%OnOperationConditionChangeInt%RunAll(data%State%unitySignals%OperationCondition)
  258. end subroutine
  259. integer function Get_OperationCondition()
  260. implicit none
  261. Get_OperationCondition = data%State%unitySignals%OperationCondition
  262. end function
  263. subroutine Evaluate_OperationCondition()
  264. implicit none
  265. end subroutine
  266. subroutine Set_MouseHole(v)
  267. implicit none
  268. integer , intent(in) :: v
  269. #ifdef ExcludeExtraChanges
  270. if(data%State%unitySignals%MouseHole == v) return
  271. #endif
  272. !call sleep(2)
  273. data%State%unitySignals%MouseHole = v
  274. #ifdef deb
  275. if(print_log) print*, 'MouseHole=', data%State%unitySignals%MouseHole
  276. #endif
  277. !**call data%State%unitySignals%OnMouseHoleChange%RunAll()
  278. end subroutine
  279. integer function Get_MouseHole()
  280. implicit none
  281. Get_MouseHole = data%State%unitySignals%MouseHole
  282. end function
  283. subroutine Set_Kelly(v)
  284. implicit none
  285. integer , intent(in) :: v
  286. #ifdef ExcludeExtraChanges
  287. if(data%State%unitySignals%Kelly == v) return
  288. #endif
  289. data%State%unitySignals%Kelly = v
  290. #ifdef deb
  291. if(print_log) print*, 'Kelly=', data%State%unitySignals%Kelly
  292. #endif
  293. !**call data%State%unitySignals%OnKellyChange%RunAll()
  294. end subroutine
  295. integer function Get_Kelly()
  296. implicit none
  297. Get_Kelly = data%State%unitySignals%Kelly
  298. end function
  299. subroutine Set_Ibop(v)
  300. implicit none
  301. integer , intent(in) :: v
  302. #ifdef ExcludeExtraChanges
  303. if(data%State%unitySignals%Ibop == v) return
  304. #endif
  305. data%State%unitySignals%Ibop = v
  306. #ifdef deb
  307. if(print_log) print*, 'Ibop=', data%State%unitySignals%Ibop
  308. #endif
  309. !**call data%State%unitySignals%OnIbopChange%RunAll()
  310. end subroutine
  311. integer function Get_Ibop()
  312. implicit none
  313. Get_Ibop = data%State%unitySignals%Ibop
  314. end function
  315. subroutine Set_FillupHead(v)
  316. use CManifolds, only: ToggleFillupHead
  317. implicit none
  318. integer , intent(in) :: v
  319. #ifdef ExcludeExtraChanges
  320. if(data%State%unitySignals%FillupHead == v) return
  321. #endif
  322. data%State%unitySignals%FillupHead = v
  323. if (data%State%unitySignals%FillupHead == FILLUP_HEAD_INSTALL) then
  324. call ToggleFillupHead(.true.)
  325. else if (data%State%unitySignals%FillupHead == FILLUP_HEAD_REMOVE) then
  326. call ToggleFillupHead(.false.)
  327. endif
  328. #ifdef deb
  329. if(print_log) print*, 'FillupHead=', data%State%unitySignals%FillupHead
  330. #endif
  331. !**call data%State%unitySignals%OnFillupHeadChange%RunAll()
  332. end subroutine
  333. integer function Get_FillupHead()
  334. implicit none
  335. Get_FillupHead = data%State%unitySignals%FillupHead
  336. end function
  337. subroutine Evaluate_FillupHead()
  338. use CHoistingVariables
  339. use SimulationVariables
  340. use CStudentStationVariables!, only: data%State%StudentStation%FillupHeadInstallation
  341. implicit none
  342. if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
  343. #ifdef OST
  344. if(print_log) print*, 'Evaluate_FillupHead=TopDrive'
  345. #endif
  346. endif
  347. if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
  348. #ifdef OST
  349. if(print_log) print*, 'Evaluate_FillupHead=Kelly'
  350. #endif
  351. endif
  352. if (Get_FillupHead() == FILLUP_HEAD_INSTALL) then
  353. data%State%StudentStation%FillupHeadInstallation = .true.
  354. else if (Get_FillupHead() == FILLUP_HEAD_REMOVE) then
  355. data%State%StudentStation%FillupHeadInstallation = .false.
  356. endif
  357. end subroutine
  358. subroutine Set_Elevator(v)
  359. implicit none
  360. integer , intent(in) :: v
  361. #ifdef ExcludeExtraChanges
  362. if(data%State%unitySignals%Elevator == v) return
  363. #endif
  364. data%State%unitySignals%Elevator = v
  365. #ifdef deb
  366. if(print_log) print*, 'Elevator=', data%State%unitySignals%Elevator
  367. #endif
  368. !**call data%State%unitySignals%OnElevatorChange%RunAll()
  369. end subroutine
  370. integer function Get_Elevator()
  371. implicit none
  372. Get_Elevator = data%State%unitySignals%Elevator
  373. end function
  374. subroutine Set_MudBucket(v)
  375. use CManifolds, only: ToggleMudBox
  376. implicit none
  377. integer , intent(in) :: v
  378. #ifdef ExcludeExtraChanges
  379. if(data%State%unitySignals%MudBucket == v) return
  380. #endif
  381. data%State%unitySignals%MudBucket = v
  382. if (data%State%unitySignals%MudBucket == MUD_BUCKET_INSTALL) then
  383. call ToggleMudBox(.true.)
  384. else if (data%State%unitySignals%MudBucket == MUD_BUCKET_REMOVE) then
  385. call ToggleMudBox(.false.)
  386. endif
  387. #ifdef deb
  388. if(print_log) print*, 'MudBucket=', data%State%unitySignals%MudBucket
  389. #endif
  390. !**call data%State%unitySignals%OnMudBucketChange%RunAll()
  391. end subroutine
  392. integer function Get_MudBucket()
  393. implicit none
  394. Get_MudBucket = data%State%unitySignals%MudBucket
  395. end function
  396. subroutine Evaluate_MudBucket()
  397. use CStudentStationVariables!, only: data%State%StudentStation%MudBoxInstallation
  398. implicit none
  399. if (Get_MudBucket() == MUD_BUCKET_INSTALL) then
  400. data%State%StudentStation%MudBoxInstallation = .true.
  401. else if (Get_MudBucket() == MUD_BUCKET_REMOVE) then
  402. data%State%StudentStation%MudBoxInstallation = .false.
  403. endif
  404. end subroutine
  405. !! Moved from CTdsConnectionModeEnum
  406. subroutine Set_TdsConnectionModes(v)
  407. use CManifolds, Only: KellyConnected, KellyDisconnected
  408. implicit none
  409. integer , intent(in) :: v
  410. #ifdef ExcludeExtraChanges
  411. if(data%State%unitySignals%TdsConnectionModes == v) return
  412. #endif
  413. data%State%unitySignals%TdsConnectionModes = v
  414. if(data%State%unitySignals%TdsConnectionModes == TDS_CONNECTION_NOTHING) then
  415. call KellyDisconnected()
  416. else
  417. call KellyConnected()
  418. endif
  419. #ifdef deb
  420. if(print_log) print*, 'data%State%unitySignals%TdsConnectionModes=', data%State%unitySignals%TdsConnectionModes
  421. #endif
  422. !**call data%State%unitySignals%OnTdsConnectionModesChange%RunAll()
  423. end subroutine
  424. integer function Get_TdsConnectionModes()
  425. use SimulationVariables
  426. implicit none
  427. Get_TdsConnectionModes = data%State%unitySignals%TdsConnectionModes
  428. end function
  429. subroutine Evaluate_TdsConnectionModes()
  430. use CUnityInputs
  431. use SimulationVariables
  432. use UnityModule
  433. implicit none
  434. if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
  435. !TOPDRIVE-CODE=3
  436. if (Get_TdsStemIn() .and.&
  437. Get_TdsSpine() == TDS_SPINE_CONNECT_END .and.&
  438. !TopDriveDrillTorqueState == TdsMu_SPINE
  439. Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING) then
  440. call Set_TdsConnectionModes(TDS_CONNECTION_SPINE)
  441. return
  442. end if
  443. !TOPDRIVE-CODE=4
  444. if (Get_TdsTong() == TDS_TONG_MAKEUP_END .and.&
  445. Get_TdsConnectionModes() == TDS_CONNECTION_SPINE ) then
  446. call Set_TdsConnectionModes(TDS_CONNECTION_STRING)
  447. data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF
  448. return
  449. end if
  450. !TOPDRIVE-CODE=5
  451. if (Get_TdsTong() == TDS_TONG_BREAKOUT_END .and.&
  452. Get_TdsConnectionModes() == TDS_CONNECTION_STRING ) then
  453. call Set_TdsConnectionModes(TDS_CONNECTION_SPINE)
  454. data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF
  455. return
  456. end if
  457. !TOPDRIVE-CODE=6
  458. if (Get_TdsSpine() == TDS_SPINE_DISCONNECT_END .and.&
  459. !Get_TdsStemIn() == .false. .and.&
  460. Get_TdsConnectionModes() == TDS_CONNECTION_SPINE) then
  461. call Set_TdsConnectionModes(TDS_CONNECTION_NOTHING)
  462. return
  463. end if
  464. endif
  465. ! if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
  466. ! if(print_log) print*, 'Evaluate_TdsConnectionModes=Kelly'
  467. ! endif
  468. end subroutine
  469. end module UnitySignalsModule