From 530f758b421fc0ce33bedaf0397c739ced0af348 Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Fri, 30 Sep 2016 12:57:06 -0400
Subject: [PATCH] Fixed the cucumber features being tested. Added the beginings
 of a KISS class.

---
 apex.gemspec          | 13 +++++----
 bin/apex              |  4 +--
 features/apex.feature |  7 ++++-
 lib/apex.rb           |  5 ++--
 lib/kiss/constants.rb | 61 ++++++++++++++++++++++++++++++++++++++++
 lib/kiss/kiss.rb      | 65 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 144 insertions(+), 11 deletions(-)
 create mode 100644 lib/kiss/constants.rb
 create mode 100644 lib/kiss/kiss.rb

diff --git a/apex.gemspec b/apex.gemspec
index 20b6a76..576235c 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 5987898..9a97ec1 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 e5b7720..7ba029b 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 0b9db71..060ec8d 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 0000000..8298059
--- /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 0000000..c8e6441
--- /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
-- 
GitLab