This commit is contained in:
morgan 2016-07-03 14:03:15 -07:00
commit 705884497a
6 changed files with 75 additions and 187 deletions

View File

@ -1290,10 +1290,13 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
if(buffer[i] == ' ') { if(buffer[i] == ' ') {
// We delay by 4 here, if we previously sent a symbol. Otherwise 7. // We delay by 4 here, if we previously sent a symbol. Otherwise 7.
// This could probably just be always 7 and go relatively unnoticed. // This could probably just be always 7 and go relatively unnoticed.
if(prev == 0 || prev == ' ') if(prev == 0 || prev == ' '){
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 7);
delay(HAMSHIELD_MORSE_DOT*7); delay(HAMSHIELD_MORSE_DOT*7);
else } else {
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 4);
delay(HAMSHIELD_MORSE_DOT*4); delay(HAMSHIELD_MORSE_DOT*4);
}
continue; continue;
} }
// Otherwise, lookup our character symbol // Otherwise, lookup our character symbol
@ -1301,17 +1304,19 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
if(bits) { // If it is a valid character... if(bits) { // If it is a valid character...
do { do {
if(bits & 1) { if(bits & 1) {
tone(HAMSHIELD_PWM_PIN, 1000, HAMSHIELD_MORSE_DOT * 3); tone(HAMSHIELD_PWM_PIN, 600, HAMSHIELD_MORSE_DOT * 3);
delay(HAMSHIELD_MORSE_DOT*3); delay(HAMSHIELD_MORSE_DOT*3);
} else { } else {
tone(HAMSHIELD_PWM_PIN, 1000, HAMSHIELD_MORSE_DOT); tone(HAMSHIELD_PWM_PIN, 600, HAMSHIELD_MORSE_DOT);
delay(HAMSHIELD_MORSE_DOT); delay(HAMSHIELD_MORSE_DOT);
} }
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT);
delay(HAMSHIELD_MORSE_DOT); delay(HAMSHIELD_MORSE_DOT);
bits >>= 1; // Shift into the next symbol bits >>= 1; // Shift into the next symbol
} while(bits != 1); // Wait for 1 termination to be all we have left } while(bits != 1); // Wait for 1 termination to be all we have left
} }
// End of character // End of character
tone(HAMSHIELD_PWM_PIN, 6000, HAMSHIELD_MORSE_DOT * 3);
delay(HAMSHIELD_MORSE_DOT * 3); delay(HAMSHIELD_MORSE_DOT * 3);
} }
return; return;

View File

