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
89614f16
Commit
89614f16
authored
Aug 29, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Xdata convert
parent
1faef439
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
5 deletions
+52
-5
bench_client.cpp
examples/bench_client/bench_client.cpp
+9
-3
bench_client.vcxproj.user
examples/bench_client/bench_client.vcxproj.user
+1
-1
ademco_packet.h
include/ademco_packet.h
+42
-1
No files found.
examples/bench_client/bench_client.cpp
View file @
89614f16
...
...
@@ -63,6 +63,7 @@ struct Session {
int
fd
=
0
;
int
thread_id
=
0
;
bufferevent
*
bev
=
nullptr
;
event
*
timer
=
nullptr
;
int
id
=
0
;
std
::
string
acct
=
{};
size_t
ademco_id
=
0
;
...
...
@@ -174,6 +175,7 @@ void timer_cb(evutil_socket_t fd, short what, void* arg)
//bufferevent_free(bev);
//evutil_closesocket(fd);
session
->
timer
=
nullptr
;
bufferevent_disable
(
session
->
bev
,
EV_WRITE
);
// SHUT_WR
shutdown
(
session
->
fd
,
1
);
...
...
@@ -197,14 +199,14 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
seq
,
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
auto
base
=
bufferevent_get_base
(
bev
);
auto
timer
=
event_new
(
base
,
-
1
,
EV_TIMEOUT
,
timer_cb
,
session
);
if
(
!
timer
)
{
session
->
timer
=
event_new
(
base
,
-
1
,
EV_TIMEOUT
,
timer_cb
,
session
);
if
(
!
session
->
timer
)
{
fprintf
(
stderr
,
"create timer failed
\n
"
);
event_base_loopbreak
(
base
);
return
;
}
struct
timeval
tv
=
{
timeout
,
0
};
event_add
(
timer
,
&
tv
);
event_add
(
session
->
timer
,
&
tv
);
if
(
++
ctx
->
session_start
<
ctx
->
session_end
)
{
ctx
->
connectNext
();
...
...
@@ -246,6 +248,10 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
}
}
if
(
session
->
timer
)
{
event_del
(
session
->
timer
);
session
->
timer
=
nullptr
;
}
delete
session
;
bufferevent_free
(
bev
);
//event_base_loopbreak(bufferevent_get_base(bev));
...
...
examples/bench_client/bench_client.vcxproj.user
View file @
89614f16
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LocalDebuggerCommandArguments>
192.168.1.
166 12345 6 18000 15
0
</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>
192.168.1.
90 12345 6 1200 3
0
</LocalDebuggerCommandArguments>
<DebuggerFlavor>
WindowsLocalDebugger
</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
...
...
include/ademco_packet.h
View file @
89614f16
...
...
@@ -301,7 +301,7 @@ struct XData
enum
class
DataFormat
{
AS_IS
,
//! 原样打包
TO_ASCII
,
//! 一个字节的HEX值转换为两个ASCII字符,如 6 转为
00 06
TO_ASCII
,
//! 一个字节的HEX值转换为两个ASCII字符,如 6 转为
"06", '6' 转为 "36"
};
LengthFormat
lengthFormat_
=
LengthFormat
::
TWO_HEX
;
...
...
@@ -320,11 +320,52 @@ struct XData
size_t
size
()
const
{
return
data_
.
size
();
}
size_t
rawSize
()
const
{
return
rawData_
.
size
();
}
bool
valid
()
const
{
if
(
data_
.
empty
()
||
rawData_
.
empty
())
{
return
false
;
}
size_t
len
=
0
;
if
(
lengthFormat_
==
LengthFormat
::
TWO_HEX
)
{
if
(
rawData_
.
size
()
<
4
)
{
return
false
;
}
len
=
(
rawData_
[
1
]
<<
8
)
|
rawData_
[
2
];
if
(
len
!=
data_
.
size
()
||
(
data_
.
size
()
+
4
!=
rawData_
.
size
()))
{
return
false
;
}
}
else
{
if
(
rawData_
.
size
()
<
6
)
{
return
false
;
}
len
=
ademco
::
detail
::
HexCharArrayToDec
(
rawData_
.
data
()
+
1
,
4
);
if
((
len
!=
data_
.
size
())
||
(
data_
.
size
()
+
6
!=
rawData_
.
size
()))
{
return
false
;
}
}
return
true
;
}
bool
operator
==
(
const
XData
&
rhs
)
const
{
return
lengthFormat_
==
rhs
.
lengthFormat_
&&
data_
==
rhs
.
data_
;
}
bool
convert
(
LengthFormat
lengthFormat
=
LengthFormat
::
TWO_HEX
)
{
if
(
!
valid
())
{
return
false
;
}
if
(
lengthFormat_
==
lengthFormat
)
{
return
true
;
}
lengthFormat_
=
lengthFormat
;
if
(
lengthFormat_
==
LengthFormat
::
TWO_HEX
)
{
std
::
vector
<
char
>
tmp
(
data_
.
size
()
/
2
);
detail
::
ConvertHiLoAsciiToHexCharArray
(
&
tmp
[
0
],
data_
.
data
(),
data_
.
size
());
data_
=
tmp
;
rawData_
.
resize
(
data_
.
size
()
+
4
);
rawData_
[
0
]
=
'['
;
rawData_
[
1
]
=
(
data_
.
size
()
>>
8
)
&
0xFF
;
rawData_
[
2
]
=
data_
.
size
()
&
0xFF
;
memcpy
(
&
rawData_
[
3
],
data_
.
data
(),
data_
.
size
());
rawData_
.
back
()
=
']'
;
}
else
{
auto
tmp
=
detail
::
toString
(
data_
,
detail
::
ToStringOption
::
ALL_CHAR_AS_HEX
,
false
,
false
);
data_
.
clear
();
std
::
copy
(
tmp
.
begin
(),
tmp
.
end
(),
std
::
back_inserter
(
data_
));
rawData_
.
resize
(
data_
.
size
()
+
6
);
rawData_
[
0
]
=
'['
;
detail
::
Dec2HexCharArray_4
(
data_
.
size
(),
&
rawData_
[
1
],
false
);
memcpy
(
&
rawData_
[
5
],
data_
.
data
(),
data_
.
size
());
rawData_
.
back
()
=
']'
;
}
return
true
;
}
};
typedef
std
::
shared_ptr
<
XData
>
XDataPtr
;
...
...
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