For Hepta-Sat Lite

Revision:
7:d07155a73b24
Parent:
6:94eef84c1a50
Child:
8:8e925f198e21
diff -r 94eef84c1a50 -r d07155a73b24 HeptaXbee.cpp
--- a/HeptaXbee.cpp	Mon Sep 04 16:37:25 2017 +0000
+++ b/HeptaXbee.cpp	Tue Sep 05 12:47:16 2017 +0000
@@ -6,9 +6,11 @@
 {
     rcmd = 0;
     cmdflag = 0;
-    //xbee.baud(115200);
 }
-
+void HeptaXbee::baud(int rate)
+{
+    xbee.baud(rate);
+}
 void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag)
 {
     xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq);
@@ -30,100 +32,88 @@
     //xbee.printf("Xbeedata= %d,%d",rcmd,cmdflag);
 }
 
-void HeptaXbee::xbee_transmit(char* output_data,size_t output_n,
-                              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[],
-                              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)
+//*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 
+void HeptaXbee::xbee_transmit(char dataA[],char dataB[],char dataC[],char dataD[],char dataE[],
+                              char dataF[],char dataG[],char dataH[],char dataI[],char dataJ[],
+                              char dataK[],char dataL[],char dataM[],char dataN[])
 {
+    char OutputData[255];
+    int output_num,numA,numB,numC,numD,numE,numF,numG,numH,numI,numJ,numK,numL,numM,numN;
+    numA = sizeof(dataA) / sizeof(dataA[0]);
+    numB = sizeof(dataB) / sizeof(dataB[0]);
+    numC = sizeof(dataC) / sizeof(dataC[0]);
+    numD = sizeof(dataD) / sizeof(dataD[0]);
+    numE = sizeof(dataE) / sizeof(dataE[0]);
+    numF = sizeof(dataF) / sizeof(dataF[0]);
+    numG = sizeof(dataG) / sizeof(dataG[0]);
+    numH = sizeof(dataH) / sizeof(dataH[0]);
+    numI = sizeof(dataI) / sizeof(dataI[0])*2;
+    numJ = sizeof(dataJ) / sizeof(dataJ[0])*2;
+    numK = sizeof(dataK) / sizeof(dataK[0]);
+    numL = sizeof(dataL) / sizeof(dataL[0]);
+    numM = sizeof(dataM) / sizeof(dataM[0]);
+    numN = sizeof(dataN) / sizeof(dataN[0]);
+    output_num=numA+numB+numC+numD+numE+numF+numG+numH+numI+numJ+numK+numL+numM+numN;
     int N=0,i=0,ii;
-    if(data_num>=1) {
-        for(i = 0; i <= n1-1; i++) {
-            output_data[N+i] = data1[i];
-        }
-        N=i;
-    }
-
-    if(data_num>=2) {
-        for(i = 0; i <= n2-1; i++) {
-            output_data[N+i] = data2[i];
-        }
-        N=N+i;
+    for(i = 0; i <= numA-1; i++) {
+        OutputData[N+i] = dataA[i];
     }
-    if(data_num>=3) {
-        for(i = 0; i <= n3-1; i++) {
-            output_data[N+i] = data3[i];
-        }
-        N=N+i;
-    }
-    if(data_num>=4) {
-        for(i = 0; i <= n4-1; i++) {
-            output_data[N+i] = data4[i];
-        }
-        N=N+i;
+    N=i;
+    for(i = 0; i <= numB-1; i++) {
+        OutputData[N+i] = dataB[i];
     }
-    if(data_num>=5) {
-        for(i = 0; i <= n5-1; i++) {
-            output_data[N+i] = data5[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numC-1; i++) {
+        OutputData[N+i] = dataC[i];
     }
-    if(data_num>=6) {
-        for(i = 0; i <= n6-1; i++) {
-            output_data[N+i] = data6[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numD-1; i++) {
+        OutputData[N+i] = dataD[i];
     }
-    if(data_num>=7) {
-        for(i = 0; i <= n7-1; i++) {
-            output_data[N+i] = data7[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numE-1; i++) {
+        OutputData[N+i] = dataE[i];
     }
-    if(data_num>=8) {
-        for(i = 0; i <= n8-1; i++) {
-            output_data[N+i] = data8[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numF-1; i++) {
+        OutputData[N+i] = dataF[i];
     }
-    if(data_num>=9) {
-        for(i = 0; i <= n9-1; i++) {
-            output_data[N+i] = data9[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numG-1; i++) {
+        OutputData[N+i] = dataG[i];
     }
-    if(data_num>=10) {
-        for(i = 0; i <= n10-1; i++) {
-            output_data[N+i] = data10[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numH-1; i++) {
+        OutputData[N+i] = dataH[i];
+    }
+    N=N+i;
+    for(i = 0; i <= numI-1; i++) {
+        OutputData[N+i] = dataI[i];
     }
-    if(data_num>=11) {
-        for(i = 0; i <= n11-1; i++) {
-            output_data[N+i] = data11[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numJ-1; i++) {
+        OutputData[N+i] = dataJ[i];
     }
-    if(data_num>=12) {
-        for(i = 0; i <= n12-1; i++) {
-            output_data[N+i] = data12[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numK-1; i++) {
+        OutputData[N+i] = dataK[i];
+    }
+    N=N+i;
+    for(i = 0; i <= numL-1; i++) {
+        OutputData[N+i] = dataL[i];
     }
-    if(data_num>=13) {
-        for(i = 0; i <= n13-1; i++) {
-            output_data[N+i] = data13[i];
-        }
-        N=N+i;
+    N=N+i;
+    for(i = 0; i <= numM-1; i++) {
+        OutputData[N+i] = dataM[i];
     }
-    if(data_num>=14) {
-        for(i = 0; i <= n14-1; i++) {
-            output_data[N+i] = data14[i];
-        }
+    N=N+i;
+    for(i = 0; i <= numN-1; i++) {
+        OutputData[N+i] = dataN[i];
     }
-    for(ii=0; ii<output_n; ii++) {
-        xbee.putc(output_data[ii]);
-
+    for(ii=0; ii<output_num; ii++) {
+        xbee.putc(OutputData[ii]);
     }
-    xbee.printf("\n");
+    xbee.putc(0x0a);
 }
 void HeptaXbee::puts( char *s )
 {
@@ -148,7 +138,7 @@
     return character;
 }
 
-void HeptaXbee::putc(char chara)
+void HeptaXbee::putc(char data)
 {
-    xbee.putc(chara);
+    xbee.putc(data);
 }