node-opcua-address-space 2.71.0 → 2.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (408) hide show
  1. package/dist/source/address_space_ts.d.ts +118 -118
  2. package/dist/source/address_space_ts.js +17 -17
  3. package/dist/source/continuation_points/continuation_point_manager.d.ts +32 -32
  4. package/dist/source/continuation_points/continuation_point_manager.js +195 -195
  5. package/dist/source/helpers/adjust_browse_direction.d.ts +5 -5
  6. package/dist/source/helpers/adjust_browse_direction.js +11 -11
  7. package/dist/source/helpers/argument_list.d.ts +34 -34
  8. package/dist/source/helpers/argument_list.js +285 -285
  9. package/dist/source/helpers/call_helpers.d.ts +6 -6
  10. package/dist/source/helpers/call_helpers.js +70 -70
  11. package/dist/source/helpers/check_event_clause.d.ts +17 -17
  12. package/dist/source/helpers/check_event_clause.js +52 -52
  13. package/dist/source/helpers/coerce_enum_value.d.ts +6 -6
  14. package/dist/source/helpers/coerce_enum_value.js +33 -33
  15. package/dist/source/helpers/dump_tools.d.ts +14 -14
  16. package/dist/source/helpers/dump_tools.js +78 -78
  17. package/dist/source/helpers/ensure_secure_access.d.ts +9 -9
  18. package/dist/source/helpers/ensure_secure_access.js +76 -76
  19. package/dist/source/helpers/make_optionals_map.d.ts +21 -21
  20. package/dist/source/helpers/make_optionals_map.js +29 -29
  21. package/dist/source/helpers/multiform_func.d.ts +11 -11
  22. package/dist/source/helpers/multiform_func.js +73 -73
  23. package/dist/source/helpers/resolve_opaque_on_address_space.d.ts +3 -3
  24. package/dist/source/helpers/resolve_opaque_on_address_space.js +36 -36
  25. package/dist/source/index.d.ts +40 -40
  26. package/dist/source/index.js +66 -66
  27. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.d.ts +12 -12
  28. package/dist/source/interfaces/alarms_and_conditions/condition_info_i.js +2 -2
  29. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.d.ts +21 -21
  30. package/dist/source/interfaces/data_access/ua_multistate_discrete_ex.js +2 -2
  31. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.d.ts +24 -24
  32. package/dist/source/interfaces/data_access/ua_multistate_value_discrete_ex.js +2 -2
  33. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.d.ts +12 -12
  34. package/dist/source/interfaces/data_access/ua_two_state_discrete_ex.js +2 -2
  35. package/dist/source/interfaces/data_access/ua_y_array_item_ex.d.ts +8 -8
  36. package/dist/source/interfaces/data_access/ua_y_array_item_ex.js +2 -2
  37. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.d.ts +12 -12
  38. package/dist/source/interfaces/state_machine/ua_exclusive_limit_state_machine_type_ex.js +2 -2
  39. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.d.ts +49 -49
  40. package/dist/source/interfaces/state_machine/ua_finite_state_machine_type.js +2 -2
  41. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.d.ts +11 -11
  42. package/dist/source/interfaces/state_machine/ua_program_state_machine_type.js +2 -2
  43. package/dist/source/interfaces/state_machine/ua_state_machine_type.d.ts +222 -222
  44. package/dist/source/interfaces/state_machine/ua_state_machine_type.js +2 -2
  45. package/dist/source/interfaces/state_machine/ua_transition_ex.d.ts +6 -6
  46. package/dist/source/interfaces/state_machine/ua_transition_ex.js +2 -2
  47. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.d.ts +8 -8
  48. package/dist/source/interfaces/ua_subscription_diagnostics_variable_ex.js +2 -2
  49. package/dist/source/loader/decode_xml_extension_object.d.ts +6 -6
  50. package/dist/source/loader/decode_xml_extension_object.js +71 -71
  51. package/dist/source/loader/ensure_datatype_extracted.d.ts +5 -5
  52. package/dist/source/loader/ensure_datatype_extracted.js +45 -45
  53. package/dist/source/loader/generateAddressSpaceRaw.d.ts +10 -10
  54. package/dist/source/loader/generateAddressSpaceRaw.js +45 -45
  55. package/dist/source/loader/load_nodeset2.d.ts +16 -16
  56. package/dist/source/loader/load_nodeset2.js +1468 -1464
  57. package/dist/source/loader/load_nodeset2.js.map +1 -1
  58. package/dist/source/loader/make_semver_compatible.d.ts +6 -0
  59. package/dist/source/loader/make_semver_compatible.js +26 -0
  60. package/dist/source/loader/make_semver_compatible.js.map +1 -0
  61. package/dist/source/loader/make_xml_extension_object_parser.d.ts +28 -28
  62. package/dist/source/loader/make_xml_extension_object_parser.js +325 -315
  63. package/dist/source/loader/make_xml_extension_object_parser.js.map +1 -1
  64. package/dist/source/loader/namespace_post_step.d.ts +6 -6
  65. package/dist/source/loader/namespace_post_step.js +47 -47
  66. package/dist/source/loader/register_node_promoter.d.ts +3 -3
  67. package/dist/source/loader/register_node_promoter.js +9 -9
  68. package/dist/source/namespace.d.ts +6 -6
  69. package/dist/source/namespace.js +2 -2
  70. package/dist/source/namespace_alarm_and_condition.d.ts +24 -24
  71. package/dist/source/namespace_alarm_and_condition.js +2 -2
  72. package/dist/source/namespace_data_access.d.ts +42 -42
  73. package/dist/source/namespace_data_access.js +2 -2
  74. package/dist/source/namespace_machine_state.d.ts +7 -7
  75. package/dist/source/namespace_machine_state.js +2 -2
  76. package/dist/source/pseudo_session.d.ts +55 -55
  77. package/dist/source/pseudo_session.js +203 -203
  78. package/dist/source/session_context.d.ts +111 -111
  79. package/dist/source/session_context.js +265 -265
  80. package/dist/source/set_namespace_meta_data.d.ts +2 -2
  81. package/dist/source/set_namespace_meta_data.js +59 -59
  82. package/dist/source/ua_root_folder.d.ts +9 -9
  83. package/dist/source/ua_root_folder.js +2 -2
  84. package/dist/source/ua_two_state_variable_ex.d.ts +23 -23
  85. package/dist/source/ua_two_state_variable_ex.js +2 -2
  86. package/dist/source/xml_writer.d.ts +9 -9
  87. package/dist/source/xml_writer.js +2 -2
  88. package/dist/src/address_space.d.ts +392 -392
  89. package/dist/src/address_space.js +1387 -1387
  90. package/dist/src/address_space_change_event_tools.d.ts +6 -6
  91. package/dist/src/address_space_change_event_tools.js +149 -149
  92. package/dist/src/address_space_private.d.ts +43 -43
  93. package/dist/src/address_space_private.js +2 -2
  94. package/dist/src/alarms_and_conditions/check_where_clause.d.ts +4 -4
  95. package/dist/src/alarms_and_conditions/check_where_clause.js +109 -109
  96. package/dist/src/alarms_and_conditions/condition.d.ts +5 -5
  97. package/dist/src/alarms_and_conditions/condition.js +80 -80
  98. package/dist/src/alarms_and_conditions/condition_info.d.ts +27 -27
  99. package/dist/src/alarms_and_conditions/condition_info.js +54 -54
  100. package/dist/src/alarms_and_conditions/condition_snapshot.d.ts +233 -233
  101. package/dist/src/alarms_and_conditions/condition_snapshot.js +666 -666
  102. package/dist/src/alarms_and_conditions/deviation_alarm_helper.d.ts +21 -21
  103. package/dist/src/alarms_and_conditions/deviation_alarm_helper.js +46 -46
  104. package/dist/src/alarms_and_conditions/extract_event_fields.d.ts +10 -10
  105. package/dist/src/alarms_and_conditions/extract_event_fields.js +89 -89
  106. package/dist/src/alarms_and_conditions/index.d.ts +18 -18
  107. package/dist/src/alarms_and_conditions/index.js +34 -34
  108. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.d.ts +64 -62
  109. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js +244 -244
  110. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.js.map +1 -1
  111. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +124 -118
  112. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +416 -416
  113. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  114. package/dist/src/alarms_and_conditions/ua_base_event_impl.d.ts +29 -29
  115. package/dist/src/alarms_and_conditions/ua_base_event_impl.js +38 -38
  116. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +36 -21
  117. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +115 -25
  118. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
  119. package/dist/src/alarms_and_conditions/ua_condition_impl.d.ts +187 -182
  120. package/dist/src/alarms_and_conditions/ua_condition_impl.js +1024 -1022
  121. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  122. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.d.ts +18 -17
  123. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js +57 -57
  124. package/dist/src/alarms_and_conditions/ua_discrete_alarm_impl.js.map +1 -1
  125. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.d.ts +30 -27
  126. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js +56 -56
  127. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.js.map +1 -1
  128. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.d.ts +11 -9
  129. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js +11 -11
  130. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.js.map +1 -1
  131. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.d.ts +40 -38
  132. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js +86 -86
  133. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.js.map +1 -1
  134. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.d.ts +10 -10
  135. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.js +7 -7
  136. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.d.ts +105 -97
  137. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js +250 -250
  138. package/dist/src/alarms_and_conditions/ua_limit_alarm_impl.js.map +1 -1
  139. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.d.ts +29 -28
  140. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js +50 -50
  141. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.js.map +1 -1
  142. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.d.ts +26 -25
  143. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js +162 -162
  144. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.js.map +1 -1
  145. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.d.ts +48 -39
  146. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +161 -135
  147. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  148. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.d.ts +17 -16
  149. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js +17 -17
  150. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.js.map +1 -1
  151. package/dist/src/apply_condition_refresh.d.ts +6 -6
  152. package/dist/src/apply_condition_refresh.js +27 -27
  153. package/dist/src/base_node_impl.d.ts +281 -281
  154. package/dist/src/base_node_impl.js +1395 -1395
  155. package/dist/src/base_node_private.d.ts +61 -61
  156. package/dist/src/base_node_private.js +705 -705
  157. package/dist/src/data_access/add_dataItem_stuff.d.ts +11 -11
  158. package/dist/src/data_access/add_dataItem_stuff.js +61 -61
  159. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.d.ts +1 -1
  160. package/dist/src/data_access/check_variant_compatibility_ua_analog_item.js +34 -34
  161. package/dist/src/data_access/ua_multistate_discrete_impl.d.ts +32 -32
  162. package/dist/src/data_access/ua_multistate_discrete_impl.js +130 -130
  163. package/dist/src/data_access/ua_multistate_value_discrete.d.ts +51 -51
  164. package/dist/src/data_access/ua_multistate_value_discrete.js +249 -249
  165. package/dist/src/data_access/ua_two_state_discrete.d.ts +25 -25
  166. package/dist/src/data_access/ua_two_state_discrete.js +153 -153
  167. package/dist/src/event_data.d.ts +29 -29
  168. package/dist/src/event_data.js +95 -95
  169. package/dist/src/extension_object_array_node.d.ts +61 -61
  170. package/dist/src/extension_object_array_node.js +276 -276
  171. package/dist/src/historical_access/address_space_historical_data_node.d.ts +26 -26
  172. package/dist/src/historical_access/address_space_historical_data_node.js +630 -630
  173. package/dist/src/index_current.d.ts +45 -45
  174. package/dist/src/index_current.js +77 -77
  175. package/dist/src/namespace_impl.d.ts +457 -457
  176. package/dist/src/namespace_impl.js +1733 -1733
  177. package/dist/src/namespace_private.d.ts +21 -21
  178. package/dist/src/namespace_private.js +32 -32
  179. package/dist/src/nodeid_manager.d.ts +36 -36
  180. package/dist/src/nodeid_manager.js +197 -197
  181. package/dist/src/nodeset_tools/adjust_namespace_array.d.ts +2 -2
  182. package/dist/src/nodeset_tools/adjust_namespace_array.js +13 -13
  183. package/dist/src/nodeset_tools/construct_namespace_dependency.d.ts +2 -2
  184. package/dist/src/nodeset_tools/construct_namespace_dependency.js +83 -83
  185. package/dist/src/nodeset_tools/nodeset_to_xml.d.ts +2 -2
  186. package/dist/src/nodeset_tools/nodeset_to_xml.js +1143 -1143
  187. package/dist/src/nodeset_tools/typedictionary_to_xml.d.ts +2 -2
  188. package/dist/src/nodeset_tools/typedictionary_to_xml.js +154 -154
  189. package/dist/src/reference_impl.d.ts +43 -43
  190. package/dist/src/reference_impl.js +139 -139
  191. package/dist/src/role_permissions.d.ts +2 -2
  192. package/dist/src/role_permissions.js +10 -10
  193. package/dist/src/state_machine/finite_state_machine.d.ts +67 -67
  194. package/dist/src/state_machine/finite_state_machine.js +353 -353
  195. package/dist/src/state_machine/ua_shelving_state_machine_ex.d.ts +34 -34
  196. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +250 -250
  197. package/dist/src/state_machine/ua_two_state_variable.d.ts +61 -61
  198. package/dist/src/state_machine/ua_two_state_variable.js +331 -331
  199. package/dist/src/tool_isSupertypeOf.d.ts +17 -17
  200. package/dist/src/tool_isSupertypeOf.js +108 -108
  201. package/dist/src/ua_condition_type.d.ts +8 -8
  202. package/dist/src/ua_condition_type.js +2 -2
  203. package/dist/src/ua_data_type_impl.d.ts +93 -93
  204. package/dist/src/ua_data_type_impl.js +368 -368
  205. package/dist/src/ua_method_impl.d.ts +41 -41
  206. package/dist/src/ua_method_impl.js +208 -208
  207. package/dist/src/ua_object_impl.d.ts +35 -33
  208. package/dist/src/ua_object_impl.js +162 -156
  209. package/dist/src/ua_object_impl.js.map +1 -1
  210. package/dist/src/ua_object_type_impl.d.ts +48 -48
  211. package/dist/src/ua_object_type_impl.js +124 -124
  212. package/dist/src/ua_reference_type_impl.d.ts +43 -43
  213. package/dist/src/ua_reference_type_impl.js +139 -139
  214. package/dist/src/ua_variable_impl.d.ts +351 -351
  215. package/dist/src/ua_variable_impl.js +1604 -1604
  216. package/dist/src/ua_variable_impl_ext_obj.d.ts +17 -17
  217. package/dist/src/ua_variable_impl_ext_obj.js +437 -437
  218. package/dist/src/ua_variable_type_impl.d.ts +62 -62
  219. package/dist/src/ua_variable_type_impl.js +570 -570
  220. package/dist/src/ua_view_impl.d.ts +19 -15
  221. package/dist/src/ua_view_impl.js +43 -36
  222. package/dist/src/ua_view_impl.js.map +1 -1
  223. package/distHelpers/add_event_generator_object.d.ts +3 -3
  224. package/distHelpers/add_event_generator_object.js +65 -65
  225. package/distHelpers/alarms_and_conditions_demo.d.ts +10 -10
  226. package/distHelpers/alarms_and_conditions_demo.js +114 -114
  227. package/distHelpers/assertHasMatchingReference.d.ts +19 -19
  228. package/distHelpers/assertHasMatchingReference.js +40 -40
  229. package/distHelpers/boiler_system.d.ts +113 -113
  230. package/distHelpers/boiler_system.js +395 -395
  231. package/distHelpers/create_minimalist_address_space_nodeset.d.ts +5 -5
  232. package/distHelpers/create_minimalist_address_space_nodeset.js +171 -171
  233. package/distHelpers/date_utils.d.ts +3 -3
  234. package/distHelpers/date_utils.js +9 -9
  235. package/distHelpers/dump_statemachine.js +127 -127
  236. package/distHelpers/get_address_space_fixture.d.ts +1 -1
  237. package/distHelpers/get_address_space_fixture.js +30 -30
  238. package/distHelpers/get_mini_address_space.d.ts +7 -7
  239. package/distHelpers/get_mini_address_space.js +36 -36
  240. package/distHelpers/index.d.ts +12 -12
  241. package/distHelpers/index.js +28 -28
  242. package/distHelpers/mock_session.d.ts +14 -14
  243. package/distHelpers/mock_session.js +25 -25
  244. package/distNodeJS/generate_address_space.d.ts +4 -4
  245. package/distNodeJS/generate_address_space.js +41 -41
  246. package/distNodeJS/index.d.ts +1 -1
  247. package/distNodeJS/index.js +17 -17
  248. package/package.json +23 -23
  249. package/source/loader/load_nodeset2.ts +21 -17
  250. package/source/loader/make_semver_compatible.ts +23 -0
  251. package/source/loader/make_xml_extension_object_parser.ts +16 -6
  252. package/src/alarms_and_conditions/ua_acknowledgeable_condition_impl.ts +13 -6
  253. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +15 -10
  254. package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +126 -10
  255. package/src/alarms_and_conditions/ua_condition_impl.ts +26 -13
  256. package/src/alarms_and_conditions/ua_discrete_alarm_impl.ts +10 -4
  257. package/src/alarms_and_conditions/ua_exclusive_deviation_alarm_impl.ts +7 -6
  258. package/src/alarms_and_conditions/ua_exclusive_level_alarm_impl.ts +5 -3
  259. package/src/alarms_and_conditions/ua_exclusive_limit_alarm_impl.ts +7 -6
  260. package/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm_impl.ts +1 -1
  261. package/src/alarms_and_conditions/ua_limit_alarm_impl.ts +23 -13
  262. package/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm_impl.ts +6 -7
  263. package/src/alarms_and_conditions/ua_non_exclusive_limit_alarm_impl.ts +6 -7
  264. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +62 -30
  265. package/src/alarms_and_conditions/ua_system_off_normal_alarm_impl.ts +5 -5
  266. package/src/ua_object_impl.ts +11 -3
  267. package/src/ua_view_impl.ts +6 -4
  268. package/test_helpers/test_fixtures/dataType_issue.xml +9 -9
  269. package/test_helpers/test_fixtures/nodeset_with_guid.xml +1442 -0
  270. package/test_helpers/test_fixtures/nodeset_with_int64_values.xml +31 -0
  271. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.d.ts +0 -23
  272. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js +0 -3
  273. package/dist/source/interfaces/alarms_and_conditions/ua_condition_base_i.js.map +0 -1
  274. package/dist/source/interfaces/data_access/ua_discrete_item.d.ts +0 -6
  275. package/dist/source/interfaces/data_access/ua_discrete_item.js +0 -3
  276. package/dist/source/interfaces/data_access/ua_discrete_item.js.map +0 -1
  277. package/dist/source/interfaces/data_access/ua_multistate_discrete.d.ts +0 -25
  278. package/dist/source/interfaces/data_access/ua_multistate_discrete.js +0 -3
  279. package/dist/source/interfaces/data_access/ua_multistate_discrete.js.map +0 -1
  280. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.d.ts +0 -27
  281. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js +0 -3
  282. package/dist/source/interfaces/data_access/ua_multistate_value_discrete.js.map +0 -1
  283. package/dist/source/interfaces/data_access/ua_two_state_discrete.d.ts +0 -17
  284. package/dist/source/interfaces/data_access/ua_two_state_discrete.js +0 -3
  285. package/dist/source/interfaces/data_access/ua_two_state_discrete.js.map +0 -1
  286. package/dist/source/interfaces/data_access/ua_y_array_item.d.ts +0 -19
  287. package/dist/source/interfaces/data_access/ua_y_array_item.js +0 -3
  288. package/dist/source/interfaces/data_access/ua_y_array_item.js.map +0 -1
  289. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.d.ts +0 -11
  290. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js +0 -3
  291. package/dist/source/interfaces/state_machine/exclusive_limit_state_machine.js.map +0 -1
  292. package/dist/source/interfaces/state_machine/finite_state_machine.d.ts +0 -70
  293. package/dist/source/interfaces/state_machine/finite_state_machine.js +0 -3
  294. package/dist/source/interfaces/state_machine/finite_state_machine.js.map +0 -1
  295. package/dist/source/interfaces/state_machine/program_finite_state_machine.d.ts +0 -74
  296. package/dist/source/interfaces/state_machine/program_finite_state_machine.js +0 -3
  297. package/dist/source/interfaces/state_machine/program_finite_state_machine.js.map +0 -1
  298. package/dist/source/interfaces/state_machine/state_machine.d.ts +0 -342
  299. package/dist/source/interfaces/state_machine/state_machine.js +0 -3
  300. package/dist/source/interfaces/state_machine/state_machine.js.map +0 -1
  301. package/dist/source/interfaces/state_machine/ua_finite_state_variable.d.ts +0 -18
  302. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js +0 -3
  303. package/dist/source/interfaces/state_machine/ua_finite_state_variable.js.map +0 -1
  304. package/dist/source/interfaces/state_machine/ua_state_variable.d.ts +0 -29
  305. package/dist/source/interfaces/state_machine/ua_state_variable.js +0 -3
  306. package/dist/source/interfaces/state_machine/ua_state_variable.js.map +0 -1
  307. package/dist/source/interfaces/state_machine/ua_two_state_variable.d.ts +0 -26
  308. package/dist/source/interfaces/state_machine/ua_two_state_variable.js +0 -3
  309. package/dist/source/interfaces/state_machine/ua_two_state_variable.js.map +0 -1
  310. package/dist/source/interfaces/subscription_diagnostics_variable.d.ts +0 -41
  311. package/dist/source/interfaces/subscription_diagnostics_variable.js +0 -3
  312. package/dist/source/interfaces/subscription_diagnostics_variable.js.map +0 -1
  313. package/dist/src/alarms_and_conditions/base_event_type.d.ts +0 -26
  314. package/dist/src/alarms_and_conditions/base_event_type.js +0 -41
  315. package/dist/src/alarms_and_conditions/base_event_type.js.map +0 -1
  316. package/dist/src/alarms_and_conditions/shelving_state_machine.d.ts +0 -22
  317. package/dist/src/alarms_and_conditions/shelving_state_machine.js +0 -241
  318. package/dist/src/alarms_and_conditions/shelving_state_machine.js.map +0 -1
  319. package/dist/src/alarms_and_conditions/trip_alarm.d.ts +0 -16
  320. package/dist/src/alarms_and_conditions/trip_alarm.js +0 -21
  321. package/dist/src/alarms_and_conditions/trip_alarm.js.map +0 -1
  322. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.d.ts +0 -54
  323. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js +0 -255
  324. package/dist/src/alarms_and_conditions/ua_acknowledgeable_condition_base.js.map +0 -1
  325. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.d.ts +0 -138
  326. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js +0 -460
  327. package/dist/src/alarms_and_conditions/ua_alarm_condition_base.js.map +0 -1
  328. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.d.ts +0 -35
  329. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js +0 -32
  330. package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm.js.map +0 -1
  331. package/dist/src/alarms_and_conditions/ua_condition_base.d.ts +0 -191
  332. package/dist/src/alarms_and_conditions/ua_condition_base.js +0 -1029
  333. package/dist/src/alarms_and_conditions/ua_condition_base.js.map +0 -1
  334. package/dist/src/alarms_and_conditions/ua_discrete_alarm.d.ts +0 -11
  335. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js +0 -58
  336. package/dist/src/alarms_and_conditions/ua_discrete_alarm.js.map +0 -1
  337. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.d.ts +0 -24
  338. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js +0 -59
  339. package/dist/src/alarms_and_conditions/ua_exclusive_deviation_alarm.js.map +0 -1
  340. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.d.ts +0 -14
  341. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js +0 -17
  342. package/dist/src/alarms_and_conditions/ua_exclusive_level_alarm.js.map +0 -1
  343. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.d.ts +0 -22
  344. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js +0 -87
  345. package/dist/src/alarms_and_conditions/ua_exclusive_limit_alarm.js.map +0 -1
  346. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.d.ts +0 -6
  347. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js +0 -11
  348. package/dist/src/alarms_and_conditions/ua_exclusive_rate_of_change_alarm.js.map +0 -1
  349. package/dist/src/alarms_and_conditions/ua_limit_alarm.d.ts +0 -76
  350. package/dist/src/alarms_and_conditions/ua_limit_alarm.js +0 -237
  351. package/dist/src/alarms_and_conditions/ua_limit_alarm.js.map +0 -1
  352. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.d.ts +0 -27
  353. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js +0 -62
  354. package/dist/src/alarms_and_conditions/ua_non_exclusive_deviation_alarm.js.map +0 -1
  355. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.d.ts +0 -49
  356. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js +0 -176
  357. package/dist/src/alarms_and_conditions/ua_non_exclusive_limit_alarm.js.map +0 -1
  358. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.d.ts +0 -47
  359. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js +0 -151
  360. package/dist/src/alarms_and_conditions/ua_off_normal_alarm.js.map +0 -1
  361. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.d.ts +0 -16
  362. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js +0 -18
  363. package/dist/src/alarms_and_conditions/ua_system_off_normal_alarm.js.map +0 -1
  364. package/dist/src/base_node.d.ts +0 -270
  365. package/dist/src/base_node.js +0 -1299
  366. package/dist/src/base_node.js.map +0 -1
  367. package/dist/src/data_access/ua_analog_item.d.ts +0 -13
  368. package/dist/src/data_access/ua_analog_item.js +0 -37
  369. package/dist/src/data_access/ua_analog_item.js.map +0 -1
  370. package/dist/src/data_access/ua_data_item.d.ts +0 -16
  371. package/dist/src/data_access/ua_data_item.js +0 -66
  372. package/dist/src/data_access/ua_data_item.js.map +0 -1
  373. package/dist/src/data_access/ua_multistate_discrete.d.ts +0 -24
  374. package/dist/src/data_access/ua_multistate_discrete.js +0 -132
  375. package/dist/src/data_access/ua_multistate_discrete.js.map +0 -1
  376. package/dist/src/namespace.d.ts +0 -472
  377. package/dist/src/namespace.js +0 -1759
  378. package/dist/src/namespace.js.map +0 -1
  379. package/dist/src/reference.d.ts +0 -43
  380. package/dist/src/reference.js +0 -138
  381. package/dist/src/reference.js.map +0 -1
  382. package/dist/src/session_context.d.ts +0 -4
  383. package/dist/src/session_context.js +0 -9
  384. package/dist/src/session_context.js.map +0 -1
  385. package/dist/src/ua_data_type.d.ts +0 -81
  386. package/dist/src/ua_data_type.js +0 -259
  387. package/dist/src/ua_data_type.js.map +0 -1
  388. package/dist/src/ua_method.d.ts +0 -33
  389. package/dist/src/ua_method.js +0 -194
  390. package/dist/src/ua_method.js.map +0 -1
  391. package/dist/src/ua_object.d.ts +0 -27
  392. package/dist/src/ua_object.js +0 -153
  393. package/dist/src/ua_object.js.map +0 -1
  394. package/dist/src/ua_object_type.d.ts +0 -49
  395. package/dist/src/ua_object_type.js +0 -123
  396. package/dist/src/ua_object_type.js.map +0 -1
  397. package/dist/src/ua_reference_type.d.ts +0 -31
  398. package/dist/src/ua_reference_type.js +0 -108
  399. package/dist/src/ua_reference_type.js.map +0 -1
  400. package/dist/src/ua_variable.d.ts +0 -346
  401. package/dist/src/ua_variable.js +0 -1651
  402. package/dist/src/ua_variable.js.map +0 -1
  403. package/dist/src/ua_variable_type.d.ts +0 -57
  404. package/dist/src/ua_variable_type.js +0 -530
  405. package/dist/src/ua_variable_type.js.map +0 -1
  406. package/dist/src/ua_view.d.ts +0 -16
  407. package/dist/src/ua_view.js +0 -41
  408. package/dist/src/ua_view.js.map +0 -1
