Skip to content

Commit 58678a1

Browse files
siara-ccsiara-in
authored andcommitted
First commit
1 parent 30a7f2e commit 58678a1

File tree

10 files changed

+2896
-0
lines changed

10 files changed

+2896
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
This example demonstrates compression and de-compression of Short Strings
3+
using Shox96 compression utility found at https://github.com/siara-cc/Shox96
4+
5+
How Shox96 works:
6+
https://github.com/siara-cc/Shox96/blob/master/Shox96_Article_0_2_0.pdf?raw=true
7+
8+
Other projects using Shox96:
9+
As SQLite loadable extension - https://github.com/siara-cc/Shox96_Sqlite_UDF
10+
Sqlite3 Library for ESP32 - https://github.com/siara-cc/esp32_arduino_sqlite3_lib
11+
Sqlite3 Library for ESP8266 - https://github.com/siara-cc/esp_arduino_sqlite3_lib
12+
Sqlite3 Library for ESP-IDF - https://github.com/siara-cc/esp32-idf-sqlite3
13+
*/
14+
#include "shox96_0_2.h"
15+
16+
void setup() {
17+
18+
Serial.begin(115200);
19+
20+
}
21+
22+
void print_compressed(char *in, int len) {
23+
int l;
24+
byte bit;
25+
for (l=0; l<len; l++) {
26+
Serial.write((int) in[l]);
27+
}
28+
Serial.write("\n");
29+
for (l=0; l<len*8; l++) {
30+
bit = (in[l/8]>>(7-l%8))&0x01;
31+
Serial.print((int)bit);
32+
if (l%8 == 7) printf(" ");
33+
}
34+
}
35+
36+
int input_string(char *str, int max_len) {
37+
max_len--;
38+
int ctr = 0;
39+
str[ctr] = 0;
40+
while (str[ctr] != '\n') {
41+
if (Serial.available()) {
42+
str[ctr] = Serial.read();
43+
if (str[ctr] >= ' ' && str[ctr] <= '~')
44+
ctr++;
45+
if (ctr >= max_len)
46+
break;
47+
}
48+
}
49+
str[ctr] = 0;
50+
Serial.println(str);
51+
return ctr;
52+
}
53+
54+
55+
void loop() {
56+
57+
char str[256];
58+
char cbuf[300];
59+
char dbuf[300];
60+
Serial.write("Welcome\n");
61+
Serial.write("-------\n");
62+
63+
Serial.write("Enter string to compress:\n");
64+
int len = input_string(str);
65+
66+
if (len > 0) {
67+
memset(cbuf, 0, sizeof(cbuf));
68+
int ctot = shox96_0_2_compress(str, len, cbuf, NULL);
69+
print_compressed(cbuf, ctot);
70+
memset(dbuf, 0, sizeof(dbuf));
71+
int dlen = shox96_0_2_decompress(cbuf, ctot, dbuf, NULL);
72+
dbuf[dlen] = 0;
73+
Serial.write("Decompressed:");
74+
Serial.write(dbuf);
75+
float perc = (len-ctot);
76+
perc /= len;
77+
perc *= 100;
78+
Serial.write("\nRatio: ");
79+
Serial.write(ctot);
80+
Serial.write("/");
81+
Serial.write(len);
82+
Serial.write("=");
83+
Serial.write(perc);
84+
}
85+
86+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
This example demonstrates de-compression of Error messages
3+
Source: include/errno.h
4+
Decompresses data from errno.h, which was generated using Shox96 compression utility
5+
found at https://github.com/siara-cc/Shox96
6+
Command to generate Errno.h: `./shox96 G errno.txt errno`
7+
8+
Original size: 2122 bytes
9+
Compressed size: 1212 bytes
10+
Savings: 42.88%
11+
12+
The savings do not justify compression as the decompressor itself takes around 3500 bytes.
13+
This example has been given to show the use case.
14+
15+
How Shox96 works:
16+
https://github.com/siara-cc/Shox96/blob/master/Shox96_Article_0_2_0.pdf?raw=true
17+
18+
Other projects using Shox96:
19+
As SQLite loadable extension - https://github.com/siara-cc/Shox96_Sqlite_UDF
20+
Sqlite3 Library for ESP32 - https://github.com/siara-cc/esp32_arduino_sqlite3_lib
21+
Sqlite3 Library for ESP8266 - https://github.com/siara-cc/esp_arduino_sqlite3_lib
22+
Sqlite3 Library for ESP-IDF - https://github.com/siara-cc/esp32-idf-sqlite3
23+
*/
24+
#include "shox96_0_2.h"
25+
#include "errno.h"
26+
27+
void setup() {
28+
29+
Serial.begin(115200);
30+
Serial.write("Hello World\n");
31+
32+
char out[100];
33+
34+
for (int i=0; i < errno0_2_line_count; i++) {
35+
int len = shox96_0_2_decompress(errno0_2, i, out, 0);
36+
out[len] = 0;
37+
Serial.write(out);
38+
Serial.write("\n");
39+
}
40+
41+
}
42+
43+
void loop() {
44+
45+
}

examples/Error_Messages/errno.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#ifndef __errno_SHOX96_0_2_COMPRESSED__
2+
#define __errno_SHOX96_0_2_COMPRESSED__
3+
const byte errno0_2_0[] PROGMEM = {13, 43, 20, 253, 83, 47, 86, 220, 66, 159, 133, 228, 140, 35};
4+
const byte errno0_2_1[] PROGMEM = {15, 45, 181, 194, 0, 52, 61, 159, 106, 252, 130, 207, 48, 75, 240, 249};
5+
const byte errno0_2_2[] PROGMEM = {9, 45, 181, 194, 0, 52, 43, 214, 7, 220};
6+
const byte errno0_2_3[] PROGMEM = {14, 44, 216, 253, 225, 5, 70, 18, 225, 254, 140, 90, 5, 127, 230};
7+
const byte errno0_2_4[] PROGMEM = {12, 44, 209, 66, 67, 178, 196, 130, 132, 137, 251, 215, 227};
8+
const byte errno0_2_5[] PROGMEM = {13, 32, 153, 140, 3, 91, 113, 2, 244, 123, 6, 137, 230, 17};
9+
const byte errno0_2_6[] PROGMEM = {13, 42, 240, 209, 5, 189, 139, 249, 209, 75, 181, 251, 209, 166};
10+
const byte errno0_2_7[] PROGMEM = {11, 38, 106, 96, 67, 215, 225, 117, 19, 247, 175, 198};
11+
const byte errno0_2_8[] PROGMEM = {12, 33, 148, 18, 30, 207, 180, 19, 224, 123, 5, 75, 241};
12+
const byte errno0_2_9[] PROGMEM = {11, 45, 180, 0, 243, 225, 33, 94, 176, 62, 231, 198};
13+
const byte errno0_2_10[] PROGMEM = {15, 47, 62, 177, 60, 6, 130, 116, 23, 236, 6, 74, 140, 94, 4, 194};
14+
const byte errno0_2_11[] PROGMEM = {9, 57, 33, 33, 213, 200, 137, 208, 218, 205};
15+
const byte errno0_2_12[] PROGMEM = {13, 32, 86, 237, 197, 95, 253, 130, 163, 66, 216, 187, 240, 249};
16+
const byte errno0_2_13[] PROGMEM = {10, 33, 79, 194, 243, 187, 47, 80, 79, 113, 132};
17+
const byte errno0_2_14[] PROGMEM = {7, 33, 148, 18, 160, 130, 243, 238};
18+
const byte errno0_2_15[] PROGMEM = {14, 33, 159, 176, 25, 32, 153, 140, 3, 94, 102, 98, 103, 152, 70};
19+
const byte errno0_2_16[] PROGMEM = {8, 32, 153, 140, 3, 67, 4, 225, 243};
20+
const byte errno0_2_17[] PROGMEM = {7, 33, 236, 251, 76, 213, 157, 56};
21+
const byte errno0_2_18[] PROGMEM = {11, 32, 122, 251, 142, 176, 153, 140, 3, 95, 205, 50};
22+
const byte errno0_2_19[] PROGMEM = {15, 55, 16, 157, 194, 10, 21, 126, 140, 36, 48, 125, 4, 204, 96, 25};
23+
const byte errno0_2_20[] PROGMEM = {9, 45, 184, 169, 5, 158, 96, 151, 225, 243};
24+
const byte errno0_2_21[] PROGMEM = {9, 44, 229, 72, 44, 243, 4, 191, 15, 155};
25+
const byte errno0_2_22[] PROGMEM = {10, 44, 211, 21, 252, 9, 87, 134, 136, 45, 236};
26+
const byte errno0_2_23[] PROGMEM = {17, 41, 118, 133, 214, 143, 171, 20, 245, 15, 103, 223, 44, 213, 195, 253, 24, 179};
27+
const byte errno0_2_24[] PROGMEM = {3, 55, 33, 128};
28+
const byte errno0_2_25[] PROGMEM = {18, 44, 218, 20, 43, 214, 43, 217, 81, 172, 176, 79, 161, 235, 242, 9, 152, 192, 51};
29+
const byte errno0_2_26[] PROGMEM = {10, 40, 205, 81, 15, 103, 218, 24, 39, 15, 155};
30+
const byte errno0_2_27[] PROGMEM = {9, 33, 236, 251, 82, 237, 126, 188, 53, 155};
31+
const byte errno0_2_28[] PROGMEM = {13, 45, 181, 194, 168, 13, 125, 143, 69, 122, 130, 102, 48, 12};
32+
const byte errno0_2_29[] PROGMEM = {8, 44, 255, 216, 218, 250, 230, 204, 141};
33+
const byte errno0_2_30[] PROGMEM = {14, 47, 58, 8, 235, 189, 248, 250, 30, 207, 190, 31, 232, 197, 155};
34+
const byte errno0_2_31[] PROGMEM = {9, 41, 118, 133, 214, 143, 175, 230, 153, 113};
35+
const byte errno0_2_32[] PROGMEM = {8, 33, 158, 179, 39, 168, 86, 10, 102};
36+
const byte errno0_2_33[] PROGMEM = {19, 45, 16, 91, 246, 2, 190, 171, 195, 68, 22, 246, 43, 18, 43, 30, 65, 88, 186, 205};
37+
const byte errno0_2_34[] PROGMEM = {9, 47, 62, 19, 241, 75, 181, 250, 240, 214};
38+
const byte errno0_2_35[] PROGMEM = {20, 47, 62, 177, 60, 6, 163, 22, 42, 253, 94, 207, 143, 161, 54, 140, 86, 126, 134, 125, 155};
39+
const byte errno0_2_36[] PROGMEM = {14, 43, 20, 253, 83, 47, 80, 235, 19, 225, 33, 159, 176, 25, 27};
40+
const byte errno0_2_37[] PROGMEM = {11, 55, 0, 192, 7, 44, 212, 43, 214, 55, 207, 184};
41+
const byte errno0_2_38[] PROGMEM = {17, 43, 20, 253, 83, 47, 85, 127, 206, 130, 31, 89, 168, 87, 172, 111, 159, 113};
42+
const byte errno0_2_39[] PROGMEM = {17, 46, 176, 25, 56, 172, 83, 245, 76, 189, 87, 171, 111, 78, 190, 176, 25, 56};
43+
const byte errno0_2_40[] PROGMEM = {16, 32, 159, 76, 218, 153, 122, 168, 32, 188, 251, 151, 153, 152, 153, 230, 17};
44+
const byte errno0_2_41[] PROGMEM = {10, 33, 111, 186, 134, 181, 46, 215, 239, 70, 155};
45+
const byte errno0_2_42[] PROGMEM = {19, 33, 94, 185, 96, 191, 161, 222, 189, 26, 160, 248, 166, 135, 175, 203, 172, 6, 78, 27};
46+
const byte errno0_2_43[] PROGMEM = {13, 33, 94, 185, 96, 191, 173, 184, 168, 197, 103, 232, 103, 217};
47+
const byte errno0_2_44[] PROGMEM = {8, 55, 8, 28, 32, 161, 87, 232, 194};
48+
const byte errno0_2_45[] PROGMEM = {10, 46, 176, 25, 56, 160, 248, 166, 110, 40, 128};
49+
const byte errno0_2_46[] PROGMEM = {9, 55, 16, 194, 120, 65, 66, 175, 209, 132};
50+
const byte errno0_2_47[] PROGMEM = {13, 33, 94, 185, 96, 191, 161, 234, 23, 159, 31, 55, 20, 68};
51+
const byte errno0_2_48[] PROGMEM = {14, 42, 8, 47, 62, 227, 114, 44, 64, 134, 15, 161, 70, 226, 32};
52+
const byte errno0_2_49[] PROGMEM = {10, 42, 8, 47, 62, 227, 112, 69, 140, 39, 51};
53+
const byte errno0_2_50[] PROGMEM = {18, 32, 86, 159, 113, 87, 118, 13, 213, 230, 102, 35, 232, 194, 84, 16, 94, 125, 198};
54+
const byte errno0_2_51[] PROGMEM = {10, 45, 112, 117, 248, 201, 103, 32, 172, 118, 155};
55+
const byte errno0_2_52[] PROGMEM = {13, 45, 112, 117, 248, 201, 103, 33, 55, 206, 128, 29, 12, 251};
56+
const byte errno0_2_53[] PROGMEM = {20, 45, 112, 117, 248, 201, 5, 235, 20, 41, 132, 129, 123, 172, 19, 47, 85, 234, 243, 231, 13};
57+
const byte errno0_2_54[] PROGMEM = {14, 46, 177, 232, 58, 188, 208, 40, 78, 55, 20, 145, 67, 47, 208};
58+
const byte errno0_2_55[] PROGMEM = {13, 32, 94, 235, 4, 203, 213, 231, 206, 33, 131, 232, 83, 126};
59+
const byte errno0_2_56[] PROGMEM = {16, 45, 180, 48, 65, 225, 231, 229, 194, 168, 13, 81, 138, 207, 208, 207, 179};
60+
const byte errno0_2_57[] PROGMEM = {15, 46, 176, 25, 56, 179, 149, 127, 206, 130, 31, 64, 189, 214, 8, 194};
61+
const byte errno0_2_58[] PROGMEM = {12, 46, 176, 25, 56, 179, 150, 220, 64, 189, 214, 8, 194};
62+
const byte errno0_2_59[] PROGMEM = {19, 32, 86, 159, 113, 115, 208, 149, 15, 71, 229, 214, 3, 39, 23, 6, 36, 10, 199, 105};
63+
const byte errno0_2_60[] PROGMEM = {20, 41, 118, 133, 214, 143, 175, 49, 231, 231, 160, 124, 121, 160, 86, 159, 113, 112, 175, 224, 25};
64+
const byte errno0_2_61[] PROGMEM = {11, 43, 20, 253, 83, 47, 84, 193, 108, 37, 98, 67};
65+
const byte errno0_2_62[] PROGMEM = {7, 55, 8, 132, 60, 39, 48, 141};
66+
const byte errno0_2_63[] PROGMEM = {21, 41, 118, 133, 214, 143, 175, 179, 15, 252, 172, 121, 112, 248, 177, 151, 252, 2, 254, 105, 151, 27};
67+
const byte errno0_2_64[] PROGMEM = {11, 33, 236, 251, 91, 66, 218, 151, 107, 247, 163, 77};
68+
const byte errno0_2_65[] PROGMEM = {7, 32, 239, 162, 206, 65, 88, 237};
69+
const byte errno0_2_66[] PROGMEM = {9, 45, 181, 235, 18, 53, 45, 7, 125, 13};
70+
const byte errno0_2_67[] PROGMEM = {12, 32, 179, 204, 18, 252, 62, 182, 226, 98, 197, 65, 243};
71+
const byte errno0_2_68[] PROGMEM = {11, 41, 118, 133, 214, 143, 161, 94, 176, 62, 231, 198};
72+
const byte errno0_2_69[] PROGMEM = {9, 41, 118, 133, 214, 143, 161, 57, 251, 141};
73+
const byte errno0_2_70[] PROGMEM = {12, 32, 179, 128, 140, 196, 185, 73, 154, 128, 216, 76, 35};
74+
const byte errno0_2_71[] PROGMEM = {14, 46, 149, 246, 139, 72, 120, 185, 15, 103, 218, 14, 180, 47, 179};
75+
const byte errno0_2_72[] PROGMEM = {11, 55, 33, 136, 158, 98, 238, 53, 154, 133, 84, 12};
76+
const byte errno0_2_73[] PROGMEM = {12, 47, 16, 162, 2, 233, 225, 1, 22, 114, 25, 65, 27};
77+
const byte errno0_2_74[] PROGMEM = {12, 47, 16, 162, 2, 48, 253, 217, 122, 135, 122, 244, 105};
78+
const byte errno0_2_75[] PROGMEM = {14, 47, 16, 162, 2, 21, 235, 26, 116, 91, 113, 81, 138, 207, 155};
79+
const byte errno0_2_76[] PROGMEM = {8, 33, 94, 177, 190, 161, 102, 226, 100};
80+
const byte errno0_2_77[] PROGMEM = {17, 33, 148, 18, 21, 235, 3, 8, 79, 52, 61, 126, 66, 189, 99, 125, 66, 205};
81+
const byte errno0_2_78[] PROGMEM = {11, 45, 181, 251, 1, 151, 42, 49, 89, 250, 25, 246};
82+
const byte errno0_2_79[] PROGMEM = {14, 33, 225, 52, 19, 47, 86, 220, 88, 44, 87, 216, 183, 177, 132};
83+
const byte errno0_2_80[] PROGMEM = {15, 55, 16, 196, 135, 179, 237, 65, 241, 77, 95, 144, 245, 248, 93, 67};
84+
const byte errno0_2_81[] PROGMEM = {11, 42, 18, 6, 246, 96, 42, 101, 234, 126, 245, 248};
85+
const byte errno0_2_82[] PROGMEM = {10, 45, 108, 37, 66, 64, 222, 204, 5, 75, 241};
86+
const byte errno0_2_83[] PROGMEM = {11, 44, 9, 236, 193, 236, 126, 94, 98, 236, 195, 8};
87+
const byte errno0_2_84[] PROGMEM = {15, 45, 180, 45, 247, 80, 214, 172, 121, 4, 251, 60, 194, 80, 124, 83};
88+
const byte errno0_2_85[] PROGMEM = {22, 35, 21, 241, 26, 151, 107, 245, 225, 173, 75, 67, 26, 233, 126, 97, 44, 212, 21, 74, 80, 124, 83};
89+
const byte errno0_2_86[] PROGMEM = {10, 43, 20, 253, 83, 47, 80, 43, 64, 254, 194};
90+
const byte errno0_2_87[] PROGMEM = {13, 44, 255, 216, 218, 250, 24, 63, 26, 230, 102, 35, 208, 51};
91+
const byte errno0_2_88[] PROGMEM = {11, 42, 147, 216, 48, 72, 214, 220, 67, 214, 38, 132};
92+
const byte errno0_2_89[] PROGMEM = {12, 33, 94, 177, 190, 161, 98, 243, 70, 167, 239, 95, 141};
93+
const byte errno0_2_90[] PROGMEM = {16, 33, 98, 116, 67, 26, 102, 98, 87, 215, 235, 195, 95, 68, 253, 237, 179};
94+
const byte errno0_2_91[] PROGMEM = {14, 23, 97, 96, 240, 250, 243, 130, 123, 84, 180, 43, 214, 7, 220};
95+
const byte errno0_2_92[] PROGMEM = {9, 243, 233, 94, 139, 135, 248, 21, 255, 155};
96+
const byte errno0_2_93[] PROGMEM = {19, 10, 244, 251, 136, 93, 133, 131, 195, 235, 204, 111, 29, 72, 208, 78, 139, 206, 9, 237};
97+
const byte errno0_2_94[] PROGMEM = {18, 203, 4, 250, 219, 136, 58, 208, 190, 194, 67, 7, 212, 15, 57, 126, 135, 223, 141};
98+
const byte errno0_2_95[] PROGMEM = {15, 10, 208, 89, 230, 8, 178, 193, 62, 179, 81, 13, 38, 86, 66, 205};
99+
const byte * const errno0_2[] PROGMEM = {errno0_2_0, errno0_2_1, errno0_2_2, errno0_2_3, errno0_2_4, errno0_2_5, errno0_2_6, errno0_2_7, errno0_2_8, errno0_2_9, errno0_2_10, errno0_2_11, errno0_2_12, errno0_2_13, errno0_2_14, errno0_2_15, errno0_2_16, errno0_2_17, errno0_2_18, errno0_2_19, errno0_2_20, errno0_2_21, errno0_2_22, errno0_2_23, errno0_2_24, errno0_2_25, errno0_2_26, errno0_2_27, errno0_2_28, errno0_2_29, errno0_2_30, errno0_2_31, errno0_2_32, errno0_2_33, errno0_2_34, errno0_2_35, errno0_2_36, errno0_2_37, errno0_2_38, errno0_2_39, errno0_2_40, errno0_2_41, errno0_2_42, errno0_2_43, errno0_2_44, errno0_2_45, errno0_2_46, errno0_2_47, errno0_2_48, errno0_2_49, errno0_2_50, errno0_2_51, errno0_2_52, errno0_2_53, errno0_2_54, errno0_2_55, errno0_2_56, errno0_2_57, errno0_2_58, errno0_2_59, errno0_2_60, errno0_2_61, errno0_2_62, errno0_2_63, errno0_2_64, errno0_2_65, errno0_2_66, errno0_2_67, errno0_2_68, errno0_2_69, errno0_2_70, errno0_2_71, errno0_2_72, errno0_2_73, errno0_2_74, errno0_2_75, errno0_2_76, errno0_2_77, errno0_2_78, errno0_2_79, errno0_2_80, errno0_2_81, errno0_2_82, errno0_2_83, errno0_2_84, errno0_2_85, errno0_2_86, errno0_2_87, errno0_2_88, errno0_2_89, errno0_2_90, errno0_2_91, errno0_2_92, errno0_2_93, errno0_2_94, errno0_2_95};
100+
#define errno0_2_line_count 96
101+
#define errno0_2_max_len 47
102+
#endif

0 commit comments

Comments
 (0)