2015-07-02 02:30:49 +00:00
|
|
|
#include <HamShield.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
|
|
|
|
HamShield radio;
|
|
|
|
DDS dds;
|
|
|
|
|
2015-07-14 01:01:32 +00:00
|
|
|
#define DON(p) PORTD |= _BV((p))
|
|
|
|
#define DOFF(p) PORTD &= ~(_BV((p)))
|
|
|
|
|
2015-07-02 02:30:49 +00:00
|
|
|
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-14 01:01:32 +00:00
|
|
|
pinMode(4, OUTPUT);
|
|
|
|
pinMode(5, OUTPUT);
|
|
|
|
pinMode(6, OUTPUT);
|
|
|
|
pinMode(7, 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();
|
2015-07-14 01:01:32 +00:00
|
|
|
radio.frequency(145010);
|
|
|
|
//radio.setRfPower(0);
|
2015-07-04 03:21:51 +00:00
|
|
|
delay(100);
|
2015-07-02 02:30:49 +00:00
|
|
|
dds.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-04 03:21:51 +00:00
|
|
|
pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11
|
|
|
|
delay(100);
|
2015-07-14 01:01:32 +00:00
|
|
|
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);
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2015-07-14 01:01:32 +00:00
|
|
|
DON(6);
|
2015-07-02 02:30:49 +00:00
|
|
|
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-14 01:01:32 +00:00
|
|
|
packet->print(millis());
|
|
|
|
packet->println(F("\r\nThis is a test of the HamShield Kickstarter prototype. de VE6SLP"));
|
2015-07-02 02:30:49 +00:00
|
|
|
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();
|
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 {
|
2015-07-14 01:01:32 +00:00
|
|
|
Serial.println(F("Tx Start failure"));
|
2015-07-04 03:21:51 +00:00
|
|
|
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.
|
2015-07-14 01:01:32 +00:00
|
|
|
DOFF(6);
|
2015-07-02 07:31:36 +00:00
|
|
|
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-14 01:01:32 +00:00
|
|
|
Serial.println("Not done");
|
2015-07-02 07:31:36 +00:00
|
|
|
}
|
2015-07-04 03:21:51 +00:00
|
|
|
Serial.println("Done sending");
|
2015-07-14 01:01:32 +00:00
|
|
|
delay(100);
|
2015-07-02 07:31:36 +00:00
|
|
|
radio.setModeReceive();
|
2015-07-14 01:01:32 +00:00
|
|
|
delay(2000);
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ISR(ADC_vect) {
|
|
|
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
2015-07-14 01:01:32 +00:00
|
|
|
DON(4);
|
2015-07-02 02:30:49 +00:00
|
|
|
dds.clockTick();
|
2015-07-14 01:01:32 +00:00
|
|
|
DON(5);
|
|
|
|
radio.afsk.timer();
|
|
|
|
DOFF(5);
|
|
|
|
DOFF(4);
|
2015-07-02 02:30:49 +00:00
|
|
|
}
|