2015-07-04 03:21:51 +00:00
|
|
|
#define DDS_REFCLK_DEFAULT 9600
|
|
|
|
|
2015-07-02 02:30:49 +00:00
|
|
|
#include <HamShield.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
|
|
|
|
HamShield radio;
|
|
|
|
DDS dds;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
2015-07-04 03:21:51 +00:00
|
|
|
Wire.begin();
|
2015-07-02 02:30:49 +00:00
|
|
|
pinMode(2, OUTPUT);
|
|
|
|
pinMode(3, OUTPUT);
|
|
|
|
|
2015-07-02 07:26:47 +00:00
|
|
|
Serial.println(F("Radio test connection"));
|
2015-07-04 03:21:51 +00:00
|
|
|
Serial.println(radio.testConnection(), DEC);
|
2015-07-02 07:26:47 +00:00
|
|
|
Serial.println(F("Initialize"));
|
2015-07-04 03:21:51 +00:00
|
|
|
delay(100);
|
2015-07-02 07:26:47 +00:00
|
|
|
radio.initialize();
|
|
|
|
Serial.println(F("Frequency"));
|
2015-07-04 03:21:51 +00:00
|
|
|
delay(100);
|
|
|
|
radio.setVHF();
|
|
|
|
radio.frequency(145050);
|
|
|
|
radio.setRfPower(0);
|
2015-07-02 07:26:47 +00:00
|
|
|
Serial.println(F("DDS Start"));
|
2015-07-04 03:21:51 +00:00
|
|
|
delay(100);
|
2015-07-02 02:30:49 +00:00
|
|
|
dds.start();
|
2015-07-02 07:26:47 +00:00
|
|
|
Serial.println(F("AFSK start"));
|
2015-07-04 03:21:51 +00:00
|
|
|
delay(100);
|
2015-07-02 02:30:49 +00:00
|
|
|
radio.afsk.start(&dds);
|
2015-07-02 07:26:47 +00:00
|
|
|
Serial.println(F("Starting..."));
|
2015-07-04 03:21:51 +00:00
|
|
|
pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11
|
|
|
|
delay(100);
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
|
|
|
packet->start();
|
2015-07-02 08:38:28 +00:00
|
|
|
packet->appendCallsign("VE6SLP",0);
|
|
|
|
packet->appendCallsign("VA6GA",15,true);
|
2015-07-02 02:30:49 +00:00
|
|
|
packet->appendFCS(0x03);
|
|
|
|
packet->appendFCS(0xf0);
|
2015-07-04 03:21:51 +00:00
|
|
|
packet->print(F("Hello "));
|
2015-07-02 02:30:49 +00:00
|
|
|
packet->println(millis());
|
|
|
|
packet->finish();
|
|
|
|
|
|
|
|
bool ret = radio.afsk.putTXPacket(packet);
|
2015-07-04 03:21:51 +00:00
|
|
|
|
|
|
|
if(radio.afsk.txReady()) {
|
|
|
|
Serial.println(F("txReady"));
|
|
|
|
radio.setModeTransmit();
|
|
|
|
//delay(100);
|
2015-07-02 02:30:49 +00:00
|
|
|
if(radio.afsk.txStart()) {
|
2015-07-04 03:21:51 +00:00
|
|
|
Serial.println(F("txStart"));
|
|
|
|
} else {
|
|
|
|
radio.setModeReceive();
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|
2015-07-04 03:21:51 +00:00
|
|
|
}
|
2015-07-02 02:30:49 +00:00
|
|
|
// Wait 2 seconds before we send our beacon again.
|
|
|
|
Serial.println("tick");
|
2015-07-02 07:31:36 +00:00
|
|
|
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
|
|
|
|
// TODO: This is hackery.
|
|
|
|
for(int i = 0; i < 500; i++) {
|
2015-07-04 03:21:51 +00:00
|
|
|
if(radio.afsk.encoder.isDone())
|
2015-07-02 07:31:36 +00:00
|
|
|
break;
|
|
|
|
delay(50);
|
|
|
|
}
|
2015-07-04 03:21:51 +00:00
|
|
|
Serial.println("Done sending");
|
2015-07-02 07:31:36 +00:00
|
|
|
radio.setModeReceive();
|
2015-07-04 03:21:51 +00:00
|
|
|
delay(30000);
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ISR(TIMER2_OVF_vect) {
|
|
|
|
TIFR2 = _BV(TOV2);
|
|
|
|
static uint8_t tcnt = 0;
|
|
|
|
if(++tcnt == 8) {
|
|
|
|
digitalWrite(2, HIGH);
|
|
|
|
dds.clockTick();
|
|
|
|
digitalWrite(2, LOW);
|
|
|
|
tcnt = 0;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
ISR(ADC_vect) {
|
2015-07-04 03:21:51 +00:00
|
|
|
static uint8_t tcnt = 0;
|
2015-07-02 02:30:49 +00:00
|
|
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
2015-07-04 03:21:51 +00:00
|
|
|
PORTD |= _BV(2); // Diagnostic pin (D2)
|
2015-07-02 02:30:49 +00:00
|
|
|
dds.clockTick();
|
2015-07-04 03:21:51 +00:00
|
|
|
if(++tcnt == 1) {
|
|
|
|
if(radio.afsk.encoder.isSending()) {
|
|
|
|
radio.afsk.timer();
|
|
|
|
}
|
|
|
|
tcnt = 0;
|
|
|
|
}
|
|
|
|
PORTD &= ~(_BV(2)); // Pin D2 off again
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|
|
|
|
|