From a4bdef41510e15fc27c20967cd68e96be9cc98eb Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Mon, 11 Apr 2022 22:12:04 -0700 Subject: [PATCH] compression WIP compression works. next is to store it in the proto as a oneof and then decompress it on use. --- platformio.ini | 5 ++++- src/mesh/Router.cpp | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index e692888c2..ba5c37489 100644 --- a/platformio.ini +++ b/platformio.ini @@ -110,11 +110,14 @@ lib_ignore = ESP32 BLE Arduino platform_packages = framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#4cde0f5d412d2695184f32e8a47e9bea57b45276 -; leave this commented out to avoid breaking Windows +; leave this commented out to avoid breaking Windows ;upload_port = /dev/ttyUSB0 ;monitor_port = /dev/ttyUSB0 +upload_port = /dev/cu.SLAB_USBtoUART +monitor_port = /dev/cu.SLAB_USBtoUART + ; customize the partition table ; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables board_build.partitions = partition-table.csv diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 34ab85a26..c81359604 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -325,26 +325,29 @@ Routing_Error perhapsEncode(MeshPacket *p) size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), Data_fields, &p->decoded); - if (1) { - // int orig_len, compressed_len; + if (p->decoded.portnum == PortNum_TEXT_MESSAGE_APP) { + + char original_payload[Constants_DATA_PAYLOAD_LEN]; + memcpy(original_payload, p->decoded.payload.bytes, p->decoded.payload.size); + int compressed_len; char compressed_out[100] = {0}; - // char *orig = (char *)"Hiiiiiiii! :) How are you doing? I am doing well."; - // char *orig = (char *)"Meshtastic"; - // orig_len = strlen(orig); - // compressed_len = unishox2_compress_simple(orig, orig_len, compressed_out); - compressed_len = unishox2_compress_simple((char *)bytes, numbytes, compressed_out); + compressed_len = unishox2_compress_simple(original_payload, p->decoded.payload.size, compressed_out); + Serial.print("Original length - "); + Serial.println(p->decoded.payload.size); + + Serial.print("Compressed length - "); Serial.println(compressed_len); - Serial.println(compressed_out); - //&p->decoded.portnum; + //Serial.println(compressed_out); char decompressed_out[100] = {}; int decompressed_len; decompressed_len = unishox2_decompress_simple(compressed_out, compressed_len, decompressed_out); + Serial.print("Decompressed length - "); Serial.println(decompressed_len); Serial.println(decompressed_out); }