Battery

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaBattery by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 06:37:27 2016 +0000
Revision:
1:166ddf929155
Parent:
0:d53e9c6fc771
HeptaBattery

Who changed what in which revision?

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