Commit d1ca171c authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

Refactored several of the methods and classes out into seperate files.

parent c72c1080
require 'colorize'
require 'yaml'
require 'kiss/kiss_serial'
require 'aprs/aprs_kiss'
require 'apex/app_info'
require 'apex/plugins/plugin_factory'
require 'apex/echo'
require 'apex/config_loader'
require 'apex/plugin_loader'
module Apex
BUILTIN_PLUGINS = %w(apex/plugins/apex_paradigm apex/plugins/beacon apex/plugins/id apex/plugins/status)
def self.all_plugins(extra_plugins=[])
return BUILTIN_PLUGINS + extra_plugins
end
def self.load_plugins(plugins=BUILTIN_PLUGINS)
plugins.each do |plugin|
require plugin
end
return Plugins::PluginFactory.get_registered_plugins
end
def self.find_config(verbose, config_paths=[])
config_file = 'apex.conf'
rc_file = '.apexrc'
cur_path = config_file
home_path = File.join(Dir.home, rc_file)
etc_path = File.join('', 'etc', config_file)
config_paths = [cur_path, home_path, etc_path] + config_paths
if verbose
puts 'Searching for configuration file in the following locations: ' + config_paths.inspect
end
config_paths.each do |config_path|
if File.file?(config_path)
return YAML::load_file(config_path)
end
end
return nil
end
def self.echo_color_frame(frame, port_name, direction_in)
formatted_aprs = [frame[:source].colorize(:green), frame[:destination].colorize(:blue)].join('>')
paths = []
frame[:path].each do |path|
paths << path.colorize(:cyan)
end
paths = paths.join(',')
if frame[:path] and frame[:path].length > 0
formatted_aprs = [formatted_aprs, paths].join(',')
end
formatted_aprs += ':'
formatted_aprs += frame[:text]
if direction_in
puts (port_name + ' << ').colorize(:magenta) + formatted_aprs
else
# TODO : make this bold and/or blink
puts (port_name + ' >> ').colorize(:color => :magenta, :mode => :bold) + formatted_aprs
end
end
def self.echo_colorized_error(text)
puts 'Error: '.colorize(:color => :red, :mode => [:bold, :blink]) + text.colorize(:bold)
end
def self.echo_colorized_warning(text)
puts 'Warning: '.colorize(:color => :yellow) + text
end
def self.main
config = find_config(true)
......
require 'yaml'
module Apex
def self.find_config(verbose, config_paths=[])
config_file = 'apex.conf'
rc_file = '.apexrc'
cur_path = config_file
home_path = File.join(Dir.home, rc_file)
etc_path = File.join('', 'etc', config_file)
config_paths = [cur_path, home_path, etc_path] + config_paths
if verbose
puts 'Searching for configuration file in the following locations: ' + config_paths.inspect
end
config_paths.each do |config_path|
if File.file?(config_path)
return YAML::load_file(config_path)
end
end
return nil
end
end
\ No newline at end of file
require 'colorize'
module Apex
def self.echo_color_frame(frame, port_name, direction_in)
formatted_aprs = [frame[:source].colorize(:green), frame[:destination].colorize(:blue)].join('>')
paths = []
frame[:path].each do |path|
paths << path.colorize(:cyan)
end
paths = paths.join(',')
if frame[:path] and frame[:path].length > 0
formatted_aprs = [formatted_aprs, paths].join(',')
end
formatted_aprs += ':'
formatted_aprs += frame[:text]
if direction_in
puts (port_name + ' << ').colorize(:magenta) + formatted_aprs
else
# TODO : make this bold and/or blink
puts (port_name + ' >> ').colorize(:color => :magenta, :mode => :bold) + formatted_aprs
end
end
def self.echo_colorized_error(text)
puts 'Error: '.colorize(:color => :red, :mode => [:bold, :blink]) + text.colorize(:bold)
end
def self.echo_colorized_warning(text)
puts 'Warning: '.colorize(:color => :yellow) + text
end
end
require 'apex/plugins/plugin_factory'
module Apex
BUILTIN_PLUGINS = %w(apex/plugins/apex_paradigm apex/plugins/beacon apex/plugins/id apex/plugins/status)
def self.all_plugins(extra_plugins=[])
return BUILTIN_PLUGINS + extra_plugins
end
def self.load_plugins(plugins=BUILTIN_PLUGINS)
plugins.each do |plugin|
require plugin
end
return Plugins::PluginFactory.get_registered_plugins
end
end
\ No newline at end of file
module Apex
class TncPort
protected
def initialize(data_stream, name, identifier, net, port=0)
@data_stream = data_stream
@port = port
@name = name
@identifier = identifier
@net = net
end
public
def connect(*args, **kwargs)
@data_stream.connect(*args, **kwargs)
end
public
def close(*args, **kwargs)
@data_stream.close(*args, **kwargs)
end
public
def read(*args, **kwargs)
return @data_stream.read(*args, **kwargs)
end
public
def write(frame, *args, **kwargs)
@data_stream.write(frame, @port, *args, **kwargs)
end
attr_reader :name, :net, :port, :identifier
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment