cpee-handlerwrapper-opcua 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75f8d367a1dc766fb0d718129b3df522b488c23c0851b223cd82361fb09bceab
4
- data.tar.gz: 127104e0d36ad736b127c06c3cc415496db6b1f07744ac758dfe4ed60f486c05
3
+ metadata.gz: f37682803c030cfe276827a2c1eb378f50dfc6ab7e755dc12a456e6ce88fa523
4
+ data.tar.gz: b7c508574b45a91100579a649204894fbd0a32b4c3350794b33410ca2749ebcd
5
5
  SHA512:
6
- metadata.gz: a6cfc998614c19c4480ac9cfd41bbec4d3b975038b0eb1d773f19715f781728c4ba36bc068b8061f0a94a3a354c3cc95609ea7bc5c8c25ca3e7847e880de89a5
7
- data.tar.gz: f3524fe41cf3409b909f489d5525c49a583e87d8fe8b16e9caa3c1c2c075391a30f546a8926dabb81572e4c5283c25f60d872ddaa738101216db45dcacd103a7
6
+ metadata.gz: bf62016abb1077af6a8dbc22a0e600b5a6969454b680fd302c5bc1fe2c3292cb201b574a944580f930138b277f74e0a8a0290a288636abe89e9bfd3deb23d352
7
+ data.tar.gz: 5e65951566c8c4e4f742f11ab7b524bc6063c6bdc2e2986affc68a3b95aae2c6e6540f44eefd885d051fb2dc30b695e444385f64e563845564465c1486293d4a
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-handlerwrapper-opcua"
3
- s.version = "0.4"
3
+ s.version = "0.5"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "OPCUA for CPEE HandlerWrapper. Use opc.tcp-read|write|exececute:// links."
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.email = 'juergen.mangler@gmail.com'
19
19
  s.homepage = 'https://cpee.org//cpee-handlerwrapper-opcua'
20
20
 
21
- s.add_runtime_dependency 'cpee', '~>1.5', '>= 1.5.5'
21
+ s.add_runtime_dependency 'cpee', '~>1.5', '>= 1.5.8'
22
22
  s.add_runtime_dependency 'opcua', '~>0', '>= 0.13'
23
23
  s.add_development_dependency 'rake', '~> 12'
24
24
  s.add_development_dependency 'rake-compiler', '~> 1.0'
@@ -48,8 +48,12 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
48
48
  @label = ''
49
49
  end # }}}
50
50
 
51
- def prepare(readonly, endpoints, parameters) #{{{
52
- @handler_endpoint = endpoints.is_a?(Array) ? endpoints.map{ |ep| readonly.endpoints[ep] }.compact : readonly.endpoints[endpoints]
51
+ def prepare(readonly, endpoints, parameters, replay=false) #{{{
52
+ if replay
53
+ @handler_endpoint = @controller.attributes[:replayer]
54
+ else
55
+ @handler_endpoint = endpoints.is_a?(Array) ? endpoints.map{ |ep| readonly.endpoints[ep] }.compact : readonly.endpoints[endpoints]
56
+ end
53
57
  params = parameters.dup
54
58
  params[:arguments] = params[:arguments].dup if params[:arguments]
55
59
  params[:arguments]&.map! do |ele|
@@ -62,123 +66,144 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
62
66
  params
63
67
  end #}}}
64
68
 
