working afsk packets
This commit is contained in:
parent
b9f75e0c11
commit
4ff3f7d9d0
|
@ -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,60 +95,54 @@ 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(":"));
|
|
||||||
|
|
||||||
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
// Serial.print("From: "); Serial.print(origin_call); Serial.print(" To: "); Serial.println(destination_call); Serial.println("Text: "); Serial.println(textmessage);
|
||||||
|
|
||||||
packet->start();
|
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
||||||
packet->appendFCS(HDLC_FRAME);
|
|
||||||
packet->appendCallsign(origin_call.c_str(),0);
|
|
||||||
packet->appendCallsign(destination_call.c_str(),15,true);
|
|
||||||
packet->appendFCS(0x03);
|
|
||||||
packet->appendFCS(0xf0);
|
|
||||||
packet->print(textmessage);
|
|
||||||
packet->finish();
|
|
||||||
|
|
||||||
textmessage = "";
|
packet->start();
|
||||||
|
packet->appendCallsign(origin_call.c_str(),0);
|
||||||
|
packet->appendCallsign(destination_call.c_str(),15,true);
|
||||||
|
packet->appendFCS(0x03);
|
||||||
|
packet->appendFCS(0xf0);
|
||||||
|
packet->print(textmessage);
|
||||||
|
packet->finish();
|
||||||
|
|
||||||
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"));
|
||||||
} else {
|
} else {
|
||||||
radio.setModeReceive();
|
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(afsk.encoder.isDone())
|
for(int i = 0; i < 500; i++) {
|
||||||
break;
|
if(afsk.encoder.isDone())
|
||||||
delay(50);
|
break;
|
||||||
}
|
delay(50);
|
||||||
Serial.println("Done sending");
|
}
|
||||||
delay(3000);
|
Serial.println("Done sending");
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue