Hepta 2
/
HEPTA2_XBEE
HEPTA2Xbee_
Fork of HEPTA_Xbee by
Revision 1:9bf7fa8a7615, committed 2017-07-19
- Comitter:
- hepta2ume
- Date:
- Wed Jul 19 08:01:08 2017 +0000
- Parent:
- 0:f922c2672aa4
- Commit message:
- Hepta2_xbee_(0719)
Changed in this revision
diff -r f922c2672aa4 -r 9bf7fa8a7615 HeptaXbee.cpp --- a/HeptaXbee.cpp Wed Jul 19 07:52:57 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -#include "HeptaXbee.h" -#include "mbed.h" -#include <stdarg.h> - -HeptaXbee::HeptaXbee(PinName tx, PinName rx) : xbee(tx,rx) -{ - rcmd = 0; - cmdflag = 0; -} - -void HeptaXbee::xbee_recieve(int *xrcmd, int *xcmdflag) { - xbee.attach(this,&HeptaXbee::commandget,Serial::RxIrq); - //xbee.printf("ssXbeedata= %d,%d",HeptaXbee::rcmd,HeptaXbee::cmdflag); - *xrcmd = HeptaXbee::rcmd; - *xcmdflag = HeptaXbee::cmdflag; -} - -void HeptaXbee::initialize(){ - HeptaXbee::rcmd = 0; - HeptaXbee::cmdflag = 0; -} - -void HeptaXbee::commandget(){ - HeptaXbee::rcmd=xbee.getc(); - HeptaXbee::cmdflag = 1; - //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[], - int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int data_num) -{ - int N=0,i=0,ii,jj=0; - 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; - } - 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; - } - if(data_num>=5){ - for(i = 0; i <= n5-1; i++){ - output_data[N+i] = data5[i]; - } - N=N+i; - } - if(data_num>=6){ - for(i = 0; i <= n6-1; i++){ - output_data[N+i] = data6[i]; - } - N=N+i; - } - if(data_num>=7){ - for(i = 0; i <= n7-1; i++){ - output_data[N+i] = data7[i]; - } - N=N+i; - } - if(data_num>=8){ - for(i = 0; i <= n8-1; i++){ - output_data[N+i] = data8[i]; - } - N=N+i; - } - if(data_num>=9){ - for(i = 0; i <= n9-1; i++){ - output_data[N+i] = data9[i]; - } - } - for(ii=0;ii<output_n;ii++){ - xbee.putc(output_data[ii]); - jj++; - if(jj==2) - { - xbee.putc(0x20); - jj=0; - } - } - xbee.putc(0x0a); -} -void HeptaXbee::puts( char *s ) { - while ( char c = *s++ ) - xbee.putc( c ); -} -void HeptaXbee::printf( char *format, ... ) { - char s[ 32 ]; - va_list args; - - va_start( args, format ); - vsnprintf( s, 32, format, args ); - va_end( args ); - - xbee.puts( s ); -} \ No newline at end of file
diff -r f922c2672aa4 -r 9bf7fa8a7615 HeptaXbee.h --- a/HeptaXbee.h Wed Jul 19 07:52:57 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#ifndef MBED_HEPTAXBEE_H -#define MBED_HEPTAXBEE_H -#include "mbed.h" - -//Xbee Series2 - -class HeptaXbee{ -public: - Serial xbee; - int rcmd; - int cmdflag; - HeptaXbee( - PinName tx, - PinName rx - ); - void xbee_recieve(int *xrcmd, int *xcmdflag); - void initialize(); - void commandget(); - void 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[], - int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int data_num); - void puts( char *s ); - void printf(char *format, ... ); -private: -}; -#endif \ No newline at end of file
diff -r f922c2672aa4 -r 9bf7fa8a7615 HeptaXbee.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeptaXbee.lib Wed Jul 19 08:01:08 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/hepta2ume/code/HeptaXbee/#1e02be589d1f
diff -r f922c2672aa4 -r 9bf7fa8a7615 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 19 08:01:08 2017 +0000 @@ -0,0 +1,23 @@ +#include "HeptaXbee.h" +HeptaXbee xbee(p9,p10); +Serial pc(USBTX,USBRX); +int main() +{ + + int i=0,rcmd=0,cmdflag=0; + xbee.printf("Count Up!\r"); + while(1) { + xbee.printf("num = %d\r",i); + i++; + wait(1.0); + xbee.xbee_recieve(&rcmd,&cmdflag); + pc.printf("rcmd=%d, cmdflag=%d\r\n",rcmd, cmdflag); + if (cmdflag == 1) { + if (rcmd == 'a') { + pc.printf("Command Get %d\r\n",rcmd); + xbee.printf("HEPTA Uplink OK\r"); + } + xbee.initialize(); + } + } +} \ No newline at end of file