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
158dd30f
Commit
158dd30f
authored
Sep 02, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
b1dfcec1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
270 additions
and
267 deletions
+270
-267
bench.cpp
examples/bench/bench.cpp
+0
-3
bench_client.cpp
examples/bench_client/bench_client.cpp
+2
-2
demo.cpp
examples/demo/demo.cpp
+5
-7
server_demo.cpp
examples/server_demo/server_demo.cpp
+5
-5
server_demo_libevent.cpp
examples/server_demo_libevent/server_demo_libevent.cpp
+35
-35
ademco_event.h
include/ademco_event.h
+2
-0
ademco_packet.h
include/ademco_packet.h
+207
-174
hb_detail.h
include/hb_detail.h
+13
-34
hb_helper.h
include/hb_helper.h
+1
-7
No files found.
examples/bench/bench.cpp
View file @
158dd30f
...
...
@@ -17,9 +17,6 @@ constexpr int TIMES = 100000;
char
data
[
TIMES
*
256
];
static
constexpr
size_t
MaxAdemcoId
=
999999
;
static
constexpr
size_t
AdemcoIdSentinel
=
MaxAdemcoId
+
1
;
void
ademcoPacketBench
()
{
printf
(
"
\n
ademcoPacketBench...
\n
"
);
...
...
examples/bench_client/bench_client.cpp
View file @
158dd30f
...
...
@@ -66,7 +66,7 @@ struct Session {
event
*
timer
=
nullptr
;
int
id
=
0
;
std
::
string
acct
=
{};
size_t
ademco_id
=
0
;
AdemcoId
ademco_id
=
0
;
uint16_t
seq
=
0
;
AdemcoPacket
packet
=
{};
...
...
@@ -97,7 +97,7 @@ void handle_ademco_msg(Session* session, bufferevent* bev)
{
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
session
->
packet
.
id_
.
eid_
)
{
case
AdemcoId
:
:
id_ack
:
case
Ademco
Msg
Id
:
:
id_ack
:
if
(
session
->
packet
.
seq_
.
value_
==
session
->
seq
)
{
if
(
++
session
->
seq
==
10000
)
{
session
->
seq
=
1
;
...
...
examples/demo/demo.cpp
View file @
158dd30f
...
...
@@ -32,7 +32,7 @@ void test()
EXPECT_EQ
(
cb_commited
,
strlen
(
raw
));
EXPECT_EQ
(
ap
.
crc_
.
value_
,
0xC5C3
);
EXPECT_EQ
(
ap
.
len_
.
value_
,
0x0053
);
EXPECT_EQ
(
ap
.
id_
.
eid_
,
AdemcoId
::
Enum
::
id_hb
);
EXPECT_EQ
(
ap
.
id_
.
eid_
,
Ademco
Msg
Id
::
Enum
::
id_hb
);
EXPECT_EQ
(
ap
.
seq_
.
value_
,
0
);
// 0 is not a valid seq, but...
EXPECT_TRUE
(
strncmp
(
"R000000"
,
ap
.
rrcvr_
.
data_
.
data
(),
7
)
==
0
);
EXPECT_TRUE
(
strncmp
(
"L000000"
,
ap
.
lpref_
.
data_
.
data
(),
7
)
==
0
);
...
...
@@ -64,11 +64,11 @@ void handle_network_data(const char* data_from_network)
{
printf
(
"parse ok:
\n
%s
\n
"
,
ap
.
toString
().
data
());
switch
(
ap
.
id_
.
eid_
)
{
case
AdemcoId
:
:
id_ack
:
case
Ademco
Msg
Id
:
:
id_ack
:
// success
break
;
case
AdemcoId
:
:
id_hb
:
// event report
case
Ademco
Msg
Id
:
:
id_hb
:
// event report
// reply ack
{
char
ack
[
1024
];
...
...
@@ -107,8 +107,6 @@ int main()
handle_network_data
(
data_from_network
);
handle_network_data
(
"
\n
593F0034
\"
ACK
\"
0209R123ABCL456DEF#000001[]_09:00:00,04-18-2020
\r
"
);
char
buff
[
1024
];
AdemcoPacket
ap
;
...
...
@@ -118,8 +116,8 @@ int main()
ap
.
make_ack
(
buff
,
sizeof
(
buff
),
1
,
"861234567890"
,
123321
);
handle_network_data
(
buff
);
size_t
ademco_id
=
123456
;
// 主机标识
size_t
zone
=
123
;
// 防区标识
AdemcoId
ademco_id
=
123456
;
// 主机标识
AdemcoZone
zone
=
123
;
// 防区标识
auto
evnt
=
EVENT_FIRE
;
// 事件码
ap
.
make_hb
(
buff
,
sizeof
(
buff
),
1
,
nullptr
,
ademco_id
,
0
,
evnt
,
zone
);
handle_network_data
(
buff
);
...
...
examples/server_demo/server_demo.cpp
View file @
158dd30f
...
...
@@ -54,7 +54,7 @@ struct Buffer
SOCKET
clientSock
=
INVALID_SOCKET
;
Buffer
clientBuffer
=
{};
std
::
string
clientAcct
=
{};
size_t
clientAdemcoId
=
0
;
AdemcoId
clientAdemcoId
=
0
;
std
::
mutex
mutex
=
{};
std
::
vector
<
ADEMCO_EVENT
>
evntsWaiting4Send
=
{};
...
...
@@ -151,11 +151,11 @@ int main(int argc, char** argv)
//printf("id=%s\n", ap.id_.data());
printf
(
"C:%s
\n
"
,
ap
.
toString
().
data
());
switch
(
ap
.
id_
.
eid_
)
{
case
AdemcoId
:
:
id_ack
:
case
Ademco
Msg
Id
:
:
id_ack
:
// success
break
;
case
AdemcoId
:
:
id_null
:
// reply ack
case
Ademco
Msg
Id
:
:
id_null
:
// reply ack
{
char
ack
[
1024
];
auto
len
=
ap
.
make_ack
(
ack
,
sizeof
(
ack
),
ap
.
seq_
.
value_
,
ap
.
acct_
.
acct
(),
ap
.
ademcoData_
.
ademco_id_
);
...
...
@@ -164,8 +164,8 @@ int main(int argc, char** argv)
break
;
}
case
AdemcoId
:
:
id_hb
:
// event report
case
AdemcoId
:
:
id_admcid
:
case
Ademco
Msg
Id
:
:
id_hb
:
// event report
case
Ademco
Msg
Id
:
:
id_admcid
:
{
clientAcct
=
ap
.
acct_
.
acct
();
clientAdemcoId
=
ap
.
ademcoData_
.
ademco_id_
;
...
...
examples/server_demo_libevent/server_demo_libevent.cpp
View file @
158dd30f
This diff is collapsed.
Click to expand it.
include/ademco_event.h
View file @
158dd30f
...
...
@@ -104,6 +104,8 @@ enum ADEMCO_EVENT : uint32_t {
EVENT_WHAT_IS_YOUR_TYPE
=
1798
,
// 索要主机类型
EVENT_SIGNAL_STRENGTH_CHANGED
=
1799
,
// 主机信号强度变化
AdemcoEventSentinel
=
10000
,
// -------------------接警中心内部使用事件------------------------------
EVENT_PRIVATE_EVENT_BASE
=
0x00010000
,
EVENT_CLEARMSG
,
// 清除报警信息
...
...
include/ademco_packet.h
View file @
158dd30f
This diff is collapsed.
Click to expand it.
include/hb_detail.h
View file @
158dd30f
...
...
@@ -7,7 +7,7 @@
#include <string>
#include <type_traits>
#include <iterator>
#include "ademco_
detail
.h"
#include "ademco_
packet
.h"
namespace
hb
{
...
...
@@ -145,10 +145,6 @@ static constexpr MachineType AllMachineTypes[MachineTypeCount] = {
IoT
,
};
//! 防区号为0时表示主机自身
static
constexpr
uint16_t
Zone4MachineSelf
=
0
;
//! 主机防区号范围
static
constexpr
uint16_t
ZoneMin
=
1
;
//! 最大防区号根据型号不同而不同
static
uint16_t
zoneMax
(
MachineType
type
)
{
switch
(
type
)
{
...
...
@@ -177,27 +173,15 @@ static uint16_t zoneMax(MachineType type) {
break
;
}
}
//! 对任何主机类型,最大的防区数量
static
constexpr
uint16_t
MaxZoneCount
=
1000
;
//! 对任何主机类型,防区号是否合法(可以包含0防区)
static
bool
isValidZone
(
uint16_t
zone
)
{
return
Zone4MachineSelf
<=
zone
&&
zone
<
MaxZoneCount
;
}
//! 对任何主机类型,防区号是否合法(不可以包含0防区)
static
bool
isValidZoneStrict
(
uint16_t
zone
)
{
return
ZoneMin
<=
zone
&&
zone
<
MaxZoneCount
;
}
//! 防区号是否合法(可以包含0防区)
static
bool
isValidZone
(
MachineType
type
,
uint16_t
zone
)
{
return
Zone4MachineSelf
<=
zone
&&
zone
<=
zoneMax
(
type
);
return
ademco
::
Zone4MachineSelf
<=
zone
&&
zone
<=
zoneMax
(
type
);
}
//! 防区号是否合法(不可以可以包含0防区)
static
bool
isValidZoneStrict
(
MachineType
type
,
uint16_t
zone
)
{
return
ZoneMin
<=
zone
&&
zone
<=
zoneMax
(
type
);
return
ademco
::
ZoneMin
<=
zone
&&
zone
<=
zoneMax
(
type
);
}
//! 主机是否具有半布防功能
...
...
@@ -1776,20 +1760,15 @@ struct WirelessAddress {
};
//! 防区号为0时表示主机(或分主机)自身
static
constexpr
uint16_t
Zone4MachineSelf
=
0
;
//! 主机防区号范围1~999
static
constexpr
uint16_t
ZoneMin
=
1
;
static
constexpr
uint16_t
ZoneMax
=
999
;
//! 主机有线防区范围1~7
static
constexpr
uint16_t
ZoneMinWired
=
ZoneMin
;
static
constexpr
uint16_t
ZoneMaxWired
=
8
;
constexpr
ademco
::
AdemcoZone
ZoneMinWired
=
1
;
constexpr
ademco
::
AdemcoZone
ZoneMaxWired
=
8
;
//! 主机无线防区最小值
static
constexpr
uint16_t
ZoneMinWireless
=
ZoneMaxWired
+
1
;
static
constexpr
uint16_t
ZoneMaxWireless
=
ZoneMax
;
constexpr
ademco
::
AdemcoZone
ZoneMinWireless
=
9
;
constexpr
ademco
::
AdemcoZone
ZoneMaxWireless
=
999
;
//! 分主机防区号范围1~99
static
constexpr
uint16_t
ZoneMinSubMachine
=
1
;
static
constexpr
uint16_t
ZoneMaxSubMachine
=
99
;
constexpr
ademco
::
AdemcoZone
ZoneMinSubMachine
=
1
;
constexpr
ademco
::
AdemcoZone
ZoneMaxSubMachine
=
99
;
//! 以2个字节表示的防区号
...
...
@@ -1841,9 +1820,9 @@ struct ZoneInfo {
//! 所有防区信息
struct
AllZoneInfo
{
//! use extra 1 space, for convenience to use zone as index
ZoneInfo
zones
[
ZoneMax
+
1
]
=
{};
ZoneInfo
zones
[
ademco
::
ZoneSentinel
]
=
{};
AllZoneInfo
()
{
for
(
uint16_t
i
=
0
;
i
<
=
ZoneMax
;
i
++
)
{
zones
[
i
].
zone
=
i
;
}
}
AllZoneInfo
()
{
for
(
uint16_t
i
=
0
;
i
<
ademco
::
ZoneSentinel
;
i
++
)
{
zones
[
i
].
zone
=
i
;
}
}
bool
isUniqueAddr
(
WirelessAddress
addr
)
const
{
for
(
const
auto
&
z
:
zones
)
{
if
(
z
.
addr
==
addr
)
return
false
;
}
...
...
@@ -1906,7 +1885,7 @@ struct Query {
void
setZone
(
ZoneAsTwoChar
zone
)
{
data
[
3
]
=
zone
.
hi
;
data
[
4
]
=
zone
.
lo
;
}
static
Query
queryMachineStatus
()
{
return
queryZoneStatus
(
Zone4MachineSelf
);
return
queryZoneStatus
(
ademco
::
Zone4MachineSelf
);
}
static
Query
queryZoneStatus
(
uint16_t
zone
)
{
...
...
@@ -1918,7 +1897,7 @@ struct Query {
}
static
Query
querySubMachineStatus
()
{
return
queryZoneStatusOfSubMachine
(
Zone4MachineSelf
);
return
queryZoneStatusOfSubMachine
(
ademco
::
Zone4MachineSelf
);
}
static
Query
queryZoneStatusOfSubMachine
(
Char
zone
)
{
...
...
include/hb_helper.h
View file @
158dd30f
...
...
@@ -5,13 +5,6 @@
namespace
hb
{
//! 安定宝ID范围
static
constexpr
size_t
MinAdemcoId
=
1
;
static
constexpr
size_t
MaxAdemcoId
=
999999
;
// 兼容性考虑,最大安定宝 ID 为 0x0F423F
static
constexpr
size_t
AdemcoIdSentinel
=
MaxAdemcoId
+
1
;
static
constexpr
bool
isValidAdemcoId
(
size_t
ademcoId
)
{
return
MinAdemcoId
<=
ademcoId
&&
ademcoId
<=
MaxAdemcoId
;
}
/******** 结合 hb 与 ademco ******/
//! 从事件码推出主机类型
...
...
@@ -23,6 +16,7 @@ static common::MachineType machineTypeFromAdemcoEvent(ademco::ADEMCO_EVENT e) {
case
ademco
:
:
EVENT_I_AM_WIRE_MACHINE
:
return
common
::
MachineType
::
Wired
;
case
ademco
:
:
EVENT_I_AM_WIFI_MACHINE
:
return
common
::
MachineType
::
WiFi
;
case
ademco
:
:
EVENT_I_AM_3_SECTION_MACHINE
:
return
common
::
MachineType
::
ThreeSection
;
case
ademco
:
:
EVENT_I_AM_IOT_MACHINE
:
return
common
::
MachineType
::
IoT
;
default
:
return
common
::
MachineType
::
InvalidMachineType
;
}
}
...
...
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