Xbee
Dependents: HEPTA HEPTA_assembly template HEPTA_GS
Fork of HeptaXbee by
HeptaXbee.cpp@5:aa4d53e86ab6, 2017-09-02 (annotated)
- Committer:
- umeume
- Date:
- Sat Sep 02 22:00:48 2017 +0000
- Revision:
- 5:aa4d53e86ab6
- Parent:
- 4:ede5c519e238
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hepta2ume | 0:1e02be589d1f | 1 | #include "HeptaXbee.h" |
hepta2ume | 0:1e02be589d1f | 2 | #include "mbed.h" |
hepta2ume | 0:1e02be589d1f | 3 | #include <stdarg.h> |
hepta2ume | 0:1e02be589d1f | 4 | |
hepta2ume | 0:1e02be589d1f | 5 | HeptaXbee::HeptaXbee(PinName tx, PinName rx) : xbee(tx,rx) |
hepta2ume | 0:1e02be589d1f | 6 | { |
hepta2ume | 0:1e02be589d1f | 7 | rcmd = 0; |
hepta2ume | 0:1e02be589d1f | 8 | cmdflag = 0; |
umeume | 4:ede5c519e238 | 9 | //xbee.baud(115200); |
hepta2ume | 0:1e02be589d1f | 10 | } |
hepta2ume | 0:1e02be589d1f | 11 | |
umeume | 4:ede5c519e238 | 12 | void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag) |
umeume | 4:ede5c519e238 | 13 | { |
hepta2ume | 0:1e02be589d1f | 14 | xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq); |
hepta2ume | 0:1e02be589d1f | 15 | //xbee.printf("ssXbeedata= %d,%d",HeptaXbee::rcmd,HeptaXbee::cmdflag); |
hepta2ume | 0:1e02be589d1f | 16 | *xrcmd = HeptaXbee::rcmd; |
hepta2ume | 0:1e02be589d1f | 17 | *xcmdflag = HeptaXbee::cmdflag; |
hepta2ume | 0:1e02be589d1f | 18 | } |
hepta2ume | 0:1e02be589d1f | 19 | |
umeume | 4:ede5c519e238 | 20 | void HeptaXbee::initialize() |
umeume | 4:ede5c519e238 | 21 | { |
hepta2ume | 0:1e02be589d1f | 22 | HeptaXbee::rcmd = 0; |
hepta2ume | 0:1e02be589d1f | 23 | HeptaXbee::cmdflag = 0; |
hepta2ume | 0:1e02be589d1f | 24 | } |
hepta2ume | 0:1e02be589d1f | 25 | |
umeume | 4:ede5c519e238 | 26 | void HeptaXbee::commandget() |
umeume | 4:ede5c519e238 | 27 | { |
hepta2ume | 0:1e02be589d1f | 28 | HeptaXbee::rcmd=xbee.getc(); |
hepta2ume | 0:1e02be589d1f | 29 | HeptaXbee::cmdflag = 1; |
hepta2ume | 0:1e02be589d1f | 30 | //xbee.printf("Xbeedata= %d,%d",rcmd,cmdflag); |
hepta2ume | 0:1e02be589d1f | 31 | } |
hepta2ume | 0:1e02be589d1f | 32 | |
hepta2ume | 0:1e02be589d1f | 33 | void HeptaXbee::xbee_transmit(char* output_data,size_t output_n, |
umeume | 4:ede5c519e238 | 34 | char data1[],char data2[],char data3[],char data4[],char data5[],char data6[],char data7[],char data8[],char data9[],char data10[],char data11[],char data12[],char data13[],char data14[], |
umeume | 4:ede5c519e238 | 35 | int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int n10,int n11,int n12,int n13,int n14,int data_num) |
hepta2ume | 0:1e02be589d1f | 36 | { |
umeume | 3:c3e667ee70f1 | 37 | int N=0,i=0,ii; |
umeume | 4:ede5c519e238 | 38 | if(data_num>=1) { |
umeume | 4:ede5c519e238 | 39 | for(i = 0; i <= n1-1; i++) { |
umeume | 4:ede5c519e238 | 40 | output_data[N+i] = data1[i]; |
hepta2ume | 0:1e02be589d1f | 41 | } |
hepta2ume | 0:1e02be589d1f | 42 | N=i; |
hepta2ume | 0:1e02be589d1f | 43 | } |
umeume | 4:ede5c519e238 | 44 | |
umeume | 4:ede5c519e238 | 45 | if(data_num>=2) { |
umeume | 4:ede5c519e238 | 46 | for(i = 0; i <= n2-1; i++) { |
umeume | 4:ede5c519e238 | 47 | output_data[N+i] = data2[i]; |
hepta2ume | 0:1e02be589d1f | 48 | } |
hepta2ume | 0:1e02be589d1f | 49 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 50 | } |
umeume | 4:ede5c519e238 | 51 | if(data_num>=3) { |
umeume | 4:ede5c519e238 | 52 | for(i = 0; i <= n3-1; i++) { |
umeume | 4:ede5c519e238 | 53 | output_data[N+i] = data3[i]; |
umeume | 4:ede5c519e238 | 54 | } |
umeume | 4:ede5c519e238 | 55 | N=N+i; |
umeume | 4:ede5c519e238 | 56 | } |
umeume | 4:ede5c519e238 | 57 | if(data_num>=4) { |
umeume | 4:ede5c519e238 | 58 | for(i = 0; i <= n4-1; i++) { |
umeume | 4:ede5c519e238 | 59 | output_data[N+i] = data4[i]; |
umeume | 4:ede5c519e238 | 60 | } |
umeume | 4:ede5c519e238 | 61 | N=N+i; |
umeume | 4:ede5c519e238 | 62 | } |
umeume | 4:ede5c519e238 | 63 | if(data_num>=5) { |
umeume | 4:ede5c519e238 | 64 | for(i = 0; i <= n5-1; i++) { |
umeume | 4:ede5c519e238 | 65 | output_data[N+i] = data5[i]; |
hepta2ume | 0:1e02be589d1f | 66 | } |
hepta2ume | 0:1e02be589d1f | 67 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 68 | } |
umeume | 4:ede5c519e238 | 69 | if(data_num>=6) { |
umeume | 4:ede5c519e238 | 70 | for(i = 0; i <= n6-1; i++) { |
umeume | 4:ede5c519e238 | 71 | output_data[N+i] = data6[i]; |
hepta2ume | 0:1e02be589d1f | 72 | } |
hepta2ume | 0:1e02be589d1f | 73 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 74 | } |
umeume | 4:ede5c519e238 | 75 | if(data_num>=7) { |
umeume | 4:ede5c519e238 | 76 | for(i = 0; i <= n7-1; i++) { |
umeume | 4:ede5c519e238 | 77 | output_data[N+i] = data7[i]; |
umeume | 4:ede5c519e238 | 78 | } |
umeume | 4:ede5c519e238 | 79 | N=N+i; |
umeume | 4:ede5c519e238 | 80 | } |
umeume | 4:ede5c519e238 | 81 | if(data_num>=8) { |
umeume | 4:ede5c519e238 | 82 | for(i = 0; i <= n8-1; i++) { |
umeume | 4:ede5c519e238 | 83 | output_data[N+i] = data8[i]; |
hepta2ume | 0:1e02be589d1f | 84 | } |
hepta2ume | 0:1e02be589d1f | 85 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 86 | } |
umeume | 4:ede5c519e238 | 87 | if(data_num>=9) { |
umeume | 4:ede5c519e238 | 88 | for(i = 0; i <= n9-1; i++) { |
umeume | 4:ede5c519e238 | 89 | output_data[N+i] = data9[i]; |
umeume | 4:ede5c519e238 | 90 | } |
umeume | 4:ede5c519e238 | 91 | N=N+i; |
umeume | 4:ede5c519e238 | 92 | } |
umeume | 4:ede5c519e238 | 93 | if(data_num>=10) { |
umeume | 4:ede5c519e238 | 94 | for(i = 0; i <= n10-1; i++) { |
umeume | 4:ede5c519e238 | 95 | output_data[N+i] = data10[i]; |
hepta2ume | 0:1e02be589d1f | 96 | } |
hepta2ume | 0:1e02be589d1f | 97 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 98 | } |
umeume | 4:ede5c519e238 | 99 | if(data_num>=11) { |
umeume | 4:ede5c519e238 | 100 | for(i = 0; i <= n11-1; i++) { |
umeume | 4:ede5c519e238 | 101 | output_data[N+i] = data11[i]; |
hepta2ume | 0:1e02be589d1f | 102 | } |
hepta2ume | 0:1e02be589d1f | 103 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 104 | } |
umeume | 4:ede5c519e238 | 105 | if(data_num>=12) { |
umeume | 4:ede5c519e238 | 106 | for(i = 0; i <= n12-1; i++) { |
umeume | 4:ede5c519e238 | 107 | output_data[N+i] = data12[i]; |
umeume | 4:ede5c519e238 | 108 | } |
umeume | 4:ede5c519e238 | 109 | N=N+i; |
umeume | 4:ede5c519e238 | 110 | } |
umeume | 4:ede5c519e238 | 111 | if(data_num>=13) { |
umeume | 4:ede5c519e238 | 112 | for(i = 0; i <= n13-1; i++) { |
umeume | 4:ede5c519e238 | 113 | output_data[N+i] = data13[i]; |
hepta2ume | 0:1e02be589d1f | 114 | } |
hepta2ume | 0:1e02be589d1f | 115 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 116 | } |
umeume | 4:ede5c519e238 | 117 | if(data_num>=14) { |
umeume | 4:ede5c519e238 | 118 | for(i = 0; i <= n14-1; i++) { |
umeume | 4:ede5c519e238 | 119 | output_data[N+i] = data14[i]; |
hepta2ume | 0:1e02be589d1f | 120 | } |
umeume | 4:ede5c519e238 | 121 | } |
umeume | 4:ede5c519e238 | 122 | for(ii=0; ii<output_n; ii++) { |
umeume | 4:ede5c519e238 | 123 | xbee.putc(output_data[ii]); |
umeume | 4:ede5c519e238 | 124 | |
hepta2ume | 1:c31e4a5db17c | 125 | } |
umeume | 4:ede5c519e238 | 126 | xbee.printf("\n"); |
umeume | 4:ede5c519e238 | 127 | } |
umeume | 4:ede5c519e238 | 128 | void HeptaXbee::puts( char *s ) |
umeume | 4:ede5c519e238 | 129 | { |
umeume | 4:ede5c519e238 | 130 | while ( char c = *s++ ) |
umeume | 4:ede5c519e238 | 131 | xbee.putc( c ); |
umeume | 4:ede5c519e238 | 132 | } |
umeume | 4:ede5c519e238 | 133 | void HeptaXbee::printf( char *format, ... ) |
umeume | 4:ede5c519e238 | 134 | { |
umeume | 4:ede5c519e238 | 135 | char s[ 100 ]; |
umeume | 4:ede5c519e238 | 136 | va_list args; |
umeume | 4:ede5c519e238 | 137 | |
umeume | 4:ede5c519e238 | 138 | va_start( args, format ); |
umeume | 4:ede5c519e238 | 139 | vsnprintf( s, 100, format, args ); |
umeume | 4:ede5c519e238 | 140 | va_end( args ); |
umeume | 4:ede5c519e238 | 141 | |
umeume | 4:ede5c519e238 | 142 | xbee.puts( s ); |
umeume | 4:ede5c519e238 | 143 | } |
umeume | 4:ede5c519e238 | 144 | char HeptaXbee::getc() |
umeume | 4:ede5c519e238 | 145 | { |
umeume | 4:ede5c519e238 | 146 | char character; |
umeume | 4:ede5c519e238 | 147 | character = xbee.getc(); |
umeume | 4:ede5c519e238 | 148 | return character; |
umeume | 4:ede5c519e238 | 149 | } |
umeume | 4:ede5c519e238 | 150 | |
umeume | 4:ede5c519e238 | 151 | char HeptaXbee::putc(char cc) |
umeume | 4:ede5c519e238 | 152 | { |
umeume | 4:ede5c519e238 | 153 | xbee.putc(cc); |
umeume | 4:ede5c519e238 | 154 | } |
umeume | 4:ede5c519e238 | 155 | /* |
umeume | 4:ede5c519e238 | 156 | void HeptaXbee::xbee_transmit_SD(char* output_data,size_t output_n, |
umeume | 4:ede5c519e238 | 157 | char data1[],char data2[],char data3[],char data4[],char data5[],char data6[],char data7[],char data8[],char data9[],char data10[],char data11[],char data12[],char data13[],char data14[], |
umeume | 4:ede5c519e238 | 158 | int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int n10,int n11,int n12,int n13,int n14,int data_num) |
umeume | 4:ede5c519e238 | 159 | { |
umeume | 4:ede5c519e238 | 160 | int N=0,i=0,ii; |
umeume | 4:ede5c519e238 | 161 | if(data_num>=1) { |
umeume | 4:ede5c519e238 | 162 | for(i = 0; i <= n1-1; i++) { |
umeume | 4:ede5c519e238 | 163 | output_data[N+i] = data1[i]; |
umeume | 4:ede5c519e238 | 164 | } |
umeume | 4:ede5c519e238 | 165 | N=i; |
umeume | 4:ede5c519e238 | 166 | } |
umeume | 4:ede5c519e238 | 167 | |
umeume | 4:ede5c519e238 | 168 | if(data_num>=2) { |
umeume | 4:ede5c519e238 | 169 | for(i = 0; i <= n2-1; i++) { |
umeume | 4:ede5c519e238 | 170 | output_data[N+i] = data2[i]; |
hepta2ume | 1:c31e4a5db17c | 171 | } |
hepta2ume | 1:c31e4a5db17c | 172 | N=N+i; |
hepta2ume | 1:c31e4a5db17c | 173 | } |
umeume | 4:ede5c519e238 | 174 | if(data_num>=3) { |
umeume | 4:ede5c519e238 | 175 | for(i = 0; i <= n3-1; i++) { |
umeume | 4:ede5c519e238 | 176 | output_data[N+i] = data3[i]; |
hepta2ume | 1:c31e4a5db17c | 177 | } |
hepta2ume | 2:031c35ada7e6 | 178 | N=N+i; |
hepta2ume | 2:031c35ada7e6 | 179 | } |
umeume | 4:ede5c519e238 | 180 | if(data_num>=4) { |
umeume | 4:ede5c519e238 | 181 | for(i = 0; i <= n4-1; i++) { |
umeume | 4:ede5c519e238 | 182 | output_data[N+i] = data4[i]; |
umeume | 4:ede5c519e238 | 183 | } |
umeume | 4:ede5c519e238 | 184 | N=N+i; |
umeume | 4:ede5c519e238 | 185 | } |
umeume | 4:ede5c519e238 | 186 | if(data_num>=5) { |
umeume | 4:ede5c519e238 | 187 | for(i = 0; i <= n5-1; i++) { |
umeume | 4:ede5c519e238 | 188 | output_data[N+i] = data5[i]; |
umeume | 4:ede5c519e238 | 189 | } |
umeume | 4:ede5c519e238 | 190 | N=N+i; |
umeume | 4:ede5c519e238 | 191 | } |
umeume | 4:ede5c519e238 | 192 | if(data_num>=6) { |
umeume | 4:ede5c519e238 | 193 | for(i = 0; i <= n6-1; i++) { |
umeume | 4:ede5c519e238 | 194 | output_data[N+i] = data6[i]; |
umeume | 4:ede5c519e238 | 195 | } |
umeume | 4:ede5c519e238 | 196 | N=N+i; |
umeume | 4:ede5c519e238 | 197 | } |
umeume | 4:ede5c519e238 | 198 | if(data_num>=7) { |
umeume | 4:ede5c519e238 | 199 | for(i = 0; i <= n7-1; i++) { |
umeume | 4:ede5c519e238 | 200 | output_data[N+i] = data7[i]; |
umeume | 4:ede5c519e238 | 201 | } |
umeume | 4:ede5c519e238 | 202 | N=N+i; |
umeume | 4:ede5c519e238 | 203 | } |
umeume | 4:ede5c519e238 | 204 | if(data_num>=8) { |
umeume | 4:ede5c519e238 | 205 | for(i = 0; i <= n8-1; i++) { |
umeume | 4:ede5c519e238 | 206 | output_data[N+i] = data8[i]; |
umeume | 4:ede5c519e238 | 207 | } |
umeume | 4:ede5c519e238 | 208 | N=N+i; |
umeume | 4:ede5c519e238 | 209 | } |
umeume | 4:ede5c519e238 | 210 | if(data_num>=9) { |
umeume | 4:ede5c519e238 | 211 | for(i = 0; i <= n9-1; i++) { |
umeume | 4:ede5c519e238 | 212 | output_data[N+i] = data9[i]; |
umeume | 4:ede5c519e238 | 213 | } |
umeume | 4:ede5c519e238 | 214 | N=N+i; |
umeume | 4:ede5c519e238 | 215 | } |
umeume | 4:ede5c519e238 | 216 | if(data_num>=10) { |
umeume | 4:ede5c519e238 | 217 | for(i = 0; i <= n10-1; i++) { |
umeume | 4:ede5c519e238 | 218 | output_data[N+i] = data10[i]; |
umeume | 4:ede5c519e238 | 219 | } |
umeume | 4:ede5c519e238 | 220 | N=N+i; |
umeume | 4:ede5c519e238 | 221 | } |
umeume | 4:ede5c519e238 | 222 | if(data_num>=11) { |
umeume | 4:ede5c519e238 | 223 | for(i = 0; i <= n11-1; i++) { |
umeume | 4:ede5c519e238 | 224 | output_data[N+i] = data11[i]; |
umeume | 4:ede5c519e238 | 225 | } |
umeume | 4:ede5c519e238 | 226 | N=N+i; |
umeume | 4:ede5c519e238 | 227 | } |
umeume | 4:ede5c519e238 | 228 | if(data_num>=12) { |
umeume | 4:ede5c519e238 | 229 | for(i = 0; i <= n12-1; i++) { |
umeume | 4:ede5c519e238 | 230 | output_data[N+i] = data12[i]; |
umeume | 4:ede5c519e238 | 231 | } |
umeume | 4:ede5c519e238 | 232 | N=N+i; |
umeume | 4:ede5c519e238 | 233 | } |
umeume | 4:ede5c519e238 | 234 | if(data_num>=13) { |
umeume | 4:ede5c519e238 | 235 | for(i = 0; i <= n13-1; i++) { |
umeume | 4:ede5c519e238 | 236 | output_data[N+i] = data13[i]; |
umeume | 4:ede5c519e238 | 237 | } |
umeume | 4:ede5c519e238 | 238 | N=N+i; |
umeume | 4:ede5c519e238 | 239 | } |
umeume | 4:ede5c519e238 | 240 | if(data_num>=14) { |
umeume | 4:ede5c519e238 | 241 | for(i = 0; i <= n14-1; i++) { |
umeume | 4:ede5c519e238 | 242 | output_data[N+i] = data14[i]; |
hepta2ume | 2:031c35ada7e6 | 243 | } |
hepta2ume | 0:1e02be589d1f | 244 | } |
umeume | 4:ede5c519e238 | 245 | for(ii=0; ii<output_n; ii++) { |
umeume | 4:ede5c519e238 | 246 | xbee.putc(output_data[ii]); |
hepta2ume | 0:1e02be589d1f | 247 | } |
umeume | 4:ede5c519e238 | 248 | xbee.printf("\n"); |
hepta2ume | 0:1e02be589d1f | 249 | } |
umeume | 4:ede5c519e238 | 250 | */ |