bcs-interrogator 0.0.2 → 0.0.6

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 (36) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -6
  3. data/lib/brewery_control_system.rb +106 -0
  4. data/lib/brewery_control_system/api.rb +94 -0
  5. data/lib/brewery_control_system/api/3.7.0/bcs_sys.rb +158 -0
  6. data/lib/brewery_control_system/api/3.7.0/device_endpoint.rb +25 -0
  7. data/lib/brewery_control_system/api/3.7.0/endpoint.rb +48 -0
  8. data/lib/brewery_control_system/api/3.7.0/setpoints.rb +15 -0
  9. data/lib/brewery_control_system/api/3.7.0/sysname.rb +247 -0
  10. data/lib/brewery_control_system/api/3.7.0/temperature_probe_names_endpoint.rb +21 -0
  11. data/lib/brewery_control_system/api/3.7.0/temperature_probes_endpoint.rb +42 -0
  12. data/lib/brewery_control_system/api/3.7.0/temps.rb +15 -0
  13. data/lib/brewery_control_system/api/3.7.0/ultemp.rb +117 -0
  14. data/lib/brewery_control_system/api/device.rb +8 -0
  15. data/lib/brewery_control_system/api/server_version.rb +7 -0
  16. data/lib/brewery_control_system/api/version_check.rb +26 -0
  17. data/lib/brewery_control_system/http_service.rb +27 -0
  18. data/lib/brewery_control_system/http_service/user_agent.rb +33 -0
  19. data/lib/brewery_control_system/input.rb +4 -0
  20. data/lib/brewery_control_system/middleware.rb +5 -0
  21. data/lib/brewery_control_system/middleware/registration.rb +18 -0
  22. data/lib/brewery_control_system/output.rb +4 -0
  23. data/lib/brewery_control_system/temperature_probe.rb +4 -0
  24. data/lib/brewery_control_system/version.rb +6 -0
  25. data/spec/spec_helper.rb +6 -1
  26. metadata +48 -80
  27. data/lib/bcs_interrogator.rb +0 -36
  28. data/lib/bcs_interrogator/api.rb +0 -46
  29. data/lib/bcs_interrogator/api/endpoint.rb +0 -61
  30. data/lib/bcs_interrogator/api/response.rb +0 -38
  31. data/lib/bcs_interrogator/api/sysname.rb +0 -227
  32. data/lib/bcs_interrogator/api/ultemp.rb +0 -110
  33. data/lib/bcs_interrogator/entity.rb +0 -43
  34. data/lib/bcs_interrogator/version.rb +0 -6
  35. data/spec/cases/api_spec.rb +0 -33
  36. data/spec/cases/bcs_interrogator_spec.rb +0 -4
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0717bda2b32e02b0b2bf97ded0d4fa4a7675cef6
4
+ data.tar.gz: 5c67f1e6fe53a249928ddff9a45d8220dabccb73
5
+ SHA512:
6
+ metadata.gz: 67efd5b42bf25e79812df4b5a4b6703ddec253551d2c419a79c1f20a821d1ef88e2cdc2362a3d96b6cd76cd8d07bb771809b12248884edc0ead9d6d09e2935a8
7
+ data.tar.gz: 232a4d768c0cac99f521b8f3718c7e31aff5e36855e2b7724d3f0a212277d3b658130babf43c0057d7e413d515c7ab60d9041e2fd58cff27fae5298d248a8fb6
data/README.md CHANGED
@@ -1,11 +1,8 @@
1
1
  BCS-Interrogator
