0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

(win)C、C++處理文件名稱

DS小龍哥-嵌入式技術 ? 來源:DS小龍哥-嵌入式技術 ? 作者:DS小龍哥-嵌入式技 ? 2022-09-09 11:45 ? 次閱讀

一. 前言

環(huán)境: windows、純C\C++環(huán)境編程。

在文件、目錄處理時,經常需要對文件名稱、目錄名稱、文件后綴等數(shù)據(jù)做處理。在linux下比較方便。有basename可以直接調用,獲取文件名稱。windows下C、C++標準庫里沒有現(xiàn)成的函數(shù)可以直接提取文件名稱、目錄名稱、剔除文件路徑,下面就自己實現(xiàn)了幾個方式完成文件名提取。

二. 實現(xiàn)代碼-純C/C++

示例代碼:

string path = "C:\Users\Administ.1.2.3rator\Desktop\text\data.22.txt";
    //string path = "http://cqpc:8001/Uploads/1/220512030806054762.mp4";
    //1.獲取不帶路徑的文件名
    string::size_type iPos;
    if (strstr(path.c_str(), ""))
    {
        iPos = path.find_last_of('\') + 1;
    }
    else
    {
        iPos = path.find_last_of('/') + 1;
    }
    
    string filename = path.substr(iPos, path.length() - iPos);
    cout <<"獲取不帶路徑的文件名:"<

返回結果:

獲取不帶路徑的文件名:data.22.txt
獲取不帶后綴的文件名:data.22
獲取后綴名:txt
基本名稱:data
復制代碼

三. C語言字符串處理案例

1. 計算空格、大小寫字母

從鍵盤上輸入一個字符串, 計算字符串里有多少個空格、小寫字母、大寫字母、數(shù)字。

#include  //標準輸入輸出
#include  //字符串處理頭文件
int main(int argc,char **argv)
{
    int len=0;
    int i;
    char str[100];
    int cnt[5]={0}; //初始化賦值
    //scanf("%s",str); //從鍵盤上錄入字符串,字符串結尾: '\0'
    //gets(str);    //從鍵盤上錄入字符串
    fgets(str,100,stdin); //從鍵盤上錄入字符串 (標準輸入)
    
    //空格、小寫字母、大寫字母、數(shù)字 其他數(shù)據(jù)
    
    /*1. 計算字符串的長度*/
    while(str[len]!='\0')len++;
    printf("len1=%d\n",len);
    printf("len2=%d\n",strlen(str)); //計算字符串長度
    
    /*2. 處理字符串*/
    for(i=0;i='a'&&str[i]<='z')cnt[1]++;
?        else if(str[i]>='A'&&str[i]<='Z')cnt[2]++;
?        else if(str[i]>='0'&&str[i]<='9')cnt[3]++;
?        else cnt[4]++;
?    }
?    
?    /*3. 打印結果*/
?    printf("空格:%d\n",cnt[0]);
?    printf("小寫:%d\n",cnt[1]);
?    printf("大寫:%d\n",cnt[2]);
?    printf("數(shù)字:%d\n",cnt[3]);
?    printf("其他:%d\n",cnt[4]);
?    return 0;
?}
復制代碼

2. 字符串排序

