working afsk packets

This commit is contained in:
morgan 2016-09-24 17:33:00 -07:00
parent b9f75e0c11
commit 4ff3f7d9d0
2 changed files with 43 additions and 58 deletions

View File

@ -13,7 +13,6 @@
*/ */
#define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h> #include <HamShield.h>
#include <DDS.h> #include <DDS.h>
@ -63,14 +62,15 @@ void setup() {
Serial.println("HELLO"); Serial.println("HELLO");
} }
String temp[1] = "";
void loop() { void loop() {
if(Serial.available()) { if(Serial.available()) {
char temp = (char)Serial.read(); char temp = (char)Serial.read();
if(temp == '`') { if(temp == '`') {
prepMessage(); msgptr = 0; Serial.print("!!"); } //Serial.println(messagebuff);
prepMessage();
msgptr = 0;
Serial.print("!!");
}
else { else {
messagebuff += temp; messagebuff += temp;
msgptr++; msgptr++;
@ -79,7 +79,6 @@ void loop() {
if(msgptr > 254) { messagebuff = ""; Serial.print("X!"); } if(msgptr > 254) { messagebuff = ""; Serial.print("X!"); }
if(afsk.decoder.read() || afsk.rxPacketCount()) { if(afsk.decoder.read() || afsk.rxPacketCount()) {
Serial.println("got pkt");
// A true return means something was put onto the packet FIFO // A true return means something was put onto the packet FIFO
// If we actually have data packets in the buffer, process them all now // If we actually have data packets in the buffer, process them all now
while(afsk.rxPacketCount()) { while(afsk.rxPacketCount()) {
@ -96,16 +95,16 @@ void loop() {
void prepMessage() { void prepMessage() {
radio.setModeTransmit(); radio.setModeTransmit();
delay(500); delay(1000);
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, destination_call = messagebuff.substring(messagebuff.indexOf(',')+1,messagebuff.indexOf(',',messagebuff.indexOf(',')+1)); // get the destination call
messagebuff.indexOf(',',messagebuff.indexOf(',')+1)); // get the destination call textmessage = messagebuff.substring(messagebuff.indexOf(":")+1);
textmessage = messagebuff.substring(messagebuff.indexOf(":"));
// 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->appendFCS(HDLC_FRAME);
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);
@ -113,13 +112,11 @@ void prepMessage() {
packet->print(textmessage); packet->print(textmessage);
packet->finish(); packet->finish();
textmessage = "";
bool ret = afsk.putTXPacket(packet); bool ret = afsk.putTXPacket(packet);
if(afsk.txReady()) { if(afsk.txReady()) {
Serial.println(F("txReady")); Serial.println(F("txReady"));
//radio.setModeTransmit(); radio.setModeTransmit();
//delay(100); //delay(100);
if(afsk.txStart()) { if(afsk.txStart()) {
Serial.println(F("txStart")); Serial.println(F("txStart"));
@ -137,19 +134,15 @@ void prepMessage() {
delay(50); delay(50);
} }
Serial.println("Done sending"); Serial.println("Done sending");
delay(3000);
radio.setModeReceive(); radio.setModeReceive();
} }
// TODO: d2 is now our switch, so don't write to that
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;
} }
} }
@ -157,15 +150,9 @@ 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(afsk.encoder.isSending())
{
afsk.timer(); afsk.timer();
}
tcnt = 0; tcnt = 0;
} }
//PORTD &= ~(_BV(2)); // Pin D2 off again
} }

View File

@ -18,7 +18,6 @@ DDS dds;
KISS kiss(&Serial, &radio, &dds); KISS kiss(&Serial, &radio, &dds);
AFSK afsk; AFSK afsk;
//TODO: move these into library
#define PWM_PIN 3 #define PWM_PIN 3
#define RESET_PIN A3 #define RESET_PIN A3
#define SWITCH_PIN 2 #define SWITCH_PIN 2
@ -45,7 +44,6 @@ void setup() {
radio.initialize(); radio.initialize();
radio.setSQOff(); radio.setSQOff();
radio.frequency(144390); radio.frequency(144390);
//I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0x05FF);
dds.start(); dds.start();
afsk.start(&dds); afsk.start(&dds);