diff --git a/apex.gemspec b/apex.gemspec index 20b6a76b0f591fd6a70e82875a217fb8054be4ba..576235ceec3e3ddf81529cc051c6df66a6586053 100644 --- a/apex.gemspec +++ b/apex.gemspec @@ -29,10 +29,11 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_development_dependency "json", "~> 1.8.3" - spec.add_development_dependency "bundler", "~> 1.13" - spec.add_development_dependency "rake", "~> 11.3.0" - spec.add_development_dependency('rdoc') - spec.add_development_dependency('aruba') - spec.add_dependency('methadone', '~> 1.8.0') + spec.add_development_dependency 'abstraction', '~> 0.0.4' + spec.add_development_dependency 'json', '~> 1.8.3' + spec.add_development_dependency 'bundler', '~> 1.13' + spec.add_development_dependency 'rake', '~> 11.3.0' + spec.add_development_dependency 'rdoc' + spec.add_development_dependency 'aruba' + spec.add_dependency 'methadone' end diff --git a/bin/apex b/bin/apex index 598789860eb90ec7b6bea09ebb071a553a4f23f9..9a97ec18affebdb1fa76a1e7ea69d654a55c742b 100755 --- a/bin/apex +++ b/bin/apex @@ -9,8 +9,8 @@ class App include Methadone::CLILogging main do |needed, maybe| - options[:switch] - options[:flag] + puts options[:switch] + puts options[:flag] end description "APEX reference implementation for the APEX protocol." diff --git a/features/apex.feature b/features/apex.feature index e5b77204af9987a762e937e7465b1e9e8272b72c..7ba029b40d24d5b89ac995842cae9279e002e45e 100644 --- a/features/apex.feature +++ b/features/apex.feature @@ -10,4 +10,9 @@ Feature: My bootstrapped app kinda works And the banner should document that this app takes options And the following options should be documented: |--version| - And the banner should document that this app takes no arguments + |--[no]-switch| + |--flag| + And the banner should document that this app's arguments are: + |needed|which is required| + |maybe|which is optional| + And there should be a one line summary of what the app does diff --git a/lib/apex.rb b/lib/apex.rb index 0b9db7146a08ad890e133c356588548e8f78ea8e..060ec8dd5c4550ddd94545678b7fa3295c1d5cfa 100644 --- a/lib/apex.rb +++ b/lib/apex.rb @@ -1,5 +1,6 @@ -require_relative "apex/version" +require_relative 'apex/version' +require_relative 'kiss/kiss' module Apex - # Your code goes here... + end diff --git a/lib/kiss/constants.rb b/lib/kiss/constants.rb new file mode 100644 index 0000000000000000000000000000000000000000..82980593ea04f9d3e39013055e5156cb78135373 --- /dev/null +++ b/lib/kiss/constants.rb @@ -0,0 +1,61 @@ +module KISS + # KISS Special Characters + # http://en.wikipedia.org/wiki/KISS_(TNC)#Special_Characters + FEND = 0xC0 + FESC = 0xDB + TFEND = 0xDC + TFESC = 0xDD + + # "FEND is sent as FESC, TFEND" + FESC_TFEND = [KISS::FESC] + [KISS::TFEND] + + # "FESC is sent as FESC, TFESC" + FESC_TFESC = [KISS::FESC] + [KISS::TFESC] + + # KISS Command Codes + # http://en.wikipedia.org/wiki/KISS_(TNC)#Command_Codes + DATA_FRAME = 0x00 + TX_DELAY = 0x01 + PERSISTENCE = 0x02 + SLOT_TIME = 0x03 + TX_TAIL = 0x04 + FULL_DUPLEX = 0x05 + SET_HARDWARE = 0x06 + RETURN = 0xFF + + DEFAULT_KISS_CONFIG_VALUES = { + 'TX_DELAY': 40, + 'PERSISTENCE': 63, + 'SLOT_TIME': 20, + 'TX_TAIL': 30, + 'FULL_DUPLEX': 0, + } + + # This command will exit KISS mode + MODE_END = [192, 255, 192, 13] + + # This will start kiss on a WA8DED or LINK>.<NORD firmware + MODE_INIT_W8DED = [13, 27, 64, 75, 13] + MODE_INIT_LINKNORD = KISS::MODE_INIT_W8DED + + # Kenwood D710 + MODE_INIT_KENWOOD_D710 = [72, 66, 32, 49, 50, 48, 48, 13, # HB 1200 + 75, 73, 83, 83, 32, 79, 78, 13, # KISS ON + 82, 69, 83, 84, 65, 82, 84, 13] # RESTART + + # Kantronics TNCs + MODE_INIT_KANTRONICS = [13, # Blank + 73, 78, 84, 32, 75, 73, 83, 83, 13, # INT KISS + 82, 69, 83, 84, 65, 82, 84, 13] # RESTART + + # TINY2 TNC (TNC2) + MODE_INIT_TINY2 = [13, # Blank + 75, 73, 83, 83, 32, 79, 78, 13, # KISS ON + 82, 69, 83, 84, 65, 82, 84, 13] # RESTART + + # Advanced Electronic Application (later Timewave) PK-232 TNC + MODE_INIT_PK232 = [42, 126, 13, # *~ + 69, 88, 80, 69, 82, 84, 32, 79, 78, 13, # EXPERT ON + 75, 73, 83, 83, 32, 79, 78, 13, # KISS ON + 82, 69, 83, 84, 65, 82, 84, 13] # RESTART +end \ No newline at end of file diff --git a/lib/kiss/kiss.rb b/lib/kiss/kiss.rb new file mode 100644 index 0000000000000000000000000000000000000000..c8e6441520801c602c8ccefa4d82db71ebc25d6e --- /dev/null +++ b/lib/kiss/kiss.rb @@ -0,0 +1,65 @@ +require 'thread' +require 'abstraction' +require_relative 'constants' + +module KISS + class KISS + abstract + + protected + def initialize(strip_df_start=true, exit_kiss=true) + @strip_df_start = strip_df_start + @exit_kiss = exit_kiss + @lock = Mutex.new + end + + private + def self.strip_df_start(frame) + while frame[0] == KISS::DATA_FRAME + frame.shift + end + frame.strip + return frame + end + + private + def self.escape_special_codes(raw_code_bytes) + encoded_bytes = [] + raw_code_bytes.each do |raw_code_byte| + if raw_code_byte == KISS::FESC + encoded_bytes += KISS::FESC_TFESC + elsif raw_code_byte == KISS::FEND + encoded_bytes += KISS::FESC_TFEND + else + encoded_bytes += [raw_code_byte] + end + return encoded_bytes + end + end + + private + def self.command_byte_combine(port, command_code) + if port > 127 or port < 0 + raise 'port out of range' + elsif command_code > 127 or command_code < 0 + raise 'command_Code out of range' + end + return (port << 4) & command_code + end + + def connect(mode_init=None, *args, **kwargs) + end + + def read() + @lock.synchronize do + # read stuff + end + end + + def write(frame_bytes, port=0) + @lock.synchronize do + # write stuff + end + end + end +end \ No newline at end of file