示例:
#include  //標準輸入輸出
#include  //字符串處理頭文件
?
int main(int argc,char **argv)
{
    int len=0;
    int i,j;
    char tmp;
    char str[100];
    fgets(str,100,stdin); //從鍵盤上錄入字符串 (標準輸入)
        
    /*1. 計算字符串的長度*/
    len=strlen(str); //計算字符串長度
    
    /*2. 字符串排序*/
    for(i=0;i;i++)>

3. 字符串插入

字符串插入: “1234567890” 在第2個位置后面插入”ABC” 最終結果: “12ABC34567890”

#include  //標準輸入輸出
#include  //字符串處理頭文件
int main(int argc,char **argv)
{
    int i,j;
    int src_len;
    int new_len;
    /*
    123456789
    12   3456789
    */
    char src_str[100]="123456789"; 
    char new_str[]="abcd";
    int addr=2; //插入的位置
    
    /*1. 計算字符串的長度*/
    src_len=strlen(src_str); //"123"
    new_len=strlen(new_str);
    
    /*2. 字符串移動*/
    for(i=src_len-1;i>addr-1;i--)
    {
        src_str[i+new_len]=src_str[i]; //向后移動 new_len
    }
    
    /*3. 插入新的數(shù)據(jù)*/
    for(i=0;i;i++)src_str[addr+i]=new_str[i];>

5. 字符串刪除

字符串刪除: “1234567890” 刪除”456” 最終結果: “1237890”

示例:
#include  //標準輸入輸出
#include  //字符串處理頭文件
?
int main(int argc,char **argv)
{
    char src_str[100];
    char del_str[10];
    int src_len=0,del_len=0;
    int i,j;
    int cnt=0;
    
    /*1. 錄入字符串*/
    printf("輸入源字符串:"); //123dufvdfv123dfljvb
    fgets(src_str,100,stdin); //從鍵盤上錄入源字符串
    
    printf("輸入查找的字符串:"); //123
    fgets(del_str,10,stdin); //從鍵盤上錄入源字符串
    
    /*2. 計算長度*/
    src_len=strlen(src_str);
    src_str[src_len-1]='\0';
    src_len-=1; //src_len=src_len-1;
    
    del_len=strlen(del_str); //"123\n" =4
    del_str[del_len-1]='\0';
    del_len-=1;
    
    printf("源字符串:%s,%d\n",src_str,src_len);
    printf("刪除字符串:%s,%d\n",del_str,del_len);
?
    /*3. 查找*/
    for(i=0;i+1;i++)>

6. 字符串替換

字符串”1234567890”
將456替換為”888”
 最終: “1238887890”
需要考慮3種情況
復制代碼

7. 字符串轉整數(shù)。

從鍵盤上輸入一個字符串”12345”, 得到整數(shù): 12345;

#include  //標準輸入輸出
#include  //字符串處理頭文件
int string_to_int(char str[]);
int main(int argc,char **argv)
{
    int data;
    char str[]="125abcd";
    data=string_to_int(str);
    printf("data=%d\n",data);
    return 0;
}
?
/*
函數(shù)功能: 字符串轉為整數(shù)
字符轉為整數(shù): -48 或者 -'0'
?
1234
*/
int string_to_int(char str[])
{
    int value=0; //存放轉換之后的結果
    int i=0;
    while((str[i]!='\0')&&(str[i]>='0'&&str[i]<='9'))
?    {
?        value*=10;
?        value+=str[i]-'0';
?        i++;
?    }   
?    return value;
?}
復制代碼

四、GPS解碼示例-字符串處理

#include 
#include 
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;

const u8 GPS_Info_1[]="\
$GNGGA,114955.000,2842.4158,N,11549.5439,E,1,05,3.8,54.8,M,0.0,M,,*4F\
$GNGLL,2842.4158,N,11549.5439,E,114955.000,A,A*4D\
$GPGSA,A,3,10,31,18,,,,,,,,,,5.7,3.8,4.2*37\
$BDGSA,A,3,07,10,,,,,,,,,,,5.7,3.8,4.2*2A\
$GPGSV,3,1,10,10,49,184,42,12,16,039,,14,54,341,,18,22,165,23*7B\
$GPGSV,3,2,10,22,11,318,,25,51,055,,26,24,205,,29,13,110,*7C\
$GPGSV,3,3,10,31,50,287,36,32,66,018,*7F\
$BDGSV,1,1,04,03,,,07,05,,,29,07,79,246,33,10,52,232,19*62\
$GNRMC,114955.000,A,2842.4158,N,11549.5439,E,0.00,44.25,061117,,,A*4D\
$GNVTG,44.25,T,,M,0.00,N,0.00,K,A*14\
$GNZDA,114955.000,06,11,2017,00,00*47\
$GPTXT,01,01,01,ANTENNA OK*35";

const u8 GPS_Info_2[]="\
$GPGSV,3,2,10,20,16,138,,21,27,204,,24,39,040,26,25,35,145,22*7B\
$GPGSV,3,3,10,31,13,226,20,32,33,300,23*7F\
$BDGSV,2,1,08,03,,,31,04,,,31,06,65,033,24,10,,,31*54\
$BDGSV,2,2,08,11,,,30,12,,,30,13,,,29,15,,,31*6C\
$GNRMC,144513.000,A,2856.3560,N,11524.5587,E,1.48,292.74,230817,,,A*7B\
$GNVTG,292.74,T,,M,1.48,N,2.73,K,A*22\
$GNZDA,144513.000,23,08,2017,00,00*43\
$GPTXT,01,01,01,ANTENNA OK*35\
$GNGGA,144514.000,2856.3563,N,11524.5596,E,1,06,4.0,-13.0,M,0.0,M,,*68\
$GNGLL,2856.3563,N,11524.5596,E,144514.000,A,A*40\
$GPGSA,A,3,15,24,12,18,25,,,,,,,,6.7,4.0,5.3*3E\
$BDGSA,A,3,06,,,,,,,,,,,,6.7,4.0,5.3*26\
";

#pragma pack(1)    /* 必須在結構體定義之前使用,這是為了讓結構體中各成員按1字節(jié)對齊 */
//美國GPS衛(wèi)星信息
typedef struct
{
	u8 num;		//衛(wèi)星編號
	u8 eledeg;	//衛(wèi)星仰角
	u16 azideg;	//衛(wèi)星方位角
	u8 sn;		//信噪比		   
}nmea_slmsg;

//北斗衛(wèi)星信息
typedef struct
{
	u8 beidou_num;		//衛(wèi)星編號
	u8 beidou_eledeg;	//衛(wèi)星仰角
	u16 beidou_azideg;	//衛(wèi)星方位角
	u8 beidou_sn;		//信噪比		   
}beidou_nmea_slmsg;

//UTC時間信息
typedef struct
{
	u16 year;	//年份
	u8 month;	//月份
	u8 date;	//日期
	u8 hour; 	//小時
	u8 min; 	//分鐘
	u8 sec; 	//秒鐘
}nmea_utc_time;

//GPS協(xié)議解析后數(shù)據(jù)存放結構體
 typedef struct
{
	u8 svnum;					//可見GPS衛(wèi)星數(shù)
	u8 beidou_svnum;			//可見GPS衛(wèi)星數(shù)
	nmea_slmsg slmsg[12];		//最多12顆GPS衛(wèi)星
	beidou_nmea_slmsg beidou_slmsg[12];		//暫且算最多12顆北斗衛(wèi)星
	nmea_utc_time utc;			//UTC時間
	u32 latitude;				//緯度 分擴大100000倍,實際要除以100000
	u8 nshemi;					//北緯/南緯,N:北緯;S:南緯				  
	u32 longitude;			    //經度 分擴大100000倍,實際要除以100000
	u8 ewhemi;					//東經/西經,E:東經;W:西經
	u8 gpssta;					//GPS狀態(tài):0,未定位;1,非差分定位;2,差分定位;6,正在估算.				  
	u8 posslnum;				//用于定位的GPS衛(wèi)星數(shù),0~12.
	u8 possl[12];				//用于定位的衛(wèi)星編號
	u8 fixmode;					//定位類型:1,沒有定位;2,2D定位;3,3D定位
	u16 pdop;					//位置精度因子 0~500,對應實際值0~50.0
	u16 hdop;					//水平精度因子 0~500,對應實際值0~50.0
	u16 vdop;					//垂直精度因子 0~500,對應實際值0~50.0 

	int altitude;			 	//海拔高度,放大了10倍,實際除以10.單位:0.1m	 
	u16 speed;					//地面速率,放大了1000倍,實際除以10.單位:0.001公里/小時	 
}GPS_Msg;

u8 GPS_GetCommaOffset(u8 *buf,u8 cnt);
void GPS_MsgShow(void);
u8 GPS_GetCommaOffset(u8 *buf,u8 cnt);
void GPS_GPGSV_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf);
void GPS_GNVTG_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf);
void GPS_GNRMC_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf);
void GPS_GNGSA_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf);
void GPS_BDGSV_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf);
void GPS_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf);
GPS_Msg GPS_DecodeInfo; //存放GPS解碼信息

int main()
{
	GPS_InfoGet(&GPS_DecodeInfo,GPS_Info_2);
	GPS_MsgShow();
	return 0;
}

const u8*fixmode_tbl[4]={"失敗","失敗"," 2D "," 3D "};	//fix mode字符串
u8 dtbuf[50];   										//打印緩存器

/*
函數(shù)功能:顯示GPS定位信息
*/
void GPS_MsgShow(void)
{
	float tp;
	tp=GPS_DecodeInfo.longitude;
	sprintf((char *)dtbuf,"經度:%.5f %1c",tp/=100000,GPS_DecodeInfo.ewhemi);	//得到經度字符串
	printf("%s\r\n",dtbuf);
	tp=GPS_DecodeInfo.latitude;
	sprintf((char *)dtbuf,"緯度:%.5f %1c",tp/=100000,GPS_DecodeInfo.nshemi);	//得到緯度字符串
	printf("%s\r\n",dtbuf);
	tp=GPS_DecodeInfo.altitude;
	sprintf((char *)dtbuf,"高度:%.1fm",tp/=10);	    			//得到高度字符串
	printf("%s\r\n",dtbuf);
	tp=GPS_DecodeInfo.speed;
	sprintf((char *)dtbuf,"速度:%.3fkm/h",tp/=1000);		    		//得到速度字符串	 
	printf("%s\r\n",dtbuf);
	if(GPS_DecodeInfo.fixmode<=3)														//定位狀態(tài)
	{
		sprintf((char *)dtbuf,"定位模式:%s",fixmode_tbl[GPS_DecodeInfo.fixmode]);
		printf("%s\r\n",dtbuf);
	}
	sprintf((char *)dtbuf,"GPS+BD 定位的GPS衛(wèi)星數(shù):%02d",GPS_DecodeInfo.posslnum);	 		//用于定位的GPS衛(wèi)星數(shù)
	printf("%s\r\n",dtbuf);
	sprintf((char *)dtbuf,"GPS 可見GPS衛(wèi)星數(shù):%02d",GPS_DecodeInfo.svnum%100);	 		//可見GPS衛(wèi)星數(shù)
	printf("%s\r\n",dtbuf);

	sprintf((char *)dtbuf,"BD 可見北斗衛(wèi)星數(shù):%02d",GPS_DecodeInfo.beidou_svnum%100);	 		//可見北斗衛(wèi)星數(shù)
	printf("%s\r\n",dtbuf);

	sprintf((char *)dtbuf,"UTC日期:%04d/%02d/%02d   ",GPS_DecodeInfo.utc.year,GPS_DecodeInfo.utc.month,GPS_DecodeInfo.utc.date);	//顯示UTC日期
	printf("%s\r\n",dtbuf);
	sprintf((char *)dtbuf,"顯示UTC時間:%02d:%02d:%02d   ",GPS_DecodeInfo.utc.hour,GPS_DecodeInfo.utc.min,GPS_DecodeInfo.utc.sec);	//顯示UTC時間
	printf("%s\r\n",dtbuf);
}


