gyo

Committer:
gotto0
Date:
Mon May 08 07:50:22 2017 +0000
Revision:
5:a4a994824c96
Parent:
3:16a15d26ebe8
Child:
6:da71294502ee
v1.0;

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 3:16a15d26ebe8 9 readable = 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 5:a4a994824c96 69 char SBDBT::maru()
gotto0 5:a4a994824c96 70 {
gotto0 5:a4a994824c96 71 if(data[2] & 64)
gotto0 5:a4a994824c96 72 return 1;
gotto0 5:a4a994824c96 73 return 0;
gotto0 5:a4a994824c96 74 }
gotto0 5:a4a994824c96 75
gotto0 5:a4a994824c96 76 char SBDBT::batu()
gotto0 5:a4a994824c96 77 {
gotto0 5:a4a994824c96 78 if(data[2] & 32)
gotto0 5:a4a994824c96 79 return 1;
gotto0 5:a4a994824c96 80 return 0;
gotto0 5:a4a994824c96 81 }
gotto0 5:a4a994824c96 82
gotto0 5:a4a994824c96 83 char SBDBT::sikaku()
gotto0 5:a4a994824c96 84 {
gotto0 5:a4a994824c96 85 if(data[1] & 1)
gotto0 5:a4a994824c96 86 return 1;
gotto0 5:a4a994824c96 87 return 0;
gotto0 5:a4a994824c96 88 }
gotto0 5:a4a994824c96 89
gotto0 5:a4a994824c96 90 char SBDBT::sankaku()
gotto0 5:a4a994824c96 91 {
gotto0 5:a4a994824c96 92 if(data[2] & 16)
gotto0 5:a4a994824c96 93 return 1;
gotto0 5:a4a994824c96 94 return 0;
gotto0 5:a4a994824c96 95 }
gotto0 5:a4a994824c96 96
gotto0 5:a4a994824c96 97 char SBDBT::L1()
gotto0 5:a4a994824c96 98 {
gotto0 5:a4a994824c96 99 if(data[1] & 2)
gotto0 5:a4a994824c96 100 return 1;
gotto0 5:a4a994824c96 101 return 0;
gotto0 5:a4a994824c96 102 }
gotto0 5:a4a994824c96 103
gotto0 5:a4a994824c96 104 char SBDBT::L2()
gotto0 5:a4a994824c96 105 {
gotto0 5:a4a994824c96 106 if(data[1] & 4)
gotto0 5:a4a994824c96 107 return 1;
gotto0 5:a4a994824c96 108 return 0;
gotto0 5:a4a994824c96 109 }
gotto0 5:a4a994824c96 110
gotto0 5:a4a994824c96 111 char SBDBT::R1()
gotto0 5:a4a994824c96 112 {
gotto0 5:a4a994824c96 113 if(data[1] & 8)
gotto0 5:a4a994824c96 114 return 1;
gotto0 5:a4a994824c96 115 return 0;
gotto0 5:a4a994824c96 116 }
gotto0 5:a4a994824c96 117
gotto0 5:a4a994824c96 118 char SBDBT::R2()
gotto0 5:a4a994824c96 119 {
gotto0 5:a4a994824c96 120 if(data[1] & 16)
gotto0 5:a4a994824c96 121 return 1;
gotto0 5:a4a994824c96 122 return 0;
gotto0 5:a4a994824c96 123 }
gotto0 5:a4a994824c96 124
gotto0 5:a4a994824c96 125 char SBDBT::ue()
gotto0 5:a4a994824c96 126 {
gotto0 5:a4a994824c96 127 if(data[2] & 1)
gotto0 5:a4a994824c96 128 return 1;
gotto0 5:a4a994824c96 129 return 0;
gotto0 5:a4a994824c96 130 }
gotto0 5:a4a994824c96 131
gotto0 5:a4a994824c96 132 char SBDBT::sita()
gotto0 5:a4a994824c96 133 {
gotto0 5:a4a994824c96 134 if(data[2] & 2)
gotto0 5:a4a994824c96 135 return 1;
gotto0 5:a4a994824c96 136 return 0;
gotto0 5:a4a994824c96 137 }
gotto0 5:a4a994824c96 138
gotto0 5:a4a994824c96 139 char SBDBT::migi()
gotto0 5:a4a994824c96 140 {
gotto0 5:a4a994824c96 141 if(data[2] & 4)
gotto0 5:a4a994824c96 142 return 1;
gotto0 5:a4a994824c96 143 return 0;
gotto0 5:a4a994824c96 144 }
gotto0 5:a4a994824c96 145
gotto0 5:a4a994824c96 146 char SBDBT::hidari()
gotto0 5:a4a994824c96 147 {
gotto0 5:a4a994824c96 148 if(data[2] & 8)
gotto0 5:a4a994824c96 149 return 1;
gotto0 5:a4a994824c96 150 return 0;
gotto0 5:a4a994824c96 151 }
gotto0 5:a4a994824c96 152
gotto0 5:a4a994824c96 153 char SBDBT::rs_x()
gotto0 5:a4a994824c96 154 {
gotto0 5:a4a994824c96 155 return data[5];
gotto0 5:a4a994824c96 156 }
gotto0 5:a4a994824c96 157
gotto0 5:a4a994824c96 158 char SBDBT::rs_y()
gotto0 5:a4a994824c96 159 {
gotto0 5:a4a994824c96 160 return data[6];
gotto0 5:a4a994824c96 161 }
gotto0 5:a4a994824c96 162
gotto0 5:a4a994824c96 163 char SBDBT::ls_x()
gotto0 5:a4a994824c96 164 {
gotto0 5:a4a994824c96 165 return data[3];
gotto0 5:a4a994824c96 166 }
gotto0 5:a4a994824c96 167
gotto0 5:a4a994824c96 168 char SBDBT::ls_y()
gotto0 5:a4a994824c96 169 {
gotto0 5:a4a994824c96 170 return data[4];
gotto0 5:a4a994824c96 171 }
gotto0 5:a4a994824c96 172
gotto0 0:afe58893bfe7 173 SBDBT::~SBDBT()
gotto0 0:afe58893bfe7 174 {
gotto0 0:afe58893bfe7 175 delete sr;
gotto0 0:afe58893bfe7 176 }
gotto0 0:afe58893bfe7 177 }//namespace