UART wo rakuraku hedda- dasite kureru benrina yatu

Revision:
0:93df1cb29b75
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/COBS.cpp	Wed Jun 29 06:32:25 2022 +0000
@@ -0,0 +1,33 @@
+#include "COBS.h"
+
+void COBS::Encode(uint8_t *array)
+{
+    int cnt = 0;
+    array[dataSizeEncode + 1] = 0;
+    //[i]を[i+1]に移動しながらエンコードする
+    for (int i = dataSizeEncode; i >= 0; i--) {
+        if (array[i] == 0) {
+            array[i + 1] = cnt;
+            cnt = 0;
+        } 
+        else
+            array[i + 1]= array[i];
+        cnt++;
+    }
+    array[0] = cnt;
+}
+
+void COBS::Decode(uint8_t *array)
+{
+    int cnt = array[0];
+    //[i]を[i-1]に移動しながらデコードする
+    for (int i = 1; i < dataSizeDecode + 1; i++) {
+        cnt--;
+        if (cnt == 0) {
+            array[i - 1] = 0;
+            cnt = array[i];
+        } 
+        else
+            array[i - 1] = array[i];
+    }
+}
\ No newline at end of file