gyo

Committer:
gotto0
Date:
Tue Aug 15 04:13:58 2017 +0000
Revision:
7:30e05998769b
Parent:
6:da71294502ee
Child:
9:8538fc8f6259
update

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 6:da71294502ee 69 void SBDBT::print()
gotto0 6:da71294502ee 70 {
gotto0 6:da71294502ee 71 printf("%3d %3d %3d %3d %3d %3d %3d %3d\n",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
gotto0 6:da71294502ee 72 }
gotto0 6:da71294502ee 73
gotto0 5:a4a994824c96 74 char SBDBT::maru()
gotto0 5:a4a994824c96 75 {
gotto0 5:a4a994824c96 76 if(data[2] & 64)
gotto0 5:a4a994824c96 77 return 1;
gotto0 5:a4a994824c96 78 return 0;
gotto0 5:a4a994824c96 79 }
gotto0 5:a4a994824c96 80
gotto0 5:a4a994824c96 81 char SBDBT::batu()
gotto0 5:a4a994824c96 82 {
gotto0 5:a4a994824c96 83 if(data[2] & 32)
gotto0 5:a4a994824c96 84 return 1;
gotto0 5:a4a994824c96 85 return 0;
gotto0 5:a4a994824c96 86 }
gotto0 5:a4a994824c96 87
gotto0 5:a4a994824c96 88 char SBDBT::sikaku()
gotto0 5:a4a994824c96 89 {
gotto0 5:a4a994824c96 90 if(data[1] & 1)
gotto0 5:a4a994824c96 91 return 1;
gotto0 5:a4a994824c96 92 return 0;
gotto0 5:a4a994824c96 93 }
gotto0 5:a4a994824c96 94
gotto0 5:a4a994824c96 95 char SBDBT::sankaku()
gotto0 5:a4a994824c96 96 {
gotto0 5:a4a994824c96 97 if(data[2] & 16)
gotto0 5:a4a994824c96 98 return 1;
gotto0 5:a4a994824c96 99 return 0;
gotto0 5:a4a994824c96 100 }
gotto0 5:a4a994824c96 101
gotto0 5:a4a994824c96 102 char SBDBT::L1()
gotto0 5:a4a994824c96 103 {
gotto0 5:a4a994824c96 104 if(data[1] & 2)
gotto0 5:a4a994824c96 105 return 1;
gotto0 5:a4a994824c96 106 return 0;
gotto0 5:a4a994824c96 107 }
gotto0 5:a4a994824c96 108
gotto0 5:a4a994824c96 109 char SBDBT::L2()
gotto0 5:a4a994824c96 110 {
gotto0 5:a4a994824c96 111 if(data[1] & 4)
gotto0 5:a4a994824c96 112 return 1;
gotto0 5:a4a994824c96 113 return 0;
gotto0 5:a4a994824c96 114 }
gotto0 5:a4a994824c96 115
gotto0 5:a4a994824c96 116 char SBDBT::R1()
gotto0 5:a4a994824c96 117 {
gotto0 5:a4a994824c96 118 if(data[1] & 8)
gotto0 5:a4a994824c96 119 return 1;
gotto0 5:a4a994824c96 120 return 0;
gotto0 5:a4a994824c96 121 }
gotto0 5:a4a994824c96 122
gotto0 5:a4a994824c96 123 char SBDBT::R2()
gotto0 5:a4a994824c96 124 {
gotto0 5:a4a994824c96 125 if(data[1] & 16)
gotto0 5:a4a994824c96 126 return 1;
gotto0 5:a4a994824c96 127 return 0;
gotto0 5:a4a994824c96 128 }
gotto0 5:a4a994824c96 129
gotto0 5:a4a994824c96 130 char SBDBT::ue()
gotto0 5:a4a994824c96 131 {
gotto0 5:a4a994824c96 132 if(data[2] & 1)
gotto0 5:a4a994824c96 133 return 1;
gotto0 5:a4a994824c96 134 return 0;
gotto0 5:a4a994824c96 135 }
gotto0 5:a4a994824c96 136
gotto0 5:a4a994824c96 137 char SBDBT::sita()
gotto0 5:a4a994824c96 138 {
gotto0 5:a4a994824c96 139 if(data[2] & 2)
gotto0 5:a4a994824c96 140 return 1;
gotto0 5:a4a994824c96 141 return 0;
gotto0 5:a4a994824c96 142 }
gotto0 5:a4a994824c96 143
gotto0 5:a4a994824c96 144 char SBDBT::migi()
gotto0 5:a4a994824c96 145 {
gotto0 5:a4a994824c96 146 if(data[2] & 4)
gotto0 5:a4a994824c96 147 return 1;
gotto0 5:a4a994824c96 148 return 0;
gotto0 5:a4a994824c96 149 }
gotto0 5:a4a994824c96 150
gotto0 5:a4a994824c96 151 char SBDBT::hidari()
gotto0 5:a4a994824c96 152 {
gotto0 5:a4a994824c96 153 if(data[2] & 8)
gotto0 5:a4a994824c96 154 return 1;
gotto0 5:a4a994824c96 155 return 0;
gotto0 5:a4a994824c96 156 }
gotto0 5:a4a994824c96 157
gotto0 6:da71294502ee 158 signed char SBDBT::rs_x()
gotto0 6:da71294502ee 159 {
gotto0 7:30e05998769b 160 return data[5];
gotto0 6:da71294502ee 161 }
gotto0 6:da71294502ee 162
gotto0 6:da71294502ee 163 signed char SBDBT::rs_y()
gotto0 5:a4a994824c96 164 {
gotto0 7:30e05998769b 165 return data[6];
gotto0 6:da71294502ee 166 }
gotto0 6:da71294502ee 167
gotto0 6:da71294502ee 168 signed char SBDBT::ls_x()
gotto0 6:da71294502ee 169 {
gotto0 7:30e05998769b 170 return data[3];
gotto0 5:a4a994824c96 171 }
gotto0 5:a4a994824c96 172
gotto0 6:da71294502ee 173 signed char SBDBT::ls_y()
gotto0 5:a4a994824c96 174 {
gotto0 7:30e05998769b 175 return data[4];
gotto0 6:da71294502ee 176 }
gotto0 6:da71294502ee 177
gotto0 6:da71294502ee 178 char SBDBT::rs_x_check()
gotto0 6:da71294502ee 179 {
gotto0 6:da71294502ee 180 return data[5]==data[5] ? 0 : 1;
gotto0 5:a4a994824c96 181 }
gotto0 5:a4a994824c96 182
gotto0 6:da71294502ee 183 char SBDBT::rs_y_check()
gotto0 5:a4a994824c96 184 {
gotto0 6:da71294502ee 185 return data[6]==data[6] ? 0 : 1;
gotto0 5:a4a994824c96 186 }
gotto0 5:a4a994824c96 187
gotto0 6:da71294502ee 188 char SBDBT::ls_x_check()
gotto0 5:a4a994824c96 189 {
gotto0 6:da71294502ee 190 return data[3]==data[3] ? 0 : 1;
gotto0 6:da71294502ee 191 }
gotto0 6:da71294502ee 192
gotto0 6:da71294502ee 193 char SBDBT::ls_y_check()
gotto0 6:da71294502ee 194 {
gotto0 6:da71294502ee 195 return data[4]==data[4] ? 0 : 1;
gotto0 5:a4a994824c96 196 }
gotto0 5:a4a994824c96 197
gotto0 0:afe58893bfe7 198 SBDBT::~SBDBT()
gotto0 0:afe58893bfe7 199 {
gotto0 0:afe58893bfe7 200 delete sr;
gotto0 6:da71294502ee 201 delete tmp;
gotto0 6:da71294502ee 202 delete data;
gotto0 0:afe58893bfe7 203 }
gotto0 0:afe58893bfe7 204 }//namespace