gyo

Committer:
gotto0
Date:
Sat May 06 03:02:04 2017 +0000
Revision:
2:1472e7c5317d
Parent:
1:8810976be033
Child:
3:16a15d26ebe8
fix; (readable)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gotto0 0:afe58893bfe7 1 #include "SBDBT.h"
gotto0 0:afe58893bfe7 2
gotto0 0:afe58893bfe7 3 namespace raven
gotto0 0:afe58893bfe7 4 {
gotto0 0:afe58893bfe7 5
gotto0 0:afe58893bfe7 6 SBDBT::SBDBT(PinName p1, PinName p2)
gotto0 0:afe58893bfe7 7 {
gotto0 0:afe58893bfe7 8 i = 0;
gotto0 2:1472e7c5317d 9 readstat = 0;
gotto0 1:8810976be033 10 length = 8;
gotto0 1:8810976be033 11 value = 128;
gotto0 1:8810976be033 12 position = 0;
gotto0 2:1472e7c5317d 13 tmp = new char [length];
gotto0 1:8810976be033 14 data = new char [length];
gotto0 0:afe58893bfe7 15 sr = new Serial(p1,p2);
gotto0 0:afe58893bfe7 16 sr -> baud(2400);
gotto0 1:8810976be033 17 sr -> attach(this,&SBDBT::getf,Serial::RxIrq);
gotto0 0:afe58893bfe7 18 }
gotto0 0:afe58893bfe7 19
gotto0 1:8810976be033 20 SBDBT::SBDBT(PinName p1, PinName p2, int baud)
gotto0 1:8810976be033 21 {
gotto0 1:8810976be033 22 i = 0;
gotto0 2:1472e7c5317d 23 readable = 0;
gotto0 1:8810976be033 24 length = 8;
gotto0 1:8810976be033 25 value = 128;
gotto0 1:8810976be033 26 position = 0;
gotto0 2:1472e7c5317d 27 tmp = new char [length];
gotto0 1:8810976be033 28 data = new char [length];
gotto0 1:8810976be033 29 sr = new Serial(p1,p2);
gotto0 1:8810976be033 30 sr -> baud(baud);
gotto0 1:8810976be033 31 sr -> attach(this,&SBDBT::getf,Serial::RxIrq);
gotto0 1:8810976be033 32 }
gotto0 1:8810976be033 33
gotto0 1:8810976be033 34 void SBDBT::getf()
gotto0 0:afe58893bfe7 35 {
gotto0 2:1472e7c5317d 36 tmp[i] = sr -> getc();
gotto0 2:1472e7c5317d 37 if(tmp[i] == value) //受信したデータが訂正用定数であり
gotto0 0:afe58893bfe7 38 {
gotto0 1:8810976be033 39 if(i != position) //訂正用定数を受信すべき位置でないとき
gotto0 1:8810976be033 40 {
gotto0 2:1472e7c5317d 41 tmp[position] = value; //正しい位置に訂正用定数を代入
gotto0 1:8810976be033 42 i = position + 1; //受信先も正しい位置へもどす
gotto0 1:8810976be033 43 }
gotto0 1:8810976be033 44 else //訂正用定数を受信すべき位置であるとき
gotto0 1:8810976be033 45 i++; //次の位置で受信する
gotto0 1:8810976be033 46 }
gotto0 1:8810976be033 47 else //受信したデータが訂正用定数でなく
gotto0 1:8810976be033 48 {
gotto0 1:8810976be033 49 if(i == position){} //訂正用定数を受信すべき位置であるとき
gotto0 1:8810976be033 50 //再度同じ位置で受信する
gotto0 1:8810976be033 51 else //訂正用定数を受信すべき場所でないとき
gotto0 1:8810976be033 52 i++; //次の位置で受信する
gotto0 1:8810976be033 53 }
gotto0 1:8810976be033 54 if(i>=length) //位置がデータの長さを超えたら
gotto0 1:8810976be033 55 {
gotto0 2:1472e7c5317d 56 data[0] = tmp[0];
gotto0 2:1472e7c5317d 57 data[1] = tmp[1];
gotto0 2:1472e7c5317d 58 data[2] = tmp[2];
gotto0 2:1472e7c5317d 59 data[3] = tmp[3];
gotto0 2:1472e7c5317d 60 data[4] = tmp[4];
gotto0 2:1472e7c5317d 61 data[5] = tmp[5];
gotto0 2:1472e7c5317d 62 data[6] = tmp[6];
gotto0 2:1472e7c5317d 63 data[7] = tmp[7];
gotto0 2:1472e7c5317d 64 readable = 1; //全データ受信完了
gotto0 1:8810976be033 65 i=0; //位置を初期化
gotto0 0:afe58893bfe7 66 }
gotto0 0:afe58893bfe7 67 }
gotto0 0:afe58893bfe7 68
gotto0 0:afe58893bfe7 69 SBDBT::~SBDBT()
gotto0 0:afe58893bfe7 70 {
gotto0 0:afe58893bfe7 71 delete sr;
gotto0 0:afe58893bfe7 72 }
gotto0 0:afe58893bfe7 73 }//namespace