@ -4,7 +4,6 @@
* *
*/ */
#define DDS_REFCLK_DEFAULT 9600 #define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h> #include <HamShield.h>
@ -14,7 +13,6 @@
#define RESET_PIN A3 #define RESET_PIN A3
#define SWITCH_PIN 2 #define SWITCH_PIN 2
HamShield radio; HamShield radio;
DDS dds; DDS dds;
String messagebuff = ""; String messagebuff = "";
@ -47,70 +45,61 @@ void setup() {
Serial.println("HELLO"); Serial.println("HELLO");
} }
String temp[1] = "";
void loop() { void loop() {
messagebuff = "KC7IBT,KC7IBT,:HAMSHIELD TEST"; messagebuff = "KC7IBT,KC7IBT,:HAMSHIELD TEST";
prepMessage(); prepMessage();
delay(10000); delay(10000);
} }
void prepMessage() { void prepMessage() {
radio.setModeTransmit(); radio.setModeTransmit();
delay(500); delay(500);
origin_call = messagebuff.substring(0,messagebuff.indexOf(',')); // get originating callsign origin_call = messagebuff.substring(0,messagebuff.indexOf(',')); // get originating callsign
destination_call = messagebuff.substring(messagebuff.indexOf(',')+1,messagebuff.indexOf(',',messagebuff.indexOf(',')+1)); // get the destination call destination_call = messagebuff.substring(messagebuff.indexOf(',')+1,messagebuff.indexOf(',',messagebuff.indexOf(',')+1)); // get the destination call
textmessage = messagebuff.substring(messagebuff.indexOf(":")+1); textmessage = messagebuff.substring(messagebuff.indexOf(":")+1);
Serial.print("From: "); Serial.print(origin_call); Serial.print(" To: "); Serial.println(destination_call); Serial.println("Text: "); Serial.println(textmessage); Serial.print("From: "); Serial.print(origin_call); Serial.print(" To: "); Serial.println(destination_call); Serial.println("Text: "); Serial.println(textmessage);
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32); AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
packet->start(); packet->start();
packet->appendCallsign(origin_call.c_str(),0); packet->appendCallsign(origin_call.c_str(),0);
packet->appendCallsign(destination_call.c_str(),15,true); packet->appendCallsign(destination_call.c_str(),15,true);
packet->appendFCS(0x03); packet->appendFCS(0x03);
packet->appendFCS(0xf0); packet->appendFCS(0xf0);
packet->print(textmessage); packet->print(textmessage);
packet->finish(); packet->finish();
bool ret = radio.afsk.putTXPacket(packet);
bool ret = radio.afsk.putTXPacket(packet); if(radio.afsk.txReady()) {
Serial.println(F("txReady"));
if(radio.afsk.txReady()) { radio.setModeTransmit();
Serial.println(F("txReady")); //delay(100);
radio.setModeTransmit(); if(radio.afsk.txStart()) {
//delay(100); Serial.println(F("txStart"));
if(radio.afsk.txStart()) { } else {
Serial.println(F("txStart")); radio.setModeReceive();
} else {
radio.setModeReceive();
}
} }
// Wait 2 seconds before we send our beacon again. }
Serial.println("tick"); // Wait 2 seconds before we send our beacon again.
// Wait up to 2.5 seconds to finish sending, and stop transmitter. Serial.println("tick");
// TODO: This is hackery. // Wait up to 2.5 seconds to finish sending, and stop transmitter.
for(int i = 0; i < 500; i++) { // TODO: This is hackery.
if(radio.afsk.encoder.isDone()) for(int i = 0; i < 500; i++) {
break; if(radio.afsk.encoder.isDone())
delay(50); break;
} delay(50);
Serial.println("Done sending"); }
delay(3000); Serial.println("Done sending");
radio.setModeReceive(); radio.setModeReceive();
} }
ISR(TIMER2_OVF_vect) { ISR(TIMER2_OVF_vect) {
TIFR2 = _BV(TOV2); TIFR2 = _BV(TOV2);
static uint8_t tcnt = 0; static uint8_t tcnt = 0;
if(++tcnt == 8) { if(++tcnt == 8) {
digitalWrite(2, HIGH); dds.clockTick();
dds.clockTick();
digitalWrite(2, LOW);
tcnt = 0; tcnt = 0;
} }
} }
@ -118,7 +107,6 @@ ISR(TIMER2_OVF_vect) {
ISR(ADC_vect) { ISR(ADC_vect) {
static uint8_t tcnt = 0; static uint8_t tcnt = 0;
TIFR1 = _BV(ICF1); // Clear the timer flag TIFR1 = _BV(ICF1); // Clear the timer flag
PORTD |= _BV(2); // Diagnostic pin (D2)
dds.clockTick(); dds.clockTick();
if(++tcnt == 1) { if(++tcnt == 1) {
if(radio.afsk.encoder.isSending()) { if(radio.afsk.encoder.isSending()) {
@ -126,7 +114,4 @@ ISR(ADC_vect) {
} }
tcnt = 0; tcnt = 0;
} }
PORTD &= ~(_BV(2)); // Pin D2 off again
} }

View File

@ -1,105 +0,0 @@
#include <HamShield.h>
HamShield radio;
DDS dds;
#define PWM_PIN 3
#define RESET_PIN A3
#define SWITCH_PIN 2
#define DON(p) PORTD |= _BV((p))
#define DOFF(p) PORTD &= ~(_BV((p)))
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
// NOTE: if not using PWM out, it should be held low to avoid tx noise
pinMode(PWM_PIN, OUTPUT);
digitalWrite(PWM_PIN, LOW);
// prep the switch
pinMode(SWITCH_PIN, INPUT_PULLUP);
// set up the reset control pin
pinMode(RESET_PIN, OUTPUT);
// turn on pwr to the radio
digitalWrite(RESET_PIN, HIGH);
Serial.println(F("Radio test connection"));
Serial.println(radio.testConnection(), DEC);
Serial.println(F("Initialize"));
delay(100);
radio.initialize();
Serial.println(F("Frequency"));
delay(100);
radio.frequency(145010);
//radio.setRfPower(0);
delay(100);
dds.start();
delay(100);
radio.afsk.start(&dds);
delay(100);
dds.setFrequency(0);
dds.on();
dds.setAmplitude(255);
I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0b0000011111111111);
//I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x53, 0x0);
//I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x32, 0xffff);
}
void loop() {
DON(6);
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
packet->start();
packet->appendCallsign("VE6SLP",0);
packet->appendCallsign("VA6GA",15,true);
packet->appendFCS(0x03);
packet->appendFCS(0xf0);
packet->print(F("Hello "));
packet->print(millis());
packet->println(F("\r\nThis is a test of the HamShield Kickstarter prototype. de VE6SLP"));
packet->finish();
bool ret = radio.afsk.putTXPacket(packet);
if(radio.afsk.txReady()) {
Serial.println(F("txReady"));
radio.setModeTransmit();
if(radio.afsk.txStart()) {
Serial.println(F("txStart"));
} else {
Serial.println(F("Tx Start failure"));
radio.setModeReceive();
}
}
// Wait 2 seconds before we send our beacon again.
Serial.println("tick");
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
// TODO: This is hackery.
DOFF(6);
for(int i = 0; i < 500; i++) {
if(radio.afsk.encoder.isDone())
break;
delay(50);
Serial.println("Not done");
}
Serial.println("Done sending");
delay(100);
radio.setModeReceive();
delay(2000);
}
ISR(ADC_vect) {
TIFR1 = _BV(ICF1); // Clear the timer flag
DON(4);
dds.clockTick();
DON(5);
radio.afsk.timer();
DOFF(5);
DOFF(4);
}

View File

@ -1,7 +1,9 @@
// Example sketch to show how to transmit arbitrary tones.
// In this case, the sketch alternates between 1200Hz and 2200Hz at 1s intervals.
#define DDS_REFCLK_DEFAULT 9600 #define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h> #include <HamShield.h>
#define PWM_PIN 3 #define PWM_PIN 3
#define RESET_PIN A3 #define RESET_PIN A3
#define SWITCH_PIN 2 #define SWITCH_PIN 2
@ -24,7 +26,7 @@ void setup() {
radio.initialize(); radio.initialize();
radio.setRfPower(0); radio.setRfPower(0);
radio.setFrequency(145060); radio.frequency(438000);
radio.setModeTransmit(); radio.setModeTransmit();
dds.start(); dds.start();
dds.playWait(600, 3000); dds.playWait(600, 3000);
@ -48,10 +50,8 @@ ISR(ADC_vect) {
static unsigned char tcnt = 0; static unsigned char tcnt = 0;
TIFR1 = _BV(ICF1); // Clear the timer flag TIFR1 = _BV(ICF1); // Clear the timer flag
if(++tcnt == 4) { if(++tcnt == 4) {
//digitalWrite(2, HIGH);
tcnt = 0; tcnt = 0;
} }
dds.clockTick(); dds.clockTick();
//digitalWrite(2, LOW);
} }
#endif #endif

View File

@ -3,16 +3,18 @@ Morse Code Beacon
Test beacon will transmit and wait 30 seconds. Test beacon will transmit and wait 30 seconds.
Beacon will check to see if the channel is clear before it will transmit. Beacon will check to see if the channel is clear before it will transmit.
TO-DO: Radio chip audio AGC too slow in responding to tones, worked around by playing a 6khz tone between actual dits/dahs.
Should work on adjusting AGC to not require this.
*/ */
// Include the HamSheild #define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h> #include <HamShield.h>
#define PWM_PIN 3 #define PWM_PIN 3
#define RESET_PIN A3 #define RESET_PIN A3
#define SWITCH_PIN 2 #define SWITCH_PIN 2
// Create a new instance of our HamSheild class, called 'radio'
HamShield radio; HamShield radio;
// Run our start up things here // Run our start up things here
@ -42,8 +44,9 @@ void setup() {
// Tell the HamShield to start up // Tell the HamShield to start up
radio.initialize(); radio.initialize();
radio.setRfPower(0); radio.setRfPower(0);
// Configure the HamShield to transmit and recieve on 446.000MHz // Configure the HamShield to transmit and recieve on 446.000MHz
radio.frequency(145570); radio.frequency(438000);
Serial.println("Radio Configured."); Serial.println("Radio Configured.");
} }
@ -60,13 +63,13 @@ void loop() {
radio.setModeTransmit(); radio.setModeTransmit();
// Send a message out in morse code // Send a message out in morse code
radio.morseOut("KC7IBT ARDUINO HAMSHIELD"); radio.morseOut(" KC7IBT ARDUINO HAMSHIELD");
// We're done sending the message, set the radio back into recieve mode. // We're done sending the message, set the radio back into recieve mode.
radio.setModeReceive(); radio.setModeReceive();
Serial.println("Done."); Serial.println("Done.");
// Wait 30 seconds before we send our beacon again. // Wait a second before we send our beacon again.
delay(1000); delay(1000);
} else { } else {
// If we get here, the channel is busy. Let's also print out the RSSI. // If we get here, the channel is busy. Let's also print out the RSSI.

View File

@ -6,9 +6,9 @@
#define RESET_PIN A3 #define RESET_PIN A3
#define SWITCH_PIN 2 #define SWITCH_PIN 2
// transmit for 1 minute, every 10 minutes // In milliseconds
#define TRANSMITLENGTH 60000
#define TRANSMITLENGTH 1 // In minutes
#define INTERVAL 10 #define INTERVAL 10
#define RANDOMCHANCE 3 #define RANDOMCHANCE 3
@ -27,23 +27,23 @@ void setup() {
digitalWrite(RESET_PIN, HIGH); digitalWrite(RESET_PIN, HIGH);
radio.initialize(); radio.initialize();
radio.frequency(145510); radio.setRfPower(0);
radio.frequency(438000);
radio.setModeReceive(); radio.setModeReceive();
} }
void loop() { void loop() {
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly up to 3 minutes later if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers
if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers radio.setModeTransmit(); // turn on transmit mode
radio.setModeTransmit(); // turn on transmit mode tone(PWM_PIN, 1000, TRANSMITLENGTH); // play a long solid tone
tone(1000,11,TRANSMITLENGTH * 60 * 1000); // play a long solid tone delay(TRANSMITLENGTH);
radio.morseOut("1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter radio.morseOut(" 1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter
radio.setModeReceive(); // turn off the transmit mode radio.setModeReceive(); // turn off the transmit mode
} }
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly
} }
// a function so we can wait by minutes // a function so we can wait by minutes
void waitMinute(unsigned long period) {
void waitMinute(int period) {
delay(period * 60 * 1000); delay(period * 60 * 1000);
} }