require 'thor' require 'rfbeam' require 'tty-table' require 'tty-logger' require 'tty-spinner' require 'io/console' require 'unicode_plot' module RfBeam class CLI < Thor attr_accessor :radar, :logger desc 'list', 'List available radar modules' def list logger = TTY::Logger.new devices = RfBeam.connected logger.warning 'No Radar modules found.' unless devices.count.positive? table = TTY::Table.new(header: %w[id Path Version]) devices.each.with_index { |path, index| table << ["#{index}", path, radar(index).sw_version] } puts table.render(:ascii) end desc 'config ', 'Shows the parameter setting for the Radar module' def config(radar_id) puts radar(radar_id).config end desc 'reset ', 'Shows the parameter setting for the Radar module' def reset(radar_id) @logger.success 'Radar reset to factory defaults' if radar(radar_id).reset end desc 'set_param ', 'Set radar parameters, see readme for keys' def set_param(radar_id, param, value) return @logger.warn("Invalid param: '#{param}'") unless RfBeam::K_ld7::RADAR_PARAMETERS.include?(param.to_sym) r = radar(radar_id) r.send("#{param}=", value.to_i) @logger.success r.formatted_parameter(param.to_sym) end desc 'ddat ', 'stream any valid detections, stop stream with q and enter' option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device' def ddat(radar_id) cli = RfBeam::KLD7::CliOutput.new(radar_id) cli.display(:ddat, stream: options[:stream]) end desc 'pdat ', 'Display Tracked Targets' def pdat(radar_id) cli = RfBeam::KLD7::CliOutput.new(radar_id) cli.display(:pdat, stream: options[:stream]) end desc 'rfft ', 'Display the dopplar radar data as a plot' option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device' option :raw, type: :boolean, aliases: '-r', desc: 'Display raw data' def rfft(radar_id) plotter = RfBeam::KLD7::CliOutput.new(radar_id) if options[:raw] print radar(radar_id).rfft else plotter.plot(:rfft, stream: options[:stream]) end end desc 'tdat ', 'Display tracked target data' def tdat(radar_id) cli = RfBeam::KLD7::CliOutput.new(radar_id) cli.display(:tdat, stream: options[:stream]) end private def radar(id) devices = RfBeam.connected @logger = TTY::Logger.new return @logger.warning 'No Radar modules found.' unless devices.count.positive? RfBeam::K_ld7.new(devices[id.to_i]) end end end