From 6538ae7db3e2ea07141f66ae35aba06427cc5053 Mon Sep 17 00:00:00 2001 From: spaceneedle Date: Mon, 8 May 2017 19:21:18 -0500 Subject: [PATCH] Long awaited fix to CTCSS detection and encoding Two extremely powerful functions: setCtcssEncoder(float freq) setCtcssDecoder(float freq) Yes, that does mean *any* frequency, including non-standard CTCSS tones. Enjoy. -Casey --- src/HamShield.cpp | 35 ++++++++++++++++++++++++++++++++--- src/HamShield.h | 11 ++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 2de61bc..2d72c48 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -1,4 +1,4 @@ -// HamShield library collection +// HamShield library collection // Based on Programming Manual rev. 2.0, 5/19/2011 (RM-MPU-6000A-00) // 11/22/2013 by Morgan Redfield // 04/26/2015 various changes Casey Halverson @@ -105,11 +105,11 @@ const uint16_t asciiMorseProgmem[] PROGMEM = { }; #endif // MORSE_TABLE_PROGMEM -/* 2200 Hz */ +/* 2200 Hz -- This lookup table should be deprecated */ const unsigned char AFSK_mark[] PROGMEM = { 154, 249, 91, 11, 205, 216, 25, 68, 251, 146, 0, 147, 250, 68, 24, 218, 203, 13, 88, 254, 128, 1, 167, 242, 52, 37, 231, 186, 5, 108, 255, 108, 5, 186, 231, 37, 52, 242, 167, 1, 128, 254, 88, 13, 203, 218, 24, 69, 250, 147, 0, 147, 250, 69, 24, 218, 203, 13, 88, 255, 127, 2, 165, 245, 48 }; -/* 1200 Hz */ +/* 1200 Hz -- This lookup table should be deprecated */ const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, 249, 230, 128, 24, 7, 88, 203, 255, 203, 88, 7, 24, 128, 230, 249, 167, 53, 0, 53, 167, 249, 230, 128, 24, 6, 88, 202, 255, 202, 88, 6, 24, 127, 231, 249, 167, 52, 0, 52, 167, 248, 231, 127, 25, 6, 89, 202, 255, 202, 89, 6, 25, 127, 231, 248, 167, 53, 0, 54, 165, 251, 227, 133, 14}; @@ -672,6 +672,35 @@ uint16_t HamShield::getPABiasVoltage(){ } */ // Subaudio settings + + +// recommended function for placing CTCSS tone on channel -- schedule remainder for deprecation + + +// ctcss freq encoder +void HamShield::setCtcssEncoder(float freq) { + int dfreq = freq * 100; // Convert float into whole number (ctcss freq * 100) + setCtcssFreq(dfreq); // program CTCSS frequency buffer + HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 10, 1); // program CTCSS frequency buffer into CTCSS encoder (step 1) + HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 9, 1); // program CTCSS frequency buffer into CTCSS encoder (step 2) +} + +// recommended function for detecting (and requiring) CTCSS to be on channel before audio is unmuted -- schedule remainder for deprecation + +// ctcss freq decoder +void HamShield::setCtcssDecoder(float freq) { + int dfreq = freq * 100; // Convert float into whole number (ctcss freq * 100) + setCtcssFreq(dfreq); // program CTCSS frequency buffer + HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 10, 1); // program CTCSS frequency buffer into CTCSS encoder (step 1) + HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 9, 1); // program CTCSS frequency buffer into CTCSS encoder (step 2) +} + + + + + + + // TX and RX code /* Set code mode: diff --git a/src/HamShield.h b/src/HamShield.h index 5a5f7a0..8d25ac3 100644 --- a/src/HamShield.h +++ b/src/HamShield.h @@ -2,7 +2,7 @@ // Based on Programming Manual rev. 2.0, 5/19/2011 (RM-MPU-6000A-00) // 11/22/2013 by Morgan Redfield // 04/26/2015 various changes Casey Halverson - +// 05/08/2017 CTCSS code added #ifndef _HAMSHIELD_H_ @@ -311,6 +311,15 @@ class HamShield { // Subaudio settings + // Recommended user function for setting and receiving CTCSS does + // TODO: set others to private and/or deprecate + + void setCtcssEncoder(float freq); // generate sub audio tone on channel when transmitting + void setCtcssDecoder(float freq); // unmute audio on tone present when receiving channel + + + + // Ctcss/cdcss mode sel // x00=disable, // 001=inner ctcss en,