Commit 60af7808 by ZhongJianfu

update:123

parent 7844662b
...@@ -19,6 +19,7 @@ using namespace std; ...@@ -19,6 +19,7 @@ using namespace std;
string get_sim_num(); string get_sim_num();
int set_blue_alarm_led(int value); int set_blue_alarm_led(int value);
string get_gps();
int main(int args, const char *argv[]) int main(int args, const char *argv[])
{ {
...@@ -29,7 +30,8 @@ int main(int args, const char *argv[]) ...@@ -29,7 +30,8 @@ int main(int args, const char *argv[])
// } // }
easylogginginit(); //日志初始化 easylogginginit(); //日志初始化
// get_sim_num(); // get_sim_num();
set_blue_alarm_led(1); // set_blue_alarm_led(1);
get_gps();
return 0; return 0;
} }
/** /**
...@@ -128,3 +130,177 @@ int set_blue_alarm_led(int value) ...@@ -128,3 +130,177 @@ int set_blue_alarm_led(int value)
close(ttyfd); close(ttyfd);
return 0; return 0;
} }
string get_gps()
{
string sim_num;
int ttyfd;
int stdout_changed = 0;
int tty_changed = 0;
struct termios stdout_tio;
struct termios tty_tio;
char readbuf[256];
ttyfd = open("/dev/ttyUSB2", O_RDWR | O_NOCTTY | O_NDELAY);
if (ttyfd < 0)
{
return "open error";
}
struct termios tio;
int ret = tcgetattr(ttyfd, &tio);
if (ret == -1)
{
perror("tcgetattr");
}
memcpy(&tty_tio, &tio, sizeof(struct termios));
tio.c_iflag = 0;
tio.c_oflag = 0;
tio.c_cflag = CS8 | CREAD | CLOCAL;
tio.c_cflag &= (~CRTSCTS);
tio.c_lflag = 0;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
if (cfsetospeed(&tio, B115200) < 0 || cfsetispeed(&tio, B115200) < 0)
{
perror("cfseti/ospeed");
}
ret = tcsetattr(ttyfd, TCSANOW, &tio);
if (ret == -1)
{
perror("tcsetattr");
}
tty_changed = 1;
struct termios outio;
ret = tcgetattr(STDIN_FILENO, &outio);
if (ret == -1)
{
perror("tcgetattr");
}
memcpy(&stdout_tio, &outio, sizeof(struct termios));
stdout_changed = 1;
outio.c_lflag &= ~ECHO;
ret = tcsetattr(STDIN_FILENO, TCSANOW, &outio);
int flags = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
// struct pollfd fds[] = {
// {STDIN_FILENO, POLLIN, 0},
// {ttyfd, POLLIN, 0}};
ret = write(ttyfd, "ATE0\r\n", 6); //关闭回显
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "ATE0 readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
ret = write(ttyfd, "at+qgps\r\n", 9); //打开GPS
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "at+qgps readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
ret = write(ttyfd, "AT+QGPSCFG=\"gnssconfig\",0\r\n", 27); //配置1
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "AT+QGPSCFG=\"gnssconfig\",0 readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
ret = write(ttyfd, "at+qgps=1\r\n", 11); //配置2
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "at+qgps=1 readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
ret = write(ttyfd, "AT+QGPSLOC=0\r\n", 14); //配置3
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "AT+QGPSLOC=0 readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
ret = write(ttyfd, "AT+QGPSLOC=1\r\n", 14); //配置3
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "AT+QGPSLOC=1 readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
ret = write(ttyfd, "AT+QGPSLOC=0\r\n", 14); //配置3
if (ret < 0)
{
close(ttyfd);
return "write error";
}
usleep(500 * 1000);
ret = read(ttyfd, readbuf, sizeof(readbuf));
if (ret < 0 && errno != EAGAIN)
{
close(ttyfd);
return "read error";
}
LOG(INFO) << "AT+QGPSLOC=0 readbuf =" << readbuf;
memset(readbuf, 0, sizeof(readbuf));
return sim_num;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment