Commit 9b87ab9c authored by captainwong's avatar captainwong

针对三区段主机的布撤防操作修改

parent cb3e0d48
......@@ -43,6 +43,7 @@ struct Client {
std::string acct = {};
size_t ademco_id = 0;
uint16_t seq = 0;
int type = -1;
};
struct ThreadContext {
......@@ -91,6 +92,9 @@ void handle_ademco_msg(ThreadContext* context, bufferevent* bev)
if (context->packet.id_.eid_ != AdemcoId::id_null) {
client.acct = context->packet.acct_.acct();
client.ademco_id = context->packet.ademcoData_.ademco_id_;
if (ademco::isMachineTypeEvent(context->packet.ademcoData_.ademco_event_)) {
client.type = context->packet.ademcoData_.ademco_event_;
}
}
{
char buf[1024];
......@@ -127,10 +131,28 @@ void commandcb(evutil_socket_t, short, void* user_data)
std::lock_guard<std::mutex> lg(context->mutex);
for (auto& client : context->clients) {
for (auto e : evs) {
size_t n = 0;
if (client.second.type == EVENT_I_AM_3_SECTION_MACHINE) {
for (int gg = 1; gg <= 3; gg++) {
if (++client.second.seq == 10000) {
client.second.seq = 1;
}
if (e == EVENT_DISARM) {
auto xdata = makeXData(pwd, 6);
n = context->packet.make_hb(buf, sizeof(buf), client.second.seq, client.second.acct, client.second.ademco_id, gg, e, 0, xdata);
} else {
n = context->packet.make_hb(buf, sizeof(buf), client.second.seq, client.second.acct, client.second.ademco_id, gg, e, 0);
}
evbuffer_add(client.second.output, buf, n);
if (!disable_data_print) {
printf("T#%d S#%d acct=%s ademco_id=%06zX :%s\n",
context->worker_id, client.second.fd, client.second.acct.data(), client.second.ademco_id, context->packet.toString().data());
}
}
} else {
if (++client.second.seq == 10000) {
client.second.seq = 1;
}
size_t n = 0;
if (e == EVENT_DISARM) {
auto xdata = makeXData(pwd, 6);
n = context->packet.make_hb(buf, sizeof(buf), client.second.seq, client.second.acct, client.second.ademco_id, 0, e, 0, xdata);
......@@ -139,8 +161,9 @@ void commandcb(evutil_socket_t, short, void* user_data)
}
evbuffer_add(client.second.output, buf, n);
if (!disable_data_print) {
printf("S#%d acct=%s ademco_id=%06zX :%s\n",
client.second.fd, client.second.acct.data(), client.second.ademco_id, context->packet.toString().data());
printf("T#%d S#%d acct=%s ademco_id=%06zX :%s\n",
context->worker_id, client.second.fd, client.second.acct.data(), client.second.ademco_id, context->packet.toString().data());
}
}
}
}
......@@ -203,7 +226,7 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int
char str[INET_ADDRSTRLEN] = { 0 };
auto sin = (sockaddr_in*)addr;
inet_ntop(AF_INET, &sin->sin_addr, str, INET_ADDRSTRLEN);
printf("accpet TCP connection #%d from: %s:%d\n", fd, str, sin->sin_port);
printf("accpet TCP connection #%d from: %s:%d\n", (int)fd, str, sin->sin_port);
evutil_make_socket_nonblocking(fd);
......
<?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>12345 8 1</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>12345 4 0</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment