Class: MeasReceiver::MeasTypeReceiver
- Inherits:
-
Object
- Object
- MeasReceiver::MeasTypeReceiver
- Defined in:
- lib/meas_receiver/meas_type_receiver.rb
Constant Summary collapse
- SCH_MIN_INTERVAL =
0.05
- DEFAULT_FETCH_INTERVAL =
0.5
- MIN_FETCH_INTERVAL =
0.1
Instance Attribute Summary collapse
-
#after_proc ⇒ Object
readonly
Returns the value of attribute after_proc.
-
#coefficients ⇒ Object
readonly
Returns the value of attribute coefficients.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#fetch_interval ⇒ Object
readonly
Returns the value of attribute fetch_interval.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#meas_buffer ⇒ Object
readonly
Returns the value of attribute meas_buffer.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#response_size ⇒ Object
readonly
Returns the value of attribute response_size.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #clean ⇒ Object
- #fetch ⇒ Object
- #first ⇒ Object
-
#initialize(_options) ⇒ MeasTypeReceiver
constructor
TODO convert all keys to Symbols.
- #last ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(_options) ⇒ MeasTypeReceiver
TODO convert all keys to Symbols
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 15 def initialize() @options = @options[:logger] ||= Hash.new @options[:logger][:output] ||= STDOUT @options[:logger][:level] ||= Logger::INFO @logger = Logger.new(@options[:logger][:output]) @logger.level = @options[:logger][:level] @debug = (@options[:logger][:level] == Logger::DEBUG) @fetch_interval = [:fetch_interval] || DEFAULT_FETCH_INTERVAL @fetch_interval = MIN_FETCH_INTERVAL if @fetch_interval < MIN_FETCH_INTERVAL @name = @options[:name] @command = @options[:command] @response_size = @options[:response_size] @coefficients = @options[:coefficients] || Hash.new @coefficients[:linear] ||= 1.0 @coefficients[:offset] ||= 0.0 @after_proc = @options[:after_proc] @storage = @options[:storage] || Hash.new @storage[:min_time_interval] ||= @fetch_interval @storage[:min_unit_interval] = (@storage[:min_time_interval] / @fetch_interval).floor @storage[:max_time_interval] ||= 3600 @storage[:max_unit_interval] = (@storage[:max_time_interval] / @fetch_interval).floor @storage[:store_interval] ||= 10*60 #2*3600 @comm_object = CommProtocol.new(@command, @response_size) @meas_buffer = MeasTypeBuffer.new(self) end |
Instance Attribute Details
#after_proc ⇒ Object (readonly)
Returns the value of attribute after_proc.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def after_proc @after_proc end |
#coefficients ⇒ Object (readonly)
Returns the value of attribute coefficients.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def coefficients @coefficients end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def command @command end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def debug @debug end |
#fetch_interval ⇒ Object (readonly)
Returns the value of attribute fetch_interval.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def fetch_interval @fetch_interval end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def logger @logger end |
#meas_buffer ⇒ Object (readonly)
Returns the value of attribute meas_buffer.
83 84 85 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 83 def meas_buffer @meas_buffer end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def name @name end |
#response_size ⇒ Object (readonly)
Returns the value of attribute response_size.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def response_size @response_size end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
46 47 48 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 46 def storage @storage end |
Instance Method Details
#[](i) ⇒ Object
85 86 87 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 85 def [](i) @meas_buffer[i] end |
#clean ⇒ Object
79 80 81 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 79 def clean @meas_buffer.clean_up! end |
#fetch ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 66 def fetch v = @comm_object.g @meas_buffer.add!(v) @logger.debug("Fetched #{self.name.red} = #{v.to_s.yellow}") if @debug return v end |
#first ⇒ Object
89 90 91 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 89 def first @meas_buffer.first end |
#last ⇒ Object
93 94 95 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 93 def last @meas_buffer.last end |
#start ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 48 def start @logger.debug("MeasReceiver started for #{self.name.red}") if @debug @scheduler = Rufus::Scheduler.start_new(frequency: SCH_MIN_INTERVAL) @scheduler.every "#{@fetch_interval}s" do fetch end @scheduler.every "#{@storage[:store_interval]}s" do store end end |
#stop ⇒ Object
61 62 63 64 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 61 def stop @scheduler.stop @logger.debug("MeasReceiver stopped for #{self.name.red}") if @debug end |
#store ⇒ Object
75 76 77 |
# File 'lib/meas_receiver/meas_type_receiver.rb', line 75 def store @meas_buffer.perform_storage! end |