Accel
Dependencies: mbed PowerControl SDFileSystem
Fork of HeptaAccel by
hepta_sat/HeptaXbee.cpp@0:d721efd58e4e, 2016-12-09 (annotated)
- Committer:
- tomoya123
- Date:
- Fri Dec 09 03:40:15 2016 +0000
- Revision:
- 0:d721efd58e4e
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:d721efd58e4e | 1 | #include "HeptaXbee.h" |
tomoya123 | 0:d721efd58e4e | 2 | #include "mbed.h" |
tomoya123 | 0:d721efd58e4e | 3 | #include <stdarg.h> |
tomoya123 | 0:d721efd58e4e | 4 | |
tomoya123 | 0:d721efd58e4e | 5 | HeptaXbee::HeptaXbee(PinName tx, PinName rx) : xbee(tx,rx) |
tomoya123 | 0:d721efd58e4e | 6 | { |
tomoya123 | 0:d721efd58e4e | 7 | rcmd = 0; |
tomoya123 | 0:d721efd58e4e | 8 | cmdflag = 0; |
tomoya123 | 0:d721efd58e4e | 9 | } |
tomoya123 | 0:d721efd58e4e | 10 | void HeptaXbee::baud(int rate) |
tomoya123 | 0:d721efd58e4e | 11 | { |
tomoya123 | 0:d721efd58e4e | 12 | xbee.baud(rate); |
tomoya123 | 0:d721efd58e4e | 13 | } |
tomoya123 | 0:d721efd58e4e | 14 | void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag) { |
tomoya123 | 0:d721efd58e4e | 15 | xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq); |
tomoya123 | 0:d721efd58e4e | 16 | //xbee.printf("ssXbeedata= %d,%d",HeptaXbee::rcmd,HeptaXbee::cmdflag); |
tomoya123 | 0:d721efd58e4e | 17 | *xrcmd = HeptaXbee::rcmd; |
tomoya123 | 0:d721efd58e4e | 18 | *xcmdflag = HeptaXbee::cmdflag; |
tomoya123 | 0:d721efd58e4e | 19 | } |
tomoya123 | 0:d721efd58e4e | 20 | |
tomoya123 | 0:d721efd58e4e | 21 | void HeptaXbee::initialize(){ |
tomoya123 | 0:d721efd58e4e | 22 | HeptaXbee::rcmd = 0; |
tomoya123 | 0:d721efd58e4e | 23 | HeptaXbee::cmdflag = 0; |
tomoya123 | 0:d721efd58e4e | 24 | } |
tomoya123 | 0:d721efd58e4e | 25 | |
tomoya123 | 0:d721efd58e4e | 26 | void HeptaXbee::commandget(){ |
tomoya123 | 0:d721efd58e4e | 27 | HeptaXbee::rcmd=xbee.getc(); |
tomoya123 | 0:d721efd58e4e | 28 | HeptaXbee::cmdflag = 1; |
tomoya123 | 0:d721efd58e4e | 29 | //xbee.printf("Xbeedata= %d,%d",rcmd,cmdflag); |
tomoya123 | 0:d721efd58e4e | 30 | } |
tomoya123 | 0:d721efd58e4e | 31 | void HeptaXbee::putc(char data) |
tomoya123 | 0:d721efd58e4e | 32 | { |
tomoya123 | 0:d721efd58e4e | 33 | xbee.putc(data); |
tomoya123 | 0:d721efd58e4e | 34 | } |
tomoya123 | 0:d721efd58e4e | 35 | void HeptaXbee::xbee_transmit(char* output_data,size_t output_n, |
tomoya123 | 0:d721efd58e4e | 36 | char data1[],char data2[],char data3[],char data4[],char data5[],char data6[],char data7[],char data8[],char data9[], |
tomoya123 | 0:d721efd58e4e | 37 | int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9) |
tomoya123 | 0:d721efd58e4e | 38 | { |
tomoya123 | 0:d721efd58e4e | 39 | int N=0,i=0,ii,jj=0; |
tomoya123 | 0:d721efd58e4e | 40 | for(i = 0; i <= n1-1; i++){ |
tomoya123 | 0:d721efd58e4e | 41 | output_data[N+i] = data1[i]; |
tomoya123 | 0:d721efd58e4e | 42 | } |
tomoya123 | 0:d721efd58e4e | 43 | N=i; |
tomoya123 | 0:d721efd58e4e | 44 | for(i = 0; i <= n2-1; i++){ |
tomoya123 | 0:d721efd58e4e | 45 | output_data[N+i] = data2[i]; |
tomoya123 | 0:d721efd58e4e | 46 | } |
tomoya123 | 0:d721efd58e4e | 47 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 48 | for(i = 0; i <= n3-1; i++){ |
tomoya123 | 0:d721efd58e4e | 49 | output_data[N+i] = data3[i]; |
tomoya123 | 0:d721efd58e4e | 50 | } |
tomoya123 | 0:d721efd58e4e | 51 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 52 | for(i = 0; i <= n4-1; i++){ |
tomoya123 | 0:d721efd58e4e | 53 | output_data[N+i] = data4[i]; |
tomoya123 | 0:d721efd58e4e | 54 | } |
tomoya123 | 0:d721efd58e4e | 55 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 56 | for(i = 0; i <= n5-1; i++){ |
tomoya123 | 0:d721efd58e4e | 57 | output_data[N+i] = data5[i]; |
tomoya123 | 0:d721efd58e4e | 58 | } |
tomoya123 | 0:d721efd58e4e | 59 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 60 | for(i = 0; i <= n6-1; i++){ |
tomoya123 | 0:d721efd58e4e | 61 | output_data[N+i] = data6[i]; |
tomoya123 | 0:d721efd58e4e | 62 | } |
tomoya123 | 0:d721efd58e4e | 63 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 64 | for(i = 0; i <= n7-1; i++){ |
tomoya123 | 0:d721efd58e4e | 65 | output_data[N+i] = data7[i]; |
tomoya123 | 0:d721efd58e4e | 66 | } |
tomoya123 | 0:d721efd58e4e | 67 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 68 | for(i = 0; i <= n8-1; i++){ |
tomoya123 | 0:d721efd58e4e | 69 | output_data[N+i] = data8[i]; |
tomoya123 | 0:d721efd58e4e | 70 | } |
tomoya123 | 0:d721efd58e4e | 71 | N=N+i; |
tomoya123 | 0:d721efd58e4e | 72 | for(i = 0; i <= n9-1; i++){ |
tomoya123 | 0:d721efd58e4e | 73 | output_data[N+i] = data9[i]; |
tomoya123 | 0:d721efd58e4e | 74 | } |
tomoya123 | 0:d721efd58e4e | 75 | for(ii=0;ii<output_n;ii++){ |
tomoya123 | 0:d721efd58e4e | 76 | xbee.putc(output_data[ii]); |
tomoya123 | 0:d721efd58e4e | 77 | jj++; |
tomoya123 | 0:d721efd58e4e | 78 | if(jj==2) |
tomoya123 | 0:d721efd58e4e | 79 | { |
tomoya123 | 0:d721efd58e4e | 80 | xbee.putc(0x20); |
tomoya123 | 0:d721efd58e4e | 81 | jj=0; |
tomoya123 | 0:d721efd58e4e | 82 | } |
tomoya123 | 0:d721efd58e4e | 83 | } |
tomoya123 | 0:d721efd58e4e | 84 | xbee.putc(0x0a); |
tomoya123 | 0:d721efd58e4e | 85 | } |
tomoya123 | 0:d721efd58e4e | 86 | void HeptaXbee::puts( char *s ) { |
tomoya123 | 0:d721efd58e4e | 87 | while ( char c = *s++ ) |
tomoya123 | 0:d721efd58e4e | 88 | xbee.putc( c ); |
tomoya123 | 0:d721efd58e4e | 89 | } |
tomoya123 | 0:d721efd58e4e | 90 | void HeptaXbee::printf( char *format, ... ) { |
tomoya123 | 0:d721efd58e4e | 91 | char s[ 32 ]; |
tomoya123 | 0:d721efd58e4e | 92 | va_list args; |
tomoya123 | 0:d721efd58e4e | 93 | |
tomoya123 | 0:d721efd58e4e | 94 | va_start( args, format ); |
tomoya123 | 0:d721efd58e4e | 95 | vsnprintf( s, 32, format, args ); |
tomoya123 | 0:d721efd58e4e | 96 | va_end( args ); |
tomoya123 | 0:d721efd58e4e | 97 | |
tomoya123 | 0:d721efd58e4e | 98 | xbee.puts( s ); |
tomoya123 | 0:d721efd58e4e | 99 | } |