/*
函數(shù)功能:從buf里面得到第cnt個逗號所在的位置
返 回 值:0~254,代表逗號所在位置的偏移.
255,代表不存在第cnt個逗號
*/
u8 GPS_GetCommaOffset(u8 *buf,u8 cnt)
{
	u8 *p=buf;
	while(cnt)
	{
		if(*buf=='*'||*buf<' '||*buf>'z')return 255;//遇到'*'或者非法字符,則不存在第cx個逗號
		if(*buf==',')cnt--;
		buf++;
	}
	return buf-p; //計算偏移量
}


/*
函數(shù)功能:m^n函數(shù)
返 回 值:m^n次方.
*/
u32 GPS_GetPow(u8 m,u8 n)
{
	u32 tmp=1;
	while(n--)tmp*=m;
	return tmp;
}


/*
函數(shù)功能:str轉換為數(shù)字,以','或者'*'結束
函數(shù)參數(shù):buf:數(shù)字存儲區(qū)
		 dx:小數(shù)點位數(shù),返回給調用函數(shù)
返 回 值:轉換后的整數(shù)數(shù)值
*/
int GPS_StrtoNum(u8 *buf,u8*dx)
{
	u8 *p=buf;
	u32 ires=0,fres=0;
	u8 ilen=0,flen=0,i;
	u8 mask=0;
	int res;
	while(1) //得到整數(shù)和小數(shù)的長度
	{
		if(*p=='-'){ mask|=0X02; p++; }//是負數(shù)
		if(*p==','||(*p=='*'))break;//遇到結束了
		if(*p=='.'){ mask|=0X01; p++; }//遇到小數(shù)點了
		else if(*p>'9'||(*p<'0'))	//有非法字符
		{
			ilen=0;
			flen=0;
			break;
		}
		if(mask&0X01)flen++;
		else ilen++;
		p++;
	}
	if(mask&0X02)buf++;	//去掉負號
	for(i=0; i5)flen=5;	//最多取5位小數(shù)
	*dx=flen;	 		//小數(shù)點位數(shù)
	for(i=0; isvnum=GPS_StrtoNum(p1+posx,&dx);
	for(i=0; islmsg[slx].num=GPS_StrtoNum(p1+posx,&dx);	//得到衛(wèi)星編號
			else break;
			posx=GPS_GetCommaOffset(p1,5+j*4);
			if(posx!=0XFF)GPS_DecodeInfo->slmsg[slx].eledeg=GPS_StrtoNum(p1+posx,&dx);//得到衛(wèi)星仰角 
			else break;
			posx=GPS_GetCommaOffset(p1,6+j*4);
			if(posx!=0XFF)GPS_DecodeInfo->slmsg[slx].azideg=GPS_StrtoNum(p1+posx,&dx);//得到衛(wèi)星方位角
			else break;
			posx=GPS_GetCommaOffset(p1,7+j*4);
			if(posx!=0XFF)GPS_DecodeInfo->slmsg[slx].sn=GPS_StrtoNum(p1+posx,&dx);	//得到衛(wèi)星信噪比
			else break;
			slx++;
		}
		p=p1+1;//切換到下一個GPGSV信息
	}
}


