UART wo rakuraku hedda- dasite kureru benrina yatu

Committer:
TakushimaYukimasa
Date:
Wed Jun 29 06:32:25 2022 +0000
Revision:
0:93df1cb29b75
Ver1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TakushimaYukimasa 0:93df1cb29b75 1 #include "COBS.h"
TakushimaYukimasa 0:93df1cb29b75 2
TakushimaYukimasa 0:93df1cb29b75 3 void COBS::Encode(uint8_t *array)
TakushimaYukimasa 0:93df1cb29b75 4 {
TakushimaYukimasa 0:93df1cb29b75 5 int cnt = 0;
TakushimaYukimasa 0:93df1cb29b75 6 array[dataSizeEncode + 1] = 0;
TakushimaYukimasa 0:93df1cb29b75 7 //[i]を[i+1]に移動しながらエンコードする
TakushimaYukimasa 0:93df1cb29b75 8 for (int i = dataSizeEncode; i >= 0; i--) {
TakushimaYukimasa 0:93df1cb29b75 9 if (array[i] == 0) {
TakushimaYukimasa 0:93df1cb29b75 10 array[i + 1] = cnt;
TakushimaYukimasa 0:93df1cb29b75 11 cnt = 0;
TakushimaYukimasa 0:93df1cb29b75 12 }
TakushimaYukimasa 0:93df1cb29b75 13 else
TakushimaYukimasa 0:93df1cb29b75 14 array[i + 1]= array[i];
TakushimaYukimasa 0:93df1cb29b75 15 cnt++;
TakushimaYukimasa 0:93df1cb29b75 16 }
TakushimaYukimasa 0:93df1cb29b75 17 array[0] = cnt;
TakushimaYukimasa 0:93df1cb29b75 18 }
TakushimaYukimasa 0:93df1cb29b75 19
TakushimaYukimasa 0:93df1cb29b75 20 void COBS::Decode(uint8_t *array)
TakushimaYukimasa 0:93df1cb29b75 21 {
TakushimaYukimasa 0:93df1cb29b75 22 int cnt = array[0];
TakushimaYukimasa 0:93df1cb29b75 23 //[i]を[i-1]に移動しながらデコードする
TakushimaYukimasa 0:93df1cb29b75 24 for (int i = 1; i < dataSizeDecode + 1; i++) {
TakushimaYukimasa 0:93df1cb29b75 25 cnt--;
TakushimaYukimasa 0:93df1cb29b75 26 if (cnt == 0) {
TakushimaYukimasa 0:93df1cb29b75 27 array[i - 1] = 0;
TakushimaYukimasa 0:93df1cb29b75 28 cnt = array[i];
TakushimaYukimasa 0:93df1cb29b75 29 }
TakushimaYukimasa 0:93df1cb29b75 30 else
TakushimaYukimasa 0:93df1cb29b75 31 array[i - 1] = array[i];
TakushimaYukimasa 0:93df1cb29b75 32 }
TakushimaYukimasa 0:93df1cb29b75 33 }