@@ -1,1023 +1,1025 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UAConditionImpl = void 0;
4
- /* eslint-disable complexity */
5
- /**
6
- * @module node-opcua-address-space.AlarmsAndConditions
7
- */
8
- const chalk = require("chalk");
9
- const node_opcua_assert_1 = require("node-opcua-assert");
10
- const node_opcua_basic_types_1 = require("node-opcua-basic-types");
11
- const node_opcua_data_model_1 = require("node-opcua-data-model");
12
- const node_opcua_debug_1 = require("node-opcua-debug");
13
- const node_opcua_factory_1 = require("node-opcua-factory");
14
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
- const node_opcua_status_code_1 = require("node-opcua-status-code");
16
- const node_opcua_types_1 = require("node-opcua-types");
17
- const node_opcua_variant_1 = require("node-opcua-variant");
18
- const ua_two_state_variable_1 = require("../state_machine/ua_two_state_variable");
19
- const ua_object_impl_1 = require("../ua_object_impl");
20
- const ua_base_event_impl_1 = require("./ua_base_event_impl");
21
- const condition_snapshot_1 = require("./condition_snapshot");
22
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
23
- const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
24
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
25
- /**
26
- *
27
- * └─ ConditionType
28
- * ├─ DialogConditionType
29
- * └─ AcknowledgeableConditionType
30
- * └─ AlarmConditionType
31
- * ├─ LimitAlarmType
32
- * │ ├─ ExclusiveLimitAlarmType
33
- * │ │ ├─ ExclusiveLevelAlarmType
34
- * │ │ ├─ ExclusiveDeviationAlarmType
35
- * │ │ └─ ExclusiveRateOfChangeAlarmType
36
- * │ └─ NonExclusiveLimitAlarmType
37
- * │ ├─ NonExclusiveLevelAlarmType
38
- * │ ├─ NonExclusiveDeviationAlarmType
39
- * │ └─ NonExclusiveRateOfChangeAlarmType
40
- * └─ DiscreteAlarmType
41
- * ├─ OffNormalAlarmType
42
- * │ ├─ SystemOffNormalAlarmType
43
- * │ │ └─ CertificateExpirationAlarmType
44
- * │ └─ TripAlarmType
45
- *
46
- */
47
- class UAConditionImpl extends ua_base_event_impl_1.UABaseEventImpl {
48
- constructor() {
49
- super(...arguments);
50
- this._branch0 = null;
51
- this._previousRetainFlag = false;
52
- this._branches = {};
53
- }
54
- static instantiate(namespace, conditionTypeId, options, data) {
55
- return UACondition_instantiate(namespace, conditionTypeId, options, data);
56
- }
57
- static install_condition_refresh_handle(addressSpace) {
58
- //
59
- // install ConditionRefresh
60
- //
61
- // NOTE:
62
- // OPCUA doesn't implement the condition refresh method ! yet
63
- // .5.7 ConditionRefresh Method
64
- // ConditionRefresh allows a Client to request a Refresh of all Condition instances that currently
65
- // are in an interesting state (they have the Retain flag set). This includes previous states of a
66
- // Condition instance for which the Server maintains Branches. A Client would typically invoke
67
- // this Method when it initially connects to a Server and following any situations, such as
68
- // communication disruptions, in which it would require resynchronization with the Server. This
69
- // Method is only available on the ConditionType or its subtypes. To invoke this Method, the call
70
- // shall pass the well known MethodId of the Method on the ConditionType and the ObjectId
71
- // shall be the well known ObjectId of the ConditionType Object.
72
- const conditionType = addressSpace.findEventType("ConditionType");
73
- (0, node_opcua_assert_1.assert)(conditionType !== null);
74
- conditionType.disable.bindMethod(_disable_method);
75
- conditionType.enable.bindMethod(_enable_method);
76
- conditionType.conditionRefresh.bindMethod(_condition_refresh_method);
77
- conditionType.conditionRefresh2.bindMethod(_condition_refresh2_method);
78
- // those methods can be call on the ConditionType or on the ConditionInstance itself...
79
- conditionType.addComment.bindMethod(_add_comment_method);
80
- }
81
- /**
82
- *
83
- * Helper method to handle condition methods that takes a branchId and a comment
84
- *
85
- */
86
- static with_condition_method(inputArguments, context, callback, inner_func) {
87
- const conditionNode = context.object;
88
- // xx console.log(inputArguments.map(function(a){return a.toString()}));
89
- if (!(conditionNode instanceof UAConditionImpl)) {
90
- callback(null, {
91
- statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdInvalid
92
- });
93
- return;
94
- }
95
- if (!conditionNode.getEnabledState()) {
96
- callback(null, {
97
- statusCode: node_opcua_status_code_1.StatusCodes.BadConditionDisabled
98
- });
99
- return;
100
- }
101
- // inputArguments has 2 arguments
102
- // EventId => ByteString The Identifier of the event to comment
103
- // Comment => LocalizedText The Comment to add to the condition
104
- (0, node_opcua_assert_1.assert)(inputArguments.length === 2);
105
- (0, node_opcua_assert_1.assert)(inputArguments[0].dataType === node_opcua_variant_1.DataType.ByteString);
106
- (0, node_opcua_assert_1.assert)(inputArguments[1].dataType === node_opcua_variant_1.DataType.LocalizedText);
107
- const eventId = inputArguments[0].value;
108
- (0, node_opcua_assert_1.assert)(!eventId || eventId instanceof Buffer);
109
- const comment = inputArguments[1].value;
110
- (0, node_opcua_assert_1.assert)(comment instanceof node_opcua_data_model_1.LocalizedText);
111
- const branch = conditionNode._findBranchForEventId(eventId);
112
- if (!branch) {
113
- callback(null, {
114
- statusCode: node_opcua_status_code_1.StatusCodes.BadEventIdUnknown
115
- });
116
- return;
117
- }
118
- (0, node_opcua_assert_1.assert)(branch instanceof condition_snapshot_1.ConditionSnapshot);
119
- const statusCode = inner_func(eventId, comment, branch, conditionNode);
120
- // record also who did the call
121
- branch.setClientUserId(context.userIdentity || "<unknown client user id>");
122
- callback(null, {
123
- statusCode
124
- });
125
- }
126
- /**
127
- * @method initialize
128
- * @private
129
- */
130
- initialize() {
131
- this._branches = {};
132
- }
133
- /**
134
- * @method post_initialize
135
- * @private
136
- */
137
- post_initialize() {
138
- (0, node_opcua_assert_1.assert)(!this._branch0);
139
- this._branch0 = new condition_snapshot_1.ConditionSnapshot(this, new node_opcua_nodeid_1.NodeId());
140
- // the condition OPCUA object alway reflects the default branch states
141
- // so we set a mechanism that automatically keeps self in sync
142
- // with the default branch.
143
- // the implication of this convention is that interacting with the condition variable
144
- // shall be made by using branch0, any value change made
145
- // using the standard setValueFromSource mechanism will not be work properly.
146
- this._branch0.on("value_changed", (node, variant) => {
147
- (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
148
- node.setValueFromSource(variant);
149
- });
150
- }
151
- getBranchCount() {
152
- return Object.keys(this._branches).length;
153
- }
154
- getBranches() {
155
- return Object.keys(this._branches).map((x) => {
156
- return this._branches[x];
157
- });
158
- }
159
- getBranchIds() {
160
- return this.getBranches().map((b) => b.getBranchId());
161
- }
162
- /**
163
- * @method createBranch
164
- * @return {ConditionSnapshot}
165
- */
166
- createBranch() {
167
- const branchId = _create_new_branch_id();
168
- const snapshot = new condition_snapshot_1.ConditionSnapshot(this, branchId);
169
- this._branches[branchId.toString()] = snapshot;
170
- return snapshot;
171
- }
172
- /**
173
- * @method deleteBranch
174
- * @param branch {ConditionSnapshot}
175
- */
176
- deleteBranch(branch) {
177
- const key = branch.getBranchId().toString();
178
- (0, node_opcua_assert_1.assert)(!(0, node_opcua_nodeid_1.sameNodeId)(branch.getBranchId(), node_opcua_nodeid_1.NodeId.nullNodeId), "cannot delete branch zero");
179
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(this._branches, key));
180
- delete this._branches[key];
181
- this.emit("branch_deleted", key);
182
- }
183
- /**
184
- * @method getEnabledState
185
- * @return {Boolean}
186
- */
187
- getEnabledState() {
188
- return this.enabledState.getValue();
189
- }
190
- /**
191
- * @method getEnabledStateAsString
192
- * @return {String}
193
- */
194
- getEnabledStateAsString() {
195
- return this.enabledState.getValueAsString();
196
- }
197
- /**
198
- * returns {StatusCode} StatusCodes.Good if successful or BadConditionAlreadyEnabled/BadConditionAlreadyDisabled
199
- * @private
200
- */
201
- _setEnabledState(requestedEnabledState) {
202
- (0, node_opcua_assert_1.assert)(typeof requestedEnabledState === "boolean");
203
- const enabledState = this.getEnabledState();
204
- if (enabledState && requestedEnabledState) {
205
- return node_opcua_status_code_1.StatusCodes.BadConditionAlreadyEnabled;
206
- }
207
- if (!enabledState && !requestedEnabledState) {
208
- return node_opcua_status_code_1.StatusCodes.BadConditionAlreadyDisabled;
209
- }
210
- this._branch0.setEnabledState(requestedEnabledState);
211
- // conditionNode.enabledState.setValue(requestedEnabledState);
212
- // xx assert(conditionNode.enabledState.id.readValue().value.value === requestedEnabledState,"sanity check 1");
213
- // xx assert(conditionNode.currentBranch().getEnabledState() === requestedEnabledState,"sanity check 2");
214
- if (!requestedEnabledState) {
215
- // as per Spec 1.0.3 part 9:
216
- // * When the Condition instance enters the Disabled state, the Retain Property of this
217
- // Condition shall be set to FALSE by the Server to indicate to the Client that the
218
- // Condition instance is currently not of interest to Clients.
219
- // TODO : shall we really set retain to false or artificially expose the retain false as false
220
- // whist enabled state is false ?
221
- this._previousRetainFlag = this.currentBranch().getRetain();
222
- this.currentBranch().setRetain(false);
223
- // todo: install the mechanism by which all condition values will be return
224
- // as Null | BadConditionDisabled;
225
- const statusCode = node_opcua_status_code_1.StatusCodes.BadConditionDisabled;
226
- // a notification must be send
227
- this.raiseConditionEvent(this.currentBranch(), true);
228
- }
229
- else {
230
- // * When the Condition instance enters the enabled state, the Condition shall be
231
- // evaluated and all of its Properties updated to reflect the current values. If this
232
- // evaluation causes the Retain Property to transition to TRUE for any ConditionBranch,
233
- // then an Event Notification shall be generated for that ConditionBranch.
234
- this.evaluateConditionsAfterEnabled();
235
- // todo evaluate branches
236
- // conditionNode.evaluateBranches();
237
- // restore retain flag
238
- if (Object.prototype.hasOwnProperty.call(this, "_previousRetainFlag")) {
239
- this.currentBranch().setRetain(this._previousRetainFlag);
240
- }
241
- // todo send notification for branches with retain = true
242
- let nb_condition_resent = 0;
243
- if (this.currentBranch().getRetain()) {
244
- nb_condition_resent += this._resend_conditionEvents();
245
- }
246
- if (nb_condition_resent === 0) {
247
- // a notification must be send
248
- this.raiseConditionEvent(this.currentBranch(), true);
249
- }
250
- }
251
- return node_opcua_status_code_1.StatusCodes.Good;
252
- }
253
- /**
254
- *
255
- * @method setEnabledState
256
- * @param requestedEnabledState {Boolean}
257
- * @private
258
- */
259
- setEnabledState(requestedEnabledState) {
260
- return this._setEnabledState(requestedEnabledState);
261
- }
262
- /**
263
- * @method setReceiveTime
264
- * @param time {Date}
265
- */
266
- setReceiveTime(time) {
267
- return this._branch0.setReceiveTime(time);
268
- }
269
- /**
270
- * @method setLocalTime (optional)
271
- * @param time
272
- */
273
- setLocalTime(time) {
274
- return this._branch0.setLocalTime(time);
275
- }
276
- /**
277
- * @method setTime
278
- * @param time {Date}
279
- */
280
- setTime(time) {
281
- return this._branch0.setTime(time);
282
- }
283
- _assert_valid() {
284
- (0, node_opcua_assert_1.assert)(this.receiveTime.readValue().value.dataType === node_opcua_variant_1.DataType.DateTime);
285
- (0, node_opcua_assert_1.assert)(this.receiveTime.readValue().value.value instanceof Date);
286
- (0, node_opcua_assert_1.assert)(this.message.readValue().value.dataType === node_opcua_variant_1.DataType.LocalizedText);
287
- (0, node_opcua_assert_1.assert)(this.severity.readValue().value.dataType === node_opcua_variant_1.DataType.UInt16);
288
- (0, node_opcua_assert_1.assert)(this.time.readValue().value.dataType === node_opcua_variant_1.DataType.DateTime);
289
- (0, node_opcua_assert_1.assert)(this.time.readValue().value.value instanceof Date);
290
- (0, node_opcua_assert_1.assert)(this.quality.readValue().value.dataType === node_opcua_variant_1.DataType.StatusCode);
291
- (0, node_opcua_assert_1.assert)(this.enabledState.readValue().value.dataType === node_opcua_variant_1.DataType.LocalizedText);
292
- (0, node_opcua_assert_1.assert)(this.branchId.readValue().value.dataType === node_opcua_variant_1.DataType.NodeId);
293
- // note localTime has been made optional in 1.04
294
- (0, node_opcua_assert_1.assert)(!this.localTime || this.localTime.readValue().value.dataType === node_opcua_variant_1.DataType.ExtensionObject);
295
- }
296
- /**
297
- * @method conditionOfNode
298
- * @return {UAObject}
299
- */
300
- conditionOfNode() {
301
- const refs = this.findReferencesExAsObject("HasCondition", node_opcua_data_model_1.BrowseDirection.Inverse);
302
- if (refs.length === 0) {
303
- return null;
304
- }
305
- (0, node_opcua_assert_1.assert)(refs.length !== 0, "UACondition must be the condition of some node");
306
- (0, node_opcua_assert_1.assert)(refs.length === 1, "expecting only one ConditionOf");
307
- const node = refs[0];
308
- (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Object || node.nodeClass === node_opcua_data_model_1.NodeClass.Variable, "node for which we are the condition shall be an UAObject or UAVariable");
309
- return node;
310
- }
311
- /**
312
- * @method raiseConditionEvent
313
- * Raise a Instance Event
314
- * (see also UAObject#raiseEvent to raise a transient event)
315
- * @param branch the condition branch to raise
316
- * @param renewEventId true if event Id of the condition branch should be renewed
317
- */
318
- raiseConditionEvent(branch, renewEventId) {
319
- (0, node_opcua_assert_1.assert)(arguments.length === 2, "expecting 2 arguments");
320
- if (renewEventId) {
321
- branch.renewEventId();
322
- }
323
- // xx console.log("MMMMMMMM%%%%%%%%%%%%%%%%%%%%% branch " +
324
- // branch.getBranchId().toString() + " eventId = " + branch.getEventId().toString("hex"));
325
- (0, node_opcua_assert_1.assert)(branch instanceof condition_snapshot_1.ConditionSnapshot);
326
- this._assert_valid();
327
- // In fact the event is raised by the object of which we are the condition
328
- const conditionOfNode = this.conditionOfNode();
329
- if (conditionOfNode) {
330
- const eventData = branch._constructEventData();
331
- this.emit("event", eventData);
332
- if (conditionOfNode instanceof ua_object_impl_1.UAObjectImpl) {
333
- // xx assert(conditionOfNode.eventNotifier === 0x01);
334
- conditionOfNode._bubble_up_event(eventData);
335
- }
336
- else {
337
- (0, node_opcua_assert_1.assert)(conditionOfNode.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
338
- // in this case
339
- const eventOfs = conditionOfNode.getEventSourceOfs();
340
- (0, node_opcua_assert_1.assert)(eventOfs.length === 1);
341
- const node = eventOfs[0];
342
- if (node instanceof ua_object_impl_1.UAObjectImpl) {
343
- node._bubble_up_event(eventData);
344
- }
345
- }
346
- }
347
- // xx console.log("MMMMMMMM%%%%%%%%%%%%%%%%%%%%% branch " +
348
- // branch.getBranchId().toString() + " eventId = " + branch.getEventId().toString("hex"));
349
- }
350
- /**
351
- *
352
- * @method raiseNewCondition
353
- * @param conditionInfo {ConditionInfo}
354
- *
355
- */
356
- raiseNewCondition(conditionInfo) {
357
- if (!this.getEnabledState()) {
358
- throw new Error("UACondition#raiseNewCondition Condition is not enabled");
359
- }
360
- conditionInfo = conditionInfo || {};
361
- conditionInfo.severity = Object.prototype.hasOwnProperty.call(conditionInfo, "severity")
362
- ? conditionInfo.severity
363
- : UAConditionImpl.defaultSeverity;
364
- // only valid for ConditionObjects
365
- // todo check that object is of type ConditionType
366
- const addressSpace = this.addressSpace;
367
- const selfConditionType = this.typeDefinitionObj;
368
- const conditionType = addressSpace.findObjectType("ConditionType");
369
- (0, node_opcua_assert_1.assert)(selfConditionType.isSupertypeOf(conditionType));
370
- const branch = this.currentBranch();
371
- const now = new Date();
372
- // install the eventTimestamp
373
- // set the received Time
374
- branch.setTime(now);
375
- branch.setReceiveTime(now);
376
- // note : in 1.04 LocalTime property is optional
377
- if (Object.prototype.hasOwnProperty.call(this, "localTime")) {
378
- branch.setLocalTime(new node_opcua_types_1.TimeZoneDataType({
379
- daylightSavingInOffset: false,
380
- offset: 0
381
- }));
382
- }
383
- if (Object.prototype.hasOwnProperty.call(conditionInfo, "message") && conditionInfo.message) {
384
- branch.setMessage(conditionInfo.message);
385
- }
386
- // todo receive time : when the server received the event from the underlying system.
387
- // self.receiveTime.setValueFromSource();
388
- if (Object.prototype.hasOwnProperty.call(conditionInfo, "severity") && conditionInfo.severity !== null) {
389
- (0, node_opcua_assert_1.assert)(isFinite(conditionInfo.severity));
390
- branch.setSeverity(conditionInfo.severity);
391
- }
392
- if (Object.prototype.hasOwnProperty.call(conditionInfo, "quality") && conditionInfo.quality !== null) {
393
- (0, node_opcua_assert_1.assert)(conditionInfo.quality instanceof node_opcua_status_code_1.StatusCode);
394
- branch.setQuality(conditionInfo.quality);
395
- }
396
- if (Object.prototype.hasOwnProperty.call(conditionInfo, "retain") && conditionInfo.retain !== null) {
397
- (0, node_opcua_assert_1.assert)(typeof conditionInfo.retain === "boolean");
398
- branch.setRetain(!!conditionInfo.retain);
399
- }
400
- this.raiseConditionEvent(branch, true);
401
- }
402
- raiseNewBranchState(branch) {
403
- this.raiseConditionEvent(branch, true);
404
- if (!(0, node_opcua_nodeid_1.sameNodeId)(branch.getBranchId(), node_opcua_nodeid_1.NodeId.nullNodeId) && !branch.getRetain()) {
405
- // xx console.log(" Deleting not longer needed branch ", branch.getBranchId().toString());
406
- // branch can be deleted
407
- this.deleteBranch(branch);
408
- }
409
- }
410
- /**
411
- * @method currentBranch
412
- * @return {ConditionSnapshot}
413
- */
414
- currentBranch() {
415
- return this._branch0;
416
- }
417
- _resend_conditionEvents() {
418
- // for the time being , only current branch
419
- const currentBranch = this.currentBranch();
420
- if (currentBranch.getRetain()) {
421
- debugLog(" resending condition event for " + this.browseName.toString());
422
- this.raiseConditionEvent(currentBranch, false);
423
- return 1;
424
- }
425
- return 0;
426
- }
427
- // ------------------------------------------------------------------------------------
428
- // Acknowledgeable
429
- // ------------------------------------------------------------------------------------
430
- /**
431
- * @method _raiseAuditConditionCommentEvent
432
- * @param sourceName {string}
433
- * @param conditionEventId {Buffer}
434
- * @param comment {LocalizedText}
435
- * @private
436
- */
437
- _raiseAuditConditionCommentEvent(sourceName, conditionEventId, comment) {
438
- (0, node_opcua_assert_1.assert)(conditionEventId === null || conditionEventId instanceof Buffer);
439
- (0, node_opcua_assert_1.assert)(comment instanceof node_opcua_data_model_1.LocalizedText);
440
- const server = this.addressSpace.rootFolder.objects.server;
441
- const now = new Date();
442
- // xx if (true || server.isAuditing) {
443
- // ----------------------------------------------------------------------------------------------------
444
- server.raiseEvent("AuditConditionCommentEventType", {
445
- // AuditEventType
446
- /* part 5 - 6.4.3 AuditEventType */
447
- actionTimeStamp: {
448
- dataType: "DateTime",
449
- value: now
450
- },
451
- status: {
452
- dataType: "Boolean",
453
- value: true
454
- },
455
- serverId: {
456
- dataType: "String",
457
- value: ""
458
- },
459
- // ClientAuditEntryId contains the human-readable AuditEntryId defined in Part 3.
460
- clientAuditEntryId: {
461
- dataType: "String",
462
- value: ""
463
- },
464
- // The ClientUserId identifies the user of the client requesting an action. The ClientUserId can be
465
- // obtained from the UserIdentityToken passed in the ActivateSession call.
466
- clientUserId: {
467
- dataType: "String",
468
- value: ""
469
- },
470
- sourceName: {
471
- dataType: "String",
472
- value: sourceName
473
- },
474
- // AuditUpdateMethodEventType
475
- methodId: {
476
- dataType: "Null"
477
- },
478
- inputArguments: {
479
- dataType: "Null"
480
- },
481
- // AuditConditionCommentEventType
482
- conditionEventId: {
483
- dataType: "ByteString",
484
- value: conditionEventId
485
- },
486
- comment: {
487
- dataType: "LocalizedText",
488
- value: comment
489
- }
490
- });
491
- // xx }
492
- }
493
- _findBranchForEventId(eventId) {
494
- if (sameBuffer(this.eventId.readValue().value.value, eventId)) {
495
- return this.currentBranch();
496
- }
497
- const e = Object.values(this._branches).filter((branch) => sameBuffer(branch.getEventId(), eventId));
498
- if (e.length === 1) {
499
- return e[0];
500
- }
501
- (0, node_opcua_assert_1.assert)(e.length === 0, "cannot have 2 branches with same eventId");
502
- return null; // not found
503
- }
504
- evaluateConditionsAfterEnabled() {
505
- (0, node_opcua_assert_1.assert)(this.getEnabledState() === true);
506
- throw new Error("Unimplemented , please override");
507
- }
508
- }
509
- exports.UAConditionImpl = UAConditionImpl;
510
- UAConditionImpl.defaultSeverity = 250;
511
- UAConditionImpl.typeDefinition = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType");
512
- /**
513
- * instantiate a Condition.
514
- * this will create the unique EventId and will set eventType
515
- * @method instantiate
516
- * @param namespace {INamespace}
517
- * @param conditionTypeId {String|NodeId} the EventType to instantiate
518
- * @param options {object}
519
- * @param options.browseName {String|QualifiedName}
520
- * @param options.componentOf {NodeId|UAObject}
521
- * @param options.conditionOf {NodeId|UAObject} Mandatory
522
- * @param options.organizedBy {NodeId|UAObject} ( only provide componentOf or organizedBy but not both)
523
- * @param [options.conditionClass =BaseConditionClassType] {NodeId|UAObject}
524
- * The condition Class nodeId or object used to set the ConditionClassId and
525
- * ConditionClassName properties of the condition.
526
- *
527
- * @param options.conditionSource {NodeId|UAObject} the condition source node.
528
- * this node must be marked a EventSource.
529
- * the conditionSource is used to populate the sourceNode and
530
- * sourceName variables defined by BaseEventType
531
- * @param options.conditionName {String} the condition Name
532
- * @param [options.optionals] [Array<String>] an Array of optionals fields
533
- *
534
- * @param data a object containing the value to set
535
- * @param data.eventId {String|NodeId} the EventType Identifier to instantiate (type cannot be abstract)
536
- * @return a instantiated UAConditionEx
537
- */
538
- function UACondition_instantiate(namespace, conditionTypeId, options, data) {
539
- /* eslint max-statements: ["error", 100] */
540
- const addressSpace = namespace.addressSpace;
541
- const conditionType = addressSpace.findEventType(conditionTypeId);
542
- /* istanbul ignore next */
543
- if (!conditionType) {
544
- throw new Error(" cannot find Condition Type for " + conditionTypeId);
545
- }
546
- // reminder : abstract event type cannot be instantiated directly !
547
- (0, node_opcua_assert_1.assert)(!conditionType.isAbstract, "Cannot instantiate abstract conditionType");
548
- const baseConditionEventType = addressSpace.findEventType("ConditionType");
549
- /* istanbul ignore next */
550
- if (!baseConditionEventType) {
551
- throw new Error("cannot find ConditionType");
552
- }
553
- (0, node_opcua_assert_1.assert)(conditionType.isSupertypeOf(baseConditionEventType));
554
- // assert((typeof options.browseName === "string"));
555
- options.browseName = options.browseName || "??? instantiateCondition - missing browseName";
556
- options.optionals = options.optionals || [];
557
- // now optionals in 1.04
558
- options.optionals.push("EventType");
559
- options.optionals.push("BranchId");
560
- //
561
- options.optionals.push("Comment");
562
- options.optionals.push("Comment.SourceTimestamp");
563
- options.optionals.push("EnabledState.TrueState");
564
- options.optionals.push("EnabledState.TrueState");
565
- options.optionals.push("EnabledState.FalseState");
566
- options.optionals.push("EnabledState.TransitionTime");
567
- options.optionals.push("EnabledState.EffectiveTransitionTime");
568
- options.optionals.push("EnabledState.EffectiveDisplayName");
569
- const conditionNode = conditionType.instantiate(options);
570
- Object.setPrototypeOf(conditionNode, UAConditionImpl.prototype);
571
- conditionNode.initialize();
572
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "conditionSource"), "must specify a condition source either as null or as a UAObject");
573
- if (!options.conditionOf) {
574
- options.conditionOf = options.conditionSource;
575
- }
576
- if (options.conditionOf) {
577
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "conditionOf")); // must provide a conditionOf
578
- options.conditionOf = addressSpace._coerceNode(options.conditionOf);
579
- // HasCondition References can be used in the Type definition of an Object or a Variable.
580
- (0, node_opcua_assert_1.assert)(options.conditionOf.nodeClass === node_opcua_data_model_1.NodeClass.Object || options.conditionOf.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
581
- conditionNode.addReference({
582
- isForward: false,
583
- nodeId: options.conditionOf,
584
- referenceType: "HasCondition"
585
- });
586
- (0, node_opcua_assert_1.assert)(conditionNode.conditionOfNode().nodeId === options.conditionOf.nodeId);
587
- }
588
- // the constant property of this condition
589
- conditionNode.eventType.setValueFromSource({
590
- dataType: node_opcua_variant_1.DataType.NodeId,
591
- value: conditionType.nodeId
592
- });
593
- data = data || {};
594
- // install initial branch ID (null NodeId);
595
- conditionNode.branchId.setValueFromSource({
596
- dataType: node_opcua_variant_1.DataType.NodeId,
597
- value: new node_opcua_nodeid_1.NodeId()
598
- });
599
- // install 'Comment' condition variable
600
- _install_condition_variable_type(conditionNode.comment);
601
- // install 'Quality' condition variable
602
- _install_condition_variable_type(conditionNode.quality);
603
- // xx conditionNode.quality.setValueFromSource({dataType: DataType.StatusCode,value: StatusCodes.Good });
604
- // install 'LastSeverity' condition variable
605
- _install_condition_variable_type(conditionNode.lastSeverity);
606
- // xx conditionNode.severity.setValueFromSource({dataType: DataType.UInt16,value: 0 });
607
- // xx conditionNode.lastSeverity.setValueFromSource({dataType: DataType.UInt16,value: 0 });
608
- // install 'EnabledState' TwoStateVariable
609
- /**
610
- * @property enabledState
611
- * @type {UATwoStateVariable}
612
- */
613
- // -------------- fixing missing EnabledState.EffectiveDisplayName
614
- if (!conditionNode.enabledState.effectiveDisplayName) {
615
- namespace.addVariable({
616
- browseName: new node_opcua_data_model_1.QualifiedName({ namespaceIndex: 0, name: "EffectiveDisplayName" }),
617
- dataType: "LocalizedText",
618
- propertyOf: conditionNode.enabledState
619
- });
620
- }
621
- (0, ua_two_state_variable_1._install_TwoStateVariable_machinery)(conditionNode.enabledState, {
622
- falseState: "Disabled",
623
- trueState: "Enabled"
624
- });
625
- // installing sourceName and sourceNode
626
- conditionNode.enabledState.setValue(true);
627
- // set properties to in initial values
628
- Object.keys(data).forEach((key) => {
629
- const varNode = _getCompositeKey(conditionNode, key);
630
- (0, node_opcua_assert_1.assert)(varNode.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
631
- const variant = new node_opcua_variant_1.Variant(data[key]);
632
- // check that Variant DataType is compatible with the UAVariable dataType
633
- // xx var nodeDataType = addressSpace.findNode(varNode.dataType).browseName;
634
- /* istanbul ignore next */
635
- if (!varNode._validate_DataType(variant.dataType)) {
636
- throw new Error(" Invalid variant dataType " + variant + " " + varNode.browseName.toString());
637
- }
638
- const value = new node_opcua_variant_1.Variant(data[key]);
639
- varNode.setValueFromSource(value);
640
- });
641
- // bind condition methods -
642
- /**
643
- * @property enable
644
- * @type {UAMethod}
645
- */
646
- conditionNode.enable.bindMethod(_enable_method);
647
- /**
648
- * @property disable
649
- * @type {UAMethod}
650
- */
651
- conditionNode.disable.bindMethod(_disable_method);
652
- // bind condition methods - AddComment
653
- /**
654
- * @property addComment
655
- * @type {UAMethod}
656
- */
657
- conditionNode.addComment.bindMethod(_add_comment_method);
658
- (0, node_opcua_assert_1.assert)(conditionNode instanceof UAConditionImpl);
659
- // ConditionSource => cf SourceNode
660
- // As per spec OPCUA 1.03 part 9 page 54:
661
- // The ConditionType inherits all Properties of the BaseEventType. Their semantic is defined in
662
- // Part 5. SourceNode identifies the ConditionSource.
663
- // The SourceNode is the Node which the condition is associated with, it may be the same as the
664
- // InputNode for an alarm, but it may be a separate node. For example a motor, which is a
665
- // variable with a value that is an RPM, may be the ConditionSource for Conditions that are
666
- // related to the motor as well as a temperature sensor associated with the motor. In the former
667
- // the InputNode for the High RPM alarm is the value of the Motor RPM, while in the later the
668
- // InputNode of the High Alarm would be the value of the temperature sensor that is associated
669
- // with the motor.
670
- if (options.conditionSource) {
671
- options.conditionSource = addressSpace._coerceNode(options.conditionSource);
672
- if (options.conditionSource.nodeClass !== node_opcua_data_model_1.NodeClass.Object && options.conditionSource.nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
673
- // tslint:disable:no-console
674
- console.log(options.conditionSource);
675
- throw new Error("Expecting condition source to be NodeClass.Object or Variable");
676
- }
677
- const conditionSourceNode = addressSpace.findNode(options.conditionSource.nodeId);
678
- if (conditionSourceNode) {
679
- conditionNode.sourceNode.setValueFromSource({
680
- dataType: node_opcua_variant_1.DataType.NodeId,
681
- value: conditionSourceNode.nodeId
682
- });
683
- // conditionSourceNode node must be registered as a EventSource of an other node.
684
- // As per spec OPCUA 1.03 part 9 page 54:
685
- // HasNotifier and HasEventSource References are used to expose the hierarchical organization
686
- // of Event notifying Objects and ConditionSources. An Event notifying Object represents
687
- // typically an area of Operator responsibility. The definition of such an area configuration is
688
- // outside the scope of this standard. If areas are available they shall be linked together and
689
- // with the included ConditionSources using the HasNotifier and the HasEventSource Reference
690
- // Types. The Server Object shall be the root of this hierarchy.
691
- if (!(0, node_opcua_nodeid_1.sameNodeId)(conditionSourceNode.nodeId, (0, node_opcua_nodeid_1.coerceNodeId)("ns=0;i=2253"))) {
692
- // server object
693
- /* istanbul ignore next */
694
- if (conditionSourceNode.getEventSourceOfs().length === 0) {
695
- errorLog("conditionSourceNode = ", conditionSourceNode.browseName.toString());
696
- errorLog("conditionSourceNode = ", conditionSourceNode.nodeId.toString());
697
- throw new Error("conditionSourceNode must be an event source " +
698
- conditionSourceNode.browseName.toString() +
699
- conditionSourceNode.nodeId.toString());
700
- }
701
- }
702
- // set source Node (defined in UABaseEventType)
703
- conditionNode.sourceNode.setValueFromSource(conditionSourceNode.readAttribute(null, node_opcua_data_model_1.AttributeIds.NodeId).value);
704
- // set source Name (defined in UABaseEventType)
705
- const displayName = conditionSourceNode.readAttribute(null, node_opcua_data_model_1.AttributeIds.DisplayName).value
706
- .value;
707
- conditionNode.sourceName.setValueFromSource({ dataType: node_opcua_variant_1.DataType.String, value: displayName.text });
708
- }
709
- }
710
- conditionNode.eventType.setValueFromSource({
711
- dataType: node_opcua_variant_1.DataType.NodeId,
712
- value: conditionType.nodeId
713
- });
714
- // as per spec:
715
- /**
716
- *
717
- * dataType: DataType.NodeId
718
- *
719
- * As per spec OPCUA 1.03 part 9:
720
- * ConditionClassId specifies in which domain this Condition is used. It is the NodeId of the
721
- * corresponding ConditionClassType. See 5.9 for the definition of ConditionClass and a set of
722
- * ConditionClasses defined in this standard. When using this Property for filtering, Clients have
723
- * to specify all individual ConditionClassType NodeIds. The OfType operator cannot be applied.
724
- * BaseConditionClassType is used as class whenever a Condition cannot be assigned to a
725
- * more concrete class.
726
- *
727
- * BaseConditionClassType
728
- * |
729
- * +---------------------------+----------------------------+
730
- * | | |
731
- * ProcessConditionClassType MaintenanceConditionClassType SystemConditionClassType
732
- *
733
- * @property conditionName
734
- * @type {UAVariable}
735
- */
736
- const baseConditionClassType = addressSpace.findObjectType("ProcessConditionClassType");
737
- // assert(baseConditionClassType,"Expecting BaseConditionClassType to be in addressSpace");
738
- let conditionClassId = baseConditionClassType ? baseConditionClassType.nodeId : new node_opcua_nodeid_1.NodeId();
739
- let conditionClassName = baseConditionClassType ? baseConditionClassType.displayName[0] : "";
740
- if (options.conditionClass) {
741
- if (typeof options.conditionClass === "string") {
742
- options.conditionClass = addressSpace.findObjectType(options.conditionClass);
743
- }
744
- const conditionClassNode = addressSpace._coerceNode(options.conditionClass);
745
- if (!conditionClassNode) {
746
- throw new Error("cannot find condition class " + options.conditionClass.toString());
747
- }
748
- conditionClassId = conditionClassNode.nodeId;
749
- conditionClassName = conditionClassNode.displayName[0];
750
- }
751
- conditionNode.conditionClassId.setValueFromSource({
752
- dataType: node_opcua_variant_1.DataType.NodeId,
753
- value: conditionClassId
754
- });
755
- // as per spec:
756
- // ConditionClassName provides the display name of the ConditionClassType.
757
- conditionNode.conditionClassName.setValueFromSource({
758
- dataType: node_opcua_variant_1.DataType.LocalizedText,
759
- value: (0, node_opcua_data_model_1.coerceLocalizedText)(conditionClassName)
760
- });
761
- // as per spec:
762
- /**
763
- *
764
- * dataType: DataType.String
765
- *
766
- * As per spec OPCUA 1.03 part 9:
767
- * ConditionName identifies the Condition instance that the Event originated from. It can be used
768
- * together with the SourceName in a user display to distinguish between different Condition
769
- * instances. If a ConditionSource has only one instance of a ConditionType, and the Server has
770
- * no instance name, the Server shall supply the ConditionType browse name.
771
- * @property conditionName
772
- * @type {UAVariable}
773
- */
774
- const conditionName = options.conditionName || "Unset Condition Name";
775
- (0, node_opcua_assert_1.assert)(typeof conditionName === "string");
776
- conditionNode.conditionName.setValueFromSource({
777
- dataType: node_opcua_variant_1.DataType.String,
778
- value: conditionName
779
- });
780
- // set SourceNode and SourceName based on HasCondition node
781
- const sourceNodes = conditionNode.findReferencesAsObject("HasCondition", false);
782
- if (sourceNodes.length) {
783
- (0, node_opcua_assert_1.assert)(sourceNodes.length === 1);
784
- conditionNode.setSourceNode(sourceNodes[0].nodeId);
785
- conditionNode.setSourceName(sourceNodes[0].browseName.toString());
786
- }
787
- conditionNode.post_initialize();
788
- const branch0 = conditionNode.currentBranch();
789
- branch0.setRetain(false);
790
- branch0.setComment("");
791
- branch0.setQuality(node_opcua_status_code_1.StatusCodes.Good);
792
- branch0.setSeverity(0);
793
- branch0.setLocalTime(new node_opcua_types_1.TimeZoneDataType({
794
- daylightSavingInOffset: false,
795
- offset: 0
796
- }));
797
- branch0.setMessage("");
798
- branch0.setReceiveTime(node_opcua_factory_1.minDate);
799
- branch0.setTime(node_opcua_factory_1.minDate);
800
- return conditionNode;
801
- }
802
- function _disable_method(inputArguments, context, callback) {
803
- (0, node_opcua_assert_1.assert)(inputArguments.length === 0);
804
- const conditionNode = context.object;
805
- (0, node_opcua_assert_1.assert)(conditionNode);
806
- // istanbul ignore next
807
- if (!(conditionNode instanceof UAConditionImpl)) {
808
- console.log("conditionNode is not a UACondition ", conditionNode === null || conditionNode === void 0 ? void 0 : conditionNode.toString());
809
- return callback(null, {
810
- statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdInvalid
811
- });
812
- }
813
- const statusCode = conditionNode._setEnabledState(false);
814
- return callback(null, {
815
- statusCode
816
- });
817
- }
818
- function _enable_method(inputArguments, context, callback) {
819
- (0, node_opcua_assert_1.assert)(inputArguments.length === 0);
820
- const conditionNode = context.object;
821
- (0, node_opcua_assert_1.assert)(conditionNode);
822
- if (!(conditionNode instanceof UAConditionImpl)) {
823
- return callback(null, {
824
- statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdInvalid
825
- });
826
- }
827
- const statusCode = conditionNode._setEnabledState(true);
828
- return callback(null, {
829
- statusCode
830
- });
831
- }
832
- function _condition_refresh_method(inputArguments, context, callback) {
833
- // arguments : IntegerId SubscriptionId
834
- (0, node_opcua_assert_1.assert)(inputArguments.length === 1);
835
- const addressSpace = context.object.addressSpace;
836
- if (doDebug) {
837
- debugLog(chalk.red(" ConditionType.ConditionRefresh ! subscriptionId ="), inputArguments[0].toString());
838
- }
839
- const subscriptionId = inputArguments[0].value;
840
- let statusCode = _check_subscription_id_is_valid(subscriptionId, context);
841
- if (statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
842
- return statusCode;
843
- }
844
- statusCode = _perform_condition_refresh(addressSpace, inputArguments, context);
845
- return callback(null, {
846
- statusCode
847
- });
848
- }
849
- function _perform_condition_refresh(addressSpace, inputArguments, context) {
850
- // --- possible StatusCodes:
851
- //
852
- // Bad_SubscriptionIdInvalid See Part 4 for the description of this result code
853
- // Bad_RefreshInProgress See Table 74 for the description of this result code
854
- // Bad_UserAccessDenied The Method was not called in the context of the Session
855
- // that owns the Subscription
856
- //
857
- // istanbul ignore next
858
- if (addressSpace._condition_refresh_in_progress) {
859
- // a refresh operation is already in progress....
860
- return node_opcua_status_code_1.StatusCodes.BadRefreshInProgress;
861
- }
862
- addressSpace._condition_refresh_in_progress = true;
863
- const server = context.object.addressSpace.rootFolder.objects.server;
864
- const refreshStartEventType = addressSpace.findEventType("RefreshStartEventType");
865
- const refreshEndEventType = addressSpace.findEventType("RefreshEndEventType");
866
- server.raiseEvent(refreshStartEventType, {});
867
- // todo : resend retained conditions
868
- const _server = server;
869
- // starting from server object ..
870
- // evaluated all --> hasNotifier/hasEventSource -> node
871
- _server._conditionRefresh();
872
- server.raiseEvent(refreshEndEventType, {});
873
- addressSpace._condition_refresh_in_progress = false;
874
- return node_opcua_status_code_1.StatusCodes.Good;
875
- }
876
- function _condition_refresh2_method(inputArguments, context, callback) {
877
- // arguments : IntegerId SubscriptionId
878
- // arguments : IntegerId MonitoredItemId
879
- (0, node_opcua_assert_1.assert)(inputArguments.length === 2);
880
- if (!context.object) {
881
- throw new Error("Invalid context => missing Object");
882
- }
883
- const addressSpace = context.object.addressSpace;
884
- // istanbul ignore next
885
- if (doDebug) {
886
- debugLog(chalk.cyan.bgWhite(" ConditionType.conditionRefresh2 !"));
887
- }
888
- // xx var subscriptionId = inputArguments[0].value;
889
- // xx var monitoredItemId = inputArguments[1].value;
890
- const statusCode = _perform_condition_refresh(addressSpace, inputArguments, context);
891
- return callback(null, {
892
- statusCode
893
- });
894
- }
895
- function _add_comment_method(inputArguments, context, callback) {
896
- //
897
- // The AddComment Method is used to apply a comment to a specific state of a Condition
898
- // instance. Normally, the NodeId of the object instance as the ObjectId is passed to the Call
899
- // Service. However, some Servers do not expose Condition instances in the AddressSpace.
900
- // Therefore all Servers shall also allow Clients to call the AddComment Method by specifying
901
- // ConditionId as the ObjectId. The Method cannot be called with an ObjectId of the
902
- // ConditionType Node.
903
- // Signature
904
- // - EventId EventId identifying a particular Event Notification where a state was reported for a
905
- // Condition.
906
- // - Comment A localized text to be applied to the Condition.
907
- //
908
- // AlwaysGeneratesEvent AuditConditionCommentEventType
909
- //
910
- UAConditionImpl.with_condition_method(inputArguments, context, callback, (conditionEventId, comment, branch, conditionNode) => {
911
- (0, node_opcua_assert_1.assert)(inputArguments instanceof Array);
912
- (0, node_opcua_assert_1.assert)(conditionEventId instanceof Buffer || conditionEventId === null);
913
- (0, node_opcua_assert_1.assert)(branch instanceof condition_snapshot_1.ConditionSnapshot);
914
- branch.setComment(comment);
915
- const sourceName = "Method/AddComment";
916
- conditionNode._raiseAuditConditionCommentEvent(sourceName, conditionEventId, comment);
917
- // raise new event
918
- conditionNode.raiseConditionEvent(branch, true);
919
- /**
920
- * raised when the branch has been added a comment
921
- * @event addComment
922
- * @param conditionEventId NodeId|null
923
- * @param comment {LocalizedText}
924
- * @param branch {ConditionSnapshot}
925
- */
926
- conditionNode.emit("addComment", conditionEventId, comment, branch);
927
- return node_opcua_status_code_1.StatusCodes.Good;
928
- });
929
- }
930
- function sameBuffer(b1, b2) {
931
- if (!b1 && !b2) {
932
- return true;
933
- }
934
- if (b1 && !b2) {
935
- return false;
936
- }
937
- if (!b1 && b2) {
938
- return false;
939
- }
940
- (0, node_opcua_assert_1.assert)(b1 instanceof Buffer);
941
- (0, node_opcua_assert_1.assert)(b2 instanceof Buffer);
942
- if (b1.length !== b2.length) {
943
- return false;
944
- }
945
- /*
946
- var bb1 = (Buffer.from(b1)).toString("hex");
947
- var bb2 = (Buffer.from(b2)).toString("hex");
948
- return bb1 === bb2;
949
- */
950
- const n = b1.length;
951
- for (let i = 0; i < n; i++) {
952
- if (b1[i] !== b2[i]) {
953
- return false;
954
- }
955
- }
956
- return true;
957
- }
958
- function _create_new_branch_id() {
959
- return (0, node_opcua_nodeid_1.makeNodeId)((0, node_opcua_basic_types_1.randomGuid)(), 1);
960
- }
961
- function _update_sourceTimestamp(dataValue /*, indexRange*/) {
962
- this.sourceTimestamp.setValueFromSource({
963
- dataType: node_opcua_variant_1.DataType.DateTime,
964
- value: dataValue.sourceTimestamp
965
- });
966
- }
967
- // tslint:disable:no-console
968
- function _install_condition_variable_type(node) {
969
- // from spec 1.03 : 5.3 condition variables
970
- // However, a change in their value is considered important and supposed to trigger
971
- // an Event Notification. These information elements are called ConditionVariables.
972
- if (node.sourceTimestamp) {
973
- node.sourceTimestamp.accessLevel = (0, node_opcua_data_model_1.makeAccessLevelFlag)("CurrentRead");
974
- }
975
- else {
976
- console.warn("cannot find node.sourceTimestamp", node.browseName.toString());
977
- }
978
- node.accessLevel = (0, node_opcua_data_model_1.makeAccessLevelFlag)("CurrentRead");
979
- // from spec 1.03 : 5.3 condition variables
980
- // a condition VariableType has a sourceTimeStamp exposed property
981
- // SourceTimestamp indicates the time of the last change of the Value of this ConditionVariable.
982
- // It shall be the same time that would be returned from the Read Service inside the DataValue
983
- // structure for the ConditionVariable Value Attribute.
984
- (0, node_opcua_assert_1.assert)(node.typeDefinitionObj.browseName.toString() === "ConditionVariableType");
985
- (0, node_opcua_assert_1.assert)(node.sourceTimestamp.browseName.toString() === "SourceTimestamp");
986
- node.on("value_changed", _update_sourceTimestamp);
987
- }
988
- /**
989
- * @method _getCompositeKey
990
- * @param node {BaseNode}
991
- * @param key {String}
992
- * @return {BaseNode}
993
- * @private
994
- *
995
- * @example
996
- *
997
- * var node = _getComposite(node,"enabledState.id");
998
- *
999
- */
1000
- function _getCompositeKey(node, key) {
1001
- let cur = node;
1002
- const elements = key.split(".");
1003
- for (const e of elements) {
1004
- // istanbul ignore next
1005
- if (!Object.prototype.hasOwnProperty.call(cur, e)) {
1006
- throw new Error(" cannot extract '" + key + "' from " + node.browseName.toString());
1007
- }
1008
- cur = cur[e];
1009
- }
1010
- return cur;
1011
- }
1012
- /**
1013
- * verify that the subscription id belongs to the session that make the call.
1014
- * @method _check_subscription_id_is_valid
1015
- * @param subscriptionId {Number}
1016
- * @param context {Object}
1017
- * @private
1018
- */
1019
- function _check_subscription_id_is_valid(subscriptionId, context) {
1020
- /// todo: return StatusCodes.BadSubscriptionIdInvalid; if subscriptionId doesn't belong to session...
1021
- return node_opcua_status_code_1.StatusCodes.Good;
1022
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UAConditionImpl = void 0;
4
+ /* eslint-disable complexity */
5
+ /**
6
+ * @module node-opcua-address-space.AlarmsAndConditions
7
+ */
8
+ const chalk = require("chalk");
9
+ const node_opcua_assert_1 = require("node-opcua-assert");
10
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
11
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
12
+ const node_opcua_debug_1 = require("node-opcua-debug");
13
+ const node_opcua_factory_1 = require("node-opcua-factory");
14
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
16
+ const node_opcua_types_1 = require("node-opcua-types");
17
+ const node_opcua_variant_1 = require("node-opcua-variant");
18
+ const ua_two_state_variable_1 = require("../state_machine/ua_two_state_variable");
19
+ const ua_object_impl_1 = require("../ua_object_impl");
20
+ const ua_base_event_impl_1 = require("./ua_base_event_impl");
21
+ const condition_snapshot_1 = require("./condition_snapshot");
22
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
23
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
24
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
25
+ /**
26
+ *
27
+ * └─ ConditionType
28
+ * ├─ DialogConditionType
29
+ * └─ AcknowledgeableConditionType
30
+ * └─ AlarmConditionType
31
+ * ├─ LimitAlarmType
32
+ * │ ├─ ExclusiveLimitAlarmType
33
+ * │ │ ├─ ExclusiveLevelAlarmType
34
+ * │ │ ├─ ExclusiveDeviationAlarmType
35
+ * │ │ └─ ExclusiveRateOfChangeAlarmType
36
+ * │ └─ NonExclusiveLimitAlarmType
37
+ * │ ├─ NonExclusiveLevelAlarmType
38
+ * │ ├─ NonExclusiveDeviationAlarmType
39
+ * │ └─ NonExclusiveRateOfChangeAlarmType
40
+ * └─ DiscreteAlarmType
41
+ * ├─ OffNormalAlarmType
42
+ * │ ├─ SystemOffNormalAlarmType
43
+ * │ │ └─ CertificateExpirationAlarmType
44
+ * │ └─ TripAlarmType
45
+ *
46
+ */
47
+ class UAConditionImpl extends ua_base_event_impl_1.UABaseEventImpl {
48
+ constructor() {
49
+ super(...arguments);
50
+ this._branch0 = null;
51
+ this._previousRetainFlag = false;
52
+ this._branches = {};
53
+ }
54
+ static instantiate(namespace, conditionTypeId, options, data) {
55
+ return UACondition_instantiate(namespace, conditionTypeId, options, data);
56
+ }
57
+ static install_condition_refresh_handle(addressSpace) {
58
+ //
59
+ // install ConditionRefresh
60
+ //
61
+ // NOTE:
62
+ // OPCUA doesn't implement the condition refresh method ! yet
63
+ // .5.7 ConditionRefresh Method
64
+ // ConditionRefresh allows a Client to request a Refresh of all Condition instances that currently
65
+ // are in an interesting state (they have the Retain flag set). This includes previous states of a
66
+ // Condition instance for which the Server maintains Branches. A Client would typically invoke
67
+ // this Method when it initially connects to a Server and following any situations, such as
68
+ // communication disruptions, in which it would require resynchronization with the Server. This
69
+ // Method is only available on the ConditionType or its subtypes. To invoke this Method, the call
70
+ // shall pass the well known MethodId of the Method on the ConditionType and the ObjectId
71
+ // shall be the well known ObjectId of the ConditionType Object.
72
+ const conditionType = addressSpace.findEventType("ConditionType");
73
+ (0, node_opcua_assert_1.assert)(conditionType !== null);
74
+ conditionType.disable.bindMethod(_disable_method);
75
+ conditionType.enable.bindMethod(_enable_method);
76
+ conditionType.conditionRefresh.bindMethod(_condition_refresh_method);
77
+ conditionType.conditionRefresh2.bindMethod(_condition_refresh2_method);
78
+ // those methods can be call on the ConditionType or on the ConditionInstance itself...
79
+ conditionType.addComment.bindMethod(_add_comment_method);
80
+ }
81
+ /**
82
+ *
83
+ * Helper method to handle condition methods that takes a branchId and a comment
84
+ *
85
+ */
86
+ static with_condition_method(inputArguments, context, callback, inner_func) {
87
+ const conditionNode = context.object;
88
+ // xx console.log(inputArguments.map(function(a){return a.toString()}));
89
+ if (!(conditionNode instanceof UAConditionImpl)) {
90
+ callback(null, {
91
+ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdInvalid
92
+ });
93
+ return;
94
+ }
95
+ if (!conditionNode.getEnabledState()) {
96
+ callback(null, {
97
+ statusCode: node_opcua_status_code_1.StatusCodes.BadConditionDisabled
98
+ });
99
+ return;
100
+ }
101
+ // inputArguments has 2 arguments
102
+ // EventId => ByteString The Identifier of the event to comment
103
+ // Comment => LocalizedText The Comment to add to the condition
104
+ (0, node_opcua_assert_1.assert)(inputArguments.length === 2);
105
+ (0, node_opcua_assert_1.assert)(inputArguments[0].dataType === node_opcua_variant_1.DataType.ByteString);
106
+ (0, node_opcua_assert_1.assert)(inputArguments[1].dataType === node_opcua_variant_1.DataType.LocalizedText);
107
+ const eventId = inputArguments[0].value;
108
+ (0, node_opcua_assert_1.assert)(!eventId || eventId instanceof Buffer);
109
+ const comment = inputArguments[1].value;
110
+ (0, node_opcua_assert_1.assert)(comment instanceof node_opcua_data_model_1.LocalizedText);
111
+ const branch = conditionNode._findBranchForEventId(eventId);
112
+ if (!branch) {
113
+ callback(null, {
114
+ statusCode: node_opcua_status_code_1.StatusCodes.BadEventIdUnknown
115
+ });
116
+ return;
117
+ }
118
+ (0, node_opcua_assert_1.assert)(branch instanceof condition_snapshot_1.ConditionSnapshot);
119
+ const statusCode = inner_func(eventId, comment, branch, conditionNode);
120
+ // record also who did the call
121
+ branch.setClientUserId(context.userIdentity || "<unknown client user id>");
122
+ callback(null, {
123
+ statusCode
124
+ });
125
+ }
126
+ /**
127
+ * @method initialize
128
+ * @private
129
+ */
130
+ initialize() {
131
+ this._branches = {};
132
+ }
133
+ /**
134
+ * @method post_initialize
135
+ * @private
136
+ */
137
+ post_initialize() {
138
+ (0, node_opcua_assert_1.assert)(!this._branch0);
139
+ this._branch0 = new condition_snapshot_1.ConditionSnapshot(this, new node_opcua_nodeid_1.NodeId());
140
+ // the condition OPCUA object alway reflects the default branch states
141
+ // so we set a mechanism that automatically keeps self in sync
142
+ // with the default branch.
143
+ // the implication of this convention is that interacting with the condition variable
144
+ // shall be made by using branch0, any value change made
145
+ // using the standard setValueFromSource mechanism will not be work properly.
146
+ this._branch0.on("value_changed", (node, variant) => {
147
+ (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
148
+ node.setValueFromSource(variant);
149
+ });
150
+ }
151
+ getBranchCount() {
152
+ return Object.keys(this._branches).length;
153
+ }
154
+ getBranches() {
155
+ return Object.keys(this._branches).map((x) => {
156
+ return this._branches[x];
157
+ });
158
+ }
159
+ getBranchIds() {
160
+ return this.getBranches().map((b) => b.getBranchId());
161
+ }
162
+ /**
163
+ * @method createBranch
164
+ * @return {ConditionSnapshot}
165
+ */
166
+ createBranch() {
167
+ const branchId = _create_new_branch_id();
168
+ const snapshot = new condition_snapshot_1.ConditionSnapshot(this, branchId);
169
+ this._branches[branchId.toString()] = snapshot;
170
+ return snapshot;
171
+ }
172
+ /**
173
+ * @method deleteBranch
174
+ * @param branch {ConditionSnapshot}
175
+ */
176
+ deleteBranch(branch) {
177
+ const key = branch.getBranchId().toString();
178
+ (0, node_opcua_assert_1.assert)(!(0, node_opcua_nodeid_1.sameNodeId)(branch.getBranchId(), node_opcua_nodeid_1.NodeId.nullNodeId), "cannot delete branch zero");
179
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(this._branches, key));
180
+ delete this._branches[key];
181
+ this.emit("branch_deleted", key);
182
+ }
183
+ /**
184
+ * @method getEnabledState
185
+ * @return {Boolean}
186
+ */
187
+ getEnabledState() {
188
+ return this.enabledState.getValue();
189
+ }
190
+ /**
191
+ * @method getEnabledStateAsString
192
+ * @return {String}
193
+ */
194
+ getEnabledStateAsString() {
195
+ return this.enabledState.getValueAsString();
196
+ }
197
+ /**
198
+ * returns {StatusCode} StatusCodes.Good if successful or BadConditionAlreadyEnabled/BadConditionAlreadyDisabled
199
+ * @private
200
+ */
201
+ _setEnabledState(requestedEnabledState) {
202
+ (0, node_opcua_assert_1.assert)(typeof requestedEnabledState === "boolean");
203
+ const enabledState = this.getEnabledState();
204
+ if (enabledState && requestedEnabledState) {
205
+ return node_opcua_status_code_1.StatusCodes.BadConditionAlreadyEnabled;
206
+ }
207
+ if (!enabledState && !requestedEnabledState) {
208
+ return node_opcua_status_code_1.StatusCodes.BadConditionAlreadyDisabled;
209
+ }
210
+ this._branch0.setEnabledState(requestedEnabledState);
211
+ // conditionNode.enabledState.setValue(requestedEnabledState);
212
+ // xx assert(conditionNode.enabledState.id.readValue().value.value === requestedEnabledState,"sanity check 1");
213
+ // xx assert(conditionNode.currentBranch().getEnabledState() === requestedEnabledState,"sanity check 2");
214
+ if (!requestedEnabledState) {
215
+ // as per Spec 1.0.3 part 9:
216
+ // * When the Condition instance enters the Disabled state, the Retain Property of this
217
+ // Condition shall be set to FALSE by the Server to indicate to the Client that the
218
+ // Condition instance is currently not of interest to Clients.
219
+ // TODO : shall we really set retain to false or artificially expose the retain false as false
220
+ // whist enabled state is false ?
221
+ this._previousRetainFlag = this.currentBranch().getRetain();
222
+ this.currentBranch().setRetain(false);
223
+ // todo: install the mechanism by which all condition values will be return
224
+ // as Null | BadConditionDisabled;
225
+ const statusCode = node_opcua_status_code_1.StatusCodes.BadConditionDisabled;
226
+ // a notification must be send
227
+ this.raiseConditionEvent(this.currentBranch(), true);
228
+ }
229
+ else {
230
+ // * When the Condition instance enters the enabled state, the Condition shall be
231
+ // evaluated and all of its Properties updated to reflect the current values. If this
232
+ // evaluation causes the Retain Property to transition to TRUE for any ConditionBranch,
233
+ // then an Event Notification shall be generated for that ConditionBranch.
234
+ this.evaluateConditionsAfterEnabled();
235
+ // todo evaluate branches
236
+ // conditionNode.evaluateBranches();
237
+ // restore retain flag
238
+ if (Object.prototype.hasOwnProperty.call(this, "_previousRetainFlag")) {
239
+ this.currentBranch().setRetain(this._previousRetainFlag);
240
+ }
241
+ // todo send notification for branches with retain = true
242
+ let nb_condition_resent = 0;
243
+ if (this.currentBranch().getRetain()) {
244
+ nb_condition_resent += this._resend_conditionEvents();
245
+ }
246
+ if (nb_condition_resent === 0) {
247
+ // a notification must be send
248
+ this.raiseConditionEvent(this.currentBranch(), true);
249
+ }
250
+ }
251
+ return node_opcua_status_code_1.StatusCodes.Good;
252
+ }
253
+ /**
254
+ *
255
+ * @method setEnabledState
256
+ * @param requestedEnabledState {Boolean}
257
+ * @private
258
+ */
259
+ setEnabledState(requestedEnabledState) {
260
+ return this._setEnabledState(requestedEnabledState);
261
+ }
262
+ /**
263
+ * @method setReceiveTime
264
+ * @param time {Date}
265
+ */
266
+ setReceiveTime(time) {
267
+ return this._branch0.setReceiveTime(time);
268
+ }
269
+ /**
270
+ * @method setLocalTime (optional)
271
+ * @param time
272
+ */
273
+ setLocalTime(time) {
274
+ return this._branch0.setLocalTime(time);
275
+ }
276
+ /**
277
+ * @method setTime
278
+ * @param time {Date}
279
+ */
280
+ setTime(time) {
281
+ return this._branch0.setTime(time);
282
+ }
283
+ _assert_valid() {
284
+ (0, node_opcua_assert_1.assert)(this.receiveTime.readValue().value.dataType === node_opcua_variant_1.DataType.DateTime);
285
+ (0, node_opcua_assert_1.assert)(this.receiveTime.readValue().value.value instanceof Date);
286
+ (0, node_opcua_assert_1.assert)(this.message.readValue().value.dataType === node_opcua_variant_1.DataType.LocalizedText);
287
+ (0, node_opcua_assert_1.assert)(this.severity.readValue().value.dataType === node_opcua_variant_1.DataType.UInt16);
288
+ (0, node_opcua_assert_1.assert)(this.time.readValue().value.dataType === node_opcua_variant_1.DataType.DateTime);
289
+ (0, node_opcua_assert_1.assert)(this.time.readValue().value.value instanceof Date);
290
+ (0, node_opcua_assert_1.assert)(this.quality.readValue().value.dataType === node_opcua_variant_1.DataType.StatusCode);
291
+ (0, node_opcua_assert_1.assert)(this.enabledState.readValue().value.dataType === node_opcua_variant_1.DataType.LocalizedText);
292
+ (0, node_opcua_assert_1.assert)(this.branchId.readValue().value.dataType === node_opcua_variant_1.DataType.NodeId);
293
+ // note localTime has been made optional in 1.04
294
+ (0, node_opcua_assert_1.assert)(!this.localTime || this.localTime.readValue().value.dataType === node_opcua_variant_1.DataType.ExtensionObject);
295
+ }
296
+ /**
297
+ * @method conditionOfNode
298
+ * @return {UAObject}
299
+ */
300
+ conditionOfNode() {
301
+ const refs = this.findReferencesExAsObject("HasCondition", node_opcua_data_model_1.BrowseDirection.Inverse);
302
+ if (refs.length === 0) {
303
+ return null;
304
+ }
305
+ (0, node_opcua_assert_1.assert)(refs.length !== 0, "UACondition must be the condition of some node");
306
+ (0, node_opcua_assert_1.assert)(refs.length === 1, "expecting only one ConditionOf");
307
+ const node = refs[0];
308
+ (0, node_opcua_assert_1.assert)(node.nodeClass === node_opcua_data_model_1.NodeClass.Object || node.nodeClass === node_opcua_data_model_1.NodeClass.Variable, "node for which we are the condition shall be an UAObject or UAVariable");
309
+ return node;
310
+ }
311
+ /**
312
+ * @method raiseConditionEvent
313
+ * Raise a Instance Event
314
+ * (see also UAObject#raiseEvent to raise a transient event)
315
+ * @param branch the condition branch to raise
316
+ * @param renewEventId true if event Id of the condition branch should be renewed
317
+ */
318
+ raiseConditionEvent(branch, renewEventId) {
319
+ (0, node_opcua_assert_1.assert)(arguments.length === 2, "expecting 2 arguments");
320
+ if (renewEventId) {
321
+ branch.renewEventId();
322
+ }
323
+ // xx console.log("MMMMMMMM%%%%%%%%%%%%%%%%%%%%% branch " +
324
+ // branch.getBranchId().toString() + " eventId = " + branch.getEventId().toString("hex"));
325
+ (0, node_opcua_assert_1.assert)(branch instanceof condition_snapshot_1.ConditionSnapshot);
326
+ this._assert_valid();
327
+ // In fact the event is raised by the object of which we are the condition
328
+ const conditionOfNode = this.conditionOfNode();
329
+ if (conditionOfNode) {
330
+ const eventData = branch._constructEventData();
331
+ this.emit("event", eventData);
332
+ if (conditionOfNode instanceof ua_object_impl_1.UAObjectImpl) {
333
+ // xx assert(conditionOfNode.eventNotifier === 0x01);
334
+ conditionOfNode._bubble_up_event(eventData);
335
+ }
336
+ else {
337
+ (0, node_opcua_assert_1.assert)(conditionOfNode.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
338
+ // in this case
339
+ const eventOfs = conditionOfNode.getEventSourceOfs();
340
+ (0, node_opcua_assert_1.assert)(eventOfs.length === 1);
341
+ const node = eventOfs[0];
342
+ if (node instanceof ua_object_impl_1.UAObjectImpl) {
343
+ node._bubble_up_event(eventData);
344
+ }
345
+ }
346
+ }
347
+ // xx console.log("MMMMMMMM%%%%%%%%%%%%%%%%%%%%% branch " +
348
+ // branch.getBranchId().toString() + " eventId = " + branch.getEventId().toString("hex"));
349
+ }
350
+ /**
351
+ *
352
+ * @method raiseNewCondition
353
+ * @param conditionInfo {ConditionInfo}
354
+ *
355
+ */
356
+ raiseNewCondition(conditionInfo) {
357
+ if (!this.getEnabledState()) {
358
+ throw new Error("UACondition#raiseNewCondition Condition is not enabled");
359
+ }
360
+ conditionInfo = conditionInfo || {};
361
+ conditionInfo.severity = Object.prototype.hasOwnProperty.call(conditionInfo, "severity")
362
+ ? conditionInfo.severity
363
+ : UAConditionImpl.defaultSeverity;
364
+ // only valid for ConditionObjects
365
+ // todo check that object is of type ConditionType
366
+ const addressSpace = this.addressSpace;
367
+ const selfConditionType = this.typeDefinitionObj;
368
+ const conditionType = addressSpace.findObjectType("ConditionType");
369
+ (0, node_opcua_assert_1.assert)(selfConditionType.isSupertypeOf(conditionType));
370
+ const branch = this.currentBranch();
371
+ const now = new Date();
372
+ // install the eventTimestamp
373
+ // set the received Time
374
+ branch.setTime(now);
375
+ branch.setReceiveTime(now);
376
+ // note : in 1.04 LocalTime property is optional
377
+ if (Object.prototype.hasOwnProperty.call(this, "localTime")) {
378
+ branch.setLocalTime(new node_opcua_types_1.TimeZoneDataType({
379
+ daylightSavingInOffset: false,
380
+ offset: 0
381
+ }));
382
+ }
383
+ if (Object.prototype.hasOwnProperty.call(conditionInfo, "message") && conditionInfo.message) {
384
+ branch.setMessage(conditionInfo.message);
385
+ }
386
+ // todo receive time : when the server received the event from the underlying system.
387
+ // self.receiveTime.setValueFromSource();
388
+ if (Object.prototype.hasOwnProperty.call(conditionInfo, "severity") && conditionInfo.severity !== null) {
389
+ (0, node_opcua_assert_1.assert)(isFinite(conditionInfo.severity));
390
+ branch.setSeverity(conditionInfo.severity);
391
+ }
392
+ if (Object.prototype.hasOwnProperty.call(conditionInfo, "quality") && conditionInfo.quality !== null) {
393
+ (0, node_opcua_assert_1.assert)(conditionInfo.quality instanceof node_opcua_status_code_1.StatusCode);
394
+ branch.setQuality(conditionInfo.quality);
395
+ }
396
+ if (Object.prototype.hasOwnProperty.call(conditionInfo, "retain") && conditionInfo.retain !== null) {
397
+ (0, node_opcua_assert_1.assert)(typeof conditionInfo.retain === "boolean");
398
+ branch.setRetain(!!conditionInfo.retain);
399
+ }
400
+ this.raiseConditionEvent(branch, true);
401
+ }
402
+ raiseNewBranchState(branch) {
403
+ this.raiseConditionEvent(branch, true);
404
+ if (!(0, node_opcua_nodeid_1.sameNodeId)(branch.getBranchId(), node_opcua_nodeid_1.NodeId.nullNodeId) && !branch.getRetain()) {
405
+ // xx console.log(" Deleting not longer needed branch ", branch.getBranchId().toString());
406
+ // branch can be deleted
407
+ this.deleteBranch(branch);
408
+ }
409
+ }
410
+ /**
411
+ * @method currentBranch
412
+ * @return {ConditionSnapshot}
413
+ */
414
+ currentBranch() {
415
+ return this._branch0;
416
+ }
417
+ _resend_conditionEvents() {
418
+ // for the time being , only current branch
419
+ const currentBranch = this.currentBranch();
420
+ if (currentBranch.getRetain()) {
421
+ debugLog(" resending condition event for " + this.browseName.toString());
422
+ this.raiseConditionEvent(currentBranch, false);
423
+ return 1;
424
+ }
425
+ return 0;
426
+ }
427
+ // ------------------------------------------------------------------------------------
428
+ // Acknowledgeable
429
+ // ------------------------------------------------------------------------------------
430
+ /**
431
+ * @method _raiseAuditConditionCommentEvent
432
+ * @param sourceName {string}
433
+ * @param conditionEventId {Buffer}
434
+ * @param comment {LocalizedText}
435
+ * @private
436
+ */
437
+ _raiseAuditConditionCommentEvent(sourceName, conditionEventId, comment) {
438
+ (0, node_opcua_assert_1.assert)(conditionEventId === null || conditionEventId instanceof Buffer);
439
+ (0, node_opcua_assert_1.assert)(comment instanceof node_opcua_data_model_1.LocalizedText);
440
+ const server = this.addressSpace.rootFolder.objects.server;
441
+ const now = new Date();
442
+ // xx if (true || server.isAuditing) {
443
+ // ----------------------------------------------------------------------------------------------------
444
+ server.raiseEvent("AuditConditionCommentEventType", {
445
+ // AuditEventType
446
+ /* part 5 - 6.4.3 AuditEventType */
447
+ actionTimeStamp: {
448
+ dataType: "DateTime",
449
+ value: now
450
+ },
451
+ status: {
452
+ dataType: "Boolean",
453
+ value: true
454
+ },
455
+ serverId: {
456
+ dataType: "String",
457
+ value: ""
458
+ },
459
+ // ClientAuditEntryId contains the human-readable AuditEntryId defined in Part 3.
460
+ clientAuditEntryId: {
461
+ dataType: "String",
462
+ value: ""
463
+ },
464
+ // The ClientUserId identifies the user of the client requesting an action. The ClientUserId can be
465
+ // obtained from the UserIdentityToken passed in the ActivateSession call.
466
+ clientUserId: {
467
+ dataType: "String",
468
+ value: ""
469
+ },
470
+ sourceName: {
471
+ dataType: "String",
472
+ value: sourceName
473
+ },
474
+ // AuditUpdateMethodEventType
475
+ methodId: {
476
+ dataType: "Null"
477
+ },
478
+ inputArguments: {
479
+ dataType: "Null"
480
+ },
481
+ // AuditConditionCommentEventType
482
+ conditionEventId: {
483
+ dataType: "ByteString",
484
+ value: conditionEventId
485
+ },
486
+ comment: {
487
+ dataType: "LocalizedText",
488
+ value: comment
489
+ }
490
+ });
491
+ // xx }
492
+ }
493
+ _findBranchForEventId(eventId) {
494
+ if (sameBuffer(this.eventId.readValue().value.value, eventId)) {
495
+ return this.currentBranch();
496
+ }
497
+ const e = Object.values(this._branches).filter((branch) => sameBuffer(branch.getEventId(), eventId));
498
+ if (e.length === 1) {
499
+ return e[0];
500
+ }
501
+ (0, node_opcua_assert_1.assert)(e.length === 0, "cannot have 2 branches with same eventId");
502
+ return null; // not found
503
+ }
504
+ evaluateConditionsAfterEnabled() {
505
+ (0, node_opcua_assert_1.assert)(this.getEnabledState() === true);
506
+ throw new Error("Unimplemented , please override");
507
+ }
508
+ }
509
+ exports.UAConditionImpl = UAConditionImpl;
510
+ UAConditionImpl.defaultSeverity = 250;
511
+ UAConditionImpl.typeDefinition = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType");
512
+ /**
513
+ * instantiate a Condition.
514
+ * this will create the unique EventId and will set eventType
515
+ * @method instantiate
516
+ * @param namespace {INamespace}
517
+ * @param conditionTypeId {String|NodeId} the EventType to instantiate
518
+ * @param options {object}
519
+ * @param options.browseName {String|QualifiedName}
520
+ * @param options.componentOf {NodeId|UAObject}
521
+ * @param options.conditionOf {NodeId|UAObject} Mandatory
522
+ * @param options.organizedBy {NodeId|UAObject} ( only provide componentOf or organizedBy but not both)
523
+ * @param [options.conditionClass =BaseConditionClassType] {NodeId|UAObject}
524
+ * The condition Class nodeId or object used to set the ConditionClassId and
525
+ * ConditionClassName properties of the condition.
526
+ *
527
+ * @param options.conditionSource {NodeId|UAObject} the condition source node.
528
+ * this node must be marked a EventSource.
529
+ * the conditionSource is used to populate the sourceNode and
530
+ * sourceName variables defined by BaseEventType
531
+ * @param options.conditionName {String} the condition Name
532
+ * @param [options.optionals] [Array<String>] an Array of optionals fields
533
+ *
534
+ * @param data a object containing the value to set
535
+ * @param data.eventId {String|NodeId} the EventType Identifier to instantiate (type cannot be abstract)
536
+ * @return a instantiated UAConditionEx
537
+ */
538
+ function UACondition_instantiate(namespace, conditionTypeId, options, data) {
539
+ /* eslint max-statements: ["error", 100] */
540
+ const addressSpace = namespace.addressSpace;
541
+ const conditionType = addressSpace.findEventType(conditionTypeId);
542
+ /* istanbul ignore next */
543
+ if (!conditionType) {
544
+ throw new Error(" cannot find Condition Type for " + conditionTypeId);
545
+ }
546
+ // reminder : abstract event type cannot be instantiated directly !
547
+ (0, node_opcua_assert_1.assert)(!conditionType.isAbstract, "Cannot instantiate abstract conditionType");
548
+ const baseConditionEventType = addressSpace.findEventType("ConditionType");
549
+ /* istanbul ignore next */
550
+ if (!baseConditionEventType) {
551
+ throw new Error("cannot find ConditionType");
552
+ }
553
+ (0, node_opcua_assert_1.assert)(conditionType.isSupertypeOf(baseConditionEventType));
554
+ // assert((typeof options.browseName === "string"));
555
+ options.browseName = options.browseName || "??? instantiateCondition - missing browseName";
556
+ options.optionals = options.optionals || [];
557
+ // now optionals in 1.04
558
+ options.optionals.push("EventType");
559
+ options.optionals.push("BranchId");
560
+ //
561
+ options.optionals.push("Comment");
562
+ options.optionals.push("Comment.SourceTimestamp");
563
+ options.optionals.push("EnabledState.TrueState");
564
+ options.optionals.push("EnabledState.TrueState");
565
+ options.optionals.push("EnabledState.FalseState");
566
+ options.optionals.push("EnabledState.TransitionTime");
567
+ options.optionals.push("EnabledState.EffectiveTransitionTime");
568
+ options.optionals.push("EnabledState.EffectiveDisplayName");
569
+ const conditionNode = conditionType.instantiate(options);
570
+ Object.setPrototypeOf(conditionNode, UAConditionImpl.prototype);
571
+ conditionNode.initialize();
572
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "conditionSource"), "must specify a condition source either as null or as a UAObject");
573
+ if (!options.conditionOf) {
574
+ options.conditionOf = options.conditionSource;
575
+ }
576
+ if (options.conditionOf) {
577
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "conditionOf")); // must provide a conditionOf
578
+ options.conditionOf = addressSpace._coerceNode(options.conditionOf);
579
+ // HasCondition References can be used in the Type definition of an Object or a Variable.
580
+ (0, node_opcua_assert_1.assert)(options.conditionOf.nodeClass === node_opcua_data_model_1.NodeClass.Object || options.conditionOf.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
581
+ conditionNode.addReference({
582
+ isForward: false,
583
+ nodeId: options.conditionOf,
584
+ referenceType: "HasCondition"
585
+ });
586
+ (0, node_opcua_assert_1.assert)(conditionNode.conditionOfNode().nodeId === options.conditionOf.nodeId);
587
+ }
588
+ // the constant property of this condition
589
+ conditionNode.eventType.setValueFromSource({
590
+ dataType: node_opcua_variant_1.DataType.NodeId,
591
+ value: conditionType.nodeId
592
+ });
593
+ data = data || {};
594
+ // install initial branch ID (null NodeId);
595
+ conditionNode.branchId.setValueFromSource({
596
+ dataType: node_opcua_variant_1.DataType.NodeId,
597
+ value: new node_opcua_nodeid_1.NodeId()
598
+ });
599
+ // install 'Comment' condition variable
600
+ _install_condition_variable_type(conditionNode.comment);
601
+ // install 'Quality' condition variable
602
+ _install_condition_variable_type(conditionNode.quality);
603
+ // xx conditionNode.quality.setValueFromSource({dataType: DataType.StatusCode,value: StatusCodes.Good });
604
+ // install 'LastSeverity' condition variable
605
+ _install_condition_variable_type(conditionNode.lastSeverity);
606
+ // xx conditionNode.severity.setValueFromSource({dataType: DataType.UInt16,value: 0 });
607
+ // xx conditionNode.lastSeverity.setValueFromSource({dataType: DataType.UInt16,value: 0 });
608
+ // install 'EnabledState' TwoStateVariable
609
+ /**
610
+ * @property enabledState
611
+ * @type {UATwoStateVariable}
612
+ */
613
+ // -------------- fixing missing EnabledState.EffectiveDisplayName
614
+ if (!conditionNode.enabledState.effectiveDisplayName) {
615
+ namespace.addVariable({
616
+ browseName: new node_opcua_data_model_1.QualifiedName({ namespaceIndex: 0, name: "EffectiveDisplayName" }),
617
+ dataType: "LocalizedText",
618
+ propertyOf: conditionNode.enabledState
619
+ });
620
+ }
621
+ (0, ua_two_state_variable_1._install_TwoStateVariable_machinery)(conditionNode.enabledState, {
622
+ falseState: "Disabled",
623
+ trueState: "Enabled"
624
+ });
625
+ // installing sourceName and sourceNode
626
+ conditionNode.enabledState.setValue(true);
627
+ // set properties to in initial values
628
+ Object.entries(data).forEach(([key, value]) => {
629
+ const varNode = _getCompositeKey(conditionNode, key);
630
+ (0, node_opcua_assert_1.assert)(varNode.nodeClass === node_opcua_data_model_1.NodeClass.Variable);
631
+ const variant = new node_opcua_variant_1.Variant(value);
632
+ // check that Variant DataType is compatible with the UAVariable dataType
633
+ // xx var nodeDataType = addressSpace.findNode(varNode.dataType).browseName;
634
+ /* istanbul ignore next */
635
+ if (!varNode._validate_DataType(variant.dataType)) {
636
+ throw new Error(" Invalid variant dataType " + variant + " " + varNode.browseName.toString());
637
+ }
638
+ varNode.setValueFromSource(variant);
639
+ });
640
+ // bind condition methods -
641
+ /**
642
+ * @property enable
643
+ * @type {UAMethod}
644
+ */
645
+ conditionNode.enable.bindMethod(_enable_method);
646
+ /**
647
+ * @property disable
648
+ * @type {UAMethod}
649
+ */
650
+ conditionNode.disable.bindMethod(_disable_method);
651
+ // bind condition methods - AddComment
652
+ /**
653
+ * @property addComment
654
+ * @type {UAMethod}
655
+ */
656
+ conditionNode.addComment.bindMethod(_add_comment_method);
657
+ (0, node_opcua_assert_1.assert)(conditionNode instanceof UAConditionImpl);
658
+ // ConditionSource => cf SourceNode
659
+ // As per spec OPCUA 1.03 part 9 page 54:
660
+ // The ConditionType inherits all Properties of the BaseEventType. Their semantic is defined in
661
+ // Part 5. SourceNode identifies the ConditionSource.
662
+ // The SourceNode is the Node which the condition is associated with, it may be the same as the
663
+ // InputNode for an alarm, but it may be a separate node. For example a motor, which is a
664
+ // variable with a value that is an RPM, may be the ConditionSource for Conditions that are
665
+ // related to the motor as well as a temperature sensor associated with the motor. In the former
666
+ // the InputNode for the High RPM alarm is the value of the Motor RPM, while in the later the
667
+ // InputNode of the High Alarm would be the value of the temperature sensor that is associated
668
+ // with the motor.
669
+ if (options.conditionSource) {
670
+ options.conditionSource = addressSpace._coerceNode(options.conditionSource);
671
+ if (options.conditionSource.nodeClass !== node_opcua_data_model_1.NodeClass.Object && options.conditionSource.nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
672
+ // tslint:disable:no-console
673
+ console.log(options.conditionSource);
674
+ throw new Error("Expecting condition source to be NodeClass.Object or Variable");
675
+ }
676
+ const conditionSourceNode = addressSpace.findNode(options.conditionSource.nodeId);
677
+ if (conditionSourceNode) {
678
+ conditionNode.sourceNode.setValueFromSource({
679
+ dataType: node_opcua_variant_1.DataType.NodeId,
680
+ value: conditionSourceNode.nodeId
681
+ });
682
+ // conditionSourceNode node must be registered as a EventSource of an other node.
683
+ // As per spec OPCUA 1.03 part 9 page 54:
684
+ // HasNotifier and HasEventSource References are used to expose the hierarchical organization
685
+ // of Event notifying Objects and ConditionSources. An Event notifying Object represents
686
+ // typically an area of Operator responsibility. The definition of such an area configuration is
687
+ // outside the scope of this standard. If areas are available they shall be linked together and
688
+ // with the included ConditionSources using the HasNotifier and the HasEventSource Reference
689
+ // Types. The Server Object shall be the root of this hierarchy.
690
+ if (!(0, node_opcua_nodeid_1.sameNodeId)(conditionSourceNode.nodeId, (0, node_opcua_nodeid_1.coerceNodeId)("ns=0;i=2253"))) {
691
+ // server object
692
+ /* istanbul ignore next */
693
+ if (conditionSourceNode.getEventSourceOfs().length === 0) {
694
+ errorLog("conditionSourceNode = ", conditionSourceNode.browseName.toString());
695
+ errorLog("conditionSourceNode = ", conditionSourceNode.nodeId.toString());
696
+ throw new Error("conditionSourceNode must be an event source " +
697
+ conditionSourceNode.browseName.toString() +
698
+ conditionSourceNode.nodeId.toString());
699
+ }
700
+ }
701
+ // set source Node (defined in UABaseEventType)
702
+ conditionNode.sourceNode.setValueFromSource(conditionSourceNode.readAttribute(null, node_opcua_data_model_1.AttributeIds.NodeId).value);
703
+ // set source Name (defined in UABaseEventType)
704
+ const displayName = conditionSourceNode.readAttribute(null, node_opcua_data_model_1.AttributeIds.DisplayName).value
705
+ .value;
706
+ conditionNode.sourceName.setValueFromSource({ dataType: node_opcua_variant_1.DataType.String, value: displayName.text });
707
+ }
708
+ }
709
+ conditionNode.eventType.setValueFromSource({
710
+ dataType: node_opcua_variant_1.DataType.NodeId,
711
+ value: conditionType.nodeId
712
+ });
713
+ // as per spec:
714
+ /**
715
+ *
716
+ * dataType: DataType.NodeId
717
+ *
718
+ * As per spec OPCUA 1.03 part 9:
719
+ * ConditionClassId specifies in which domain this Condition is used. It is the NodeId of the
720
+ * corresponding ConditionClassType. See 5.9 for the definition of ConditionClass and a set of
721
+ * ConditionClasses defined in this standard. When using this Property for filtering, Clients have
722
+ * to specify all individual ConditionClassType NodeIds. The OfType operator cannot be applied.
723
+ * BaseConditionClassType is used as class whenever a Condition cannot be assigned to a
724
+ * more concrete class.
725
+ *
726
+ * BaseConditionClassType
727
+ * |
728
+ * +---------------------------+----------------------------+
729
+ * | | |
730
+ * ProcessConditionClassType MaintenanceConditionClassType SystemConditionClassType
731
+ *
732
+ * @property conditionName
733
+ * @type {UAVariable}
734
+ */
735
+ const baseConditionClassType = addressSpace.findObjectType("ProcessConditionClassType");
736
+ // assert(baseConditionClassType,"Expecting BaseConditionClassType to be in addressSpace");
737
+ let conditionClassId = baseConditionClassType ? baseConditionClassType.nodeId : new node_opcua_nodeid_1.NodeId();
738
+ let conditionClassName = baseConditionClassType ? baseConditionClassType.displayName[0] : "";
739
+ if (options.conditionClass) {
740
+ if (typeof options.conditionClass === "string") {
741
+ options.conditionClass = addressSpace.findObjectType(options.conditionClass);
742
+ if (!options.conditionClass) {
743
+ throw new Error("cannot find condition class " + options.conditionClass);
744
+ }
745
+ }
746
+ const conditionClassNode = addressSpace._coerceNode(options.conditionClass);
747
+ if (!conditionClassNode) {
748
+ throw new Error("cannot find condition class " + options.conditionClass.toString());
749
+ }
750
+ conditionClassId = conditionClassNode.nodeId;
751
+ conditionClassName = conditionClassNode.displayName[0];
752
+ }
753
+ conditionNode.conditionClassId.setValueFromSource({
754
+ dataType: node_opcua_variant_1.DataType.NodeId,
755
+ value: conditionClassId
756
+ });
757
+ // as per spec:
758
+ // ConditionClassName provides the display name of the ConditionClassType.
759
+ conditionNode.conditionClassName.setValueFromSource({
760
+ dataType: node_opcua_variant_1.DataType.LocalizedText,
761
+ value: (0, node_opcua_data_model_1.coerceLocalizedText)(conditionClassName)
762
+ });
763
+ // as per spec:
764
+ /**
765
+ *
766
+ * dataType: DataType.String
767
+ *
768
+ * As per spec OPCUA 1.03 part 9:
769
+ * ConditionName identifies the Condition instance that the Event originated from. It can be used
770
+ * together with the SourceName in a user display to distinguish between different Condition
771
+ * instances. If a ConditionSource has only one instance of a ConditionType, and the Server has
772
+ * no instance name, the Server shall supply the ConditionType browse name.
773
+ * @property conditionName
774
+ * @type {UAVariable}
775
+ */
776
+ const conditionName = options.conditionName || "Unset Condition Name";
777
+ (0, node_opcua_assert_1.assert)(typeof conditionName === "string");
778
+ conditionNode.conditionName.setValueFromSource({
779
+ dataType: node_opcua_variant_1.DataType.String,
780
+ value: conditionName
781
+ });
782
+ // set SourceNode and SourceName based on HasCondition node
783
+ const sourceNodes = conditionNode.findReferencesAsObject("HasCondition", false);
784
+ if (sourceNodes.length) {
785
+ (0, node_opcua_assert_1.assert)(sourceNodes.length === 1);
786
+ conditionNode.setSourceNode(sourceNodes[0].nodeId);
787
+ conditionNode.setSourceName(sourceNodes[0].browseName.toString());
788
+ }
789
+ conditionNode.post_initialize();
790
+ const branch0 = conditionNode.currentBranch();
791
+ branch0.setRetain(false);
792
+ branch0.setComment("");
793
+ branch0.setQuality(node_opcua_status_code_1.StatusCodes.Good);
794
+ branch0.setSeverity(0);
795
+ branch0.setLocalTime(new node_opcua_types_1.TimeZoneDataType({
796
+ daylightSavingInOffset: false,
797
+ offset: 0
798
+ }));
799
+ branch0.setMessage("");
800
+ branch0.setReceiveTime(node_opcua_factory_1.minDate);
801
+ branch0.setTime(node_opcua_factory_1.minDate);
802
+ return conditionNode;
803
+ }
804
+ function _disable_method(inputArguments, context, callback) {
805
+ (0, node_opcua_assert_1.assert)(inputArguments.length === 0);
806
+ const conditionNode = context.object;
807
+ (0, node_opcua_assert_1.assert)(conditionNode);
808
+ // istanbul ignore next
809
+ if (!(conditionNode instanceof UAConditionImpl)) {
810
+ console.log("conditionNode is not a UACondition ", conditionNode === null || conditionNode === void 0 ? void 0 : conditionNode.toString());
811
+ return callback(null, {
812
+ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdInvalid
813
+ });
814
+ }
815
+ const statusCode = conditionNode._setEnabledState(false);
816
+ return callback(null, {
817
+ statusCode
818
+ });
819
+ }
820
+ function _enable_method(inputArguments, context, callback) {
821
+ (0, node_opcua_assert_1.assert)(inputArguments.length === 0);
822
+ const conditionNode = context.object;
823
+ (0, node_opcua_assert_1.assert)(conditionNode);
824
+ if (!(conditionNode instanceof UAConditionImpl)) {
825
+ return callback(null, {
826
+ statusCode: node_opcua_status_code_1.StatusCodes.BadNodeIdInvalid
827
+ });
828
+ }
829
+ const statusCode = conditionNode._setEnabledState(true);
830
+ return callback(null, {
831
+ statusCode
832
+ });
833
+ }
834
+ function _condition_refresh_method(inputArguments, context, callback) {
835
+ // arguments : IntegerId SubscriptionId
836
+ (0, node_opcua_assert_1.assert)(inputArguments.length === 1);
837
+ const addressSpace = context.object.addressSpace;
838
+ if (doDebug) {
839
+ debugLog(chalk.red(" ConditionType.ConditionRefresh ! subscriptionId ="), inputArguments[0].toString());
840
+ }
841
+ const subscriptionId = inputArguments[0].value;
842
+ let statusCode = _check_subscription_id_is_valid(subscriptionId, context);
843
+ if (statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
844
+ return statusCode;
845
+ }
846
+ statusCode = _perform_condition_refresh(addressSpace, inputArguments, context);
847
+ return callback(null, {
848
+ statusCode
849
+ });
850
+ }
851
+ function _perform_condition_refresh(addressSpace, inputArguments, context) {
852
+ // --- possible StatusCodes:
853
+ //
854
+ // Bad_SubscriptionIdInvalid See Part 4 for the description of this result code
855
+ // Bad_RefreshInProgress See Table 74 for the description of this result code
856
+ // Bad_UserAccessDenied The Method was not called in the context of the Session
857
+ // that owns the Subscription
858
+ //
859
+ // istanbul ignore next
860
+ if (addressSpace._condition_refresh_in_progress) {
861
+ // a refresh operation is already in progress....
862
+ return node_opcua_status_code_1.StatusCodes.BadRefreshInProgress;
863
+ }
864
+ addressSpace._condition_refresh_in_progress = true;
865
+ const server = context.object.addressSpace.rootFolder.objects.server;
866
+ const refreshStartEventType = addressSpace.findEventType("RefreshStartEventType");
867
+ const refreshEndEventType = addressSpace.findEventType("RefreshEndEventType");
868
+ server.raiseEvent(refreshStartEventType, {});
869
+ // todo : resend retained conditions
870
+ const _server = server;
871
+ // starting from server object ..
872
+ // evaluated all --> hasNotifier/hasEventSource -> node
873
+ _server._conditionRefresh();
874
+ server.raiseEvent(refreshEndEventType, {});
875
+ addressSpace._condition_refresh_in_progress = false;
876
+ return node_opcua_status_code_1.StatusCodes.Good;
877
+ }
878
+ function _condition_refresh2_method(inputArguments, context, callback) {
879
+ // arguments : IntegerId SubscriptionId
880
+ // arguments : IntegerId MonitoredItemId
881
+ (0, node_opcua_assert_1.assert)(inputArguments.length === 2);
882
+ if (!context.object) {
883
+ throw new Error("Invalid context => missing Object");
884
+ }
885
+ const addressSpace = context.object.addressSpace;
886
+ // istanbul ignore next
887
+ if (doDebug) {
888
+ debugLog(chalk.cyan.bgWhite(" ConditionType.conditionRefresh2 !"));
889
+ }
890
+ // xx var subscriptionId = inputArguments[0].value;
891
+ // xx var monitoredItemId = inputArguments[1].value;
892
+ const statusCode = _perform_condition_refresh(addressSpace, inputArguments, context);
893
+ return callback(null, {
894
+ statusCode
895
+ });
896
+ }
897
+ function _add_comment_method(inputArguments, context, callback) {
898
+ //
899
+ // The AddComment Method is used to apply a comment to a specific state of a Condition
900
+ // instance. Normally, the NodeId of the object instance as the ObjectId is passed to the Call
901
+ // Service. However, some Servers do not expose Condition instances in the AddressSpace.
902
+ // Therefore all Servers shall also allow Clients to call the AddComment Method by specifying
903
+ // ConditionId as the ObjectId. The Method cannot be called with an ObjectId of the
904
+ // ConditionType Node.
905
+ // Signature
906
+ // - EventId EventId identifying a particular Event Notification where a state was reported for a
907
+ // Condition.
908
+ // - Comment A localized text to be applied to the Condition.
909
+ //
910
+ // AlwaysGeneratesEvent AuditConditionCommentEventType
911
+ //
912
+ UAConditionImpl.with_condition_method(inputArguments, context, callback, (conditionEventId, comment, branch, conditionNode) => {
913
+ (0, node_opcua_assert_1.assert)(inputArguments instanceof Array);
914
+ (0, node_opcua_assert_1.assert)(conditionEventId instanceof Buffer || conditionEventId === null);
915
+ (0, node_opcua_assert_1.assert)(branch instanceof condition_snapshot_1.ConditionSnapshot);
916
+ branch.setComment(comment);
917
+ const sourceName = "Method/AddComment";
918
+ conditionNode._raiseAuditConditionCommentEvent(sourceName, conditionEventId, comment);
919
+ // raise new event
920
+ conditionNode.raiseConditionEvent(branch, true);
921
+ /**
922
+ * raised when the branch has been added a comment
923
+ * @event addComment
924
+ * @param conditionEventId NodeId|null
925
+ * @param comment {LocalizedText}
926
+ * @param branch {ConditionSnapshot}
927
+ */
928
+ conditionNode.emit("addComment", conditionEventId, comment, branch);
929
+ return node_opcua_status_code_1.StatusCodes.Good;
930
+ });
931
+ }
932
+ function sameBuffer(b1, b2) {
933
+ if (!b1 && !b2) {
934
+ return true;
935
+ }
936
+ if (b1 && !b2) {
937
+ return false;
938
+ }
939
+ if (!b1 && b2) {
940
+ return false;
941
+ }
942
+ (0, node_opcua_assert_1.assert)(b1 instanceof Buffer);
943
+ (0, node_opcua_assert_1.assert)(b2 instanceof Buffer);
944
+ if (b1.length !== b2.length) {
945
+ return false;
946
+ }
947
+ /*
948
+ var bb1 = (Buffer.from(b1)).toString("hex");
949
+ var bb2 = (Buffer.from(b2)).toString("hex");
950
+ return bb1 === bb2;
951
+ */
952
+ const n = b1.length;
953
+ for (let i = 0; i < n; i++) {
954
+ if (b1[i] !== b2[i]) {
955
+ return false;
956
+ }
957
+ }
958
+ return true;
959
+ }
960
+ function _create_new_branch_id() {
961
+ return (0, node_opcua_nodeid_1.makeNodeId)((0, node_opcua_basic_types_1.randomGuid)(), 1);
962
+ }
963
+ function _update_sourceTimestamp(dataValue /*, indexRange*/) {
964
+ this.sourceTimestamp.setValueFromSource({
965
+ dataType: node_opcua_variant_1.DataType.DateTime,
966
+ value: dataValue.sourceTimestamp
967
+ });
968
+ }
969
+ // tslint:disable:no-console
970
+ function _install_condition_variable_type(node) {
971
+ // from spec 1.03 : 5.3 condition variables
972
+ // However, a change in their value is considered important and supposed to trigger
973
+ // an Event Notification. These information elements are called ConditionVariables.
974
+ if (node.sourceTimestamp) {
975
+ node.sourceTimestamp.accessLevel = (0, node_opcua_data_model_1.makeAccessLevelFlag)("CurrentRead");
976
+ }
977
+ else {
978
+ console.warn("cannot find node.sourceTimestamp", node.browseName.toString());
979
+ }
980
+ node.accessLevel = (0, node_opcua_data_model_1.makeAccessLevelFlag)("CurrentRead");
981
+ // from spec 1.03 : 5.3 condition variables
982
+ // a condition VariableType has a sourceTimeStamp exposed property
983
+ // SourceTimestamp indicates the time of the last change of the Value of this ConditionVariable.
984
+ // It shall be the same time that would be returned from the Read Service inside the DataValue
985
+ // structure for the ConditionVariable Value Attribute.
986
+ (0, node_opcua_assert_1.assert)(node.typeDefinitionObj.browseName.toString() === "ConditionVariableType");
987
+ (0, node_opcua_assert_1.assert)(node.sourceTimestamp.browseName.toString() === "SourceTimestamp");
988
+ node.on("value_changed", _update_sourceTimestamp);
989
+ }
990
+ /**
991
+ * @method _getCompositeKey
992
+ * @param node {BaseNode}
993
+ * @param key {String}
994
+ * @return {BaseNode}
995
+ * @private
996
+ *
997
+ * @example
998
+ *
999
+ * var node = _getComposite(node,"enabledState.id");
1000
+ *
1001
+ */
1002
+ function _getCompositeKey(node, key) {
1003
+ let cur = node;
1004
+ const elements = key.split(".");
1005
+ for (const e of elements) {
1006
+ // istanbul ignore next
1007
+ if (!Object.prototype.hasOwnProperty.call(cur, e)) {
1008
+ throw new Error(" cannot extract '" + key + "' from " + node.browseName.toString());
1009
+ }
1010
+ cur = cur[e];
1011
+ }
1012
+ return cur;
1013
+ }
1014
+ /**
1015
+ * verify that the subscription id belongs to the session that make the call.
1016
+ * @method _check_subscription_id_is_valid
1017
+ * @param subscriptionId {Number}
1018
+ * @param context {Object}
1019
+ * @private
1020
+ */
1021
+ function _check_subscription_id_is_valid(subscriptionId, context) {
1022
+ /// todo: return StatusCodes.BadSubscriptionIdInvalid; if subscriptionId doesn't belong to session...
1023
+ return node_opcua_status_code_1.StatusCodes.Good;
1024
+ }
1023
1025
  //# sourceMappingURL=ua_condition_impl.js.map