/*
函數(shù)功能:分析BDGSV信息
函數(shù)參數(shù):GPS_DecodeInfo:nmea信息結構體
		  buf:接收到的GPS數(shù)據(jù)緩沖區(qū)首地址
*/
void GPS_BDGSV_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf)
{
	u8 *p,*p1,dx;
	u8 len,i,j,slx=0;
	u8 posx;
	p=buf;
	p1=(u8*)strstr((const char *)p,"$BDGSV");
	if(!p1)return; //沒有查找成功
	len=p1[7]-'0';								//得到BDGSV的條數(shù)
	posx=GPS_GetCommaOffset(p1,3); 					//得到可見北斗衛(wèi)星總數(shù)
	if(posx!=0XFF)GPS_DecodeInfo->beidou_svnum=GPS_StrtoNum(p1+posx,&dx);
	for(i=0; ibeidou_slmsg[slx].beidou_num=GPS_StrtoNum(p1+posx,&dx);	//得到衛(wèi)星編號
			else break;
			posx=GPS_GetCommaOffset(p1,5+j*4);
			if(posx!=0XFF)GPS_DecodeInfo->beidou_slmsg[slx].beidou_eledeg=GPS_StrtoNum(p1+posx,&dx);//得到衛(wèi)星仰角 
			else break;
			posx=GPS_GetCommaOffset(p1,6+j*4);
			if(posx!=0XFF)GPS_DecodeInfo->beidou_slmsg[slx].beidou_azideg=GPS_StrtoNum(p1+posx,&dx);//得到衛(wèi)星方位角
			else break;
			posx=GPS_GetCommaOffset(p1,7+j*4);
			if(posx!=0XFF)GPS_DecodeInfo->beidou_slmsg[slx].beidou_sn=GPS_StrtoNum(p1+posx,&dx);	//得到衛(wèi)星信噪比
			else break;
			slx++;
		}
		p=p1+1;//切換到下一個BDGSV信息
	}
}


