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 #ifndef INCLDUED_COBS_h_
TakushimaYukimasa 0:93df1cb29b75 2 #define INCLDUED_COBS_h_
TakushimaYukimasa 0:93df1cb29b75 3 #include "mbed.h"
TakushimaYukimasa 0:93df1cb29b75 4 /*-------------- クラス定義 --------------*/
TakushimaYukimasa 0:93df1cb29b75 5 class COBS
TakushimaYukimasa 0:93df1cb29b75 6 {
TakushimaYukimasa 0:93df1cb29b75 7 private:
TakushimaYukimasa 0:93df1cb29b75 8 public:
TakushimaYukimasa 0:93df1cb29b75 9 /* 送受信するデータサイズ(byte)を指定
TakushimaYukimasa 0:93df1cb29b75 10 * 送信側と受信側で合わせてね */
TakushimaYukimasa 0:93df1cb29b75 11 uint8_t dataSizeEncode;
TakushimaYukimasa 0:93df1cb29b75 12 uint8_t dataSizeDecode;
TakushimaYukimasa 0:93df1cb29b75 13 /* 送受信するデータサイズ(byte)を指定 */
TakushimaYukimasa 0:93df1cb29b75 14 void Encode(uint8_t *array);
TakushimaYukimasa 0:93df1cb29b75 15 void Decode(uint8_t *array);
TakushimaYukimasa 0:93df1cb29b75 16 };
TakushimaYukimasa 0:93df1cb29b75 17 #endif
TakushimaYukimasa 0:93df1cb29b75 18
TakushimaYukimasa 0:93df1cb29b75 19 /***************************/
TakushimaYukimasa 0:93df1cb29b75 20 /* E n c o d e S a m p l e */
TakushimaYukimasa 0:93df1cb29b75 21 /***************************/
TakushimaYukimasa 0:93df1cb29b75 22 /*
TakushimaYukimasa 0:93df1cb29b75 23 #include "COBS.h"
TakushimaYukimasa 0:93df1cb29b75 24 COBS cobs;
TakushimaYukimasa 0:93df1cb29b75 25 cobs.dataSizeEncode = 5;
TakushimaYukimasa 0:93df1cb29b75 26 int main(){
TakushimaYukimasa 0:93df1cb29b75 27 //配列は送信データサイズ+2確保してください
TakushimaYukimasa 0:93df1cb29b75 28 uint8_t data[cobs.dataSizeEncode + 2] = {0x23,0x10,0x33,0x00,0x21};
TakushimaYukimasa 0:93df1cb29b75 29 cobs.Encode(data);
TakushimaYukimasa 0:93df1cb29b75 30 for(int i=0; i<cobs.dataSizeEncode+2; i++)
TakushimaYukimasa 0:93df1cb29b75 31 putc(data[i]);
TakushimaYukimasa 0:93df1cb29b75 32 }
TakushimaYukimasa 0:93df1cb29b75 33 */
TakushimaYukimasa 0:93df1cb29b75 34
TakushimaYukimasa 0:93df1cb29b75 35 /***************************/
TakushimaYukimasa 0:93df1cb29b75 36 /* D e c o d e S a m p l e */
TakushimaYukimasa 0:93df1cb29b75 37 /***************************/
TakushimaYukimasa 0:93df1cb29b75 38 /*
TakushimaYukimasa 0:93df1cb29b75 39 #include "COBS.h"
TakushimaYukimasa 0:93df1cb29b75 40 COBS cobs;
TakushimaYukimasa 0:93df1cb29b75 41 cobs.dataSizeDecode = 5;
TakushimaYukimasa 0:93df1cb29b75 42 //配列は受信データサイズ+2確保してください
TakushimaYukimasa 0:93df1cb29b75 43 uint8_t data[cobs.dataSizeEncode + 2] = {0};
TakushimaYukimasa 0:93df1cb29b75 44 uint8_t header = 0; //配列の代入位置
TakushimaYukimasa 0:93df1cb29b75 45
TakushimaYukimasa 0:93df1cb29b75 46 int main(){
TakushimaYukimasa 0:93df1cb29b75 47 uint8_t readData = getc();
TakushimaYukimasa 0:93df1cb29b75 48 if(readData == 0){
TakushimaYukimasa 0:93df1cb29b75 49 //データ数あってるならデコード
TakushimaYukimasa 0:93df1cb29b75 50 if(header == cobs.dataSizeEncode + 2)
TakushimaYukimasa 0:93df1cb29b75 51 cobs.Encode(data);
TakushimaYukimasa 0:93df1cb29b75 52 header = 0;
TakushimaYukimasa 0:93df1cb29b75 53 }
TakushimaYukimasa 0:93df1cb29b75 54 else
TakushimaYukimasa 0:93df1cb29b75 55 data[header] = readData;
TakushimaYukimasa 0:93df1cb29b75 56 header++;
TakushimaYukimasa 0:93df1cb29b75 57 }
TakushimaYukimasa 0:93df1cb29b75 58 */