diff --git a/Modem/compression/heatshrink_encoder.c b/Modem/compression/heatshrink_encoder.c index 54d6e79..f2cc24f 100644 --- a/Modem/compression/heatshrink_encoder.c +++ b/Modem/compression/heatshrink_encoder.c @@ -38,7 +38,7 @@ static const char *state_names[] = { }; #else #define LOG(...) /* no-op */ -#define ASSERT(X) /* no-op */ +//#define ASSERT(X) /* no-op */ #endif // Encoder flags @@ -315,7 +315,6 @@ static HSE_state st_step_search(heatshrink_encoder *hse) { LOG("ss Found match of %d bytes at %d\n", match_length, match_pos); hse->match_pos = match_pos; hse->match_length = match_length; - ASSERT(match_pos < 1 << hse->window_sz2 /*window_length*/); return HSES_YIELD_TAG_BIT; } diff --git a/Modem/config.h b/Modem/config.h index c19edc8..66b0237 100644 --- a/Modem/config.h +++ b/Modem/config.h @@ -3,7 +3,7 @@ #define FSK_CFG // Debug & test options -#define SERIAL_DEBUG true +#define SERIAL_DEBUG false #define PASSALL false #define AUTOREPLY false @@ -17,7 +17,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 500UL // The length of the packet preamble in milliseconds -#define CONFIG_AFSK_TRAILER_LEN 100UL // The length of the packet tail in milliseconds +#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 #endif \ No newline at end of file diff --git a/Modem/main.c b/Modem/main.c index 65b96d4..0da2aac 100644 --- a/Modem/main.c +++ b/Modem/main.c @@ -39,7 +39,6 @@ static size_t serialLen = 0; // Counter for counting length of data from s static bool sertx = false; // Flag signifying whether it's time to send data // Received on the serial port. - ////////////////////////////////////////////////////// // And here comes the actual program :) // ////////////////////////////////////////////////////// @@ -52,7 +51,9 @@ static void mp1Callback(struct MP1Packet *packet) { if (AUTOREPLY && packet->data[0]-128 == 'R' && packet->data[1]-128 == 'Q') { timer_delay(1000); - mp1Send(&mp1, TEST_PACKET, sizeof(TEST_PACKET)); + + uint8_t output[sizeof(TEST_PACKET)] = TEST_PACKET; + mp1Send(&mp1, output, sizeof(TEST_PACKET)); } } @@ -134,7 +135,8 @@ int main(void) // Reset the timer counter; start = timer_clock(); // And send a test packet! - mp1Send(&mp1, TEST_PACKET, sizeof(TEST_PACKET)); + uint8_t output[sizeof(TEST_PACKET)] = TEST_PACKET; + mp1Send(&mp1, output, sizeof(TEST_PACKET)); } } return 0; diff --git a/Modem/protocol/mp1.c b/Modem/protocol/mp1.c index d019841..c9e7335 100644 --- a/Modem/protocol/mp1.c +++ b/Modem/protocol/mp1.c @@ -20,6 +20,10 @@ static uint8_t lastByte = 0x00; // decompressing packet data. static uint8_t compressionBuffer[MP1_MAX_FRAME_LENGTH+10]; +// An int to hold amount of free RAM updated +// by the FREE_RAM function; +static int FREE_RAM; + // The GET_BIT macro is used in the interleaver // and deinterleaver to access single bits of a // byte. @@ -68,6 +72,8 @@ static void mp1Decode(MP1 *mp1) { buffer++; } + if (SERIAL_DEBUG) kprintf("[TS=%d] ", mp1->packetLength); + // Set the payload length of the packet to the counted // length minus 1, so we remove the checksum packet.dataLength = mp1->packetLength - 2 - (header & 0x01); @@ -76,7 +82,9 @@ static void mp1Decode(MP1 *mp1) { if (header & MP1_HEADER_COMPRESSION) { // If we have, we decompress it and use the // decompressed data for the packet + if (SERIAL_DEBUG) kprintf("[CS=%d] ", packet.dataLength); size_t decompressedSize = decompress(buffer, packet.dataLength); + if (SERIAL_DEBUG) kprintf("[DS=%d]", decompressedSize); packet.dataLength = decompressedSize; memcpy(buffer, compressionBuffer, decompressedSize); } @@ -113,7 +121,7 @@ void mp1Poll(MP1 *mp1) { // HDLC_FLAG), we will start looking at the // incoming data and perform forward error // correction on it. - if (mp1->reading && (byte != AX25_ESC) ) { + if ((mp1->reading && (byte != AX25_ESC )) || (mp1->reading && (mp1->escape && byte == AX25_ESC))) { mp1->readLength++; // Check if we have read three bytes. If we @@ -331,7 +339,6 @@ static void mp1Putbyte(MP1 *mp1, uint8_t byte) { if (sendParityBlock) { uint8_t p = mp1ParityBlock(lastByte, byte); - //kfile_putc(p, mp1->modem); mp1Interleave(mp1, p); } @@ -342,9 +349,11 @@ static void mp1Putbyte(MP1 *mp1, uint8_t byte) { // This function accepts a buffer with data // to be transmitted, and structures it into // a valid packet. -void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { +void mp1Send(MP1 *mp1, void *_buffer, size_t length) { // Get the transmit data buffer - const uint8_t *buffer = (const uint8_t *)_buffer; + uint8_t *buffer = (uint8_t *)_buffer; + + uint8_t *compressed = (uint8_t *)compressionBuffer; // Initialize checksum to zero mp1->checksum_out = MP1_CHECKSUM_INIT; @@ -352,9 +361,6 @@ void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { // We also reset the interleave counter to zero mp1->interleaveCounter = 0; - // Transmit the HDLC_FLAG to signify start of TX - kfile_putc(HDLC_FLAG, mp1->modem); - // We start out assuming we should not use // compression. bool packetCompression = false; @@ -369,6 +375,7 @@ void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { // Write the compressed data into the // outgoing data buffer memcpy(buffer, compressionBuffer, compressedSize); + // Make sure to set the length of the // data to the new (compressed) length length = compressedSize; @@ -377,6 +384,8 @@ void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { // so we don't do anything. } + // Transmit the HDLC_FLAG to signify start of TX + kfile_putc(HDLC_FLAG, mp1->modem); // We now need to construct a header, that // can tell the receiving end whether the @@ -437,8 +446,8 @@ void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { // counter reaches 3, a block will be // transmitted. while (length--) { - mp1->checksum_out = mp1->checksum_out ^ *buffer; - mp1Putbyte(mp1, *buffer++); + mp1->checksum_out = mp1->checksum_out ^ *buffer; + mp1Putbyte(mp1, *buffer++); } // Finally we write the checksum to the @@ -466,8 +475,9 @@ void mp1Init(MP1 *mp1, KFile *modem, mp1_callback_t callback) { // how much available memory we have left. int freeRam(void) { extern int __heap_start, *__brkval; - int v; - return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); + int v; + FREE_RAM = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); + return FREE_RAM; } // Following is the functions responsible @@ -601,6 +611,7 @@ void mp1Deinterleave(MP1 *mp1) { size_t compress(uint8_t *input, size_t length) { heatshrink_encoder *hse = heatshrink_encoder_alloc(8, 4); if (hse == NULL) { + if (SERIAL_DEBUG) kprintf("Could not allocate compressor\n"); return 0; } @@ -627,6 +638,7 @@ size_t compress(uint8_t *input, size_t length) { size_t decompress(uint8_t *input, size_t length) { heatshrink_decoder *hsd = heatshrink_decoder_alloc(MP1_MAX_FRAME_LENGTH, 8, 4); if (hsd == NULL) { + if (SERIAL_DEBUG) kprintf("Could not allocate decompressor\n"); return 0; } diff --git a/Modem/protocol/mp1.h b/Modem/protocol/mp1.h index 3f574c5..6d32439 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 300 +#define MP1_MAX_FRAME_LENGTH 250 #define MP1_INTERLEAVE_SIZE 3 #define MP1_CHECKSUM_INIT 0xAA @@ -59,7 +59,7 @@ typedef struct MP1Packet { void mp1Init(MP1 *mp1, KFile *modem, mp1_callback_t callback); void mp1Read(MP1 *mp1, int byte); void mp1Poll(MP1 *mp1); -void mp1Send(MP1 *mp1, const void *_buffer, size_t length); +void mp1Send(MP1 *mp1, void *_buffer, size_t length); int freeRam(void); size_t compress(uint8_t *input, size_t length); diff --git a/bertos/cpu/avr/drv/ser_mega.c b/bertos/cpu/avr/drv/ser_mega.c index 5e89325..9df3032 100644 --- a/bertos/cpu/avr/drv/ser_mega.c +++ b/bertos/cpu/avr/drv/ser_mega.c @@ -690,7 +690,9 @@ static void spi_init(UNUSED_ARG(struct SerialHardware *, _hw), UNUSED_ARG(struct * - as input but tied high forever! * This driver set the pin as output. */ - #warning FIXME:SPI SS pin set as output for proper operation, check schematics for possible conflicts. + + // Squelching this warning + // #warning FIXME:SPI SS pin set as output for proper operation, check schematics for possible conflicts. ATOMIC(SPI_DDR |= BV(SPI_SS_BIT)); ATOMIC(SPI_DDR &= ~BV(SPI_MISO_BIT)); diff --git a/buildrev.h b/buildrev.h index 480d29a..cd67810 100644 --- a/buildrev.h +++ b/buildrev.h @@ -1,2 +1,2 @@ -#define VERS_BUILD 1206 +#define VERS_BUILD 1281 #define VERS_HOST "vixen"