For Hepta-Sat Lite

Committer:
hepta2ume
Date:
Sat Aug 05 13:36:13 2017 +0000
Revision:
2:031c35ada7e6
Parent:
1:c31e4a5db17c
Child:
3:c3e667ee70f1
test

Who changed what in which revision?

UserRevisionLine numberNew 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 2:031c35ada7e6 30 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[],
hepta2ume 2:031c35ada7e6 31 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 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 1:c31e4a5db17c 87 N=N+i;
hepta2ume 1:c31e4a5db17c 88 }
hepta2ume 1:c31e4a5db17c 89 if(data_num>=10){
hepta2ume 1:c31e4a5db17c 90 for(i = 0; i <= n10-1; i++){
hepta2ume 1:c31e4a5db17c 91 output_data[N+i] = data10[i];
hepta2ume 1:c31e4a5db17c 92 }
hepta2ume 1:c31e4a5db17c 93 N=N+i;
hepta2ume 1:c31e4a5db17c 94 }
hepta2ume 1:c31e4a5db17c 95 if(data_num>=11){
hepta2ume 1:c31e4a5db17c 96 for(i = 0; i <= n11-1; i++){
hepta2ume 1:c31e4a5db17c 97 output_data[N+i] = data11[i];
hepta2ume 1:c31e4a5db17c 98 }
hepta2ume 1:c31e4a5db17c 99 N=N+i;
hepta2ume 1:c31e4a5db17c 100 }
hepta2ume 1:c31e4a5db17c 101 if(data_num>=12){
hepta2ume 1:c31e4a5db17c 102 for(i = 0; i <= n12-1; i++){
hepta2ume 1:c31e4a5db17c 103 output_data[N+i] = data12[i];
hepta2ume 1:c31e4a5db17c 104 }
hepta2ume 1:c31e4a5db17c 105 N=N+i;
hepta2ume 1:c31e4a5db17c 106 }
hepta2ume 1:c31e4a5db17c 107 if(data_num>=13){
hepta2ume 1:c31e4a5db17c 108 for(i = 0; i <= n13-1; i++){
hepta2ume 1:c31e4a5db17c 109 output_data[N+i] = data13[i];
hepta2ume 1:c31e4a5db17c 110 }
hepta2ume 2:031c35ada7e6 111 N=N+i;
hepta2ume 2:031c35ada7e6 112 }
hepta2ume 2:031c35ada7e6 113 if(data_num>=14){
hepta2ume 2:031c35ada7e6 114 for(i = 0; i <= n14-1; i++){
hepta2ume 2:031c35ada7e6 115 output_data[N+i] = data14[i];
hepta2ume 2:031c35ada7e6 116 }
hepta2ume 0:1e02be589d1f 117 }
hepta2ume 0:1e02be589d1f 118 for(ii=0;ii<output_n;ii++){
hepta2ume 0:1e02be589d1f 119 xbee.putc(output_data[ii]);
hepta2ume 2:031c35ada7e6 120 /*
hepta2ume 0:1e02be589d1f 121 jj++;
hepta2ume 0:1e02be589d1f 122 if(jj==2)
hepta2ume 0:1e02be589d1f 123 {
hepta2ume 0:1e02be589d1f 124 xbee.putc(0x20);
hepta2ume 0:1e02be589d1f 125 jj=0;
hepta2ume 2:031c35ada7e6 126 } */
hepta2ume 0:1e02be589d1f 127 }
hepta2ume 2:031c35ada7e6 128 xbee.printf("\n");
hepta2ume 0:1e02be589d1f 129 }
hepta2ume 0:1e02be589d1f 130 void HeptaXbee::puts( char *s ) {
hepta2ume 0:1e02be589d1f 131 while ( char c = *s++ )
hepta2ume 0:1e02be589d1f 132 xbee.putc( c );
hepta2ume 0:1e02be589d1f 133 }
hepta2ume 0:1e02be589d1f 134 void HeptaXbee::printf( char *format, ... ) {
hepta2ume 0:1e02be589d1f 135 char s[ 32 ];
hepta2ume 0:1e02be589d1f 136 va_list args;
hepta2ume 0:1e02be589d1f 137
hepta2ume 0:1e02be589d1f 138 va_start( args, format );
hepta2ume 0:1e02be589d1f 139 vsnprintf( s, 32, format, args );
hepta2ume 0:1e02be589d1f 140 va_end( args );
hepta2ume 0:1e02be589d1f 141
hepta2ume 0:1e02be589d1f 142 xbee.puts( s );
hepta2ume 2:031c35ada7e6 143 }
hepta2ume 2:031c35ada7e6 144 char HeptaXbee::getc(){
hepta2ume 2:031c35ada7e6 145 char chara;
hepta2ume 2:031c35ada7e6 146 chara = xbee.getc();
hepta2ume 2:031c35ada7e6 147 return chara;
hepta2ume 2:031c35ada7e6 148 }