2
2
  ================
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/NewRepublicBrewing/BCS-Interrogator.png)](http://travis-ci.org/NewRepublicBrewing/BCS-Interrogator)
5
4
  [![Dependency Status](https://gemnasium.com/NewRepublicBrewing/BCS-Interrogator.png)](https://gemnasium.com/NewRepublicBrewing/BCS-Interrogator)
6
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/NewRepublicBrewing/BCS-Interrogator)
7
- [![Buggerall](https://buggerall.herokuapp.com/bug/BCS-Interrogator.png)](https://github.com/brundage/buggerall)
8
-
5
+ [![Code Climate](https://codeclimate.com/github/NewRepublicBrewing/BCS-Interrogator/badges/gpa.svg)](https://codeclimate.com/github/NewRepublicBrewing/BCS-Interrogator)
9
6
 
10
7
  Gem to talk to an EEC Brewery Control System
11
8
 
@@ -14,5 +11,3 @@ Requirements
14
11
  ============
15
12
 
16
13
  Ruby 1.9
17
- [NRB HTTP Service gem](https://github.com/NewRepublicBrewing/http-service)
18
-
@@ -0,0 +1,106 @@
1
+ module NRB
2
+ class BreweryControlSystem
3
+ require 'brewery_control_system/version'
4
+
5
+ autoload :API, 'brewery_control_system/api'
6
+ autoload :HTTPService, 'brewery_control_system/http_service'
7
+ autoload :Input, 'brewery_control_system/input'
8
+ autoload :Middleware, 'brewery_control_system/middleware'
9
+ autoload :TemperatureProbe, 'brewery_control_system/temperature_probe'
10
+
11
+ attr_reader :base_url
12
+
13
+ def api_version
14
+ @api_version ||= firmware_version
15
+ end
16
+
17
+
18
+ def device
19
+ api.device
20
+ end
21
+
22
+
23
+ def discrete_inputs
24
+ # 8
25
+ end
26
+
27
+
28
+ def firmware_version
29
+ device.version
30
+ end
31
+
32
+
33
+ def firmware_build
34
+ device.build
35
+ end
36
+
37
+
38
+ def http_service &block
39
+ http_service_class.default_service url: base_url, &block
40
+ end
41
+
42
+
43
+ def initialize(api_class: API, base_url: nil, http_service_class: HTTPService, api_version: nil)
44
+ self.api_class = api_class
45
+ @base_url = base_url; @base_url.freeze
46
+ self.http_service_class = http_service_class
47
+ self.api_version = api_version
48
+ end
49
+
50
+
51
+ def inputs
52
+ # 8
53
+ []
54
+ end
55
+ alias_method :discrete_inputs, :inputs
56
+
57
+
58
+ def name
59
+ device.name
60
+ end
61
+
62
+
63
+ def outputs
64
+ # 18
65
+ end
66
+
67
+
68
+ def processes
69
+ # 8
70
+ # 8 states
71
+ # 4 timers
72
+ # 4 web inputs
73
+ []
74
+ end
75
+
76
+
77
+ def setpoints
78
+ api.setpoints
79
+ end
80
+
81
+
82
+ def temp_probes
83
+ api.temperature_probes
84
+ end
85
+ alias_method :temperature_probes, :temp_probes
86
+
87
+
88
+ def type
89
+ device.type
90
+ end
91
+
92
+ private
93
+
94
+ attr_accessor :api_class, :http_service_class
95
+ attr_reader :base_url
96
+ attr_writer :api, :api_version
97
+
98
+ def api
99
+ return @api unless @api.nil?
100
+ api_args = { base_url: base_url, bcs: self }
101
+ api_args[:api_version] = api_version unless @api_version.nil?
102
+ @api = api_class.new api_args
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,94 @@
1
+ class NRB::BreweryControlSystem
2
+ class API
3
+
4
+ autoload :Device, 'brewery_control_system/api/device'
5
+ autoload :ServerVersion, 'brewery_control_system/api/server_version'
6
+ autoload :VersionCheck, 'brewery_control_system/api/version_check'
7
+
8
+ # Device
9
+ # name string
10
+ # type string
11
+ # version string
12
+ # build string
13
+ # 3.x
14
+ # /bcs_sys.cfg
15
+ # 4.x
16
+ # /device
17
+ def device
18
+ @device_response ||= http_service do |b|
19
+ b.response DeviceEndpoint
20
+ end.get(DeviceEndpoint.endpoint).body
21
+ Device.new *@device_response
22
+ end
23
+
24
+
25
+ def http_service
26
+ service = bcs.http_service do |b|
27
+ b.response VersionCheck, api_version
28
+ end
29
+ yield service if block_given?
30
+ service
31
+ end
32
+
33
+
34
+ # Temperature Probes
35
+ # name string
36
+ # temp integer
37
+ # setpoint integer
38
+ # resistance integer
39
+ # enabled boolean
40
+ # coefficients array
41
+ def temperature_probes
42
+ TemperatureProbesEndpoint.fetch api: self
43
+ end
44
+
45
+ # Digital Inputs
46
+ # name string
47
+ # on boolean
48
+ # enabled boolean
49
+ # oneshot boolean
50
+
51
+ # Outputs
52
+ # name string
53
+ # on boolean
54
+ # enabled boolean
55
+
56
+ # Processes
57
+ # name string
58
+ # running boolean
59
+ # paused boolean
60
+ # run_on_startup boolean
61
+ # current_state state
62
+ # name string
63
+ # state integer
64
+
65
+ def initialize(api_version: '3.7.0', base_url: nil, bcs: nil)
66
+ self.base_url = base_url
67
+ self.bcs = bcs
68
+ self.api_version = api_version
69
+
70
+ require_endpoints
71
+ end
72
+
73
+ private
74
+
75
+ attr_accessor :base_url, :bcs, :api_version
76
+
77
+ def require_endpoints
78
+ %w( endpoint
79
+ device_endpoint
80
+ setpoints
81
+ temps
82
+ temperature_probes_endpoint
83
+ ultemp
84
+ ).each do |f|
85
+ begin
86
+ require "brewery_control_system/api/#{api_version}/#{f}"
87
+ rescue LoadError => e
88
+ warn "API v#{api_version} may not function: #{e}"
89
+ end
90
+ end
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,158 @@
1
+ class NRB::BreweryControlSystem::API
2
+ class BCSSys < Endpoint
3
+ # http://wiki.embeddedcc.com/index.php/Bcs_sys.cfg
4
+ # The configuration file contains of all non-process parameters, with
5
+ # some exclusions. All entries in the sysname structure cannot be more
6
+ # than 16 characters, commas are not allowed.
7
+
8
+ class << self
9
+ def endpoint; 'bcs_sys.cfg'; end
10
+ end
11
+
12
+ DESCRIPTIONS = [
13
+ 'Firmware version',
14
+ 'System Name 0',
15
+ 'System Name 1',
16
+ 'Output 0 Name',
17
+ 'Output 1 Name',
18
+ 'Output 2 Name',
19
+ 'Output 3 Name',
20
+ 'Output 4 Name',
21
+ 'Output 5 Name',
22
+ 'Output 6 Name',
23
+ 'Output 7 Name',
24
+ 'Output 8 Name',
25
+ 'Output 9 Name',
26
+ 'Output 10 Name',
27
+ 'Output 11 Name',
28
+ 'Output 12 Name',
29
+ 'Output 13 Name',
30
+ 'Output 14 Name',
31
+ 'Output 15 Name',
32
+ 'Output 16 Name',
33
+ 'Output 17 Name',
34
+ 'Discrete Output 1 Name',
35
+ 'Discrete Output 2 Name',
36
+ 'Discrete Output 3 Name',
37
+ 'Discrete Output 4 Name',
38
+ 'Discrete Output 5 Name',
39
+ 'Discrete Output 6 Name',
40
+ 'Discrete Output 7 Name',
41
+ 'Discrete Output 8 Name',
42
+ 'Temp Probe 0 Name',
43
+ 'Temp Probe 1 Name',
44
+ 'Temp Probe 2 Name',
45
+ 'Temp Probe 3 Name',
46
+ 'Temp Probe 4 Name',
47
+ 'Temp Probe 5 Name',
48
+ 'Temp Probe 6 Name',
49
+ 'Temp Probe 7 Name',
50
+ 'Reserved 0',
51
+ 'Reserved 1',
52
+ 'Register 0 Name',
53
+ 'Register 1 Name',
54
+ 'Register 2 Name',
55
+ 'Register 3 Name',
56
+ 'Register 4 Name',
57
+ 'Register 5 Name',
58
+ 'Register 6 Name',
59
+ 'Register 7 Name',
60
+ 'Register 8 Name',
61
+ 'Register 9 Name',
62
+ 'Register 10 Name',
63
+ 'Register 11 Name',
64
+ 'Register 12 Name',
65
+ 'Register 13 Name',
66
+ 'Register 14 Name',
67
+ 'Register 15 Name',
68
+ 'Process 0 State',
69
+ 'Process 1 State',
70
+ 'Process 2 State',
71
+ 'Process 3 State',
72
+ 'Output 0,6,12 Value',
73
+ 'Output 1,7,13 Value',
74
+ 'Output 2,8,14 Value',
75
+ 'Output 3,9,15 Value',
76
+ 'Output 4,10,16 Value',
77
+ 'Output 5,11,17 Value',
78
+ 'Discrete Input 0,4 Value',
79
+ 'Discrete Input 1,5 Value',
80
+ 'Discrete Input 2,6 Value',
81
+ 'Discrete Input 3,7 Value',
82
+ 'Process 0,4 Web Input 0 Value',
83
+ 'Process 0,4 Web Input 1 Value',
84
+ 'Process 0,4 Web Input 2 Value',
85
+ 'Process 0,4 Web Input 3 Value',
86
+ 'Process 1,5 Web Input 0 Value',
87
+ 'Process 1,5 Web Input 1 Value',
88
+ 'Process 1,5 Web Input 2 Value',
89
+ 'Process 1,5 Web Input 3 Value',
90
+ 'Process 2,6 Web Input 0 Value',
91
+ 'Process 2,6 Web Input 1 Value',
92
+ 'Process 2,6 Web Input 2 Value',
93
+ 'Process 2,6 Web Input 3 Value',
94
+ 'Process 3,7 Web Input 0 Value',
95
+ 'Process 3,7 Web Input 1 Value',
96
+ 'Process 3,7 Web Input 2 Value',
97
+ 'Process 3,7 Web Input 3 Value',
98
+ 'Process 0,4 Run',
99
+ 'Process 1,5 Run',
100
+ 'Process 2,6 Run',
101
+ 'Proces,7 Run',
102
+ 'Manual Mode Run',
103
+ 'BCS Version', # 0=BCS-460, 2=BCS-462
104
+ 'Reserved 0',
105
+ 'Reserved 1',
106
+ 'Discrete Input 0,4 Enable',
107
+ 'Discrete Input 1,5 Enable',
108
+ 'Discrete Input 2,6 Enable',
109
+ 'Discrete Input 3,7 Enable',
110
+ 'Process 0,4 Web Input 0 Enable',
111
+ 'Process 0,4 Web Input 1 Enable',
112
+ 'Process 0,4 Web Input 2 Enable',
113
+ 'Process 0,4 Web Input 3 Enable',
114
+ 'Process 1,5 Web Input 0 Enable',
115
+ 'Process 1,5 Web Input 1 Enable',
116
+ 'Process 1,5 Web Input 2 Enable',
117
+ 'Process 1,5 Web Input 3 Enable',
118
+ 'Process 2,6 Web Input 0 Enable',
119
+ 'Process 2,6 Web Input 1 Enable',
120
+ 'Process 2,6 Web Input 2 Enable',
121
+ 'Process 2,6 Web Input 3 Enable',
122
+ 'Process 3,7 Web Input 0 Enable',
123
+ 'Process 3,7 Web Input 1 Enable',
124
+ 'Process 3,7 Web Input 2 Enable',
125
+ 'Process 3,7 Web Input 3 Enable',
126
+ 'Output 0,6,12 Enable',
127
+ 'Output 1,7,13 Enable',
128
+ 'Output 2,8,14 Enable',
129
+ 'Output 3,9,15 Enable',
130
+ 'Output 4,10,16 Enable',
131
+ 'Output 5,11,17 Enable',
132
+ 'Temp 0,4 Enable',
133
+ 'Temp 1,5 Enable',
134
+ 'Temp 2,6 Enable',
135
+ 'Temp 3,7 Enable',
136
+ ].freeze
137
+
138
+ register_middleware middleware_options(self)
139
+
140
+ private
141
+
142
+ def body_array
143
+ super.map { |val| val.strip[/.+/m] }
144
+ end
145
+
146
+
147
+ def parse
148
+ raise "Stop using this"
149
+ return if body_text.nil?
150
+ body_array[0..55] + body_array[248..252].map { |i| i.to_f / 10.0 }
151
+ # body_array.each_with_index.inject({}) do |hash,(body,i)|
152
+ # hash[descriptions[i]] = body_array[i]
153
+ # hash
154
+ # end
155
+ end
156
+
157
+ end
158
+ end
@@ -0,0 +1,25 @@
1
+ class NRB::BreweryControlSystem::API
2
+ class DeviceEndpoint < Endpoint
3
+ # http://wiki.embeddedcc.com/index.php/Bcs_sys.cfg
4
+
5
+ class << self
6
+ def endpoint; 'bcs_sys.cfg'; end
7
+ end
8
+
9
+ register_middleware middleware_options(self)
10
+
11
+ private
12
+
13
+ def body_array
14
+ super.map { |val| val.strip[/.+/m] }
15
+ end
16
+
17
+
18
+ def parse
19
+ return if body_text.nil?
20
+ (device, version) = body_array[0].split(/\s+/)
21
+ [ body_array[1], device, version, nil ]
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ class NRB::BreweryControlSystem::API
2
+ class Endpoint < Faraday::Response::Middleware
3
+
4
+ extend NRB::BreweryControlSystem::Middleware::Registration
5
+
6
+ class << self
7
+
8
+ def descriptions;
9
+ self.const_defined?(:DESCRIPTIONS) ? self.const_get(:DESCRIPTIONS) : []
10
+ end
11
+
12
+
13
+ def middleware_name; self; end
14
+
15
+
16
+ def middleware_options(endpoint)
17
+ opts = Hash.new
18
+ opts[middleware_name] = endpoint
19
+ opts
20
+ end
21
+
22
+ end
23
+
24
+
25
+ def descriptions; self.class.descriptions; end
26
+
27
+
28
+ def on_complete(env)
29
+ self.body_text = env[:body]
30
+ env[:body] = parse
31
+ end
32
+
33
+ private
34
+
35
+ attr_accessor :body_text
36
+ attr_reader :body_array
37
+
38
+ def body_array
39
+ return unless body_text
40
+ @body_array ||= body_text.split(/,/)
41
+ end
42
+
43
+
44
+ def parse
45
+ end
46
+
47
+ end
48
+ end