update Morse

This commit is contained in:
Morgan Redfield 2019-06-01 15:25:56 -07:00
parent 7e509ca0fc
commit 6472b103b4
2 changed files with 61 additions and 22 deletions

View File

@ -10,6 +10,18 @@
* monitor the status of the beacon. To test, set a HandyTalkie
* to 438MHz. You should hear the message " CALLSIGN HAMSHIELD"
* in morse code.
*
*
* Note: only upper case letters, numbers, and a few symbols
* are supported.
* Supported symbols: &/+(=:?";@`-._),!$
*
* If you're having trouble accurately decoding, you may want to
* tweak the min/max . and - times. You can also uncomment
* the Serial.print debug statements that can tell you when tones
* are being detected, how long they're detected for, and whether
* the tones are decoded as a . or -.
*
*/
#define DDS_REFCLK_DEFAULT 9600
@ -28,10 +40,10 @@
#define CHAR_END_TIME (MORSE_DOT*2.7)
#define MESSAGE_END_TIME (MORSE_DOT*8)
#define MIN_DOT_TIME (MORSE_DOT*0.7)
#define MAX_DOT_TIME (MORSE_DOT*1.3)
#define MIN_DASH_TIME (MORSE_DOT*2.7)
#define MAX_DASH_TIME (MORSE_DOT*3.3)
#define MIN_DOT_TIME (MORSE_DOT-30)
#define MAX_DOT_TIME (MORSE_DOT+55)
#define MIN_DASH_TIME (MORSE_DOT*3-30)
#define MAX_DASH_TIME (MORSE_DOT*3+55)
HamShield radio;
@ -83,7 +95,7 @@ void setup() {
radio.lookForTone(MORSE_FREQ);
// Configure the HamShield to operate on 438.000MHz
radio.frequency((uint32_t) 438000);
radio.frequency(432000);
radio.setModeReceive();
Serial.println("Radio Configured.");
@ -95,7 +107,6 @@ void setup() {
rx_morse_bit = 1;
bits_to_process = false;
radio.bypassPreDeEmph();
}
void loop() {
@ -119,6 +130,7 @@ void loop() {
// end the last tone
uint16_t tone_time = millis() - tone_in_progress;
tone_in_progress = 0;
//Serial.println(tone_time);
handleTone(tone_time);
}
}
@ -151,9 +163,11 @@ void loop() {
// We'll wait up to 30 seconds for a clear channel, requiring that the channel is clear for 2 seconds before we transmit
if (radio.waitForChannel(30000,2000,-5)) {
// If we get here, the channel is clear.
Serial.println("sending");
// Start transmitting by putting the radio into transmit mode.
radio.setModeTransmit();
Serial.println("tx");
unsigned int MORSE_BUF_SIZE = 128;
char morse_buf[MORSE_BUF_SIZE];
unsigned int morse_idx;

View File

@ -1070,29 +1070,40 @@ void HamShield::setDTMFCode(uint16_t code){
void HamShield::HStone(uint8_t pin, unsigned int frequency) {
HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf);
old_dtmf_reg = radio_i2c_buf[0];
// store old dtmf reg for noTone
// HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf);
// old_dtmf_reg = radio_i2c_buf[0];
// set frequency
HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10);
// set 0x79 dtmf control
HSwriteBitsW(devAddr, 0x79, 15, 2, 0x3); // transmit single tone (not dtmf)
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 2, 0x2); // transmit single tone (not dtmf)
// HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 2, 0x2); // transmit single tone (not dtmf)
// bypass pre/de-emphasis
HSwriteBitsW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10);
setTxSourceTone1();
// set source for tx
setTxSourceTone1(); // writes to 3A
//tone(pin, frequency);
}
void HamShield::HSnoTone(uint8_t pin) {
HSwriteWord(devAddr, A1846S_DTMF_ENABLE_REG, old_dtmf_reg); // disable tone and dtmf
setTxSourceMic();
//HSwriteWord(devAddr, A1846S_DTMF_ENABLE_REG, old_dtmf_reg); // disable tone and dtmf
// noTone(pin);
}
// Tone detection
void HamShield::lookForTone(uint16_t t_hz) {
float tone_hz = (float) t_hz;
// set 0x79 dtmf control
HSwriteBitsW(devAddr, 0x79, 15, 2, 0x3); // transmit single tone (not dtmf)
// bypass pre/de-emphasis
HSwriteBitsW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
float tone_hz = (float) t_hz;
float Fs = 6400000/1024;
float k = floor(tone_hz/Fs*127 + 0.5);
uint16_t t = (uint16_t) (round(2.0*cos(2.0*M_PI*k/127)*1024));
@ -1100,24 +1111,38 @@ void HamShield::lookForTone(uint16_t t_hz) {
float k2 = floor(2*tone_hz/Fs*127+0.5);
uint16_t h = (uint16_t) (round(2.0*cos(2.0*M_PI*k2/127)*1024));
// set tone
HSwriteWord(devAddr, 0x68, t);
HSwriteWord(devAddr, 0x67, t); // looking for tone 1
// set second harmonic
HSwriteWord(devAddr, 0x70, h);
HSwriteWord(devAddr, 0x6F, h); // looking for tone
// turn on tone detect
HSwriteBitW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_TONE_DETECT, 1);
HSwriteBitW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 1);
}
bool redetect = false;
uint8_t last_tone_detected = 0;
uint8_t HamShield::toneDetected() {
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_SAMPLE_BIT, 1, radio_i2c_buf);
if (radio_i2c_buf[0] != 0) {
if (!redetect) {
redetect = true;
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LEN, radio_i2c_buf);
if (radio_i2c_buf[0] == 1) {
return 1;
}
}
last_tone_detected = radio_i2c_buf[0];
//Serial.print("t: ");
//Serial.println(last_tone_detected);
}
if (last_tone_detected == 0) {
return 1;
}
} else if (redetect) {
// re-enable detect
redetect = false;
HSwriteBitW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_TONE_DETECT, 1);
HSwriteBitW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 1);
}
return 0;
}
@ -1656,7 +1681,7 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
}
//tone(hs_mic_pin, 6000, morse_dot_millis);
HSnoTone(hs_mic_pin);
HSdelay(morse_dot_millis); // delay between elements
HSdelay(morse_dot_millis);
bits >>= 1; // Shift into the next symbol
} while(bits != 1); // Wait for 1 termination to be all we have left
}