ladder_drive 0.6.3 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +7 -2
  3. data/Gemfile.lock +107 -62
  4. data/README.md +1 -0
  5. data/README_jp.md +2 -2
  6. data/ladder_drive.gemspec +12 -8
  7. data/lib/ladder_drive/cli.rb +16 -4
  8. data/lib/ladder_drive/config.rb +4 -1
  9. data/lib/ladder_drive/config_target.rb +1 -0
  10. data/lib/ladder_drive/plc_device.rb +11 -0
  11. data/lib/ladder_drive/protocol/keyence/kv_protocol.rb +1 -11
  12. data/lib/ladder_drive/protocol/mitsubishi/fx_protocol.rb +0 -11
  13. data/lib/ladder_drive/protocol/mitsubishi/mc_protocol.rb +1 -11
  14. data/lib/ladder_drive/protocol/omron/c_mode_protocol.rb +224 -0
  15. data/lib/ladder_drive/protocol/omron/fins_tcp_protocol.rb +380 -0
  16. data/lib/ladder_drive/protocol/omron/omron.rb +28 -0
  17. data/lib/ladder_drive/protocol/omron/omron_device.rb +139 -0
  18. data/lib/ladder_drive/protocol/protocol.rb +16 -5
  19. data/lib/ladder_drive/tasks/build.rb +1 -1
  20. data/lib/ladder_drive/version.rb +1 -1
  21. data/lib/ladder_drive.rb +3 -0
  22. data/lib/plc/emulator/emu_plc_server.rb +3 -1
  23. data/lib/plc/emulator/plc_plugins.rb +20 -13
  24. data/lib/plc/emulator/plugin_trigger_state.rb +152 -0
  25. data/plugins/ambient_plugin.rb +155 -0
  26. data/plugins/config/ambient.yaml.example +34 -0
  27. data/plugins/config/google_drive.yaml.example +39 -0
  28. data/plugins/config/ifttt.yaml.example +24 -0
  29. data/plugins/config/plc_mapper.yaml.example +36 -0
  30. data/plugins/config/slack.yaml.example +36 -0
  31. data/plugins/config/trello.yaml.example +41 -0
  32. data/plugins/ifttt_plugin.rb +4 -27
  33. data/plugins/plc_mapper_plugin.rb +27 -15
  34. data/plugins/slack_plugin.rb +14 -3
  35. data/plugins/trello_plugin.rb +30 -42
  36. metadata +72 -15
@@ -90,6 +90,7 @@ class SlackPlugin < Plugin
90
90
  v = nil
91
91
  case event[:trigger][:type]
92
92
  when "interval"
93
+
93
94
  t = @times[event.object_id] || now
94
95
  triggered = t <= now
95
96
  if triggered
@@ -97,9 +98,9 @@ class SlackPlugin < Plugin
97
98
  t += event[:trigger][:interval] || 300
98
99
  @times[event.object_id] = t
99
100
  end
100
- v = device.send event[:value_type], event[:trigger][:text_length] || 8
101
+ v = device.send event[:value_type] || :value, event[:trigger][:text_length] || 8
101
102
  else
102
- v = device.send event[:value_type], event[:text_length] || 8
103
+ v = device.send event[:value_type] || :value, event[:text_length] || 8
103
104
  unless @values[device.name] == v
104
105
  @values[device.name] = v
105
106
  case event[:trigger][:type]
@@ -122,6 +123,8 @@ class SlackPlugin < Plugin
122
123
  end
123
124
  rescue => e
124
125
  p e
126
+ puts $!
127
+ puts $@
125
128
  end
126
129
  end
127
130
  end
@@ -147,7 +150,15 @@ class SlackPlugin < Plugin
147
150
  req["Content-Type"] = "application/json"
148
151
 
149
152
  format = event[:format] || "__comment__ occured at __time__"
150
- format = arg[:value] ? format[:raise] : format[:fall] unless format.is_a? String
153
+ case format
154
+ when Hash
155
+ case arg[:value]
156
+ when false, nil, 0
157
+ format = format[:fall]
158
+ else
159
+ format = format[:interval] || format[:raise]
160
+ end
161
+ end
151
162
 
152
163
  device_name = arg[:device_name]
153
164
  comment = @comments[device_name] || device_name
@@ -80,42 +80,16 @@ class TrelloPlugin < Plugin
80
80
 
81
81
  @config[:events].each do |event|
82
82
  begin
83
+ next unless self.triggered?(event)
83
84
 
