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
7cf05836
Commit
7cf05836
authored
Aug 23, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
print
parent
3f98e592
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
37 deletions
+67
-37
server_demo_libevent.cpp
examples/server_demo_libevent/server_demo_libevent.cpp
+67
-37
No files found.
examples/server_demo_libevent/server_demo_libevent.cpp
View file @
7cf05836
...
...
@@ -107,8 +107,12 @@ struct Client {
MachineStatus
status3
=
MachineStatus
::
Arm
;
std
::
map
<
size_t
,
ZonePropertyAndLostConfig
>
zones
=
{};
QueryStage
queryStage
=
QueryStage
::
None
;
com
::
MachineTimer
timer
=
{};
uint16_t
nextSeq
()
{
if
(
++
seq
==
10000
)
{
seq
=
1
;
}
return
seq
;
}
void
printInfo
()
const
;
Client
&
operator
=
(
const
Client
&
)
=
default
;
};
struct
ThreadContext
{
...
...
@@ -247,17 +251,28 @@ void handle_com_passthrough(ThreadContext* context, Client& client, evbuffer* ou
break
;
case
com
:
:
ResponseParser
::
ResponseType
::
A6_response
:
{
com
::
A6R
resp
;
memcpy
(
resp
.
data
,
xdata
.
data
(),
resp
.
len
);
com
::
MachineTimer
t
=
resp
.
getTimer
();
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
if
(
com
::
isValidMachineTimer
(
t
.
timer
[
i
]))
{
printf
(
"
\t\t
Machine Timer#%d: Arm at %02d:%02d, Disarm at %02d:%02d
\n
"
,
i
+
1
,
t
.
timer
[
i
].
armAt
.
hour
,
t
.
timer
[
i
].
armAt
.
minute
,
t
.
timer
[
i
].
disarmAt
.
hour
,
t
.
timer
[
i
].
disarmAt
.
minute
);
}
else
{
printf
(
"
\t\t
Machine Timer#%d: Not Set
\n
"
,
i
+
1
);
if
(
client
.
queryStage
==
QueryStage
::
QueryingTimer
)
{
client
.
queryStage
=
QueryStage
::
None
;
com
::
A6R
resp
;
memcpy
(
resp
.
data
,
xdata
.
data
(),
resp
.
len
);
client
.
timer
=
resp
.
getTimer
();
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
if
(
com
::
isValidMachineTimer
(
client
.
timer
.
timer
[
i
]))
{
printf
(
"
\t\t
Machine Timer#%d: Arm at %02d:%02d, Disarm at %02d:%02d
\n
"
,
i
+
1
,
client
.
timer
.
timer
[
i
].
armAt
.
hour
,
client
.
timer
.
timer
[
i
].
armAt
.
minute
,
client
.
timer
.
timer
[
i
].
disarmAt
.
hour
,
client
.
timer
.
timer
[
i
].
disarmAt
.
minute
);
}
else
{
printf
(
"
\t\t
Machine Timer#%d: Not Set
\n
"
,
i
+
1
);
}
}
}
}
auto
n
=
context
->
packet
.
make_hb
(
buf
,
sizeof
(
buf
),
client
.
nextSeq
(),
client
.
acct
,
client
.
ademco_id
,
0
,
EVENT_EXIT_SET_MODE
,
0
);
evbuffer_add
(
output
,
buf
,
n
);
if
(
!
disable_data_print
)
{
printf
(
"T#%d S#%d acct=%s ademco_id=%06zX :%s
\n
"
,
context
->
worker_id
,
client
.
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
context
->
packet
.
toString
(
detail
::
ToStringOption
::
ALL_CHAR_AS_HEX
).
data
());
}
}
break
;
case
com
:
:
ResponseParser
::
ResponseType
::
A7_response
:
...
...
@@ -310,15 +325,16 @@ void handle_com_passthrough(ThreadContext* context, Client& client, evbuffer* ou
case
com
:
:
ResponseParser
::
ResponseType
::
AE_response
:
break
;
case
com
:
:
ResponseParser
::
ResponseType
::
B1_response
:
{
{
com
::
B1R
b1
;
memcpy
(
b1
.
data
.
data
,
xdata
.
data
(),
xdata
.
size
());
client
.
status1
=
b1
.
data
.
cmd
.
status1
==
0
?
MachineStatus
::
Arm
:
MachineStatus
::
Disarm
;
client
.
status2
=
b1
.
data
.
cmd
.
status2
==
0
?
MachineStatus
::
Arm
:
MachineStatus
::
Disarm
;
client
.
status3
=
b1
.
data
.
cmd
.
status3
==
0
?
MachineStatus
::
Arm
:
MachineStatus
::
Disarm
;
printf
(
"
\t\t
status1: %d %s
\n\t\t
status2: %d %s
\n\t\t
status3: %d %s
\n
"
,
(
int
)
client
.
status1
,
machineStatusToString
(
client
.
status1
),
(
int
)
client
.
status2
,
machineStatusToString
(
client
.
status2
),
(
int
)
client
.
status3
,
machineStatusToString
(
client
.
status3
));
(
int
)
client
.
status1
,
machineStatusToString
(
client
.
status1
),
(
int
)
client
.
status2
,
machineStatusToString
(
client
.
status2
),
(
int
)
client
.
status3
,
machineStatusToString
(
client
.
status3
));
break
;
}
case
com
:
:
ResponseParser
::
ResponseType
::
Invalid_response
:
...
...
@@ -920,29 +936,7 @@ int main(int argc, char** argv)
printf
(
"Total connnected %zd clients:
\n
"
,
copiedClients
.
size
());
for
(
const
auto
&
client
:
copiedClients
)
{
if
(
client
.
type
==
EVENT_I_AM_3_SECTION_MACHINE
)
{
printf
(
" fd=#%d acct=%s ademco_id=%zd type=%s
\n
"
,
client
.
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
machineTypeToString
(
machineTypeFromAdemcoEvent
((
ADEMCO_EVENT
)
client
.
type
)));
printf
(
" status1: %d %s status2: %d %s status3: %d %s
\n
"
,
(
int
)
client
.
status1
,
machineStatusToString
(
client
.
status1
),
(
int
)
client
.
status2
,
machineStatusToString
(
client
.
status2
),
(
int
)
client
.
status3
,
machineStatusToString
(
client
.
status3
));
}
else
{
printf
(
" fd=#%d acct=%s ademco_id=%zd type=%s status=%d %s
\n
"
,
client
.
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
machineTypeToString
(
machineTypeFromAdemcoEvent
((
ADEMCO_EVENT
)
client
.
type
)),
(
int
)
client
.
status
,
machineStatusToString
(
client
.
status
));
}
for
(
const
auto
&
zp
:
client
.
zones
)
{
char
buf
[
512
];
snprintf
(
buf
,
sizeof
(
buf
),
getZoneFormatString
(
machineTypeFromAdemcoEvent
((
ADEMCO_EVENT
)
client
.
type
)),
zp
.
first
);
printf
(
" Zone:"
);
printf
(
"%s"
,
buf
);
printf
(
" Prop:0x%02X %s
\t
Tamper Enabled:%s
\n
"
,
zp
.
second
.
prop
,
zonePropertyToStringEn
(
zp
.
second
.
prop
),
zp
.
second
.
tamper_enabled
?
"true"
:
"false"
);
}
client
.
printInfo
();
}
}
break
;
...
...
@@ -983,3 +977,39 @@ int main(int argc, char** argv)
return
0
;
}
void
Client
::
printInfo
()
const
{
if
(
type
==
EVENT_I_AM_3_SECTION_MACHINE
)
{
printf
(
" fd=#%d acct=%s ademco_id=%zd type=%s
\n
"
,
fd
,
acct
.
data
(),
ademco_id
,
machineTypeToString
(
machineTypeFromAdemcoEvent
((
ADEMCO_EVENT
)
type
)));
printf
(
" status1: %d %s status2: %d %s status3: %d %s
\n
"
,
(
int
)
status1
,
machineStatusToString
(
status1
),
(
int
)
status2
,
machineStatusToString
(
status2
),
(
int
)
status3
,
machineStatusToString
(
status3
));
}
else
{
printf
(
" fd=#%d acct=%s ademco_id=%zd type=%s status=%d %s
\n
"
,
fd
,
acct
.
data
(),
ademco_id
,
machineTypeToString
(
machineTypeFromAdemcoEvent
((
ADEMCO_EVENT
)
type
)),
(
int
)
status
,
machineStatusToString
(
status
));
}
for
(
const
auto
&
zp
:
zones
)
{
char
buf
[
512
];
snprintf
(
buf
,
sizeof
(
buf
),
getZoneFormatString
(
machineTypeFromAdemcoEvent
((
ADEMCO_EVENT
)
type
)),
zp
.
first
);
printf
(
" Zone:"
);
printf
(
"%s"
,
buf
);
printf
(
" Prop:0x%02X %s
\t
Tamper Enabled:%s
\n
"
,
zp
.
second
.
prop
,
zonePropertyToStringEn
(
zp
.
second
.
prop
),
zp
.
second
.
tamper_enabled
?
"true"
:
"false"
);
}
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
if
(
com
::
isValidMachineTimer
(
timer
.
timer
[
i
]))
{
printf
(
" Machine Timer#%d: Arm at %02d:%02d, Disarm at %02d:%02d
\n
"
,
i
+
1
,
timer
.
timer
[
i
].
armAt
.
hour
,
timer
.
timer
[
i
].
armAt
.
minute
,
timer
.
timer
[
i
].
disarmAt
.
hour
,
timer
.
timer
[
i
].
disarmAt
.
minute
);
}
else
{
printf
(
" Machine Timer#%d: Not Set
\n
"
,
i
+
1
);
}
}
}
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