cpee-handlerwrapper-opcua 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9486fd693ad758f8606465a4e1ab91b76630c8c86058b429c0c163b694ef4f0
4
+ data.tar.gz: d5dddcb07d26ed7e3f119f7aae9b9ead68b9f89d367e37d69f66d54f86599be4
5
+ SHA512:
6
+ metadata.gz: bc9a13724855dd7043bfbe5f2c929f89b043a676e8a3745f385dee8384f2340ebc77621131fdcd963ebe54501aeaefb4eb82945026ff9901ac466480c7dd991a
7
+ data.tar.gz: 761142229b1e07199d1eaa40f4cbe50d741523847a3be334fdcc5c5c3bbad51f94488769d42cc2c36933575747c274ed30a12b8d090ccf5fde6a1d4c82bbe42d
data/COPYING ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,20 @@
1
+ # CPEE-HandlerWrapper-OPCUA
2
+
3
+ Copyright (C) 2004-2019 Jürgen "eTM" Mangler <juergen.mangler@gmail.com>
4
+
5
+ CPEE-HandlerWrapper-OPCUA is freely distributable according to the terms of
6
+ the GNU Lesser General Public License 3.0 (see the file 'COPYING').
7
+
8
+ This code is distributed without any warranty. See the file 'COPYING' for
9
+ details.
10
+
11
+ # Usage
12
+
13
+ Go to a handlerwrapper directory and execute
14
+
15
+ ```bash
16
+ cpee-handlerwrapper-opcua >> opcua.rb
17
+ ```
18
+
19
+ This creates a OPCUAHandlerWrapper in this directory. Rename it to default if
20
+ necessary.
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rubygems/package_task'
3
+ require 'fileutils'
4
+
5
+ spec = eval(File.read('cpee-handlerwrapper-opcua.gemspec'))
6
+ Gem::PackageTask.new(spec) do |pkg|
7
+ pkg.need_zip = true
8
+ pkg.need_tar = true
9
+ FileUtils.mkdir 'pkg' rescue nil
10
+ FileUtils.rm_rf Dir.glob('pkg/*')
11
+ FileUtils.ln_sf "#{pkg.name}.gem", "pkg/#{spec.name}.gem"
12
+ end
13
+
14
+ task :default => :gem
15
+
16
+ task :push => :gem do |r|
17
+ `gem push pkg/#{spec.name}.gem`
18
+ end
19
+
20
+ task :install => :gem do |r|
21
+ `gem install pkg/#{spec.name}.gem`
22
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cpee-handlerwrapper-opcua"
3
+ s.version = "0.1"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.license = "LGPL-3.0"
6
+ s.summary = "OPCUA for CPEE HandlerWrapper. Use opc.tcp-read|write|exececute:// links."
7
+
8
+ s.description = "see https://github.com/etm/opcua-smart"
9
+
10
+ s.files = Dir['{example/**/*,tools/**/*,lib/**/*.rb}'] + %w(COPYING Rakefile cpee-handlerwrapper-opcua.gemspec README.md)
11
+ s.require_path = 'lib'
12
+ s.extra_rdoc_files = ['README.md']
13
+ s.bindir = 'tools'
14
+
15
+ s.required_ruby_version = '>=2.5.0'
16
+
17
+ s.authors = ['Juergen eTM Mangler']
18
+ s.email = 'juergen.mangler@gmail.com'
19
+ s.homepage = 'https://cpee.org//cpee-handlerwrapper-opcua'
20
+
21
+ s.add_runtime_dependency 'cpee', '~>1.5', '>= 1.5.0'
22
+ s.add_runtime_dependency 'opcua', '~>0', '>= 0.13'
23
+ s.add_development_dependency 'rake', '~> 12'
24
+ s.add_development_dependency 'rake-compiler', '~> 1.0'
25
+ end
@@ -0,0 +1,324 @@
1
+ # This file is part of CPEE-HandlerWrapper-OPCUA.
2
+ #
3
+ # CPEE is free software: you can redistribute it and/or modify it under the terms
4
+ # of the GNU General Public License as published by the Free Software Foundation,
5
+ # either version 3 of the License, or (at your option) any later version.
6
+ #
7
+ # CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
8
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9
+ # PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
+ #
11
+ # You should have received a copy of the GNU General Public License along with
12
+ # CPEE (file COPYING in the main directory). If not, see
13
+ # <http://www.gnu.org/licenses/>.
14
+
15
+ require 'opcua/client'
16
+
17
+ class OPCUAHandlerWrapper < WEEL::HandlerWrapperBase
18
+ def self::inform_state_change(arguments,newstate) # {{{
19
+ controller = arguments[0]
20
+ controller.serialize_state!
21
+ controller.notify("state/change", :instance => controller.instance, :instance_uuid => controller.uuid, :state => newstate, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
22
+ controller.finalize_if_finished
23
+ end # }}}
24
+ def self::inform_syntax_error(arguments,err,code)# {{{
25
+ controller = arguments[0]
26
+ controller.notify("description/error", :instance => controller.instance, :instance_uuid => controller.uuid, :message => err.message, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
27
+ end# }}}
28
+ def self::inform_handlerwrapper_error(arguments,err) # {{{
29
+ controller = arguments[0]
30
+ controller.notify("handlerwrapper/error", :instance => controller.instance, :instance_uuid => controller.uuid, :message => err.message, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
31
+ end # }}}
32
+ def self::inform_position_change(arguments,ipc={}) # {{{
33
+ controller = arguments[0]
34
+ controller.serialize_positions!
35
+ ipc[:instance] = controller.instance
36
+ ipc[:instance_uuid] = controller.uuid
37
+ ipc[:timestamp] = Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z")
38
+ controller.notify("position/change", ipc)
39
+ end # }}}
40
+
41
+ def initialize(arguments,position=nil,continue=nil) # {{{
42
+ @controller = arguments[0]
43
+ @handler_continue = continue
44
+ @handler_position = position
45
+ @handler_passthrough = nil
46
+ @handler_returnValue = nil
47
+ @label = ''
48
+ end # }}}
49
+
50
+ def prepare(readonly, endpoints, parameters)
51
+ @handler_endpoint = endpoints.is_a?(Array) ? endpoints.map{ |ep| readonly.endpoints[ep] }.compact : readonly.endpoints[endpoints]
52
+ parameters[:arguments].each do |ele|
53
+ if ele.value.is_a?(Proc)
54
+ ele.value = readonly.instance_exec &ele.value
55
+ end
56
+ end
57
+ parameters
58
+ end
59
+
60
+ def activity_handle(passthrough, parameters) # {{{
61
+ raise "Wrong endpoint" if @handler_endpoint.nil? || @handler_endpoint.empty?
62
+ @label = parameters[:label]
63
+ @sensors = parameters[:sensors]
64
+ @aggregators = parameters[:aggregators]
65
+ @costs = parameters[:costs]
66
+ @controller.notify("activity/calling", :instance => @controller.instance, :instance_uuid => @controller.uuid, :label => @label, :instance_name => @controller.info, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
67
+ if passthrough.to_s.empty?
68
+ if @handler_endpoint.start_with?('opc.tcp')
69
+ if @handler_endpoint =~ /^opc\.tcp-read:\/\/([^\/]+)\/(\d+)\/(.+)/
70
+ nid = $3 == $3.to_i.to_s ? $3.to_i : $3
71
+ ns = $2
72
+ url = 'opc.tcp://' + $1
73
+ client = OPCUA::Client.new(url)
74
+ if (node = client.get ns.to_i, nid)
75
+ result = node.value
76
+ else
77
+ raise 'invalid nodeid'
78
+ end
79
+ client.disconnect
80
+ callback [Riddl::Parameter::Simple.new('value',result)], {}
81
+ elsif @handler_endpoint =~ /^opc\.tcp-write:\/\/([^\/]+)\/(\d+)\/([^\?]+)(\?value=(.*))?/
82
+ nid = $3 == $3.to_i.to_s ? $3.to_i : $3
83
+ ns = $2
84
+ par = $5
85
+ url = 'opc.tcp://' + $1
86
+ client = OPCUA::Client.new(url)
87
+ if (node = client.get ns.to_i, nid)
88
+ (parameters[:arguments] || [→(:name => 'value', :value => par)] || []).each do |ele|
89
+ what = CPEE::ValueHelper::parse_extended(ele.value)
90
+ node.value = what
91
+ result = what
92
+ end
93
+ else
94
+ raise 'invalid nodeid'
95
+ end
96
+ client.disconnect
97
+ callback [Riddl::Parameter::Simple.new('value',result)], {}
98
+ elsif @handler_endpoint =~ /^opc\.tcp-execute:\/\/([^\/]+)\/(\d+)\/([^\?]+)(\?value=(.*))?/
99
+ nid = $3 == $3.to_i.to_s ? $3.to_i : $3
100
+ ns = $2
101
+ par = $5
102
+ url = 'opc.tcp://' + $1
103
+ client = OPCUA::Client.new(url)
104
+ if (node = client.get ns.to_i, nid)
105
+ params = []
106
+ (parameters[:arguments] || []).each do |ele|
107
+ what = CPEE::ValueHelper::parse_extended(ele.value)
108
+ params << what
109
+ end
110
+ result = node.call *params
111
+ else
112
+ raise 'invalid nodeid'
113
+ end
114
+ client.disconnect
115
+ callback [Riddl::Parameter::Simple.new('value',result)], {}
116
+ end
117
+ else
118
+ params = []
119
+ callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
120
+ (parameters[:arguments] || []).each do |s|
121
+ if s.respond_to?(:mimetype)
122
+ params << Riddl::Parameter::Complex.new(s.name.to_s,v.mimetype,v.value)
123
+ else
124
+ if s.name.to_s =~ /__$/
125
+ params << Riddl::Parameter::Simple.new(s.name.to_s.chop.chop,CPEE::ValueHelper::generate(s.value),:query)
126
+ else
127
+ params << Riddl::Parameter::Simple.new(s.name.to_s,CPEE::ValueHelper::generate(s.value))
128
+ end
129
+ end
130
+ end
131
+
132
+ params << Riddl::Header.new("CPEE-BASE",@controller.base_url)
133
+ params << Riddl::Header.new("CPEE-INSTANCE",@controller.instance)
134
+ params << Riddl::Header.new("CPEE-INSTANCE-URL",@controller.instance_url)
135
+ params << Riddl::Header.new("CPEE-INSTANCE-UUID",@controller.uuid)
136
+ params << Riddl::Header.new("CPEE-CALLBACK",@controller.instance_url + '/callbacks/' + callback)
137
+ params << Riddl::Header.new("CPEE-CALLBACK-ID",callback)
138
+ params << Riddl::Header.new("CPEE-ACTIVITY",@handler_position)
139
+ params << Riddl::Header.new("CPEE-LABEL",parameters[:label]||'')
140
+ @controller.attributes.each do |key,value|
141
+ params << Riddl::Header.new("CPEE-ATTR-#{key.to_s.gsub(/_/,'-')}",value)
142
+ end
143
+
144
+ tendpoint = @handler_endpoint.sub(/^http(s)?-(get|put|post|delete):/,'http\\1:')
145
+ type = $2 || parameters[:method] || 'post'
146
+
147
+ client = Riddl::Client.new(tendpoint)
148
+
149
+ @controller.callbacks[callback] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
150
+ @handler_passthrough = callback
151
+
152
+ status, result, headers = client.request type => params
153
+ if status < 200 || status >= 300
154
+ callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => status, 'error' => result[0].value.read }))) ], 'CPEE_SALVAGE' => true)
155
+ else
156
+ if headers['CPEE_INSTANTIATION']
157
+ @controller.notify("task/instantiation", :instance => @controller.instance, :label => @label, :instance_name => @controller.info, :instance_uuid => @controller.uuid, :activity => @handler_position, :endpoint => @handler_endpoint, :received => CPEE::ValueHelper.parse(headers['CPEE_INSTANTIATION']), :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
158
+ end
159
+ if headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.any?
160
+ headers['CPEE_UPDATE'] = true
161
+ callback result, headers
162
+ elsif headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.empty?
163
+ # do nothing, later on things will happend
164
+ else
165
+ callback result
166
+ end
167
+ end
168
+ end
169
+ else
170
+ @controller.callbacks[passthrough] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
171
+ @handler_passthrough = passthrough
172
+ end
173
+ end # }}}
174
+ def activity_manipulate_handle(parameters) #{{{
175
+ @label = parameters[:label]
176
+ end #}}}
177
+
178
+ def activity_result_value # {{{
179
+ @handler_returnValue
180
+ end # }}}
181
+
182
+ def activity_stop # {{{
183
+ unless @handler_passthrough.nil?
184
+ @controller.callbacks.delete(@handler_passthrough)
185
+ end
186
+ end # }}}
187
+ def activity_passthrough_value # {{{
188
+ @handler_passthrough
189
+ end # }}}
190
+
191
+ def activity_no_longer_necessary # {{{
192
+ true
193
+ end # }}}
194
+
195
+ def inform_activity_done # {{{
196
+ @controller.notify("activity/done", :endpoint => @handler_endpoint, :instance => @controller.instance, :label => @label, :instance_name => @controller.info, :instance_uuid => @controller.uuid, :activity => @handler_position, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
197
+ end # }}}
198
+ def inform_activity_manipulate # {{{
199
+ @controller.notify("activity/manipulating", :endpoint => @handler_endpoint, :instance => @controller.instance, :label => @label, :instance_name => @controller.info, :instance_uuid => @controller.uuid, :activity => @handler_position, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
200
+ end # }}}
201
+ def inform_activity_failed(err) # {{{
202
+ puts err.message
203
+ puts err.backtrace
204
+ @controller.notify("activity/failed", :endpoint => @handler_endpoint, :label => @label, :instance_name => @controller.info, :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :message => err.message, :line => err.backtrace[0].match(/(.*?):(\d+):/)[2], :where => err.backtrace[0].match(/(.*?):(\d+):/)[1], :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
205
+ end # }}}
206
+ def inform_manipulate_change(status,changed_dataelements,changed_endpoints,dataelements,endpoints) # {{{
207
+ unless status.nil?
208
+ @controller.serialize_status!
209
+ @controller.notify("status/change", :endpoint => @handler_endpoint, :label => @label, :instance_name => @controller.info, :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :id => status.id, :message => status.message, :attributes => @controller.attributes_translated, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
210
+ end
211
+ unless changed_dataelements.nil?
212
+ @controller.serialize_dataelements!
213
+ @controller.notify("dataelements/change", :endpoint => @handler_endpoint, :label => @label, :instance_name => @controller.info, :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :changed => changed_dataelements, :values => dataelements, :attributes => @controller.attributes_translated, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
214
+ end
215
+ unless changed_endpoints.nil?
216
+ @controller.serialize_endpoints!
217
+ @controller.notify("endpoints/change", :endpoint => @handler_endpoint, :label => @label, :instance_name => @controller.info, :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :changed => changed_endpoints, :values => endpoints, :attributes => @controller.attributes_translated, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
218
+ end
219
+ end # }}}
220
+
221
+ def vote_sync_after # {{{
222
+ @controller.call_vote("activity/syncing_after", :endpoint => @handler_endpoint, :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
223
+ end # }}}
224
+ def vote_sync_before(parameters=nil) # {{{
225
+ @controller.call_vote("activity/syncing_before", :endpoint => @handler_endpoint, :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :parameters => parameters, :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
226
+ end # }}}
227
+
228
+ def simplify_result(result)
229
+ if result.length == 1
230
+ if result[0].is_a? Riddl::Parameter::Simple
231
+ result = result[0].value
232
+ elsif result[0].is_a? Riddl::Parameter::Complex
233
+ if result[0].mimetype == 'application/json'
234
+ result = JSON::parse(result[0].value.read) rescue nil
235
+ elsif result[0].mimetype == 'application/xml' || result[0].mimetype == 'text/xml'
236
+ result = XML::Smart::string(result[0].value.read) rescue nil
237
+ elsif result[0].mimetype == 'text/plain'
238
+ result = result[0].value.read
239
+ if result.start_with?("<?xml version=")
240
+ result = XML::Smart::string(result)
241
+ else
242
+ result = result.to_f if result == result.to_f.to_s
243
+ result = result.to_i if result == result.to_i.to_s
244
+ end
245
+ elsif result[0].mimetype == 'text/html'
246
+ result = result[0].value.read
247
+ result = result.to_f if result == result.to_f.to_s
248
+ result = result.to_i if result == result.to_i.to_s
249
+ else
250
+ result = result[0]
251
+ end
252
+ end
253
+ end
254
+ result
255
+ end
256
+
257
+ def structurize_result(result)
258
+ result.map do |r|
259
+ if r.is_a? Riddl::Parameter::Simple
260
+ { 'name' => r.name, 'data' => r.value }
261
+ elsif r.is_a? Riddl::Parameter::Complex
262
+ res = if r.mimetype == 'application/json'
263
+ JSON::parse(r.value.read) rescue nil
264
+ elsif r.mimetype == 'text/plain' || r.mimetype == 'text/html'
265
+ ttt = r.value.read
266
+ ttt = ttt.to_f if ttt == ttt.to_f.to_s
267
+ ttt = ttt.to_i if ttt == ttt.to_i.to_s
268
+ ttt
269
+ else
270
+ r.value.read
271
+ end
272
+ tmp = {
273
+ 'name' => r.name == '' ? 'result' : r.name,
274
+ 'mimetype' => r.mimetype,
275
+ 'data' => res
276
+ }
277
+ r.value.rewind
278
+ tmp
279
+ end
280
+ end
281
+ end
282
+
283
+ def callback(result=nil,options={})
284
+ @controller.notify("activity/receiving", :instance => @controller.instance, :label => @label, :instance_name => @controller.info, :instance_uuid => @controller.uuid, :activity => @handler_position, :endpoint => @handler_endpoint, :received => structurize_result(result), :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated, :sensors => @sensors, :aggregators => @aggregators, :costs => @costs)
285
+ result = simplify_result(result)
286
+ if options['CPEE_UPDATE']
287
+ @handler_returnValue = result
288
+ if options['CPEE_UPDATE_STATUS']
289
+ @controller.notify("activity/status", :instance => @controller.instance, :instance_uuid => @controller.uuid, :activity => @handler_position, :endpoint => @handler_endpoint, :status => options['CPEE_UPDATE_STATUS'], :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
290
+ end
291
+ @handler_continue.continue WEEL::Signal::Again
292
+ else
293
+ @controller.callbacks.delete(@handler_passthrough)
294
+ @handler_returnValue = result
295
+ @handler_passthrough = nil
296
+ if options['CPEE_SALVAGE']
297
+ @handler_continue.continue WEEL::Signal::Salvage
298
+ else
299
+ @handler_continue.continue
300
+ end
301
+ end
302
+ end
303
+
304
+ def test_condition(mr,code)
305
+ res = mr.instance_eval(code)
306
+ @controller.notify("condition/eval", :instance => @controller.instance, :instance_uuid => @controller.uuid, :code => code, :condition => (res ? "true" : "false"), :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated)
307
+ res
308
+ end
309
+
310
+ def simulate(type,nesting,tid,parent,parameters={}) #{{{
311
+ pp "#{type} - #{nesting} - #{tid} - #{parent} - #{parameters.inspect}"
312
+
313
+ @controller.call_vote("simulating/step",
314
+ :endpoint => @handler_endpoint,
315
+ :instance => @controller.instance,
316
+ :instance_uuid => @controller.uuid,
317
+ :activity => tid,
318
+ :type => type,
319
+ :nesting => nesting,
320
+ :parent => parent,
321
+ :parameters => parameters
322
+ )
323
+ end #}}}
324
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby
2
+ curpath = __dir__
3
+
4
+ puts <<-END
5
+ # encoding: utf-8
6
+ #
7
+ # This file is part of CPEE-HandlerWrapper-OPCUA.
8
+ #
9
+ # CPEE-HandlerWrapper-OPCUA is free software: you can redistribute it and/or
10
+ # modify it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or (at your
12
+ # option) any later version.
13
+ #
14
+ # CPEE-HandlerWrapper-OPCUA is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17
+ # Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License along with
20
+ # CPEE-HandlerWrapper-OPCUA (file COPYING in the main directory). If not, see
21
+ # <http://www.gnu.org/licenses/>.
22
+
23
+ require 'cpee-handlerwrapper-opcua'
24
+ END
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpee-handlerwrapper-opcua
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Juergen eTM Mangler
8
+ autorequire:
9
+ bindir: tools
10
+ cert_chain: []
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cpee
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: opcua
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0.13'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0.13'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '12'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '12'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake-compiler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.0'
81
+ description: see https://github.com/etm/opcua-smart
82
+ email: juergen.mangler@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - README.md
87
+ files:
88
+ - COPYING
89
+ - README.md
90
+ - Rakefile
91
+ - cpee-handlerwrapper-opcua.gemspec
92
+ - lib/cpee-handlerwrapper-opcua.rb
93
+ - tools/cpee-handlerwrapper-opcua
94
+ homepage: https://cpee.org//cpee-handlerwrapper-opcua
95
+ licenses:
96
+ - LGPL-3.0
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.5.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: OPCUA for CPEE HandlerWrapper. Use opc.tcp-read|write|exececute:// links.
117
+ test_files: []