Deleted RFduino code
Deleted RFduino code

--- a/src/RFDuino_TNC/AFSK_Demodulator.c
+++ /dev/null
@@ -1,200 +1,1 @@
-// AFSK_Demodulator.c
 
-#include "AFSK_Demodulator.h"
-
-static AFSK_Demodulator self;
-
-void AFSK_Demodulator_reset() {
-
-  self.count_last = 0;
-
-  self.window = (int)(SAMPLE_RATE / self.bit_rate + 0.5);
-
-  self.bitwidth = SAMPLE_RATE / self.bit_rate;
-
-  /*
-   * Calculate Goertzel coefficents for calculating frequency magnitudes
-   */
-  float k0 = ((float)self.window * self.frequency_0 / SAMPLE_RATE);
-  float k1 = ((float)self.window * self.frequency_1 / SAMPLE_RATE);
-  float w0 = (2 * PI / self.window) * k0;
-  float w1 = (2 * PI / self.window) * k1;
-
-  self.coeff0 = d_from_float(2 * cos(w0));
-  self.coeff1 = d_from_float(2 * cos(w1));
-
-  self.last_bit = 0;
-
-  self.bit_stuffing = false;
-
-  if (self.input_buffer.size != 0)
-    decimal_ring_buffer_destory(&self.input_buffer);
-  decimal_ring_buffer_init(&self.input_buffer, self.window + 2);
-
-  self.fcd_filt = 0;
-
-  self.byte_seq_len = 0;
-
-  char_ring_buffer_clear(&self.bit_sequence);
-
-}
-
-void AFSK_Demodulator_init(const uint16_t frequency_0, const uint16_t frequency_1, const uint16_t bit_rate, const decimal offset) {
-
-  self.frequency_0 = frequency_0;
-  self.frequency_1 = frequency_1;
-
-  self.bit_rate = bit_rate;
-
-  self.offset = offset;
-
-  self.input_buffer.size = 0;
-
-  self.fcd_filt = 0;
-  self.byte_seq_len = 0;
-
-  char_ring_buffer_init(&self.bit_sequence, 14);
-
-  AFSK_Demodulator_reset(self);
-
-}
-
-void AFSK_Demodulator_proccess_byte(const int8_t data_point, uint8_t * new_data) {
-
-  new_data[0] = 0;
-
-  decimal_ring_buffer_put(&self.input_buffer, d_from_int(data_point));
-
-  if (decimal_ring_buffer_avail(&self.input_buffer) > self.window) {
-
-    decimal q1_0 = 0;
-    decimal q1_1 = 0;
-    decimal q2_0 = 0;
-    decimal q2_1 = 0;
-
-    int16_t i;
-    for (i = 0; i <= self.window; i++) {
-
-      decimal q0_0 = dcmul(self.coeff0, q1_0) - q2_0 + decimal_ring_buffer_get(&self.input_buffer, i);
-      decimal q0_1 = dcmul(self.coeff1, q1_1) - q2_1 + decimal_ring_buffer_get(&self.input_buffer, i);
-      q2_0 = q1_0;
-      q2_1 = q1_1;
-      q1_0 = q0_0;
-      q1_1 = q0_1;
-
-    }
-
-    decimal fc1 = dcmul(q1_0, q1_0) + dcmul(q2_0, q2_0) - dcmul(dcmul(q1_0, q2_0), self.coeff0);
-    decimal fc2 = dcmul(q1_1, q1_1) + dcmul(q2_1, q2_1) - dcmul(dcmul(q1_1, q2_1), self.coeff1);
-
-    /* The 1800 Offset needs to be calculated based on the amplitude of the incomming signal
-     * the radio should have a tunning utility so it will turn on an LED when the signal amplitude
-     * is in the ideal range for the offset
-     */
-    decimal fcd = fc1 - fc2 - self.offset;
-
-    decimal_ring_buffer_pop(&self.input_buffer);
-
-    // Moving average filter
-    self.fcd_filt = self.fcd_filt + dmul((fcd - self.fcd_filt), d_from_float(0.4)); // FILT <-- FILT + FF(NEW - FILT)
-
-    uint8_t current_value = 0;
-    if (self.fcd_filt < 0)
-      current_value = 1;
-
-    if (current_value != self.last_bit) {
-
-      self.last_bit = current_value;
-
-      // Ignore any noise
-      if (self.same_count >= 3) {
-
-        // Calculate how many bit lengths there are to the transition
-        // Integer rounding
-        uint8_t new_bits = (self.count_last + 1 + (self.bitwidth / 2)) / self.bitwidth;
-
-        // If we are not bit stuffing Add a 0
-        if (!self.bit_stuffing)
-          char_ring_buffer_put(&self.bit_sequence, 0);
-
-        // If we where bit stuffing stop now
-        self.bit_stuffing = false;
-
-        // Decrement new_bits
-        new_bits--;
-
-        // If new_bits > 5 we just found a preamble
-        if (new_bits > 5) {
-
-          // Preamble related things
-
-          uint16_t len = self.byte_seq_len;
-          if (len >= 17) {
-
-            new_data[0] = len;
-            memcpy(new_data + 1, &self.byte_sequence, len);
-
-          }
-
-          self.byte_seq_len = 0;
-          char_ring_buffer_clear(&self.bit_sequence);
-
-          // Set bit stuffing true so last bit of preamble will be removed
-          self.bit_stuffing = true;
-
-        }
-
-        // If its not a preamble
-        else {
-
-          // If new_bits == 5 bit stuffing is occurring
-          if (new_bits == 5)
-            self.bit_stuffing = true;
-
-          // Add the rest of the bits as 1's
-          for (i = 0; i < new_bits; i++)
-            char_ring_buffer_put(&self.bit_sequence, 1);
-
-        }
-
-        // Add bits to the sequence
-        uint8_t avail = char_ring_buffer_avail(&self.bit_sequence);
-        if (avail >= 8) {
-
-          int8_t dat = 0;
-          for (i = 7; i >= 0; i--) {
-            dat <<= 1;
-            if (char_ring_buffer_get(&self.bit_sequence, i)) dat |= 1;
-          }
-
-          char_ring_buffer_remove(&self.bit_sequence, 8);
-          self.byte_sequence[self.byte_seq_len++] = dat;
-          if (self.byte_seq_len >= MAX_BYTES) {
-            // Packet Overized!
-            AFSK_Demodulator_reset();
-          }
-
-        }
-
-        self.count_last = 0;
-
-      }
-
-      self.same_count = 0;
-
-    } else {
-
-      self.count_last++;
-      self.same_count++;
-
-    }
-
-  }
-
-}
-
-void AFSK_Demodulator_set_offset(const decimal offset) {
-  self.offset = offset;
-}
-
-

--- a/src/RFDuino_TNC/AFSK_Demodulator.h
+++ /dev/null
@@ -1,174 +1,1 @@
-/**
- * @file	AFSK_Demodulator.h
- * @author	Michael Marques <dryerzinia@gmail.com>
- * @brief	Demodulator for AFSK modulated AX.25 Frames.
- * @ingroup Packet
- *
- * This file contains a struct AFSK_Demodulator for holding all the data
- * necessary for the AFSK_Demodulator process byte function which takes in 8
- * bit signed samples from an audio signal.
- */
 
-#ifndef AFSK_DEMODULATOR_H
-#define AFSK_DEMODULATOR_H
-
-// malloc, free, int types, boolean's
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-// memcpy for generating packet data to return
-#include <string.h>
-
-#include <ctype.h>
-
-#include <math.h>
-
-#include "decimal.h"
-
-#include "char_ring_buffer.h"
-#include "decimal_ring_buffer.h"
-
-#ifndef PI
-#define PI 3.14159265359
-#endif
-
-#define MAX_BYTES 255
-#define SAMPLE_RATE 11025
-
-/**
- * @ingroup Packet
- * Contains all information necessary to demodulate AFSK modulated AX-25 frames
- */
-typedef struct {
-
-  /**
-   * Bit rate of the encoded digital information in the audio signal
-   * Do not adjust this value directly, instead call the appropriate
-   * functions on the decoder as other variables require re-calibration
-   * when these change
-   */
-  uint16_t bit_rate;
-
-  /**
-   * Width of the window of samples to run Goertzels algorithm on and to
-   * average Fourier coefficients across
-   */
-  uint8_t window;
-
-  /**
-   * Width of a bit calculated from Sample Rate and Bit Rate
-   * TODO: call reset in the functions that set Sample Rate and Bit Rate
-   */
-  uint8_t bitwidth;
-
-  /**
-   * Buffer to hold incoming data until there is enough to fill the window
-   * and calculate Fourier Coefficients
-   */
-  decimal_ring_buffer input_buffer;
-
-  /**
-   * Buffer of Fourier Coefficients so we can average them and smooth out
-   * the signal for extracting bits from Zero-Crossings
-   */
-  decimal fcd_filt;
-
-  /**
-   * Goertzel Coefficient for calculating magnitude of frequency 0
-   */
-  decimal coeff0;
-  /**
-   * Goertzel Coefficient for calculating magnitude of frequency 1
-   */
-  decimal coeff1;
-
-  decimal offset;
-
-  /**
-   * Frequency of the 1st AFSK Symbol
-   * Standard VHF packet is 1200/2200 Hz
-   * Standard HF packet is
-   *  PK232 tones 1600/1800 Hz
-   *  KAM tones 2110/2310 Hz
-   */
-  uint16_t frequency_0;
-  /**
-   * Frequency of the 2nd AFSK Symbol
-   */
-  uint16_t frequency_1;
-
-  uint16_t same_count;
-
-  /**
-   * Count of samples since last Zero-Crossing
-   */
-  uint16_t count_last;
-
-  /**
-   * A 14 character ring buffer for Bit Data
-   * Stores currently demodulated bits after Bit Stuffing removal and
-   * NRZI decoding
-   * The highest number of bits that should be collected before they are
-   * pushed to the byte array is 12, 8 for a byte + 6 from bit stuffing
-   */
-  char_ring_buffer bit_sequence;
-
-  /**
-   * Value of the last bit to be decoded
-   * used to check if there has been a Zero-Crossing
-   */
-  uint8_t last_bit;
-
-  /**
-   * Indicator if bit stuffing is occurring
-   * TODO: same as above
-   */
-  bool bit_stuffing;
-
-  /**
-   * Expandable array containing the sequence of bytes in the received packet
-   * It has a default size of 330 to contain a standard APRS packet without
-   * any reallocations
-   */
-  uint16_t byte_seq_len;
-  char byte_sequence[MAX_BYTES];
-
-} AFSK_Demodulator;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @ingroup Packet
- * Set up the demodulator with parameters for the type of signal to receive
- */
-void AFSK_Demodulator_init(uint16_t frequency_0, uint16_t frequency_1, uint16_t bit_rate, decimal offset);
-
-/**
- * @ingroup Packet
- * Pass another byte of signal data to the demodulator
- * @returns a pointer to a char array containing a demodulated packet
- *  if this byte did not complete demodulation of a packet it returns a
- *  NULL pointer instead
- */
-void AFSK_Demodulator_proccess_byte(int8_t data_point, uint8_t * new_data);
-
-/**
- * @ingroup Packet
- * Adjust the bit rate of the incoming data
- * This function resets the window width so these parameters cannot be
- * adjusted directly
- */
-void AFSK_Demodulator_set_bit_rate(uint16_t br);
-
-void AFSK_Demodulator_set_offset(decimal offset);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-

--- a/src/RFDuino_TNC/AFSK_Modulator.c
+++ /dev/null
@@ -1,136 +1,1 @@
 
-#include "AFSK_Modulator.h"
-
-#define PREAMBLE_START_STAGE 0
-#define DATA_STAGE 1
-#define PREAMBLE_END_STAGE 2
-#define PACKET_SENT_STAGE 3
-
-
-static AFSK_Modulator self;
-
-void AFSK_Modulator_init(uint8_t * data, const uint8_t len, const uint16_t bit_rate, const uint16_t frequency_0, const uint16_t frequency_1, const uint8_t start_preambles, const uint8_t end_preambles){
-
-  self.stage = 0;
-
-  self.start_preambles = start_preambles;
-  self.end_preambles = end_preambles;
-
-  self.bit_rate = bit_rate;
-
-  self.frequency_0 = frequency_0;
-  self.frequency_1 = frequency_1;
-
-  self.current_frequency = frequency_0;
-
-  self.len = len;
-  memcpy(self.data, data, len);
-
-  self.same_count = 0;
-  self.last_bit = 0;
-  self.sample_counter = 0;
-
-}
-
-static inline void AFSK_Modulator_advance_stage(){
-
-  self.last_bit = 0;
-  self.sample_counter = 0;
-  self.stage++;
-
-}
-
-static inline void AFSK_Modulator_change_frequency(){
-
-  if(self.current_frequency == self.frequency_0)
-    self.current_frequency = self.frequency_1;
-
-  else
-    self.current_frequency = self.frequency_0;
-
-}
-
-static int8_t AFSK_Modulator_next(const uint16_t freq){
-
-  self.phi += 256 * freq / MODULATOR_SAMPLE_RATE;
-  self.sample_counter++;
-
-  return sin_table[self.phi];
-
-}
-
-static int8_t AFSK_Modulator_get_preamble(const uint8_t num_preambles){
-
-  uint16_t current_bit = self.sample_counter * self.bit_rate / MODULATOR_SAMPLE_RATE;
-
-  if(current_bit != self.last_bit){
-
-    if(current_bit % 8 <= 1)
-      AFSK_Modulator_change_frequency();
-
-    if(current_bit >= num_preambles * 8 + 1){
-      AFSK_Modulator_change_frequency();
-      AFSK_Modulator_advance_stage();
-    }
-
-    self.last_bit = current_bit;
-
-  }
-
-  return AFSK_Modulator_next(self.current_frequency);
-
-}
-
-static int8_t AFSK_Modulator_get_data(){
-
-  uint16_t current_bit = self.sample_counter * self.bit_rate / MODULATOR_SAMPLE_RATE;
-
-  if(current_bit != self.last_bit){
-
-     // Bit stuffing
-    if(self.same_count == 5){
-
-      self.same_count = 0;
-      self.sample_counter -= MODULATOR_SAMPLE_RATE / self.bit_rate;
-      AFSK_Modulator_change_frequency();
-
-    } else {
-
-      // Change frequencies to indicate 0 bit
-      if((self.data[current_bit / 8] & (1 << (current_bit % 8))) == 0)
-        AFSK_Modulator_change_frequency();
- 
-      if(current_bit >= self.len * 8)
-        AFSK_Modulator_advance_stage();
-
-      self.last_bit = current_bit;
-
-    }
-
-    if((self.data[current_bit / 8] & (1 << (current_bit % 8))) != 0)
-      self.same_count++;
-    else
-      self.same_count = 0;
-
-  }
-
-  return AFSK_Modulator_next(self.current_frequency);
-
-}
-
-int16_t AFSK_Modulator_next_sample(){
-
-  switch(self.stage){
-    case PREAMBLE_START_STAGE:
-      return AFSK_Modulator_get_preamble(self.start_preambles);
-    case DATA_STAGE:
-      return AFSK_Modulator_get_data();
-    case PREAMBLE_END_STAGE:
-      return AFSK_Modulator_get_preamble(self.end_preambles);
-    case PACKET_SENT_STAGE:
-      return AFSK_MODULATOR_PACKET_FINISHED; // Indicates packet is finished
-  }
-
-  return 0x101; // ERROR: This should never happen
-}
-

--- a/src/RFDuino_TNC/AFSK_Modulator.h
+++ /dev/null
@@ -1,52 +1,1 @@
 
-#ifndef AFSK_MODULATOR_H
-#define AFSK_MODULATOR_H
-
-#include <stdint.h>
-#include <string.h>
-
-#include "sin_table.h"
-
-#define AFSK_MODULATOR_PACKET_FINISHED 0x100
-
-#define MODULATOR_SAMPLE_RATE 11025
-#define MAX_BYTES 255
-
-typedef struct {
-
-  uint8_t stage;
-
-  uint8_t len;
-  uint8_t data[MAX_BYTES];
-
-  uint8_t start_preambles;
-  uint8_t end_preambles;
-
-  uint16_t bit_rate;
-
-  uint16_t frequency_0;
-  uint16_t frequency_1;
-
-  uint16_t current_frequency;
-
-  uint8_t same_count;
-  uint16_t last_bit;
-  uint32_t sample_counter;
-  uint8_t phi;
-
-} AFSK_Modulator;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void AFSK_Modulator_init(uint8_t * data, uint8_t len, uint16_t bit_rate, uint16_t frequency_0, uint16_t frequency_1, uint8_t start_preambles, uint8_t end_preambles);
-
-int16_t AFSK_Modulator_next_sample();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-

--- a/src/RFDuino_TNC/RFDuino_TNC.ino
+++ /dev/null
@@ -1,440 +1,1 @@
-/* RFDuino_BLE_AFSK_TNC
- * Interfaces with a PIC controler to get Analog samples from the
- * audio output of a radio and demodulates the audio sending the
- * recivied packets over Bluetooth LE to connected devices
- * @author Michael Marques <dryerzinia@gmail.com>
- */
 