65
- def activity_handle(passthrough, parameters) # {{{
66
- raise "Wrong endpoint" if @handler_endpoint.nil? || @handler_endpoint.empty?
67
- @label = parameters[:label]
68
- @sensors = parameters[:sensors]
69
- @aggregators = parameters[:aggregators]
70
- @costs = parameters[:costs]
71
- @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)
72
- if passthrough.to_s.empty?
73
- if @handler_endpoint.start_with?('opc.tcp')
74
- if @handler_endpoint =~ /^opc\.tcp-read:\/\/([^\/]+)\/(\d+)\/(.+)/
75
- nid = $3 == $3.to_i.to_s ? $3.to_i : $3
76
- ns = $2
77
- url = 'opc.tcp://' + $1
78
- client = OPCUA::Client.new(url)
79
- if (node = client.get ns.to_i, nid)
80
- result = node.value
81
- else
82
- raise 'invalid nodeid'
83
- end
84
- client.disconnect
85
- callback [Riddl::Parameter::Simple.new('value',result)], {}
86
- elsif @handler_endpoint =~ /^opc\.tcp-write:\/\/([^\/]+)\/(\d+)\/([^\?]+)(\?value=(.*))?/
87
- nid = $3 == $3.to_i.to_s ? $3.to_i : $3
88
- ns = $2
89
- par = $5
90
- url = 'opc.tcp://' + $1
91
- client = OPCUA::Client.new(url)
92
- if (node = client.get ns.to_i, nid)
93
- (parameters[:arguments] || [→(:name => 'value', :value => par)] || []).each do |ele|
94
- what = CPEE::ValueHelper::parse_extended(ele.value)
95
- node.value = what
96
- result = what
97
- end
98
- else
99
- raise 'invalid nodeid'
100
- end
101
- client.disconnect
102
- callback [Riddl::Parameter::Simple.new('value',result)], {}
103
- elsif @handler_endpoint =~ /^opc\.tcp-execute:\/\/([^\/]+)\/(\d+)\/([^\?]+)(\?value=(.*))?/
104
- nid = $3 == $3.to_i.to_s ? $3.to_i : $3
105
- ns = $2
106
- par = $5
107
- url = 'opc.tcp://' + $1
108
- client = OPCUA::Client.new(url)
109
- if (node = client.get ns.to_i, nid)
110
- params = []
111
- (parameters[:arguments] || []).each do |ele|
112
- what = CPEE::ValueHelper::parse_extended(ele.value)
113
- params << what
114
- end
115
- result = node.call *params
116
- else
117
- raise 'invalid nodeid'
118
- end
119
- client.disconnect
120
- callback [Riddl::Parameter::Simple.new('value',result)], {}
121
- end
69
+ def proto_curl(parameters) #{{{
70
+ params = []
71
+ callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
72
+ (parameters[:arguments] || []).each do |s|
73
+ if s.respond_to?(:mimetype)
74
+ params << Riddl::Parameter::Complex.new(s.name.to_s,v.mimetype,v.value)
122
75
  else
123
- params = []
124
- callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
125
- (parameters[:arguments] || []).each do |s|
126
- if s.respond_to?(:mimetype)
127
- params << Riddl::Parameter::Complex.new(s.name.to_s,v.mimetype,v.value)
128
- else
129
- if s.name.to_s =~ /^__Q_/
130
- params << Riddl::Parameter::Simple.new(s.name.to_s.sub(/^__Q_/,''),CPEE::ValueHelper::generate(s.value),:query)
131
- elsif s.name.to_s =~ /^__B_/
132
- params << Riddl::Parameter::Simple.new(s.name.to_s.sub(/^__B_/,''),CPEE::ValueHelper::generate(s.value),:body)
133
- elsif s.name.to_s =~ /^__H_/
134
- params << Riddl::Header.new(s.name.to_s.sub(/^__H_/,''),CPEE::ValueHelper::generate(s.value))
135
- elsif s.name.to_s =~ /^__C_/
136
- params << Riddl::Parameter::Complex.new(s.name.to_s.sub(/^__C_/,''),*CPEE::ValueHelper::generate(s.value).split(';',2))
137
- else
138
- params << Riddl::Parameter::Simple.new(s.name.to_s,CPEE::ValueHelper::generate(s.value))
139
- end
140
- end
76
+ if s.name.to_s =~ /^__Q_/
77
+ params << Riddl::Parameter::Simple.new(s.name.to_s.sub(/^__Q_/,''),CPEE::ValueHelper::generate(s.value),:query)
78
+ elsif s.name.to_s =~ /^__B_/
79
+ params << Riddl::Parameter::Simple.new(s.name.to_s.sub(/^__B_/,''),CPEE::ValueHelper::generate(s.value),:body)
80
+ elsif s.name.to_s =~ /^__H_/
81
+ params << Riddl::Header.new(s.name.to_s.sub(/^__H_/,''),CPEE::ValueHelper::generate(s.value))
82
+ elsif s.name.to_s =~ /^__C_/
83
+ params << Riddl::Parameter::Complex.new(s.name.to_s.sub(/^__C_/,''),*CPEE::ValueHelper::generate(s.value).split(';',2))
84
+ else
85
+ params << Riddl::Parameter::Simple.new(s.name.to_s,CPEE::ValueHelper::generate(s.value))
141
86
  end
