test
Dependents: HEPTA_assembly template HEPTA_GS
Diff: HeptaSerial.cpp
- Revision:
- 4:57c7f33a3621
- Parent:
- 3:12659e671bad
- Child:
- 5:50a03fcd9cc0
--- a/HeptaSerial.cpp Fri Jul 21 10:35:56 2017 +0000 +++ b/HeptaSerial.cpp Mon Jul 24 05:51:24 2017 +0000 @@ -12,7 +12,7 @@ * @param rx A pin for receive. * @param baud Baud rate. (Default is Baud14400.) */ -HeptaSerial::HeptaSerial(PinName tx, PinName rx, int baud) : serial(tx, rx) +HeptaSerial::HeptaSerial(PinName tx, PinName rx) : serial(tx, rx) { //serial.baud(baud); } @@ -673,4 +673,168 @@ printf("[FAIL] : Camera::init (Error=%02X)\r\n", (int)err); } +} + +//*********************serial*********************// +char HeptaSerial::getc() +{ + serial.setTimeout(999); + c = serial.getc(); + return c; +} +int HeptaSerial::readable() +{ + serial.setTimeout(999); + i = serial.readable(); + return i; +} +void HeptaSerial::flushSerialBuffer(void) +{ + serial.setTimeout(999); + ite = 0; + while (serial.readable()) + { + serial.getc(); + ite++; + if(ite==100){break;}; + } + return; +} +void HeptaSerial::gga_sensing(float *time, float *latitude, char *ns, float *longitude, char *ew, int *quality, int *stnum, float *hacu, float *altitude, char *aunit, int *serial_check) +{ + serial.setTimeout(999); + int ite = 0; + while(serial.getc()!='$'){ + ite++; + if(ite==10000) break; + } + for(int i=0; i<5; i++){ + msg[i] = serial.getc(); + } + if((msg[2]=='G')&(msg[3]=='G')&(msg[4]=='A')){ + for(int j=0; j<6; j++){ + if(j==0){ + for(int i=5; i<256; i++){ + msg[i] = serial.getc(); + if(msg[i] == '\r') { + msg[i] = 0; + break; + } + } + }else{ + for(int i=0; i<256; i++){ + msgd[i] = serial.getc(); + if(msgd[i] == '\r') { + break; + } + } + if((msgd[4]=='V')&(msgd[5]=='T')&(msgd[6]=='G')){ + break; + } + } + } + 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) { + if(!(quality)) { + //latitude(unit transformation) + *latitude=int(*latitude/100)+(*latitude-int(*latitude/100)*100)/60; + //longitude(unit transformation) + *longitude = int(*longitude/100)+(*longitude-int(*longitude/100)*100)/60; + *serial_check = 0; + } else { + //latitude(unit transformation) + *latitude=int(*latitude/100)+(*latitude-int(*latitude/100)*100)/60; + //longitude(unit transformation) + *longitude = int(*longitude/100)+(*longitude-int(*longitude/100)*100)/60; + *serial_check = 1; + } + } + else{ + printf("No Data"); + *serial_check = 2; + } + } + else{ + *serial_check = 3; + } +} +void HeptaSerial::lat_log_sensing_u16(char *lat, char *log, int *dsize) +{ + serial.setTimeout(999); + 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}; + int i=0,j=0; + while (serial.readable()){ + serial.getc(); + } + loop: + while(serial.getc()!='$'){} + for(j=0;j<5;j++){ + gps_data[1][j]=serial.getc(); + } + if((gps_data[1][2]==0x52)&(gps_data[1][3]==0x4d)&(gps_data[1][4]==0x43)){ + for(j=0;j<1;j++){ + if(j==0){ + i=0; + while((gps_data[j+1][i+5] = serial.getc()) != '\r'){ + //pc.putc(gps_data[j+1][i+5]); + i++; + } + gps_data[j+1][i+5]='\0'; + i=0; + //pc.printf("\n\r"); + } + else{ + while(serial.getc()!='$'){} + i=0; + while((gps_data[j+1][i] = serial.getc()) != '\r'){ + //pc.putc(gps_data[j+1][i]); + i++; + } + gps_data[j+1][i]='\0'; + i=0; + //pc.printf("\n\r"); + } + } + } + else + { + goto loop; + } + if( sscanf(gps_data[1],"GPRMC,%f,%c,%f,%c,%f,%c,%f",&time,&statas,&hokui,&ns,&tokei,&ew,&vel) >= 1){ + //hokui + d_hokui=int(hokui/100); + m_hokui=(hokui-d_hokui*100); + //m_hokui=(hokui-d_hokui*100)/60; + g_hokui=d_hokui+(hokui-d_hokui*100)/60; + sprintf( gph1, "%02X", (char(d_hokui)) & 0xFF); + sprintf( gph2, "%02X", (char(m_hokui)) & 0xFF); + sprintf( gph3, "%02X", (char((m_hokui-char(m_hokui))*100)) & 0xFF); + sprintf( gph4, "%02X", (char(((m_hokui-char(m_hokui))*100-char((m_hokui-char(m_hokui))*100))*100)) & 0xFF); + + //tokei + d_tokei=int(tokei/100); + m_tokei=(tokei-d_tokei*100); + //m_tokei=(tokei-d_tokei*100)/60; + g_tokei=d_tokei+(tokei-d_tokei*100)/60; + sprintf( gpt1, "%02X", (char(d_tokei)) & 0xFF); + sprintf( gpt2, "%02X", (char(m_tokei)) & 0xFF); + sprintf( gpt3, "%02X", (char((m_tokei-char(m_tokei))*100)) & 0xFF); + sprintf( gpt4, "%02X", (char(((m_tokei-char(m_tokei))*100-char((m_tokei-char(m_tokei))*100))*100)) & 0xFF); + lat[0] = gph1[0]; + lat[1] = gph1[1]; + lat[2] = gph2[0]; + lat[3] = gph2[1]; + lat[4] = gph3[0]; + lat[5] = gph3[1]; + lat[6] = gph4[0]; + lat[7] = gph4[1]; + log[0] = gpt1[0]; + log[1] = gpt1[1]; + log[2] = gpt2[0]; + log[3] = gpt2[1]; + log[4] = gpt3[0]; + log[5] = gpt3[1]; + log[6] = gpt4[0]; + log[7] = gpt4[1]; + } + *dsize = 8; } \ No newline at end of file