-#include <RFduinoBLE.h>
-#include <stdint.h>
-
-#include "AFSK_Demodulator.h"
-#include "AFSK_Modulator.h"
-#include "crcccitt.h"
-
-#define SCK   4
-#define MOSI  5
-#define MISO  3
-
-#define BLE_START_PACKET      0x01
-#define BLE_PACKET_CONTINUED  0x02
-#define BLE_INPUT_VOLUME      0x03
-#define BLE_BATTERY_VOLTAGE   0x04
-
-uint8_t spi_wait_flag = 1;
-
-#define RX_MODE 0
-#define TX_MODE 1
-
-#define RX_STAGE_1 0
-
-#define TX_STAGE_1 1
-#define TX_STAGE_2 2
-#define TX_STAGE_3 3
-#define TX_STAGE_4 4
-
-uint8_t mode = RX_MODE;
-uint8_t stage = RX_STAGE_1;
-
-// Store up to 4 255 byte packets at once
-#define NUM_PACKET_BUFFERS 4
-#define PACKET_BUF_LEN 256
-
-uint16_t start_packet_buffer = 0;
-uint16_t end_packet_buffer = 0;
-uint8_t packet_buffer[NUM_PACKET_BUFFERS][PACKET_BUF_LEN];
-
-uint8_t send_packet_buffer_length = 0;
-uint8_t send_packet_buffer_status = 0;
-uint8_t send_packet_buffer[PACKET_BUF_LEN];
-
-// Time
-volatile uint64_t given_time = 0;
-volatile uint64_t start_time = 0;
-
-// Peak Volume Detection
-#define SAMPLE_RATE 11025
-
-uint16_t max_volume_sample_count = 0;
-uint8_t max_volume = 0;
-
-// Battery Voltage
-#define BATTERY_MEASURE_PIN 2
-#define BATTERY_UPDATE_SEC 10
-uint8_t battery_update_count = 0;
-uint8_t battery_measure_status = 2;
-
-uint8_t battery_measurement;
-
-// BLE Message Status
-#define BLE_READY    0x00
-#define BLE_BUFFERED 0x01
-
-uint8_t ble_status = BLE_READY;
-
-// Packet send via bluetooth
-bool cnnected = false;
-uint8_t packet_data[20];
-uint8_t packet_data_len;
-uint8_t packet_progress = 0;
-
-void ADC_Setup(void) {
-
-  NRF_ADC->CONFIG =
-    (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) // Reference is 1.2V bandgap
-    | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) // scale input to 1/3
-    | ((1 << (BATTERY_MEASURE_PIN + 1)) << ADC_CONFIG_PSEL_Pos) // GPIO2 as Analog Input
-    | (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos) // 8 bit resolution
-    | (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos); // No External ADC Ref
-
-  NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; // Enable ADC
-
-}
-
-void SPI_Setup(void) {
-
-  // Disable peripheral's with same ID as SPI and SPI
-  NRF_SPI0->ENABLE = 0;
-
-  // All SPIS pins should be configured as inputs
-  pinMode(SCK, OUTPUT);
-  pinMode(MOSI, OUTPUT);
-  pinMode(MISO, INPUT);
-
-  NRF_SPI0->PSELMOSI = MOSI;
-  NRF_SPI0->PSELMISO = MISO;
-  NRF_SPI0->PSELSCK  = SCK;
-
-  NRF_SPI0->FREQUENCY = (SPI_FREQUENCY_FREQUENCY_M2 << SPI_FREQUENCY_FREQUENCY_Pos);
-
-  NRF_SPI0->CONFIG =
-    (
-      (SPI_CONFIG_CPOL_ActiveHigh << SPIS_CONFIG_CPOL_Pos) |
-      (SPI_CONFIG_CPHA_Trailing << SPIS_CONFIG_CPHA_Pos) |
-      (SPI_CONFIG_ORDER_MsbFirst << SPIS_CONFIG_ORDER_Pos)
-    );
-
-  NRF_SPI0->EVENTS_READY = 0;
-
-  NRF_SPI0->ENABLE = SPI_ENABLE_ENABLE_Enabled;
-
-}
-
-void setup() {
-
-  RFduinoBLE.deviceName = "BLE TNC";
-  //RFduinoBLE.advertisementData = ""; // use for serial number
-  RFduinoBLE.advertisementInterval = MILLISECONDS(1000);
-  //RFduinoBLE.txPowerLevel = -20; // Find good middle ground -20dbM to +4 dbM
-
-  RFduinoBLE.begin();
-
-  AFSK_Demodulator_init(1200, 2200, 1200, d_from_float(0.0));
-
-  SPI_Setup();
-  ADC_Setup();
-  pinMode(BATTERY_MEASURE_PIN, INPUT);
-  pinMode(6, OUTPUT);
-
-}
-
-void RFduinoBLE_onConnect() {
-
-  cnnected = true;
-
-}
-
-void RFduinoBLE_onDisconnect() {
-
-  cnnected = false;
-
-}
-
-void RFduinoBLE_onReceive(char *data, int len) {
-
-  // Messages types:
-  // 0x01 Change Decoder Parameters
-  // 0x02 Send message from radio (Message Length + Data)
-  // 0x03 Send message from radio (Message Data)
-  // 0x04 Go to sleep
-  // 0x05 Radio tuning if possible
-  // 0x06 Adjust TX volume
-  // 0x07 Set Time
-  switch (data[0]) {
-    case 0x01:
-      break;
-    case 0x02:
-      // Set up sending message move
-      // prepare to recieve packet data
-      send_packet_buffer_length = data[1];
-      send_packet_buffer_status = len - 2;
-      for (uint8_t i = 0; i < len - 2; i++) {
-        send_packet_buffer[i] = data[i + 2];
-      }
-      break;
-    case 0x03:
-      // Get data
-      for (uint8_t i = 0; i < len - 1; i++) {
-        send_packet_buffer[send_packet_buffer_status + i] = data[i + 1];
-      }
-      send_packet_buffer_status += len - 1;
-      if (send_packet_buffer_status >= send_packet_buffer_length) {
-        mode = TX_MODE; // Switch to TX Mode
-        AFSK_Modulator_init(send_packet_buffer, send_packet_buffer_length, 1200, 1200, 2200, 120, 60); // Prepare Modulator
-        stage = TX_STAGE_1; // Set tx stage 1
-      }
-      break;
-    case 0x04:
-      break;
-    case 0x07:
-      given_time = (data[0] << 48) + (data[1] << 32) + (data[2] << 16) + data[3];
-      start_time = millis();
-      break;
-  }
-
-}
-
-void loop() {
-
-  // Start SPI request for ADC Sample
-  if (spi_wait_flag) {
-
-    // SPI Output Codes
-    // RX Mode
-    // 0X7E Get ADC Sample
-    // 0x7F Switch to TX Mode
-    // TX Mode
-    // 0x7F Final sample switch back to RX Mode
-
-    if (mode == RX_MODE) {
-
-      NRF_SPI0->TXD = 'B'; // get next ADC sample
-
-    } else if (mode == TX_MODE) {
-
-      // if starting send 0x7E to switch to DAC mode
-      if (stage == TX_STAGE_1) {
-        NRF_SPI0->TXD = 0x7E;
-        stage = TX_STAGE_2;
-      }
-      // else send next tx byte from modulator
-      else if (stage == TX_STAGE_2) {
-
-        uint16_t sample = AFSK_Modulator_next_sample();
-
-        // if modulator 0x100 recived finished sending wait for tx buffer to empty
-        if (sample == AFSK_MODULATOR_PACKET_FINISHED) {
-          NRF_SPI0->TXD = 0x7E; // NULL data character
-          stage = TX_STAGE_3;
-
-        } else {
-
-          // Don't send 0x7F or 0x7E those are special codes
-          if (sample == 0x7F || sample == 0x7E)
-            NRF_SPI0->TXD = 0x7D;
-          else
-            NRF_SPI0->TXD = (uint8_t)(sample & 0xFF);
-
-        }
-      }
-      else if (stage == TX_STAGE_3) {
-
-        NRF_SPI0->TXD = 0x7E; // Send 7E because we have no further data for buffer
-
-      } else if (stage == TX_STAGE_4) {
-
-        mode = RX_MODE;
-        stage = RX_STAGE_1;
-        NRF_SPI0->TXD = 0x7F; // Switch back to ADC mode
-
-      }
-
-    }
-
-    spi_wait_flag = 0;
-
-  }
-
-  if (NRF_SPI0->EVENTS_READY != 0) {
-
-    spi_wait_flag = 1;
-    NRF_SPI0->EVENTS_READY = 0;
-    uint8_t data = NRF_SPI0->RXD;
-
-    // Special codes
-    // RX Mode
-    // 0x7F Buffer Empty or Radio Squelched sleep 1 ms
-    // TX Mode
-    // 0x7F Buffer Full sleep 1 ms
-    // 0x7E TX Finished
-
-    if (mode == RX_MODE) {
-
-      if (data == 0x7F) {
-
-        // Ignore sample buffer is empty or radio is squelched
-        // Sleep for 1ms while buffer refills
-        RFduino_ULPDelay(1);
-
-      } else {
-
-        // Get maximum volume
-        max_volume_sample_count++;
-        if (data < 0x7F && data > max_volume) {
-          max_volume = data;
-        }
-
-        // Got ADC sample, proccess it
-        AFSK_Demodulator_proccess_byte((int8_t)data, packet_buffer[end_packet_buffer]);
-        if (packet_buffer[end_packet_buffer][0] != 0) {
-
-          uint16_t fsc = CRCCCITT(packet_buffer[end_packet_buffer] + 1, packet_buffer[end_packet_buffer][0] - 2, 0x8408);
-
-          // CRC is added to packet with bytes reversed
-          uint16_t fsc2 = packet_buffer[end_packet_buffer][packet_buffer[end_packet_buffer][0]];
-          fsc2 <<= 8;
-          fsc2 |= packet_buffer[end_packet_buffer][packet_buffer[end_packet_buffer][0] - 1] & 0xFF;
-
-          if (fsc == fsc2) {
-
-            end_packet_buffer++;
-            if (end_packet_buffer == NUM_PACKET_BUFFERS)
-              end_packet_buffer = 0;
-
-          } else {
-
-            // CRC failed mark in packet buffer as empty
-            packet_buffer[end_packet_buffer][0] = 0;
-
-          }
-
-        }
-      }
-
-    } else if (mode == TX_MODE) {
-
-      // Buffer ok keep sending
-      if (data == 0x7E) {
-
-      } else if (data == 0x7F) {
-        // Buffer full delay atleast 1 sample time before sending more data
-        RFduino_ULPDelay(1);
-      } else if (data == 0x7D && stage == TX_STAGE_3) {
-        // Buffer empty and stage 3 switch to stage 4
-        stage = TX_STAGE_4;
-      }
-
-    }
-  }
-  // Handle sending any decoded packets via BLE
-  if (cnnected) {
-
-    if (ble_status == BLE_BUFFERED) {
-      boolean stat = RFduinoBLE.send((const char *)(packet_data), packet_data_len);
-      if (stat == 1)
-        ble_status = BLE_READY;
-    }
-
-    if (battery_measure_status == 0) {
-
-      if ((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) != (ADC_BUSY_BUSY_Busy << ADC_BUSY_BUSY_Pos)) {
-
-        battery_measure_status = 1;
-        battery_measurement = NRF_ADC->RESULT & 0xFF;
-
-      }
-
-    }
-
-    if (ble_status == BLE_READY) {
-
-      // Send battery status 1/10 Hz
-      if (battery_measure_status == 1) {
-
-        packet_data[0] = BLE_BATTERY_VOLTAGE;
-        packet_data[1] = battery_measurement;
-
-        packet_data_len = 2;
-
-        ble_status = BLE_BUFFERED;
-
-        battery_measure_status = 2;
-
-      }
-      // Send input volume 1 Hz
-      else if (max_volume_sample_count >= SAMPLE_RATE) {
-
-        packet_data[0] = BLE_INPUT_VOLUME;
-        packet_data[1] = max_volume;
-
-        packet_data_len = 2;
-
-        max_volume = 0;
-        max_volume_sample_count = 0;
-
-        ble_status = BLE_BUFFERED;
-
-        battery_update_count++;
-        if (battery_update_count >= BATTERY_UPDATE_SEC) {
-          battery_update_count = 0;
-          battery_measure_status = 0;
-          NRF_ADC->TASKS_START = 1; // Start Battery Measurment Conversion
-        }
-
-      } else if (packet_buffer[start_packet_buffer][0] != 0) {
-
-        uint8_t fill_start;
-
-        if (!packet_progress) {
-
-          // 0x01 Start Send packet
-          // 2nd byte length
-          // remaining 18 bytes data
-          // Send the packet length
-          packet_data[0] = BLE_START_PACKET;
-          packet_data[1] = packet_buffer[start_packet_buffer][0];
-
-          fill_start = 2;
-
-        } else {
-
-          // 0x02 packet data continuted
-          packet_data[0] = BLE_PACKET_CONTINUED;
-
-          fill_start = 1;
-
-        }
-
-        uint8_t len = packet_buffer[start_packet_buffer][0] - packet_progress;
-        if (len > 20 - fill_start)
-          len = 20 - fill_start;
-
-        uint8_t i;
-        for (i = 0; i < len; i++) {
-          packet_data[i + fill_start] = packet_buffer[start_packet_buffer][packet_progress + i + 1];
-        }
-
-        ble_status = BLE_BUFFERED;
-        packet_data_len = len + fill_start;
-
-        packet_progress += len;
-
-        if (packet_progress >= packet_buffer[start_packet_buffer][0]) {
-
-          packet_progress = 0;
-          packet_buffer[start_packet_buffer][0] = 0;
-
-          start_packet_buffer++;
-
-          if (start_packet_buffer == NUM_PACKET_BUFFERS)
-            start_packet_buffer = 0;
-
-
-        }
-
-      }
-    }
-  }
-}
-
-

--- a/src/RFDuino_TNC/char_ring_buffer.h
+++ /dev/null
@@ -1,89 +1,1 @@
-// char_ring_buffer.h
 
-#ifndef CHAR_RING_BUFFER_H
-#define CHAR_RING_BUFFER_H
-
-#include <stdlib.h>
-
-typedef struct {
-
-  signed char *data;
-
-  unsigned short read_position;
-  unsigned short write_position;
-
-  unsigned short size;
-
-} char_ring_buffer;
-
-static inline void char_ring_buffer_init(char_ring_buffer *self, unsigned short capacity) {
-
-  self->size = capacity;
-  self->data = (signed char*) malloc(sizeof(char) * capacity);
-
-  self->read_position = 0;
-  self->write_position = 0;
-
-}
-
-static inline void char_ring_buffer_put(char_ring_buffer *self, signed char c) {
-
-  self->data[self->write_position++] = c;
-
-  if (self->write_position >= self->size)
-    self->write_position = 0;
-
-}
-
-static inline signed char char_ring_buffer_get(char_ring_buffer *self, unsigned short index) {
-
-  unsigned short position = self->read_position + index;
-
-  if (position >= self->size)
-    position -= self->size;
-
-  return self->data[position];
-
-}
-
-static inline void char_ring_buffer_pop(char_ring_buffer *self) {
-
-  self->read_position++;
-  if (self->read_position >= self->size)
-    self->read_position = 0;
-
-}
-
-static inline void char_ring_buffer_remove(char_ring_buffer *self, unsigned short count) {
-
-  self->read_position += count;
-
-  if (self->read_position >= self->size)
-    self->read_position -= self->size;
-
-}
-
-static inline void char_ring_buffer_clear(char_ring_buffer *self) {
-
-  self->read_position = 0;
-  self->write_position = 0;
-
-}
-
-static inline unsigned short char_ring_buffer_avail(char_ring_buffer *self) {
-
-  if (self->read_position <= self->write_position)
-    return self->write_position - self->read_position;
-
-  return self->write_position + self->size - self->read_position;
-
-}
-
-static inline void char_ring_buffer_destory(char_ring_buffer *self) {
-
-  free(self->data);
-
-}
-
-#endif
-

