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
d997b70e
Commit
d997b70e
authored
Jan 05, 2021
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update c# dll demo
parent
ca76c5a9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
11 deletions
+79
-11
ademco_hb.h
examples/ademco_hb/ademco_hb.h
+25
-0
dllmain.cpp
examples/ademco_hb/dllmain.cpp
+17
-0
Program.cs
examples/csharp_dll_demo/Program.cs
+32
-11
update_tools.bat
tools/update_tools.bat
+5
-0
No files found.
examples/ademco_hb/ademco_hb.h
View file @
d997b70e
...
...
@@ -28,6 +28,20 @@ DLL_FUNC int parse(const char* pack, int pack_len, int* cb_commited);
*/
DLL_FUNC
int
pack
(
char
*
buff
,
int
buff_len
,
int
seq
,
int
ademco_id
,
int
ademco_event
,
int
zone
,
int
gg
);
/*
* @brief 将远程控制命令打包成网络传输数据
* @param[in|out] buff 缓冲区
* @param[in] buff_len 缓冲区长度
* @param[in] seq 序号
* @param[in] acct 主机账号
* @param[in] ademco_id 安定宝ID
* @param[in] ademco_event 安定宝事件码
* @param[in] zone 防区号
* @param[in] gg 分防区号
* @return 大于0 成功,返回值代表包长;0 buff空间不足
*/
DLL_FUNC
int
pack2
(
char
*
buff
,
int
buff_len
,
int
seq
,
const
char
*
acct
,
int
ademco_id
,
int
ademco_event
,
int
zone
,
int
gg
);
/*
* @brief 打包ACK
* @param[in|out] buff 缓冲区
...
...
@@ -37,3 +51,14 @@ DLL_FUNC int pack(char* buff, int buff_len, int seq, int ademco_id, int ademco_e
* @return 大于0 成功,返回值代表包长;0 buff空间不足
*/
DLL_FUNC
int
pack_ack
(
char
*
buff
,
int
buff_len
,
int
seq
,
int
ademco_id
);
/*
* @brief 打包ACK
* @param[in|out] buff 缓冲区
* @param[in] buff_len 缓冲区长度
* @param[in] seq 序号
* @param[in] acct 主机账号
* @return 大于0 成功,返回值代表包长;0 buff空间不足
*/
DLL_FUNC
int
pack_ack2
(
char
*
buff
,
int
buff_len
,
int
seq
,
const
char
*
acct
);
examples/ademco_hb/dllmain.cpp
View file @
d997b70e
...
...
@@ -39,6 +39,15 @@ int pack(char* buff, int buff_len, int seq, int ademco_id, int ademco_event, int
return
static_cast
<
int
>
(
res
);
}
int
pack2
(
char
*
buff
,
int
buff_len
,
int
seq
,
const
char
*
acct
,
int
ademco_id
,
int
ademco_event
,
int
zone
,
int
gg
)
{
ademco
::
AdemcoPacket
ap
;
auto
res
=
ap
.
make_hb
(
buff
,
static_cast
<
size_t
>
(
buff_len
),
static_cast
<
uint16_t
>
(
seq
),
acct
,
static_cast
<
size_t
>
(
ademco_id
),
static_cast
<
unsigned
char
>
(
gg
),
static_cast
<
ademco
::
ADEMCO_EVENT
>
(
ademco_event
),
static_cast
<
size_t
>
(
zone
));
return
static_cast
<
int
>
(
res
);
}
int
pack_ack
(
char
*
buff
,
int
buff_len
,
int
seq
,
int
ademco_id
)
{
ademco
::
AdemcoPacket
ap
;
...
...
@@ -46,3 +55,11 @@ int pack_ack(char* buff, int buff_len, int seq, int ademco_id)
nullptr
,
static_cast
<
size_t
>
(
ademco_id
));
return
static_cast
<
int
>
(
res
);
}
int
pack_ack2
(
char
*
buff
,
int
buff_len
,
int
seq
,
const
char
*
acct
)
{
ademco
::
AdemcoPacket
ap
;
auto
res
=
ap
.
make_ack
(
buff
,
static_cast
<
size_t
>
(
buff_len
),
static_cast
<
uint16_t
>
(
seq
),
acct
,
0
);
return
static_cast
<
int
>
(
res
);
}
\ No newline at end of file
examples/csharp_dll_demo/Program.cs
View file @
d997b70e
...
...
@@ -11,21 +11,33 @@ namespace csharp_dll_demo
{
class
Program
{
[
DllImport
(
@"G:\dev_libs\ademco_hb\x64\Release\ademco_hb.dll"
,
[
DllImport
(
@"G:\dev_libs\ademco_hb\
examples\
x64\Release\ademco_hb.dll"
,
EntryPoint
=
"parse"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
public
static
extern
Int32
parse
(
string
buf
,
Int32
buf_len
,
ref
Int32
commited
);
[
DllImport
(
@"G:\dev_libs\ademco_hb\x64\Release\ademco_hb.dll"
,
[
DllImport
(
@"G:\dev_libs\ademco_hb\
examples\
x64\Release\ademco_hb.dll"
,
EntryPoint
=
"pack"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
public
static
extern
Int32
pack
(
ref
byte
buf
,
Int32
buf_len
,
Int32
seq
,
Int32
ademco_id
,
Int32
ademco_event
,
Int32
zone
,
Int32
gg
);
[
DllImport
(
@"G:\dev_libs\ademco_hb\x64\Release\ademco_hb.dll"
,
[
DllImport
(
@"G:\dev_libs\ademco_hb\examples\x64\Release\ademco_hb.dll"
,
EntryPoint
=
"pack"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
public
static
extern
Int32
pack2
(
ref
byte
buf
,
Int32
buf_len
,
Int32
seq
,
string
acct
,
Int32
ademco_id
,
Int32
ademco_event
,
Int32
zone
,
Int32
gg
);
[
DllImport
(
@"G:\dev_libs\ademco_hb\examples\x64\Release\ademco_hb.dll"
,
EntryPoint
=
"pack_ack"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
public
static
extern
Int32
pack_ack
(
ref
byte
buf
,
Int32
buf_len
,
Int32
seq
,
Int32
ademco_id
);
[
DllImport
(
@"G:\dev_libs\ademco_hb\examples\x64\Release\ademco_hb.dll"
,
EntryPoint
=
"pack_ack"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
public
static
extern
Int32
pack_ack2
(
ref
byte
buf
,
Int32
buf_len
,
Int32
seq
,
string
acct
);
static
void
Main
(
string
[]
args
)
{
Console
.
WriteLine
(
"Hello World!"
);
...
...
@@ -33,12 +45,12 @@ namespace csharp_dll_demo
// test parse
{
Console
.
WriteLine
(
"test parse"
);
string
raw
=
"\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#
000000
|1737 00 000]_09:11:19,08-05-2019\r"
;
string
raw
=
"\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#
90219125916578
|1737 00 000]_09:11:19,08-05-2019\r"
;
Int32
commited
=
0
;
Int32
res
=
parse
(
raw
,
raw
.
Length
,
ref
commited
);
Console
.
WriteLine
(
"res={0:D}, commited={1:D}"
,
res
,
commited
);
Console
.
WriteLine
(
"parse ademco_id/event, etc."
);
string
pattern
=
@"\
[\#(?<ademco_id>\d{6}
)\|(?<ademco_event>\d{4})\s(?<gg>\d{2})\s(?<zone>\d{3})\]"
;
string
pattern
=
@"\
#(?<acct>.+)\[\#(?<ademco_id>[0-9a-fA-F]+
)\|(?<ademco_event>\d{4})\s(?<gg>\d{2})\s(?<zone>\d{3})\]"
;
foreach
(
Match
match
in
Regex
.
Matches
(
raw
,
pattern
))
{
GroupCollection
groups
=
match
.
Groups
;
...
...
@@ -102,24 +114,33 @@ namespace csharp_dll_demo
Int32
res
=
parse
(
data
,
len
,
ref
commited
);
if
(
res
==
0
)
{
string
pattern
=
"\"(?<id>.+)\"(?<seq>\\d{4}).+\\#(?<a
demco_id
>.+)\\["
;
string
pattern
=
"\"(?<id>.+)\"(?<seq>\\d{4}).+\\#(?<a
cct
>.+)\\["
;
Match
match
=
Regex
.
Matches
(
data
,
pattern
)[
0
];
string
id
=
match
.
Groups
[
"id"
].
Value
;
int
seq
=
Int32
.
Parse
(
match
.
Groups
[
"seq"
].
Value
);
int
ademco_id
=
Int32
.
Parse
(
match
.
Groups
[
"ademco_id"
].
Value
,
System
.
Globalization
.
NumberStyles
.
HexNumber
);
//
int ademco_id = Int32.Parse(match.Groups["ademco_id"].Value, System.Globalization.NumberStyles.HexNumber);
string
acct
=
match
.
Groups
[
"acct"
].
Value
;
// reply ack
{
Byte
[]
sendBuff
=
new
Byte
[
1024
];
res
=
pack_ack
(
ref
sendBuff
[
0
],
1024
,
seq
,
ademco_id
);
res
=
pack_ack
2
(
ref
sendBuff
[
0
],
1024
,
seq
,
acct
);
clientSocket
.
Send
(
sendBuff
,
0
,
res
,
SocketFlags
.
None
);
}
// handle event
if
(
id
==
"HENG-BO"
||
id
==
"ADM-CID"
)
{
pattern
=
@"\[\#(?<ademco_id>[\d|a-fA-F]{6})\|(?<ademco_event>\d{4})\s(?<gg>\d{2})\s(?<zone>\d{3})\]"
;
Console
.
WriteLine
(
Regex
.
Matches
(
data
,
pattern
)[
0
].
ToString
());
pattern
=
@"\[\#(?<ademco_id>[0-9a-fA-F]+)\|(?<ademco_event>\d{4})\s(?<gg>\d{2})\s(?<zone>\d{3})\]"
;
//Console.WriteLine(Regex.Matches(data, pattern)[0].ToString());
foreach
(
Match
match2
in
Regex
.
Matches
(
data
,
pattern
))
{
GroupCollection
groups
=
match2
.
Groups
;
foreach
(
Group
group
in
groups
)
{
Console
.
WriteLine
(
group
.
Name
+
" "
+
group
.
Value
);
}
}
Console
.
WriteLine
(
""
);
}
}
}
...
...
tools/update_tools.bat
View file @
d997b70e
...
...
@@ -3,4 +3,9 @@ del .\Win32\ademco_java.dll
del .\Win32\gen_event_md.exe
xcopy /i /s /y /exclude:exclude.txt ..\examples\x64\Release .\x64
del .\x64\gen_event_md.exe
set the_7z="C:\Program Files\7-Zip\7z.exe"
%the_7z% a Win32.7z Win32
%the_7z% a x64.7z x64
PAUSE
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