UART wo rakuraku hedda- dasite kureru benrina yatu
Diff: COBS.h
- Revision:
- 0:93df1cb29b75
diff -r 000000000000 -r 93df1cb29b75 COBS.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/COBS.h Wed Jun 29 06:32:25 2022 +0000 @@ -0,0 +1,58 @@ +#ifndef INCLDUED_COBS_h_ +#define INCLDUED_COBS_h_ +#include "mbed.h" +/*-------------- クラス定義 --------------*/ +class COBS +{ +private: +public: + /* 送受信するデータサイズ(byte)を指定 + * 送信側と受信側で合わせてね */ + uint8_t dataSizeEncode; + uint8_t dataSizeDecode; + /* 送受信するデータサイズ(byte)を指定 */ + void Encode(uint8_t *array); + void Decode(uint8_t *array); +}; +#endif + +/***************************/ +/* E n c o d e S a m p l e */ +/***************************/ +/* +#include "COBS.h" +COBS cobs; +cobs.dataSizeEncode = 5; +int main(){ + //配列は送信データサイズ+2確保してください + uint8_t data[cobs.dataSizeEncode + 2] = {0x23,0x10,0x33,0x00,0x21}; + cobs.Encode(data); + for(int i=0; i<cobs.dataSizeEncode+2; i++) + putc(data[i]); +} +*/ + +/***************************/ +/* D e c o d e S a m p l e */ +/***************************/ +/* +#include "COBS.h" +COBS cobs; +cobs.dataSizeDecode = 5; +//配列は受信データサイズ+2確保してください +uint8_t data[cobs.dataSizeEncode + 2] = {0}; +uint8_t header = 0; //配列の代入位置 + +int main(){ + uint8_t readData = getc(); + if(readData == 0){ + //データ数あってるならデコード + if(header == cobs.dataSizeEncode + 2) + cobs.Encode(data); + header = 0; + } + else + data[header] = readData; + header++; +} +*/ \ No newline at end of file