--- a/src/RFDuino_TNC/crcccitt.c
+++ /dev/null
@@ -1,28 +1,1 @@
-// crcccitt.c
 
-#include "crcccitt.h"
-
-uint16_t CRCCCITT(const uint8_t *data, uint16_t len, const uint16_t polynomial) {
-
-  uint16_t crc = 0xFFFF;
-  uint8_t i;
-
-  while (len--) {
-
-    crc ^= *data++;
-
-    for (i = 0; i < 8; i++) {
-      if (crc & 0x0001)
-        crc = (crc >> 1) ^ polynomial;
-      else
-        crc >>= 1;
-    }
-
-  }
-
-  crc ^= 0xFFFF;
-
-  return crc;
-
-}
-

--- a/src/RFDuino_TNC/crcccitt.h
+++ /dev/null
@@ -1,19 +1,1 @@
-// crcccitt.h
 
-#ifndef CRCCCITT_H
-#define CRCCCITT_H
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-uint16_t CRCCCITT(const uint8_t *data, uint16_t len, const uint16_t polynomial);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-

--- a/src/RFDuino_TNC/decimal.h
+++ /dev/null
@@ -1,14 +1,1 @@
-#ifndef DECIMAL_H
-#define DECIMAL_H
 
-#include "fx32.h"
-typedef fx32 decimal;
-#define dmul(a, b) fx32_mul(a, b)
-#define dcmul(a, b) fx32_cmul(a, b)
-#define ddiv(a, b) fx32_div(a, b)
-#define d_from_int(a) fx32_from_int(a)
-#define d_from_float(a) fx32_from_float(a)
-#define d_to_int(a) fx32_to_int(a)
-
-#endif
-

--- a/src/RFDuino_TNC/decimal_ring_buffer.h
+++ /dev/null
@@ -1,91 +1,1 @@
-// decimal_ring_buffer.h
 
