Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ademco_hb
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
captainwong
ademco_hb
Commits
a8cf6036
Commit
a8cf6036
authored
Sep 14, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
isMachineStatusEvent & bench_client
parent
14606367
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
32 deletions
+42
-32
bench_client.cpp
examples/bench_client/bench_client.cpp
+40
-31
bench_client.vcxproj.user
examples/bench_client/bench_client.vcxproj.user
+1
-1
ademco_event.h
include/ademco_event.h
+1
-0
No files found.
examples/bench_client/bench_client.cpp
View file @
a8cf6036
...
@@ -53,6 +53,7 @@ int thread_count = 0;
...
@@ -53,6 +53,7 @@ int thread_count = 0;
int
session_count
=
0
;
int
session_count
=
0
;
int
session_connected
=
0
;
int
session_connected
=
0
;
int
timeout
=
0
;
int
timeout
=
0
;
int
load_test
=
0
;
std
::
mutex
mutex
=
{};
std
::
mutex
mutex
=
{};
int64_t
totalBytesRead
=
0
;
int64_t
totalBytesRead
=
0
;
...
@@ -66,7 +67,7 @@ struct Session {
...
@@ -66,7 +67,7 @@ struct Session {
int
fd
=
0
;
int
fd
=
0
;
int
thread_id
=
0
;
int
thread_id
=
0
;
bufferevent
*
bev
=
nullptr
;
bufferevent
*
bev
=
nullptr
;
event
*
timer
=
nullptr
;
event
*
timer
=
nullptr
;
// life or heartbeat timer
int
id
=
0
;
int
id
=
0
;
std
::
string
acct
=
{};
std
::
string
acct
=
{};
AdemcoId
ademco_id
=
0
;
AdemcoId
ademco_id
=
0
;
...
@@ -105,15 +106,10 @@ void handle_ademco_msg(Session* session, bufferevent* bev)
...
@@ -105,15 +106,10 @@ void handle_ademco_msg(Session* session, bufferevent* bev)
auto
output
=
bufferevent_get_output
(
bev
);
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
session
->
packet
.
id_
.
eid_
)
{
switch
(
session
->
packet
.
id_
.
eid_
)
{
case
AdemcoMsgId
:
:
id_ack
:
case
AdemcoMsgId
:
:
id_ack
:
if
(
session
->
packet
.
seq_
.
value_
==
session
->
seq
)
{
if
(
load_test
)
{
if
(
++
session
->
seq
==
10000
)
{
session
->
seq
=
1
;
}
}
{
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
char
buf
[
1024
];
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
seq
,
session
->
acct
,
session
->
ademco_id
);
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
()
,
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
output
,
buf
,
session
->
lastTimePacketSize
);
evbuffer_add
(
output
,
buf
,
session
->
lastTimePacketSize
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
encodeTime
+=
us
;
session
->
encodeTime
+=
us
;
...
@@ -168,24 +164,33 @@ void writecb(struct bufferevent* bev, void* user_data)
...
@@ -168,24 +164,33 @@ void writecb(struct bufferevent* bev, void* user_data)
session
->
bytesWritten
+=
session
->
lastTimePacketSize
;
session
->
bytesWritten
+=
session
->
lastTimePacketSize
;
session
->
msgWritten
++
;
session
->
msgWritten
++
;
}
}
}
}
void
timer_cb
(
evutil_socket_t
fd
,
short
wha
t
,
void
*
arg
)
void
timer_cb
(
evutil_socket_t
,
shor
t
,
void
*
arg
)
{
{
auto
session
=
(
Session
*
)
arg
;
auto
session
=
(
Session
*
)
arg
;
//Session* session = nullptr;
//bufferevent_getcb(bev, nullptr, nullptr, nullptr, (void**)&session);
printf
(
"session #%d timeout
\n
"
,
session
->
id
);
//auto bev = (bufferevent*)arg;
//bufferevent_free(bev);
//evutil_closesocket(fd);
if
(
load_test
)
{
printf
(
"session #%d timeout
\n
"
,
session
->
id
);
session
->
timer
=
nullptr
;
session
->
timer
=
nullptr
;
bufferevent_disable
(
session
->
bev
,
EV_WRITE
);
bufferevent_disable
(
session
->
bev
,
EV_WRITE
);
// SHUT_WR
// SHUT_WR
shutdown
(
session
->
fd
,
1
);
shutdown
(
session
->
fd
,
1
);
}
else
{
printf
(
"session #%d heartbeat
\n
"
,
session
->
id
);
session
->
timer
=
event_new
(
threadContexts
[
session
->
thread_id
]
->
base
,
-
1
,
0
,
timer_cb
,
session
);
if
(
!
session
->
timer
)
{
fprintf
(
stderr
,
"create heartbeat_timer failed
\n
"
);
event_base_loopbreak
(
threadContexts
[
session
->
thread_id
]
->
base
);
return
;
}
struct
timeval
heartbeat_tv
=
{
timeout
,
0
};
event_add
(
session
->
timer
,
&
heartbeat_tv
);
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
bufferevent_get_output
(
session
->
bev
),
buf
,
session
->
lastTimePacketSize
);
}
}
}
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
...
@@ -203,9 +208,10 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
...
@@ -203,9 +208,10 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
}
}
}
}
char
buf
[
1024
];
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_hb
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
,
0
,
session
->
status
,
0
);
session
->
lastTimePacketSize
=
session
->
packet
.
make_hb
(
buf
,
sizeof
(
buf
),
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
,
0
,
session
->
status
,
0
);
session
->
lastTimePacketSize
+=
session
->
packet
.
make_hb
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
,
0
,
session
->
type
,
0
);
session
->
lastTimePacketSize
+=
session
->
packet
.
make_hb
(
buf
+
session
->
lastTimePacketSize
,
sizeof
(
buf
)
-
session
->
lastTimePacketSize
,
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
,
0
,
session
->
type
,
0
);
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
auto
base
=
bufferevent_get_base
(
bev
);
auto
base
=
bufferevent_get_base
(
bev
);
...
@@ -324,8 +330,11 @@ int main(int argc, char** argv)
...
@@ -324,8 +330,11 @@ int main(int argc, char** argv)
}
}
#endif
#endif
if
(
argc
<
6
)
{
if
(
argc
<
7
)
{
printf
(
"Usage: %s ip port thread_count session_count timeout
\n
timeout is in seconds
\n
"
,
argv
[
0
]);
printf
(
"Usage: %s ip port thread_count session_count load_test timeout
\n
"
" load_test: 0 or 1:
\n
"
" 0 to disable load test mode, timeout is client's heartbeat timeout in seconds
\n
"
" 1 to enable load test mode, timeout is client's lifecycle timeout in seconds
\n
"
,
argv
[
0
]);
return
1
;
return
1
;
}
}
...
@@ -353,8 +362,8 @@ int main(int argc, char** argv)
...
@@ -353,8 +362,8 @@ int main(int argc, char** argv)
puts
(
"session_count must times thread_count"
);
puts
(
"session_count must times thread_count"
);
return
1
;
return
1
;
}
}
load_test
=
atoi
(
argv
[
5
])
==
1
;
timeout
=
atoi
(
argv
[
5
]);
timeout
=
atoi
(
argv
[
6
]);
if
(
timeout
<=
0
)
{
if
(
timeout
<=
0
)
{
puts
(
"Invalid timeout"
);
puts
(
"Invalid timeout"
);
return
1
;
return
1
;
...
@@ -362,8 +371,8 @@ int main(int argc, char** argv)
...
@@ -362,8 +371,8 @@ int main(int argc, char** argv)
printf
(
"using libevent %s
\n
"
,
event_get_version
());
printf
(
"using libevent %s
\n
"
,
event_get_version
());
int
session_per_thread
=
session_count
/
thread_count
;
int
session_per_thread
=
session_count
/
thread_count
;
printf
(
"starting %s to %s:%d with %d threads, %d sessions, %d sessions per thread, timeout=%ds
\n
"
,
printf
(
"starting %s to %s:%d with %d threads, %d sessions, %d sessions per thread,
load_test is %s,
timeout=%ds
\n
"
,
argv
[
0
],
ip
,
port
,
thread_count
,
session_count
,
session_per_thread
,
timeout
);
argv
[
0
],
ip
,
port
,
thread_count
,
session_count
,
session_per_thread
,
load_test
?
"on"
:
"off"
,
timeout
);
sockaddr_in
sin
=
{
0
};
sockaddr_in
sin
=
{
0
};
sin
.
sin_family
=
AF_INET
;
sin
.
sin_family
=
AF_INET
;
...
...
examples/bench_client/bench_client.vcxproj.user
View file @
a8cf6036
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LocalDebuggerCommandArguments>
192.168.1.90 12345 1 20
30
</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>
192.168.1.90 12345 1 20
0 30
</LocalDebuggerCommandArguments>
<DebuggerFlavor>
WindowsLocalDebugger
</DebuggerFlavor>
<DebuggerFlavor>
WindowsLocalDebugger
</DebuggerFlavor>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
...
...
include/ademco_event.h
View file @
a8cf6036
...
@@ -359,6 +359,7 @@ static inline bool isMachineStatusEvent(ADEMCO_EVENT ademco_event)
...
@@ -359,6 +359,7 @@ static inline bool isMachineStatusEvent(ADEMCO_EVENT ademco_event)
{
{
return
ademco_event
==
EVENT_ARM
return
ademco_event
==
EVENT_ARM
||
ademco_event
==
EVENT_HALFARM
||
ademco_event
==
EVENT_HALFARM
||
ademco_event
==
EVENT_HALFARM_1456
||
ademco_event
==
EVENT_DISARM
;
||
ademco_event
==
EVENT_DISARM
;
}
}
...
...
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