Commit e4c9168c authored by captainwong's avatar captainwong

update doc

parent 4a3d8d89
...@@ -16,12 +16,7 @@ QQ群:`1093730796` ...@@ -16,12 +16,7 @@ QQ群:`1093730796`
## docs ## docs
[开发文档](docs/README.md) [对接说明](docs/对接说明.md)
[协议文档](docs/README.md)
## 测试及演示工具,已编译的dll等请点击 [releases](https://github.com/captainwong/ademco_hb/releases)下载 ## 测试及演示工具,已编译的dll等请点击 [releases](https://github.com/captainwong/ademco_hb/releases)下载
## ChangeLog
* 2022年7月31日 废弃旧版 `C++` 头文件版本,启用纯 `C` 版本。`C++` 版本可以在 `cpp` 分支查看。
This diff is collapsed.
对接说明
===============
# 0. 简介
目前有两种对接方式,即 `TCP/HTTP` 对接,前者需要自行开发 `TCP SERVER`,后者需要自行开发 `HTTP SERVER`,目前前者比较复杂但既可以接收主机事件报告又可以控制主机,后者更简单一点,不过缺点是仅能接收主机事件报告无法控制主机,有需要的朋友可以提需求,我找时间更新 `httprelay` 让它可以逆向控制主机.
# 1. 通过TCP协议对接
目前所有主机均为免配置即可上网,可以用APP配置网络参数,将直连接警中心的域名/端口或`IP`/端口配置为你的服务器地址,
即可接收来自主机的`TCP`连接传输的事件报告,可以通过`TCP`对主机进行控制,协议看 [README.md](./README.md)
**需要自行开发`TCP SERVER`**
## 1.1 对 `C/C++` 熟悉的同学
参考 `examples/server_demo`,源码在手,天下你有
## 1.2 其他编程语言
作者对其他语言不熟悉,所以通过 `swig` 生成了其他语言可以使用的库
-`Java` 熟悉的同学,参考 `swig/JavaDemo.java`
-`C#` 熟悉的同学,参考 `swig/CSharpDemo.cs`
-`javascript` 熟悉的同学,参考 `swig/nodejs-demo.js`
有其他语言对接的需要,可以提 `issue` 或在群里发言.
# 2. 通过HTTP协议对接
## 2.1 说明
`examples/httprelay``C` 编写的简易版 `TCP` 服务器与 `HTTP` 转发器,可以用来接收主机`TCP`连接,并转发主机事件到指定的 `URI`,协议看 [README.md](./README.md) 中的 `data`段,参数是 `acct/ademco_event/zone/gg``acct` 用来区分是哪个主机,`ademco_event/zone/gg` 用来判断主机上报了什么事件,所以重点看 `事件码含义`.
## 2.2 网络环境需求
`httprelay` 须运行在能接收主机`TCP`连接的环境:
-`SIM`卡的主机,需要将`httprelay`运行在公网环境,否则主机无法通过`TCP`连接到服务器
- 网线主机,工程主机+网络模块,`WiFi`主机等可以运行在内网环境的主机,可以将 `httprelay` 运行在该主机可以访问的网段,前提是先在公网环境下通过`APP`配置好直连接警中心信息、配对好探测器等.
## 2.3 启动 `httprelay` 示例
```bash
./httprelay 12345 http://your-http-server.com:8080/ademco
```
将监听来自端口`12345``TCP`连接,并在收到事件报告后转发至 `http://your-http-server.com:8080/ademco`
## 2.4 事件转发示例
### 2.4.1 示例1
```
POST http://your-http-server.com:8080/ademco?acct=861234567890&ademco_event=3400&zone=0&gg=0
```
含义是主机账号为 `861234567890`的主机上报了 `3400 布防` 事件
### 2.4.2 示例2
```
POST http://your-http-server.com:8080/ademco?acct=861234567891&ademco_event=1130&zone=80&gg=0
```
含义是主机账号为 `861234567890`的主机上报了 `80防区触发了1130 盗警` 事件
...@@ -64,83 +64,81 @@ hb_zone_property_t allZoneProperties[] = { ...@@ -64,83 +64,81 @@ hb_zone_property_t allZoneProperties[] = {
#undef XX #undef XX
}; };
void printEvents(const ademco_event_t* events, size_t len) void printEvents(const ademco_event_t* events, size_t len) {
{
printf("|事件码|含义|en|\n|-----|----|--|\n"); printf("|事件码|含义|en|\n|-----|----|--|\n");
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
auto e = events[i]; auto e = events[i];
printf("|%04d|%s|%s|\n", e, printf("|%04d|%s|%s|\n", e,
ademco_event_to_string_chinese(e), ademco_event_to_string_chinese(e),
ademco_event_to_string(e)); ademco_event_to_string(e));
} }
printf("\n"); printf("\n");
} }
const char* get_core_author(hb_machine_type_t t) const char* get_core_author(hb_machine_type_t t) {
{
switch (t) { switch (t) {
case HMT_WIFI: case HMT_GPRS:
case HMT_GPRS_IOT: case HMT_WIFI:
case HMT_GPRS: case HMT_GPRS_IOT:
case HMT_WIRED: case HMT_WIFI2:
case HMT_WIFI2: return "wzq";
return "wzq";
case HMT_LCD:
case HMT_NETMOD: case HMT_TRUE_COLOR:
case HMT_LCD: case HMT_THREE_SECTION:
case HMT_TRUE_COLOR: case HMT_IOT:
case HMT_THREE_SECTION: case HMT_GPRS_PHONE:
case HMT_IOT: return "jjf";
case HMT_GPRS_PHONE:
return "jjf"; case HMT_NETMOD:
case HMT_WIRED:
return "jack";
} }
return ""; return "";
} }
const char* get_net_author(hb_machine_type_t t) const char* get_net_author(hb_machine_type_t t) {
{
switch (t) { switch (t) {
case HMT_WIFI: case HMT_WIFI:
case HMT_WIRED: case HMT_GPRS_IOT:
case HMT_NETMOD: case HMT_GPRS:
case HMT_GPRS_IOT: case HMT_LCD:
case HMT_GPRS: case HMT_TRUE_COLOR:
case HMT_LCD: case HMT_THREE_SECTION:
case HMT_TRUE_COLOR: case HMT_IOT:
case HMT_THREE_SECTION: case HMT_GPRS_PHONE:
case HMT_IOT: case HMT_WIFI2:
case HMT_GPRS_PHONE: return "qfm";
case HMT_WIFI2:
return "qfm"; case HMT_WIRED:
case HMT_NETMOD:
return "jack";
} }
return ""; return "";
} }
std::vector<std::string> get_machine_brands(hb_machine_type_t t) std::vector<std::string> get_machine_brands(hb_machine_type_t t) {
{
switch (t) { switch (t) {
case HMT_WIFI: case HMT_WIFI:
case HMT_CAMERA: return {}; case HMT_CAMERA: return {};
case HMT_GPRS_IOT: return { "5050G-4GW", }; case HMT_GPRS_IOT: return { "5050G-4GW", };
case HMT_NETMOD: return { "G250" }; case HMT_NETMOD: return { "G250" };
case HMT_GPRS: return { "4040G", "5050G", "5050G-4G", }; case HMT_GPRS: return { "4040G", "5050G", "5050G-4G", };
case HMT_LCD: return { "BJQ560", "BJQ560B" }; case HMT_LCD: return { "BJQ560", "BJQ560B" };
case HMT_WIRED: return { "4040R", "5050R" }; case HMT_WIRED: return { "4040R", "5050R" };
case HMT_TRUE_COLOR:return { "G1000", "G1000-4G" }; case HMT_TRUE_COLOR:return { "G1000", "G1000-4G" };
case HMT_THREE_SECTION:return { "G1000", "G1000-4G" }; case HMT_THREE_SECTION:return { "G1000", "G1000-4G" };
case HMT_IOT: return { "2050-4GW" }; case HMT_IOT: return { "2050-4GW" };
case HMT_GPRS_PHONE: return { "2050" }; case HMT_GPRS_PHONE: return { "2050" };
//case hb::common::Nb: return { "" }; default: return {};
default: return {}; break;
break;
} }
} }
std::string brand_to_path(const std::string& brand) std::string brand_to_path(const std::string& brand) {
{
std::vector<std::string> exts = { "png", "jpg" }; std::vector<std::string> exts = { "png", "jpg" };
std::string path = jlib::win32::utf16_to_mbcs(L"..\\..\\docs\\主机类型\\smartresize\\HB-") + brand; std::string path = jlib::win32::utf16_to_mbcs(L"..\\..\\docs\\主机类型\\smartresize\\HB-") + brand;
for (auto ext : exts) { for (auto ext : exts) {
...@@ -151,21 +149,18 @@ std::string brand_to_path(const std::string& brand) ...@@ -151,21 +149,18 @@ std::string brand_to_path(const std::string& brand)
return {}; return {};
} }
void print_machine_brands(hb_machine_type_t t) void print_machine_brands(hb_machine_type_t t) {
{
printf("|<ul>"); printf("|<ul>");
for (auto brand : get_machine_brands(t)) { for (auto brand : get_machine_brands(t)) {
auto path = brand_to_path(brand); auto path = brand_to_path(brand);
if (!path.empty()) { if (!path.empty()) {
printf(jlib::win32::utf16_to_mbcs(LR"(<li>%s</li>)").data(), brand.data());// , brand.data(), path.data()); printf(jlib::win32::utf16_to_mbcs(LR"(<li>%s</li>)").data(), brand.data());
} }
} }
printf("</ul>"); printf("</ul>");
} }
void print_machineTypes() void print_machineTypes() {
{
printf("### *恒博主机类型对照表*\n\n"); printf("### *恒博主机类型对照表*\n\n");
printf("*SMS指主机自身是否可以拨打电话、发送短信,不是指通过阿里语音打电话*\n"); printf("*SMS指主机自身是否可以拨打电话、发送短信,不是指通过阿里语音打电话*\n");
...@@ -174,9 +169,9 @@ void print_machineTypes() ...@@ -174,9 +169,9 @@ void print_machineTypes()
"|------|-------|----|----|-----|----|-------|----|-------|---|----|---|----|\n"); "|------|-------|----|----|-----|----|-------|----|-------|---|----|---|----|\n");
for (auto e : allEvents) { for (auto e : allEvents) {
if (ademco_is_machine_type_event(e)) { if (ademco_is_machine_type_event(e)) {
auto t = hb_machine_type_from_ademco_event(e); auto t = hb_machine_type_from_ademco_event(e);
if(!hb_is_machine_on_sale(t)) continue; if (!hb_is_machine_on_sale(t)) continue;
printf("|%04d %s", (int)e, ademco_event_to_string_chinese(e)); printf("|%04d %s", (int)e, ademco_event_to_string_chinese(e));
printf("|%d %s", (int)t, hb_machine_type_to_string_chinese(t)); printf("|%d %s", (int)t, hb_machine_type_to_string_chinese(t));
...@@ -198,11 +193,9 @@ void print_machineTypes() ...@@ -198,11 +193,9 @@ void print_machineTypes()
printf("|\n"); printf("|\n");
} }
} }
} }
void print_imgs() void print_imgs() {
{
printf("\n\n### *恒博主机型号示例图片*\n\n"); printf("\n\n### *恒博主机型号示例图片*\n\n");
printf("|型号|示例图片|\n" printf("|型号|示例图片|\n"
...@@ -236,20 +229,13 @@ bool zprop_is_contain(hb_zone_property_t* props, int count, hb_zone_property_t p ...@@ -236,20 +229,13 @@ bool zprop_is_contain(hb_zone_property_t* props, int count, hb_zone_property_t p
return false; return false;
} }
void print_available_zone_props() void print_available_zone_props() {
{
printf("### *恒博主机类型与支持的防区属性对照表*\n\n"); printf("### *恒博主机类型与支持的防区属性对照表*\n\n");
//auto all_props = getAvailableZoneProperties();
auto print_prop = [](hb_zone_property_t zp) { auto print_prop = [](hb_zone_property_t zp) {
printf("%02X %s", zp, hb_zone_property_to_string_chinese(zp)); printf("%02X %s", zp, hb_zone_property_to_string_chinese(zp));
}; };
printf("* 防区属性是否支持失联报告\n\n"); printf("* 防区属性是否支持失联报告\n\n");
printf("|"); printf("|");
for (auto zp : allZoneProperties) { for (auto zp : allZoneProperties) {
...@@ -269,7 +255,6 @@ void print_available_zone_props() ...@@ -269,7 +255,6 @@ void print_available_zone_props()
} }
printf("|\n\n"); printf("|\n\n");
printf("* 主机类型与支持的防区属性对照表\n\n"); printf("* 主机类型与支持的防区属性对照表\n\n");
printf("|事件码|类型|型号"); printf("|事件码|类型|型号");
for (auto zp : allZoneProperties) { for (auto zp : allZoneProperties) {
...@@ -299,13 +284,9 @@ void print_available_zone_props() ...@@ -299,13 +284,9 @@ void print_available_zone_props()
printf("|\n"); printf("|\n");
} }
} }
} }
void print_g250_alarm_codes() {
void print_g250_alarm_codes()
{
//printf("# 工程主机串口通信协议\n\n"); //printf("# 工程主机串口通信协议\n\n");
//printf("9600, N, 8, 1\n\n"); //printf("9600, N, 8, 1\n\n");
//printf("SUM = DATA(N) = DATA(0) + DATA(1) + ... + DATA(N-1)\n\n"); //printf("SUM = DATA(N) = DATA(0) + DATA(1) + ... + DATA(N-1)\n\n");
...@@ -375,16 +356,18 @@ void gen_sources() { ...@@ -375,16 +356,18 @@ void gen_sources() {
const char* comment = R"( const char* comment = R"(
```c ```c
/* control source defs /* control source defs
* 范围 0~255 * 范围 0-255
* 0: 主机 * 0: 主机(布撤防来源目前只有键盘,紧急报警可以是键盘,也可以是遥控器)
* 1~50: 遥控器 * 1-10: 遥控器
* 51~97: 智能家居 * 11-50: 保留
* 51-96: 智能家居
* 97: 定时器自动控制
* 98: 中转接警中心 * 98: 中转接警中心
* 99: 直连接警中心 * 99: 直连接警中心
* 100~199: 手机APP,末二位为手机尾号 * 100-199: 手机APP,末二位为手机尾号
* 200: web用户,web端包括 网页,H5, 公众号,小程序等 * 200: web用户,web端包括 网页,H5, 公众号,小程序等
* 201~255: web分享用户 * 201-255: web分享用户
* 特别注意:三区段主机,0 代表主机,1~255 都是遥控器 * 特别注意:三区段主机,0 代表主机,1-255 都是遥控器
*/ */
``` ```
)"; )";
...@@ -397,8 +380,7 @@ void gen_sources() { ...@@ -397,8 +380,7 @@ void gen_sources() {
#undef XX #undef XX
} }
int main() int main() {
{
#define GEN_EVENTS 1 #define GEN_EVENTS 1
#define GEN_G250_CODES 2 #define GEN_G250_CODES 2
......
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