Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
gm_telemetry_server
Project
Project
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
Christopher Reis
gm_telemetry_server
Commits
ceaab152
Commit
ceaab152
authored
May 15, 2017
by
Christopher Reis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added MySQL database
parent
dc197c58
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
+35
-2
Makefile
Makefile
+2
-2
dataset.hpp
dataset.hpp
+26
-0
gm_telemetry_server.cpp
gm_telemetry_server.cpp
+7
-0
No files found.
Makefile
100644 → 100755
View file @
ceaab152
...
@@ -10,8 +10,8 @@ TARGET = gm_telemetry_server
...
@@ -10,8 +10,8 @@ TARGET = gm_telemetry_server
include
../AppMake.mf
include
../AppMake.mf
INCS
+=
-I
./websocketpp
INCS
+=
-I
./websocketpp
-I
/user/include/mysql
LDFLAGS
+=
-lboost_system
LDFLAGS
+=
-lboost_system
-lmysqlclient
-lz
CXXFLAGS
+=
-std
=
c++11
CXXFLAGS
+=
-std
=
c++11
dataset.hpp
View file @
ceaab152
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <fstream>
#include <fstream>
#include <string>
#include <string>
#include <chrono>
#include <chrono>
#include <mysql/mysql.h>
#include <boost/any.hpp>
#include <boost/any.hpp>
...
@@ -35,12 +36,17 @@ struct measurement {
...
@@ -35,12 +36,17 @@ struct measurement {
struct
subsystem
{
struct
subsystem
{
std
::
string
name
;
std
::
string
name
;
std
::
vector
<
measurement
>
v
;
std
::
vector
<
measurement
>
v
;
MYSQL
*
con
=
mysql_init
(
NULL
);
MYSQL_RES
*
res
;
void
updateMeasurement
(
std
::
string
m
,
std
::
string
value
,
unsigned
long
t
){
void
updateMeasurement
(
std
::
string
m
,
std
::
string
value
,
unsigned
long
t
){
mysql_real_connect
(
con
,
"192.168.1.4"
,
"root"
,
"root"
,
"gmsec"
,
0
,
NULL
,
0
);
for
(
std
::
vector
<
measurement
>::
iterator
it
=
v
.
begin
();
it
!=
v
.
end
();
++
it
){
for
(
std
::
vector
<
measurement
>::
iterator
it
=
v
.
begin
();
it
!=
v
.
end
();
++
it
){
if
(
it
->
name
==
m
){
if
(
it
->
name
==
m
){
it
->
v
=
value
;
it
->
v
=
value
;
it
->
timestamp
=
t
;
it
->
timestamp
=
t
;
std
::
string
insert
=
"INSERT INTO "
+
m
+
" VALUES("
+
value
+
","
+
std
::
to_string
(
t
)
+
");"
;
mysql_query
(
con
,
insert
.
c_str
());
return
;
return
;
}
}
}
}
...
@@ -49,6 +55,26 @@ struct subsystem {
...
@@ -49,6 +55,26 @@ struct subsystem {
meas
.
v
=
value
;
meas
.
v
=
value
;
meas
.
timestamp
=
t
;
meas
.
timestamp
=
t
;
v
.
push_back
(
meas
);
v
.
push_back
(
meas
);
//mysql_query
std
::
string
str
=
"CREATE TABLE "
+
m
+
"(Timestamp TEXT, Value TEXT);"
;
std
::
cout
<<
str
<<
'\n'
;
mysql_query
(
con
,
str
.
c_str
());
std
::
cout
<<
mysql_error
(
con
)
<<
'\n'
;
str
=
"INSERT INTO "
+
m
+
" VALUES("
+
value
+
","
+
std
::
to_string
(
t
)
+
");"
;
mysql_query
(
con
,
str
.
c_str
());
std
::
cout
<<
mysql_error
(
con
)
<<
'\n'
;
return
;
}
void
connectToDB
(
std
::
string
s
,
std
::
string
prefix
){
std
::
cout
<<
"Connecting to server "
<<
s
<<
" version: "
<<
mysql_get_client_info
()
<<
'\n'
;
mysql_real_connect
(
con
,
s
.
c_str
(),
"root"
,
"root"
,
"gmsec"
,
0
,
NULL
,
0
);
std
::
string
test
=
"CREATE TABLE "
+
prefix
+
"(Timestamp TEXT, Value TEXT);"
;
mysql_query
(
con
,
test
.
c_str
());
test
=
"INSERT INTO "
+
prefix
+
" VALUES(2000,9999);"
;
mysql_query
(
con
,
test
.
c_str
());
mysql_free_result
(
res
);
mysql_close
(
con
);
return
;
return
;
}
}
...
...
gm_telemetry_server.cpp
View file @
ceaab152
...
@@ -61,6 +61,7 @@ std::mutex systemdata_mutex;
...
@@ -61,6 +61,7 @@ std::mutex systemdata_mutex;
std
::
vector
<
std
::
time_t
>
time_vector
;
std
::
vector
<
std
::
time_t
>
time_vector
;
std
::
mutex
sys_mutex
;
std
::
mutex
sys_mutex
;
nlohmann
::
json
j
;
nlohmann
::
json
j
;
std
::
string
SQL_Server
;
class
gmsub
class
gmsub
{
{
...
@@ -467,6 +468,12 @@ int main(int argc, char* argv[])
...
@@ -467,6 +468,12 @@ int main(int argc, char* argv[])
//load dictionary
//load dictionary
std
::
string
filename
=
example
::
get
(
config
,
"dictionary"
,
"/GMSEC_API/bin/dictionary.json"
);
std
::
string
filename
=
example
::
get
(
config
,
"dictionary"
,
"/GMSEC_API/bin/dictionary.json"
);
dictionary
=
load_dictionary
(
filename
);
dictionary
=
load_dictionary
(
filename
);
port
=
example
::
get
(
config
,
"port"
,
8081
);
//set sql server
SQL_Server
=
example
::
get
(
config
,
"SQL_Server"
,
"192.168.1.4"
);
nav_sys
.
connectToDB
(
SQL_Server
,
"N"
);
orb_sys
.
connectToDB
(
SQL_Server
,
"O"
);
veh_sys
.
connectToDB
(
SQL_Server
,
"V"
);
//Threads
//Threads
std
::
thread
gmsec
(
&
gmsub
::
run
,
&
g
);
std
::
thread
gmsec
(
&
gmsub
::
run
,
&
g
);
...
...
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