From 0b2683e4864865d00b55ba24503f565713db045c Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 15 Apr 2014 20:18:22 +0200 Subject: [PATCH] Before interleaver --- Modem/config.h | 4 ++-- Modem/hardware.c | 2 +- Modem/main.c | 15 ++++++++------- Modem/protocol/mp1.c | 23 +++++++++++++++++++---- Modem/protocol/mp1.h | 3 ++- buildrev.h | 2 +- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Modem/config.h b/Modem/config.h index 56c07c5..c2d238f 100644 --- a/Modem/config.h +++ b/Modem/config.h @@ -11,7 +11,7 @@ #define CONFIG_AFSK_RXTIMEOUT 0 // How long a read operation from the modem // will wait for data before timing out. -#define CONFIG_AFSK_PREAMBLE_LEN 250UL // The length of the packet preamble in milliseconds -#define CONFIG_AFSK_TRAILER_LEN 20UL // The length of the packet tail in milliseconds +#define CONFIG_AFSK_PREAMBLE_LEN 500UL // The length of the packet preamble in milliseconds +#define CONFIG_AFSK_TRAILER_LEN 100UL // The length of the packet tail in milliseconds #endif \ No newline at end of file diff --git a/Modem/hardware.c b/Modem/hardware.c index 9714e37..1102b85 100644 --- a/Modem/hardware.c +++ b/Modem/hardware.c @@ -19,7 +19,7 @@ static Afsk *modem; // M1 correction = 9500 // M2 correction = 40000 -#define FREQUENCY_CORRECTION 40000 +#define FREQUENCY_CORRECTION 9500 // This function initializes the ADC and configures // it the way we need. diff --git a/Modem/main.c b/Modem/main.c index 14a46dd..94e6eee 100644 --- a/Modem/main.c +++ b/Modem/main.c @@ -49,13 +49,12 @@ static bool sertx = false; // Flag signifying whether it's time to send da // Right now it just prints the packet to the serial port. static void mp1Callback(struct MP1Packet *packet) { kfile_printf(&ser.fd, "%.*s\n", packet->dataLength, packet->data); - - // if (false) { - // // strcmp(packet->data, "OZ7TMD") - // timer_delay(300); - // mp1Send(&mp1, TEST_PACKET, sizeof(TEST_PACKET)); - // } - + + if (packet->data[0]-128 == 'R' && packet->data[1]-128 == 'Q') { + timer_delay(1000); + mp1Send(&mp1, TEST_PACKET, sizeof(TEST_PACKET)); + } + //kprintf("%.*s\n", packet->dataLength, packet->data); } @@ -118,6 +117,8 @@ int main(void) // If one of the above conditions were actually the // case, it means we have to transmit, se we set // transmission flag to true. + serialBuffer[serialLen] = sbyte; + serialLen++; sertx = true; } } diff --git a/Modem/protocol/mp1.c b/Modem/protocol/mp1.c index b2ef8ff..9afb2ce 100644 --- a/Modem/protocol/mp1.c +++ b/Modem/protocol/mp1.c @@ -113,6 +113,8 @@ void mp1Poll(MP1 *mp1) { mp1->checksum_in ^= correction; } mp1->buffer[mp1->packetLength-(2-i)] ^= correction; + + if (s != 0) mp1->correctionsMade += 1; } } continue; @@ -129,13 +131,15 @@ void mp1Poll(MP1 *mp1) { // the end of the packet. Pass control to the // decoder. if ((mp1->checksum_in & 0xff) == 0x00) { + kprintf("[CHK-OK] [C=%d] ", mp1->correctionsMade); mp1Decode(mp1); } else { // Checksum was incorrect, we don't do anything, // but you can enable the decode anyway, if you // need it for testing or debugging // kprintf("[ER] [%d] ", mp1->checksum_in); - //mp1Decode(mp1); + kprintf("[CHK-ER] [C=%d] ", mp1->correctionsMade); + mp1Decode(mp1); } } // If the above is not the case, this must be the @@ -144,6 +148,7 @@ void mp1Poll(MP1 *mp1) { mp1->packetLength = 0; mp1->readLength = 0; mp1->checksum_in = MP1_CHECKSUM_INIT; + mp1->correctionsMade = 0; // We have indicated that we are reading, // and reset the length counter. Now we'll @@ -206,8 +211,6 @@ static void mp1Putbyte(MP1 *mp1, uint8_t byte) { byte == HDLC_RESET || byte == AX25_ESC) { kfile_putc(AX25_ESC, mp1->modem); - lastByte = AX25_ESC; - //sendParityBlock ^= true; } kfile_putc(byte, mp1->modem); @@ -221,6 +224,19 @@ static void mp1Putbyte(MP1 *mp1, uint8_t byte) { sendParityBlock ^= true; } +static void mp1WriteByte(MP1 *mp1, uint8_t byte) { + // If we are sending something that looks + // like an HDLC special byte, send an escape + // character first + if (byte == HDLC_FLAG || + byte == HDLC_RESET || + byte == AX25_ESC) { + kfile_putc(AX25_ESC, mp1->modem); + } + + kfile_putc(byte, mp1->modem); +} + void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { // Get the transmit data buffer const uint8_t *buffer = (const uint8_t *)_buffer; @@ -234,7 +250,6 @@ void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { bool packetCompression = false; size_t compressedSize = compress(buffer, length); if (compressedSize != 0 && compressedSize < length) { - //kprintf("Using compression\n"); // Compression saved us some space, we'll // send the paket compressed packetCompression = true; diff --git a/Modem/protocol/mp1.h b/Modem/protocol/mp1.h index 1c29ce3..61b3cdc 100644 --- a/Modem/protocol/mp1.h +++ b/Modem/protocol/mp1.h @@ -6,7 +6,7 @@ // Frame sizing & checksum #define MP1_MIN_FRAME_LENGTH 3 -#define MP1_MAX_FRAME_LENGTH 200 +#define MP1_MAX_FRAME_LENGTH 300 #define MP1_CHECKSUM_INIT 0xAA // We need to know some basic HDLC flag bytes @@ -44,6 +44,7 @@ typedef struct MP1 { bool reading; // True when we have seen a HDLC flag bool escape; // We need to know if we are in an escape sequence bool fecEscape; // fec escape + long correctionsMade; // correction count } MP1; // A struct encapsulating a network packet diff --git a/buildrev.h b/buildrev.h index c9c7547..484351d 100644 --- a/buildrev.h +++ b/buildrev.h @@ -1,2 +1,2 @@ -#define VERS_BUILD 1070 +#define VERS_BUILD 1108 #define VERS_HOST "vixen"