/*
函數(shù)功能:分析GNGGA信息
函數(shù)參數(shù):
		GPS_DecodeInfo:nmea信息結構體
		buf:接收到的GPS數(shù)據(jù)緩沖區(qū)首地址
*/
void GPS_GNGGA_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf)
{
	u8 *p1,dx;
	u8 posx;
	p1=(u8*)strstr((const char *)buf,"$GNGGA");
	if(!p1)return; //沒有查找成功
	posx=GPS_GetCommaOffset(p1,6);								//得到GPS狀態(tài)
	if(posx!=0XFF)GPS_DecodeInfo->gpssta=GPS_StrtoNum(p1+posx,&dx);
	posx=GPS_GetCommaOffset(p1,7);								//得到用于定位的衛(wèi)星數(shù)
	if(posx!=0XFF)GPS_DecodeInfo->posslnum=GPS_StrtoNum(p1+posx,&dx);
	posx=GPS_GetCommaOffset(p1,9);								//得到海拔高度
	if(posx!=0XFF)GPS_DecodeInfo->altitude=GPS_StrtoNum(p1+posx,&dx);
}


/*
函數(shù)功能:分析GNGSA信息
參    數(shù):GPS_DecodeInfo:nmea信息結構體
		  buf:接收到的GPS數(shù)據(jù)緩沖區(qū)首地址
*/
void GPS_GNGSA_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf)
{
	u8 *p1,dx;
	u8 posx;
	u8 i;
	p1=(u8*)strstr((const char *)buf,"$GNGSA");
	if(!p1)return; //沒有查找成功
	posx=GPS_GetCommaOffset(p1,2);								//得到定位類型
	if(posx!=0XFF)GPS_DecodeInfo->fixmode=GPS_StrtoNum(p1+posx,&dx);
	for(i=0; i<12; i++)										//得到定位衛(wèi)星編號
	{
		posx=GPS_GetCommaOffset(p1,3+i);
		if(posx!=0XFF)GPS_DecodeInfo->possl[i]=GPS_StrtoNum(p1+posx,&dx);
		else break;
	}
	posx=GPS_GetCommaOffset(p1,15);								//得到PDOP位置精度因子
	if(posx!=0XFF)GPS_DecodeInfo->pdop=GPS_StrtoNum(p1+posx,&dx);
	posx=GPS_GetCommaOffset(p1,16);								//得到HDOP位置精度因子
	if(posx!=0XFF)GPS_DecodeInfo->hdop=GPS_StrtoNum(p1+posx,&dx);
	posx=GPS_GetCommaOffset(p1,17);								//得到VDOP位置精度因子
	if(posx!=0XFF)GPS_DecodeInfo->vdop=GPS_StrtoNum(p1+posx,&dx);
}


