Cleanup on AFSK-PacketTester example, verified working with current library and hardware v09
This commit is contained in:
parent
75e964289c
commit
868882f81e
|
@ -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);
|
|
||||||
|
|
||||||
if(radio.afsk.txReady()) {
|
bool ret = radio.afsk.putTXPacket(packet);
|
||||||
Serial.println(F("txReady"));
|
|
||||||
radio.setModeTransmit();
|
if(radio.afsk.txReady()) {
|
||||||
//delay(100);
|
Serial.println(F("txReady"));
|
||||||
if(radio.afsk.txStart()) {
|
radio.setModeTransmit();
|
||||||
Serial.println(F("txStart"));
|
//delay(100);
|
||||||
} else {
|
if(radio.afsk.txStart()) {
|
||||||
radio.setModeReceive();
|
Serial.println(F("txStart"));
|
||||||
}
|
} 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue