Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f7db1d561 | ||
|
|
d8d97789d7 | ||
|
|
d232424bb4 | ||
|
|
6538ae7db3 | ||
|
|
307d33add0 | ||
|
|
219d89ff60 | ||
|
|
6954402ac6 | ||
|
|
ec0400c1c6 | ||
|
|
1d02387649 | ||
|
|
4593f1d44c | ||
|
|
292a774a79 | ||
|
|
5874e6b8e5 | ||
|
|
4ff3f7d9d0 | ||
|
|
b9f75e0c11 | ||
|
|
f462bc0342 | ||
|
|
33962a585d | ||
|
|
d54c5404a8 | ||
|
|
6b775130d1 | ||
|
|
e65893402a | ||
|
|
9096d2ffa2 | ||
|
|
3e76e6e72f | ||
|
|
8b8fd7a9a1 | ||
|
|
164888fd49 | ||
|
|
e8ad7e9c93 | ||
|
|
4f30789e88 | ||
|
|
f369c2ff9a | ||
|
|
25813b7968 | ||
|
|
e10e351e49 | ||
|
|
62e137f8f2 | ||
|
|
9e0db9d537 | ||
|
|
bce0b1e0d8 | ||
|
|
39b543877b | ||
|
|
f5e004fbb3 | ||
|
|
09c9911ba1 | ||
|
|
2b5fbeff4a | ||
|
|
8e35c83185 | ||
|
|
7a07bd3056 | ||
|
|
ad7d729010 | ||
|
|
c9a9320719 | ||
|
|
0ed024cd7d | ||
|
|
07221e2426 | ||
|
|
06cb3f24ed | ||
|
|
2907eaf02e | ||
|
|
0fe34bbbb9 | ||
|
|
6a889580f2 | ||
|
|
d98eafb11a | ||
|
|
705884497a | ||
|
|
b818b73054 | ||
|
|
506d3dfb0c | ||
|
|
12c9cdf3d9 | ||
|
|
8c90a134ad | ||
|
|
3c9965fd62 | ||
|
|
868882f81e | ||
|
|
558414d084 |
738
AFSK.cpp
738
AFSK.cpp
@@ -1,738 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include "HamShield.h"
|
|
||||||
#include "SimpleFIFO.h"
|
|
||||||
#include <util/atomic.h>
|
|
||||||
|
|
||||||
#define PHASE_BIT 8
|
|
||||||
#define PHASE_INC 1
|
|
||||||
|
|
||||||
#define PHASE_MAX (SAMPLEPERBIT * PHASE_BIT)
|
|
||||||
#define PHASE_THRES (PHASE_MAX / 2)
|
|
||||||
|
|
||||||
#define BIT_DIFFER(bitline1, bitline2) (((bitline1) ^ (bitline2)) & 0x01)
|
|
||||||
#define EDGE_FOUND(bitline) BIT_DIFFER((bitline), (bitline) >> 1)
|
|
||||||
|
|
||||||
#define PPOOL_SIZE 2
|
|
||||||
|
|
||||||
#define AFSK_SPACE 2200
|
|
||||||
#define AFSK_MARK 1200
|
|
||||||
|
|
||||||
// Timers
|
|
||||||
volatile unsigned long lastTx = 0;
|
|
||||||
volatile unsigned long lastTxEnd = 0;
|
|
||||||
volatile unsigned long lastRx = 0;
|
|
||||||
|
|
||||||
#define T_BIT ((unsigned int)(SAMPLERATE/BITRATE))
|
|
||||||
|
|
||||||
#ifdef PACKET_PREALLOCATE
|
|
||||||
SimpleFIFO<AFSK::Packet *,PPOOL_SIZE> preallocPool;
|
|
||||||
AFSK::Packet preallocPackets[PPOOL_SIZE];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void AFSK::Encoder::process() {
|
|
||||||
// We're on the start of a byte position, so fetch one
|
|
||||||
if(bitPosition == 0) {
|
|
||||||
if(preamble) { // Still in preamble
|
|
||||||
currentByte = HDLC_PREAMBLE;
|
|
||||||
--preamble; // Decrement by one
|
|
||||||
} else {
|
|
||||||
if(!packet) { // We aren't on a packet, grab one
|
|
||||||
// Unless we already sent enough
|
|
||||||
if(maxTx-- == 0) {
|
|
||||||
stop();
|
|
||||||
lastTxEnd = millis();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
packet = pBuf.getPacket();
|
|
||||||
if(!packet) { // There actually weren't any
|
|
||||||
stop(); // Stop transmitting and return
|
|
||||||
lastTxEnd = millis();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastTx = millis();
|
|
||||||
currentBytePos = 0;
|
|
||||||
nextByte = HDLC_FRAME; // Our next output should be a frame boundary
|
|
||||||
hdlc = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We ran out of actual data, provide an HDLC frame (idle)
|
|
||||||
if(currentBytePos == packet->len && nextByte == 0) {
|
|
||||||
// We also get here if nextByte isn't set, to handle empty frames
|
|
||||||
pBuf.freePacket(packet);
|
|
||||||
packet = pBuf.getPacket(); // Get the next, if any
|
|
||||||
//packet = NULL;
|
|
||||||
currentBytePos = 0;
|
|
||||||
nextByte = 0;
|
|
||||||
currentByte = HDLC_FRAME;
|
|
||||||
hdlc = true;
|
|
||||||
} else {
|
|
||||||
if(nextByte) {
|
|
||||||
// We queued up something other than the actual stream to be sent next
|
|
||||||
currentByte = nextByte;
|
|
||||||
nextByte = 0;
|
|
||||||
} else {
|
|
||||||
// Get the next byte to send, but if it's an HDLC frame, escape it
|
|
||||||
// and queue the real byte for the next cycle.
|
|
||||||
currentByte = packet->getByte();
|
|
||||||
if(currentByte == HDLC_FRAME) {
|
|
||||||
nextByte = currentByte;
|
|
||||||
currentByte = HDLC_ESCAPE;
|
|
||||||
} else {
|
|
||||||
currentBytePos++;
|
|
||||||
}
|
|
||||||
hdlc = false; // If we get here, it will be NRZI bit stuffed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pickup the last bit
|
|
||||||
currentBit = currentByte & 0x1;
|
|
||||||
|
|
||||||
if(lastZero == 5) {
|
|
||||||
currentBit = 0; // Force a 0 bit output
|
|
||||||
} else {
|
|
||||||
currentByte >>= 1; // Bit shift it right, for the next round
|
|
||||||
++bitPosition; // Note our increase in position
|
|
||||||
}
|
|
||||||
|
|
||||||
// To handle NRZI 5 bit stuffing, count the bits
|
|
||||||
if(!currentBit || hdlc)
|
|
||||||
lastZero = 0;
|
|
||||||
else
|
|
||||||
++lastZero;
|
|
||||||
|
|
||||||
// NRZI and AFSK uses toggling 0s, "no change" on 1
|
|
||||||
// So, if not a 1, toggle to the opposite tone
|
|
||||||
if(!currentBit)
|
|
||||||
currentTone = !currentTone;
|
|
||||||
|
|
||||||
if(currentTone == 0) {
|
|
||||||
PORTD |= _BV(7);
|
|
||||||
dds->setFrequency(AFSK_SPACE);
|
|
||||||
} else {
|
|
||||||
PORTD &= ~_BV(7);
|
|
||||||
dds->setFrequency(AFSK_MARK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AFSK::Encoder::start() {
|
|
||||||
if(!done || sending) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(randomWait > millis()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// First real byte is a frame
|
|
||||||
currentBit = 0;
|
|
||||||
lastZero = 0;
|
|
||||||
bitPosition = 0;
|
|
||||||
//bitClock = 0;
|
|
||||||
preamble = 0b110000; // 6.7ms each, 23 = 153ms
|
|
||||||
done = false;
|
|
||||||
hdlc = true;
|
|
||||||
packet = 0x0; // No initial packet, find in the ISR
|
|
||||||
currentBytePos = 0;
|
|
||||||
maxTx = 3;
|
|
||||||
sending = true;
|
|
||||||
nextByte = 0;
|
|
||||||
dds->setFrequency(0);
|
|
||||||
dds->on();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AFSK::Encoder::stop() {
|
|
||||||
randomWait = 0;
|
|
||||||
sending = false;
|
|
||||||
done = true;
|
|
||||||
dds->setFrequency(0);
|
|
||||||
dds->off();
|
|
||||||
}
|
|
||||||
|
|
||||||
AFSK::Decoder::Decoder() {
|
|
||||||
// Initialize the sampler delay line (phase shift)
|
|
||||||
//for(unsigned char i = 0; i < SAMPLEPERBIT/2; i++)
|
|
||||||
// delay_fifo.enqueue(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AFSK::HDLCDecode::hdlcParse(bool bit, SimpleFIFO<uint8_t,HAMSHIELD_AFSK_RX_FIFO_LEN> *fifo) {
|
|
||||||
bool ret = true;
|
|
||||||
|
|
||||||
demod_bits <<= 1;
|
|
||||||
demod_bits |= bit ? 1 : 0;
|
|
||||||
|
|
||||||
// Flag
|
|
||||||
if(demod_bits == HDLC_FRAME) {
|
|
||||||
fifo->enqueue(HDLC_FRAME);
|
|
||||||
rxstart = true;
|
|
||||||
currchar = 0;
|
|
||||||
bit_idx = 0;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset
|
|
||||||
if((demod_bits & HDLC_RESET) == HDLC_RESET) {
|
|
||||||
rxstart = false;
|
|
||||||
lastRx = millis();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if(!rxstart) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stuffed?
|
|
||||||
if((demod_bits & 0x3f) == 0x3e)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if(demod_bits & 0x01)
|
|
||||||
currchar |= 0x80;
|
|
||||||
|
|
||||||
if(++bit_idx >= 8) {
|
|
||||||
if(currchar == HDLC_FRAME ||
|
|
||||||
currchar == HDLC_RESET ||
|
|
||||||
currchar == HDLC_ESCAPE) {
|
|
||||||
fifo->enqueue(HDLC_ESCAPE);
|
|
||||||
}
|
|
||||||
fifo->enqueue(currchar & 0xff);
|
|
||||||
currchar = 0;
|
|
||||||
bit_idx = 0;
|
|
||||||
} else {
|
|
||||||
currchar >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, int size>
|
|
||||||
class FastRing {
|
|
||||||
private:
|
|
||||||
T ring[size];
|
|
||||||
uint8_t position;
|
|
||||||
public:
|
|
||||||
FastRing(): position(0) {}
|
|
||||||
inline void write(T value) {
|
|
||||||
ring[(position++) & (size-1)] = value;
|
|
||||||
}
|
|
||||||
inline T read() const {
|
|
||||||
return ring[position & (size-1)];
|
|
||||||
}
|
|
||||||
inline T readn(uint8_t n) const {
|
|
||||||
return ring[(position + (~n+1)) & (size-1)];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Create a delay line that's half the length of the bit cycle (-90 degrees)
|
|
||||||
FastRing<uint8_t,(T_BIT/2)> delayLine;
|
|
||||||
|
|
||||||
// Handle the A/D converter interrupt (hopefully quickly :)
|
|
||||||
void AFSK::Decoder::process(int8_t curr_sample) {
|
|
||||||
// Run the same through the phase multiplier and butterworth filter
|
|
||||||
iir_x[0] = iir_x[1];
|
|
||||||
iir_x[1] = ((int8_t)delayLine.read() * curr_sample) >> 2;
|
|
||||||
iir_y[0] = iir_y[1];
|
|
||||||
iir_y[1] = iir_x[0] + iir_x[1] + (iir_y[0] >> 1) + (iir_y[0]>>3) + (iir_y[0]>>5);
|
|
||||||
|
|
||||||
// Place this ADC sample into the delay line
|
|
||||||
delayLine.write(curr_sample);
|
|
||||||
|
|
||||||
// Shift the bit into place based on the output of the discriminator
|
|
||||||
sampled_bits <<= 1;
|
|
||||||
sampled_bits |= (iir_y[1] > 0) ? 1 : 0;
|
|
||||||
|
|
||||||
// If we found a 0/1 transition, adjust phases to track
|
|
||||||
if(EDGE_FOUND(sampled_bits)) {
|
|
||||||
if(curr_phase < PHASE_THRES)
|
|
||||||
curr_phase += PHASE_INC;
|
|
||||||
else
|
|
||||||
curr_phase -= PHASE_INC;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move ahead in phase
|
|
||||||
curr_phase += PHASE_BIT;
|
|
||||||
|
|
||||||
// If we've gone over the phase maximum, we should now have some data
|
|
||||||
if(curr_phase >= PHASE_MAX) {
|
|
||||||
curr_phase %= PHASE_MAX;
|
|
||||||
found_bits <<= 1;
|
|
||||||
|
|
||||||
// If we have 3 bits or more set, it's a positive bit
|
|
||||||
register uint8_t bits = sampled_bits & 0x07;
|
|
||||||
if(bits == 0x07 || bits == 0x06 || bits == 0x05 || bits == 0x03) {
|
|
||||||
found_bits |= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
hdlc.hdlcParse(!EDGE_FOUND(found_bits), &rx_fifo); // Process it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This routine uses a pre-allocated Packet structure
|
|
||||||
// to save on the memory requirements of the stream data
|
|
||||||
bool AFSK::Decoder::read() {
|
|
||||||
bool retVal = false;
|
|
||||||
if(!currentPacket) { // We failed a prior memory allocation
|
|
||||||
currentPacket = pBuf.makePacket(PACKET_MAX_LEN);
|
|
||||||
if(!currentPacket) // Still nothing
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// While we have AFSK receive FIFO bytes...
|
|
||||||
while(rx_fifo.count()) {
|
|
||||||
// Grab the character
|
|
||||||
char c = rx_fifo.dequeue();
|
|
||||||
bool escaped = false;
|
|
||||||
if(c == HDLC_ESCAPE) { // We received an escaped byte, mark it
|
|
||||||
escaped = true;
|
|
||||||
// Do we want to keep HDLC_ESCAPEs in the packet?
|
|
||||||
//currentPacket->append(HDLC_ESCAPE); // Append without FCS
|
|
||||||
c = rx_fifo.dequeue(); // Reset to the next character
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append all the bytes
|
|
||||||
// This will include unescaped HDLC_FRAME bytes
|
|
||||||
if(c != HDLC_FRAME || escaped) // Append frame if it is escaped
|
|
||||||
currentPacket->appendFCS(c); // Escaped characters and all else go into FCS
|
|
||||||
|
|
||||||
if(currentPacket->len > PACKET_MAX_LEN) {
|
|
||||||
// We've now gone too far and picked up far too many bytes
|
|
||||||
// Cancel this frame, start back at the beginning
|
|
||||||
currentPacket->clear();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have a frame boundary, if it isn't escaped
|
|
||||||
// If it's escaped, it was part of the data stream
|
|
||||||
if(c == HDLC_FRAME && !escaped) {
|
|
||||||
if(!currentPacket->len) {
|
|
||||||
currentPacket->clear(); // There wasn't any data, restart stream
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// We have some bytes in stream, check it meets minimum payload length
|
|
||||||
// Min payload is 1 (flag) + 14 (addressing) + 2 (control/PID) + 1 (flag)
|
|
||||||
if(currentPacket->len >= 16) {
|
|
||||||
// We should end up here with a valid FCS due to the appendFCS
|
|
||||||
if(currentPacket->crcOK()) { // Magic number for the CRC check passing
|
|
||||||
// Valid frame, so, let's filter for control + PID
|
|
||||||
// Maximum search distance is 71 bytes to end of the address fields
|
|
||||||
// Skip the HDLC frame start
|
|
||||||
bool filtered = false;
|
|
||||||
for(unsigned char i = 0; i < (currentPacket->len<70?currentPacket->len:71); ++i) {
|
|
||||||
if((currentPacket->getByte() & 0x1) == 0x1) { // Found a byte with LSB set
|
|
||||||
// which marks the final address payload
|
|
||||||
// next two bytes should be the control/PID
|
|
||||||
//if(currentPacket->getByte() == 0x03 && currentPacket->getByte() == 0xf0) {
|
|
||||||
filtered = true;
|
|
||||||
break; // Found it
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!filtered) {
|
|
||||||
// Frame wasn't one we care about, discard
|
|
||||||
currentPacket->clear();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// It's all done and formatted, ready to go
|
|
||||||
currentPacket->ready = 1;
|
|
||||||
if(!pBuf.putPacket(currentPacket)) // Put it in the receive FIFO
|
|
||||||
pBuf.freePacket(currentPacket); // Out of FIFO space, so toss it
|
|
||||||
|
|
||||||
// Allocate a new one of maximum length
|
|
||||||
currentPacket = pBuf.makePacket(PACKET_MAX_LEN);
|
|
||||||
retVal = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Restart the stream
|
|
||||||
currentPacket->clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retVal; // This is true if we parsed a packet in this flow
|
|
||||||
}
|
|
||||||
|
|
||||||
void AFSK::Decoder::start() {
|
|
||||||
// Do this in start to allocate our first packet
|
|
||||||
currentPacket = pBuf.makePacket(PACKET_MAX_LEN);
|
|
||||||
/* ASSR &= ~(_BV(EXCLK) | _BV(AS2));
|
|
||||||
|
|
||||||
// Do non-inverting PWM on pin OC2B (arduino pin 3) (p.159).
|
|
||||||
// OC2A (arduino pin 11) stays in normal port operation:
|
|
||||||
// COM2B1=1, COM2B0=0, COM2A1=0, COM2A0=0
|
|
||||||
// Mode 1 - Phase correct PWM
|
|
||||||
TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0)) |
|
|
||||||
_BV(WGM21) | _BV(WGM20);
|
|
||||||
// No prescaler (p.162)
|
|
||||||
TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20) | _BV(WGM22);
|
|
||||||
|
|
||||||
OCR2A = pow(2,COMPARE_BITS)-1;
|
|
||||||
OCR2B = 0;
|
|
||||||
// Configure the ADC and Timer1 to trigger automatic interrupts
|
|
||||||
TCCR1A = 0;
|
|
||||||
TCCR1B = _BV(CS11) | _BV(WGM13) | _BV(WGM12);
|
|
||||||
ICR1 = ((F_CPU / 8) / REFCLK) - 1;
|
|
||||||
ADMUX = _BV(REFS0) | _BV(ADLAR) | 0; // Channel 0, shift result left (ADCH used)
|
|
||||||
DDRC &= ~_BV(0);
|
|
||||||
PORTC &= ~_BV(0);
|
|
||||||
DIDR0 |= _BV(0);
|
|
||||||
ADCSRB = _BV(ADTS2) | _BV(ADTS1) | _BV(ADTS0);
|
|
||||||
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADIE) | _BV(ADPS2); // | _BV(ADPS0); */
|
|
||||||
}
|
|
||||||
|
|
||||||
AFSK::PacketBuffer::PacketBuffer() {
|
|
||||||
nextPacketIn = 0;
|
|
||||||
nextPacketOut = 0;
|
|
||||||
inBuffer = 0;
|
|
||||||
for(unsigned char i = 0; i < PACKET_BUFFER_SIZE; ++i) {
|
|
||||||
packets[i] = 0x0;
|
|
||||||
}
|
|
||||||
#ifdef PACKET_PREALLOCATE
|
|
||||||
for(unsigned char i = 0; i < PPOOL_SIZE; ++i) {
|
|
||||||
// Put some empty packets in the FIFO
|
|
||||||
preallocPool.enqueue(&preallocPackets[i]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char AFSK::PacketBuffer::readyCount() volatile {
|
|
||||||
unsigned char i;
|
|
||||||
unsigned int cnt = 0;
|
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
||||||
for(i = 0; i < PACKET_BUFFER_SIZE; ++i) {
|
|
||||||
if(packets[i] && packets[i]->ready)
|
|
||||||
++cnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return NULL on empty packet buffers
|
|
||||||
AFSK::Packet *AFSK::PacketBuffer::getPacket() volatile {
|
|
||||||
unsigned char i = 0;
|
|
||||||
AFSK::Packet *p = NULL;
|
|
||||||
|
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
||||||
if(inBuffer == 0) {
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
p = packets[nextPacketOut];
|
|
||||||
if(p) {
|
|
||||||
packets[nextPacketOut] = 0x0;
|
|
||||||
--inBuffer;
|
|
||||||
}
|
|
||||||
nextPacketOut = ++nextPacketOut % PACKET_BUFFER_SIZE;
|
|
||||||
++i;
|
|
||||||
} while(!p && i<PACKET_BUFFER_SIZE);
|
|
||||||
|
|
||||||
// Return whatever we found, if anything
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
//void Packet::init(uint8_t *buf, unsigned int dlen, bool freeData) {
|
|
||||||
void AFSK::Packet::init(unsigned short dlen) {
|
|
||||||
//data = (unsigned char *)buf;
|
|
||||||
ready = 0;
|
|
||||||
#ifdef PACKET_PREALLOCATE
|
|
||||||
freeData = 0;
|
|
||||||
maxLen = PACKET_MAX_LEN; // Put it here instead
|
|
||||||
#else
|
|
||||||
freeData = 1;
|
|
||||||
dataPtr = (uint8_t *)malloc(dlen+16);
|
|
||||||
maxLen = dlen; // Put it here instead
|
|
||||||
#endif
|
|
||||||
type = PACKET_STATIC;
|
|
||||||
len = 0; // We had a length, but don't put it here.
|
|
||||||
dataPos = dataPtr;
|
|
||||||
readPos = dataPtr;
|
|
||||||
fcs = 0xffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a new packet with a data buffer as set
|
|
||||||
AFSK::Packet *AFSK::PacketBuffer::makePacket(unsigned short dlen) {
|
|
||||||
AFSK::Packet *p;
|
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
||||||
//Packet *p = findPooledPacket();
|
|
||||||
#ifdef PACKET_PREALLOCATE
|
|
||||||
if(preallocPool.count())
|
|
||||||
p = preallocPool.dequeue();
|
|
||||||
else p = NULL;
|
|
||||||
#else
|
|
||||||
p = new Packet(); //(Packet *)malloc(sizeof(Packet));
|
|
||||||
#endif
|
|
||||||
if(p) // If allocated
|
|
||||||
p->init(dlen);
|
|
||||||
}
|
|
||||||
return p; // Passes through a null on failure.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free a packet struct, mainly convenience
|
|
||||||
void AFSK::PacketBuffer::freePacket(Packet *p) {
|
|
||||||
if(!p)
|
|
||||||
return;
|
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
||||||
#ifdef PACKET_PREALLOCATE
|
|
||||||
preallocPool.enqueue(p);
|
|
||||||
#else
|
|
||||||
p->free();
|
|
||||||
/*unsigned char i;
|
|
||||||
for(i = 0; i < PPOOL_SIZE; ++i)
|
|
||||||
if(p == &(pPool[i]))
|
|
||||||
break;
|
|
||||||
if(i < PPOOL_SIZE)
|
|
||||||
pStatus &= ~(1<<i);*/
|
|
||||||
delete p;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put a packet onto the buffer array
|
|
||||||
bool AFSK::PacketBuffer::putPacket(Packet *p) volatile {
|
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
||||||
if(inBuffer >= PACKET_BUFFER_SIZE) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
packets[nextPacketIn] = p;
|
|
||||||
nextPacketIn = ++nextPacketIn % PACKET_BUFFER_SIZE;
|
|
||||||
++inBuffer;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print a single byte to the data array
|
|
||||||
size_t AFSK::Packet::write(uint8_t c) {
|
|
||||||
return (appendFCS(c)?1:0);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t AFSK::Packet::write(const uint8_t *ptr, size_t len) {
|
|
||||||
size_t i;
|
|
||||||
for(i = 0; i < len; ++i)
|
|
||||||
if(!appendFCS(ptr[i]))
|
|
||||||
break;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a callsign, flagged as source, destination, or digi
|
|
||||||
// Also tell the routine the SSID to use and if this is the final callsign
|
|
||||||
size_t AFSK::Packet::appendCallsign(const char *callsign, uint8_t ssid, bool final) {
|
|
||||||
uint8_t i;
|
|
||||||
for(i = 0; i < strlen(callsign) && i < 6; i++) {
|
|
||||||
appendFCS(callsign[i]<<1);
|
|
||||||
}
|
|
||||||
if(i < 6) {
|
|
||||||
for(;i<6;i++) {
|
|
||||||
appendFCS(' '<<1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uint8_t ssidField = (ssid&0xf) << 1;
|
|
||||||
// TODO: Handle digis in the address C bit
|
|
||||||
if(final) {
|
|
||||||
ssidField |= 0b01100001;
|
|
||||||
} else {
|
|
||||||
ssidField |= 0b11100000;
|
|
||||||
}
|
|
||||||
appendFCS(ssidField);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PACKET_PARSER
|
|
||||||
// Process the AX25 frame and turn it into a bunch of useful strings
|
|
||||||
bool AFSK::Packet::parsePacket() {
|
|
||||||
uint8_t *d = dataPtr;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// First 7 bytes are destination-ssid
|
|
||||||
for(i = 0; i < 6; i++) {
|
|
||||||
dstCallsign[i] = (*d++)>>1;
|
|
||||||
if(dstCallsign[i] == ' ') {
|
|
||||||
dstCallsign[i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dstCallsign[6] = '\0';
|
|
||||||
dstSSID = ((*d++)>>1) & 0xF;
|
|
||||||
|
|
||||||
// Next 7 bytes are source-ssid
|
|
||||||
for(i = 0; i < 6; i++) {
|
|
||||||
srcCallsign[i] = (*d++)>>1;
|
|
||||||
if(srcCallsign[i] == ' ') {
|
|
||||||
srcCallsign[i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
srcCallsign[6] = '\0';
|
|
||||||
srcSSID = *d++; // Don't shift yet, we need the LSB
|
|
||||||
|
|
||||||
digipeater[0][0] = '\0'; // Set null in case we have none anyway
|
|
||||||
if((srcSSID & 1) == 0) { // Not the last address field
|
|
||||||
int digi; // Which digi we're on
|
|
||||||
for(digi = 0; digi < 8; digi++) {
|
|
||||||
for(i = 0; i < 6; i++) {
|
|
||||||
digipeater[digi][i] = (*d++)>>1;
|
|
||||||
if(digipeater[digi][i] == ' ') {
|
|
||||||
digipeater[digi][i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uint8_t last = (*d) & 1;
|
|
||||||
digipeaterSSID[digi] = ((*d++)>>1) & 0xF;
|
|
||||||
if(last == 1)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
digipeater[digi][6] = '\0';
|
|
||||||
for(digi += 1; digi<8; digi++) { // Empty out the rest of them
|
|
||||||
digipeater[digi][0] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now handle the SSID itself
|
|
||||||
srcSSID >>= 1;
|
|
||||||
srcSSID &= 0xF;
|
|
||||||
|
|
||||||
// After the address parsing, we end up on the control field
|
|
||||||
control = *d++;
|
|
||||||
// We have a PID if control type is U or I
|
|
||||||
// Control & 1 == 0 == I frame
|
|
||||||
// Control & 3 == 3 == U frame
|
|
||||||
if((control & 1) == 0 || (control & 3) == 3)
|
|
||||||
pid = *d++;
|
|
||||||
else pid = 0;
|
|
||||||
|
|
||||||
// If there is no PID, we have no data
|
|
||||||
if(!pid) {
|
|
||||||
iFrameData = NULL;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// At this point, we've walked far enough along that data is just at d
|
|
||||||
iFrameData = d;
|
|
||||||
|
|
||||||
// Cheat a little by setting the first byte of the FCS to 0, making it a string
|
|
||||||
// First FCS byte is found at -2, HDLC flags aren't in this buffer
|
|
||||||
dataPtr[len-2] = '\0';
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void AFSK::Packet::printPacket(Stream *s) {
|
|
||||||
uint8_t i;
|
|
||||||
#ifdef PACKET_PARSER
|
|
||||||
if(!parsePacket()) {
|
|
||||||
s->print(F("Packet not valid"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->print(srcCallsign);
|
|
||||||
if(srcSSID > 0) {
|
|
||||||
s->write('-');
|
|
||||||
s->print(srcSSID);
|
|
||||||
}
|
|
||||||
s->print(F(" > "));
|
|
||||||
s->print(dstCallsign);
|
|
||||||
if(dstSSID > 0) {
|
|
||||||
s->write('-');
|
|
||||||
s->print(dstSSID);
|
|
||||||
}
|
|
||||||
s->write(' ');
|
|
||||||
if(digipeater[0][0] != '\0') {
|
|
||||||
s->print(F("via "));
|
|
||||||
for(i = 0; i < 8; i++) {
|
|
||||||
if(digipeater[i][0] == '\0')
|
|
||||||
break;
|
|
||||||
s->print(digipeater[i]);
|
|
||||||
if(digipeaterSSID[i] != 0) {
|
|
||||||
s->write('-');
|
|
||||||
s->print(digipeaterSSID[i]);
|
|
||||||
}
|
|
||||||
if((digipeaterSSID[i] & _BV(7)) == _BV(7)) {
|
|
||||||
s->write('*'); // Digipeated already
|
|
||||||
}
|
|
||||||
// If we might have more, check to add a comma
|
|
||||||
if(i < 7 && digipeater[i+1][0] != '\0') {
|
|
||||||
s->write(',');
|
|
||||||
}
|
|
||||||
s->write(' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is an S frame, we can only print control info
|
|
||||||
if(control & 3 == 1) {
|
|
||||||
switch((control>>2)&3) {
|
|
||||||
case 0:
|
|
||||||
s->print(F("RR"));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
s->print(F("RNR"));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
s->print(F("REJ"));
|
|
||||||
break;
|
|
||||||
case 3: // Undefined
|
|
||||||
s->print(F("unk"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Use a + to indicate poll bit
|
|
||||||
if(control & _BV(4) == _BV(4)) {
|
|
||||||
s->write('+');
|
|
||||||
}
|
|
||||||
} else if((control & 3) == 3) { // U Frame
|
|
||||||
s->print(F("U("));
|
|
||||||
s->print(control, HEX);
|
|
||||||
s->write(',');
|
|
||||||
s->print(pid, HEX);
|
|
||||||
s->print(F(") "));
|
|
||||||
} else if((control & 1) == 0) { // I Frame
|
|
||||||
s->print(F("I("));
|
|
||||||
s->print(control, HEX);
|
|
||||||
s->write(',');
|
|
||||||
s->print(pid, HEX);
|
|
||||||
s->print(F(") "));
|
|
||||||
}
|
|
||||||
s->print(F("len "));
|
|
||||||
s->print(len);
|
|
||||||
s->print(F(": "));
|
|
||||||
s->print((char *)iFrameData);
|
|
||||||
s->println();
|
|
||||||
#else // no packet parser, do a rudimentary print
|
|
||||||
// Second 6 bytes are source callsign
|
|
||||||
for(i=7; i<13; i++) {
|
|
||||||
s->write(*(dataPtr+i)>>1);
|
|
||||||
}
|
|
||||||
// SSID
|
|
||||||
s->write('-');
|
|
||||||
s->print((*(dataPtr+13) >> 1) & 0xF);
|
|
||||||
s->print(F(" -> "));
|
|
||||||
// First 6 bytes are destination callsign
|
|
||||||
for(i=0; i<6; i++) {
|
|
||||||
s->write(*(dataPtr+i)>>1);
|
|
||||||
}
|
|
||||||
// SSID
|
|
||||||
s->write('-');
|
|
||||||
s->print((*(dataPtr+6) >> 1) & 0xF);
|
|
||||||
// Control/PID next two bytes
|
|
||||||
// Skip those, print payload
|
|
||||||
for(i = 15; i<len; i++) {
|
|
||||||
s->write(*(dataPtr+i));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine what we want to do on this ADC tick.
|
|
||||||
void AFSK::timer() {
|
|
||||||
static uint8_t tcnt = 0;
|
|
||||||
if(++tcnt == T_BIT && encoder.isSending()) {
|
|
||||||
PORTD |= _BV(6);
|
|
||||||
// Only run the encoder every 8th tick
|
|
||||||
// This is actually DDS RefClk / 1200 = 8, set as T_BIT
|
|
||||||
// A different refclk needs a different value
|
|
||||||
encoder.process();
|
|
||||||
tcnt = 0;
|
|
||||||
PORTD &= ~_BV(6);
|
|
||||||
} else {
|
|
||||||
decoder.process(((int8_t)(ADCH - 128)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AFSK::start(DDS *dds) {
|
|
||||||
afskEnabled = true;
|
|
||||||
encoder.setDDS(dds);
|
|
||||||
decoder.start();
|
|
||||||
}
|
|
||||||
301
AFSK.h
301
AFSK.h
@@ -1,301 +0,0 @@
|
|||||||
#ifndef _AFSK_H_
|
|
||||||
#define _AFSK_H_
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <SimpleFIFO.h>
|
|
||||||
#include <DDS.h>
|
|
||||||
|
|
||||||
#define SAMPLERATE 9600
|
|
||||||
#define BITRATE 1200
|
|
||||||
|
|
||||||
#define SAMPLEPERBIT (SAMPLERATE / BITRATE)
|
|
||||||
|
|
||||||
#define RX_FIFO_LEN 16
|
|
||||||
|
|
||||||
#define PACKET_BUFFER_SIZE 2
|
|
||||||
#define PACKET_STATIC 0
|
|
||||||
|
|
||||||
// Enable the packet parser which will tokenize the AX25 frame into easy strings
|
|
||||||
#define PACKET_PARSER
|
|
||||||
|
|
||||||
// If this is set, all the packet buffers will be pre-allocated at compile time
|
|
||||||
// This will use more RAM, but can make it easier to do memory planning.
|
|
||||||
// TODO: Make this actually work right and not crash.
|
|
||||||
#define PACKET_PREALLOCATE
|
|
||||||
|
|
||||||
// This is with all the digis, two addresses, and full payload
|
|
||||||
// Dst(7) + Src(7) + Digis(56) + Ctl(1) + PID(1) + Data(0-256) + FCS(2)
|
|
||||||
#define PACKET_MAX_LEN 330
|
|
||||||
// Minimum is Dst + Src + Ctl + FCS
|
|
||||||
#define AX25_PACKET_HEADER_MINLEN 17
|
|
||||||
|
|
||||||
// HDLC framing bits
|
|
||||||
#define HDLC_FRAME 0x7E
|
|
||||||
#define HDLC_RESET 0x7F
|
|
||||||
#define HDLC_PREAMBLE 0x00
|
|
||||||
#define HDLC_ESCAPE 0x1B
|
|
||||||
#define HDLC_TAIL 0x1C
|
|
||||||
|
|
||||||
class AFSK {
|
|
||||||
private:
|
|
||||||
volatile bool afskEnabled;
|
|
||||||
public:
|
|
||||||
bool enabled() { return afskEnabled; };
|
|
||||||
|
|
||||||
class Packet:public Print {
|
|
||||||
public:
|
|
||||||
Packet():Print() {};
|
|
||||||
virtual size_t write(uint8_t);
|
|
||||||
// Stock virtual method does what we want here.
|
|
||||||
//virtual size_t write(const char *);
|
|
||||||
virtual size_t write(const uint8_t *, size_t);
|
|
||||||
using Print::write;
|
|
||||||
unsigned char ready : 1;
|
|
||||||
unsigned char type : 2;
|
|
||||||
unsigned char freeData : 1;
|
|
||||||
unsigned short len;
|
|
||||||
unsigned short maxLen;
|
|
||||||
//void init(uint8_t *buf, unsigned int dlen, bool freeData);
|
|
||||||
void init(unsigned short dlen);
|
|
||||||
inline void free() {
|
|
||||||
if(freeData)
|
|
||||||
::free(dataPtr);
|
|
||||||
}
|
|
||||||
inline const unsigned char getByte(void) {
|
|
||||||
return *readPos++;
|
|
||||||
}
|
|
||||||
inline const unsigned char getByte(uint16_t p) {
|
|
||||||
return *(dataPtr+p);
|
|
||||||
}
|
|
||||||
inline void start() {
|
|
||||||
fcs = 0xffff;
|
|
||||||
// No longer put an explicit frame start here
|
|
||||||
//*dataPos++ = HDLC_ESCAPE;
|
|
||||||
//*dataPos++ = HDLC_FRAME;
|
|
||||||
//len = 2;
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool append(char c) {
|
|
||||||
if(len < maxLen) {
|
|
||||||
++len;
|
|
||||||
*dataPos++ = c;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define UPDATE_FCS(d) e=fcs^(d); f=e^(e<<4); fcs=(fcs>>8)^(f<<8)^(f<<3)^(f>>4)
|
|
||||||
//#define UPDATE_FCS(d) s=(d)^(fcs>>8); t=s^(s>>4); fcs=(fcs<<8)^t^(t<<5)^(t<<12)
|
|
||||||
inline bool appendFCS(unsigned char c) {
|
|
||||||
register unsigned char e, f;
|
|
||||||
if(len < maxLen - 4) { // Leave room for FCS/HDLC
|
|
||||||
append(c);
|
|
||||||
UPDATE_FCS(c);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t appendCallsign(const char *callsign, uint8_t ssid, bool final = false);
|
|
||||||
|
|
||||||
inline void finish() {
|
|
||||||
append(~(fcs & 0xff));
|
|
||||||
append(~((fcs>>8) & 0xff));
|
|
||||||
// No longer append the frame boundaries themselves
|
|
||||||
//append(HDLC_ESCAPE);
|
|
||||||
//append(HDLC_FRAME);
|
|
||||||
ready = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void clear() {
|
|
||||||
fcs = 0xffff;
|
|
||||||
len = 0;
|
|
||||||
readPos = dataPtr;
|
|
||||||
dataPos = dataPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool crcOK() {
|
|
||||||
return (fcs == 0xF0B8);
|
|
||||||
}
|
|
||||||
#ifdef PACKET_PARSER
|
|
||||||
bool parsePacket();
|
|
||||||
#endif
|
|
||||||
void printPacket(Stream *s);
|
|
||||||
private:
|
|
||||||
#ifdef PACKET_PREALLOCATE
|
|
||||||
uint8_t dataPtr[PACKET_MAX_LEN]; // 256 byte I frame + headers max of 78
|
|
||||||
#else
|
|
||||||
uint8_t *dataPtr;
|
|
||||||
#endif
|
|
||||||
#ifdef PACKET_PARSER
|
|
||||||
char srcCallsign[7];
|
|
||||||
uint8_t srcSSID;
|
|
||||||
char dstCallsign[7];
|
|
||||||
uint8_t dstSSID;
|
|
||||||
char digipeater[8][7];
|
|
||||||
uint8_t digipeaterSSID[8];
|
|
||||||
uint8_t *iFrameData;
|
|
||||||
uint8_t length;
|
|
||||||
uint8_t control;
|
|
||||||
uint8_t pid;
|
|
||||||
#endif
|
|
||||||
uint8_t *dataPos, *readPos;
|
|
||||||
unsigned short fcs;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class PacketBuffer {
|
|
||||||
public:
|
|
||||||
// Initialize the buffers
|
|
||||||
PacketBuffer();
|
|
||||||
// How many packets are in the buffer?
|
|
||||||
unsigned char count() volatile { return inBuffer; };
|
|
||||||
// And how many of those are ready?
|
|
||||||
unsigned char readyCount() volatile;
|
|
||||||
// Retrieve the next packet
|
|
||||||
Packet *getPacket() volatile;
|
|
||||||
// Create a packet structure as needed
|
|
||||||
// This does not place it in the queue
|
|
||||||
static Packet *makePacket(unsigned short);
|
|
||||||
// Conveniently free packet memory
|
|
||||||
static void freePacket(Packet *);
|
|
||||||
// Place a packet into the buffer
|
|
||||||
bool putPacket(Packet *) volatile;
|
|
||||||
private:
|
|
||||||
volatile unsigned char inBuffer;
|
|
||||||
Packet * volatile packets[PACKET_BUFFER_SIZE];
|
|
||||||
volatile unsigned char nextPacketIn;
|
|
||||||
volatile unsigned char nextPacketOut;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Encoder {
|
|
||||||
public:
|
|
||||||
Encoder() {
|
|
||||||
randomWait = 1000; // At the very begin, wait at least one second
|
|
||||||
sending = false;
|
|
||||||
done = true;
|
|
||||||
packet = 0x0;
|
|
||||||
currentBytePos = 0;
|
|
||||||
nextByte = 0;
|
|
||||||
}
|
|
||||||
void setDDS(DDS *d) { dds = d; }
|
|
||||||
volatile inline bool isSending() volatile {
|
|
||||||
return sending;
|
|
||||||
}
|
|
||||||
volatile inline bool isDone() volatile {
|
|
||||||
return done;
|
|
||||||
}
|
|
||||||
volatile inline bool hasPackets() volatile {
|
|
||||||
return (pBuf.count() > 0);
|
|
||||||
}
|
|
||||||
inline bool putPacket(Packet *packet) {
|
|
||||||
return pBuf.putPacket(packet);
|
|
||||||
}
|
|
||||||
inline void setRandomWait() {
|
|
||||||
randomWait = 250 + (rand() % 1000) + millis();
|
|
||||||
}
|
|
||||||
bool start();
|
|
||||||
void stop();
|
|
||||||
void process();
|
|
||||||
private:
|
|
||||||
volatile bool sending;
|
|
||||||
byte currentByte;
|
|
||||||
byte currentBit : 1;
|
|
||||||
byte currentTone : 1;
|
|
||||||
byte lastZero : 3;
|
|
||||||
byte bitPosition : 3;
|
|
||||||
byte preamble : 6;
|
|
||||||
//byte bitClock;
|
|
||||||
bool hdlc;
|
|
||||||
byte nextByte;
|
|
||||||
byte maxTx;
|
|
||||||
Packet *packet;
|
|
||||||
PacketBuffer pBuf;
|
|
||||||
unsigned int currentBytePos;
|
|
||||||
volatile unsigned long randomWait;
|
|
||||||
volatile bool done;
|
|
||||||
DDS *dds;
|
|
||||||
};
|
|
||||||
|
|
||||||
class HDLCDecode {
|
|
||||||
public:
|
|
||||||
bool hdlcParse(bool, SimpleFIFO<uint8_t,RX_FIFO_LEN> *fifo);
|
|
||||||
volatile bool rxstart;
|
|
||||||
private:
|
|
||||||
uint8_t demod_bits;
|
|
||||||
uint8_t bit_idx;
|
|
||||||
uint8_t currchar;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Decoder {
|
|
||||||
public:
|
|
||||||
Decoder();
|
|
||||||
void start();
|
|
||||||
bool read();
|
|
||||||
void process(int8_t);
|
|
||||||
inline bool dataAvailable() {
|
|
||||||
return (rx_fifo.count() > 0);
|
|
||||||
}
|
|
||||||
inline uint8_t getByte() {
|
|
||||||
return rx_fifo.dequeue();
|
|
||||||
}
|
|
||||||
inline uint8_t packetCount() volatile {
|
|
||||||
return pBuf.count();
|
|
||||||
}
|
|
||||||
inline Packet *getPacket() {
|
|
||||||
return pBuf.getPacket();
|
|
||||||
}
|
|
||||||
inline bool isReceiving() volatile {
|
|
||||||
return hdlc.rxstart;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
Packet *currentPacket;
|
|
||||||
//SimpleFIFO<int8_t,SAMPLEPERBIT/2+1> delay_fifo;
|
|
||||||
SimpleFIFO<uint8_t,RX_FIFO_LEN> rx_fifo; // This should be drained fairly often
|
|
||||||
int16_t iir_x[2];
|
|
||||||
int16_t iir_y[2];
|
|
||||||
uint8_t sampled_bits;
|
|
||||||
int8_t curr_phase;
|
|
||||||
uint8_t found_bits;
|
|
||||||
PacketBuffer pBuf;
|
|
||||||
HDLCDecode hdlc;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline bool read() {
|
|
||||||
return decoder.read();
|
|
||||||
}
|
|
||||||
volatile inline bool txReady() volatile {
|
|
||||||
if(encoder.isDone() && encoder.hasPackets())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
volatile inline bool isDone() volatile { return encoder.isDone(); }
|
|
||||||
inline bool txStart() {
|
|
||||||
if(decoder.isReceiving()) {
|
|
||||||
encoder.setRandomWait();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return encoder.start();
|
|
||||||
}
|
|
||||||
inline bool putTXPacket(Packet *packet) {
|
|
||||||
bool ret = encoder.putPacket(packet);
|
|
||||||
if(!ret) // No room?
|
|
||||||
PacketBuffer::freePacket(packet);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
inline Packet *getRXPacket() {
|
|
||||||
return decoder.getPacket();
|
|
||||||
}
|
|
||||||
inline uint8_t rxPacketCount() volatile {
|
|
||||||
return decoder.packetCount();
|
|
||||||
}
|
|
||||||
//unsigned long lastTx;
|
|
||||||
//unsigned long lastRx;
|
|
||||||
void start(DDS *);
|
|
||||||
void timer();
|
|
||||||
Encoder encoder;
|
|
||||||
Decoder decoder;
|
|
||||||
};
|
|
||||||
#endif /* _AFSK_H_ */
|
|
||||||
175
DDS.cpp
175
DDS.cpp
@@ -1,175 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include "DDS.h"
|
|
||||||
|
|
||||||
// To start the DDS, we use Timer1, set to the reference clock
|
|
||||||
// We use Timer2 for the PWM output, running as fast as feasible
|
|
||||||
void DDS::start() {
|
|
||||||
// Use the clkIO clock rate
|
|
||||||
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
|
|
||||||
|
|
||||||
// First, the timer for the PWM output
|
|
||||||
// Setup the timer to use OC2B (pin 3) in fast PWM mode with a configurable top
|
|
||||||
// Run it without the prescaler
|
|
||||||
#ifdef DDS_PWM_PIN_3
|
|
||||||
TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0)) |
|
|
||||||
_BV(WGM21) | _BV(WGM20);
|
|
||||||
TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20) | _BV(WGM22);
|
|
||||||
#else
|
|
||||||
// Alternatively, use pin 11
|
|
||||||
// Enable output compare on OC2A, toggle mode
|
|
||||||
TCCR2A = _BV(COM2A1) | _BV(WGM21) | _BV(WGM20);
|
|
||||||
//TCCR2A = (TCCR2A | _BV(COM2A1)) & ~(_BV(COM2A0) | _BV(COM2B1) | _BV(COM2B0)) |
|
|
||||||
// _BV(WGM21) | _BV(WGM20);
|
|
||||||
TCCR2B = _BV(CS20);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set the top limit, which will be our duty cycle accuracy.
|
|
||||||
// Setting Comparator Bits smaller will allow for higher frequency PWM,
|
|
||||||
// with the loss of resolution.
|
|
||||||
#ifdef DDS_PWM_PIN_3
|
|
||||||
OCR2A = pow(2,COMPARATOR_BITS)-1;
|
|
||||||
OCR2B = 0;
|
|
||||||
#else
|
|
||||||
OCR2A = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DDS_USE_ONLY_TIMER2
|
|
||||||
TIMSK2 |= _BV(TOIE2);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Second, setup Timer1 to trigger the ADC interrupt
|
|
||||||
// This lets us use decoding functions that run at the same reference
|
|
||||||
// clock as the DDS.
|
|
||||||
// We use ICR1 as TOP and prescale by 8
|
|
||||||
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
|
|
||||||
TCCR1A = 0;
|
|
||||||
ICR1 = ((F_CPU / 1) / refclk) - 1;
|
|
||||||
#ifdef DDS_DEBUG_SERIAL
|
|
||||||
Serial.print(F("DDS SysClk: "));
|
|
||||||
Serial.println(F_CPU/8);
|
|
||||||
Serial.print(F("DDS RefClk: "));
|
|
||||||
Serial.println(refclk, DEC);
|
|
||||||
Serial.print(F("DDS ICR1: "));
|
|
||||||
Serial.println(ICR1, DEC);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Configure the ADC here to automatically run and be triggered off Timer1
|
|
||||||
ADMUX = _BV(REFS0) | _BV(ADLAR) | 0; // Channel 0, shift result left (ADCH used)
|
|
||||||
DDRC &= ~_BV(0);
|
|
||||||
PORTC &= ~_BV(0);
|
|
||||||
DIDR0 |= _BV(0);
|
|
||||||
ADCSRB = _BV(ADTS2) | _BV(ADTS1) | _BV(ADTS0);
|
|
||||||
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADIE) | _BV(ADPS2); // | _BV(ADPS0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DDS::stop() {
|
|
||||||
// TODO: Stop the timers.
|
|
||||||
#ifndef DDS_USE_ONLY_TIMER2
|
|
||||||
TCCR1B = 0;
|
|
||||||
#endif
|
|
||||||
TCCR2B = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set our current sine wave frequency in Hz
|
|
||||||
ddsAccumulator_t DDS::calcFrequency(unsigned short freq) {
|
|
||||||
// Fo = (M*Fc)/2^N
|
|
||||||
// M = (Fo/Fc)*2^N
|
|
||||||
ddsAccumulator_t newStep;
|
|
||||||
if(refclk == DDS_REFCLK_DEFAULT) {
|
|
||||||
// Try to use precalculated values if possible
|
|
||||||
if(freq == 2200) {
|
|
||||||
newStep = (2200.0 / (DDS_REFCLK_DEFAULT+DDS_REFCLK_OFFSET)) * pow(2,ACCUMULATOR_BITS);
|
|
||||||
} else if (freq == 1200) {
|
|
||||||
newStep = (1200.0 / (DDS_REFCLK_DEFAULT+DDS_REFCLK_OFFSET)) * pow(2,ACCUMULATOR_BITS);
|
|
||||||
} else if(freq == 2400) {
|
|
||||||
newStep = (2400.0 / (DDS_REFCLK_DEFAULT+DDS_REFCLK_OFFSET)) * pow(2,ACCUMULATOR_BITS);
|
|
||||||
} else if (freq == 1500) {
|
|
||||||
newStep = (1500.0 / (DDS_REFCLK_DEFAULT+DDS_REFCLK_OFFSET)) * pow(2,ACCUMULATOR_BITS);
|
|
||||||
} else if (freq == 600) {
|
|
||||||
newStep = (600.0 / (DDS_REFCLK_DEFAULT+DDS_REFCLK_OFFSET)) * pow(2,ACCUMULATOR_BITS);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newStep = pow(2,ACCUMULATOR_BITS)*freq / (refclk+refclkOffset);
|
|
||||||
}
|
|
||||||
return newStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Degrees should be between -360 and +360 (others don't make much sense)
|
|
||||||
void DDS::setPhaseDeg(int16_t degrees) {
|
|
||||||
accumulator = degrees * (pow(2,ACCUMULATOR_BITS)/360.0);
|
|
||||||
}
|
|
||||||
void DDS::changePhaseDeg(int16_t degrees) {
|
|
||||||
accumulator += degrees * (pow(2,ACCUMULATOR_BITS)/360.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Clean this up a bit..
|
|
||||||
void DDS::clockTick() {
|
|
||||||
/* if(running) {
|
|
||||||
accumulator += stepRate;
|
|
||||||
OCR2A = getDutyCycle();
|
|
||||||
}
|
|
||||||
return;*/
|
|
||||||
if(running) {
|
|
||||||
accumulator += stepRate;
|
|
||||||
if(timeLimited && tickDuration == 0) {
|
|
||||||
#ifndef DDS_PWM_PIN_3
|
|
||||||
OCR2A = 0;
|
|
||||||
#else
|
|
||||||
#ifdef DDS_IDLE_HIGH
|
|
||||||
// Set the duty cycle to 50%
|
|
||||||
OCR2B = pow(2,COMPARATOR_BITS)/2;
|
|
||||||
#else
|
|
||||||
// Set duty cycle to 0, effectively off
|
|
||||||
OCR2B = 0;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
running = false;
|
|
||||||
accumulator = 0;
|
|
||||||
} else {
|
|
||||||
#ifdef DDS_PWM_PIN_3
|
|
||||||
OCR2B = getDutyCycle();
|
|
||||||
#else
|
|
||||||
OCR2A = getDutyCycle();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
// Reduce our playback duration by one tick
|
|
||||||
tickDuration--;
|
|
||||||
} else {
|
|
||||||
// Hold it low
|
|
||||||
#ifndef DDS_PWM_PIN_3
|
|
||||||
OCR2A = 0;
|
|
||||||
#else
|
|
||||||
#ifdef DDS_IDLE_HIGH
|
|
||||||
// Set the duty cycle to 50%
|
|
||||||
OCR2B = pow(2,COMPARATOR_BITS)/2;
|
|
||||||
#else
|
|
||||||
// Set duty cycle to 0, effectively off
|
|
||||||
OCR2B = 0;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t DDS::getDutyCycle() {
|
|
||||||
#if ACCUMULATOR_BIT_SHIFT >= 24
|
|
||||||
uint16_t phAng;
|
|
||||||
#else
|
|
||||||
uint8_t phAng;
|
|
||||||
#endif
|
|
||||||
if(amplitude == 0) // Shortcut out on no amplitude
|
|
||||||
return 128>>(8-COMPARATOR_BITS);
|
|
||||||
phAng = (accumulator >> ACCUMULATOR_BIT_SHIFT);
|
|
||||||
int8_t position = pgm_read_byte_near(ddsSineTable + phAng); //>>(8-COMPARATOR_BITS);
|
|
||||||
// Apply scaling and return
|
|
||||||
int16_t scaled = position;
|
|
||||||
// output = ((duty * amplitude) / 256) + 128
|
|
||||||
// This keeps amplitudes centered around 50% duty
|
|
||||||
if(amplitude != 255) { // Amplitude is reduced, so do the full math
|
|
||||||
scaled *= amplitude;
|
|
||||||
scaled >>= 8+(8-COMPARATOR_BITS);
|
|
||||||
} else { // Otherwise, only shift for the comparator bits
|
|
||||||
scaled >>= (8-COMPARATOR_BITS);
|
|
||||||
}
|
|
||||||
scaled += 128>>(8-COMPARATOR_BITS);
|
|
||||||
return scaled;
|
|
||||||
}
|
|
||||||
228
DDS.h
228
DDS.h
@@ -1,228 +0,0 @@
|
|||||||
#ifndef _DDS_H_
|
|
||||||
#define _DDS_H_
|
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
|
||||||
|
|
||||||
// Use pin 3 for PWM? If not defined, use pin 11
|
|
||||||
// Quality on pin 3 is higher than on 11, as it can be clocked faster
|
|
||||||
// when the COMPARATOR_BITS value is less than 8
|
|
||||||
#define DDS_PWM_PIN_3
|
|
||||||
|
|
||||||
// Normally, we turn on timer2 and timer1, and have ADC sampling as our clock
|
|
||||||
// Define this to only use Timer2, and not start the ADC clock
|
|
||||||
// #define DDS_USE_ONLY_TIMER2
|
|
||||||
|
|
||||||
// Use a short (16 bit) accumulator. Phase accuracy is reduced, but speed
|
|
||||||
// is increased, along with a reduction in memory use.
|
|
||||||
#define SHORT_ACCUMULATOR
|
|
||||||
|
|
||||||
#ifdef SHORT_ACCUMULATOR
|
|
||||||
#define ACCUMULATOR_BITS 16
|
|
||||||
typedef uint16_t ddsAccumulator_t;
|
|
||||||
#else
|
|
||||||
#define ACCUMULATOR_BITS 32
|
|
||||||
typedef uint32_t ddsAccumulator_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If defined, the timer will idle at 50% duty cycle
|
|
||||||
// This leaves it floating in the centre of the PWM/DAC voltage range
|
|
||||||
#define DDS_IDLE_HIGH
|
|
||||||
|
|
||||||
// Select how fast the PWM is, at the expense of level accuracy.
|
|
||||||
// A faster PWM rate will make for easier filtering of the output wave,
|
|
||||||
// while a slower one will allow for more accurate voltage level outputs,
|
|
||||||
// but will increase the filtering requirements on the output.
|
|
||||||
// 8 = 62.5kHz PWM
|
|
||||||
// 7 = 125kHz PWM
|
|
||||||
// 6 = 250kHz PWM
|
|
||||||
#ifdef DDS_PWM_PIN_3
|
|
||||||
#define COMPARATOR_BITS 6
|
|
||||||
#else // When using pin 11, we always want 8 bits
|
|
||||||
#define COMPARATOR_BITS 8
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This is how often we'll perform a phase advance, as well as ADC sampling
|
|
||||||
// rate. The higher this value, the smoother the output wave will be, at the
|
|
||||||
// expense of CPU time. It maxes out around 62000 (TBD)
|
|
||||||
// May be overridden in the sketch to improve performance
|
|
||||||
#ifndef DDS_REFCLK_DEFAULT
|
|
||||||
#define DDS_REFCLK_DEFAULT 9600
|
|
||||||
#endif
|
|
||||||
// As each Arduino crystal is a little different, this can be fine tuned to
|
|
||||||
// provide more accurate frequencies. Adjustments in the range of hundreds
|
|
||||||
// is a good start.
|
|
||||||
#ifndef DDS_REFCLK_OFFSET
|
|
||||||
#define DDS_REFCLK_OFFSET 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DDS_USE_ONLY_TIMER2
|
|
||||||
// TODO: Figure out where this clock value is generated from
|
|
||||||
#define DDS_REFCLK_DEFAULT (62500/4)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Output some of the calculations and information about the DDS over serial
|
|
||||||
//#define DDS_DEBUG_SERIAL
|
|
||||||
|
|
||||||
// When defined, use the 1024 element sine lookup table. This improves phase
|
|
||||||
// accuracy, at the cost of more flash and CPU requirements.
|
|
||||||
// #define DDS_TABLE_LARGE
|
|
||||||
|
|
||||||
#ifdef DDS_TABLE_LARGE
|
|
||||||
// How many bits to keep from the accumulator to look up in this table
|
|
||||||
#define ACCUMULATOR_BIT_SHIFT (ACCUMULATOR_BITS-10)
|
|
||||||
static const int8_t ddsSineTable[1024] PROGMEM = {
|
|
||||||
0, 0, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 24,
|
|
||||||
24, 25, 26, 27, 27, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 39, 39, 40, 41, 42, 42, 43, 44, 44, 45, 46, 47, 47,
|
|
||||||
48, 49, 50, 50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 57, 58, 59, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69,
|
|
||||||
70, 71, 71, 72, 73, 73, 74, 75, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85, 85, 86, 87, 87, 88, 88, 89,
|
|
||||||
89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 95, 96, 96, 97, 97, 98, 98, 99, 99, 100, 100, 101, 101, 102, 102, 102, 103, 103, 104, 104, 105,
|
|
||||||
105, 106, 106, 106, 107, 107, 108, 108, 108, 109, 109, 110, 110, 110, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117,
|
|
||||||
117, 117, 117, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 124, 124, 124,
|
|
||||||
124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
|
||||||
127, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 125, 125, 125, 125, 125, 125, 125, 125, 124, 124, 124,
|
|
||||||
124, 124, 124, 124, 123, 123, 123, 123, 123, 123, 122, 122, 122, 122, 121, 121, 121, 121, 121, 120, 120, 120, 120, 119, 119, 119, 119, 118, 118, 118, 117, 117,
|
|
||||||
117, 117, 116, 116, 116, 115, 115, 115, 114, 114, 114, 113, 113, 113, 112, 112, 112, 111, 111, 110, 110, 110, 109, 109, 108, 108, 108, 107, 107, 106, 106, 106,
|
|
||||||
105, 105, 104, 104, 103, 103, 102, 102, 102, 101, 101, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 91, 91, 90, 90,
|
|
||||||
89, 89, 88, 88, 87, 87, 86, 85, 85, 84, 84, 83, 82, 82, 81, 81, 80, 79, 79, 78, 78, 77, 76, 76, 75, 75, 74, 73, 73, 72, 71, 71,
|
|
||||||
70, 69, 69, 68, 67, 67, 66, 65, 65, 64, 63, 63, 62, 61, 61, 60, 59, 59, 58, 57, 57, 56, 55, 55, 54, 53, 52, 52, 51, 50, 50, 49,
|
|
||||||
48, 47, 47, 46, 45, 44, 44, 43, 42, 42, 41, 40, 39, 39, 38, 37, 36, 36, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28, 27, 27, 26, 25,
|
|
||||||
24, 24, 23, 22, 21, 20, 20, 19, 18, 17, 17, 16, 15, 14, 13, 13, 12, 11, 10, 10, 9, 8, 7, 7, 6, 5, 4, 3, 3, 2, 1, 0,
|
|
||||||
0, 0, -1, -2, -3, -3, -4, -5, -6, -7, -7, -8, -9, -10, -10, -11, -12, -13, -13, -14, -15, -16, -17, -17, -18, -19, -20, -20, -21, -22, -23, -24,
|
|
||||||
-24, -25, -26, -27, -27, -28, -29, -30, -30, -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, -39, -39, -40, -41, -42, -42, -43, -44, -44, -45, -46, -47, -47,
|
|
||||||
-48, -49, -50, -50, -51, -52, -52, -53, -54, -55, -55, -56, -57, -57, -58, -59, -59, -60, -61, -61, -62, -63, -63, -64, -65, -65, -66, -67, -67, -68, -69, -69,
|
|
||||||
-70, -71, -71, -72, -73, -73, -74, -75, -75, -76, -76, -77, -78, -78, -79, -79, -80, -81, -81, -82, -82, -83, -84, -84, -85, -85, -86, -87, -87, -88, -88, -89,
|
|
||||||
-89, -90, -90, -91, -91, -92, -93, -93, -94, -94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100, -100, -101, -101, -102, -102, -102, -103, -103, -104, -104, -105,
|
|
||||||
-105, -106, -106, -106, -107, -107, -108, -108, -108, -109, -109, -110, -110, -110, -111, -111, -112, -112, -112, -113, -113, -113, -114, -114, -114, -115, -115, -115, -116, -116, -116, -117,
|
|
||||||
-117, -117, -117, -118, -118, -118, -119, -119, -119, -119, -120, -120, -120, -120, -121, -121, -121, -121, -121, -122, -122, -122, -122, -123, -123, -123, -123, -123, -123, -124, -124, -124,
|
|
||||||
-124, -124, -124, -124, -125, -125, -125, -125, -125, -125, -125, -125, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126,
|
|
||||||
-127, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -125, -125, -125, -125, -125, -125, -125, -125, -124, -124, -124,
|
|
||||||
-124, -124, -124, -124, -123, -123, -123, -123, -123, -123, -122, -122, -122, -122, -121, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -119, -118, -118, -118, -117, -117,
|
|
||||||
-117, -117, -116, -116, -116, -115, -115, -115, -114, -114, -114, -113, -113, -113, -112, -112, -112, -111, -111, -110, -110, -110, -109, -109, -108, -108, -108, -107, -107, -106, -106, -106,
|
|
||||||
-105, -105, -104, -104, -103, -103, -102, -102, -102, -101, -101, -100, -100, -99, -99, -98, -98, -97, -97, -96, -96, -95, -95, -94, -94, -93, -93, -92, -91, -91, -90, -90,
|
|
||||||
-89, -89, -88, -88, -87, -87, -86, -85, -85, -84, -84, -83, -82, -82, -81, -81, -80, -79, -79, -78, -78, -77, -76, -76, -75, -75, -74, -73, -73, -72, -71, -71,
|
|
||||||
-70, -69, -69, -68, -67, -67, -66, -65, -65, -64, -63, -63, -62, -61, -61, -60, -59, -59, -58, -57, -57, -56, -55, -55, -54, -53, -52, -52, -51, -50, -50, -49,
|
|
||||||
-48, -47, -47, -46, -45, -44, -44, -43, -42, -42, -41, -40, -39, -39, -38, -37, -36, -36, -35, -34, -33, -33, -32, -31, -30, -30, -29, -28, -27, -27, -26, -25,
|
|
||||||
-24, -24, -23, -22, -21, -20, -20, -19, -18, -17, -17, -16, -15, -14, -13, -13, -12, -11, -10, -10, -9, -8, -7, -7, -6, -5, -4, -3, -3, -2, -1, 0
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
#define ACCUMULATOR_BIT_SHIFT (ACCUMULATOR_BITS-8)
|
|
||||||
static const int8_t ddsSineTable[256] PROGMEM = {
|
|
||||||
0, 3, 6, 9, 12, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49,
|
|
||||||
51, 54, 57, 60, 63, 65, 68, 71, 73, 76, 78, 81, 83, 85, 88, 90,
|
|
||||||
92, 94, 96, 98, 100, 102, 104, 106, 107, 109, 111, 112, 113, 115,
|
|
||||||
116, 117, 118, 120, 121, 122, 122, 123, 124, 125, 125, 126, 126,
|
|
||||||
126, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 125, 125,
|
|
||||||
124, 123, 122, 122, 121, 120, 118, 117, 116, 115, 113, 112, 111,
|
|
||||||
109, 107, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 85, 83, 81,
|
|
||||||
78, 76, 73, 71, 68, 65, 63, 60, 57, 54, 51, 49, 46, 43, 40, 37,
|
|
||||||
34, 31, 28, 25, 22, 19, 16, 12, 9, 6, 3, 0, -3, -6, -9, -12, -16,
|
|
||||||
-19, -22, -25, -28, -31, -34, -37, -40, -43, -46, -49, -51, -54,
|
|
||||||
-57, -60, -63, -65, -68, -71, -73, -76, -78, -81, -83, -85, -88,
|
|
||||||
-90, -92, -94, -96, -98, -100, -102, -104, -106, -107, -109, -111,
|
|
||||||
-112, -113, -115, -116, -117, -118, -120, -121, -122, -122, -123,
|
|
||||||
-124, -125, -125, -126, -126, -126, -127, -127, -127, -127, -127,
|
|
||||||
-127, -127, -126, -126, -126, -125, -125, -124, -123, -122, -122,
|
|
||||||
-121, -120, -118, -117, -116, -115, -113, -112, -111, -109, -107,
|
|
||||||
-106, -104, -102, -100, -98, -96, -94, -92, -90, -88, -85, -83,
|
|
||||||
-81, -78, -76, -73, -71, -68, -65, -63, -60, -57, -54, -51, -49,
|
|
||||||
-46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -12, -9, -6, -3
|
|
||||||
};
|
|
||||||
#endif /* DDS_TABLE_LARGE */
|
|
||||||
|
|
||||||
class DDS {
|
|
||||||
public:
|
|
||||||
DDS(): refclk(DDS_REFCLK_DEFAULT), refclkOffset(DDS_REFCLK_OFFSET),
|
|
||||||
accumulator(0), running(false),
|
|
||||||
timeLimited(false), tickDuration(0), amplitude(255)
|
|
||||||
{};
|
|
||||||
|
|
||||||
// Start all of the timers needed
|
|
||||||
void start();
|
|
||||||
// Is the DDS presently producing a tone?
|
|
||||||
const bool isRunning() { return running; };
|
|
||||||
// Stop the DDS timers
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
// Start and stop the PWM output
|
|
||||||
void on() {
|
|
||||||
timeLimited = false;
|
|
||||||
running = true;
|
|
||||||
}
|
|
||||||
// Provide a duration in ms for the tone
|
|
||||||
void on(unsigned short duration) {
|
|
||||||
// Duration in ticks from milliseconds is:
|
|
||||||
// t = (1/refclk)
|
|
||||||
tickDuration = (unsigned long)((unsigned long)duration * (unsigned long)refclk) / 1000;
|
|
||||||
timeLimited = true;
|
|
||||||
running = true;
|
|
||||||
}
|
|
||||||
void off() {
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a tone for a specific amount of time
|
|
||||||
void play(unsigned short freq, unsigned short duration) {
|
|
||||||
setFrequency(freq);
|
|
||||||
on(duration);
|
|
||||||
}
|
|
||||||
// Blocking version
|
|
||||||
void playWait(unsigned short freq, unsigned short duration) {
|
|
||||||
play(freq, duration);
|
|
||||||
delay(duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use these to get some calculated values for specific frequencies
|
|
||||||
// or to get the current frequency stepping rate.
|
|
||||||
ddsAccumulator_t calcFrequency(unsigned short freq);
|
|
||||||
ddsAccumulator_t getPhaseAdvance() { return stepRate; };
|
|
||||||
|
|
||||||
// Our maximum clock isn't very high, so our highest
|
|
||||||
// frequency supported will fit in a short.
|
|
||||||
void setFrequency(unsigned short freq) { stepRate = calcFrequency(freq); };
|
|
||||||
void setPrecalcFrequency(ddsAccumulator_t freq) { stepRate = freq; };
|
|
||||||
|
|
||||||
// Handle phase shifts
|
|
||||||
void setPhaseDeg(int16_t degrees);
|
|
||||||
void changePhaseDeg(int16_t degrees);
|
|
||||||
|
|
||||||
// Adjustable reference clock. This shoud be done before the timers are
|
|
||||||
// started, or they will need to be restarted. Frequencies will need to
|
|
||||||
// be set again to use the new clock.
|
|
||||||
void setReferenceClock(unsigned long ref) {
|
|
||||||
refclk = ref;
|
|
||||||
}
|
|
||||||
unsigned long getReferenceClock() {
|
|
||||||
return refclk;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setReferenceOffset(int16_t offset) {
|
|
||||||
refclkOffset = offset;
|
|
||||||
}
|
|
||||||
int16_t getReferenceOffset() {
|
|
||||||
return refclkOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t getDutyCycle();
|
|
||||||
|
|
||||||
// Set a scaling factor. To keep things quick, this is a power of 2 value.
|
|
||||||
// Set it with 0 for lowest (which will be off), 8 is highest.
|
|
||||||
void setAmplitude(unsigned char amp) {
|
|
||||||
amplitude = amp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the function called by the ADC_vect ISR to produce the tones
|
|
||||||
void clockTick();
|
|
||||||
|
|
||||||
private:
|
|
||||||
volatile bool running;
|
|
||||||
volatile unsigned long tickDuration;
|
|
||||||
volatile bool timeLimited;
|
|
||||||
volatile unsigned char amplitude;
|
|
||||||
volatile ddsAccumulator_t accumulator;
|
|
||||||
volatile ddsAccumulator_t stepRate;
|
|
||||||
ddsAccumulator_t refclk;
|
|
||||||
int16_t refclkOffset;
|
|
||||||
static DDS *sDDS;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* _DDS_H_ */
|
|
||||||
88
KISS.cpp
88
KISS.cpp
@@ -1,88 +0,0 @@
|
|||||||
#include <HamShield.h>
|
|
||||||
#include "AFSK.h"
|
|
||||||
#include "KISS.h"
|
|
||||||
|
|
||||||
//AFSK::Packet kissPacket;
|
|
||||||
bool inFrame = false;
|
|
||||||
uint8_t kissBuffer[PACKET_MAX_LEN];
|
|
||||||
uint16_t kissLen = 0;
|
|
||||||
|
|
||||||
// Inside the KISS loop, we basically wait for data to come in from the
|
|
||||||
// KISS equipment, and look if we have anything to relay along
|
|
||||||
void KISS::loop() {
|
|
||||||
static bool currentlySending = false;
|
|
||||||
if(radio->afsk.decoder.read() || radio->afsk.rxPacketCount()) {
|
|
||||||
// A true return means something was put onto the packet FIFO
|
|
||||||
// If we actually have data packets in the buffer, process them all now
|
|
||||||
while(radio->afsk.rxPacketCount()) {
|
|
||||||
AFSK::Packet *packet = radio->afsk.getRXPacket();
|
|
||||||
if(packet) {
|
|
||||||
writePacket(packet);
|
|
||||||
AFSK::PacketBuffer::freePacket(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check if we have incoming data to turn into a packet
|
|
||||||
while(io->available()) {
|
|
||||||
uint8_t c = (uint8_t)io->read();
|
|
||||||
if(c == KISS_FEND) {
|
|
||||||
if(inFrame && kissLen > 0) {
|
|
||||||
int i;
|
|
||||||
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(PACKET_MAX_LEN);
|
|
||||||
packet->start();
|
|
||||||
for(i = 0; i < kissLen; i++) {
|
|
||||||
packet->appendFCS(kissBuffer[i]);
|
|
||||||
}
|
|
||||||
packet->finish();
|
|
||||||
radio->afsk.encoder.putPacket(packet);
|
|
||||||
}
|
|
||||||
kissLen = 0;
|
|
||||||
inFrame = false;
|
|
||||||
}
|
|
||||||
// We're inside the boundaries of a FEND
|
|
||||||
if(inFrame) {
|
|
||||||
// Unescape the incoming data
|
|
||||||
if(c == KISS_FESC) {
|
|
||||||
c = io->read();
|
|
||||||
if(c == KISS_TFESC) {
|
|
||||||
c = KISS_FESC;
|
|
||||||
} else {
|
|
||||||
c = KISS_FEND;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kissBuffer[kissLen++] = c;
|
|
||||||
}
|
|
||||||
if(kissLen == 0 && c != KISS_FEND) {
|
|
||||||
if((c & 0xf) == 0) // First byte<3:0> should be a 0, otherwise we're having options
|
|
||||||
inFrame = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(radio->afsk.txReady()) {
|
|
||||||
radio->setModeTransmit();
|
|
||||||
currentlySending = true;
|
|
||||||
if(!radio->afsk.txStart()) { // Unable to start for some reason
|
|
||||||
radio->setModeReceive();
|
|
||||||
currentlySending = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(currentlySending && radio->afsk.encoder.isDone()) {
|
|
||||||
radio->setModeReceive();
|
|
||||||
currentlySending = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KISS::writePacket(AFSK::Packet *p) {
|
|
||||||
int i;
|
|
||||||
io->write(KISS_FEND);
|
|
||||||
io->write((uint8_t)0); // Host to TNC port identifier
|
|
||||||
for(i = 0; i < p->len-2; i++) {
|
|
||||||
char c = p->getByte(i);
|
|
||||||
if(c == KISS_FEND || c == KISS_FESC) {
|
|
||||||
io->write(KISS_FESC);
|
|
||||||
io->write((c==KISS_FEND?KISS_TFEND:KISS_TFESC));
|
|
||||||
} else {
|
|
||||||
io->write(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
io->write(KISS_FEND);
|
|
||||||
}
|
|
||||||
35
KISS.h
35
KISS.h
@@ -1,35 +0,0 @@
|
|||||||
#ifndef _KISS_H_
|
|
||||||
#define _KISS_H_
|
|
||||||
|
|
||||||
#include <HamShield.h>
|
|
||||||
#include "AFSK.h"
|
|
||||||
|
|
||||||
#define KISS_FEND 0xC0
|
|
||||||
#define KISS_FESC 0xDB
|
|
||||||
#define KISS_TFEND 0xDC
|
|
||||||
#define KISS_TFESC 0xDD
|
|
||||||
|
|
||||||
class KISS {
|
|
||||||
public:
|
|
||||||
KISS(Stream *_io, HamShield *h, DDS *d) : io(_io), radio(h), dds(d) {}
|
|
||||||
bool read();
|
|
||||||
void writePacket(AFSK::Packet *);
|
|
||||||
void loop();
|
|
||||||
inline void isr() {
|
|
||||||
static uint8_t tcnt = 0;
|
|
||||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
|
||||||
dds->clockTick();
|
|
||||||
if(++tcnt == (DDS_REFCLK_DEFAULT/9600)) {
|
|
||||||
//PORTD |= _BV(2); // Diagnostic pin (D2)
|
|
||||||
radio->afsk.timer();
|
|
||||||
tcnt = 0;
|
|
||||||
}
|
|
||||||
//PORTD &= ~(_BV(2));
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
Stream *io;
|
|
||||||
HamShield *radio;
|
|
||||||
DDS *dds;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* _KISS_H_ */
|
|
||||||
14
README.md
14
README.md
@@ -2,10 +2,20 @@
|
|||||||
|
|
||||||
The master branch is intended for use with HamShield hardware -09 and above.
|
The master branch is intended for use with HamShield hardware -09 and above.
|
||||||
|
|
||||||
HamShield Arduino Library and Example Sketches
|
WARNING: The dev branch is not guaranteed to work. Please use caution if you choose to use that branch.
|
||||||
|
|
||||||
|
# HamShield Arduino Library and Example Sketches
|
||||||
|
|
||||||
This repository is meant to be checked out into your Arduino application's libraries folder. After reloading the application, the library and example sketches should be available for use.
|
This repository is meant to be checked out into your Arduino application's libraries folder. After reloading the application, the library and example sketches should be available for use.
|
||||||
|
|
||||||
For overview, help, tricks, tips, and more, check out the wiki:
|
For overview, help, tricks, tips, and more, check out the wiki:
|
||||||
|
|
||||||
https://github.com/EnhancedRadioDevices/HamShield/wiki
|
https://github.com/EnhancedRadioDevices/HamShield/wiki
|
||||||
|
|
||||||
|
# KISS and AFSK
|
||||||
|
|
||||||
|
We've moved the KISS and AFSK code to a separate library to help keep memory usage in simple sketches down. To use the AFSK examples, please also install these libraries:
|
||||||
|
|
||||||
|
- https://github.com/EnhancedRadioDevices/DDS
|
||||||
|
- https://github.com/EnhancedRadioDevices/HamShield_KISS
|
||||||
|
|
||||||
|
|||||||
89
SimpleFIFO.h
89
SimpleFIFO.h
@@ -1,89 +0,0 @@
|
|||||||
#ifndef SimpleFIFO_h
|
|
||||||
#define SimpleFIFO_h
|
|
||||||
/*
|
|
||||||
||
|
|
||||||
|| @file SimpleFIFO.h
|
|
||||||
|| @version 1.2
|
|
||||||
|| @author Alexander Brevig
|
|
||||||
|| @contact alexanderbrevig@gmail.com
|
|
||||||
||
|
|
||||||
|| @description
|
|
||||||
|| | A simple FIFO class, mostly for primitive types but can be used with classes if assignment to int is allowed
|
|
||||||
|| | This FIFO is not dynamic, so be sure to choose an appropriate size for it
|
|
||||||
|| #
|
|
||||||
||
|
|
||||||
|| @license
|
|
||||||
|| | Copyright (c) 2010 Alexander Brevig
|
|
||||||
|| | This library is free software; you can redistribute it and/or
|
|
||||||
|| | modify it under the terms of the GNU Lesser General Public
|
|
||||||
|| | License as published by the Free Software Foundation; version
|
|
||||||
|| | 2.1 of the License.
|
|
||||||
|| |
|
|
||||||
|| | This library is distributed in the hope that it will be useful,
|
|
||||||
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
|| | Lesser General Public License for more details.
|
|
||||||
|| |
|
|
||||||
|| | You should have received a copy of the GNU Lesser General Public
|
|
||||||
|| | License along with this library; if not, write to the Free Software
|
|
||||||
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|| #
|
|
||||||
||
|
|
||||||
*/
|
|
||||||
template<typename T, int rawSize>
|
|
||||||
class SimpleFIFO {
|
|
||||||
public:
|
|
||||||
const int size; //speculative feature, in case it's needed
|
|
||||||
|
|
||||||
SimpleFIFO();
|
|
||||||
|
|
||||||
T dequeue(); //get next element
|
|
||||||
bool enqueue( T element ); //add an element
|
|
||||||
T peek() const; //get the next element without releasing it from the FIFO
|
|
||||||
void flush(); //[1.1] reset to default state
|
|
||||||
|
|
||||||
//how many elements are currently in the FIFO?
|
|
||||||
unsigned char count() { return numberOfElements; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
#ifndef SimpleFIFO_NONVOLATILE
|
|
||||||
volatile unsigned char numberOfElements;
|
|
||||||
volatile unsigned char nextIn;
|
|
||||||
volatile unsigned char nextOut;
|
|
||||||
volatile T raw[rawSize];
|
|
||||||
#else
|
|
||||||
unsigned char numberOfElements;
|
|
||||||
unsigned char nextIn;
|
|
||||||
unsigned char nextOut;
|
|
||||||
T raw[rawSize];
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T, int rawSize>
|
|
||||||
SimpleFIFO<T,rawSize>::SimpleFIFO() : size(rawSize) {
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
template<typename T, int rawSize>
|
|
||||||
bool SimpleFIFO<T,rawSize>::enqueue( T element ) {
|
|
||||||
if ( count() >= rawSize ) { return false; }
|
|
||||||
numberOfElements++;
|
|
||||||
nextIn %= size;
|
|
||||||
raw[nextIn] = element;
|
|
||||||
nextIn++; //advance to next index
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
template<typename T, int rawSize>
|
|
||||||
T SimpleFIFO<T,rawSize>::dequeue() {
|
|
||||||
numberOfElements--;
|
|
||||||
nextOut %= size;
|
|
||||||
return raw[ nextOut++];
|
|
||||||
}
|
|
||||||
template<typename T, int rawSize>
|
|
||||||
T SimpleFIFO<T,rawSize>::peek() const {
|
|
||||||
return raw[ nextOut % size];
|
|
||||||
}
|
|
||||||
template<typename T, int rawSize>
|
|
||||||
void SimpleFIFO<T,rawSize>::flush() {
|
|
||||||
nextIn = nextOut = numberOfElements = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
/* Serial glue to send messages over APRS
|
|
||||||
*
|
|
||||||
* To do: add message receive code
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#define DDS_REFCLK_DEFAULT 9600
|
|
||||||
|
|
||||||
#include <HamShield.h>
|
|
||||||
#include <avr/wdt.h>
|
|
||||||
|
|
||||||
#define PWM_PIN 3
|
|
||||||
#define RESET_PIN A3
|
|
||||||
#define SWITCH_PIN 2
|
|
||||||
|
|
||||||
|
|
||||||
HamShield radio;
|
|
||||||
DDS dds;
|
|
||||||
String messagebuff = "";
|
|
||||||
String origin_call = "";
|
|
||||||
String destination_call = "";
|
|
||||||
String textmessage = "";
|
|
||||||
int msgptr = 0;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
|
||||||
digitalWrite(PWM_PIN, LOW);
|
|
||||||
|
|
||||||
// prep the switch
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
||||||
|
|
||||||
// set up the reset control pin
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
|
||||||
// turn on pwr to the radio
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
radio.initialize();
|
|
||||||
radio.frequency(144390);
|
|
||||||
radio.setRfPower(0);
|
|
||||||
dds.start();
|
|
||||||
radio.afsk.start(&dds);
|
|
||||||
delay(100);
|
|
||||||
Serial.println("HELLO");
|
|
||||||
}
|
|
||||||
|
|
||||||
String temp[1] = "";
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
messagebuff = "KC7IBT,KC7IBT,:HAMSHIELD TEST";
|
|
||||||
prepMessage();
|
|
||||||
delay(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void prepMessage() {
|
|
||||||
radio.setModeTransmit();
|
|
||||||
delay(500);
|
|
||||||
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
|
|
||||||
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);
|
|
||||||
|
|
||||||
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
|
||||||
|
|
||||||
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 = radio.afsk.putTXPacket(packet);
|
|
||||||
|
|
||||||
if(radio.afsk.txReady()) {
|
|
||||||
Serial.println(F("txReady"));
|
|
||||||
radio.setModeTransmit();
|
|
||||||
//delay(100);
|
|
||||||
if(radio.afsk.txStart()) {
|
|
||||||
Serial.println(F("txStart"));
|
|
||||||
} else {
|
|
||||||
radio.setModeReceive();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Wait 2 seconds before we send our beacon again.
|
|
||||||
Serial.println("tick");
|
|
||||||
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
|
|
||||||
// TODO: This is hackery.
|
|
||||||
for(int i = 0; i < 500; i++) {
|
|
||||||
if(radio.afsk.encoder.isDone())
|
|
||||||
break;
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
Serial.println("Done sending");
|
|
||||||
delay(3000);
|
|
||||||
radio.setModeReceive();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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) {
|
|
||||||
static uint8_t tcnt = 0;
|
|
||||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
|
||||||
PORTD |= _BV(2); // Diagnostic pin (D2)
|
|
||||||
dds.clockTick();
|
|
||||||
if(++tcnt == 1) {
|
|
||||||
if(radio.afsk.encoder.isSending()) {
|
|
||||||
radio.afsk.timer();
|
|
||||||
}
|
|
||||||
tcnt = 0;
|
|
||||||
}
|
|
||||||
PORTD &= ~(_BV(2)); // Pin D2 off again
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
/* Serial glue to send messages over APRS
|
|
||||||
*
|
|
||||||
* To do: add message receive code
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#define DDS_REFCLK_DEFAULT 9600
|
|
||||||
|
|
||||||
#include <HamShield.h>
|
|
||||||
#include <avr/wdt.h>
|
|
||||||
|
|
||||||
#define PWM_PIN 3
|
|
||||||
#define RESET_PIN A3
|
|
||||||
#define SWITCH_PIN 2
|
|
||||||
|
|
||||||
HamShield radio;
|
|
||||||
DDS dds;
|
|
||||||
String messagebuff = "";
|
|
||||||
String origin_call = "";
|
|
||||||
String destination_call = "";
|
|
||||||
String textmessage = "";
|
|
||||||
int msgptr = 0;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
|
||||||
digitalWrite(PWM_PIN, LOW);
|
|
||||||
|
|
||||||
// prep the switch
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
||||||
|
|
||||||
// set up the reset control pin
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
|
||||||
// turn on the radio
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
radio.initialize();
|
|
||||||
radio.frequency(145570);
|
|
||||||
radio.setRfPower(0);
|
|
||||||
dds.start();
|
|
||||||
radio.afsk.start(&dds);
|
|
||||||
delay(100);
|
|
||||||
Serial.println("HELLO");
|
|
||||||
}
|
|
||||||
|
|
||||||
String temp[1] = "";
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if(Serial.available()) {
|
|
||||||
char temp = (char)Serial.read();
|
|
||||||
if(temp == '`') {
|
|
||||||
prepMessage(); msgptr = 0; Serial.print("!!"); }
|
|
||||||
else {
|
|
||||||
messagebuff += temp;
|
|
||||||
msgptr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(msgptr > 254) { messagebuff = ""; Serial.print("X!"); }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void prepMessage() {
|
|
||||||
radio.setModeTransmit();
|
|
||||||
delay(500);
|
|
||||||
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
|
|
||||||
textmessage = messagebuff.substring(messagebuff.indexOf(":"));
|
|
||||||
|
|
||||||
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
textmessage = "";
|
|
||||||
|
|
||||||
bool ret = radio.afsk.putTXPacket(packet);
|
|
||||||
|
|
||||||
if(radio.afsk.txReady()) {
|
|
||||||
Serial.println(F("txReady"));
|
|
||||||
//radio.setModeTransmit();
|
|
||||||
//delay(100);
|
|
||||||
if(radio.afsk.txStart()) {
|
|
||||||
Serial.println(F("txStart"));
|
|
||||||
} else {
|
|
||||||
radio.setModeReceive();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Wait 2 seconds before we send our beacon again.
|
|
||||||
Serial.println("tick");
|
|
||||||
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
|
|
||||||
// TODO: This is hackery.
|
|
||||||
for(int i = 0; i < 500; i++) {
|
|
||||||
if(radio.afsk.encoder.isDone())
|
|
||||||
break;
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
Serial.println("Done sending");
|
|
||||||
delay(3000);
|
|
||||||
radio.setModeReceive();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: d2 is now our switch, so don't write to that
|
|
||||||
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) {
|
|
||||||
static uint8_t tcnt = 0;
|
|
||||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
|
||||||
//PORTD |= _BV(2); // Diagnostic pin (D2)
|
|
||||||
dds.clockTick();
|
|
||||||
if(++tcnt == 1) {
|
|
||||||
if(radio.afsk.encoder.isSending()) {
|
|
||||||
radio.afsk.timer();
|
|
||||||
}
|
|
||||||
tcnt = 0;
|
|
||||||
}
|
|
||||||
//PORTD &= ~(_BV(2)); // Pin D2 off again
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
#include <HamShield.h>
|
|
||||||
|
|
||||||
HamShield radio;
|
|
||||||
DDS dds;
|
|
||||||
|
|
||||||
#define PWM_PIN 3
|
|
||||||
#define RESET_PIN A3
|
|
||||||
#define SWITCH_PIN 2
|
|
||||||
|
|
||||||
#define DON(p) PORTD |= _BV((p))
|
|
||||||
#define DOFF(p) PORTD &= ~(_BV((p)))
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(9600);
|
|
||||||
|
|
||||||
pinMode(4, OUTPUT);
|
|
||||||
pinMode(5, OUTPUT);
|
|
||||||
pinMode(6, OUTPUT);
|
|
||||||
pinMode(7, OUTPUT);
|
|
||||||
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
|
||||||
digitalWrite(PWM_PIN, LOW);
|
|
||||||
|
|
||||||
// prep the switch
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
||||||
|
|
||||||
// set up the reset control pin
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
|
||||||
// turn on pwr to the radio
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
Serial.println(F("Radio test connection"));
|
|
||||||
Serial.println(radio.testConnection(), DEC);
|
|
||||||
Serial.println(F("Initialize"));
|
|
||||||
delay(100);
|
|
||||||
radio.initialize();
|
|
||||||
Serial.println(F("Frequency"));
|
|
||||||
delay(100);
|
|
||||||
radio.frequency(145010);
|
|
||||||
//radio.setRfPower(0);
|
|
||||||
delay(100);
|
|
||||||
dds.start();
|
|
||||||
delay(100);
|
|
||||||
radio.afsk.start(&dds);
|
|
||||||
delay(100);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
DON(6);
|
|
||||||
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
|
||||||
packet->start();
|
|
||||||
packet->appendCallsign("VE6SLP",0);
|
|
||||||
packet->appendCallsign("VA6GA",15,true);
|
|
||||||
packet->appendFCS(0x03);
|
|
||||||
packet->appendFCS(0xf0);
|
|
||||||
packet->print(F("Hello "));
|
|
||||||
packet->print(millis());
|
|
||||||
packet->println(F("\r\nThis is a test of the HamShield Kickstarter prototype. de VE6SLP"));
|
|
||||||
packet->finish();
|
|
||||||
|
|
||||||
bool ret = radio.afsk.putTXPacket(packet);
|
|
||||||
|
|
||||||
if(radio.afsk.txReady()) {
|
|
||||||
Serial.println(F("txReady"));
|
|
||||||
radio.setModeTransmit();
|
|
||||||
if(radio.afsk.txStart()) {
|
|
||||||
Serial.println(F("txStart"));
|
|
||||||
} else {
|
|
||||||
Serial.println(F("Tx Start failure"));
|
|
||||||
radio.setModeReceive();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Wait 2 seconds before we send our beacon again.
|
|
||||||
Serial.println("tick");
|
|
||||||
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
|
|
||||||
// TODO: This is hackery.
|
|
||||||
DOFF(6);
|
|
||||||
for(int i = 0; i < 500; i++) {
|
|
||||||
if(radio.afsk.encoder.isDone())
|
|
||||||
break;
|
|
||||||
delay(50);
|
|
||||||
Serial.println("Not done");
|
|
||||||
}
|
|
||||||
Serial.println("Done sending");
|
|
||||||
delay(100);
|
|
||||||
radio.setModeReceive();
|
|
||||||
delay(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
ISR(ADC_vect) {
|
|
||||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
|
||||||
DON(4);
|
|
||||||
dds.clockTick();
|
|
||||||
DON(5);
|
|
||||||
radio.afsk.timer();
|
|
||||||
DOFF(5);
|
|
||||||
DOFF(4);
|
|
||||||
}
|
|
||||||
128
examples/AFSK_PacketTester/AFSK_PacketTester.ino
Normal file
128
examples/AFSK_PacketTester/AFSK_PacketTester.ino
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: AFSK Packet Tester
|
||||||
|
* This example sends AFSK test data. You will need a seperate
|
||||||
|
* AFSK receiver to test the output of this example.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, open the Serial Monitor to
|
||||||
|
* monitor the process of the HamShield. Check for output on
|
||||||
|
* AFSK receiver.
|
||||||
|
|
||||||
|
* Note: add message receive code
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DDS_REFCLK_DEFAULT 9600
|
||||||
|
|
||||||
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
#include <packet.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
#define PWM_PIN 3
|
||||||
|
#define RESET_PIN A3
|
||||||
|
#define SWITCH_PIN 2
|
||||||
|
|
||||||
|
HamShield radio;
|
||||||
|
DDS dds;
|
||||||
|
AFSK afsk;
|
||||||
|
String messagebuff = "";
|
||||||
|
String origin_call = "";
|
||||||
|
String destination_call = "";
|
||||||
|
String textmessage = "";
|
||||||
|
int msgptr = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
||||||
|
pinMode(PWM_PIN, OUTPUT);
|
||||||
|
digitalWrite(PWM_PIN, LOW);
|
||||||
|
|
||||||
|
// prep the switch
|
||||||
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// set up the reset control pin
|
||||||
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
|
// turn on pwr to the radio
|
||||||
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
radio.initialize();
|
||||||
|
radio.frequency(144390);
|
||||||
|
radio.setRfPower(0);
|
||||||
|
dds.start();
|
||||||
|
afsk.start(&dds);
|
||||||
|
delay(100);
|
||||||
|
Serial.println("HELLO");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
messagebuff = "KC7IBT,KC7IBT,:HAMSHIELD TEST";
|
||||||
|
prepMessage();
|
||||||
|
delay(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepMessage() {
|
||||||
|
radio.setModeTransmit();
|
||||||
|
delay(500);
|
||||||
|
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
|
||||||
|
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);
|
||||||
|
|
||||||
|
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if(afsk.txReady()) {
|
||||||
|
Serial.println(F("txReady"));
|
||||||
|
radio.setModeTransmit();
|
||||||
|
//delay(100);
|
||||||
|
if(afsk.txStart()) {
|
||||||
|
Serial.println(F("txStart"));
|
||||||
|
} else {
|
||||||
|
radio.setModeReceive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Wait 2 seconds before we send our beacon again.
|
||||||
|
Serial.println("tick");
|
||||||
|
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
|
||||||
|
// TODO: This is hackery.
|
||||||
|
for(int i = 0; i < 500; i++) {
|
||||||
|
if(afsk.encoder.isDone())
|
||||||
|
break;
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
Serial.println("Done sending");
|
||||||
|
radio.setModeReceive();
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(TIMER2_OVF_vect) {
|
||||||
|
TIFR2 = _BV(TOV2);
|
||||||
|
static uint8_t tcnt = 0;
|
||||||
|
if(++tcnt == 8) {
|
||||||
|
dds.clockTick();
|
||||||
|
tcnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(ADC_vect) {
|
||||||
|
static uint8_t tcnt = 0;
|
||||||
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
||||||
|
dds.clockTick();
|
||||||
|
if(++tcnt == 1) {
|
||||||
|
if(afsk.encoder.isSending()) {
|
||||||
|
afsk.timer();
|
||||||
|
}
|
||||||
|
tcnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
158
examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino
Normal file
158
examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: AFSK Serial Messenger
|
||||||
|
* Serial glue to send messages over APRS. You will need a
|
||||||
|
* seperate AFSK receiver to test the output of this example.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. After uploading this program
|
||||||
|
* to your Arduino, open the Serial Monitor to monitor. Type
|
||||||
|
* a message under 254 characters into the bar at the top of
|
||||||
|
* the monitor. Click the "Send" button. Check for output on
|
||||||
|
* AFSK receiver.
|
||||||
|
|
||||||
|
* NOTE: add message receive code
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
#include <packet.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
#define PWM_PIN 3
|
||||||
|
#define RESET_PIN A3
|
||||||
|
#define SWITCH_PIN 2
|
||||||
|
|
||||||
|
HamShield radio;
|
||||||
|
DDS dds;
|
||||||
|
AFSK afsk;
|
||||||
|
String messagebuff = "";
|
||||||
|
String origin_call = "";
|
||||||
|
String destination_call = "";
|
||||||
|
String textmessage = "";
|
||||||
|
int msgptr = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
||||||
|
pinMode(PWM_PIN, OUTPUT);
|
||||||
|
digitalWrite(PWM_PIN, LOW);
|
||||||
|
|
||||||
|
// prep the switch
|
||||||
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// set up the reset control pin
|
||||||
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
|
// turn on the radio
|
||||||
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
radio.initialize();
|
||||||
|
radio.frequency(145570);
|
||||||
|
radio.setRfPower(0);
|
||||||
|
radio.setVolume1(0xFF);
|
||||||
|
radio.setVolume2(0xFF);
|
||||||
|
radio.setSQHiThresh(-100);
|
||||||
|
radio.setSQLoThresh(-100);
|
||||||
|
radio.setSQOn();
|
||||||
|
dds.start();
|
||||||
|
afsk.start(&dds);
|
||||||
|
delay(100);
|
||||||
|
radio.setModeReceive();
|
||||||
|
Serial.println("HELLO");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if(Serial.available()) {
|
||||||
|
char temp = (char)Serial.read();
|
||||||
|
if(temp == '`') {
|
||||||
|
//Serial.println(messagebuff);
|
||||||
|
prepMessage();
|
||||||
|
msgptr = 0;
|
||||||
|
Serial.print("!!");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
messagebuff += temp;
|
||||||
|
msgptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(msgptr > 254) { messagebuff = ""; Serial.print("X!"); }
|
||||||
|
|
||||||
|
if(afsk.decoder.read() || afsk.rxPacketCount()) {
|
||||||
|
// A true return means something was put onto the packet FIFO
|
||||||
|
// If we actually have data packets in the buffer, process them all now
|
||||||
|
while(afsk.rxPacketCount()) {
|
||||||
|
AFSK::Packet *packet = afsk.getRXPacket();
|
||||||
|
Serial.print(F("Packet: "));
|
||||||
|
if(packet) {
|
||||||
|
packet->printPacket(&Serial);
|
||||||
|
AFSK::PacketBuffer::freePacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void prepMessage() {
|
||||||
|
radio.setModeTransmit();
|
||||||
|
delay(1000);
|
||||||
|
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
|
||||||
|
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);
|
||||||
|
|
||||||
|
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if(afsk.txReady()) {
|
||||||
|
Serial.println(F("txReady"));
|
||||||
|
radio.setModeTransmit();
|
||||||
|
//delay(100);
|
||||||
|
if(afsk.txStart()) {
|
||||||
|
Serial.println(F("txStart"));
|
||||||
|
} else {
|
||||||
|
radio.setModeReceive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Wait 2 seconds before we send our beacon again.
|
||||||
|
Serial.println("tick");
|
||||||
|
// Wait up to 2.5 seconds to finish sending, and stop transmitter.
|
||||||
|
// TODO: This is hackery.
|
||||||
|
for(int i = 0; i < 500; i++) {
|
||||||
|
if(afsk.encoder.isDone())
|
||||||
|
break;
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
Serial.println("Done sending");
|
||||||
|
radio.setModeReceive();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ISR(TIMER2_OVF_vect) {
|
||||||
|
TIFR2 = _BV(TOV2);
|
||||||
|
static uint8_t tcnt = 0;
|
||||||
|
if(++tcnt == 8) {
|
||||||
|
dds.clockTick();
|
||||||
|
tcnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(ADC_vect) {
|
||||||
|
static uint8_t tcnt = 0;
|
||||||
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
||||||
|
dds.clockTick();
|
||||||
|
if(++tcnt == 1) {
|
||||||
|
afsk.timer();
|
||||||
|
tcnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
examples/APRS-Beacon/1200.wav → examples/APRS_Beacon/1200.wav
Executable file → Normal file
0
examples/APRS-Beacon/1200.wav → examples/APRS_Beacon/1200.wav
Executable file → Normal file
0
examples/APRS-Beacon/2200.wav → examples/APRS_Beacon/2200.wav
Executable file → Normal file
0
examples/APRS-Beacon/2200.wav → examples/APRS_Beacon/2200.wav
Executable file → Normal file
@@ -1,4 +1,20 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: AX25 Receive
|
||||||
|
* This example receives AFSK test data. You will need seperate
|
||||||
|
* AFSK equipment to send data for this example.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones into
|
||||||
|
* the HamShield. Connect the Arduino to wall power and then to
|
||||||
|
* your computer via USB. After uploading this program to your
|
||||||
|
* Arduino, open the Serial Monitor so you will see the AFSK
|
||||||
|
* packet. Send AFSK packet from AFSK equipment at 145.01MHz.
|
||||||
|
|
||||||
|
* Note: add message receive code
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
#include <packet.h>
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
#define RESET_PIN A3
|
#define RESET_PIN A3
|
||||||
@@ -6,6 +22,7 @@
|
|||||||
|
|
||||||
HamShield radio;
|
HamShield radio;
|
||||||
DDS dds;
|
DDS dds;
|
||||||
|
AFSK afsk;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
||||||
@@ -29,22 +46,20 @@ void setup() {
|
|||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.frequency(145010);
|
radio.frequency(145010);
|
||||||
radio.setSQOff();
|
radio.setSQOff();
|
||||||
I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0b11111111);
|
|
||||||
Serial.println(F("Frequency"));
|
Serial.println(F("Frequency"));
|
||||||
|
Serial.println(radio.getFrequency());
|
||||||
delay(100);
|
delay(100);
|
||||||
Serial.print(F("Squelch(H/L): "));
|
Serial.print(F("Squelch(H/L): "));
|
||||||
Serial.print(radio.getSQHiThresh());
|
Serial.print(radio.getSQHiThresh());
|
||||||
Serial.print(F(" / "));
|
Serial.print(F(" / "));
|
||||||
Serial.println(radio.getSQLoThresh());
|
Serial.println(radio.getSQLoThresh());
|
||||||
radio.setModeReceive();
|
radio.setModeReceive();
|
||||||
Serial.print(F("RX? "));
|
|
||||||
Serial.println(radio.getRX());
|
|
||||||
Serial.println(F("DDS Start"));
|
Serial.println(F("DDS Start"));
|
||||||
delay(100);
|
delay(100);
|
||||||
dds.start();
|
dds.start();
|
||||||
Serial.println(F("AFSK start"));
|
Serial.println(F("AFSK start"));
|
||||||
delay(100);
|
delay(100);
|
||||||
radio.afsk.start(&dds);
|
afsk.start(&dds);
|
||||||
Serial.println(F("Starting..."));
|
Serial.println(F("Starting..."));
|
||||||
delay(100);
|
delay(100);
|
||||||
dds.setAmplitude(255);
|
dds.setAmplitude(255);
|
||||||
@@ -52,11 +67,11 @@ void setup() {
|
|||||||
|
|
||||||
uint32_t last = 0;
|
uint32_t last = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
if(radio.afsk.decoder.read() || radio.afsk.rxPacketCount()) {
|
if(afsk.decoder.read() || afsk.rxPacketCount()) {
|
||||||
// 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(radio.afsk.rxPacketCount()) {
|
while(afsk.rxPacketCount()) {
|
||||||
AFSK::Packet *packet = radio.afsk.getRXPacket();
|
AFSK::Packet *packet = afsk.getRXPacket();
|
||||||
Serial.print(F("Packet: "));
|
Serial.print(F("Packet: "));
|
||||||
if(packet) {
|
if(packet) {
|
||||||
packet->printPacket(&Serial);
|
packet->printPacket(&Serial);
|
||||||
@@ -72,6 +87,6 @@ ISR(ADC_vect) {
|
|||||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
||||||
//PORTD |= _BV(2); // Diagnostic pin (D2)
|
//PORTD |= _BV(2); // Diagnostic pin (D2)
|
||||||
//dds.clockTick();
|
//dds.clockTick();
|
||||||
radio.afsk.timer();
|
afsk.timer();
|
||||||
//PORTD &= ~(_BV(2)); // Pin D2 off again
|
//PORTD &= ~(_BV(2)); // Pin D2 off again
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: Crystal Calibration
|
||||||
|
* This example allows you to calibrate the crystal clock
|
||||||
|
* through the Arduino Serial Monitor.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, open the Serial Monitor.
|
||||||
|
* Make sure drop-down menu at the bottom of Serial Monitor
|
||||||
|
* is set to "Newline". Type 'h' into the bar at the top of
|
||||||
|
* the Serial Monitor and click the "Send" button for more
|
||||||
|
* instructions.
|
||||||
|
*/
|
||||||
|
|
||||||
#define DDS_REFCLK_DEFAULT 38400
|
#define DDS_REFCLK_DEFAULT 38400
|
||||||
#define DDS_REFCLK_OFFSET 0
|
#define DDS_REFCLK_OFFSET 0
|
||||||
#define DDS_DEBUG_SERIAL
|
#define DDS_DEBUG_SERIAL
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
#define RESET_PIN A3
|
#define RESET_PIN A3
|
||||||
@@ -28,7 +43,7 @@ void setup() {
|
|||||||
|
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
radio.setFrequency(145050);
|
radio.frequency(145050);
|
||||||
|
|
||||||
dds.start();
|
dds.start();
|
||||||
dds.setFrequency(1200);
|
dds.setFrequency(1200);
|
||||||
@@ -105,7 +120,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
while(Serial.available()) {
|
while(Serial.available()) {
|
||||||
char c = Serial.read();
|
char c = Serial.read();
|
||||||
Serial.print(c);
|
Serial.println(c);
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
Serial.println(F("Commands:"));
|
Serial.println(F("Commands:"));
|
||||||
|
|||||||
@@ -1,6 +1,18 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: DDS
|
||||||
|
* This is a simple example to show how to transmit arbitrary
|
||||||
|
* tones. In this case, the sketh alternates between 1200Hz
|
||||||
|
* and 2200Hz at 1s intervals.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. Upload this program
|
||||||
|
* to your Arduino. To test, set a HandyTalkie to 438MHz. You
|
||||||
|
* should hear two alternating tones.
|
||||||
|
*/
|
||||||
|
|
||||||
#define DDS_REFCLK_DEFAULT 9600
|
#define DDS_REFCLK_DEFAULT 9600
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
#define RESET_PIN A3
|
#define RESET_PIN A3
|
||||||
@@ -24,7 +36,7 @@ void setup() {
|
|||||||
|
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
radio.setFrequency(145060);
|
radio.frequency(438000);
|
||||||
radio.setModeTransmit();
|
radio.setModeTransmit();
|
||||||
dds.start();
|
dds.start();
|
||||||
dds.playWait(600, 3000);
|
dds.playWait(600, 3000);
|
||||||
@@ -48,10 +60,8 @@ ISR(ADC_vect) {
|
|||||||
static unsigned char tcnt = 0;
|
static unsigned char tcnt = 0;
|
||||||
TIFR1 = _BV(ICF1); // Clear the timer flag
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
||||||
if(++tcnt == 4) {
|
if(++tcnt == 4) {
|
||||||
//digitalWrite(2, HIGH);
|
|
||||||
tcnt = 0;
|
tcnt = 0;
|
||||||
}
|
}
|
||||||
dds.clockTick();
|
dds.clockTick();
|
||||||
//digitalWrite(2, LOW);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,18 +1,28 @@
|
|||||||
/*
|
/* Hamshield
|
||||||
Morse Code Beacon
|
* Example: Morse Code Beacon
|
||||||
|
* Test beacon will transmit and wait 30 seconds.
|
||||||
|
* Beacon will check to see if the channel is clear before it
|
||||||
|
* will transmit.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, open the Serial Monitor to
|
||||||
|
* monitor the status of the beacon. To test, set a HandyTalkie
|
||||||
|
* to 438MHz. You should hear the message " KC7IBT ARDUINO
|
||||||
|
* HAMSHIELD" in morse code.
|
||||||
|
|
||||||
Test beacon will transmit and wait 30 seconds.
|
* NOTE: Radio chip audio AGC too slow in responding to tones,
|
||||||
Beacon will check to see if the channel is clear before it will transmit.
|
* worked around by playing a 6khz tone between actual dits/dahs.
|
||||||
|
* Should work on adjusting AGC to not require this.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Include the HamSheild
|
#define DDS_REFCLK_DEFAULT 9600
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
#define RESET_PIN A3
|
#define RESET_PIN A3
|
||||||
#define SWITCH_PIN 2
|
#define SWITCH_PIN 2
|
||||||
|
|
||||||
// Create a new instance of our HamSheild class, called 'radio'
|
|
||||||
HamShield radio;
|
HamShield radio;
|
||||||
|
|
||||||
// Run our start up things here
|
// Run our start up things here
|
||||||
@@ -42,8 +52,12 @@ void setup() {
|
|||||||
// Tell the HamShield to start up
|
// Tell the HamShield to start up
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
|
|
||||||
|
radio.setMorseFreq(400);
|
||||||
|
radio.setMorseDotMillis(200);
|
||||||
|
|
||||||
// Configure the HamShield to transmit and recieve on 446.000MHz
|
// Configure the HamShield to transmit and recieve on 446.000MHz
|
||||||
radio.frequency(145570);
|
radio.frequency(438000);
|
||||||
|
|
||||||
Serial.println("Radio Configured.");
|
Serial.println("Radio Configured.");
|
||||||
}
|
}
|
||||||
@@ -60,13 +74,13 @@ void loop() {
|
|||||||
radio.setModeTransmit();
|
radio.setModeTransmit();
|
||||||
|
|
||||||
// Send a message out in morse code
|
// Send a message out in morse code
|
||||||
radio.morseOut("KC7IBT ARDUINO HAMSHIELD");
|
radio.morseOut(" KC7IBT ARDUINO HAMSHIELD");
|
||||||
|
|
||||||
// We're done sending the message, set the radio back into recieve mode.
|
// We're done sending the message, set the radio back into recieve mode.
|
||||||
radio.setModeReceive();
|
radio.setModeReceive();
|
||||||
Serial.println("Done.");
|
Serial.println("Done.");
|
||||||
|
|
||||||
// Wait 30 seconds before we send our beacon again.
|
// Wait a second before we send our beacon again.
|
||||||
delay(1000);
|
delay(1000);
|
||||||
} else {
|
} else {
|
||||||
// If we get here, the channel is busy. Let's also print out the RSSI.
|
// If we get here, the channel is busy. Let's also print out the RSSI.
|
||||||
|
|||||||
@@ -1,283 +0,0 @@
|
|||||||
|
|
||||||
// BlueHAM Proto01 Connection Guide
|
|
||||||
/**********************
|
|
||||||
**
|
|
||||||
** BlueHAM Proto01 <--> Arduino
|
|
||||||
** ADC_SCL A5
|
|
||||||
** ADC_DIO A4
|
|
||||||
** GND GND
|
|
||||||
** PWM_RF_CTL D9
|
|
||||||
**
|
|
||||||
** Setting Connections
|
|
||||||
** MODE -> GND
|
|
||||||
** SENB -> GND
|
|
||||||
** PDN -> 3.3V
|
|
||||||
** AVDD -> 5V (note this should be a beefy supply, could draw up to 4As)
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
** Pinout information for RadioPeripheral01 Prototype board
|
|
||||||
** GPIO0 -
|
|
||||||
** GPIO1 -
|
|
||||||
** GPIO2 - VHF_SEL
|
|
||||||
** GPIO3 - UHF_SEL
|
|
||||||
** GPIO4 - RX_EN
|
|
||||||
** GPIO5 - TX_EN
|
|
||||||
** GPIO6 -
|
|
||||||
** GPIO7 -
|
|
||||||
**************************/
|
|
||||||
|
|
||||||
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
|
|
||||||
// is used in I2Cdev.h
|
|
||||||
#include "Wire.h"
|
|
||||||
#include "HAMShield.h"
|
|
||||||
|
|
||||||
#include <Goertzel.h>
|
|
||||||
|
|
||||||
//typedef enum {
|
|
||||||
#define MAIN_S 0
|
|
||||||
#define RX_S 1
|
|
||||||
#define TX_S 2
|
|
||||||
#define FREQ_S 3
|
|
||||||
#define UHF_S 4
|
|
||||||
#define VHF_S 5
|
|
||||||
#define PWR_S 6
|
|
||||||
#define GPIO_S 7
|
|
||||||
//} menu_view;
|
|
||||||
|
|
||||||
int state;
|
|
||||||
|
|
||||||
/* goertzel routines */
|
|
||||||
|
|
||||||
int sensorPin = A0;
|
|
||||||
int led = 13;
|
|
||||||
const float TARGET_FREQUENCY = 2200;
|
|
||||||
const int N = 100;
|
|
||||||
const float THRESHOLD = 4000;
|
|
||||||
const float SAMPLING_FREQUENCY = 8900;
|
|
||||||
Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY);
|
|
||||||
|
|
||||||
// create object for RDA
|
|
||||||
HAMShield radio;
|
|
||||||
|
|
||||||
|
|
||||||
#define LED_PIN 13
|
|
||||||
bool blinkState = false;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// initialize serial communication
|
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.println("beginning radio setup");
|
|
||||||
|
|
||||||
// join I2C bus (I2Cdev library doesn't do this automatically)
|
|
||||||
Wire.begin();
|
|
||||||
|
|
||||||
// verify connection
|
|
||||||
Serial.println("Testing device connections...");
|
|
||||||
Serial.println(radio.testConnection() ? "RDA radio connection successful" : "RDA radio connection failed");
|
|
||||||
|
|
||||||
// initialize device
|
|
||||||
Serial.println("Initializing I2C devices...");
|
|
||||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
|
||||||
|
|
||||||
Serial.println("setting default Radio configuration");
|
|
||||||
|
|
||||||
|
|
||||||
// set frequency
|
|
||||||
Serial.println("changing frequency");
|
|
||||||
|
|
||||||
|
|
||||||
radio.setFrequency(446000); // in kHz
|
|
||||||
radio.setModeReceive();
|
|
||||||
|
|
||||||
// configure Arduino LED for
|
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
|
|
||||||
state = MAIN_S;
|
|
||||||
print_menu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
goertzel.sample(sensorPin);
|
|
||||||
float magnitude = goertzel.detect();
|
|
||||||
if(magnitude>THRESHOLD) digitalWrite(led, HIGH); //if found, enable led
|
|
||||||
else digitalWrite(led, LOW);
|
|
||||||
while (Serial.available()) {
|
|
||||||
if (state == FREQ_S) {
|
|
||||||
char freq_khz[6];
|
|
||||||
int i = 0;
|
|
||||||
while(i < 6) {
|
|
||||||
if (Serial.available()) {
|
|
||||||
freq_khz[i] = Serial.read();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// interpret frequency
|
|
||||||
uint32_t freq = 0;
|
|
||||||
i = 0;
|
|
||||||
while (i < 6) {
|
|
||||||
uint32_t temp = freq_khz[i] - '0';
|
|
||||||
for (int k = 5-i; k > 0; k--) {
|
|
||||||
temp = temp * 10;
|
|
||||||
}
|
|
||||||
freq += temp;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
Serial.print("setting frequency to: ");
|
|
||||||
Serial.println(freq);
|
|
||||||
radio.setFrequency(freq);
|
|
||||||
state = MAIN_S;
|
|
||||||
|
|
||||||
} else if (state == PWR_S) {
|
|
||||||
uint8_t pwr_raw[3];
|
|
||||||
int i = 0;
|
|
||||||
while(i < 3) {
|
|
||||||
if (Serial.available()) {
|
|
||||||
pwr_raw[i] = Serial.read();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// interpret power
|
|
||||||
uint8_t pwr = 0;
|
|
||||||
i = 0;
|
|
||||||
while (i < 3) {
|
|
||||||
uint8_t temp = pwr_raw[i] - '0';
|
|
||||||
for (int k = 2-i; k > 0; k--) {
|
|
||||||
temp = temp * 10;
|
|
||||||
}
|
|
||||||
pwr += temp;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.print("Setting power to: ");
|
|
||||||
Serial.println(pwr);
|
|
||||||
radio.setRfPower(pwr);
|
|
||||||
state = MAIN_S;
|
|
||||||
|
|
||||||
} else if (state == GPIO_S) {
|
|
||||||
uint8_t gpio_raw[2];
|
|
||||||
int i = 0;
|
|
||||||
while(i < 2) {
|
|
||||||
if (Serial.available()) {
|
|
||||||
gpio_raw[i] = Serial.read();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uint16_t gpio_pin = gpio_raw[0] - 48; // '0';
|
|
||||||
uint16_t gpio_mode = gpio_raw[1] - 48;
|
|
||||||
|
|
||||||
radio.setGpioMode(gpio_pin, gpio_mode);
|
|
||||||
state = MAIN_S;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
char action = Serial.read();
|
|
||||||
if (action == 'r') { // get current state
|
|
||||||
state = RX_S;
|
|
||||||
} else if (action == 't') {
|
|
||||||
state = TX_S;
|
|
||||||
} else if (action == 'f') {
|
|
||||||
state = FREQ_S;
|
|
||||||
} else if (action == 'u') {
|
|
||||||
state = UHF_S;
|
|
||||||
} else if (action == 'v') {
|
|
||||||
state = VHF_S;
|
|
||||||
} else if (action == '1') {
|
|
||||||
turn_on(state);
|
|
||||||
state = MAIN_S;
|
|
||||||
} else if (action == '0') {
|
|
||||||
turn_off(state);
|
|
||||||
state = MAIN_S;
|
|
||||||
} else if (action == 'p') {
|
|
||||||
state = PWR_S;
|
|
||||||
} else if (action == 'g') {
|
|
||||||
state = GPIO_S;
|
|
||||||
} else if (action == 's') {
|
|
||||||
int16_t rssi = radio.readRSSI();
|
|
||||||
Serial.print("rssi: ");
|
|
||||||
Serial.println(rssi);
|
|
||||||
} else if (action == 'i') {
|
|
||||||
int16_t vssi = radio.readVSSI();
|
|
||||||
Serial.print("vssi: ");
|
|
||||||
Serial.println(vssi);
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(action);
|
|
||||||
}
|
|
||||||
Serial.flush();
|
|
||||||
print_menu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void turn_off(int dev) {
|
|
||||||
switch (dev) {
|
|
||||||
case RX_S:
|
|
||||||
radio.setRX(0);
|
|
||||||
break;
|
|
||||||
case TX_S:
|
|
||||||
radio.setTX(0);
|
|
||||||
break;
|
|
||||||
case UHF_S:
|
|
||||||
radio.setGpioMode(3, 3); // set GPIO3 high (uhf is active low)
|
|
||||||
break;
|
|
||||||
case VHF_S:
|
|
||||||
radio.setGpioMode(2, 3); // set GPIO2 high (vhf is active low)
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void turn_on(int dev) {
|
|
||||||
switch (dev) {
|
|
||||||
case RX_S:
|
|
||||||
radio.setRX(1);
|
|
||||||
break;
|
|
||||||
case TX_S:
|
|
||||||
radio.setTX(1);
|
|
||||||
break;
|
|
||||||
case UHF_S:
|
|
||||||
radio.setGpioMode(3, 2); // set GPIO3 low (uhf is active low)
|
|
||||||
break;
|
|
||||||
case VHF_S:
|
|
||||||
radio.setGpioMode(2, 2); // set GPIO2 low (uhf is active low)
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_menu() {
|
|
||||||
Serial.println("MENU");
|
|
||||||
switch (state) {
|
|
||||||
case MAIN_S:
|
|
||||||
Serial.println("select step: [r]x, [t]x, [f]req, [u]hf, [v]hf, [p]wr, [g]pio control, r[s]si, vss[i] ...");
|
|
||||||
break;
|
|
||||||
case RX_S:
|
|
||||||
Serial.println("enter 1 to turn on rx, 0 to turn off rx");
|
|
||||||
break;
|
|
||||||
case TX_S:
|
|
||||||
Serial.println("enter 1 to turn on tx, 0 to turn off tx");
|
|
||||||
break;
|
|
||||||
case FREQ_S:
|
|
||||||
Serial.println("enter frequency in kHz (ffffff)");
|
|
||||||
break;
|
|
||||||
case UHF_S:
|
|
||||||
Serial.println("enter 1 to turn on uhf, 0 to turn off uhf");
|
|
||||||
break;
|
|
||||||
case VHF_S:
|
|
||||||
Serial.println("enter 1 to turn on vhf, 0 to turn off vhf");
|
|
||||||
break;
|
|
||||||
case PWR_S:
|
|
||||||
Serial.println("enter power (raw) (ppp)");
|
|
||||||
break;
|
|
||||||
case GPIO_S:
|
|
||||||
Serial.println("enter GPIO pin and control (no spaces, eg pin 1 mode 3 is 13");
|
|
||||||
Serial.println("modes 0 - HiZ, 1 - FCN, 2 - Low, 3 - Hi");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
state = MAIN_S;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,14 @@
|
|||||||
/* Fox Hunt */
|
/* Hamshield
|
||||||
|
* Example: Fox Hunt
|
||||||
|
* Plays a one minute tone at 10-13 minute intervals. Script
|
||||||
|
* will check to see if the channel is clear before it will
|
||||||
|
* transmit.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. To test, set a
|
||||||
|
* HandyTalkie to 438MHz. You should hear a one-minute tone
|
||||||
|
* followed by a callsign every 10-13 minutes.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
|
||||||
@@ -6,9 +16,9 @@
|
|||||||
#define RESET_PIN A3
|
#define RESET_PIN A3
|
||||||
#define SWITCH_PIN 2
|
#define SWITCH_PIN 2
|
||||||
|
|
||||||
// transmit for 1 minute, every 10 minutes
|
// In milliseconds
|
||||||
|
#define TRANSMITLENGTH 60000
|
||||||
#define TRANSMITLENGTH 1
|
// In minutes
|
||||||
#define INTERVAL 10
|
#define INTERVAL 10
|
||||||
#define RANDOMCHANCE 3
|
#define RANDOMCHANCE 3
|
||||||
|
|
||||||
@@ -27,23 +37,23 @@ void setup() {
|
|||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.frequency(145510);
|
radio.setRfPower(0);
|
||||||
|
radio.frequency(438000);
|
||||||
radio.setModeReceive();
|
radio.setModeReceive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly up to 3 minutes later
|
if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers
|
||||||
if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers
|
radio.setModeTransmit(); // turn on transmit mode
|
||||||
radio.setModeTransmit(); // turn on transmit mode
|
tone(PWM_PIN, 1000, TRANSMITLENGTH); // play a long solid tone
|
||||||
tone(1000,11,TRANSMITLENGTH * 60 * 1000); // play a long solid tone
|
delay(TRANSMITLENGTH);
|
||||||
radio.morseOut("1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter
|
radio.morseOut(" 1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter
|
||||||
radio.setModeReceive(); // turn off the transmit mode
|
radio.setModeReceive(); // turn off the transmit mode
|
||||||
}
|
}
|
||||||
|
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly
|
||||||
}
|
}
|
||||||
|
|
||||||
// a function so we can wait by minutes
|
// a function so we can wait by minutes
|
||||||
|
void waitMinute(unsigned long period) {
|
||||||
void waitMinute(int period) {
|
|
||||||
delay(period * 60 * 1000);
|
delay(period * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
/* HamShield Functional Test */
|
/* Hamshield
|
||||||
|
* Example: Functional Test
|
||||||
|
* This is a simple example to demonstrate HamShield receive
|
||||||
|
* and transmit functionality.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones into
|
||||||
|
* the HamShield. Connect the Arduino to wall power and then
|
||||||
|
* to your computer via USB. After uploading this program to
|
||||||
|
* your Arduino, open the Serial Monitor. Serial Monitor will
|
||||||
|
* describe what you should be expecting to hear from your
|
||||||
|
* headphones. Tune a HandytTalkie to 446MHz to hear morse
|
||||||
|
* code example.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
|
||||||
@@ -32,7 +44,7 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
radio.setModeReceive();
|
radio.setModeReceive();
|
||||||
radio.setSQLoThresh(0);
|
radio.setSQLoThresh(0);
|
||||||
radio.setSQOn();
|
radio.setSQOff();
|
||||||
radio.setVolume1(0xF);
|
radio.setVolume1(0xF);
|
||||||
radio.setVolume2(0xF);
|
radio.setVolume2(0xF);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
/*
|
/* Hamshield
|
||||||
|
* Example: Gauges
|
||||||
Gauges
|
* This example prints Signal, Audio In, and Audio Rx ADC
|
||||||
|
* Peak strength to the Serial Monitor in a graphical manner.
|
||||||
Simple gauges for the radio receiver.
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones into
|
||||||
|
* the HamShield. Connect the Arduino to wall power and then
|
||||||
|
* to your computer via USB. After uploading this program to
|
||||||
|
* your Arduino, open the Serial Monitor. You will see a
|
||||||
|
* repeating display of different signal strengths. Ex:
|
||||||
|
*
|
||||||
|
* [....|....] -73
|
||||||
|
* Signal
|
||||||
|
*
|
||||||
|
* Uncheck the "Autoscroll" box at the bottom of the Serial
|
||||||
|
* Monitor to manually control the view of the Serial Monitor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
@@ -15,13 +24,6 @@ Simple gauges for the radio receiver.
|
|||||||
|
|
||||||
HamShield radio;
|
HamShield radio;
|
||||||
|
|
||||||
void clr() {
|
|
||||||
/* Serial.write(27);
|
|
||||||
Serial.print("[2J"); // cursor to home command */
|
|
||||||
Serial.write(27);
|
|
||||||
Serial.print("[H"); // cursor to home command
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
pinMode(PWM_PIN, OUTPUT);
|
||||||
@@ -35,13 +37,13 @@ void setup() {
|
|||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
analogReference(DEFAULT);
|
analogReference(DEFAULT);
|
||||||
Serial.begin(115200);
|
Serial.begin(9600);
|
||||||
|
|
||||||
Serial.print("Radio status: ");
|
Serial.print("Radio status: ");
|
||||||
int result = radio.testConnection();
|
int result = radio.testConnection();
|
||||||
Serial.println(result,DEC);
|
Serial.println(result,DEC);
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setFrequency(446000);
|
radio.frequency(446000);
|
||||||
radio.setModeReceive();
|
radio.setModeReceive();
|
||||||
Serial.println("Entering gauges...");
|
Serial.println("Entering gauges...");
|
||||||
tone(9,1000);
|
tone(9,1000);
|
||||||
@@ -59,7 +61,6 @@ int txc = 0;
|
|||||||
int mode = 0;
|
int mode = 0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
clr();
|
|
||||||
int16_t rssi = radio.readRSSI();
|
int16_t rssi = radio.readRSSI();
|
||||||
gauge = map(rssi,-123,-50,0,8);
|
gauge = map(rssi,-123,-50,0,8);
|
||||||
Serial.print("[");
|
Serial.print("[");
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
/* Simple DTMF controlled HAM Radio Robot */
|
|
||||||
|
|
||||||
#include <ArduinoRobot.h> // include the robot library
|
|
||||||
#include <HamShield.h>
|
|
||||||
#include <SPI.h>
|
|
||||||
|
|
||||||
#define PWM_PIN 3
|
|
||||||
#define RESET_PIN A3
|
|
||||||
#define SWITCH_PIN 2
|
|
||||||
|
|
||||||
HamShield radio;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
|
||||||
digitalWrite(PWM_PIN, LOW);
|
|
||||||
|
|
||||||
// prep the switch
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
||||||
|
|
||||||
// set up the reset control pin
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
Robot.begin();
|
|
||||||
|
|
||||||
radio.initialize();
|
|
||||||
radio.frequency(145510);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if(radio.waitForDTMF()) { // wait for a received DTMF tone
|
|
||||||
uint8_t command = radio.getLastDTMFDigit(); // get the last DTMF tone sent
|
|
||||||
if(command == '4') { Robot.turn(-90); } // turn robot left
|
|
||||||
if(command == '6') { Robot.turn(90); } // turn robot right
|
|
||||||
if(command == '2') { Robot.motorsWrite(-255,-255); delay(500); Robot.motorsWrite(255, 255); } // move robot forward
|
|
||||||
if(command == '5') { // tell robot to send morse code identity
|
|
||||||
if(radio.waitForChannel()) { // wait for the user to release the transmit button
|
|
||||||
radio.setModeTransmit(); // turn on transmit mode
|
|
||||||
radio.morseOut("1ZZ9ZZ I AM HAMRADIO ROBOT"); // send morse code
|
|
||||||
radio.setModeReceive(); // go back to receive mode on radio
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,4 +1,20 @@
|
|||||||
// Hamshield
|
/* Hamshield
|
||||||
|
* Example: HandyTalkie
|
||||||
|
* This is a simple example to demonstrate HamShield receive
|
||||||
|
* and transmit functionality.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones into
|
||||||
|
* the HamShield. Connect the Arduino to wall power and then
|
||||||
|
* to your computer via USB. After uploading this program to
|
||||||
|
* your Arduino, open the Serial Monitor. Press the button on
|
||||||
|
* the HamShield to begin setup. After setup is complete, type
|
||||||
|
* your desired Tx/Rx frequency, in hertz, into the bar at the
|
||||||
|
* top of the Serial Monitor and click the "Send" button.
|
||||||
|
* To test with another HandyTalkie (HT), key up on your HT
|
||||||
|
* and make sure you can hear it through the headphones
|
||||||
|
* attached to the HamShield. Key up on the HamShield by
|
||||||
|
* holding the button.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Indentifier
|
|
||||||
|
|
||||||
Arduino audio overlay example
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <HamShield.h>
|
|
||||||
|
|
||||||
#define DOT 100
|
|
||||||
|
|
||||||
#define PWM_PIN 3
|
|
||||||
#define RESET_PIN A3
|
|
||||||
#define SWITCH_PIN 2
|
|
||||||
|
|
||||||
HamShield radio;
|
|
||||||
|
|
||||||
const char *bascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?'!/()&:;=+-_\"$@",
|
|
||||||
*bitu[] = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",".-.-.-","--..--","..--..",".----.","-.-.--","-..-.","-.--.","-.--.-",".-...","---...","-.-.-.","-...-",".-.-.","-....-","..--.-",".-..-.","...-..-",".--.-."
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *callsign = {"1ZZ9ZZ/B"} ;
|
|
||||||
|
|
||||||
char morsebuffer[8];
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
|
||||||
digitalWrite(PWM_PIN, LOW);
|
|
||||||
|
|
||||||
// prep the switch
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
||||||
|
|
||||||
// set up the reset control pin
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
Serial.begin(9600);
|
|
||||||
Serial.println("starting up..");
|
|
||||||
|
|
||||||
Serial.print("Radio status: ");
|
|
||||||
int result = radio.testConnection();
|
|
||||||
Serial.println(result,DEC);
|
|
||||||
radio.initialize();
|
|
||||||
radio.frequency(446000);
|
|
||||||
radio.setVolume1(0xF);
|
|
||||||
radio.setVolume2(0xF);
|
|
||||||
radio.setModeReceive();
|
|
||||||
radio.setTxSourceMic();
|
|
||||||
radio.setSQLoThresh(80);
|
|
||||||
radio.setSQOn();
|
|
||||||
Serial.println("Done with radio beacon setup. Press and hold a key to transmit.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int state = 0;
|
|
||||||
long timer = 0;
|
|
||||||
int morseletter = 0;
|
|
||||||
int morsesymbol = 0;
|
|
||||||
long keyer = 0;
|
|
||||||
char symbol;
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if(Serial.available() > 0) {
|
|
||||||
if(state == 0) {
|
|
||||||
state = 10;
|
|
||||||
radio.setModeTransmit();
|
|
||||||
timer = millis();
|
|
||||||
keyer = millis();
|
|
||||||
}
|
|
||||||
if(state == 10) {
|
|
||||||
timer = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(millis() > (timer + 500)) { radio.setModeReceive(); morseletter = 0; morsesymbol = 0; state = 0; }
|
|
||||||
if(state == 10) {
|
|
||||||
if(millis() > (keyer + (DOT * 3))) {
|
|
||||||
keyer = millis();
|
|
||||||
symbol = lookup(callsign[morseletter],morsesymbol);
|
|
||||||
if(symbol == '-') { tone(9,1000,DOT*3); }
|
|
||||||
if(symbol == '.') { tone(9,1000,DOT); }
|
|
||||||
if(symbol == 0) { morsesymbol = 0; morseletter++; }
|
|
||||||
if(callsign[morseletter] == 0) { morsesymbol = 0; morseletter = 0; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char lookup(char letter, int morsesymbol) {
|
|
||||||
for(int x = 0; x < 54; x++) {
|
|
||||||
if(letter == bascii[x]) {
|
|
||||||
return bitu[x][morsesymbol];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,15 @@
|
|||||||
/* Just Transmit */
|
/* Hamshield
|
||||||
|
* Example: Just Transmit
|
||||||
|
* This example continuously transmits.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones with
|
||||||
|
* built-in mic into the HamShield. Connect the Arduino to
|
||||||
|
* wall power and then to your computer via USB. After
|
||||||
|
* uploading this program to your Arduino, open the Serial
|
||||||
|
* Monitor to monitor the program's progress. After setup is
|
||||||
|
* complete, tune a HandyTalkie (HT) to 144.025MHz. Listen on
|
||||||
|
* the HT for the HamShield broadcasting from the mic.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
|
||||||
@@ -28,12 +39,11 @@ void setup() {
|
|||||||
Serial.println("Setting radio to its defaults..");
|
Serial.println("Setting radio to its defaults..");
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
radio.setChanMode(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
radio.bypassPreDeEmph();
|
radio.bypassPreDeEmph();
|
||||||
radio.frequency(144000);
|
radio.frequency(144025);
|
||||||
// radio.setTxSourceNone();
|
// radio.setTxSourceNone();
|
||||||
radio.setModeTransmit();
|
radio.setModeTransmit();
|
||||||
for(;;) { }
|
for(;;) { }
|
||||||
|
|||||||
@@ -1,11 +1,35 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: KISS
|
||||||
|
* This is a example configures the HamShield to be used as
|
||||||
|
* a TNC/KISS device. You will need a KISS device to input
|
||||||
|
* commands to the HamShield
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. Issue commands
|
||||||
|
* via the KISS equipment.
|
||||||
|
*
|
||||||
|
* To use the KISS example with YAAC:
|
||||||
|
* 1. open the configure YAAC wizard
|
||||||
|
* 2. follow the prompts and enter in your details until you get to the "Add and Configure Interfaces" window
|
||||||
|
* 3. Choose "Add Serial KISS TNC Port"
|
||||||
|
* 4. Choose the COM port for your Arduino
|
||||||
|
* 5. set baud rate to 9600 (default)
|
||||||
|
* 6. set it to KISS-only: with no command to enter KISS mode (just leave the box empty)
|
||||||
|
* 7. Use APRS protocol (default)
|
||||||
|
* 8. hit the next button and follow directions to finish configuration
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
#include <KISS.h>
|
#include <KISS.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
#include <packet.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
HamShield radio;
|
HamShield radio;
|
||||||
DDS dds;
|
DDS dds;
|
||||||
KISS kiss(&Serial, &radio, &dds);
|
AFSK afsk;
|
||||||
|
KISS kiss(&Serial, &radio, &dds, &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
|
||||||
@@ -20,28 +44,44 @@ void setup() {
|
|||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, LOW);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
while (digitalRead(SWITCH_PIN));
|
|
||||||
|
|
||||||
// let the AU ot of reset
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setSQOff();
|
//radio.setSQOff();
|
||||||
|
radio.setVolume1(0xFF);
|
||||||
|
radio.setVolume2(0xFF);
|
||||||
|
radio.setSQHiThresh(-100);
|
||||||
|
radio.setSQLoThresh(-100);
|
||||||
|
radio.setSQOn();
|
||||||
radio.frequency(144390);
|
radio.frequency(144390);
|
||||||
//I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0x05FF);
|
|
||||||
|
|
||||||
dds.start();
|
dds.start();
|
||||||
radio.afsk.start(&dds);
|
afsk.start(&dds);
|
||||||
|
delay(100);
|
||||||
|
radio.setModeReceive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
kiss.loop();
|
kiss.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(ADC_vect) {
|
ISR(TIMER2_OVF_vect) {
|
||||||
kiss.isr();
|
TIFR2 = _BV(TOV2);
|
||||||
|
static uint8_t tcnt = 0;
|
||||||
|
if(++tcnt == 8) {
|
||||||
|
dds.clockTick();
|
||||||
|
tcnt = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ISR(ADC_vect) {
|
||||||
|
static uint8_t tcnt = 0;
|
||||||
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
||||||
|
dds.clockTick();
|
||||||
|
if(++tcnt == 1) {
|
||||||
|
afsk.timer();
|
||||||
|
tcnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,17 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: PSK31Transmit
|
||||||
|
* This is a simple example to demonstrate HamShield PSK31
|
||||||
|
* transmit functionality.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, tune a PSK31 receiver and
|
||||||
|
* wait to receive the message "Why hello there, friend.
|
||||||
|
* Nice to meet you. Welcome to PSK31. 73, VE6SLP sk"
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
#include "varicode.h"
|
#include "varicode.h"
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Record sound and then plays it back a few times.
|
|
||||||
Very low sound quality @ 2KHz 0.75 seconds
|
|
||||||
A bit robotic and weird
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <HamShield.h>
|
|
||||||
|
|
||||||
#define PWM_PIN 3
|
|
||||||
#define RESET_PIN A3
|
|
||||||
#define SWITCH_PIN 2
|
|
||||||
|
|
||||||
#define RATE 500
|
|
||||||
#define SIZE 1500
|
|
||||||
|
|
||||||
HamShield radio;
|
|
||||||
|
|
||||||
char sound[SIZE];
|
|
||||||
unsigned int sample1;
|
|
||||||
int x = -1;
|
|
||||||
int16_t rssi;
|
|
||||||
byte mode = 8;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
||||||
pinMode(PWM_PIN, OUTPUT);
|
|
||||||
digitalWrite(PWM_PIN, LOW);
|
|
||||||
|
|
||||||
// prep the switch
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
||||||
|
|
||||||
// set up the reset control pin
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
|
||||||
|
|
||||||
// int result = radio.testConnection();
|
|
||||||
radio.initialize();
|
|
||||||
radio.setFrequency(446000);
|
|
||||||
setPwmFrequency(9, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
rssi = radio.readRSSI();
|
|
||||||
if(rssi > -100) {
|
|
||||||
if(x == -1) {
|
|
||||||
for(x = 0; x < SIZE; x++) {
|
|
||||||
if(mode == 4) {
|
|
||||||
sample1 = analogRead(0);
|
|
||||||
sound[x] = sample1 >> 4;
|
|
||||||
delayMicroseconds(RATE); x++;
|
|
||||||
sample1 = analogRead(0);
|
|
||||||
sound[x] = (sample1 & 0xF0) | sound[x];
|
|
||||||
delayMicroseconds(RATE);
|
|
||||||
} else {
|
|
||||||
sound[x] = analogRead(0);
|
|
||||||
delayMicroseconds(RATE); x++;
|
|
||||||
sound[x] = analogRead(0);
|
|
||||||
delayMicroseconds(RATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(rssi < -100) {
|
|
||||||
if(x == 1500) {
|
|
||||||
radio.setModeTransmit();
|
|
||||||
delay(500);
|
|
||||||
tone(9,1000,500); delay(750);
|
|
||||||
for(int r = 0; r < 10; r++) {
|
|
||||||
for(x = 0; x < SIZE; x++) {
|
|
||||||
if(mode == 4) {
|
|
||||||
|
|
||||||
analogWrite(9,sound[x] << 4);
|
|
||||||
delayMicroseconds(RATE); x++;
|
|
||||||
analogWrite(9,sound[x] & 0xF);
|
|
||||||
delayMicroseconds(RATE); } else {
|
|
||||||
|
|
||||||
analogWrite(9,sound[x]);
|
|
||||||
delayMicroseconds(RATE); x++;
|
|
||||||
analogWrite(9,sound[x]);
|
|
||||||
delayMicroseconds(RATE);
|
|
||||||
}
|
|
||||||
} }
|
|
||||||
tone(9,1000,500); delay(750);
|
|
||||||
radio.setModeReceive();
|
|
||||||
x = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPwmFrequency(int pin, int divisor) {
|
|
||||||
byte mode;
|
|
||||||
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
|
|
||||||
switch(divisor) {
|
|
||||||
case 1: mode = 0x01; break;
|
|
||||||
case 8: mode = 0x02; break;
|
|
||||||
case 64: mode = 0x03; break;
|
|
||||||
case 256: mode = 0x04; break;
|
|
||||||
case 1024: mode = 0x05; break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
if(pin == 5 || pin == 6) {
|
|
||||||
TCCR0B = TCCR0B & 0b11111000 | mode;
|
|
||||||
} else {
|
|
||||||
TCCR1B = TCCR1B & 0b11111000 | mode;
|
|
||||||
}
|
|
||||||
} else if(pin == 3 || pin == 11) {
|
|
||||||
switch(divisor) {
|
|
||||||
case 1: mode = 0x01; break;
|
|
||||||
case 8: mode = 0x02; break;
|
|
||||||
case 32: mode = 0x03; break;
|
|
||||||
case 64: mode = 0x04; break;
|
|
||||||
case 128: mode = 0x05; break;
|
|
||||||
case 256: mode = 0x06; break;
|
|
||||||
case 1024: mode = 0x7; break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
TCCR2B = TCCR2B & 0b11111000 | mode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,4 +1,17 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: QPSK63Transmit
|
||||||
|
* This is a simple example to demonstrate HamShield QPSK63
|
||||||
|
* transmit functionality.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, tune a QPSK63 receiver and
|
||||||
|
* wait to receive the message "Why hello there, friend.
|
||||||
|
* Nice to meet you. Welcome to QPSK63. 73, VE6SLP sk"
|
||||||
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
#include "varicode.h"
|
#include "varicode.h"
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
@@ -46,7 +59,7 @@ void sendChar(uint8_t c) {
|
|||||||
//PORTD &= ~_BV(2); // Diagnostic pin (D2)
|
//PORTD &= ~_BV(2); // Diagnostic pin (D2)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *string = "Why hello there, friend. Nice to meet you. Welcome to PSK31. 73, VE6SLP sk\r\n";
|
char *string = "Why hello there, friend. Nice to meet you. Welcome to QPSK63. 73, VE6SLP sk\r\n";
|
||||||
void loop() {
|
void loop() {
|
||||||
int i;
|
int i;
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/*
|
/* Hamshield
|
||||||
|
* Example: SSTV
|
||||||
Sends an SSTV test pattern
|
* This program will transmit a test pattern. You will need
|
||||||
|
* SSTV equipment to test the output.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, open the Serial Monitor to
|
||||||
|
* view the status of the program. Tune your SSTV to
|
||||||
|
* 446MHz to receive the image output.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
@@ -45,7 +51,7 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(radio.waitForChannel(1000,2000)) { // Wait forever for calling frequency to open, then wait 2 seconds for breakers
|
if(radio.waitForChannel(1000,2000, -90)) { // Wait forever for calling frequency to open, then wait 2 seconds for breakers
|
||||||
radio.setModeTransmit(); // Turn on the transmitter
|
radio.setModeTransmit(); // Turn on the transmitter
|
||||||
delay(250); // Wait a moment
|
delay(250); // Wait a moment
|
||||||
radio.SSTVTestPattern(MARTIN1); // send a MARTIN1 test pattern
|
radio.SSTVTestPattern(MARTIN1); // send a MARTIN1 test pattern
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
|
/* Hamshield
|
||||||
|
* Example: SSTV M1 Static
|
||||||
|
* This program will transmit a static image. You will need
|
||||||
|
* SSTV equipment to test the output.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
|
* power and then to your computer via USB. After uploading
|
||||||
|
* this program to your Arduino, open the Serial Monitor to
|
||||||
|
* view the status of the program. Tune your SSTV to
|
||||||
|
* 145.5MHz to receive the image output.
|
||||||
|
*/
|
||||||
|
|
||||||
// So the precalculated values will get stored
|
// So the precalculated values will get stored
|
||||||
#define DDS_REFCLK_DEFAULT (34965/2)
|
#define DDS_REFCLK_DEFAULT (34965/2)
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
#include <DDS.h>
|
||||||
|
|
||||||
#define PWM_PIN 3
|
#define PWM_PIN 3
|
||||||
#define RESET_PIN A3
|
#define RESET_PIN A3
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
/*
|
/* Hamshield
|
||||||
|
* Example: Serial Tranceiver
|
||||||
SerialTransceiver is TTL Serial port "glue" to allow desktop or laptop control of the HamShield
|
* SerialTransceiver is TTL Serial port "glue" to allow
|
||||||
|
* desktop or laptop control of the HamShield.
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones into
|
||||||
|
* the HamShield. Connect the Arduino to wall power and then
|
||||||
|
* to your computer via USB. After uploading this program to
|
||||||
|
* your Arduino, open the Serial Monitor. Use the bar at the
|
||||||
|
* top of the serial monitor to enter commands as seen below.
|
||||||
|
*
|
||||||
|
* EXAMPLE: To change the repeater offset to 144.425MHz,
|
||||||
|
* enable offset, then key in, use the following commands:
|
||||||
|
* T144425;
|
||||||
|
* R1;
|
||||||
|
* [Just a space]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
@@ -8,29 +21,15 @@ Mode ASCII Description
|
|||||||
-------------- ----------- -------------------------------------------------------------------------------------------------------------------------------------------- -----------------
|
-------------- ----------- -------------------------------------------------------------------------------------------------------------------------------------------- -----------------
|
||||||
Transmit space Space must be received at least every 500 mS Yes
|
Transmit space Space must be received at least every 500 mS Yes
|
||||||
Receive not space If space is not received and/or 500 mS timeout of space occurs, unit will go into receive mode Yes
|
Receive not space If space is not received and/or 500 mS timeout of space occurs, unit will go into receive mode Yes
|
||||||
CTCSS In A<tone>; <tone> must be a numerical ascii value with decimal point indicating CTCSS receive tone required to unsquelch No
|
|
||||||
CTCSS Out B<tone>; <tone> must be a numerical ascii value with decimal point indicating CTCSS transmit tone No
|
|
||||||
CTCSS Enable C<state>; Turns on CTCSS mode (analog tone) with 1, off with 0. No
|
|
||||||
CDCSS Enable D<state>; Turns on CDCSS mode (digital tone) with 1, off with 0. No
|
|
||||||
Bandwidth E<mode>; for 12.5KHz mode is 0, for 25KHz, mode is 1 No
|
Bandwidth E<mode>; for 12.5KHz mode is 0, for 25KHz, mode is 1 No
|
||||||
Frequency F<freq>; Set the receive frequency in KHz, if offset is disabled, this is the transmit frequency No
|
Frequency F<freq>; Set the receive frequency in KHz, if offset is disabled, this is the transmit frequency No
|
||||||
CDCSS In G<code>; <code> must be a valid CDCSS code No
|
|
||||||
CDCSS Out H<code>; <code> must be a valid CDCSS code No
|
|
||||||
Print tones I Prints out all configured tones and codes, coma delimited in format: CTCSS In, CTCSS Out, CDCSS In, CDCSS Out No
|
|
||||||
Morse Out M<text>; A small buffer for morse code (32 chars)
|
Morse Out M<text>; A small buffer for morse code (32 chars)
|
||||||
Power level P<level>; Set the power amp level, 0 = lowest, 15 = highest No
|
Power level P<level>; Set the power amp level, 0 = lowest, 15 = highest No
|
||||||
Enable Offset R<state>; 1 turns on repeater offset mode, 0 turns off repeater offset mode No
|
Enable Offset R<state>; 1 turns on repeater offset mode, 0 turns off repeater offset mode No
|
||||||
Squelch S<level>; Set the squelch level No
|
Squelch S<level>; Set the squelch level No
|
||||||
TX Offset T<freq>; The absolute frequency of the repeater offset to transmit on in KHz No
|
TX Offset T<freq>; The absolute frequency of the repeater offset to transmit on in KHz No
|
||||||
Volume V<level>; Set the volume level of the receiver No
|
RSSI ?; Respond with the current receive level in - dBm (no sign provided on numerical response) No
|
||||||
Reset X Reset all settings to default No
|
Voice Level ^; Respond with the current voice level (VSSI)
|
||||||
Sleep Z Sleep radio No
|
|
||||||
Filters @<state>; Set bit to enable, clear bit to disable: 0 = pre/de-emphasis, 1 = high pass filter, 2 = low pass filter (default: ascii 7, all enabled) No
|
|
||||||
Vox mode $<state>; 0 = vox off, >= 1 audio sensitivity. lower value more sensitive No
|
|
||||||
Mic Channel *<state>; Set the voice channel. 0 = signal from mic or arduino, 1 = internal tone generator No
|
|
||||||
RSSI ? Respond with the current receive level in - dBm (no sign provided on numerical response) No
|
|
||||||
Tone Gen % (notes) To send a tone, use the following format: Single tone: %1,<freq>,<length>; Dual tone: %2,<freq>,<freq>,<length>; DTMF: %3,<key>,<length>; No
|
|
||||||
Voice Level ^ Respond with the current voice level (VSSI)
|
|
||||||
|
|
||||||
|
|
||||||
Responses:
|
Responses:
|
||||||
@@ -82,15 +81,15 @@ void setup() {
|
|||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(9600);
|
||||||
Serial.print(";;;;;;;;;;;;;;;;;;;;;;;;;;");
|
Serial.println(";;;;;;;;;;;;;;;;;;;;;;;;;;");
|
||||||
|
|
||||||
int result = radio.testConnection();
|
int result = radio.testConnection();
|
||||||
Serial.print("*");
|
Serial.print("*");
|
||||||
Serial.print(result,DEC);
|
Serial.print(result,DEC);
|
||||||
Serial.print(";");
|
Serial.println(";");
|
||||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
||||||
Serial.print("*START;");
|
Serial.println("*START;");
|
||||||
radio.frequency(freq);
|
radio.frequency(freq);
|
||||||
radio.setVolume1(0xF);
|
radio.setVolume1(0xF);
|
||||||
radio.setVolume2(0xF);
|
radio.setVolume2(0xF);
|
||||||
@@ -120,14 +119,14 @@ void loop() {
|
|||||||
if(repeater == 1) { radio.frequency(tx); }
|
if(repeater == 1) { radio.frequency(tx); }
|
||||||
radio.setModeTransmit();
|
radio.setModeTransmit();
|
||||||
state = 10;
|
state = 10;
|
||||||
Serial.print("#TX,ON;");
|
Serial.println("#TX,ON;");
|
||||||
timer = millis();
|
timer = millis();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 63: // ? - RSSI
|
case 63: // ? - RSSI
|
||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
Serial.print(radio.readRSSI(),DEC);
|
Serial.print(radio.readRSSI(),DEC);
|
||||||
Serial.print(";");
|
Serial.println(";");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 65: // A - CTCSS In
|
case 65: // A - CTCSS In
|
||||||
@@ -148,7 +147,7 @@ void loop() {
|
|||||||
case 70: // F - frequency
|
case 70: // F - frequency
|
||||||
getValue();
|
getValue();
|
||||||
freq = atol(cmdbuff);
|
freq = atol(cmdbuff);
|
||||||
if(radio.frequency(freq) == true) { Serial.print("@"); Serial.print(freq,DEC); Serial.print(";!;"); } else { Serial.print("X1;"); }
|
if(radio.frequency(freq) == true) { Serial.print("@"); Serial.print(freq,DEC); Serial.println(";!;"); } else { Serial.println("X1;"); }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
@@ -187,14 +186,14 @@ void loop() {
|
|||||||
case 94: // ^ - VSSI (voice) level
|
case 94: // ^ - VSSI (voice) level
|
||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
Serial.print(radio.readVSSI(),DEC);
|
Serial.print(radio.readVSSI(),DEC);
|
||||||
Serial.print(";");
|
Serial.println(";");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(state == 10) {
|
if(state == 10) {
|
||||||
if(millis() > (timer + 500)) { Serial.print("#TX,OFF;");radio.setModeReceive(); if(repeater == 1) { radio.frequency(freq); } state = 0; txcount = 0; }
|
if(millis() > (timer + 500)) { Serial.println("#TX,OFF;");radio.setModeReceive(); if(repeater == 1) { radio.frequency(freq); } state = 0; txcount = 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +204,8 @@ void getValue() {
|
|||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
temp = Serial.read();
|
temp = Serial.read();
|
||||||
if(temp == 59) { cmdbuff[p] = 0; Serial.print("@");
|
if(temp == 59) { cmdbuff[p] = 0; Serial.print("@");
|
||||||
for(int x = 0; x < 32; x++) { Serial.print(cmdbuff[x]); }
|
for(int x = 0; x < 32; x++) { Serial.print(cmdbuff[x]);}
|
||||||
|
Serial.println();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cmdbuff[p] = temp;
|
cmdbuff[p] = temp;
|
||||||
@@ -213,12 +213,12 @@ void getValue() {
|
|||||||
if(p == 32) {
|
if(p == 32) {
|
||||||
Serial.print("@");
|
Serial.print("@");
|
||||||
for(int x = 0; x < 32; x++) {
|
for(int x = 0; x < 32; x++) {
|
||||||
Serial.print(cmdbuff[x]);
|
Serial.println(cmdbuff[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdbuff[0] = 0;
|
cmdbuff[0] = 0;
|
||||||
|
|
||||||
Serial.print("X0;"); return; } // some sort of alignment issue? lets not feed junk into whatever takes this string in
|
Serial.println("X0;"); return; } // some sort of alignment issue? lets not feed junk into whatever takes this string in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,24 @@
|
|||||||
/*
|
/* Hamshield
|
||||||
|
* Example: Signal Test
|
||||||
Plays back the current signal strength level and morses out it's call sign at the end.
|
* Plays back the current signal strength level and morses out
|
||||||
|
* it's call sign at the end. You will need a HandyTalkie (HT)
|
||||||
|
* to test the output of this example. You will also need to
|
||||||
*/
|
* download the PCM library from
|
||||||
|
* https://github.com/damellis/PCM
|
||||||
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
|
* into the HamShield RF jack. Plug a pair of headphones into
|
||||||
|
* the HamShield. Connect the Arduino to wall power and then
|
||||||
|
* to your computer via USB. After uploading this program to
|
||||||
|
* your Arduino, open the Serial Monitor. HamShield will print
|
||||||
|
* the results of its signal test to the Serial Monitor. To
|
||||||
|
* test with another HandyTalkie (HT), tune in to 446MHz and
|
||||||
|
* listen for the call sign. Then key up on your HT and make
|
||||||
|
* sure you can hear it through the headphones attached to the
|
||||||
|
* HamShield.
|
||||||
|
*/
|
||||||
|
|
||||||
#define DOT 100
|
#define DOT 100
|
||||||
#define CALLSIGN "1ZZ9ZZ/B"
|
char CALLSIGN[] = "1ZZ9ZZ/B";
|
||||||
|
|
||||||
/* Standard libraries and variable init */
|
/* Standard libraries and variable init */
|
||||||
|
|
||||||
|
|||||||
10
library.properties
Normal file
10
library.properties
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
name=HamShield
|
||||||
|
version=1.0.5
|
||||||
|
author=Morgan Redfield <morgan@enhancedradio.com>, Casey Halverson <casey@enhancedradio.com>
|
||||||
|
maintainer=Morgan Redfield <morgan@enhancedradio.com>
|
||||||
|
sentence=A library for use with HamShield by Enhanced Radio Devices.
|
||||||
|
paragraph=
|
||||||
|
category=Device Control
|
||||||
|
url=http://www.hamshield.com
|
||||||
|
architectures=*
|
||||||
|
includes=HamShield.h
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// HamShield library collection
|
// HamShield library collection
|
||||||
// Based on Programming Manual rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
// Based on Programming Manual rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||||
// 11/22/2013 by Morgan Redfield <redfieldm@gmail.com>
|
// 11/22/2013 by Morgan Redfield <redfieldm@gmail.com>
|
||||||
// 04/26/2015 various changes Casey Halverson <spaceneedle@gmail.com>
|
// 04/26/2015 various changes Casey Halverson <spaceneedle@gmail.com>
|
||||||
@@ -24,6 +24,10 @@ const uint32_t MURS[] PROGMEM = {0,151820,151880,151940,154570,154600};
|
|||||||
|
|
||||||
const uint32_t WX[] PROGMEM = {0,162550,162400,162475,162425,162450,162500,162525};
|
const uint32_t WX[] PROGMEM = {0,162550,162400,162475,162425,162450,162500,162525};
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int morse_freq = 600;
|
||||||
|
unsigned int morse_dot_millis = 100;
|
||||||
|
|
||||||
/* morse code lookup table */
|
/* morse code lookup table */
|
||||||
// This is the Morse table in reverse binary format.
|
// This is the Morse table in reverse binary format.
|
||||||
// It will occupy 108 bytes of memory (or program memory if defined)
|
// It will occupy 108 bytes of memory (or program memory if defined)
|
||||||
@@ -101,11 +105,11 @@ const uint16_t asciiMorseProgmem[] PROGMEM = {
|
|||||||
};
|
};
|
||||||
#endif // MORSE_TABLE_PROGMEM
|
#endif // MORSE_TABLE_PROGMEM
|
||||||
|
|
||||||
/* 2200 Hz */
|
/* 2200 Hz -- This lookup table should be deprecated */
|
||||||
|
|
||||||
const unsigned char AFSK_mark[] PROGMEM = { 154, 249, 91, 11, 205, 216, 25, 68, 251, 146, 0, 147, 250, 68, 24, 218, 203, 13, 88, 254, 128, 1, 167, 242, 52, 37, 231, 186, 5, 108, 255, 108, 5, 186, 231, 37, 52, 242, 167, 1, 128, 254, 88, 13, 203, 218, 24, 69, 250, 147, 0, 147, 250, 69, 24, 218, 203, 13, 88, 255, 127, 2, 165, 245, 48 };
|
const unsigned char AFSK_mark[] PROGMEM = { 154, 249, 91, 11, 205, 216, 25, 68, 251, 146, 0, 147, 250, 68, 24, 218, 203, 13, 88, 254, 128, 1, 167, 242, 52, 37, 231, 186, 5, 108, 255, 108, 5, 186, 231, 37, 52, 242, 167, 1, 128, 254, 88, 13, 203, 218, 24, 69, 250, 147, 0, 147, 250, 69, 24, 218, 203, 13, 88, 255, 127, 2, 165, 245, 48 };
|
||||||
|
|
||||||
/* 1200 Hz */
|
/* 1200 Hz -- This lookup table should be deprecated */
|
||||||
|
|
||||||
const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, 249, 230, 128, 24, 7, 88, 203, 255, 203, 88, 7, 24, 128, 230, 249, 167, 53, 0, 53, 167, 249, 230, 128, 24, 6, 88, 202, 255, 202, 88, 6, 24, 127, 231, 249, 167, 52, 0, 52, 167, 248, 231, 127, 25, 6, 89, 202, 255, 202, 89, 6, 25, 127, 231, 248, 167, 53, 0, 54, 165, 251, 227, 133, 14};
|
const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, 249, 230, 128, 24, 7, 88, 203, 255, 203, 88, 7, 24, 128, 230, 249, 167, 53, 0, 53, 167, 249, 230, 128, 24, 6, 88, 202, 255, 202, 88, 6, 24, 127, 231, 249, 167, 52, 0, 52, 167, 248, 231, 127, 25, 6, 89, 202, 255, 202, 89, 6, 25, 127, 231, 248, 167, 53, 0, 54, 165, 251, 227, 133, 14};
|
||||||
|
|
||||||
@@ -122,10 +126,12 @@ HamShield::HamShield() {
|
|||||||
devAddr = A1; // devAddr is the chip select pin used by the HamShield
|
devAddr = A1; // devAddr is the chip select pin used by the HamShield
|
||||||
sHamShield = this;
|
sHamShield = this;
|
||||||
|
|
||||||
pinMode(A1, OUTPUT);
|
pinMode(devAddr, OUTPUT);
|
||||||
digitalWrite(A1, HIGH);
|
digitalWrite(devAddr, HIGH);
|
||||||
pinMode(A4, OUTPUT);
|
pinMode(CLK, OUTPUT);
|
||||||
pinMode(A5, OUTPUT);
|
digitalWrite(CLK, HIGH);
|
||||||
|
pinMode(DAT, OUTPUT);
|
||||||
|
digitalWrite(DAT, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Specific address constructor.
|
/** Specific address constructor.
|
||||||
@@ -137,16 +143,27 @@ HamShield::HamShield() {
|
|||||||
HamShield::HamShield(uint8_t cs_pin) {
|
HamShield::HamShield(uint8_t cs_pin) {
|
||||||
devAddr = cs_pin;
|
devAddr = cs_pin;
|
||||||
|
|
||||||
pinMode(A1, OUTPUT);
|
pinMode(devAddr, OUTPUT);
|
||||||
digitalWrite(A1, HIGH);
|
digitalWrite(devAddr, HIGH);
|
||||||
pinMode(A4, OUTPUT);
|
pinMode(CLK, OUTPUT);
|
||||||
pinMode(A5, OUTPUT);
|
digitalWrite(CLK, HIGH);
|
||||||
|
pinMode(DAT, OUTPUT);
|
||||||
|
digitalWrite(DAT, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Power on and prepare for general usage.
|
/** Power on and prepare for general usage.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void HamShield::initialize() {
|
void HamShield::initialize() {
|
||||||
|
initialize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Power on and prepare for general usage.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void HamShield::initialize(bool narrowBand) {
|
||||||
// Note: these initial settings are for UHF 12.5kHz channel
|
// Note: these initial settings are for UHF 12.5kHz channel
|
||||||
// see the A1846S register table and initial settings for more info
|
// see the A1846S register table and initial settings for more info
|
||||||
|
|
||||||
@@ -175,7 +192,99 @@ void HamShield::initialize() {
|
|||||||
tx_data = 0x0AF2; //
|
tx_data = 0x0AF2; //
|
||||||
HSwriteWord(devAddr, 0x33, tx_data); // agc number
|
HSwriteWord(devAddr, 0x33, tx_data); // agc number
|
||||||
|
|
||||||
// AGC table
|
tx_data = 0x067F; //0x0601; //0x470F;
|
||||||
|
HSwriteWord(devAddr, 0x41, tx_data); // voice gain tx [6:0]
|
||||||
|
tx_data = 0x02FF; // using 0x04FF to avoid tx voice delay
|
||||||
|
HSwriteWord(devAddr, 0x44, tx_data); // tx gain [11:8]
|
||||||
|
tx_data = 0x7F2F;
|
||||||
|
HSwriteWord(devAddr, 0x47, tx_data);
|
||||||
|
tx_data = 0x2C62;
|
||||||
|
HSwriteWord(devAddr, 0x4F, tx_data);
|
||||||
|
tx_data = 0x0094;
|
||||||
|
HSwriteWord(devAddr, 0x53, tx_data); // compressor update time (bits 6:0, 5.12ms per unit)
|
||||||
|
tx_data = 0x2A18;
|
||||||
|
HSwriteWord(devAddr, 0x54, tx_data);
|
||||||
|
tx_data = 0x0081;
|
||||||
|
HSwriteWord(devAddr, 0x55, tx_data);
|
||||||
|
tx_data = 0x0B22;
|
||||||
|
HSwriteWord(devAddr, 0x56, tx_data); // sq detect time
|
||||||
|
tx_data = 0x1C00;
|
||||||
|
HSwriteWord(devAddr, 0x57, tx_data);
|
||||||
|
tx_data = 0x800D;
|
||||||
|
HSwriteWord(devAddr, 0x58, tx_data);
|
||||||
|
tx_data = 0x0EDD;
|
||||||
|
HSwriteWord(devAddr, 0x5A, tx_data); // sq and noise detect times
|
||||||
|
tx_data = 0x3FFF;
|
||||||
|
HSwriteWord(devAddr, 0x63, tx_data); // pre-emphasis bypass
|
||||||
|
|
||||||
|
// calibration
|
||||||
|
tx_data = 0x00A4;
|
||||||
|
HSwriteWord(devAddr, 0x30, tx_data);
|
||||||
|
delay(100);
|
||||||
|
tx_data = 0x00A6;
|
||||||
|
HSwriteWord(devAddr, 0x30, tx_data);
|
||||||
|
delay(100);
|
||||||
|
tx_data = 0x0006;
|
||||||
|
HSwriteWord(devAddr, 0x30, tx_data);
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
|
||||||
|
// set band width
|
||||||
|
if (narrowBand) {
|
||||||
|
setupNarrowBand();
|
||||||
|
} else {
|
||||||
|
setupWideBand();
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
/*
|
||||||
|
// setup default values
|
||||||
|
frequency(446000);
|
||||||
|
//setVolume1(0xF);
|
||||||
|
//setVolume2(0xF);
|
||||||
|
setModeReceive();
|
||||||
|
setTxSourceMic();
|
||||||
|
setRfPower(0);
|
||||||
|
setSQLoThresh(80);
|
||||||
|
setSQOn();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Set up the AU1846 in Narrow Band mode (12.5kHz).
|
||||||
|
*/
|
||||||
|
void HamShield::setupNarrowBand() {
|
||||||
|
uint16_t tx_data;
|
||||||
|
// setup for 12.5kHz channel width
|
||||||
|
tx_data = 0x3D37;
|
||||||
|
HSwriteWord(devAddr, 0x11, tx_data);
|
||||||
|
tx_data = 0x0100;
|
||||||
|
HSwriteWord(devAddr, 0x12, tx_data);
|
||||||
|
tx_data = 0x1100;
|
||||||
|
HSwriteWord(devAddr, 0x15, tx_data);
|
||||||
|
tx_data = 0x4495;
|
||||||
|
HSwriteWord(devAddr, 0x32, tx_data); // agc target power [11:6]
|
||||||
|
tx_data = 0x2B8E;
|
||||||
|
HSwriteWord(devAddr, 0x34, tx_data);
|
||||||
|
tx_data = 0x40C3;
|
||||||
|
HSwriteWord(devAddr, 0x3A, tx_data); // modu_det_sel sq setting
|
||||||
|
tx_data = 0x0407;
|
||||||
|
HSwriteWord(devAddr, 0x3C, tx_data); // pk_det_th sq setting [8:7]
|
||||||
|
tx_data = 0x28D0;
|
||||||
|
HSwriteWord(devAddr, 0x3F, tx_data); // rssi3_th sq setting
|
||||||
|
tx_data = 0x203E;
|
||||||
|
HSwriteWord(devAddr, 0x48, tx_data);
|
||||||
|
tx_data = 0x1BB7;
|
||||||
|
HSwriteWord(devAddr, 0x60, tx_data);
|
||||||
|
tx_data = 0x0A10; // use 0x1425 if there's an LNA
|
||||||
|
HSwriteWord(devAddr, 0x62, tx_data);
|
||||||
|
tx_data = 0x2494;
|
||||||
|
HSwriteWord(devAddr, 0x65, tx_data);
|
||||||
|
tx_data = 0xEB2E;
|
||||||
|
HSwriteWord(devAddr, 0x66, tx_data);
|
||||||
|
|
||||||
|
// AGC table
|
||||||
tx_data = 0x0001;
|
tx_data = 0x0001;
|
||||||
HSwriteWord(devAddr, 0x7F, tx_data);
|
HSwriteWord(devAddr, 0x7F, tx_data);
|
||||||
tx_data = 0x000C;
|
tx_data = 0x000C;
|
||||||
@@ -216,84 +325,80 @@ void HamShield::initialize() {
|
|||||||
HSwriteWord(devAddr, 0x7F, tx_data);
|
HSwriteWord(devAddr, 0x7F, tx_data);
|
||||||
// end AGC table
|
// end AGC table
|
||||||
|
|
||||||
tx_data = 0x067F; //0x0601; //0x470F;
|
}
|
||||||
HSwriteWord(devAddr, 0x41, tx_data); // voice gain tx [6:0]
|
|
||||||
tx_data = 0x02FF; // using 0x04FF to avoid tx voice delay
|
|
||||||
HSwriteWord(devAddr, 0x44, tx_data); // tx gain [11:8]
|
|
||||||
tx_data = 0x7F2F;
|
|
||||||
HSwriteWord(devAddr, 0x47, tx_data);
|
|
||||||
tx_data = 0x2C62;
|
|
||||||
HSwriteWord(devAddr, 0x4F, tx_data);
|
|
||||||
tx_data = 0x0094;
|
|
||||||
HSwriteWord(devAddr, 0x53, tx_data); // compressor update time (bits 6:0, 5.12ms per unit)
|
|
||||||
tx_data = 0x2A18;
|
|
||||||
HSwriteWord(devAddr, 0x54, tx_data);
|
|
||||||
tx_data = 0x0081;
|
|
||||||
HSwriteWord(devAddr, 0x55, tx_data);
|
|
||||||
tx_data = 0x0B22;
|
|
||||||
HSwriteWord(devAddr, 0x56, tx_data); // sq detect time
|
|
||||||
tx_data = 0x1C00;
|
|
||||||
HSwriteWord(devAddr, 0x57, tx_data);
|
|
||||||
tx_data = 0x800D;
|
|
||||||
HSwriteWord(devAddr, 0x58, tx_data);
|
|
||||||
tx_data = 0x0EDD;
|
|
||||||
HSwriteWord(devAddr, 0x5A, tx_data); // sq and noise detect times
|
|
||||||
tx_data = 0x3FFF;
|
|
||||||
HSwriteWord(devAddr, 0x63, tx_data); // pre-emphasis bypass
|
|
||||||
|
|
||||||
// calibration
|
|
||||||
tx_data = 0x00A4;
|
|
||||||
HSwriteWord(devAddr, 0x30, tx_data);
|
|
||||||
delay(100);
|
|
||||||
tx_data = 0x00A6;
|
|
||||||
HSwriteWord(devAddr, 0x30, tx_data);
|
|
||||||
delay(100);
|
|
||||||
tx_data = 0x0006;
|
|
||||||
HSwriteWord(devAddr, 0x30, tx_data);
|
|
||||||
delay(100);
|
|
||||||
|
|
||||||
|
/** Set up the AU1846 in Wide Band mode (25kHz).
|
||||||
// setup for 12.5kHz channel width
|
*/
|
||||||
|
void HamShield::setupWideBand() {
|
||||||
|
uint16_t tx_data;
|
||||||
|
// setup for 25kHz channel width
|
||||||
tx_data = 0x3D37;
|
tx_data = 0x3D37;
|
||||||
HSwriteWord(devAddr, 0x11, tx_data);
|
HSwriteWord(devAddr, 0x11, tx_data);
|
||||||
tx_data = 0x0100;
|
tx_data = 0x0100;
|
||||||
HSwriteWord(devAddr, 0x12, tx_data);
|
HSwriteWord(devAddr, 0x12, tx_data);
|
||||||
tx_data = 0x1100;
|
tx_data = 0x1F00;
|
||||||
HSwriteWord(devAddr, 0x15, tx_data);
|
HSwriteWord(devAddr, 0x15, tx_data);
|
||||||
tx_data = 0x4495;
|
tx_data = 0x7564;
|
||||||
HSwriteWord(devAddr, 0x32, tx_data); // agc target power [11:6]
|
HSwriteWord(devAddr, 0x32, tx_data); // agc target power [11:6]
|
||||||
tx_data = 0x2B8E;
|
tx_data = 0x2B8E;
|
||||||
HSwriteWord(devAddr, 0x34, tx_data);
|
HSwriteWord(devAddr, 0x34, tx_data);
|
||||||
tx_data = 0x40C3;
|
tx_data = 0x44C3;
|
||||||
HSwriteWord(devAddr, 0x3A, tx_data); // modu_det_sel sq setting
|
HSwriteWord(devAddr, 0x3A, tx_data); // modu_det_sel sq setting
|
||||||
tx_data = 0x0407;
|
tx_data = 0x1930;
|
||||||
HSwriteWord(devAddr, 0x3C, tx_data); // pk_det_th sq setting [8:7]
|
HSwriteWord(devAddr, 0x3C, tx_data); // pk_det_th sq setting [8:7]
|
||||||
tx_data = 0x28D0;
|
tx_data = 0x29D2;
|
||||||
HSwriteWord(devAddr, 0x3F, tx_data); // rssi3_th sq setting
|
HSwriteWord(devAddr, 0x3F, tx_data); // rssi3_th sq setting
|
||||||
tx_data = 0x203E;
|
tx_data = 0x21C0;
|
||||||
HSwriteWord(devAddr, 0x48, tx_data);
|
HSwriteWord(devAddr, 0x48, tx_data);
|
||||||
tx_data = 0x1BB7;
|
tx_data = 0x101E;
|
||||||
HSwriteWord(devAddr, 0x60, tx_data);
|
HSwriteWord(devAddr, 0x60, tx_data);
|
||||||
tx_data = 0x0A10; // use 0x1425 if there's an LNA
|
tx_data = 0x3767; // use 0x1425 if there's an LNA
|
||||||
HSwriteWord(devAddr, 0x62, tx_data);
|
HSwriteWord(devAddr, 0x62, tx_data);
|
||||||
tx_data = 0x2494;
|
tx_data = 0x248A;
|
||||||
HSwriteWord(devAddr, 0x65, tx_data);
|
HSwriteWord(devAddr, 0x65, tx_data);
|
||||||
tx_data = 0xEB2E;
|
tx_data = 0xFFAE;
|
||||||
HSwriteWord(devAddr, 0x66, tx_data);
|
HSwriteWord(devAddr, 0x66, tx_data);
|
||||||
|
|
||||||
delay(100);
|
// AGC table
|
||||||
|
tx_data = 0x0001;
|
||||||
/*
|
HSwriteWord(devAddr, 0x7F, tx_data);
|
||||||
// setup default values
|
tx_data = 0x000C;
|
||||||
frequency(446000);
|
HSwriteWord(devAddr, 0x05, tx_data);
|
||||||
//setVolume1(0xF);
|
tx_data = 0x0024;
|
||||||
//setVolume2(0xF);
|
HSwriteWord(devAddr, 0x06, tx_data);
|
||||||
setModeReceive();
|
tx_data = 0x0214;
|
||||||
setTxSourceMic();
|
HSwriteWord(devAddr, 0x07, tx_data);
|
||||||
setRfPower(0);
|
tx_data = 0x0224;
|
||||||
setSQLoThresh(80);
|
HSwriteWord(devAddr, 0x08, tx_data);
|
||||||
setSQOn();
|
tx_data = 0x0314;
|
||||||
*/
|
HSwriteWord(devAddr, 0x09, tx_data);
|
||||||
|
tx_data = 0x0324;
|
||||||
|
HSwriteWord(devAddr, 0x0A, tx_data);
|
||||||
|
tx_data = 0x0344;
|
||||||
|
HSwriteWord(devAddr, 0x0B, tx_data);
|
||||||
|
tx_data = 0x0384;
|
||||||
|
HSwriteWord(devAddr, 0x0C, tx_data);
|
||||||
|
tx_data = 0x1384;
|
||||||
|
HSwriteWord(devAddr, 0x0D, tx_data);
|
||||||
|
tx_data = 0x1B84;
|
||||||
|
HSwriteWord(devAddr, 0x0E, tx_data);
|
||||||
|
tx_data = 0x3F84;
|
||||||
|
HSwriteWord(devAddr, 0x0F, tx_data);
|
||||||
|
tx_data = 0xE0EB;
|
||||||
|
HSwriteWord(devAddr, 0x12, tx_data);
|
||||||
|
tx_data = 0xF2FE;
|
||||||
|
HSwriteWord(devAddr, 0x13, tx_data);
|
||||||
|
tx_data = 0x0A16;
|
||||||
|
HSwriteWord(devAddr, 0x14, tx_data);
|
||||||
|
tx_data = 0x2424;
|
||||||
|
HSwriteWord(devAddr, 0x15, tx_data);
|
||||||
|
tx_data = 0x2424;
|
||||||
|
HSwriteWord(devAddr, 0x16, tx_data);
|
||||||
|
tx_data = 0x2424;
|
||||||
|
HSwriteWord(devAddr, 0x17, tx_data);
|
||||||
|
tx_data = 0x0000;
|
||||||
|
HSwriteWord(devAddr, 0x7F, tx_data);
|
||||||
|
// end AGC table
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Verify the I2C connection.
|
/** Verify the I2C connection.
|
||||||
@@ -567,6 +672,35 @@ uint16_t HamShield::getPABiasVoltage(){
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// Subaudio settings
|
// Subaudio settings
|
||||||
|
|
||||||
|
|
||||||
|
// recommended function for placing CTCSS tone on channel -- schedule remainder for deprecation
|
||||||
|
|
||||||
|
|
||||||
|
// ctcss freq encoder
|
||||||
|
void HamShield::setCtcssEncoder(float freq) {
|
||||||
|
int dfreq = freq * 100; // Convert float into whole number (ctcss freq * 100)
|
||||||
|
setCtcssFreq(dfreq); // program CTCSS frequency buffer
|
||||||
|
HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 10, 1); // program CTCSS frequency buffer into CTCSS encoder (step 1)
|
||||||
|
HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 9, 1); // program CTCSS frequency buffer into CTCSS encoder (step 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// recommended function for detecting (and requiring) CTCSS to be on channel before audio is unmuted -- schedule remainder for deprecation
|
||||||
|
|
||||||
|
// ctcss freq decoder
|
||||||
|
void HamShield::setCtcssDecoder(float freq) {
|
||||||
|
int dfreq = freq * 100; // Convert float into whole number (ctcss freq * 100)
|
||||||
|
setCtcssFreq(dfreq); // program CTCSS frequency buffer
|
||||||
|
HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 10, 1); // program CTCSS frequency buffer into CTCSS encoder (step 1)
|
||||||
|
HSwriteBitW(devAddr, A1846S_CTCSS_FREQ_PRG, 9, 1); // program CTCSS frequency buffer into CTCSS encoder (step 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TX and RX code
|
// TX and RX code
|
||||||
/*
|
/*
|
||||||
Set code mode:
|
Set code mode:
|
||||||
@@ -1279,6 +1413,29 @@ bool HamShield::waitForChannel(long timeout = 0, long breakwindow = 0, int setRS
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get current morse code tone frequency (in Hz)
|
||||||
|
|
||||||
|
unsigned int HamShield::getMorseFreq() {
|
||||||
|
return morse_freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set current morse code tone frequency (in Hz)
|
||||||
|
|
||||||
|
void HamShield::setMorseFreq(unsigned int morse_freq_hz) {
|
||||||
|
morse_freq = morse_freq_hz;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current duration of a morse dot (shorter is more WPM)
|
||||||
|
|
||||||
|
unsigned int HamShield::getMorseDotMillis() {
|
||||||
|
return morse_dot_millis;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set current duration of a morse dot (shorter is more WPM)
|
||||||
|
|
||||||
|
void HamShield::setMorseDotMillis(unsigned int morse_dot_dur_millis) {
|
||||||
|
morse_dot_millis = morse_dot_dur_millis;
|
||||||
|
}
|
||||||
|
|
||||||
/* Morse code out, blocking */
|
/* Morse code out, blocking */
|
||||||
|
|
||||||
@@ -1290,10 +1447,13 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
|
|||||||
if(buffer[i] == ' ') {
|
if(buffer[i] == ' ') {
|
||||||
// We delay by 4 here, if we previously sent a symbol. Otherwise 7.
|
// We delay by 4 here, if we previously sent a symbol. Otherwise 7.
|
||||||
// This could probably just be always 7 and go relatively unnoticed.
|
// This could probably just be always 7 and go relatively unnoticed.
|
||||||
if(prev == 0 || prev == ' ')
|
if(prev == 0 || prev == ' '){
|
||||||
delay(HAMSHIELD_MORSE_DOT*7);
|
tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 7);
|
||||||
else
|
delay(morse_dot_millis*7);
|
||||||
delay(HAMSHIELD_MORSE_DOT*4);
|
} else {
|
||||||
|
tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 4);
|
||||||
|
delay(morse_dot_millis*4);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Otherwise, lookup our character symbol
|
// Otherwise, lookup our character symbol
|
||||||
@@ -1301,18 +1461,20 @@ void HamShield::morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]) {
|
|||||||
if(bits) { // If it is a valid character...
|
if(bits) { // If it is a valid character...
|
||||||
do {
|
do {
|
||||||
if(bits & 1) {
|
if(bits & 1) {
|
||||||
tone(HAMSHIELD_PWM_PIN, 1000, HAMSHIELD_MORSE_DOT * 3);
|
tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis * 3);
|
||||||
delay(HAMSHIELD_MORSE_DOT*3);
|
delay(morse_dot_millis*3);
|
||||||
} else {
|
} else {
|
||||||
tone(HAMSHIELD_PWM_PIN, 1000, HAMSHIELD_MORSE_DOT);
|
tone(HAMSHIELD_PWM_PIN, morse_freq, morse_dot_millis);
|
||||||
delay(HAMSHIELD_MORSE_DOT);
|
delay(morse_dot_millis);
|
||||||
}
|
}
|
||||||
delay(HAMSHIELD_MORSE_DOT);
|
tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis);
|
||||||
|
delay(morse_dot_millis);
|
||||||
bits >>= 1; // Shift into the next symbol
|
bits >>= 1; // Shift into the next symbol
|
||||||
} while(bits != 1); // Wait for 1 termination to be all we have left
|
} while(bits != 1); // Wait for 1 termination to be all we have left
|
||||||
}
|
}
|
||||||
// End of character
|
// End of character
|
||||||
delay(HAMSHIELD_MORSE_DOT * 3);
|
tone(HAMSHIELD_PWM_PIN, 6000, morse_dot_millis * 3);
|
||||||
|
delay(morse_dot_millis * 3);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2,39 +2,29 @@
|
|||||||
// Based on Programming Manual rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
// Based on Programming Manual rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||||
// 11/22/2013 by Morgan Redfield <redfieldm@gmail.com>
|
// 11/22/2013 by Morgan Redfield <redfieldm@gmail.com>
|
||||||
// 04/26/2015 various changes Casey Halverson <spaceneedle@gmail.com>
|
// 04/26/2015 various changes Casey Halverson <spaceneedle@gmail.com>
|
||||||
|
// 05/08/2017 CTCSS code added
|
||||||
|
|
||||||
|
|
||||||
#ifndef _HAMSHIELD_H_
|
#ifndef _HAMSHIELD_H_
|
||||||
#define _HAMSHIELD_H_
|
#define _HAMSHIELD_H_
|
||||||
|
|
||||||
//#include "I2Cdev_rda.h"
|
|
||||||
//#include "I2Cdev.h"
|
|
||||||
#include "HamShield_comms.h"
|
#include "HamShield_comms.h"
|
||||||
#include "SimpleFIFO.h"
|
//#include "SimpleFIFO.h"
|
||||||
#include "AFSK.h"
|
//#include "AFSK.h"
|
||||||
#include "DDS.h"
|
//#include "DDS.h"
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
// HamShield constants
|
// HamShield constants
|
||||||
|
|
||||||
#define HAMSHIELD_MORSE_DOT 100 // Morse code dot length (smaller is faster WPM)
|
|
||||||
#define HAMSHIELD_MORSE_BUFFER_SIZE 80 // Char buffer size for morse code text
|
#define HAMSHIELD_MORSE_BUFFER_SIZE 80 // Char buffer size for morse code text
|
||||||
#define HAMSHIELD_AUX_BUTTON 2 // Pin assignment for AUX button
|
#define HAMSHIELD_AUX_BUTTON 2 // Pin assignment for AUX button
|
||||||
#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output
|
#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output
|
||||||
#define HAMSHIELD_EMPTY_CHANNEL_RSSI -110 // Default threshold where channel is considered "clear"
|
#define HAMSHIELD_EMPTY_CHANNEL_RSSI -110 // Default threshold where channel is considered "clear"
|
||||||
|
|
||||||
#define HAMSHIELD_AFSK_RX_FIFO_LEN 16
|
|
||||||
|
|
||||||
// button modes
|
// button modes
|
||||||
#define PTT_MODE 1
|
#define PTT_MODE 1
|
||||||
#define RESET_MODE 2
|
#define RESET_MODE 2
|
||||||
|
|
||||||
// Device Constants
|
|
||||||
#define A1846S_DEV_ADDR_SENHIGH 0b0101110
|
|
||||||
#define A1846S_DEV_ADDR_SENLOW 0b1110001
|
|
||||||
|
|
||||||
|
|
||||||
// Device Registers
|
// Device Registers
|
||||||
#define A1846S_CTL_REG 0x30 // control register
|
#define A1846S_CTL_REG 0x30 // control register
|
||||||
#define A1846S_CLK_MODE_REG 0x04 // clk_mode
|
#define A1846S_CLK_MODE_REG 0x04 // clk_mode
|
||||||
@@ -57,6 +47,7 @@
|
|||||||
#define A1846S_CTCSS_FREQ_REG 0x4A // ctcss_freq<15:0>
|
#define A1846S_CTCSS_FREQ_REG 0x4A // ctcss_freq<15:0>
|
||||||
#define A1846S_CDCSS_CODE_HI_REG 0x4B // cdcss_code<23:16>
|
#define A1846S_CDCSS_CODE_HI_REG 0x4B // cdcss_code<23:16>
|
||||||
#define A1846S_CDCSS_CODE_LO_REG 0x4C // cdccs_code<15:0>
|
#define A1846S_CDCSS_CODE_LO_REG 0x4C // cdccs_code<15:0>
|
||||||
|
#define A1846S_CTCSS_FREQ_PRG 0x4e // copies CTCSS value from A1846S_CTCSS_FREQ_REG into CTCSS encoder
|
||||||
#define A1846S_SQ_OUT_SEL_REG 0x54 // see sq
|
#define A1846S_SQ_OUT_SEL_REG 0x54 // see sq
|
||||||
#define A1846S_EMPH_FILTER_REG 0x58
|
#define A1846S_EMPH_FILTER_REG 0x58
|
||||||
#define A1846S_FLAG_REG 0x5C // holds flags for different statuses
|
#define A1846S_FLAG_REG 0x5C // holds flags for different statuses
|
||||||
@@ -265,7 +256,10 @@ class HamShield {
|
|||||||
HamShield();
|
HamShield();
|
||||||
HamShield(uint8_t cs_pin);
|
HamShield(uint8_t cs_pin);
|
||||||
|
|
||||||
void initialize();
|
void initialize(); // defaults to 12.5kHz
|
||||||
|
void initialize(bool narrowBand); // select 12.5kHz if true or 25kHz if false
|
||||||
|
void setupWideBand();
|
||||||
|
void setupNarrowBand();
|
||||||
bool testConnection();
|
bool testConnection();
|
||||||
|
|
||||||
// read control reg
|
// read control reg
|
||||||
@@ -318,6 +312,15 @@ class HamShield {
|
|||||||
|
|
||||||
// Subaudio settings
|
// Subaudio settings
|
||||||
|
|
||||||
|
// Recommended user function for setting and receiving CTCSS does
|
||||||
|
// TODO: set others to private and/or deprecate
|
||||||
|
|
||||||
|
void setCtcssEncoder(float freq); // generate sub audio tone on channel when transmitting
|
||||||
|
void setCtcssDecoder(float freq); // unmute audio on tone present when receiving channel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Ctcss/cdcss mode sel
|
// Ctcss/cdcss mode sel
|
||||||
// x00=disable,
|
// x00=disable,
|
||||||
// 001=inner ctcss en,
|
// 001=inner ctcss en,
|
||||||
@@ -490,6 +493,10 @@ class HamShield {
|
|||||||
void buttonMode(uint8_t mode);
|
void buttonMode(uint8_t mode);
|
||||||
static void isr_ptt();
|
static void isr_ptt();
|
||||||
static void isr_reset();
|
static void isr_reset();
|
||||||
|
unsigned int getMorseFreq();
|
||||||
|
void setMorseFreq(unsigned int morse_freq_hz);
|
||||||
|
unsigned int getMorseDotMillis();
|
||||||
|
void setMorseDotMillis(unsigned int morse_dot_dur_millis);
|
||||||
void morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]);
|
void morseOut(char buffer[HAMSHIELD_MORSE_BUFFER_SIZE]);
|
||||||
uint8_t morseLookup(char letter);
|
uint8_t morseLookup(char letter);
|
||||||
bool waitForChannel(long timeout, long breakwindow, int setRSSI);
|
bool waitForChannel(long timeout, long breakwindow, int setRSSI);
|
||||||
@@ -498,15 +505,17 @@ class HamShield {
|
|||||||
void toneWait(uint16_t freq, long timer);
|
void toneWait(uint16_t freq, long timer);
|
||||||
void toneWaitU(uint16_t freq, long timer);
|
void toneWaitU(uint16_t freq, long timer);
|
||||||
bool parityCalc(int code);
|
bool parityCalc(int code);
|
||||||
// void AFSKOut(char buffer[80]);
|
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: split AFSK out so it can be left out
|
||||||
// AFSK routines
|
// AFSK routines
|
||||||
bool AFSKStart();
|
//bool AFSKStart();
|
||||||
bool AFSKEnabled() { return afsk.enabled(); }
|
//bool AFSKEnabled() { return afsk.enabled(); }
|
||||||
bool AFSKStop();
|
//bool AFSKStop();
|
||||||
bool AFSKOut(const char *);
|
//bool AFSKOut(const char *);
|
||||||
|
|
||||||
class AFSK afsk;
|
//class AFSK afsk;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t devAddr;
|
uint8_t devAddr;
|
||||||
@@ -514,11 +523,11 @@ class HamShield {
|
|||||||
bool tx_active;
|
bool tx_active;
|
||||||
bool rx_active;
|
bool rx_active;
|
||||||
uint32_t radio_frequency;
|
uint32_t radio_frequency;
|
||||||
uint32_t FRS[];
|
/* uint32_t FRS[];
|
||||||
uint32_t GMRS[];
|
uint32_t GMRS[];
|
||||||
uint32_t MURS[];
|
uint32_t MURS[];
|
||||||
uint32_t WX[];
|
uint32_t WX[];
|
||||||
|
*/
|
||||||
// private utility functions
|
// private utility functions
|
||||||
// these functions should not be called in the Arduino sketch
|
// these functions should not be called in the Arduino sketch
|
||||||
// just use the above public functions to do everything
|
// just use the above public functions to do everything
|
||||||
@@ -33,54 +33,27 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data)
|
|||||||
uint16_t temp_dat;
|
uint16_t temp_dat;
|
||||||
// bitbang for great justice!
|
// bitbang for great justice!
|
||||||
*data = 0;
|
*data = 0;
|
||||||
cli();
|
pinMode(DAT, OUTPUT);
|
||||||
DDRC |= ((1<<5) | (1<<4)); // set direction to output
|
|
||||||
sei();
|
|
||||||
regAddr = regAddr | (1 << 7);
|
regAddr = regAddr | (1 << 7);
|
||||||
|
|
||||||
//cli();
|
|
||||||
digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select
|
digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select
|
||||||
//sei();
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
temp = ((regAddr & (0x80 >> i)) != 0);
|
temp = ((regAddr & (0x80 >> i)) != 0);
|
||||||
cli();
|
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||||
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
|
digitalWrite(DAT, temp);
|
||||||
sei();
|
digitalWrite(CLK, 1); //PORTC |= (1<<5); //
|
||||||
//digitalWrite(DAT, regAddr & (0x80 >> i));
|
|
||||||
temp = (PORTC & ~(1<<4)) + (temp << 4);
|
|
||||||
cli();
|
|
||||||
PORTC = temp;
|
|
||||||
sei();
|
|
||||||
delayMicroseconds(9);
|
|
||||||
cli();
|
|
||||||
PORTC |= (1<<5); //digitalWrite(CLK, 1);
|
|
||||||
sei();
|
|
||||||
delayMicroseconds(9);
|
|
||||||
}
|
}
|
||||||
// change direction of DAT
|
// change direction of DAT
|
||||||
cli();
|
pinMode(DAT, INPUT); // DDRC &= ~(1<<4); //
|
||||||
DDRC &= ~(1<<4); //pinMode(DAT, INPUT);
|
|
||||||
sei();
|
|
||||||
for (int i = 15; i >= 0; i--) {
|
for (int i = 15; i >= 0; i--) {
|
||||||
cli();
|
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||||
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
|
digitalWrite(CLK, 1); //PORTC |= (1<<5); //
|
||||||
sei();
|
temp_dat = digitalRead(DAT); //((PINC & (1<<4)) != 0);
|
||||||
delayMicroseconds(9);
|
|
||||||
cli();
|
|
||||||
PORTC |= (1<<5); //digitalWrite(CLK, 1);
|
|
||||||
sei();
|
|
||||||
cli();
|
|
||||||
temp_dat = ((PINC & (1<<4)) != 0);
|
|
||||||
sei();
|
|
||||||
temp_dat = temp_dat << i;
|
temp_dat = temp_dat << i;
|
||||||
*data |= temp_dat; // digitalRead(DAT);
|
*data |= temp_dat;
|
||||||
delayMicroseconds(9);
|
|
||||||
}
|
}
|
||||||
digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS
|
digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS
|
||||||
|
|
||||||
cli();
|
|
||||||
DDRC &= ~((1<<5) | (1<<4)); // set direction all input (for ADC)
|
|
||||||
sei();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,52 +91,24 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data)
|
|||||||
//digitalWrite(13, HIGH);
|
//digitalWrite(13, HIGH);
|
||||||
|
|
||||||
// bitbang for great justice!
|
// bitbang for great justice!
|
||||||
cli();
|
pinMode(DAT, OUTPUT);
|
||||||
DDRC |= ((1<<5) | (1<<4)); // set direction all output
|
|
||||||
//PORTC |= (1<<5) & (1<<4);
|
|
||||||
sei();
|
|
||||||
regAddr = regAddr & ~(1 << 7);
|
regAddr = regAddr & ~(1 << 7);
|
||||||
|
|
||||||
//cli();
|
|
||||||
digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS
|
digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS
|
||||||
//sei();
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
||||||
cli();
|
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||||
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
|
digitalWrite(DAT, regAddr & (0x80 >> i));
|
||||||
sei();
|
digitalWrite(CLK, 1); // PORTC |= (1<<5); //
|
||||||
//digitalWrite(DAT, regAddr & (0x80 >> i));
|
|
||||||
temp_reg = (PORTC & ~(1<<4)) + (temp_reg << 4);
|
|
||||||
cli();
|
|
||||||
PORTC = temp_reg;
|
|
||||||
sei();
|
|
||||||
delayMicroseconds(8);
|
|
||||||
cli();
|
|
||||||
PORTC |= (1<<5); //digitalWrite(CLK, 1);
|
|
||||||
sei();
|
|
||||||
delayMicroseconds(10);
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
temp_dat = ((data & (0x8000 >> i)) != 0);
|
temp_dat = ((data & (0x8000 >> i)) != 0);
|
||||||
cli();
|
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
||||||
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
|
digitalWrite(DAT, temp_dat);
|
||||||
sei();
|
digitalWrite(CLK, 1); // PORTC |= (1<<5); //
|
||||||
//digitalWrite(DAT, data & (0x80000 >> i));
|
|
||||||
temp_reg = (PORTC & ~(1<<4)) + (temp_dat << 4);
|
|
||||||
cli();
|
|
||||||
PORTC = temp_reg;
|
|
||||||
sei();
|
|
||||||
delayMicroseconds(7);
|
|
||||||
cli();
|
|
||||||
PORTC |= (1<<5); //digitalWrite(CLK, 1);
|
|
||||||
sei();
|
|
||||||
delayMicroseconds(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
||||||
|
|
||||||
cli();
|
|
||||||
DDRC &= ~((1<<5) | (1<<4)); // set direction to input for ADC
|
|
||||||
sei();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user