/*
函數(shù)功能:分析GNRMC信息
函數(shù)參數(shù):GPS_DecodeInfo:nmea信息結構體
		 buf:接收到的GPS數(shù)據(jù)緩沖區(qū)首地址
*/
void GPS_GNRMC_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf)
{
	u8 *p1,dx;
	u8 posx;
	u32 temp;
	float rs;
	p1=(u8*)strstr((const char *)buf,"$GNRMC");//"$GNRMC",經常有&和GNRMC分開的情況,故只判斷GPRMC.
	if(!p1)return; //沒有查找成功
	posx=GPS_GetCommaOffset(p1,1);								//得到UTC時間
	if(posx!=0XFF)
	{
		temp=GPS_StrtoNum(p1+posx,&dx)/GPS_GetPow(10,dx);	 	//得到UTC時間,去掉ms
		GPS_DecodeInfo->utc.hour=temp/10000;
		GPS_DecodeInfo->utc.min=(temp/100)%100;
		GPS_DecodeInfo->utc.sec=temp%100;
	}
	posx=GPS_GetCommaOffset(p1,3);								//得到緯度
	if(posx!=0XFF)
	{
		temp=GPS_StrtoNum(p1+posx,&dx);
		GPS_DecodeInfo->latitude=temp/GPS_GetPow(10,dx+2);	//得到°
		rs=(float)(temp%GPS_GetPow(10,dx+2));				//得到'		 
		GPS_DecodeInfo->latitude=(u32)(GPS_DecodeInfo->latitude*GPS_GetPow(10,5)+(rs*GPS_GetPow(10,5-dx))/60);//轉換為° 
	}
	posx=GPS_GetCommaOffset(p1,4);								//南緯還是北緯 
	if(posx!=0XFF)GPS_DecodeInfo->nshemi=*(p1+posx);
	posx=GPS_GetCommaOffset(p1,5);								//得到經度
	if(posx!=0XFF)
	{
		temp=GPS_StrtoNum(p1+posx,&dx);
		GPS_DecodeInfo->longitude=temp/GPS_GetPow(10,dx+2);	//得到°
		rs=(float)(temp%GPS_GetPow(10,dx+2));				//得到'		 
		GPS_DecodeInfo->longitude=(u32)(GPS_DecodeInfo->longitude*GPS_GetPow(10,5)+(rs*GPS_GetPow(10,5-dx))/60);//轉換為° 
	}
	posx=GPS_GetCommaOffset(p1,6);								//東經還是西經
	if(posx!=0XFF)GPS_DecodeInfo->ewhemi=*(p1+posx);
	posx=GPS_GetCommaOffset(p1,9);								//得到UTC日期
	if(posx!=0XFF)
	{
		temp=GPS_StrtoNum(p1+posx,&dx);		 				//得到UTC日期
		GPS_DecodeInfo->utc.date=temp/10000;
		GPS_DecodeInfo->utc.month=(temp/100)%100;
		GPS_DecodeInfo->utc.year=2000+temp%100;
	}
}


/*
函數(shù)功能:分析GNVTG信息
函數(shù)參數(shù):GPS_DecodeInfo:nmea信息結構體
		  buf:接收到的GPS數(shù)據(jù)緩沖區(qū)首地址
*/
void GPS_GNVTG_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf)
{
	u8 *p1,dx;
	u8 posx;
	p1=(u8*)strstr((const char *)buf,"$GNVTG");
	if(!p1)return; //沒有查找成功
	posx=GPS_GetCommaOffset(p1,7);								//得到地面速率
	if(posx!=0XFF)
	{
		GPS_DecodeInfo->speed=GPS_StrtoNum(p1+posx,&dx);
		if(dx<3)GPS_DecodeInfo->speed*=GPS_GetPow(10,3-dx);	 	 		//確保擴大1000倍
	}
}

/*
函數(shù)功能:提取GPS信息
函數(shù)參數(shù):GPS_DecodeInfo:nmea信息結構體
		  buf:接收到的GPS數(shù)據(jù)緩沖區(qū)首地址
*/
void GPS_InfoGet(GPS_Msg *GPS_DecodeInfo,u8 *buf)
{
	GPS_GPGSV_InfoGet(GPS_DecodeInfo,buf);	//GPGSV解析-OK
	GPS_BDGSV_InfoGet(GPS_DecodeInfo,buf);	//BDGSV解析-OK
	GPS_GNGGA_InfoGet(GPS_DecodeInfo,buf);	//GNGGA解析-OK 	
	GPS_GNGSA_InfoGet(GPS_DecodeInfo,buf);	//GPNSA解析-ON
	GPS_GNRMC_InfoGet(GPS_DecodeInfo,buf);	//GPNMC解析-OK
	GPS_GNVTG_InfoGet(GPS_DecodeInfo,buf);	//GPNTG解析-OK
};>;>;>;>

;i++)src_str[addr+i]=new_str[i];>
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • WINDOWS
    +關注

    關注

    3

    文章

    3503

    瀏覽量

    87891
  • 編程
    +關注

    關注

    88

    文章

    3521

    瀏覽量

    93275
  • C++
    C++
    +關注

    關注

    21

    文章

    2085

    瀏覽量

    73302