84
- triggered = false
85
- now = Time.now
86
- device = nil
87
-
88
- case event[:trigger][:type]
89
- when "interval"
90
- t = @times[event.object_id] || now
91
- triggered = t <= now
92
- if triggered
93
- triggered = true
94
- t += event[:trigger][:interval] || 300
95
- @times[event.object_id] = t
96
- end
97
- else
98
- device = plc.device_by_name event[:trigger][:device]
99
- v = device.send event[:trigger][:value_type], event[:trigger][:text_length] || 8
100
- unless @values[device.name] == v
101
- @values[device.name] = v
102
- case event[:trigger][:type]
103
- when "raise"
104
- triggered = !!v
105
- when "fall"
106
- triggered = !v
107
- else
108
- triggered = true
109
- end
110
- end
111
- end
112
-
113
- next unless triggered
114
-
115
- @worker_queue.push event:event, device_name:device.name, value:v, time: now
85
+ device = trigger_state_for(event).device
86
+ v = trigger_state_for(event).value
87
+ @worker_queue.push event:event, device_name:device.name, value:v, time: Time.now
116
88
 
117
89
  rescue => e
118
90
  p e
91
+ puts $!
92
+ puts $@
119
93
  end
120
94
  end
121
95
  end
@@ -128,6 +102,11 @@ class TrelloPlugin < Plugin
128
102
  }
129
103
  end
130
104
 
105
+ def label_in_board_with_color board, color
106
+ l = board.labels.find{|l| l.name == color}
107
+ l ||= Trello::Label.create board_id:board.id, name:color, color:color
108
+ end
109
+
131
110
  def thread_proc
132
111
  while arg = @worker_queue.pop
133
112
  begin
@@ -137,24 +116,33 @@ class TrelloPlugin < Plugin
137
116
  next unless board
138
117
 
139
118
  card_name = event[:card_name].dup || ""
140
- card_name.gsub!(/__value__/, arg[:value] || "")
119
+ card_name.gsub!(/__value__/, arg[:value] || "") if arg[:value].is_a? String
141
120
  next if (card_name || "").empty?
142
121
 
143
- list_name = event[:list_name]
144
- next unless list_name
145
- list = board.lists.find{|l| l.name == list_name}
146
- next unless list
122
+ card = board.cards.find{|c| c.name == card_name}
123
+ card ||= Trello::Card.create name:card_name
124
+
125
+ # move card into a list
126
+ list = board.lists.find{|l| l.name == event[:list_name]} if event[:list_name]
127
+ card.move_to_list list if list
147
128
 
148
- card = board.lists.map{|l| l.cards.map{|c| c}}.flatten.find{|c| c.name == card_name}
149
- if card
150
- card.move_to_list list
151
- else
152
- card = Trello::Card.create name:card_name, list_id:list.id
129
+ # set color label
130
+ if event[:color]
131
+ if event[:color][:add]
132
+ label = label_in_board_with_color board, event[:color][:add]
133
+ card.add_label label
134
+ end
135
+ if event[:color][:remove]
136
+ label = label_in_board_with_color board, event[:color][:remove]
137
+ card.remove_label label
138
+ end
153
139
  end
154
140
 
155
141
  rescue => e
156
142
  # TODO: Resend if it fails.
157
143
  p e
144
+ puts $!
145
+ puts $@
158
146
  end
159
147
  end
160
148
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ladder_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuyoshi Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-02 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,21 +30,21 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '6.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '6.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ffi
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.9.24
47
+ version: '1.9'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: 1.9.24
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: 1.9.24
57
+ version: '1.9'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.9.24
@@ -82,16 +82,42 @@ dependencies:
82
82
  name: serialport
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.3'
85
88
  - - ">="
86
89
  - !ruby/object:Gem::Version
87
- version: '0'
90
+ version: 1.3.1
88
91
  type: :runtime
89
92
  prerelease: false
90
93
  version_requirements: !ruby/object:Gem::Requirement
91
94
  requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.3'
92
98
  - - ">="
93
99
  - !ruby/object:Gem::Version
94
- version: '0'
100
+ version: 1.3.1
101
+ - !ruby/object:Gem::Dependency
102
+ name: ambient_iot
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '0.1'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.1
111
+ type: :runtime
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.1'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 0.1.1
95
121
  - !ruby/object:Gem::Dependency
96
122
  name: google_drive
97
123
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +125,9 @@ dependencies:
99
125
  - - "~>"
