For Hepta-Sat Lite
HeptaXbee.cpp@0:1e02be589d1f, 2017-07-19 (annotated)
- Committer:
- hepta2ume
- Date:
- Wed Jul 19 07:59:59 2017 +0000
- Revision:
- 0:1e02be589d1f
- Child:
- 1:c31e4a5db17c
HEPTA_Xbee_0719;
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 | } |
hepta2ume | 0:1e02be589d1f | 10 | |
hepta2ume | 0:1e02be589d1f | 11 | void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag) { |
hepta2ume | 0:1e02be589d1f | 12 | xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq); |
hepta2ume | 0:1e02be589d1f | 13 | //xbee.printf("ssXbeedata= %d,%d",HeptaXbee::rcmd,HeptaXbee::cmdflag); |
hepta2ume | 0:1e02be589d1f | 14 | *xrcmd = HeptaXbee::rcmd; |
hepta2ume | 0:1e02be589d1f | 15 | *xcmdflag = HeptaXbee::cmdflag; |
hepta2ume | 0:1e02be589d1f | 16 | } |
hepta2ume | 0:1e02be589d1f | 17 | |
hepta2ume | 0:1e02be589d1f | 18 | void HeptaXbee::initialize(){ |
hepta2ume | 0:1e02be589d1f | 19 | HeptaXbee::rcmd = 0; |
hepta2ume | 0:1e02be589d1f | 20 | HeptaXbee::cmdflag = 0; |
hepta2ume | 0:1e02be589d1f | 21 | } |
hepta2ume | 0:1e02be589d1f | 22 | |
hepta2ume | 0:1e02be589d1f | 23 | void HeptaXbee::commandget(){ |
hepta2ume | 0:1e02be589d1f | 24 | HeptaXbee::rcmd=xbee.getc(); |
hepta2ume | 0:1e02be589d1f | 25 | HeptaXbee::cmdflag = 1; |
hepta2ume | 0:1e02be589d1f | 26 | //xbee.printf("Xbeedata= %d,%d",rcmd,cmdflag); |
hepta2ume | 0:1e02be589d1f | 27 | } |
hepta2ume | 0:1e02be589d1f | 28 | |
hepta2ume | 0:1e02be589d1f | 29 | void HeptaXbee::xbee_transmit(char* output_data,size_t output_n, |
hepta2ume | 0:1e02be589d1f | 30 | char data1[],char data2[],char data3[],char data4[],char data5[],char data6[],char data7[],char data8[],char data9[], |
hepta2ume | 0:1e02be589d1f | 31 | int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int data_num) |
hepta2ume | 0:1e02be589d1f | 32 | { |
hepta2ume | 0:1e02be589d1f | 33 | int N=0,i=0,ii,jj=0; |
hepta2ume | 0:1e02be589d1f | 34 | if(data_num>=1){ |
hepta2ume | 0:1e02be589d1f | 35 | for(i = 0; i <= n1-1; i++){ |
hepta2ume | 0:1e02be589d1f | 36 | output_data[N+i] = data1[i]; |
hepta2ume | 0:1e02be589d1f | 37 | } |
hepta2ume | 0:1e02be589d1f | 38 | N=i; |
hepta2ume | 0:1e02be589d1f | 39 | } |
hepta2ume | 0:1e02be589d1f | 40 | |
hepta2ume | 0:1e02be589d1f | 41 | if(data_num>=2){ |
hepta2ume | 0:1e02be589d1f | 42 | for(i = 0; i <= n2-1; i++){ |
hepta2ume | 0:1e02be589d1f | 43 | output_data[N+i] = data2[i]; |
hepta2ume | 0:1e02be589d1f | 44 | } |
hepta2ume | 0:1e02be589d1f | 45 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 46 | } |
hepta2ume | 0:1e02be589d1f | 47 | if(data_num>=3){ |
hepta2ume | 0:1e02be589d1f | 48 | for(i = 0; i <= n3-1; i++){ |
hepta2ume | 0:1e02be589d1f | 49 | output_data[N+i] = data3[i]; |
hepta2ume | 0:1e02be589d1f | 50 | } |
hepta2ume | 0:1e02be589d1f | 51 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 52 | } |
hepta2ume | 0:1e02be589d1f | 53 | if(data_num>=4){ |
hepta2ume | 0:1e02be589d1f | 54 | for(i = 0; i <= n4-1; i++){ |
hepta2ume | 0:1e02be589d1f | 55 | output_data[N+i] = data4[i]; |
hepta2ume | 0:1e02be589d1f | 56 | } |
hepta2ume | 0:1e02be589d1f | 57 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 58 | } |
hepta2ume | 0:1e02be589d1f | 59 | if(data_num>=5){ |
hepta2ume | 0:1e02be589d1f | 60 | for(i = 0; i <= n5-1; i++){ |
hepta2ume | 0:1e02be589d1f | 61 | output_data[N+i] = data5[i]; |
hepta2ume | 0:1e02be589d1f | 62 | } |
hepta2ume | 0:1e02be589d1f | 63 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 64 | } |
hepta2ume | 0:1e02be589d1f | 65 | if(data_num>=6){ |
hepta2ume | 0:1e02be589d1f | 66 | for(i = 0; i <= n6-1; i++){ |
hepta2ume | 0:1e02be589d1f | 67 | output_data[N+i] = data6[i]; |
hepta2ume | 0:1e02be589d1f | 68 | } |
hepta2ume | 0:1e02be589d1f | 69 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 70 | } |
hepta2ume | 0:1e02be589d1f | 71 | if(data_num>=7){ |
hepta2ume | 0:1e02be589d1f | 72 | for(i = 0; i <= n7-1; i++){ |
hepta2ume | 0:1e02be589d1f | 73 | output_data[N+i] = data7[i]; |
hepta2ume | 0:1e02be589d1f | 74 | } |
hepta2ume | 0:1e02be589d1f | 75 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 76 | } |
hepta2ume | 0:1e02be589d1f | 77 | if(data_num>=8){ |
hepta2ume | 0:1e02be589d1f | 78 | for(i = 0; i <= n8-1; i++){ |
hepta2ume | 0:1e02be589d1f | 79 | output_data[N+i] = data8[i]; |
hepta2ume | 0:1e02be589d1f | 80 | } |
hepta2ume | 0:1e02be589d1f | 81 | N=N+i; |
hepta2ume | 0:1e02be589d1f | 82 | } |
hepta2ume | 0:1e02be589d1f | 83 | if(data_num>=9){ |
hepta2ume | 0:1e02be589d1f | 84 | for(i = 0; i <= n9-1; i++){ |
hepta2ume | 0:1e02be589d1f | 85 | output_data[N+i] = data9[i]; |
hepta2ume | 0:1e02be589d1f | 86 | } |
hepta2ume | 0:1e02be589d1f | 87 | } |
hepta2ume | 0:1e02be589d1f | 88 | for(ii=0;ii<output_n;ii++){ |
hepta2ume | 0:1e02be589d1f | 89 | xbee.putc(output_data[ii]); |
hepta2ume | 0:1e02be589d1f | 90 | jj++; |
hepta2ume | 0:1e02be589d1f | 91 | if(jj==2) |
hepta2ume | 0:1e02be589d1f | 92 | { |
hepta2ume | 0:1e02be589d1f | 93 | xbee.putc(0x20); |
hepta2ume | 0:1e02be589d1f | 94 | jj=0; |
hepta2ume | 0:1e02be589d1f | 95 | } |
hepta2ume | 0:1e02be589d1f | 96 | } |
hepta2ume | 0:1e02be589d1f | 97 | xbee.putc(0x0a); |
hepta2ume | 0:1e02be589d1f | 98 | } |
hepta2ume | 0:1e02be589d1f | 99 | void HeptaXbee::puts( char *s ) { |
hepta2ume | 0:1e02be589d1f | 100 | while ( char c = *s++ ) |
hepta2ume | 0:1e02be589d1f | 101 | xbee.putc( c ); |
hepta2ume | 0:1e02be589d1f | 102 | } |
hepta2ume | 0:1e02be589d1f | 103 | void HeptaXbee::printf( char *format, ... ) { |
hepta2ume | 0:1e02be589d1f | 104 | char s[ 32 ]; |
hepta2ume | 0:1e02be589d1f | 105 | va_list args; |
hepta2ume | 0:1e02be589d1f | 106 | |
hepta2ume | 0:1e02be589d1f | 107 | va_start( args, format ); |
hepta2ume | 0:1e02be589d1f | 108 | vsnprintf( s, 32, format, args ); |
hepta2ume | 0:1e02be589d1f | 109 | va_end( args ); |
hepta2ume | 0:1e02be589d1f | 110 | |
hepta2ume | 0:1e02be589d1f | 111 | xbee.puts( s ); |
hepta2ume | 0:1e02be589d1f | 112 | } |