Compression on/off compile option.
This commit is contained in:
parent
409e9d93d0
commit
864c5d7dc4
|
@ -19,7 +19,7 @@
|
||||||
#define CONFIG_AFSK_RXTIMEOUT 0 // How long a read operation from the modem
|
#define CONFIG_AFSK_RXTIMEOUT 0 // How long a read operation from the modem
|
||||||
// will wait for data before timing out.
|
// will wait for data before timing out.
|
||||||
|
|
||||||
#define CONFIG_AFSK_PREAMBLE_LEN 350UL // The length of the packet preamble in milliseconds
|
#define CONFIG_AFSK_PREAMBLE_LEN 150UL // The length of the packet preamble in milliseconds
|
||||||
#define CONFIG_AFSK_TRAILER_LEN 50UL // The length of the packet tail in milliseconds
|
#define CONFIG_AFSK_TRAILER_LEN 50UL // The length of the packet tail in milliseconds
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -28,7 +28,7 @@ static Serial ser; // Declare a serial interface struct
|
||||||
// for the ADC (this is A0 on arduino)
|
// for the ADC (this is A0 on arduino)
|
||||||
|
|
||||||
|
|
||||||
static uint8_t serialBuffer[MP1_MAX_DATA_SIZE]; // This is a buffer for incoming serial data
|
static uint8_t serialBuffer[MP1_MAX_DATA_SIZE]; // This is a buffer for incoming serial data
|
||||||
|
|
||||||
static int sbyte; // For holding byte read from serial port
|
static int sbyte; // For holding byte read from serial port
|
||||||
static size_t serialLen = 0; // Counter for counting length of data from serial
|
static size_t serialLen = 0; // Counter for counting length of data from serial
|
||||||
|
|
|
@ -20,11 +20,15 @@ static uint8_t lastByte = 0x00;
|
||||||
|
|
||||||
// We also need a buffer for compressing and
|
// We also need a buffer for compressing and
|
||||||
// decompressing packet data.
|
// decompressing packet data.
|
||||||
static uint8_t compressionBuffer[MP1_MAX_FRAME_LENGTH+10];
|
#if MP1_ENABLE_COMPRESSION
|
||||||
|
static uint8_t compressionBuffer[MP1_MAX_DATA_SIZE];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SERIAL_DEBUG
|
||||||
// An int to hold amount of free RAM updated
|
// An int to hold amount of free RAM updated
|
||||||
// by the FREE_RAM function;
|
// by the FREE_RAM function;
|
||||||
static int FREE_RAM;
|
static int FREE_RAM;
|
||||||
|
#endif
|
||||||
|
|
||||||
// The GET_BIT macro is used in the interleaver
|
// The GET_BIT macro is used in the interleaver
|
||||||
// and deinterleaver to access single bits of a
|
// and deinterleaver to access single bits of a
|
||||||
|
@ -84,14 +88,16 @@ static void mp1Decode(MP1 *mp1) {
|
||||||
packet.dataLength = mp1->packetLength - 2 - (header & MP1_HEADER_PADDED)*padding;
|
packet.dataLength = mp1->packetLength - 2 - (header & MP1_HEADER_PADDED)*padding;
|
||||||
|
|
||||||
// Check if we have received a compressed packet
|
// Check if we have received a compressed packet
|
||||||
if (header & MP1_HEADER_COMPRESSION) {
|
if (MP1_ENABLE_COMPRESSION && (header & MP1_HEADER_COMPRESSION)) {
|
||||||
// If we have, we decompress it and use the
|
// If we have, we decompress it and use the
|
||||||
// decompressed data for the packet
|
// decompressed data for the packet
|
||||||
if (SERIAL_DEBUG) kprintf("[CS=%d] ", packet.dataLength);
|
#if MP1_ENABLE_COMPRESSION
|
||||||
size_t decompressedSize = decompress(buffer, packet.dataLength);
|
if (SERIAL_DEBUG) kprintf("[CS=%d] ", packet.dataLength);
|
||||||
if (SERIAL_DEBUG) kprintf("[DS=%d]", decompressedSize);
|
size_t decompressedSize = decompress(buffer, packet.dataLength);
|
||||||
packet.dataLength = decompressedSize;
|
if (SERIAL_DEBUG) kprintf("[DS=%d]", decompressedSize);
|
||||||
memcpy(mp1->buffer, compressionBuffer, decompressedSize);
|
packet.dataLength = decompressedSize;
|
||||||
|
memcpy(mp1->buffer, compressionBuffer, decompressedSize);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
// If the packet was not compressed, we shift
|
// If the packet was not compressed, we shift
|
||||||
// the data in our buffer back down to the actual
|
// the data in our buffer back down to the actual
|
||||||
|
@ -420,22 +426,24 @@ void mp1Send(MP1 *mp1, void *_buffer, size_t length) {
|
||||||
|
|
||||||
// We then try to compress the data to see
|
// We then try to compress the data to see
|
||||||
// if we can save some space with compression.
|
// if we can save some space with compression.
|
||||||
size_t compressedSize = compress(buffer, length);
|
#if MP1_ENABLE_COMPRESSION
|
||||||
if (compressedSize != 0 && compressedSize < length) {
|
size_t compressedSize = compress(buffer, length);
|
||||||
// Compression saved us some space, we'll
|
if (compressedSize != 0 && compressedSize < length) {
|
||||||
// send the paket compressed
|
// Compression saved us some space, we'll
|
||||||
packetCompression = true;
|
// send the paket compressed
|
||||||
// Write the compressed data into the
|
packetCompression = true;
|
||||||
// outgoing data buffer
|
// Write the compressed data into the
|
||||||
memcpy(buffer, compressionBuffer, compressedSize);
|
// outgoing data buffer
|
||||||
|
memcpy(buffer, compressionBuffer, compressedSize);
|
||||||
|
|
||||||
// Make sure to set the length of the
|
// Make sure to set the length of the
|
||||||
// data to the new (compressed) length
|
// data to the new (compressed) length
|
||||||
length = compressedSize;
|
length = compressedSize;
|
||||||
} else {
|
} else {
|
||||||
// We are not going to use compression,
|
// We are not going to use compression,
|
||||||
// so we don't do anything.
|
// so we don't do anything.
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Transmit the HDLC_FLAG to signify start of TX
|
// Transmit the HDLC_FLAG to signify start of TX
|
||||||
kfile_putc(HDLC_FLAG, mp1->modem);
|
kfile_putc(HDLC_FLAG, mp1->modem);
|
||||||
|
@ -568,15 +576,18 @@ bool mp1CarrierSense(MP1 *mp1) {
|
||||||
|
|
||||||
// A handy debug function that can determine
|
// A handy debug function that can determine
|
||||||
// how much available memory we have left.
|
// how much available memory we have left.
|
||||||
|
#if SERIAL_DEBUG
|
||||||
int freeRam(void) {
|
int freeRam(void) {
|
||||||
extern int __heap_start, *__brkval;
|
extern int __heap_start, *__brkval;
|
||||||
int v;
|
int v;
|
||||||
FREE_RAM = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
FREE_RAM = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
||||||
return FREE_RAM;
|
return FREE_RAM;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// This function compresses data using
|
// This function compresses data using
|
||||||
// the Heatshrink library
|
// the Heatshrink library
|
||||||
|
#if MP1_ENABLE_COMPRESSION
|
||||||
size_t compress(uint8_t *input, size_t length) {
|
size_t compress(uint8_t *input, size_t length) {
|
||||||
heatshrink_encoder *hse = heatshrink_encoder_alloc(8, 4);
|
heatshrink_encoder *hse = heatshrink_encoder_alloc(8, 4);
|
||||||
if (hse == NULL) {
|
if (hse == NULL) {
|
||||||
|
@ -601,9 +612,11 @@ size_t compress(uint8_t *input, size_t length) {
|
||||||
heatshrink_encoder_free(hse);
|
heatshrink_encoder_free(hse);
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// This function decompresses data using
|
// This function decompresses data using
|
||||||
// the Heatshrink library
|
// the Heatshrink library
|
||||||
|
#if MP1_ENABLE_COMPRESSION
|
||||||
size_t decompress(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);
|
heatshrink_decoder *hsd = heatshrink_decoder_alloc(MP1_MAX_FRAME_LENGTH, 8, 4);
|
||||||
if (hsd == NULL) {
|
if (hsd == NULL) {
|
||||||
|
@ -628,6 +641,7 @@ size_t decompress(uint8_t *input, size_t length) {
|
||||||
heatshrink_decoder_free(hsd);
|
heatshrink_decoder_free(hsd);
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Following is the functions responsible
|
// Following is the functions responsible
|
||||||
|
|
|
@ -4,9 +4,17 @@
|
||||||
#include <cfg/compiler.h>
|
#include <cfg/compiler.h>
|
||||||
#include <io/kfile.h>
|
#include <io/kfile.h>
|
||||||
|
|
||||||
|
// Options
|
||||||
|
#define MP1_ENABLE_COMPRESSION false
|
||||||
|
#define MP1_ENABLE_CSMA true
|
||||||
|
|
||||||
// Frame sizing & checksum
|
// Frame sizing & checksum
|
||||||
#define MP1_INTERLEAVE_SIZE 12
|
#define MP1_INTERLEAVE_SIZE 12
|
||||||
#define MP1_MAX_FRAME_LENGTH 22 * MP1_INTERLEAVE_SIZE
|
#if MP1_ENABLE_COMPRESSION
|
||||||
|
#define MP1_MAX_FRAME_LENGTH 22 * MP1_INTERLEAVE_SIZE
|
||||||
|
#else
|
||||||
|
#define MP1_MAX_FRAME_LENGTH 56 * MP1_INTERLEAVE_SIZE
|
||||||
|
#endif
|
||||||
#define MP1_HEADER_SIZE 1
|
#define MP1_HEADER_SIZE 1
|
||||||
#define MP1_CHECKSUM_SIZE 1
|
#define MP1_CHECKSUM_SIZE 1
|
||||||
#define MP1_MAX_DATA_SIZE MP1_MAX_FRAME_LENGTH - MP1_HEADER_SIZE - MP1_CHECKSUM_SIZE
|
#define MP1_MAX_DATA_SIZE MP1_MAX_FRAME_LENGTH - MP1_HEADER_SIZE - MP1_CHECKSUM_SIZE
|
||||||
|
@ -16,7 +24,6 @@
|
||||||
|
|
||||||
// These two parameters are used for
|
// These two parameters are used for
|
||||||
// P-persistent CSMA
|
// P-persistent CSMA
|
||||||
#define MP1_ENABLE_CSMA false
|
|
||||||
#define MP1_SETTLE_TIME 100UL // The minimum wait time before considering sending
|
#define MP1_SETTLE_TIME 100UL // The minimum wait time before considering sending
|
||||||
#define MP1_P_PERSISTENCE 85UL // The probability (between 0 and 255) for sending
|
#define MP1_P_PERSISTENCE 85UL // The probability (between 0 and 255) for sending
|
||||||
#define MP1_TXDELAY 150UL // Delay between turning on the transmitter and sending
|
#define MP1_TXDELAY 150UL // Delay between turning on the transmitter and sending
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#define VERS_BUILD 1576
|
#define VERS_BUILD 1598
|
||||||
#define VERS_HOST "shard"
|
#define VERS_HOST "shard"
|
||||||
|
|
Loading…
Reference in New Issue