Ivan Stoev / HeptaCamera_GPS

Dependents:   3daf572bcae1 Team Team01_HEPTA_Trainig

Fork of HeptaCamera_GPS by HEPTA-Sat Training 2017~2018

Files at this revision

API Documentation at this revision

Comitter:
hepta2ume
Date:
Mon Jul 24 05:51:24 2017 +0000
Parent:
3:12659e671bad
Child:
5:50a03fcd9cc0
Commit message:
Hepta_assembly

Changed in this revision

HeptaSerial.cpp Show annotated file Show diff for this revision Revisions of this file
HeptaSerial.h Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/HeptaSerial.h	Fri Jul 21 10:35:56 2017 +0000
+++ b/HeptaSerial.h	Mon Jul 24 05:51:24 2017 +0000
@@ -4,14 +4,15 @@
 #ifndef HEPTA_SERIAL_H
 #define HEPTA_SERIAL_H
 
-class HeptaSerial {
+class HeptaSerial
+{
 public:
 
     enum JpegResolution {
-         JpegResolution80x64 = 0x01,   // unofficial
-         JpegResolution160x128 = 0x03, // unofficial
-         JpegResolution320x240 = 0x05, // QVGA
-         JpegResolution640x480 = 0x07  // VGA
+        JpegResolution80x64 = 0x01,   // unofficial
+        JpegResolution160x128 = 0x03, // unofficial
+        JpegResolution320x240 = 0x05, // QVGA
+        JpegResolution640x480 = 0x07  // VGA
     };
 
     enum ErrorNumber {
@@ -30,7 +31,7 @@
         Baud115200 = 0x04,
         Baud57600  = 0x05,
         Baud28800  = 0x06,
-        Baud14400  = 0x07  // Default. 
+        Baud14400  = 0x07  // Default.
     };
 
     enum ResetType {
@@ -38,7 +39,7 @@
         High  = 0xff
     };
 
-    HeptaSerial(PinName tx, PinName rx, int baud = 14400);
+    HeptaSerial(PinName tx, PinName rx);
 
     ~HeptaSerial();
 
@@ -52,22 +53,34 @@
     void test_jpeg_snapshot_picture(int CAPTURE_FRAMES);
     void test_jpeg_snapshot_data(int CAPTURE_FRAMES);
     void jpeg_callback(char *buf, size_t siz);
-    
-    
-    
-    
+    char getc();
+    int  readable();
+    void flushSerialBuffer(void);
+    void 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);
+    void lat_log_sensing_u16(char *lat, char *log, int *dsize);
+
 private:
     SerialBuffered serial;
     static const int COMMAND_LENGTH = 6;
     static const int SYNCMAX = 60;
     static const int packageSize = 256;
     //static const int CAPTURE_FRAMES = 3;
-    
+
+    char msg[256],msgd[256];
+    int i,ite,rlock,stn;
+    char c;
+    char gps_data[7][1000];
+    char ns,ew,statas;
+    float time,hokui,tokei,vel;
+    float g_hokui,g_tokei;
+    float d_hokui,m_hokui,d_tokei,m_tokei;
+    int h_time,m_time,s_time;
+
     ErrorNumber sendInitial(Baud band, JpegResolution jr);
     ErrorNumber sendGetPicture(void);
-    ErrorNumber sendSnapshot(void);    
+    ErrorNumber sendSnapshot(void);
     ErrorNumber sendSetPackageSize(uint16_t packageSize);
-    ErrorNumber sendReset(ResetType specialReset);  
+    ErrorNumber sendReset(ResetType specialReset);
     ErrorNumber recvData(uint32_t *length);
     ErrorNumber sendSync();
     ErrorNumber recvSync();
@@ -79,5 +92,4 @@
     bool waitRecv();
     bool waitIdle();
 };
-
 #endif