-#ifndef DECIMAL_RING_BUFFER_H
-#define DECIMAL_RING_BUFFER_H
-
-#include <stdlib.h>
-
-#include "decimal.h"
-
-typedef struct {
-
-  decimal *data;
-
-  unsigned short read_position;
-  unsigned short write_position;
-
-  unsigned short size;
-
-} decimal_ring_buffer;
-
-static inline void decimal_ring_buffer_init(decimal_ring_buffer *self, unsigned short capacity) {
-
-  self->size = capacity;
-  self->data = (decimal*) malloc(sizeof(decimal) * capacity);
-
-  self->read_position = 0;
-  self->write_position = 0;
-
-}
-
-static inline void decimal_ring_buffer_put(decimal_ring_buffer *self, decimal f) {
-
-  self->data[self->write_position++] = f;
-
-  if (self->write_position >= self->size)
-    self->write_position = 0;
-
-}
-
-static inline decimal decimal_ring_buffer_get(decimal_ring_buffer *self, unsigned short index) {
-
-  unsigned short position = self->read_position + index;
-
-  if (position >= self->size)
-    position -= self->size;
-
-  return self->data[position];
-
-}
-
-static inline void decimal_ring_buffer_pop(decimal_ring_buffer *self) {
-
-  self->read_position++;
-  if (self->read_position >= self->size)
-    self->read_position = 0;
-
-}
-
-static inline void decimal_ring_buffer_remove(decimal_ring_buffer *self, unsigned short count) {
-
-  self->read_position += count;
-
-  if (self->read_position >= self->size)
-    self->read_position -= self->size;
-
-}
-
-static inline void decimal_ring_buffer_clear(decimal_ring_buffer *self) {
-
-  self->read_position = 0;
-  self->write_position = 0;
-
-}
-
-static inline unsigned short decimal_ring_buffer_avail(decimal_ring_buffer *self) {
-
-  if (self->read_position < self->write_position)
-    return self->write_position - self->read_position;
-
-  return self->write_position + self->size - self->read_position;
-
-}
-
-static inline void decimal_ring_buffer_destory(decimal_ring_buffer *self) {
-
-  free(self->data);
-
-}
-
-#endif
-

file:a/src/RFDuino_TNC/fx32.h (deleted)
--- a/src/RFDuino_TNC/fx32.h
+++ /dev/null
@@ -1,24 +1,1 @@
 
-#include <stdint.h>
-
-typedef int32_t fx32;
-typedef	int64_t	fx32d;
-
-#ifndef FX32W
-#define FX32W 26
-#endif
-
-#define FX32F (32 - FX32W)
-
-#define fx32_one ((fx32)((fx32)1 << FX32F))
-
-#define fx32_from_float(r) ((fx32)(r * fx32_one + (r >= 0 ? 0.5 : -0.5)))
-#define fx32_from_int(i) ((fx32d)(i) << FX32F)
-#define fx32_to_int(f) ((f) >> FX32F)
-#define fx32_add(a, b) (a + b)
-#define fx32_sub(a, b) (a - b)
-#define fx32_mul(a, b) ((fx32)(((fx32d)(a) * (fx32d)(b)) >> FX32F))
-#define fx32_div(a, b) ((fx32)(((fx32d)(a) << FX32F) / (fx32d)(b)))
-
-#define fx32_cmul(a, b) ((fx32)((a * b) >> FX32F))
-

--- a/src/RFDuino_TNC/sin_table.c
+++ /dev/null
@@ -1,38 +1,1 @@
 
-#include "sin_table.h"
-
-const uint8_t sin_table[256] = {
-       0,    3,    6,    9,   12,   16,   19,   22,
-      25,   28,   31,   34,   37,   40,   43,   46,
-      49,   51,   54,   57,   60,   63,   65,   68,
-      71,   73,   76,   78,   81,   83,   85,   88,
-      90,   92,   94,   96,   98,  100,  102,  104,
-     106,  107,  109,  111,  112,  113,  115,  116,
-     117,  118,  120,  121,  122,  122,  123,  124,
-     125,  125,  126,  126,  126,  127,  127,  127,
-     127,  127,  127,  127,  126,  126,  126,  125,
-     125,  124,  123,  122,  122,  121,  120,  118,
-     117,  116,  115,  113,  112,  111,  109,  107,
-     106,  104,  102,  100,   98,   96,   94,   92,
-      90,   88,   85,   83,   81,   78,   76,   73,
-      71,   68,   65,   63,   60,   57,   54,   51,
-      49,   46,   43,   40,   37,   34,   31,   28,
-      25,   22,   19,   16,   12,    9,    6,    3,
-       0,   -3,   -6,   -9,  -12,  -16,  -19,  -22,
-     -25,  -28,  -31,  -34,  -37,  -40,  -43,  -46,
-     -49,  -51,  -54,  -57,  -60,  -63,  -65,  -68,
-     -71,  -73,  -76,  -78,  -81,  -83,  -85,  -88,
-     -90,  -92,  -94,  -96,  -98, -100, -102, -104,
-    -106, -107, -109, -111, -112, -113, -115, -116,
-    -117, -118, -120, -121, -122, -122, -123, -124,
-    -125, -125, -126, -126, -126, -127, -127, -127,
-    -127, -127, -127, -127, -126, -126, -126, -125,
-    -125, -124, -123, -122, -122, -121, -120, -118,
-    -117, -116, -115, -113, -112, -111, -109, -107,
-    -106, -104, -102, -100,  -98,  -96,  -94,  -92,
-     -90,  -88,  -85,  -83,  -81,  -78,  -76,  -73,
-     -71,  -68,  -65,  -63,  -60,  -57,  -54,  -51,
-     -49,  -46,  -43,  -40,  -37,  -34,  -31,  -28,
-     -25,  -22,  -19,  -16,  -12,   -9,   -6,   -3
-};
-

--- a/src/RFDuino_TNC/sin_table.h
+++ /dev/null
@@ -1,17 +1,1 @@
-#ifndef SIN_TABLE_H
-#define SIN_TABLE_H
 
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const uint8_t sin_table[256];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-