Xbee CountUp

Dependencies:   mbed

Fork of HeptaXbee_CountUp by 智也 大野

Committer:
tomoya123
Date:
Fri Dec 09 04:58:00 2016 +0000
Revision:
0:0a7fa0911e6c
Xbee CountUP

Who changed what in which revision?

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