For Hepta-Sat Lite

Committer:
HEPTA
Date:
Mon Sep 04 16:28:12 2017 +0000
Revision:
5:c441a88f6952
Parent:
4:ede5c519e238
Child:
6:94eef84c1a50
HeptaXbee

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;
umeume 4:ede5c519e238 9 //xbee.baud(115200);
hepta2ume 0:1e02be589d1f 10 }
hepta2ume 0:1e02be589d1f 11
umeume 4:ede5c519e238 12 void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag)
umeume 4:ede5c519e238 13 {
hepta2ume 0:1e02be589d1f 14 xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq);
hepta2ume 0:1e02be589d1f 15 //xbee.printf("ssXbeedata= %d,%d",HeptaXbee::rcmd,HeptaXbee::cmdflag);
hepta2ume 0:1e02be589d1f 16 *xrcmd = HeptaXbee::rcmd;
hepta2ume 0:1e02be589d1f 17 *xcmdflag = HeptaXbee::cmdflag;
hepta2ume 0:1e02be589d1f 18 }
hepta2ume 0:1e02be589d1f 19
umeume 4:ede5c519e238 20 void HeptaXbee::initialize()
umeume 4:ede5c519e238 21 {
hepta2ume 0:1e02be589d1f 22 HeptaXbee::rcmd = 0;
hepta2ume 0:1e02be589d1f 23 HeptaXbee::cmdflag = 0;
hepta2ume 0:1e02be589d1f 24 }
hepta2ume 0:1e02be589d1f 25
umeume 4:ede5c519e238 26 void HeptaXbee::commandget()
umeume 4:ede5c519e238 27 {
hepta2ume 0:1e02be589d1f 28 HeptaXbee::rcmd=xbee.getc();
hepta2ume 0:1e02be589d1f 29 HeptaXbee::cmdflag = 1;
hepta2ume 0:1e02be589d1f 30 //xbee.printf("Xbeedata= %d,%d",rcmd,cmdflag);
hepta2ume 0:1e02be589d1f 31 }
hepta2ume 0:1e02be589d1f 32
hepta2ume 0:1e02be589d1f 33 void HeptaXbee::xbee_transmit(char* output_data,size_t output_n,
umeume 4:ede5c519e238 34 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[],
umeume 4:ede5c519e238 35 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 36 {
umeume 3:c3e667ee70f1 37 int N=0,i=0,ii;
umeume 4:ede5c519e238 38 if(data_num>=1) {
umeume 4:ede5c519e238 39 for(i = 0; i <= n1-1; i++) {
umeume 4:ede5c519e238 40 output_data[N+i] = data1[i];
hepta2ume 0:1e02be589d1f 41 }
hepta2ume 0:1e02be589d1f 42 N=i;
hepta2ume 0:1e02be589d1f 43 }
umeume 4:ede5c519e238 44
umeume 4:ede5c519e238 45 if(data_num>=2) {
umeume 4:ede5c519e238 46 for(i = 0; i <= n2-1; i++) {
umeume 4:ede5c519e238 47 output_data[N+i] = data2[i];
hepta2ume 0:1e02be589d1f 48 }
hepta2ume 0:1e02be589d1f 49 N=N+i;
hepta2ume 0:1e02be589d1f 50 }
umeume 4:ede5c519e238 51 if(data_num>=3) {
umeume 4:ede5c519e238 52 for(i = 0; i <= n3-1; i++) {
umeume 4:ede5c519e238 53 output_data[N+i] = data3[i];
umeume 4:ede5c519e238 54 }
umeume 4:ede5c519e238 55 N=N+i;
umeume 4:ede5c519e238 56 }
umeume 4:ede5c519e238 57 if(data_num>=4) {
umeume 4:ede5c519e238 58 for(i = 0; i <= n4-1; i++) {
umeume 4:ede5c519e238 59 output_data[N+i] = data4[i];
umeume 4:ede5c519e238 60 }
umeume 4:ede5c519e238 61 N=N+i;
umeume 4:ede5c519e238 62 }
umeume 4:ede5c519e238 63 if(data_num>=5) {
umeume 4:ede5c519e238 64 for(i = 0; i <= n5-1; i++) {
umeume 4:ede5c519e238 65 output_data[N+i] = data5[i];
hepta2ume 0:1e02be589d1f 66 }
hepta2ume 0:1e02be589d1f 67 N=N+i;
hepta2ume 0:1e02be589d1f 68 }
umeume 4:ede5c519e238 69 if(data_num>=6) {
umeume 4:ede5c519e238 70 for(i = 0; i <= n6-1; i++) {
umeume 4:ede5c519e238 71 output_data[N+i] = data6[i];
hepta2ume 0:1e02be589d1f 72 }
hepta2ume 0:1e02be589d1f 73 N=N+i;
hepta2ume 0:1e02be589d1f 74 }
umeume 4:ede5c519e238 75 if(data_num>=7) {
umeume 4:ede5c519e238 76 for(i = 0; i <= n7-1; i++) {
umeume 4:ede5c519e238 77 output_data[N+i] = data7[i];
umeume 4:ede5c519e238 78 }
umeume 4:ede5c519e238 79 N=N+i;
umeume 4:ede5c519e238 80 }
umeume 4:ede5c519e238 81 if(data_num>=8) {
umeume 4:ede5c519e238 82 for(i = 0; i <= n8-1; i++) {
umeume 4:ede5c519e238 83 output_data[N+i] = data8[i];
hepta2ume 0:1e02be589d1f 84 }
hepta2ume 0:1e02be589d1f 85 N=N+i;
hepta2ume 0:1e02be589d1f 86 }
umeume 4:ede5c519e238 87 if(data_num>=9) {
umeume 4:ede5c519e238 88 for(i = 0; i <= n9-1; i++) {
umeume 4:ede5c519e238 89 output_data[N+i] = data9[i];
umeume 4:ede5c519e238 90 }
umeume 4:ede5c519e238 91 N=N+i;
umeume 4:ede5c519e238 92 }
umeume 4:ede5c519e238 93 if(data_num>=10) {
umeume 4:ede5c519e238 94 for(i = 0; i <= n10-1; i++) {
umeume 4:ede5c519e238 95 output_data[N+i] = data10[i];
hepta2ume 0:1e02be589d1f 96 }
hepta2ume 0:1e02be589d1f 97 N=N+i;
hepta2ume 0:1e02be589d1f 98 }
umeume 4:ede5c519e238 99 if(data_num>=11) {
umeume 4:ede5c519e238 100 for(i = 0; i <= n11-1; i++) {
umeume 4:ede5c519e238 101 output_data[N+i] = data11[i];
hepta2ume 0:1e02be589d1f 102 }
hepta2ume 0:1e02be589d1f 103 N=N+i;
hepta2ume 0:1e02be589d1f 104 }
umeume 4:ede5c519e238 105 if(data_num>=12) {
umeume 4:ede5c519e238 106 for(i = 0; i <= n12-1; i++) {
umeume 4:ede5c519e238 107 output_data[N+i] = data12[i];
umeume 4:ede5c519e238 108 }
umeume 4:ede5c519e238 109 N=N+i;
umeume 4:ede5c519e238 110 }
umeume 4:ede5c519e238 111 if(data_num>=13) {
umeume 4:ede5c519e238 112 for(i = 0; i <= n13-1; i++) {
umeume 4:ede5c519e238 113 output_data[N+i] = data13[i];
hepta2ume 0:1e02be589d1f 114 }
hepta2ume 0:1e02be589d1f 115 N=N+i;
hepta2ume 0:1e02be589d1f 116 }
umeume 4:ede5c519e238 117 if(data_num>=14) {
umeume 4:ede5c519e238 118 for(i = 0; i <= n14-1; i++) {
umeume 4:ede5c519e238 119 output_data[N+i] = data14[i];
hepta2ume 0:1e02be589d1f 120 }
umeume 4:ede5c519e238 121 }
umeume 4:ede5c519e238 122 for(ii=0; ii<output_n; ii++) {
umeume 4:ede5c519e238 123 xbee.putc(output_data[ii]);
umeume 4:ede5c519e238 124
hepta2ume 1:c31e4a5db17c 125 }
umeume 4:ede5c519e238 126 xbee.printf("\n");
umeume 4:ede5c519e238 127 }
umeume 4:ede5c519e238 128 void HeptaXbee::puts( char *s )
umeume 4:ede5c519e238 129 {
umeume 4:ede5c519e238 130 while ( char c = *s++ )
umeume 4:ede5c519e238 131 xbee.putc( c );
umeume 4:ede5c519e238 132 }
umeume 4:ede5c519e238 133 void HeptaXbee::printf( char *format, ... )
umeume 4:ede5c519e238 134 {
umeume 4:ede5c519e238 135 char s[ 100 ];
umeume 4:ede5c519e238 136 va_list args;
umeume 4:ede5c519e238 137
umeume 4:ede5c519e238 138 va_start( args, format );
umeume 4:ede5c519e238 139 vsnprintf( s, 100, format, args );
umeume 4:ede5c519e238 140 va_end( args );
umeume 4:ede5c519e238 141
umeume 4:ede5c519e238 142 xbee.puts( s );
umeume 4:ede5c519e238 143 }
umeume 4:ede5c519e238 144 char HeptaXbee::getc()
umeume 4:ede5c519e238 145 {
umeume 4:ede5c519e238 146 char character;
umeume 4:ede5c519e238 147 character = xbee.getc();
umeume 4:ede5c519e238 148 return character;
umeume 4:ede5c519e238 149 }
umeume 4:ede5c519e238 150
HEPTA 5:c441a88f6952 151 void HeptaXbee::putc(char cc)
umeume 4:ede5c519e238 152 {
umeume 4:ede5c519e238 153 xbee.putc(cc);
umeume 4:ede5c519e238 154 }