// File: /workspace/github_cpp_makefile_star2_O2/pehublove[P]GPS-neo7n-forBaiduMap/test.cpp
// Function: main
int main(int argc, char **argv)
{
	int fd;
	int nread,i,n =0,datalen=255, len = 0;
	char testbuff[]="Hello\r\n";
	char readbuff[256];
	
	fd=serialport();
	printf("fd=%d\n",fd);
	//尝试先写内容
	nread=write(fd,testbuff,datalen);
	if(nread==-1)
	{
		printf("write bad\n");
	}
	else{
		printf("the test is ok!\n");
	}	
	//循环读取串口并输出
	while(1)
	{
		//printf("enter the while loop\n");
		bzero(readbuff, sizeof(readbuff));
		datalen=serial_read(fd,readbuff,255);
		if(datalen > 0)
		{
			cout << datalen << endl;
			string parseStr = readbuff;
			cout << parseStr << endl;
			vector<string> every;
			split(every, parseStr, "\n");
			vector<string>::iterator it = every.begin();
			for(;it != every.end();it++)
			{
			if(it->find("GPRMC") != string::npos)
			{
				vector<string> vecGps;
				vecGps.reserve(15);
				split(vecGps, *it, ",");
				if(vecGps.at(2) == "A")
				{
					cout << "valid data" << endl;
					cout << "longitude: " << vecGps.at(5) << endl;
					cout << "latitude: " << vecGps.at(3) << endl;
					double lon = stod(vecGps.at(5));
					double lat = stod(vecGps.at(3));
					int tempF = (int)lon / 100;
					double point = (lon - tempF * 100)/60;
					double longitude = tempF + point;

					int tempF1 = (int)lat / 100;
					double point1 = (lat - tempF1 * 100)/60;
					double latitude = tempF1 + point1;

					double latbd,lonbd;
					GpsBaidu::gps2bd(latitude, longitude, latbd, lonbd);
					cout << endl;
					cout << "Baidu longitude: " << lonbd << endl;
					cout << "Baidu latitude: " << latbd << endl;
				}
			}
			}

		}
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
callq 0x25aa
movl %eax, %ebx
leaq 0x1a02(%rip), %rdi      # 0x40e6
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x19ea(%rip), %rsi      # 0x40de
movl $0xff, %edx
movl %ebx, -0x2c(%rbp)
movl %ebx, %edi
callq 0x2090
cmpl $-0x1, %eax
leaq 0x1adc(%rip), %rax      # 0x41e9
leaq 0x1ac5(%rip), %rdi      # 0x41d9
cmoveq %rax, %rdi
callq 0x2290
leaq -0x1b0(%rbp), %r14
movq 0x38ad(%rip), %r15      # 0x5fd8
leaq -0x90(%rbp), %r13
leaq -0x70(%rbp), %rbx
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x2100
movl -0x2c(%rbp), %edi
movq %r14, %rsi
movl $0xff, %edx
callq 0x2582
testl %eax, %eax
jle 0x2736
movq %r15, %rdi
movl %eax, %esi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2a40
movq %r15, %rdi
movq %r12, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x20e0
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movq %r13, %rdi
leaq 0x1939(%rip), %rsi      # 0x40e4
movq %rbx, %rdx
callq 0x2a40
leaq -0x50(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movq %r13, %rdx
callq 0x25e0
movq %r13, %rdi
callq 0x20d0
movq -0x50(%rbp), %r14
cmpq -0x48(%rbp), %r14
je 0x29c1
movq %r14, %rdi
leaq 0x1907(%rip), %rsi      # 0x40ed
xorl %edx, %edx
callq 0x22f0
cmpq $-0x1, %rax
je 0x29b8
xorpd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
andq $0x0, -0x60(%rbp)
movq %rbx, %rdi
pushq $0xf
popq %rsi
callq 0x2a7c
movq %r13, %rdi
leaq 0x18d9(%rip), %rsi      # 0x40f3
leaq -0x38(%rbp), %rdx
callq 0x2a40
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x25e0
movq %r13, %rdi
callq 0x20d0
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x2b20
movq %rax, %rdi
leaq 0x18a7(%rip), %rsi      # 0x40f5
callq 0x2b10
testb %al, %al
je 0x29b0
movq %r15, %rdi
leaq 0x1892(%rip), %rsi      # 0x40f7
callq 0x21c0
movq %rax, %rdi
callq 0x20e0
movq %r15, %rdi
leaq 0x188c(%rip), %rsi      # 0x4108
callq 0x21c0
movq %rax, %r12
movq %rbx, %rdi
pushq $0x5
popq %rsi
callq 0x2b20
movq %r12, %rdi
movq %rax, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x20e0
movq %r15, %rdi
leaq 0x186e(%rip), %rsi      # 0x411a
callq 0x21c0
movq %rax, %r12
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x2b20
movq %r12, %rdi
movq %rax, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x20e0
movq %rbx, %rdi
pushq $0x5
popq %rsi
callq 0x2b20
movq %rax, %rdi
xorl %esi, %esi
callq 0x2b41
movsd %xmm0, -0x58(%rbp)
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x2b20
movq %rax, %rdi
xorl %esi, %esi
callq 0x2b41
movsd -0x58(%rbp), %xmm4
cvttsd2si %xmm4, %eax
cltd
pushq $0x64
popq %rsi
idivl %esi
imull $0x64, %eax, %ecx
cvtsi2sd %ecx, %xmm1
subsd %xmm1, %xmm4
cvtsi2sd %eax, %xmm1
movsd 0x16e1(%rip), %xmm3     # 0x4008
divsd %xmm3, %xmm4
addsd %xmm4, %xmm1
cvttsd2si %xmm0, %eax
cltd
idivl %esi
imull $0x64, %eax, %ecx
cvtsi2sd %ecx, %xmm2
subsd %xmm2, %xmm0
divsd %xmm3, %xmm0
cvtsi2sd %eax, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, %xmm0
movq %r13, %rdi
leaq -0x38(%rbp), %rsi
callq 0x34c4
movq %r15, %rdi
callq 0x20e0
movq %r15, %rdi
leaq 0x1793(%rip), %rsi      # 0x4102
callq 0x21c0
movsd -0x38(%rbp), %xmm0
movq %rax, %rdi
callq 0x22a0
movq %rax, %rdi
callq 0x20e0
movq %r15, %rdi
leaq 0x1781(%rip), %rsi      # 0x4114
callq 0x21c0
movsd -0x90(%rbp), %xmm0
movq %rax, %rdi
callq 0x22a0
movq %rax, %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2b60
addq $0x20, %r14
jmp 0x27d2
leaq -0x50(%rbp), %rdi
callq 0x2b60
leaq -0xb0(%rbp), %rdi
callq 0x20d0
leaq -0x1b0(%rbp), %r14
jmp 0x2736
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x20d0
jmp 0x2a22
movq %rax, %rbx
jmp 0x2a22
movq %rax, %rbx
jmp 0x2a2b
jmp 0x2a16
jmp 0x2a16
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x20d0
jmp 0x2a19
jmp 0x2a16
jmp 0x2a16
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2b60
leaq -0x50(%rbp), %rdi
callq 0x2b60
leaq -0xb0(%rbp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x22c0
nop