⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gps.c

📁 port of ARM to NOkia 3310 display
💻 C
字号:
/* 
	GPS.c
*/

#include "globals.h"





/* and now a mutex to protect calls to the C library */
cyg_mutex_t    cliblock;




//GPS MAIN FUNCTION
void GPS(void)
{
        //GPS data validity?      
        switch(GPRMC[17])
        {
            case 'A':   
            {
                 //Data from GPRMC:
                 strncpy(&time_stamp[0], &GPRMC[7], 6); time_stamp[6]='\0';
                 strncpy(&current_latitude[0], &GPRMC[19], 10 ); current_latitude[10]='\0';
                 strncpy(&current_longitude[0], &GPRMC[32], 11 ); current_longitude[11]='\0';
                 
                 //Data from GPGGA:
                 strncpy(&current_altitude[0], &GPGGA[53], 5 ); current_altitude[5]='\0';
                 
                 		 
		 //GPS IS CONNECTED
		 mode=0x01;
		                  
                 break;
            } 
            case 'V': mode = 0x00; break;
            default:   mode = 0x02; break;
        }
    
        //SEND
        cyg_mutex_lock(&cliblock); 
        {
           printf("%s", GPRMC);
        }
        cyg_mutex_unlock(&cliblock);
       
        free(GPRMC); free(GPGGA);
 
        return;
}



//CONVERT LONGITUDE & LATITUDE in UTM DATUM
void UTM(void)
{
   //UTM DATUM  
   //X
   f_temp = atof(current_latitude);
   f_syousu = modf((f_temp/100),&f_seisu);
   offset_y = f_seisu*36000;
   offset_y += f_syousu*60000;
   //Y	
   f_temp = atof(current_longitude);
   f_syousu = modf((f_temp/100),&f_seisu);
   offset_x = f_seisu*36000;
   offset_x += f_syousu*60000;
   
   // SEND UTM DATUM
   cyg_mutex_lock(&cliblock); 
   {
       printf("%s", GPRMC);
   }
   cyg_mutex_unlock(&cliblock);
   
   //clear X Y DATUM
   //offset_x = offset_y = 0x00;

   return;
}





/*
void gps_txt_mode(void)
{

    //Txt Mode variables
    unsigned char latitude[3][6], longitude[3][6];
    
    unsigned char count;
    
                     cls();
             	       //STAMP FEELD
             	       LcdLine(0,8,83,8,PIXEL_ON);
	              LcdUpdate();
                
                     //lcd_line 1 -> SAT <-
                     nokia_gotoxy(0,0);nokia_printmessage("5x ",0); 
                     for(count=0;count != 15;count++)
	         	{
	     	               bytefornokia=sat[count];
	                      nokia_write_data();
	         	}
	         	nokia_printmessage(" GPS TxT",0);
                     // antena
	         	nokia_gotoxy(75,0);
	         	for(count=0;count != 8;count++)
	         	{
	     	               bytefornokia=antena[count];
	                      nokia_write_data();
	         	}
	
	         	//Latitude calculation               
                     strncpy(&latitude[0][0], &current_latitude[0], 2); latitude[0][2]='\0';
                     strncpy(&latitude[1][0], &current_latitude[2], 2); latitude[1][2]='\0';
                     strncpy(&latitude[2][0], &current_latitude[5], 5); latitude[2][5]='\0';
               
                     //lcd_line 3 
                     nokia_gotoxy(0,2); 
                     nokia_printmessage("N ",0); 
                     //GRAD
                     nokia_printmessage(&latitude[0][0],0); nokia_printchar(0x00,0); 
                     //MINUTES
                     nokia_printmessage(" ",0);nokia_printmessage(&latitude[1][0],0);
                     nokia_printmessage(" ",0);nokia_printmessage(&latitude[2][0],0);
                
                     //Longitude calculation
                     strncpy(&longitude[0][0], &current_longitude[1], 2); longitude[0][2]='\0';
                     strncpy(&longitude[1][0], &current_longitude[3], 2); longitude[1][2]='\0';
                     strncpy(&longitude[2][0], &current_longitude[6], 5); longitude[2][5]='\0';
               
                     //lcd_line 4
                     nokia_gotoxy(0,3);
                     nokia_printmessage("E ",0);
                     //GRAD
                     nokia_printmessage(&longitude[0][0],0); nokia_printchar(0x00,0); 
                     //MINUTES
                     nokia_printmessage(" ",0);nokia_printmessage(&longitude[1][0],0);
                     nokia_printmessage(" ",0);nokia_printmessage(&longitude[2][0],0);
              
                     //lcd_line 5
                     nokia_gotoxy(0,4);
                     nokia_printmessage("M ",0);
                     nokia_printmessage(&current_altitude[0],0);
                     nokia_printmessage(" [m]",0);
                                 
                     
    return;
}
*/





/*
*unsigned char lt_rtc(void)
{
    unsigned char RTCHour[3], RTCMin[3], RTCSec[3];
    unsigned char *temp;
    
    // Time calculation
    // from ASCII to Dec                
    if(time_stamp!=NULL)
    {
       strncpy(&RTCHour[0], &time_stamp[0], 2); RTCHour[2]='\0';
       strncpy(&RTCMin[0], &time_stamp[2], 2); RTCMin[2]='\0';
       strncpy(&RTCSec[0], &time_stamp[4], 2); RTCSec[2]='\0';
       Hour=atoi(&RTCHour[0]); Min=atoi(&RTCMin[0]); Sec=atoi(&RTCSec[0]);
       //+2h LT
       Hour=Hour+2; 
       //lcd_line 6
       nokia_gotoxy(0,5); nokia_printmessage("T ",0); 
       LcdDec(Hour); nokia_printmessage(":",0); 
       if(Min<10) LcdDec(0);
       LcdDec(Min); nokia_printmessage(":",0); 
       if(Sec<10) LcdDec(0);
       LcdDec(Sec);
       nokia_printmessage(" [LT]",0);
   }
   return;
}
*/







void gps_latitude(void)
{
    unsigned char temp[12];
    unsigned char latitude[3][6];
    
    if(mode==1)
    {
         //Latitude calculation               
         strncpy(&latitude[0][0], &current_latitude[0], 2); latitude[0][2]='\0';
         strncpy(&latitude[1][0], &current_latitude[2], 2); latitude[1][2]='\0';
         strncpy(&latitude[2][0], &current_latitude[5], 5); latitude[2][5]='\0';
    
         strncpy(&temp[0], &latitude[0][0], 2);
         strncat(temp, " ",1);
         strncat(temp, &latitude[1][0],2);
         strncat(temp, " ",1);
         strncat(temp, &latitude[2][0],5);
         temp[11]='\0';
    }
    else
    {
         strncpy(&temp[0], "Bad signal",10);temp[10]='\0'; 
    }
    Draw_Window(0,23,83,22,"Latitude Nord",&temp[0]);
    
    return;
}







void gps_gmt(void)
{
    unsigned char temp[9];
    unsigned char RTCHour[3], RTCMin[3], RTCSec[3];
    
       
   // Time calculation
   strncpy(&RTCHour[0], &time_stamp[0], 2); RTCHour[2]='\0';
   strncpy(&RTCMin[0], &time_stamp[2], 2); RTCMin[2]='\0';
   strncpy(&RTCSec[0], &time_stamp[4], 2); RTCSec[2]='\0';
   strncpy(&temp[0],RTCHour,2);
   strcat(temp,":");
   strcat(temp,RTCMin);
   strcat(temp,":");
   strcat(temp,RTCSec);
   temp[8]='\0';
   
   //under construction
   Draw_Window(7,20,70,26,"GMT"," --:--:--");
   
   return;
}







void gps_status(void)
{
    switch(mode)
    {
         case 0: Draw_Window(5,5,73,26,"System","GPS failure"); break;
         case 1: Draw_Window(5,5,73,26,"System","GPS receive");      break;
         case 2: Draw_Window(5,5,73,26,"System","Command msg"); break;
    }
    return;
}


//eof

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -