lib/automate-em/device/device_connection.rb in automate-em-0.0.3 vs lib/automate-em/device/device_connection.rb in automate-em-0.0.4
- old
+ new
@@ -4,17 +4,17 @@
# This contains the basic constructs required for
# serialised comms over TCP and UDP
#
module AutomateEm
module DeviceConnection
- def initialize( parent )
- super
+ def initialize( parent, udp )
+ #super
@default_send_options = {
:wait => true, # Wait for response
:delay => 0, # Delay next send by x.y seconds
- :delay_on_recieve => 0, # Delay next send after a recieve by x.y seconds (only works when we are waiting for responses)
+ :delay_on_receive => 0, # Delay next send after a receive by x.y seconds (only works when we are waiting for responses)
#:emit
:max_waits => 3,
:callback => nil, # Alternative to the received function
:retries => 2,
:hex_string => false,
@@ -26,12 +26,12 @@
@config = {
:max_buffer => 524288, # 512kb
:clear_queue_on_disconnect => false,
:flush_buffer_on_disconnect => false,
- :priority_bonus => 20,
- :inactivity_timeout => 0 # part of make and break options
+ :priority_bonus => 20
+ # :inactivity_timeout => 0 # part of make and break options
# :response_length # an alternative to response_delimiter (lower priority)
# :response_delimiter # here instead of a function call
}
@@ -59,20 +59,20 @@
#
# State
#
- @connected = false
+ @connected = udp
@connecting = false
@disconnecting = false
@com_paused = true
@command = nil
@waiting = false
@processing = false
@last_sent_at = 0.0
- @last_recieve_at = 0.0
+ @last_receive_at = 0.0
@timeout = nil
#
# Configure links between objects (This is a very loose tie)
@@ -250,11 +250,11 @@
# Allow modules to set message delimiters for auto-buffering
# Default max buffer length == 1mb (setting can be overwritten)
# NOTE: The buffer cannot be defered otherwise there are concurrency issues
#
def do_receive_data(data)
- @last_recieve_at = Time.now.to_f
+ @last_receive_at = Time.now.to_f
begin
if @config[:response_delimiter].present?
if @buf.nil?
del = @config[:response_delimiter]
@@ -431,12 +431,12 @@
end
@processing = false
@waiting = false
- if @command[:delay_on_recieve] > 0.0
- delay_for = (@last_recieve_at + @command[:delay_on_recieve] - Time.now.to_f)
+ if @command[:delay_on_receive] > 0.0
+ delay_for = (@last_receive_at + @command[:delay_on_receive] - Time.now.to_f)
if delay_for > 0.0
EM.add_timer delay_for do
process_response_complete
end
@@ -448,11 +448,11 @@
end
end
end
def process_response_complete
- if (@make_break && @config[:inactivity_timeout] == 0 && @send_queue.empty?) || @command[:force_disconnect]
+ if (@make_break && [nil, 0].include?(@config[:inactivity_timeout]) && @send_queue.empty?) || @command[:force_disconnect]
if @connected
close_connection_after_writing
@disconnecting = true
end
@com_paused = true
@@ -606,10 +606,10 @@
def call_connected(*args)
#
# NOTE:: Same as add parent in device module!!!
# TODO:: Should break into a module and include it
#
- set_comm_inactivity_timeout(@config[:inactivity_timeout])
+ set_comm_inactivity_timeout(@config[:inactivity_timeout]) unless @config[:inactivity_timeout].nil?
@task_queue.push lambda {
EM.defer do
@parent[:connected] = true
begin
\ No newline at end of file