100
126
  - !ruby/object:Gem::Version
101
127
  version: '3.0'
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 3.0.3
102
131
  type: :runtime
103
132
  prerelease: false
104
133
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,6 +135,9 @@ dependencies:
106
135
  - - "~>"
107
136
  - !ruby/object:Gem::Version
108
137
  version: '3.0'
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 3.0.3
109
141
  - !ruby/object:Gem::Dependency
110
142
  name: ruby-trello
111
143
  requirement: !ruby/object:Gem::Requirement
@@ -121,19 +153,33 @@ dependencies:
121
153
  - !ruby/object:Gem::Version
122
154
  version: '2.1'
123
155
  - !ruby/object:Gem::Dependency
124
- name: bundler
156
+ name: dotenv
125
157
  requirement: !ruby/object:Gem::Requirement
126
158
  requirements:
127
159
  - - "~>"
128
160
  - !ruby/object:Gem::Version
129
- version: '1.11'
130
- type: :development
161
+ version: '2.1'
162
+ type: :runtime
131
163
  prerelease: false
132
164
  version_requirements: !ruby/object:Gem::Requirement
133
165
  requirements:
134
166
  - - "~>"
135
167
  - !ruby/object:Gem::Version
136
- version: '1.11'
168
+ version: '2.1'
169
+ - !ruby/object:Gem::Dependency
170
+ name: bundler
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
137
183
  - !ruby/object:Gem::Dependency
138
184
  name: rake
139
185
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +236,10 @@ files:
190
236
  - lib/ladder_drive/protocol/mitsubishi/mc_protocol.rb
191
237
  - lib/ladder_drive/protocol/mitsubishi/mitsubishi.rb
192
238
  - lib/ladder_drive/protocol/mitsubishi/qdevice.rb
239
+ - lib/ladder_drive/protocol/omron/c_mode_protocol.rb
240
+ - lib/ladder_drive/protocol/omron/fins_tcp_protocol.rb
241
+ - lib/ladder_drive/protocol/omron/omron.rb
242
+ - lib/ladder_drive/protocol/omron/omron_device.rb
193
243
  - lib/ladder_drive/protocol/protocol.rb
194
244
  - lib/ladder_drive/tasks/build.rb
195
245
  - lib/ladder_drive/uploader.rb
@@ -200,6 +250,7 @@ files:
200
250
  - lib/plc/emulator/emu_plc_server.rb
201
251
  - lib/plc/emulator/emulator.rb
202
252
  - lib/plc/emulator/plc_plugins.rb
253
+ - lib/plc/emulator/plugin_trigger_state.rb
203
254
  - lib/plc/keyence/kv/kv-5000/DocumentWindowInfo.xml
204
255
  - lib/plc/keyence/kv/kv-5000/KvsMon.ini
205
256
  - lib/plc/keyence/kv/kv-5000/LadderDrive.mod
@@ -226,7 +277,14 @@ files:
226
277
  - lib/plc/raspberrypi/raspberrypi.rb
227
278
  - lib/plc/raspberrypi/raspberrypi_plc.rb
228
279
  - lib/plc/raspberrypi/raspberrypi_plc_server.rb
280
+ - plugins/ambient_plugin.rb
229
281
  - plugins/blank_plugin.rb
282
+ - plugins/config/ambient.yaml.example
283
+ - plugins/config/google_drive.yaml.example
284
+ - plugins/config/ifttt.yaml.example
285
+ - plugins/config/plc_mapper.yaml.example
286
+ - plugins/config/slack.yaml.example
287
+ - plugins/config/trello.yaml.example
230
288
  - plugins/google_drive_plugin.rb
231
289
  - plugins/ifttt_plugin.rb
232
290
  - plugins/plc_mapper_plugin.rb
@@ -253,15 +311,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
311
  requirements:
254
312
  - - ">="
255
313
  - !ruby/object:Gem::Version
256
- version: '0'
314
+ version: 2.3.3
257
315
  required_rubygems_version: !ruby/object:Gem::Requirement
258
316
  requirements:
259
317
  - - ">="
260
318
  - !ruby/object:Gem::Version
261
319
  version: '0'
262
320
  requirements: []
263
- rubyforge_project:
264
- rubygems_version: 2.5.2
321
+ rubygems_version: 3.1.2
265
322
  signing_key:
266
323
  specification_version: 4
267
324
  summary: The ladder_drive is a simple abstract ladder for PLC (Programmable Logic