Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
HelloWorld
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ZhongJianfu
HelloWorld
Commits
60af7808
Commit
60af7808
authored
Jul 14, 2022
by
ZhongJianfu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:123
parent
7844662b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
178 additions
and
1 deletions
+178
-1
main.cpp
main.cpp
+178
-1
No files found.
main.cpp
View file @
60af7808
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment