diff --git a/AFSK.cpp b/AFSK.cpp index f89501b..b56363e 100644 --- a/AFSK.cpp +++ b/AFSK.cpp @@ -476,7 +476,29 @@ size_t AFSK::Packet::write(const uint8_t *ptr, size_t len) { 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); +} + // Determine what we want to do on this ADC tick. void AFSK::timer() { if(encoder.isSending()) diff --git a/AFSK.h b/AFSK.h index 694b50e..1f8b860 100644 --- a/AFSK.h +++ b/AFSK.h @@ -14,6 +14,10 @@ #define PACKET_BUFFER_SIZE 2 #define PACKET_STATIC 0 + +// 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, framing and full payload @@ -87,6 +91,8 @@ public: return false; } + size_t appendCallsign(const char *callsign, uint8_t ssid, bool final = false); + inline void finish() { append(~(fcs & 0xff)); append(~((fcs>>8) & 0xff)); diff --git a/examples/AFSK-Send/AFSK-Send.ino b/examples/AFSK-Send/AFSK-Send.ino index 9b15847..104d39c 100644 --- a/examples/AFSK-Send/AFSK-Send.ino +++ b/examples/AFSK-Send/AFSK-Send.ino @@ -31,20 +31,8 @@ void loop() { // put your main code here, to run repeatedly: AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32); packet->start(); - packet->appendFCS('V'<<1); - packet->appendFCS('E'<<1); - packet->appendFCS('6'<<1); - packet->appendFCS('S'<<1); - packet->appendFCS('L'<<1); - packet->appendFCS('P'<<1); - packet->appendFCS(0b11100000); - packet->appendFCS('V'<<1); - packet->appendFCS('A'<<1); - packet->appendFCS('6'<<1); - packet->appendFCS('G'<<1); - packet->appendFCS('A'<<1); - packet->appendFCS(' '<<1); - packet->appendFCS(0b01100001 | (15 & 0xf) << 1); + packet->appendCallsign("VE6SLP",0); + packet->appendCallsign("VA6GA",15,true); packet->appendFCS(0x03); packet->appendFCS(0xf0); packet->print("Hello "); @@ -61,7 +49,7 @@ void loop() { // 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.isSending()) + if(!radio.afsk.encoder.isSending()) break; delay(50); }