For Hepta-Sat Lite
HeptaXbee.cpp@8:8e925f198e21, 2017-09-05 (annotated)
- Committer:
- HEPTA
- Date:
- Tue Sep 05 17:15:05 2017 +0000
- Revision:
- 8:8e925f198e21
- Parent:
- 7:d07155a73b24
- Child:
- 9:96ed36bbc9dd
Hepta Xbee
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; |
hepta2ume | 0:1e02be589d1f | 9 | } |
HEPTA | 7:d07155a73b24 | 10 | void HeptaXbee::baud(int rate) |
HEPTA | 7:d07155a73b24 | 11 | { |
HEPTA | 7:d07155a73b24 | 12 | xbee.baud(rate); |
HEPTA | 7:d07155a73b24 | 13 | } |
umeume | 4:ede5c519e238 | 14 | void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag) |
umeume | 4:ede5c519e238 | 15 | { |
hepta2ume | 0:1e02be589d1f | 16 | xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq); |
hepta2ume | 0:1e02be589d1f | 17 | //xbee.printf("ssXbeedata= %d,%d",HeptaXbee::rcmd,HeptaXbee::cmdflag); |
hepta2ume | 0:1e02be589d1f | 18 | *xrcmd = HeptaXbee::rcmd; |
hepta2ume | 0:1e02be589d1f | 19 | *xcmdflag = HeptaXbee::cmdflag; |
hepta2ume | 0:1e02be589d1f | 20 | } |
hepta2ume | 0:1e02be589d1f | 21 | |
umeume | 4:ede5c519e238 | 22 | void HeptaXbee::initialize() |
umeume | 4:ede5c519e238 | 23 | { |
hepta2ume | 0:1e02be589d1f | 24 | HeptaXbee::rcmd = 0; |
hepta2ume | 0:1e02be589d1f | 25 | HeptaXbee::cmdflag = 0; |
hepta2ume | 0:1e02be589d1f | 26 | } |
hepta2ume | 0:1e02be589d1f | 27 | |
umeume | 4:ede5c519e238 | 28 | void HeptaXbee::commandget() |
umeume | 4:ede5c519e238 | 29 | { |
hepta2ume | 0:1e02be589d1f | 30 | HeptaXbee::rcmd=xbee.getc(); |
hepta2ume | 0:1e02be589d1f | 31 | HeptaXbee::cmdflag = 1; |
hepta2ume | 0:1e02be589d1f | 32 | //xbee.printf("Xbeedata= %d,%d",rcmd,cmdflag); |
hepta2ume | 0:1e02be589d1f | 33 | } |
hepta2ume | 0:1e02be589d1f | 34 | |
HEPTA | 7:d07155a73b24 | 35 | //*gyro×3 = A,B,C *Accel×3 = D,E,F *magnetic×3 = G,H,I *latitude = J *longitude = K *altitude = L *battery = M *temperature = N |
HEPTA | 7:d07155a73b24 | 36 | void HeptaXbee::xbee_transmit(char dataA[],char dataB[],char dataC[],char dataD[],char dataE[], |
HEPTA | 7:d07155a73b24 | 37 | char dataF[],char dataG[],char dataH[],char dataI[],char dataJ[], |
HEPTA | 7:d07155a73b24 | 38 | char dataK[],char dataL[],char dataM[],char dataN[]) |
hepta2ume | 0:1e02be589d1f | 39 | { |
HEPTA | 7:d07155a73b24 | 40 | char OutputData[255]; |
HEPTA | 7:d07155a73b24 | 41 | int output_num,numA,numB,numC,numD,numE,numF,numG,numH,numI,numJ,numK,numL,numM,numN; |
HEPTA | 7:d07155a73b24 | 42 | numA = sizeof(dataA) / sizeof(dataA[0]); |
HEPTA | 7:d07155a73b24 | 43 | numB = sizeof(dataB) / sizeof(dataB[0]); |
HEPTA | 7:d07155a73b24 | 44 | numC = sizeof(dataC) / sizeof(dataC[0]); |
HEPTA | 7:d07155a73b24 | 45 | numD = sizeof(dataD) / sizeof(dataD[0]); |
HEPTA | 7:d07155a73b24 | 46 | numE = sizeof(dataE) / sizeof(dataE[0]); |
HEPTA | 7:d07155a73b24 | 47 | numF = sizeof(dataF) / sizeof(dataF[0]); |
HEPTA | 7:d07155a73b24 | 48 | numG = sizeof(dataG) / sizeof(dataG[0]); |
HEPTA | 7:d07155a73b24 | 49 | numH = sizeof(dataH) / sizeof(dataH[0]); |
HEPTA | 8:8e925f198e21 | 50 | numI = sizeof(dataI) / sizeof(dataI[0]); |
HEPTA | 7:d07155a73b24 | 51 | numJ = sizeof(dataJ) / sizeof(dataJ[0])*2; |
HEPTA | 8:8e925f198e21 | 52 | numK = sizeof(dataK) / sizeof(dataK[0])*2; |
HEPTA | 7:d07155a73b24 | 53 | numL = sizeof(dataL) / sizeof(dataL[0]); |
HEPTA | 7:d07155a73b24 | 54 | numM = sizeof(dataM) / sizeof(dataM[0]); |
HEPTA | 7:d07155a73b24 | 55 | numN = sizeof(dataN) / sizeof(dataN[0]); |
HEPTA | 7:d07155a73b24 | 56 | output_num=numA+numB+numC+numD+numE+numF+numG+numH+numI+numJ+numK+numL+numM+numN; |
umeume | 3:c3e667ee70f1 | 57 | int N=0,i=0,ii; |
HEPTA | 7:d07155a73b24 | 58 | for(i = 0; i <= numA-1; i++) { |
HEPTA | 7:d07155a73b24 | 59 | OutputData[N+i] = dataA[i]; |
hepta2ume | 0:1e02be589d1f | 60 | } |
HEPTA | 7:d07155a73b24 | 61 | N=i; |
HEPTA | 7:d07155a73b24 | 62 | for(i = 0; i <= numB-1; i++) { |
HEPTA | 7:d07155a73b24 | 63 | OutputData[N+i] = dataB[i]; |
umeume | 4:ede5c519e238 | 64 | } |
HEPTA | 7:d07155a73b24 | 65 | N=N+i; |
HEPTA | 7:d07155a73b24 | 66 | for(i = 0; i <= numC-1; i++) { |
HEPTA | 7:d07155a73b24 | 67 | OutputData[N+i] = dataC[i]; |
hepta2ume | 0:1e02be589d1f | 68 | } |
HEPTA | 7:d07155a73b24 | 69 | N=N+i; |
HEPTA | 7:d07155a73b24 | 70 | for(i = 0; i <= numD-1; i++) { |
HEPTA | 7:d07155a73b24 | 71 | OutputData[N+i] = dataD[i]; |
hepta2ume | 0:1e02be589d1f | 72 | } |
HEPTA | 7:d07155a73b24 | 73 | N=N+i; |
HEPTA | 7:d07155a73b24 | 74 | for(i = 0; i <= numE-1; i++) { |
HEPTA | 7:d07155a73b24 | 75 | OutputData[N+i] = dataE[i]; |
umeume | 4:ede5c519e238 | 76 | } |
HEPTA | 7:d07155a73b24 | 77 | N=N+i; |
HEPTA | 7:d07155a73b24 | 78 | for(i = 0; i <= numF-1; i++) { |
HEPTA | 7:d07155a73b24 | 79 | OutputData[N+i] = dataF[i]; |
hepta2ume | 0:1e02be589d1f | 80 | } |
HEPTA | 7:d07155a73b24 | 81 | N=N+i; |
HEPTA | 7:d07155a73b24 | 82 | for(i = 0; i <= numG-1; i++) { |
HEPTA | 7:d07155a73b24 | 83 | OutputData[N+i] = dataG[i]; |
umeume | 4:ede5c519e238 | 84 | } |
HEPTA | 7:d07155a73b24 | 85 | N=N+i; |
HEPTA | 7:d07155a73b24 | 86 | for(i = 0; i <= numH-1; i++) { |
HEPTA | 7:d07155a73b24 | 87 | OutputData[N+i] = dataH[i]; |
HEPTA | 7:d07155a73b24 | 88 | } |
HEPTA | 7:d07155a73b24 | 89 | N=N+i; |
HEPTA | 7:d07155a73b24 | 90 | for(i = 0; i <= numI-1; i++) { |
HEPTA | 7:d07155a73b24 | 91 | OutputData[N+i] = dataI[i]; |
hepta2ume | 0:1e02be589d1f | 92 | } |
HEPTA | 7:d07155a73b24 | 93 | N=N+i; |
HEPTA | 7:d07155a73b24 | 94 | for(i = 0; i <= numJ-1; i++) { |
HEPTA | 7:d07155a73b24 | 95 | OutputData[N+i] = dataJ[i]; |
hepta2ume | 0:1e02be589d1f | 96 | } |
HEPTA | 7:d07155a73b24 | 97 | N=N+i; |
HEPTA | 7:d07155a73b24 | 98 | for(i = 0; i <= numK-1; i++) { |
HEPTA | 7:d07155a73b24 | 99 | OutputData[N+i] = dataK[i]; |
HEPTA | 7:d07155a73b24 | 100 | } |
HEPTA | 7:d07155a73b24 | 101 | N=N+i; |
HEPTA | 7:d07155a73b24 | 102 | for(i = 0; i <= numL-1; i++) { |
HEPTA | 7:d07155a73b24 | 103 | OutputData[N+i] = dataL[i]; |
umeume | 4:ede5c519e238 | 104 | } |
HEPTA | 7:d07155a73b24 | 105 | N=N+i; |
HEPTA | 7:d07155a73b24 | 106 | for(i = 0; i <= numM-1; i++) { |
HEPTA | 7:d07155a73b24 | 107 | OutputData[N+i] = dataM[i]; |
hepta2ume | 0:1e02be589d1f | 108 | } |
HEPTA | 7:d07155a73b24 | 109 | N=N+i; |
HEPTA | 7:d07155a73b24 | 110 | for(i = 0; i <= numN-1; i++) { |
HEPTA | 7:d07155a73b24 | 111 | OutputData[N+i] = dataN[i]; |
umeume | 4:ede5c519e238 | 112 | } |
HEPTA | 7:d07155a73b24 | 113 | for(ii=0; ii<output_num; ii++) { |
HEPTA | 7:d07155a73b24 | 114 | xbee.putc(OutputData[ii]); |
hepta2ume | 1:c31e4a5db17c | 115 | } |
HEPTA | 7:d07155a73b24 | 116 | xbee.putc(0x0a); |
umeume | 4:ede5c519e238 | 117 | } |
umeume | 4:ede5c519e238 | 118 | void HeptaXbee::puts( char *s ) |
umeume | 4:ede5c519e238 | 119 | { |
umeume | 4:ede5c519e238 | 120 | while ( char c = *s++ ) |
umeume | 4:ede5c519e238 | 121 | xbee.putc( c ); |
umeume | 4:ede5c519e238 | 122 | } |
umeume | 4:ede5c519e238 | 123 | void HeptaXbee::printf( char *format, ... ) |
umeume | 4:ede5c519e238 | 124 | { |
umeume | 4:ede5c519e238 | 125 | char s[ 100 ]; |
umeume | 4:ede5c519e238 | 126 | va_list args; |
umeume | 4:ede5c519e238 | 127 | |
umeume | 4:ede5c519e238 | 128 | va_start( args, format ); |
umeume | 4:ede5c519e238 | 129 | vsnprintf( s, 100, format, args ); |
umeume | 4:ede5c519e238 | 130 | va_end( args ); |
umeume | 4:ede5c519e238 | 131 | |
umeume | 4:ede5c519e238 | 132 | xbee.puts( s ); |
umeume | 4:ede5c519e238 | 133 | } |
umeume | 4:ede5c519e238 | 134 | char HeptaXbee::getc() |
umeume | 4:ede5c519e238 | 135 | { |
umeume | 4:ede5c519e238 | 136 | char character; |
umeume | 4:ede5c519e238 | 137 | character = xbee.getc(); |
umeume | 4:ede5c519e238 | 138 | return character; |
umeume | 4:ede5c519e238 | 139 | } |
umeume | 4:ede5c519e238 | 140 | |
HEPTA | 7:d07155a73b24 | 141 | void HeptaXbee::putc(char data) |
umeume | 4:ede5c519e238 | 142 | { |
HEPTA | 7:d07155a73b24 | 143 | xbee.putc(data); |
umeume | 4:ede5c519e238 | 144 | } |