收藏 人收藏

    評論

    相關推薦

    C++打印類型名稱的分析與實現(xiàn)

    打印類型名稱,聽起來像是一個很簡單的需求,但在目前的C++當中,并非易事。
    發(fā)表于 10-20 14:08 ?1272次閱讀

    C++文件操作

    C++文件操作
    的頭像 發(fā)表于 07-21 10:52 ?1020次閱讀
    <b class='flag-5'>C++</b>之<b class='flag-5'>文件</b>操作

    使用FATFS中fopen函數(shù)創(chuàng)建新文件名稱時,有什么方法可以增加字符長度嗎?

    在使用FATFS中fopen函數(shù)創(chuàng)建新文件名稱時,發(fā)現(xiàn)txt文件名長度不能超過8個英文字符,請問有什么方法可以增加字符長度嗎?在文件系統(tǒng)中的哪個位置去更改參數(shù)呢?
    發(fā)表于 03-28 08:39

    STM32CubeMX如何在*.c文件中使用c++特性?

    用arm-xxx-gcc編譯器進行編譯,*.cpp文件會使用arm-xxx-g++編譯器進行編譯,STM32CubeMX生成文件都是*.c文件,在不修改
    發(fā)表于 04-25 06:15

    C++筆記001:Microsoft Visual Studio 2010 軟件的安裝與建立第一個cpp文件

    ,填寫cpp文件名稱,點擊添加。至此,一個cpp文件就建立完成,接下來就可以編寫代碼了。 補充內容 (2018-8-11 12:16): 歡迎關注微信公眾號:依法編程獲取更多資料!`
    發(fā)表于 02-06 22:06

    使用系統(tǒng)命令來除去文件名中的特殊字符

    ;?"。為了能夠正常使用這個文件又不破壞文件名稱,就用cmd系統(tǒng)命令語句寫了個重命名小模塊。這樣文件名稱既不會被破壞也能除去名字中的“?”完成后就能正常調用文件了。
    發(fā)表于 11-07 15:36

    CH376 SD卡文件名稱不能超過14個字符要怎么處理

    ch376inc.h 配置文件中,有文件名稱最大長度的設置,默認是 13+1 ,改大之后沒有作用,新建的文件名稱長度還是不能超過14。#define MAX_FILE_NAME_LEN(34
    發(fā)表于 07-01 07:09

    時鐘芯片ds12c887的C51驅動程序

    文件名稱:ds12c887.c 適用范圍:時鐘芯片ds12c887的驅動程序
    發(fā)表于 06-03 16:03 ?262次下載

    C/C++文件大全

    C/C++文件一覽,一本很好的工具速查手冊
    發(fā)表于 11-10 17:45 ?0次下載

    C++ Builder 操作ini文件讀寫

    C++ Builder 操作ini文件讀寫
    發(fā)表于 12-15 22:50 ?0次下載

    如何在C++代碼中使用C文件

    12.3 在C target=_blank style=cursor:pointer;color:#D05C38;text-decoration:underline;》C++中使用C
    發(fā)表于 10-19 09:24 ?3次下載

    C++的const多文件編譯預處理的資料說明

    本文檔的主要內容詳細介紹的是C++的const多文件編譯預處理的資料說明包括了:1、const型常量,2、常對象,3、常成員函數(shù),4、常數(shù)據(jù)成員,5、常引用,6、多文件,7、編譯預處,
    發(fā)表于 04-03 08:00 ?0次下載
    <b class='flag-5'>C++</b>的const多<b class='flag-5'>文件</b>編譯預<b class='flag-5'>處理</b>的資料說明

    高質量C++C編程指南資料說明

    每個 C++/C 程序通常分為兩個文件。一個文件用于保存程序的聲明(declaration),稱為頭文件。另一個
    發(fā)表于 03-14 08:00 ?2次下載

    RT-Thread 開發(fā)的目錄名稱文件名稱

    文件名稱如果無特殊的需求(如果是引用其他地方,可以保留相應的名稱),請使用全小寫 的形式。另外為了避免文件名重名的問題,一些地方請盡量不要使用通用化、使用頻率高 的名稱。
    的頭像 發(fā)表于 06-09 15:53 ?2522次閱讀

    虛擬機:使用cscope瀏覽C++文件

    cscope 本意是用來查看c文件的。但是也可以查看C++文件。方法如下:
    的頭像 發(fā)表于 06-22 14:29 ?2023次閱讀
    虛擬機:使用cscope瀏覽<b class='flag-5'>C++</b><b class='flag-5'>文件</b>