87
+ end
88
+ end
142
89
 
143
- params << Riddl::Header.new("CPEE-BASE",@controller.base_url)
144
- params << Riddl::Header.new("CPEE-INSTANCE",@controller.instance)
145
- params << Riddl::Header.new("CPEE-INSTANCE-URL",@controller.instance_url)
146
- params << Riddl::Header.new("CPEE-INSTANCE-UUID",@controller.uuid)
147
- params << Riddl::Header.new("CPEE-CALLBACK",@controller.instance_url + '/callbacks/' + callback)
148
- params << Riddl::Header.new("CPEE-CALLBACK-ID",callback)
149
- params << Riddl::Header.new("CPEE-ACTIVITY",@handler_position)
150
- params << Riddl::Header.new("CPEE-LABEL",parameters[:label]||'')
151
- @controller.attributes.each do |key,value|
152
- params << Riddl::Header.new("CPEE-ATTR-#{key.to_s.gsub(/_/,'-')}",value)
153
- end
90
+ params << Riddl::Header.new("CPEE-BASE",@controller.base_url)
91
+ params << Riddl::Header.new("CPEE-INSTANCE",@controller.instance)
92
+ params << Riddl::Header.new("CPEE-INSTANCE-URL",@controller.instance_url)
93
+ params << Riddl::Header.new("CPEE-INSTANCE-UUID",@controller.uuid)
94
+ params << Riddl::Header.new("CPEE-CALLBACK",@controller.instance_url + '/callbacks/' + callback)
95
+ params << Riddl::Header.new("CPEE-CALLBACK-ID",callback)
96
+ params << Riddl::Header.new("CPEE-ACTIVITY",@handler_position)
97
+ params << Riddl::Header.new("CPEE-LABEL",@label||'')
98
+ params << Riddl::Header.new("CPEE-REPLAY",@controller.attributes['replayer_args'])
99
+ @controller.attributes.each do |key,value|
100
+ params << Riddl::Header.new("CPEE-ATTR-#{key.to_s.gsub(/_/,'-')}",value)
101
+ end
154
102
 
155
- tendpoint = @handler_endpoint.sub(/^http(s)?-(get|put|post|delete):/,'http\\1:')
156
- type = $2 || parameters[:method] || 'post'
103
+ tendpoint = @handler_endpoint.sub(/^http(s)?-(get|put|post|delete):/,'http\\1:')
104
+ type = $2 || parameters[:method] || 'post'
157
105
 
158
- client = Riddl::Client.new(tendpoint)
106
+ client = Riddl::Client.new(tendpoint)
159
107
 
160
- @controller.callbacks[callback] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
161
- @handler_passthrough = callback
108
+ @controller.callbacks[callback] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
109
+ @handler_passthrough = callback
162
110
 
163
- status, result, headers = client.request type => params
164
- if status < 200 || status >= 300
165
- headers['CPEE_SALVAGE'] = true
166
- c = result[0]&.value
167
- c = c.read if c.respond_to? :read
168
- callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => status, 'error' => c }))) ], headers)
111
+ status, result, headers = client.request type => params
112
+ if status < 200 || status >= 300
113
+ headers['CPEE_SALVAGE'] = true
114
+ c = result[0]&.value
115
+ c = c.read if c.respond_to? :read
116
+ callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => status, 'error' => c }))) ], headers)
117
+ else
118
+ if headers['CPEE_INSTANTIATION']
119
+ @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)
120
+ end
121
+ if headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.any?
122
+ headers['CPEE_UPDATE'] = true
123
+ callback result, headers
124
+ elsif headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.empty?
125
+ # do nothing, later on things will happend
126
+ else
127
+ callback result, headers
128
+ end
129
+ end
130
+ end #}}}
131
+
132
+ def proto_opcua
133
+ if @handler_endpoint =~ /^opc\.tcp-read:\/\/([^\/]+)\/(\d+)\/(.+)/
134
+ nid = $3 == $3.to_i.to_s ? $3.to_i : $3
135
+ ns = $2
136
+ url = 'opc.tcp://' + $1
137
+ begin
138
+ client = OPCUA::Client.new(url)
139
+ if (node = client.get ns.to_i, nid)
140
+ result = node.value
169
141
  else
170
- if headers['CPEE_INSTANTIATION']
171
- @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)
142
+ raise 'invalid nodeid'
143
+ end
144
+ client.disconnect
145
+ callback [Riddl::Parameter::Simple.new('value',result)], {}
146
+ rescue => e
147
+ callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => 0, 'error' => e.message }))) ], 'CPEE_SALVAGE' => true)
148
+ end
149
+ elsif @handler_endpoint =~ /^opc\.tcp-write:\/\/([^\/]+)\/(\d+)\/([^\?]+)(\?value=(.*))?/
150
+ nid = $3 == $3.to_i.to_s ? $3.to_i : $3
151
+ ns = $2
152
+ par = $5
153
+ url = 'opc.tcp://' + $1
154
+ begin
155
+ client = OPCUA::Client.new(url)
156
+ if (node = client.get ns.to_i, nid)
157
+ (parameters[:arguments] || [→(:name => 'value', :value => par)] || []).each do |ele|
158
+ what = CPEE::ValueHelper::parse_extended(ele.value)
159
+ node.value = what
160
+ result = what
172
161
  end
173
- if headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.any?
174
- headers['CPEE_UPDATE'] = true
175
- callback result, headers
176
- elsif headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.empty?
177
- # do nothing, later on things will happend
178
- else
179
- callback result, headers
162
+ else
163
+ raise 'invalid nodeid'
164
+ end
165
+ client.disconnect
166
+ callback [Riddl::Parameter::Simple.new('value',result)], {}
167
+ rescue => e
168
+ callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => 0, 'error' => e.message }))) ], 'CPEE_SALVAGE' => true)
169
+ end
170
+ elsif @handler_endpoint =~ /^opc\.tcp-execute:\/\/([^\/]+)\/(\d+)\/([^\?]+)(\?value=(.*))?/
171
+ nid = $3 == $3.to_i.to_s ? $3.to_i : $3
172
+ ns = $2
173
+ par = $5
174
+ url = 'opc.tcp://' + $1
175
+ begin
176
+ client = OPCUA::Client.new(url)
177
+ if (node = client.get ns.to_i, nid)
178
+ params = []
179
+ (parameters[:arguments] || []).each do |ele|
180
+ what = CPEE::ValueHelper::parse_extended(ele.value)
181
+ params << what
180
182
  end
183
+ result = node.call *params
184
+ else
185
+ raise 'invalid nodeid'
181
186
  end
187
+ client.disconnect
188
+ callback [Riddl::Parameter::Simple.new('value',result)], {}
189
+ rescue => e
190
+ callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => 0, 'error' => e.message }))) ], 'CPEE_SALVAGE' => true)
191
+ end
192
+ end
193
+ end
194
+
195
+ def activity_handle(passthrough, parameters) # {{{
196
+ raise "Wrong endpoint" if @handler_endpoint.nil? || @handler_endpoint.empty?
197
+ @label = parameters[:label]
198
+ @sensors = parameters[:sensors]
199
+ @aggregators = parameters[:aggregators]
200
+ @costs = parameters[:costs]
201
+ @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)
202
+ if passthrough.to_s.empty?
203
+ if @handler_endpoint.start_with?('opc.tcp')
204
+ proto_opcua parameters
205
+ else
206
+ proto_curl parameters
182
207
  end
183
208
  else
184
209
  @controller.callbacks[passthrough] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-handlerwrapper-opcua
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: tools
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cpee
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.5'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.5.5
22
+ version: 1.5.8
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.5'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.5.5
32
+ version: 1.5.8
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: opcua
35
35
  requirement: !ruby/object:Gem::Requirement