Merge branch 'master' of ssh://git.dryerzinia.io/opt/git/BluetoothLE_AFSK_TNC
Merge branch 'master' of ssh://git.dryerzinia.io/opt/git/BluetoothLE_AFSK_TNC

--- a/src/APRS_PIC.X/nbproject/configurations.xml
+++ b/src/APRS_PIC.X/nbproject/configurations.xml
@@ -58,7 +58,7 @@
         <targetPluginBoard></targetPluginBoard>
         <platformTool>PICkit3PlatformTool</platformTool>
         <languageToolchain>XC16</languageToolchain>
-        <languageToolchainVersion>1.24</languageToolchainVersion>
+        <languageToolchainVersion>1.23</languageToolchainVersion>
         <platform>2</platform>
       </toolsSet>
       <compileType>

--- a/src/APRS_PIC.X/src/base64.c
+++ b/src/APRS_PIC.X/src/base64.c
@@ -50,6 +50,9 @@
             output++;
             *output = '\0';
             break;
+        case 0:
+            output--;
+            *output = '\0';
     }
 
     return (uint16_t)(output - start);

--- /dev/null
+++ b/src/APRS_PIC.X/src/test/.gitignore
@@ -1,1 +1,2 @@
+test
 

 Binary files a/src/APRS_PIC.X/src/test/test and /dev/null differ
--- a/src/APRS_PIC.X/src/test/test.c
+++ b/src/APRS_PIC.X/src/test/test.c
@@ -14,6 +14,85 @@
 		0xae, 0x8e ,0xac, 'g', 0xf0, 0x03, 'T', 'e', 's', 't',
 		'i', 'n', 'g', ':', 0xef
 	};
+
+const char base64_encode_tests[][255] =
+	{
+		"",
+		"f",
+		"fo",
+		"foo",
+		"foob",
+		"fooba",
+		"foobar",
+		"Testing123",
+		"Testing12",
+		"Testing1",
+		"Testing",
+		"The Quick Brown Fox Jumped Over The Lazy Dog",
+		{
+			0x82, 0xa0, 0x9c, 0x66, 0x70, 0x64, 0x60, 0xae, 0x84,
+			0x6e, 0x8e, 0xa4, 0x40, 0x62, 0xae, 0x60, 0xaa, 0xa0,
+			0xa6, 0x40, 0xea, 0xae, 0x92, 0x88, 0x8a, 0x62, 0x40,
+			0xe1, 0x03, 0xf0, 0x21, 0x34, 0x31, 0x30, 0x38, 0x2e,
+			0x38, 0x31, 0x4e, 0x31, 0x31, 0x30, 0x34, 0x33, 0x32,
+			0x2e, 0x31, 0x31, 0x57, 0x23, 0x50, 0x48, 0x47, 0x37,
+			0x32, 0x32, 0x30, 0x32, 0x2f, 0x57, 0x31, 0x20, 0x46,
+			0x69, 0x6c, 0x6c, 0x2d, 0x49, 0x6e, 0x20, 0x42, 0x75,
+			0x72, 0x6e, 0x73, 0x20, 0x57, 0x42, 0x37, 0x47, 0x52,
+			0x0d, 0x0f, 0xaa
+		},
+		{
+			0x82, 0xa0, 0x62, 0xae, 0xae, 0xb0, 0xe0, 0x96, 0x86,
+			0x60, 0x88, 0x40, 0x40, 0x6c, 0x96, 0x86, 0x60, 0x88,
+			0x40, 0x40, 0xe0, 0xae, 0x60, 0xaa, 0xa0, 0xa6, 0x40,
+			0xea, 0xae, 0x92, 0x88, 0x8a, 0x64, 0x40, 0xe1, 0x03,
+			0xf0, 0x40, 0x30, 0x37, 0x30, 0x35, 0x35, 0x30, 0x7a,
+			0x33, 0x39, 0x31, 0x38, 0x2e, 0x31, 0x33, 0x4e, 0x2f,
+			0x31, 0x30, 0x34, 0x34, 0x31, 0x2e, 0x33, 0x32, 0x57,
+			0x5f, 0x31, 0x34, 0x39, 0x2f, 0x30, 0x30, 0x32, 0x67,
+			0x30, 0x30, 0x35, 0x74, 0x30, 0x34, 0x35, 0x50, 0x30,
+			0x30, 0x30, 0x72, 0x30, 0x30, 0x30, 0x68, 0x32, 0x37,
+			0x65, 0x31, 0x77, 0x0d, 0xc5, 0xc0
+
+		}
+	};
+const char base64_encode_expected[][255] =
+	{
+		"",
+		"Zg==",
+		"Zm8=",
+		"Zm9v",
+		"Zm9vYg==",
+		"Zm9vYmE=",
+		"Zm9vYmFy",
+		"VGVzdGluZzEyMw==",
+		"VGVzdGluZzEy",
+		"VGVzdGluZzE=",
+		"VGVzdGluZw==",
+		"VGhlIFF1aWNrIEJyb3duIEZveCBKdW1wZWQgT3ZlciBUaGUgTGF6eSBEb2c=",
+		"gqCcZnBkYK6Ebo6kQGKuYKqgpkDqrpKIimJA4QPwITQxMDguODFOMTEwNDMyLjExVyNQSEc3MjIwMi9XMSBGaWxsLUluIEJ1cm5zIFdCN0dSDQ+q",
+		"gqBirq6w4JaGYIhAQGyWhmCIQEDgrmCqoKZA6q6SiIpkQOED8EAwNzA1NTB6MzkxOC4xM04vMTA0NDEuMzJXXzE0OS8wMDJnMDA1dDA0NVAwMDByMDAwaDI3ZTF3DcXA"
+	};
+
+	char input_buffer[1000], output_buffer[1000];
+
+void test_base64_encode(){
+
+	int i;
+	for(i = 0; i < 14; i++){
+
+		memcpy(input_buffer, base64_encode_tests[i], strlen(base64_encode_tests[i]) + 1);
+
+		uint16_t len = base64_encode(input_buffer, output_buffer, strlen(base64_encode_tests[i]));
+		uint8_t res = memcmp(output_buffer, base64_encode_expected[i], len);
+		printf("Test: %d\n", res);
+		printf("%d %d %d\n", len, strlen(output_buffer), strlen(base64_encode_expected[i]));
+		printf("%s\n", output_buffer);
+		printf("%s\n", base64_encode_expected[i]);
+
+	}
+
+}
 
 void print_data(const char *buffer, uint16_t len){
 
@@ -43,6 +122,8 @@
 
 void main(void){
 
+	test_base64_encode();
+
 	char buffer[1000];
 
 	memcpy(buffer, test1, strlen(test1) + 1);