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 "HeptaGPS.h"
tomoya123 0:d53e9c6fc771 2 #include "mbed.h"
tomoya123 0:d53e9c6fc771 3
tomoya123 0:d53e9c6fc771 4 HeptaGPS::HeptaGPS(PinName tx, PinName rx) : gps(tx,rx)
tomoya123 0:d53e9c6fc771 5 {
tomoya123 0:d53e9c6fc771 6 }
tomoya123 0:d53e9c6fc771 7 void HeptaGPS::baud(int rate)
tomoya123 0:d53e9c6fc771 8 {
tomoya123 0:d53e9c6fc771 9 gps.baud(rate);
tomoya123 0:d53e9c6fc771 10 }
tomoya123 0:d53e9c6fc771 11 char HeptaGPS::getc()
tomoya123 0:d53e9c6fc771 12 {
tomoya123 0:d53e9c6fc771 13 c = gps.getc();
tomoya123 0:d53e9c6fc771 14 return c;
tomoya123 0:d53e9c6fc771 15 }
tomoya123 0:d53e9c6fc771 16 int HeptaGPS::readable()
tomoya123 0:d53e9c6fc771 17 {
tomoya123 0:d53e9c6fc771 18 i = gps.readable();
tomoya123 0:d53e9c6fc771 19 return i;
tomoya123 0:d53e9c6fc771 20 }
tomoya123 0:d53e9c6fc771 21 void HeptaGPS::flushSerialBuffer(void)
tomoya123 0:d53e9c6fc771 22 {
tomoya123 0:d53e9c6fc771 23 ite = 0;
tomoya123 0:d53e9c6fc771 24 while (gps.readable())
tomoya123 0:d53e9c6fc771 25 {
tomoya123 0:d53e9c6fc771 26 gps.getc();
tomoya123 0:d53e9c6fc771 27 ite++;
tomoya123 0:d53e9c6fc771 28 if(ite==100){break;};
tomoya123 0:d53e9c6fc771 29 }
tomoya123 0:d53e9c6fc771 30 return;
tomoya123 0:d53e9c6fc771 31 }
tomoya123 0:d53e9c6fc771 32 void HeptaGPS::gga_sensing(float *time, float *latitude, char *ns, float *longitude, char *ew, int *quality, int *stnum, float *hacu, float *altitude, char *aunit, int *gps_check)
tomoya123 0:d53e9c6fc771 33 {
tomoya123 0:d53e9c6fc771 34 int ite = 0;
tomoya123 0:d53e9c6fc771 35 while(gps.getc()!='$'){
tomoya123 0:d53e9c6fc771 36 ite++;
tomoya123 0:d53e9c6fc771 37 if(ite==10000) break;
tomoya123 0:d53e9c6fc771 38 }
tomoya123 0:d53e9c6fc771 39 for(int i=0; i<5; i++){
tomoya123 0:d53e9c6fc771 40 msg[i] = gps.getc();
tomoya123 0:d53e9c6fc771 41 }
tomoya123 0:d53e9c6fc771 42 if((msg[2]=='G')&(msg[3]=='G')&(msg[4]=='A')){
tomoya123 0:d53e9c6fc771 43 for(int j=0; j<6; j++){
tomoya123 0:d53e9c6fc771 44 if(j==0){
tomoya123 0:d53e9c6fc771 45 for(int i=5; i<256; i++){
tomoya123 0:d53e9c6fc771 46 msg[i] = gps.getc();
tomoya123 0:d53e9c6fc771 47 if(msg[i] == '\r') {
tomoya123 0:d53e9c6fc771 48 msg[i] = 0;
tomoya123 0:d53e9c6fc771 49 break;
tomoya123 0:d53e9c6fc771 50 }
tomoya123 0:d53e9c6fc771 51 }
tomoya123 0:d53e9c6fc771 52 }else{
tomoya123 0:d53e9c6fc771 53 for(int i=0; i<256; i++){
tomoya123 0:d53e9c6fc771 54 msgd[i] = gps.getc();
tomoya123 0:d53e9c6fc771 55 if(msgd[i] == '\r') {
tomoya123 0:d53e9c6fc771 56 break;
tomoya123 0:d53e9c6fc771 57 }
tomoya123 0:d53e9c6fc771 58 }
tomoya123 0:d53e9c6fc771 59 if((msgd[4]=='V')&(msgd[5]=='T')&(msgd[6]=='G')){
tomoya123 0:d53e9c6fc771 60 break;
tomoya123 0:d53e9c6fc771 61 }
tomoya123 0:d53e9c6fc771 62 }
tomoya123 0:d53e9c6fc771 63 }
tomoya123 0:d53e9c6fc771 64 if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c", time, latitude, ns, longitude, ew, quality, stnum, hacu, altitude, aunit) >= 1) {
tomoya123 0:d53e9c6fc771 65 if(!(quality)) {
tomoya123 0:d53e9c6fc771 66 //latitude(unit transformation)
tomoya123 0:d53e9c6fc771 67 *latitude=int(*latitude/100)+(*latitude-int(*latitude/100)*100)/60;
tomoya123 0:d53e9c6fc771 68 //longitude(unit transformation)
tomoya123 0:d53e9c6fc771 69 *longitude = int(*longitude/100)+(*longitude-int(*longitude/100)*100)/60;
tomoya123 0:d53e9c6fc771 70 *gps_check = 0;
tomoya123 0:d53e9c6fc771 71 } else {
tomoya123 0:d53e9c6fc771 72 //latitude(unit transformation)
tomoya123 0:d53e9c6fc771 73 *latitude=int(*latitude/100)+(*latitude-int(*latitude/100)*100)/60;
tomoya123 0:d53e9c6fc771 74 //longitude(unit transformation)
tomoya123 0:d53e9c6fc771 75 *longitude = int(*longitude/100)+(*longitude-int(*longitude/100)*100)/60;
tomoya123 0:d53e9c6fc771 76 *gps_check = 1;
tomoya123 0:d53e9c6fc771 77 }
tomoya123 0:d53e9c6fc771 78 }
tomoya123 0:d53e9c6fc771 79 else{
tomoya123 0:d53e9c6fc771 80 printf("No Data");
tomoya123 0:d53e9c6fc771 81 *gps_check = 2;
tomoya123 0:d53e9c6fc771 82 }
tomoya123 0:d53e9c6fc771 83 }
tomoya123 0:d53e9c6fc771 84 else{
tomoya123 0:d53e9c6fc771 85 *gps_check = 3;
tomoya123 0:d53e9c6fc771 86 }
tomoya123 0:d53e9c6fc771 87 }
tomoya123 0:d53e9c6fc771 88 void HeptaGPS::lat_log_sensing_u16(char *lat, char *log, int *dsize)
tomoya123 0:d53e9c6fc771 89 {
tomoya123 0:d53e9c6fc771 90 char gph1[8]={0x00},gph2[8]={0x00},gph3[8]={0x00},gph4[8]={0x00},gpt1[8]={0x00},gpt2[8]={0x00},gpt3[8]={0x00},gpt4[8]={0x00};
tomoya123 0:d53e9c6fc771 91 int i=0,j=0;
tomoya123 0:d53e9c6fc771 92 while (gps.readable()){
tomoya123 0:d53e9c6fc771 93 gps.getc();
tomoya123 0:d53e9c6fc771 94 }
tomoya123 0:d53e9c6fc771 95 loop:
tomoya123 0:d53e9c6fc771 96 while(gps.getc()!='$'){}
tomoya123 0:d53e9c6fc771 97 for(j=0;j<5;j++){
tomoya123 0:d53e9c6fc771 98 gps_data[1][j]=gps.getc();
tomoya123 0:d53e9c6fc771 99 }
tomoya123 0:d53e9c6fc771 100 if((gps_data[1][2]==0x52)&(gps_data[1][3]==0x4d)&(gps_data[1][4]==0x43)){
tomoya123 0:d53e9c6fc771 101 for(j=0;j<1;j++){
tomoya123 0:d53e9c6fc771 102 if(j==0){
tomoya123 0:d53e9c6fc771 103 i=0;
tomoya123 0:d53e9c6fc771 104 while((gps_data[j+1][i+5] = gps.getc()) != '\r'){
tomoya123 0:d53e9c6fc771 105 //pc.putc(gps_data[j+1][i+5]);
tomoya123 0:d53e9c6fc771 106 i++;
tomoya123 0:d53e9c6fc771 107 }
tomoya123 0:d53e9c6fc771 108 gps_data[j+1][i+5]='\0';
tomoya123 0:d53e9c6fc771 109 i=0;
tomoya123 0:d53e9c6fc771 110 //pc.printf("\n\r");
tomoya123 0:d53e9c6fc771 111 }
tomoya123 0:d53e9c6fc771 112 else{
tomoya123 0:d53e9c6fc771 113 while(gps.getc()!='$'){}
tomoya123 0:d53e9c6fc771 114 i=0;
tomoya123 0:d53e9c6fc771 115 while((gps_data[j+1][i] = gps.getc()) != '\r'){
tomoya123 0:d53e9c6fc771 116 //pc.putc(gps_data[j+1][i]);
tomoya123 0:d53e9c6fc771 117 i++;
tomoya123 0:d53e9c6fc771 118 }
tomoya123 0:d53e9c6fc771 119 gps_data[j+1][i]='\0';
tomoya123 0:d53e9c6fc771 120 i=0;
tomoya123 0:d53e9c6fc771 121 //pc.printf("\n\r");
tomoya123 0:d53e9c6fc771 122 }
tomoya123 0:d53e9c6fc771 123 }
tomoya123 0:d53e9c6fc771 124 }
tomoya123 0:d53e9c6fc771 125 else
tomoya123 0:d53e9c6fc771 126 {
tomoya123 0:d53e9c6fc771 127 goto loop;
tomoya123 0:d53e9c6fc771 128 }
tomoya123 0:d53e9c6fc771 129 if( sscanf(gps_data[1],"GPRMC,%f,%c,%f,%c,%f,%c,%f",&time,&statas,&hokui,&ns,&tokei,&ew,&vel) >= 1){
tomoya123 0:d53e9c6fc771 130 //hokui
tomoya123 0:d53e9c6fc771 131 d_hokui=int(hokui/100);
tomoya123 0:d53e9c6fc771 132 m_hokui=(hokui-d_hokui*100);
tomoya123 0:d53e9c6fc771 133 //m_hokui=(hokui-d_hokui*100)/60;
tomoya123 0:d53e9c6fc771 134 g_hokui=d_hokui+(hokui-d_hokui*100)/60;
tomoya123 0:d53e9c6fc771 135 sprintf( gph1, "%02X", (char(d_hokui)) & 0xFF);
tomoya123 0:d53e9c6fc771 136 sprintf( gph2, "%02X", (char(m_hokui)) & 0xFF);
tomoya123 0:d53e9c6fc771 137 sprintf( gph3, "%02X", (char((m_hokui-char(m_hokui))*100)) & 0xFF);
tomoya123 0:d53e9c6fc771 138 sprintf( gph4, "%02X", (char(((m_hokui-char(m_hokui))*100-char((m_hokui-char(m_hokui))*100))*100)) & 0xFF);
tomoya123 0:d53e9c6fc771 139
tomoya123 0:d53e9c6fc771 140 //tokei
tomoya123 0:d53e9c6fc771 141 d_tokei=int(tokei/100);
tomoya123 0:d53e9c6fc771 142 m_tokei=(tokei-d_tokei*100);
tomoya123 0:d53e9c6fc771 143 //m_tokei=(tokei-d_tokei*100)/60;
tomoya123 0:d53e9c6fc771 144 g_tokei=d_tokei+(tokei-d_tokei*100)/60;
tomoya123 0:d53e9c6fc771 145 sprintf( gpt1, "%02X", (char(d_tokei)) & 0xFF);
tomoya123 0:d53e9c6fc771 146 sprintf( gpt2, "%02X", (char(m_tokei)) & 0xFF);
tomoya123 0:d53e9c6fc771 147 sprintf( gpt3, "%02X", (char((m_tokei-char(m_tokei))*100)) & 0xFF);
tomoya123 0:d53e9c6fc771 148 sprintf( gpt4, "%02X", (char(((m_tokei-char(m_tokei))*100-char((m_tokei-char(m_tokei))*100))*100)) & 0xFF);
tomoya123 0:d53e9c6fc771 149 lat[0] = gph1[0];
tomoya123 0:d53e9c6fc771 150 lat[1] = gph1[1];
tomoya123 0:d53e9c6fc771 151 lat[2] = gph2[0];
tomoya123 0:d53e9c6fc771 152 lat[3] = gph2[1];
tomoya123 0:d53e9c6fc771 153 lat[4] = gph3[0];
tomoya123 0:d53e9c6fc771 154 lat[5] = gph3[1];
tomoya123 0:d53e9c6fc771 155 lat[6] = gph4[0];
tomoya123 0:d53e9c6fc771 156 lat[7] = gph4[1];
tomoya123 0:d53e9c6fc771 157 log[0] = gpt1[0];
tomoya123 0:d53e9c6fc771 158 log[1] = gpt1[1];
tomoya123 0:d53e9c6fc771 159 log[2] = gpt2[0];
tomoya123 0:d53e9c6fc771 160 log[3] = gpt2[1];
tomoya123 0:d53e9c6fc771 161 log[4] = gpt3[0];
tomoya123 0:d53e9c6fc771 162 log[5] = gpt3[1];
tomoya123 0:d53e9c6fc771 163 log[6] = gpt4[0];
tomoya123 0:d53e9c6fc771 164 log[7] = gpt4[1];
tomoya123 0:d53e9c6fc771 165 }
tomoya123 0:d53e9c6fc771 166 *dsize = 8;
tomoya123 0:d53e9c6fc771 167 }