class Argus::ATCommander
Attributes
interval[RW]
timestamps[R]
Public Class Methods
new(sender)
click to toggle source
# File lib/argus/at_commander.rb 8 def initialize(sender) 9 @sender = sender 10 @seq = 0 11 @ref_data = "0" 12 @pcmd_data = "0,0,0,0,0" 13 @buffer = "" 14 @thread = nil 15 @interval = 0.020 16 @mutex = Mutex.new 17 @timestamps = [] 18 end
Public Instance Methods
comwdg()
click to toggle source
# File lib/argus/at_commander.rb 62 def comwdg 63 @mutex.synchronize do 64 command("COMWDG") 65 end 66 end
Also aliased as: reset_watchdog
config(key, value)
click to toggle source
# File lib/argus/at_commander.rb 56 def config(key, value) 57 @mutex.synchronize do 58 command("CONFIG", "\"#{key}\",\"#{value}\"") 59 end 60 end
ctrl(mode)
click to toggle source
# File lib/argus/at_commander.rb 69 def ctrl(mode) 70 @mutex.synchronize do 71 command("CTRL", "#{mode},0") 72 end 73 end
join()
click to toggle source
# File lib/argus/at_commander.rb 44 def join 45 @thread.join if @thread 46 end
pcmd(data)
click to toggle source
# File lib/argus/at_commander.rb 52 def pcmd(data) 53 @mutex.synchronize do @pcmd_data = data end 54 end
ref(data)
click to toggle source
# File lib/argus/at_commander.rb 48 def ref(data) 49 @mutex.synchronize do @ref_data = data end 50 end
start()
click to toggle source
# File lib/argus/at_commander.rb 20 def start 21 @running = true 22 @thread = Thread.new do 23 while @running 24 log_time 25 tick 26 sleep @interval 27 end 28 end 29 end
stop()
click to toggle source
# File lib/argus/at_commander.rb 40 def stop 41 @running = false 42 end
tick()
click to toggle source
# File lib/argus/at_commander.rb 31 def tick 32 @mutex.synchronize do 33 packet do 34 command("REF", @ref_data) 35 command("PCMD", @pcmd_data) 36 end 37 end 38 end
Private Instance Methods
command(name, args=nil)
click to toggle source
# File lib/argus/at_commander.rb 92 def command(name, args=nil) 93 @seq += 1 94 if args 95 @buffer << "AT*#{name}=#{@seq},#{args}\r" 96 else 97 @buffer << "AT*#{name}=#{@seq}\r" 98 end 99 end
flush()
click to toggle source
# File lib/argus/at_commander.rb 87 def flush 88 @sender.send_packet(@buffer) 89 @buffer = "" 90 end
log_time()
click to toggle source
# File lib/argus/at_commander.rb 77 def log_time 78 @timestamps.shift if @timestamps.size >= 1000 79 @timestamps << Time.now.to_f 80 end
packet() { |self| ... }
click to toggle source
# File lib/argus/at_commander.rb 82 def packet 83 yield self 84 flush 85 end