C语言编程:GPS数据处理

Python017

C语言编程:GPS数据处理,第1张

这是通过online judge测试的

#include<stdio.h>

#include <stdlib.h>

#include<string.h>

int check(char *)

void utc(char *)

char bjtime[7]

int main()

{

char a[200]

int f=0

char *ptr

do

{

scanf("%s",a)

if(strncmp("$GPRMC",a,6)==0)

{

ptr=a

for(int i=0i<2i++){

ptr=strchr(ptr,',')

ptr++

}

if (ptr[0]=='A' &&check(a))

{

utc(a)

f=1

}

}

}while(strcmp("END",a)!=0)

if (f) printf("%c%c:%c%c:%c%c",bjtime[0],bjtime[1],bjtime[2],bjtime[3],bjtime[4],bjtime[5])

return 0

}

int check(char *s)

{

char *ck,*str

int i

char m=s[1]

for(i=2i<strlen(s)-3i++)

m^=s[i]

int z=(int)m%65536

printf("%0x",z)

ck=&s[strlen(s)-2]

int x=strtol(ck,&str,16)

if(x==z) return 1

else return 0

}

void utc(char * s)

{

char *str1

char str[7]

str1=&s[7]

strncpy(bjtime,str1,6)

int x=strtol(bjtime,&str1,10)

x+=80000

x%=240000

for(int i=5i>=0i--){

bjtime[i]=(char)((int)'0'+x%10)

x/=10

}

}

可以去看看android底层的源码,操作gps模块,本来就是用C来实现的

通过jni调用java层的gps接口,我看有android.location下有:GpsStatus.class,Loacton.class等

///////////////////////////////////////////////////////////

//

设计题目

:

基于51单片机的串口通信

//

功能

:

//

说明

:

晶振用12m,

///////////////////////////////////////////////////////////

#include

//

12m

晶振

#define

uchar

unsigned

char

#define

uint

unsigned

int

///////////////////////////////////////////////////////////

//

name

:

串口发送函数

//

in

:

//

out

:

//

function

:

//

explain

:

///////////////////////////////////////////////////////////

void

send(uchar

x)

{

sbuf=x

//

将数据放到缓冲区,发送

while(!ti)

//

等待发送完成

ti=0

//

清标志位

}

///////////////////////////////////////////////////////////

//

name

:

初始化函数

//

in

:

//

out

:

//

function

:

//

explain

:

///////////////////////////////////////////////////////////

void

init(void)

{

tmod=0x20

//

t1工作在方式2,自动重载

th1=0xe6

tl1=0xe6

//

设置波特率为1200

sm0=0

sm1=1

//

串口方式1

tr1=1

//

打开定时器1

}

///////////////////////////////////////////////////////////

//

name

:

主函数

//

in

:

//

out

:

//

function

:

//

explain

:

///////////////////////////////////////////////////////////

void

main(void)

{

uchar

i

init()

//

初始化

while(1)

{

for(i=0

i<10

i++)

{

send(i)

}

}

}