Commit 6d70a831 authored by captainwong's avatar captainwong

prettier, nothing new

parent 8770892b
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
#endif #endif
#define dline dprintf("%s %d\n", __FILE__, __LINE__); #define dline dprintf("%s %d\n", __FILE__, __LINE__);
#define dmsg dline; dprintf #define dmsg \
dline; \
dprintf
static uint8_t hex2char(uint8_t h) { static uint8_t hex2char(uint8_t h) {
h &= 0x0F; h &= 0x0F;
...@@ -40,7 +41,6 @@ static uint8_t char2hex(uint8_t c) { ...@@ -40,7 +41,6 @@ static uint8_t char2hex(uint8_t c) {
return 0xFF; return 0xFF;
} }
void ademcoPrint(const ademco_char_t* p, size_t len) { void ademcoPrint(const ademco_char_t* p, size_t len) {
while (len--) { while (len--) {
if (isprint(*(const uint8_t*)p)) if (isprint(*(const uint8_t*)p))
...@@ -74,35 +74,35 @@ int ademcoIsValidAccount(const char* acct) { ...@@ -74,35 +74,35 @@ int ademcoIsValidAccount(const char* acct) {
} }
int ademcoIsMachineStatusEvent(AdemcoEvent ademcoEvent) { int ademcoIsMachineStatusEvent(AdemcoEvent ademcoEvent) {
return ademcoEvent == EVENT_ARM return ademcoEvent == EVENT_ARM ||
|| ademcoEvent == EVENT_HALFARM ademcoEvent == EVENT_HALFARM ||
|| ademcoEvent == EVENT_HALFARM_1456 ademcoEvent == EVENT_HALFARM_1456 ||
|| ademcoEvent == EVENT_DISARM; ademcoEvent == EVENT_DISARM;
} }
int ademcoIsMachineTypeEvent(AdemcoEvent ademcoEvent) { int ademcoIsMachineTypeEvent(AdemcoEvent ademcoEvent) {
return ademcoEvent == EVENT_I_AM_NET_MODULE return ademcoEvent == EVENT_I_AM_NET_MODULE ||
|| ademcoEvent == EVENT_I_AM_GPRS ademcoEvent == EVENT_I_AM_GPRS ||
|| ademcoEvent == EVENT_I_AM_LCD_MACHINE ademcoEvent == EVENT_I_AM_LCD_MACHINE ||
|| ademcoEvent == EVENT_I_AM_WIRE_MACHINE ademcoEvent == EVENT_I_AM_WIRE_MACHINE ||
|| ademcoEvent == EVENT_I_AM_WIFI_MACHINE ademcoEvent == EVENT_I_AM_WIFI_MACHINE ||
|| ademcoEvent == EVENT_I_AM_3_SECTION_MACHINE ademcoEvent == EVENT_I_AM_3_SECTION_MACHINE ||
|| ademcoEvent == EVENT_I_AM_IOT_MACHINE ademcoEvent == EVENT_I_AM_IOT_MACHINE ||
|| ademcoEvent == EVENT_I_AM_TRUE_COLOR ademcoEvent == EVENT_I_AM_TRUE_COLOR ||
|| ademcoEvent == EVENT_I_AM_GPRS_IOT ademcoEvent == EVENT_I_AM_GPRS_IOT ||
|| ademcoEvent == EVENT_I_AM_GPRS_PHONE ademcoEvent == EVENT_I_AM_GPRS_PHONE ||
|| ademcoEvent == EVENT_I_AM_NB_MACHINE ademcoEvent == EVENT_I_AM_NB_MACHINE ||
|| ademcoEvent == EVENT_I_AM_WIFI2_MACHINE; ademcoEvent == EVENT_I_AM_WIFI2_MACHINE;
} }
int ademcoIsEventNeedControlSource(AdemcoEvent ademcoEvent) { int ademcoIsEventNeedControlSource(AdemcoEvent ademcoEvent) {
return ademcoEvent == EVENT_ARM return ademcoEvent == EVENT_ARM ||
|| ademcoEvent == EVENT_HALFARM ademcoEvent == EVENT_HALFARM ||
|| ademcoEvent == EVENT_HALFARM_1456 ademcoEvent == EVENT_HALFARM_1456 ||
|| ademcoEvent == EVENT_DISARM ademcoEvent == EVENT_DISARM ||
|| ademcoEvent == EVENT_EMERGENCY ademcoEvent == EVENT_EMERGENCY ||
|| ademcoEvent == EVENT_DURESS ademcoEvent == EVENT_DURESS ||
|| ademcoEvent == EVENT_PHONE_USER_CANCLE_ALARM; ademcoEvent == EVENT_PHONE_USER_CANCLE_ALARM;
} }
AdemcoEvent ademcoGetExceptionEventByResumeEvent(AdemcoEvent resumeEvent) { AdemcoEvent ademcoGetExceptionEventByResumeEvent(AdemcoEvent resumeEvent) {
...@@ -375,7 +375,8 @@ uint16_t ademcoCRC16(const ademco_char_t* buff, size_t len) { ...@@ -375,7 +375,8 @@ uint16_t ademcoCRC16(const ademco_char_t* buff, size_t len) {
return crc; return crc;
} }
size_t ademcoAppendDataSegment(ademco_char_t* buff, const char* acct, AdemcoId ademcoId, AdemcoEvent ademcoEvent, AdemcoGG gg, AdemcoZone zone) { size_t ademcoAppendDataSegment(ademco_char_t* buff, const char* acct, AdemcoId ademcoId,
AdemcoEvent ademcoEvent, AdemcoGG gg, AdemcoZone zone) {
char* p = (char*)buff; char* p = (char*)buff;
if (ademcoEvent == EVENT_INVALID_EVENT) { if (ademcoEvent == EVENT_INVALID_EVENT) {
*p++ = '['; *p++ = '[';
...@@ -425,21 +426,28 @@ size_t ademcoAppendDataSegment(ademco_char_t* buff, const char* acct, AdemcoId a ...@@ -425,21 +426,28 @@ size_t ademcoAppendDataSegment(ademco_char_t* buff, const char* acct, AdemcoId a
} }
} }
size_t ademcoAppendDataSegment2(AdemcoDataSegment* dataSegment, const char* acct, AdemcoId ademcoId, AdemcoEvent ademcoEvent, AdemcoGG gg, AdemcoZone zone) { size_t ademcoAppendDataSegment2(AdemcoDataSegment* dataSegment, const char* acct,
AdemcoId ademcoId, AdemcoEvent ademcoEvent, AdemcoGG gg, AdemcoZone zone) {
dataSegment->ademcoId = ademcoId; dataSegment->ademcoId = ademcoId;
dataSegment->ademcoEvent = ademcoEvent; dataSegment->ademcoEvent = ademcoEvent;
dataSegment->gg = gg; dataSegment->gg = gg;
dataSegment->zone = zone; dataSegment->zone = zone;
return dataSegment->raw_len = ademcoAppendDataSegment(dataSegment->raw, acct, ademcoId, ademcoEvent, gg, zone); return dataSegment->raw_len = ademcoAppendDataSegment(dataSegment->raw,
acct, ademcoId,
ademcoEvent, gg, zone);
} }
AdemcoParseResult ademcoParseDataSegment(const ademco_char_t* packet, size_t packet_len, AdemcoDataSegment* dataSegment) { AdemcoParseResult ademcoParseDataSegment(const ademco_char_t* packet, size_t packet_len,
if (packet_len == ADEMCO_PACKET_DATA_SEGMENT_EMPTY_LEN && packet[0] == '[' && packet[1] == ']') { AdemcoDataSegment* dataSegment) {
if (packet_len == ADEMCO_PACKET_DATA_SEGMENT_EMPTY_LEN &&
packet[0] == '[' && packet[1] == ']') {
memset(dataSegment, 0, sizeof(*dataSegment)); memset(dataSegment, 0, sizeof(*dataSegment));
strcpy((char*)dataSegment->raw, "[]"); strcpy((char*)dataSegment->raw, "[]");
dataSegment->raw_len = 2; dataSegment->raw_len = 2;
return RESULT_OK; return RESULT_OK;
} else if (packet_len >= ADEMCO_PACKET_DATA_SEGMENT_FULL_LEN && packet[0] == '[' && packet[packet_len - 1] == ']') { // [#000000|1400 00 000] } else if (packet_len >= ADEMCO_PACKET_DATA_SEGMENT_FULL_LEN &&
packet[0] == '[' &&
packet[packet_len - 1] == ']') { // [#000000|1400 00 000]
do { do {
const char* p = packet + 2; const char* p = packet + 2;
size_t acct_len = packet_len - 15; size_t acct_len = packet_len - 15;
...@@ -507,7 +515,8 @@ size_t ademcoDataSegmentToCongwinFe100(ademco_char_t* fe100, const AdemcoDataSeg ...@@ -507,7 +515,8 @@ size_t ademcoDataSegmentToCongwinFe100(ademco_char_t* fe100, const AdemcoDataSeg
*p++ = ' '; *p++ = ' ';
// E for open, R for close // E for open, R for close
if (dataSegment->ademcoEvent / 1000 == 1 || dataSegment->ademcoEvent == EVENT_HALFARM) if (dataSegment->ademcoEvent / 1000 == 1 ||
dataSegment->ademcoEvent == EVENT_HALFARM)
*p++ = 'E'; *p++ = 'E';
else else
*p++ = 'R'; *p++ = 'R';
...@@ -605,7 +614,8 @@ size_t ademcoXDataCopy(AdemcoXDataSegment* dst, const AdemcoXDataSegment* src) { ...@@ -605,7 +614,8 @@ size_t ademcoXDataCopy(AdemcoXDataSegment* dst, const AdemcoXDataSegment* src) {
return 0; return 0;
} }
int ademcoMakeXData(AdemcoXDataSegment* xdata, AdemcoXDataLengthFormat xlf, AdemcoXDataTransform xtr, const ademco_char_t* content, size_t len) { int ademcoMakeXData(AdemcoXDataSegment* xdata, AdemcoXDataLengthFormat xlf,
AdemcoXDataTransform xtr, const ademco_char_t* content, size_t len) {
char transformed[ADEMCO_PACKET_XDATA_MAX_LEN]; char transformed[ADEMCO_PACKET_XDATA_MAX_LEN];
size_t translen; size_t translen;
len &= 0xFFFF; len &= 0xFFFF;
...@@ -677,7 +687,8 @@ const char* admecoPacketIdToString(AdemcoPacketId id) { ...@@ -677,7 +687,8 @@ const char* admecoPacketIdToString(AdemcoPacketId id) {
static void getNowTimestamp(char* buff) { static void getNowTimestamp(char* buff) {
time_t now = time(NULL); time_t now = time(NULL);
struct tm* tm = localtime(&now); struct tm* tm = localtime(&now);
snprintf(buff, ADEMCO_PACKET_TIMESTAMP_LEN + 1, "_%02d:%02d:%02d,%02d-%02d-%04d", snprintf(buff, ADEMCO_PACKET_TIMESTAMP_LEN + 1,
"_%02d:%02d:%02d,%02d-%02d-%04d",
tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900); tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
} }
...@@ -685,13 +696,15 @@ static void getNowTimestamp(char* buff) { ...@@ -685,13 +696,15 @@ static void getNowTimestamp(char* buff) {
static void getGmtTimestamp(char* buff) { static void getGmtTimestamp(char* buff) {
time_t now = time(NULL); time_t now = time(NULL);
struct tm* tm = gmtime(&now); struct tm* tm = gmtime(&now);
snprintf(buff, ADEMCO_PACKET_TIMESTAMP_LEN + 1, "_%02d:%02d:%02d,%02d-%02d-%04d", snprintf(buff, ADEMCO_PACKET_TIMESTAMP_LEN + 1,
"_%02d:%02d:%02d,%02d-%02d-%04d",
tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900); tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
} }
size_t ademcoMakeEmptyDataPacket(ademco_char_t* dst_buff, size_t len, size_t ademcoMakeEmptyDataPacket(ademco_char_t* dst_buff, size_t len,
const char* id, uint16_t seq, const char* acct, AdemcoId ademcoId) { const char* id, uint16_t seq,
const char* acct, AdemcoId ademcoId) {
char buff[ADEMCO_PACKET_MAX_LEN]; char buff[ADEMCO_PACKET_MAX_LEN];
char* p = buff; char* p = buff;
char* pcrc = buff + 1; char* pcrc = buff + 1;
...@@ -741,7 +754,8 @@ size_t ademcoMakeEmptyDataPacket(ademco_char_t* dst_buff, size_t len, ...@@ -741,7 +754,8 @@ size_t ademcoMakeEmptyDataPacket(ademco_char_t* dst_buff, size_t len,
size_t ademcoMakeAdmEmptyDataPacket(ademco_char_t* dst_buff, size_t len, size_t ademcoMakeAdmEmptyDataPacket(ademco_char_t* dst_buff, size_t len,
const char* id, uint16_t seq, const char* acct, AdemcoId ademcoId) { const char* id, uint16_t seq,
const char* acct, AdemcoId ademcoId) {
char buff[ADEMCO_PACKET_MAX_LEN]; char buff[ADEMCO_PACKET_MAX_LEN];
char* p = buff; char* p = buff;
char* pcrc = buff + 1; char* pcrc = buff + 1;
...@@ -979,7 +993,8 @@ size_t ademcoMakeAdmPacket2(AdemcoPacket* pkt, uint16_t seq, const char* acct, A ...@@ -979,7 +993,8 @@ size_t ademcoMakeAdmPacket2(AdemcoPacket* pkt, uint16_t seq, const char* acct, A
seq, acct, ademcoId, ademcoEvent, gg, zone, xdata); seq, acct, ademcoId, ademcoEvent, gg, zone, xdata);
} }
AdemcoParseResult ademcoPacketParse(const ademco_char_t* buff, size_t len, AdemcoPacket* pkt, size_t* cb_commited) { AdemcoParseResult ademcoPacketParse(const ademco_char_t* buff, size_t len,
AdemcoPacket* pkt, size_t* cb_commited) {
if (len < 9) { return RESULT_NOT_ENOUGH; } if (len < 9) { return RESULT_NOT_ENOUGH; }
do { do {
const char* p = buff; const char* p = buff;
...@@ -1065,7 +1080,12 @@ AdemcoParseResult ademcoPacketParse(const ademco_char_t* buff, size_t len, Ademc ...@@ -1065,7 +1080,12 @@ AdemcoParseResult ademcoPacketParse(const ademco_char_t* buff, size_t len, Ademc
if (!isxdigit(*p)) { p = NULL; dline; break; } if (!isxdigit(*p)) { p = NULL; dline; break; }
p++; p++;
} }
if (p == NULL || p >= pcr || *p != '[' || p - pacct >= ADEMCO_PACKET_ACCT_MAX_LEN) { dline; break; } if (p == NULL ||
p >= pcr ||
*p != '[' ||
p - pacct >= ADEMCO_PACKET_ACCT_MAX_LEN) {
dline; break;
}
strncpy(pkt->acct, (const char*)pacct, p - pacct); strncpy(pkt->acct, (const char*)pacct, p - pacct);
pkt->acct[p - pacct] = '\0'; pkt->acct[p - pacct] = '\0';
......
This diff is collapsed.
#!/bin/bash
set -e
CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd ${CURRENT_DIR}
mkdir -p ./uvlib
cp -r /g/dev_libs/ademco/uvlib/llhttp ./uvlib/
cp /g/dev_libs/ademco/uvlib/*.h ./uvlib/
cp /g/dev_libs/ademco/uvlib/*.c ./uvlib/
\ No newline at end of file
...@@ -158,6 +158,7 @@ ...@@ -158,6 +158,7 @@
<ClCompile Include="uvlib\uv_httpc.c" /> <ClCompile Include="uvlib\uv_httpc.c" />
<ClCompile Include="uvlib\uv_httpd.c" /> <ClCompile Include="uvlib\uv_httpd.c" />
<ClCompile Include="uvlib\uv_log.c" /> <ClCompile Include="uvlib\uv_log.c" />
<ClCompile Include="uvlib\uv_tcp.c" />
<ClCompile Include="uvlib\uv_tcpclient.c" /> <ClCompile Include="uvlib\uv_tcpclient.c" />
<ClCompile Include="uvlib\uv_tcpserver.c" /> <ClCompile Include="uvlib\uv_tcpserver.c" />
</ItemGroup> </ItemGroup>
......
...@@ -66,6 +66,9 @@ ...@@ -66,6 +66,9 @@
<ClCompile Include="cJSON\cJSON.c"> <ClCompile Include="cJSON\cJSON.c">
<Filter>cJSON</Filter> <Filter>cJSON</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="uvlib\uv_tcp.c">
<Filter>uvlib</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\ademco.h"> <ClInclude Include="..\..\ademco.h">
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#pragma once #pragma once
#define list_append(type, l, node) \ #define list_append(type, l, node) \
do { \ do { \
type* tail_ = (l); \ type* tail_ = (l); \
while (tail_ && tail_->next) \ while (tail_ && tail_->next) \
tail_ = tail_->next; \ tail_ = tail_->next; \
...@@ -12,7 +12,6 @@ do { \ ...@@ -12,7 +12,6 @@ do { \
tail_->next = (node); \ tail_->next = (node); \
else \ else \
(l) = node; \ (l) = node; \
} while (0); } while (0);
#endif #endif
#include "mybuf.h"
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include "mybuf.h"
#include "uv_log.h" #include "uv_log.h"
void mybuf_init(mybuf_t* buf) { void mybuf_init(mybuf_t* buf) {
...@@ -17,7 +19,7 @@ size_t mybuf_space(mybuf_t* buf) { ...@@ -17,7 +19,7 @@ size_t mybuf_space(mybuf_t* buf) {
void mybuf_reserve(mybuf_t* buf, size_t size) { void mybuf_reserve(mybuf_t* buf, size_t size) {
if (mybuf_space(buf) < size) { if (mybuf_space(buf) < size) {
//fprintf(stderr, "WARN: mybuf_t not enough, space=%zu, needed=%zu\n", mybuf_space(buf), size); // fprintf(stderr, "WARN: mybuf_t not enough, space=%zu, needed=%zu\n", mybuf_space(buf), size);
while (mybuf_space(buf) < size) { while (mybuf_space(buf) < size) {
buf->capacity *= 2; buf->capacity *= 2;
} }
...@@ -38,7 +40,7 @@ void mybuf_append(mybuf_t* buf, const char* data, size_t len) { ...@@ -38,7 +40,7 @@ void mybuf_append(mybuf_t* buf, const char* data, size_t len) {
memcpy(buf->buf + buf->size, data, len); memcpy(buf->buf + buf->size, data, len);
buf->size += len; buf->size += len;
} else { } else {
//fprintf(stderr, "WARN: mybuf_t not enough, space=%zu, needed=%zu\n", mybuf_space(buf), len); // fprintf(stderr, "WARN: mybuf_t not enough, space=%zu, needed=%zu\n", mybuf_space(buf), len);
while (mybuf_space(buf) < len) { while (mybuf_space(buf) < len) {
buf->capacity *= 2; buf->capacity *= 2;
} }
...@@ -92,3 +94,12 @@ void mybuf_clear(mybuf_t* buf) { ...@@ -92,3 +94,12 @@ void mybuf_clear(mybuf_t* buf) {
buf->size = 0; buf->size = 0;
buf->capacity = MYBUF_DEFAULT_SIZE; buf->capacity = MYBUF_DEFAULT_SIZE;
} }
void mybuf_clear_append(mybuf_t* buf, const char* data, size_t len) {
mybuf_t tmp;
mybuf_init(&tmp);
mybuf_append(&tmp, data, len);
mybuf_clear(buf);
mybuf_append(buf, tmp.buf, tmp.size);
mybuf_clear(&tmp);
}
...@@ -17,7 +17,7 @@ typedef struct { ...@@ -17,7 +17,7 @@ typedef struct {
char* buf; char* buf;
char mybuf[MYBUF_DEFAULT_SIZE]; char mybuf[MYBUF_DEFAULT_SIZE];
size_t size, capacity; size_t size, capacity;
}mybuf_t; } mybuf_t;
void mybuf_init(mybuf_t* buf); void mybuf_init(mybuf_t* buf);
size_t mybuf_space(mybuf_t* buf); size_t mybuf_space(mybuf_t* buf);
...@@ -32,6 +32,8 @@ void mybuf_cat_printf(mybuf_t* buf, const char* fmt, ...); ...@@ -32,6 +32,8 @@ void mybuf_cat_printf(mybuf_t* buf, const char* fmt, ...);
#endif #endif
void mybuf_clear(mybuf_t* buf); void mybuf_clear(mybuf_t* buf);
// safe to call me when data in buf
void mybuf_clear_append(mybuf_t* buf, const char* data, size_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -3,9 +3,4 @@ ...@@ -3,9 +3,4 @@
#pragma once #pragma once
#endif // !__UV_HTTP_H__ #endif // !__UV_HTTP_H__
#include <stdlib.h> #include "uv_httpc.h"
#include <string.h>
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
#include "llhttp/include/llhttp.h" #include "llhttp/include/llhttp.h"
#include "uv_httpc.h"
#include "uv_log.h" #include "uv_log.h"
#include "list.h"
#define DEFAULT_BUFF_SIZE 1024 #define DEFAULT_BUFF_SIZE 1024
...@@ -36,7 +38,7 @@ typedef struct { ...@@ -36,7 +38,7 @@ typedef struct {
uv_write_t req; uv_write_t req;
uv_buf_t uvbuf; uv_buf_t uvbuf;
mybuf_t buf; mybuf_t buf;
}write_req_t; } write_req_t;
static void init_response(uv_httpc_response_t* response) { static void init_response(uv_httpc_response_t* response) {
response->code = uv_httpc_ok; response->code = uv_httpc_ok;
...@@ -159,7 +161,6 @@ static void setup_default_llhttp_settings(llhttp_settings_t* settings) { ...@@ -159,7 +161,6 @@ static void setup_default_llhttp_settings(llhttp_settings_t* settings) {
settings->on_status_complete = on_status_complete; settings->on_status_complete = on_status_complete;
} }
/*************************** uv callback functions ****************/ /*************************** uv callback functions ****************/
static void on_close_timer(uv_handle_t* handle) { static void on_close_timer(uv_handle_t* handle) {
...@@ -254,7 +255,7 @@ static void on_write(uv_write_t* req, int status) { ...@@ -254,7 +255,7 @@ static void on_write(uv_write_t* req, int status) {
static int send_request(uv_httpc_t* httpc) { static int send_request(uv_httpc_t* httpc) {
int r; int r;
write_req_t* req = malloc(sizeof * req); write_req_t* req = malloc(sizeof *req);
fatal_if_null(req); fatal_if_null(req);
mybuf_init(&req->buf); mybuf_init(&req->buf);
mybuf_cat_printf(&req->buf, "%s %s HTTP/1.1\r\n", httpc->method, httpc->url); mybuf_cat_printf(&req->buf, "%s %s HTTP/1.1\r\n", httpc->method, httpc->url);
...@@ -309,12 +310,11 @@ static void on_resolved(uv_getaddrinfo_t* resolver, int status, struct addrinfo* ...@@ -309,12 +310,11 @@ static void on_resolved(uv_getaddrinfo_t* resolver, int status, struct addrinfo*
fatal_on_uv_err(r, "uv_tcp_connect failed"); fatal_on_uv_err(r, "uv_tcp_connect failed");
} }
/*************************** public functions ****************/ /*************************** public functions ****************/
int uv_httpc_create(uv_httpc_t** httpc, uv_loop_t* loop, const char* host, const char* port, int uv_httpc_create(uv_httpc_t** httpc, uv_loop_t* loop, const char* host, const char* port,
uv_httpc_on_response_t on_response) { uv_httpc_on_response_t on_response) {
uv_httpc_t* ptr = malloc(sizeof * ptr); uv_httpc_t* ptr = malloc(sizeof *ptr);
if (!ptr) return UV_ENOMEM; if (!ptr) return UV_ENOMEM;
int r = uv_tcp_init(loop, &ptr->tcp); int r = uv_tcp_init(loop, &ptr->tcp);
if (r) { if (r) {
...@@ -389,7 +389,7 @@ void uv_httpc_free(uv_httpc_t* httpc) { ...@@ -389,7 +389,7 @@ void uv_httpc_free(uv_httpc_t* httpc) {
} }
uv_httpc_headers_t* uv_httpc_headers_append_nodup(uv_httpc_headers_t* headers, char* data) { uv_httpc_headers_t* uv_httpc_headers_append_nodup(uv_httpc_headers_t* headers, char* data) {
uv_httpc_headers_t* header = malloc(sizeof * header); uv_httpc_headers_t* header = malloc(sizeof *header);
if (!header) return NULL; if (!header) return NULL;
header->next = NULL; header->next = NULL;
header->data = data; header->data = data;
...@@ -400,9 +400,9 @@ uv_httpc_headers_t* uv_httpc_headers_append_nodup(uv_httpc_headers_t* headers, c ...@@ -400,9 +400,9 @@ uv_httpc_headers_t* uv_httpc_headers_append_nodup(uv_httpc_headers_t* headers, c
} }
uv_httpc_headers_t* uv_httpc_headers_dup(uv_httpc_headers_t* headers) { uv_httpc_headers_t* uv_httpc_headers_dup(uv_httpc_headers_t* headers) {
uv_httpc_headers_t* dup = NULL, *tail = NULL; uv_httpc_headers_t *dup = NULL, *tail = NULL;
while (headers) { while (headers) {
uv_httpc_headers_t* header = malloc(sizeof * header); uv_httpc_headers_t* header = malloc(sizeof *header);
fatal_if_null(header); fatal_if_null(header);
header->data = strdup(headers->data); header->data = strdup(headers->data);
fatal_if_null(header->data); fatal_if_null(header->data);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#pragma once #pragma once
#include <uv.h> #include <uv.h>
#include "mybuf.h" #include "mybuf.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -17,7 +18,7 @@ typedef struct uv_httpc_s uv_httpc_t; ...@@ -17,7 +18,7 @@ typedef struct uv_httpc_s uv_httpc_t;
typedef struct uv_httpc_headers_s { typedef struct uv_httpc_headers_s {
char* data; char* data;
struct uv_httpc_headers_s* next; struct uv_httpc_headers_s* next;
}uv_httpc_headers_t; } uv_httpc_headers_t;
typedef enum { typedef enum {
uv_httpc_ok, uv_httpc_ok,
...@@ -26,7 +27,7 @@ typedef enum { ...@@ -26,7 +27,7 @@ typedef enum {
uv_httpc_connection_reset, uv_httpc_connection_reset,
uv_httpc_connection_timeout, uv_httpc_connection_timeout,
uv_httpc_parse_failed, uv_httpc_parse_failed,
}uv_httpc_code; } uv_httpc_code;
typedef struct uv_httpc_response_s { typedef struct uv_httpc_response_s {
uv_httpc_code code; uv_httpc_code code;
...@@ -35,9 +36,9 @@ typedef struct uv_httpc_response_s { ...@@ -35,9 +36,9 @@ typedef struct uv_httpc_response_s {
int http_status; int http_status;
char* body; char* body;
size_t len; size_t len;
}uv_httpc_response_t; } uv_httpc_response_t;
typedef void(*uv_httpc_on_response_t)(uv_httpc_t* httpc, uv_httpc_response_t* res); typedef void (*uv_httpc_on_response_t)(uv_httpc_t* httpc, uv_httpc_response_t* res);
int uv_httpc_create(uv_httpc_t** httpc, uv_loop_t* loop, const char* host, const char* port, int uv_httpc_create(uv_httpc_t** httpc, uv_loop_t* loop, const char* host, const char* port,
uv_httpc_on_response_t on_response); uv_httpc_on_response_t on_response);
...@@ -54,7 +55,6 @@ void uv_httpc_headers_free_all(uv_httpc_headers_t* headers, int freedata); ...@@ -54,7 +55,6 @@ void uv_httpc_headers_free_all(uv_httpc_headers_t* headers, int freedata);
int uv_httpc_test_main(int argc, char** argv); int uv_httpc_test_main(int argc, char** argv);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
#include "uv_httpd.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "uv_httpd.h"
#include "mybuf.h" #include "mybuf.h"
#include "uv_log.h" #include "uv_log.h"
#include "uv_tcp.h"
static int enable_print = 0; static int enable_print = 0;
#define dprintf if (enable_print) printf #define dprintf \
#define dnprintf if (enable_print) nprintf if (enable_print) printf
#define dnprintf \
if (enable_print) nprintf
#define print_func dprintf("%s\n", __FUNCTION__); #define print_func dprintf("%s\n", __FUNCTION__);
#define HEADERS_DEFAULT_LENGTH 16 #define HEADERS_DEFAULT_LENGTH 16
#define DEFAULT_BUFF_SIZE 1024 #define DEFAULT_BUFF_SIZE 1024
struct uv_httpd_client_s { struct uv_httpd_client_s {
uv_tcp_t tcp; uv_tcp_t tcp;
uv_httpd_server_t* server; uv_httpd_server_t* server;
...@@ -36,7 +39,6 @@ struct write_req_t { ...@@ -36,7 +39,6 @@ struct write_req_t {
static void on_close(uv_handle_t* peer); static void on_close(uv_handle_t* peer);
/*************************** helper functions ****************/ /*************************** helper functions ****************/
static void reset_request(uv_httpd_client_t* client) { static void reset_request(uv_httpd_client_t* client) {
...@@ -71,15 +73,13 @@ static void headers_append_value(uv_httpd_client_t* client, size_t offset, size_ ...@@ -71,15 +73,13 @@ static void headers_append_value(uv_httpd_client_t* client, size_t offset, size_
static int headers_contains(uv_httpd_client_t* client, const char* key, const char* value) { static int headers_contains(uv_httpd_client_t* client, const char* key, const char* value) {
for (size_t i = 0; i < client->req.headers.n; i++) { for (size_t i = 0; i < client->req.headers.n; i++) {
uv_httpd_header_t header = client->req.headers.headers[i]; uv_httpd_header_t header = client->req.headers.headers[i];
if(0 == string0_nicmp(key, client->req.base + header.key.offset, header.key.len) if (0 == string0_nicmp(key, client->req.base + header.key.offset, header.key.len) && 0 == string0_nicmp(value, client->req.base + header.value.offset, header.value.len)) {
&& 0 == string0_nicmp(value, client->req.base + header.value.offset, header.value.len)) {
return 1; return 1;
} }
} }
return 0; return 0;
} }
/*************************** llhttp callback functions ****************/ /*************************** llhttp callback functions ****************/
static int on_message_begin(llhttp_t* llhttp) { static int on_message_begin(llhttp_t* llhttp) {
...@@ -216,10 +216,10 @@ static int on_chunk_extension_name_complete(llhttp_t* llhttp) { ...@@ -216,10 +216,10 @@ static int on_chunk_extension_name_complete(llhttp_t* llhttp) {
return 0; return 0;
} }
//static int on_chunk_extension_value_complete(llhttp_t* llhttp) { // static int on_chunk_extension_value_complete(llhttp_t* llhttp) {
// print_func; // print_func;
// return 0; // return 0;
//} // }
static int on_chunk_header(llhttp_t* llhttp) { static int on_chunk_header(llhttp_t* llhttp) {
print_func; print_func;
...@@ -272,7 +272,8 @@ static void on_write(uv_write_t* req, int status) { ...@@ -272,7 +272,8 @@ static void on_write(uv_write_t* req, int status) {
} }
static void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { static void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
print_func; dprintf("suggested_size=%zu\n", suggested_size); print_func;
dprintf("suggested_size=%zu\n", suggested_size);
uv_httpd_client_t* client = handle->data; uv_httpd_client_t* client = handle->data;
mybuf_reserve(&client->buf, DEFAULT_BUFF_SIZE); mybuf_reserve(&client->buf, DEFAULT_BUFF_SIZE);
buf->base = client->buf.buf; buf->base = client->buf.buf;
...@@ -293,7 +294,8 @@ static void on_close(uv_handle_t* peer) { ...@@ -293,7 +294,8 @@ static void on_close(uv_handle_t* peer) {
} }
static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
print_func; dprintf("nread= %zd\n", nread); print_func;
dprintf("nread= %zd\n", nread);
uv_httpd_client_t* client = stream->data; uv_httpd_client_t* client = stream->data;
enum llhttp_errno parse_ret; enum llhttp_errno parse_ret;
...@@ -318,28 +320,11 @@ static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { ...@@ -318,28 +320,11 @@ static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
mybuf_clear(&client->buf); mybuf_clear(&client->buf);
} }
static int getpeeraddr(uv_tcp_t* tcp, char* ip, size_t len) {
struct sockaddr_in addr;
int addrlen = sizeof(addr);
int r = uv_tcp_getpeername(tcp, (struct sockaddr*)&addr, &addrlen);
if (r) {
warn_on_uv_err(r, "uv_tcp_getpeername");
return r;
}
r = uv_ip4_name(&addr, ip, len);
if (r) {
warn_on_uv_err(r, "uv_ip4_name");
}
if (len)
ip[len - 1] = '\0';
return r;
}
static void on_connected(uv_stream_t* stream, int status) { static void on_connected(uv_stream_t* stream, int status) {
print_func; print_func;
assert(status == 0); assert(status == 0);
uv_httpd_server_t* server = stream->data; uv_httpd_server_t* server = stream->data;
uv_httpd_client_t* client = malloc(sizeof * client); uv_httpd_client_t* client = malloc(sizeof *client);
fatal_if_null(client); fatal_if_null(client);
int r = uv_tcp_init(stream->loop, &client->tcp); int r = uv_tcp_init(stream->loop, &client->tcp);
fatal_on_uv_err(r, "uv_tcp_init failed"); fatal_on_uv_err(r, "uv_tcp_init failed");
...@@ -355,11 +340,10 @@ static void on_connected(uv_stream_t* stream, int status) { ...@@ -355,11 +340,10 @@ static void on_connected(uv_stream_t* stream, int status) {
mybuf_init(&client->pkt); mybuf_init(&client->pkt);
client->req.headers.headers = client->headers; client->req.headers.headers = client->headers;
client->req.headers.n = 0; client->req.headers.n = 0;
getpeeraddr(&client->tcp, client->req.ip, sizeof(client->req.ip)); getpeeraddr(&client->tcp, client->req.ip, sizeof(client->req.ip), NULL);
uv_read_start((uv_stream_t*)&client->tcp, on_alloc, on_read); uv_read_start((uv_stream_t*)&client->tcp, on_alloc, on_read);
} }
/*************************** public functions ****************/ /*************************** public functions ****************/
void nprintf(const char* at, size_t len, int newline) { void nprintf(const char* at, size_t len, int newline) {
...@@ -460,8 +444,7 @@ void uv_httpd_free(uv_httpd_server_t* server) { ...@@ -460,8 +444,7 @@ void uv_httpd_free(uv_httpd_server_t* server) {
free(server); free(server);
} }
int uv_httpd_listen(uv_httpd_server_t* server, const char* ip, int port) int uv_httpd_listen(uv_httpd_server_t* server, const char* ip, int port) {
{
int r; int r;
struct sockaddr_in addr; struct sockaddr_in addr;
...@@ -477,9 +460,8 @@ int uv_httpd_listen(uv_httpd_server_t* server, const char* ip, int port) ...@@ -477,9 +460,8 @@ int uv_httpd_listen(uv_httpd_server_t* server, const char* ip, int port)
return r; return r;
} }
int uv_httpd_write_response(uv_httpd_client_t* client, char* response, size_t len) int uv_httpd_write_response(uv_httpd_client_t* client, char* response, size_t len) {
{ struct write_req_t* req = malloc(sizeof *req);
struct write_req_t* req = malloc(sizeof * req);
if (!req) return UV_ENOMEM; if (!req) return UV_ENOMEM;
req->buf.base = malloc(len); req->buf.base = malloc(len);
if (!req->buf.base) { if (!req->buf.base) {
......
#include <stdio.h> #include "uv_log.h"
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <uv.h> #include <uv.h>
#include "uv_log.h"
static uv_log_level_t g_level = uv_log_level_info; static uv_log_level_t g_level = uv_log_level_info;
static char g_logfile[1024] = { 0 }; static char g_logfile[1024] = {0};
void uv_log_set_level(uv_log_level_t level) { void uv_log_set_level(uv_log_level_t level) {
g_level = level; g_level = level;
...@@ -46,7 +47,7 @@ void uv_log_raw(uv_log_level_t level, const char* msg) { ...@@ -46,7 +47,7 @@ void uv_log_raw(uv_log_level_t level, const char* msg) {
static void uv_log_vprintf(uv_log_level_t level, const char* fmt, va_list ap) { static void uv_log_vprintf(uv_log_level_t level, const char* fmt, va_list ap) {
va_list cpy; va_list cpy;
char msg[1024], * p = msg; char msg[1024], *p = msg;
size_t len = sizeof(msg); size_t len = sizeof(msg);
int l = 0; int l = 0;
...@@ -80,5 +81,4 @@ void uv_log(uv_log_level_t level, const char* fmt, ...) { ...@@ -80,5 +81,4 @@ void uv_log(uv_log_level_t level, const char* fmt, ...) {
va_start(ap, fmt); va_start(ap, fmt);
uv_log_vprintf(level, fmt, ap); uv_log_vprintf(level, fmt, ap);
va_end(ap); va_end(ap);
} }
...@@ -17,7 +17,7 @@ typedef enum { ...@@ -17,7 +17,7 @@ typedef enum {
uv_log_level_error, uv_log_level_error,
uv_log_level_fatal, uv_log_level_fatal,
uv_log_level_raw = 1 << 10, // modifier to log without timestamp uv_log_level_raw = 1 << 10, // modifier to log without timestamp
}uv_log_level_t; } uv_log_level_t;
void uv_log_set_level(uv_log_level_t level); void uv_log_set_level(uv_log_level_t level);
void uv_log_set_log_file(const char* file); void uv_log_set_log_file(const char* file);
...@@ -34,32 +34,32 @@ void uv_log_raw(uv_log_level_t level, const char* msg); ...@@ -34,32 +34,32 @@ void uv_log_raw(uv_log_level_t level, const char* msg);
#define uvlog_fatal(...) uv_log(uv_log_level_fatal, __VA_ARGS__) #define uvlog_fatal(...) uv_log(uv_log_level_fatal, __VA_ARGS__)
#define warn_on_uv_err(r, msg) \ #define warn_on_uv_err(r, msg) \
do { \ do { \
if (r) { \ if (r) { \
uvlog_warn("WARN: %s:%d %s: %d %s %s", \ uvlog_warn("WARN: %s:%d %s: %d %s %s", \
__FILE__, __LINE__, \ __FILE__, __LINE__, \
(msg), (r), uv_err_name((r)), uv_strerror((r))); \ (msg), (r), uv_err_name((r)), uv_strerror((r))); \
} \ } \
} while (0); } while (0);
#define fatal_on_uv_err(r, msg) \ #define fatal_on_uv_err(r, msg) \
do { \ do { \
if ((r)) { \ if ((r)) { \
uvlog_fatal("FATAL %s:%d %s: %d %s %s", \ uvlog_fatal("FATAL %s:%d %s: %d %s %s", \
__FILE__, __LINE__, \ __FILE__, __LINE__, \
(msg), r, uv_err_name(r), uv_strerror((r))); \ (msg), r, uv_err_name(r), uv_strerror((r))); \
exit(r); \ exit(r); \
} \ } \
} while (0); } while (0);
#define fatal_if_null(p) \ #define fatal_if_null(p) \
do { \ do { \
if ((p) == NULL) { \ if ((p) == NULL) { \
uvlog_fatal("FATAL %s:%d malloc failed", \ uvlog_fatal("FATAL %s:%d malloc failed", \
__FILE__, __LINE__); \ __FILE__, __LINE__); \
abort(); \ abort(); \
} \ } \
} while (0); } while (0);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
#include "uv_tcp.h"
#include "uv_log.h"
int getpeeraddr(uv_tcp_t* tcp, char* ip, size_t len, uint16_t* port) {
struct sockaddr_in addr;
int addrlen = sizeof(addr);
int r = uv_tcp_getpeername(tcp, (struct sockaddr*)&addr, &addrlen);
if (r) {
warn_on_uv_err(r, "uv_tcp_getpeername");
return r;
}
r = uv_ip4_name(&addr, ip, len);
if (r) {
warn_on_uv_err(r, "uv_ip4_name");
}
if (len)
ip[len - 1] = '\0';
if (port) {
*port = ntohs(addr.sin_port);
}
return r;
}
...@@ -5,23 +5,20 @@ ...@@ -5,23 +5,20 @@
#include <uv.h> #include <uv.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef enum { typedef enum {
uv_tcp_parse_ok = 0, uv_tcp_parse_ok = 0,
uv_tcp_parse_not_enough, uv_tcp_parse_not_enough,
uv_tcp_parse_error, uv_tcp_parse_error,
}uv_tcp_parse_result_t; } uv_tcp_parse_result_t;
int getpeeraddr(uv_tcp_t* tcp, char* ip, size_t len, uint16_t* port);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif
#include "uv_tcpclient.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "uv_tcpclient.h"
#include "uv_log.h"
#include "mybuf.h" #include "mybuf.h"
#include "uv_log.h"
#define DEFAULT_BUFF_SIZE 1024 #define DEFAULT_BUFF_SIZE 1024
typedef struct { typedef struct {
uv_write_t req; uv_write_t req;
uv_buf_t buf; uv_buf_t buf;
}write_req_t; } write_req_t;
static void client_init(uv_tcpclient_t* cli) { static void client_init(uv_tcpclient_t* cli) {
cli->data = NULL; cli->data = NULL;
...@@ -166,7 +168,6 @@ static void on_resolved(uv_getaddrinfo_t* resolver, int status, struct addrinfo* ...@@ -166,7 +168,6 @@ static void on_resolved(uv_getaddrinfo_t* resolver, int status, struct addrinfo*
uv_freeaddrinfo(res); uv_freeaddrinfo(res);
} }
/********************************** uv_tcpclient_t functions ****************************/ /********************************** uv_tcpclient_t functions ****************************/
int uv_tcpclient_new(uv_tcpclient_t** client, uv_loop_t* loop, uv_tcpclient_settings_t* settings) { int uv_tcpclient_new(uv_tcpclient_t** client, uv_loop_t* loop, uv_tcpclient_settings_t* settings) {
...@@ -207,7 +208,7 @@ int uv_tcpclient_start(uv_tcpclient_t* cli, const char* domain, const char* port ...@@ -207,7 +208,7 @@ int uv_tcpclient_start(uv_tcpclient_t* cli, const char* domain, const char* port
void uv_tcpclient_send(uv_tcpclient_t* client, const char* buf, size_t len) { void uv_tcpclient_send(uv_tcpclient_t* client, const char* buf, size_t len) {
if (!client->connected) return; if (!client->connected) return;
write_req_t* req = malloc(sizeof * req); write_req_t* req = malloc(sizeof *req);
fatal_if_null(req); fatal_if_null(req);
req->buf.base = malloc(len); req->buf.base = malloc(len);
fatal_if_null(req->buf.base); fatal_if_null(req->buf.base);
......
...@@ -3,20 +3,19 @@ ...@@ -3,20 +3,19 @@
#pragma once #pragma once
#include "uv_tcp.h"
#include "mybuf.h" #include "mybuf.h"
#include "uv_tcp.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef struct uv_tcpclient_s uv_tcpclient_t; typedef struct uv_tcpclient_s uv_tcpclient_t;
typedef struct uv_tcpclient_settings_s uv_tcpclient_settings_t; typedef struct uv_tcpclient_settings_s uv_tcpclient_settings_t;
typedef uv_tcp_parse_result_t(*uv_tcpclient_on_parse_t)(uv_tcpclient_t* client, const char* buf, size_t len, size_t* ate); typedef uv_tcp_parse_result_t (*uv_tcpclient_on_parse_t)(uv_tcpclient_t* client, const char* buf, size_t len, size_t* ate);
typedef void(*uv_tcpclient_on_connect_t)(uv_tcpclient_t* client, int connected); typedef void (*uv_tcpclient_on_connect_t)(uv_tcpclient_t* client, int connected);
typedef void(*uv_tcpclient_on_closed_t)(uv_tcpclient_t* client); typedef void (*uv_tcpclient_on_closed_t)(uv_tcpclient_t* client);
int uv_tcpclient_new(uv_tcpclient_t** client, uv_loop_t* loop, uv_tcpclient_settings_t* settings); int uv_tcpclient_new(uv_tcpclient_t** client, uv_loop_t* loop, uv_tcpclient_settings_t* settings);
int uv_tcpclient_start(uv_tcpclient_t* client, const char* domain, const char* port); int uv_tcpclient_start(uv_tcpclient_t* client, const char* domain, const char* port);
...@@ -24,7 +23,6 @@ void uv_tcpclient_send(uv_tcpclient_t* client, const char* buf, size_t len); ...@@ -24,7 +23,6 @@ void uv_tcpclient_send(uv_tcpclient_t* client, const char* buf, size_t len);
void uv_tcpclient_stop(uv_tcpclient_t* client); void uv_tcpclient_stop(uv_tcpclient_t* client);
void uv_tcpclient_free(uv_tcpclient_t* client); void uv_tcpclient_free(uv_tcpclient_t* client);
struct uv_tcpclient_settings_s { struct uv_tcpclient_settings_s {
uv_tcpclient_on_connect_t on_connect; uv_tcpclient_on_connect_t on_connect;
uv_tcpclient_on_parse_t on_parse; uv_tcpclient_on_parse_t on_parse;
...@@ -46,8 +44,6 @@ struct uv_tcpclient_s { ...@@ -46,8 +44,6 @@ struct uv_tcpclient_s {
int enable_reconn; int enable_reconn;
}; };
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
#include "uv_tcpserver.h" #include "uv_tcpserver.h"
#include "uv_log.h"
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include "uv_log.h"
#define DEFAULT_BUFF_SIZE 1024 #define DEFAULT_BUFF_SIZE 1024
typedef struct { typedef struct {
uv_write_t req; uv_write_t req;
uv_buf_t buf; uv_buf_t buf;
}write_req_t; } write_req_t;
static void on_close_server(uv_handle_t* handle) { static void on_close_server(uv_handle_t* handle) {
uv_tcpserver_t* server = handle->data; uv_tcpserver_t* server = handle->data;
...@@ -51,11 +52,7 @@ static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { ...@@ -51,11 +52,7 @@ static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
mybuf_clear(&cli->buf); mybuf_clear(&cli->buf);
} else if (p != cli->buf.buf) { } else if (p != cli->buf.buf) {
if (total > 0) { if (total > 0) {
mybuf_t buf; mybuf_clear_append(&cli->buf, p, total);
mybuf_init(&buf);
mybuf_append(&buf, p, total);
mybuf_clear(&cli->buf);
mybuf_append(&cli->buf, buf.buf, buf.size);
} else { } else {
mybuf_clear(&cli->buf); mybuf_clear(&cli->buf);
} }
...@@ -86,7 +83,7 @@ static void on_connection(uv_stream_t* server, int status) { ...@@ -86,7 +83,7 @@ static void on_connection(uv_stream_t* server, int status) {
return; return;
} }
client = malloc(sizeof * client); client = malloc(sizeof *client);
fatal_if_null(client); fatal_if_null(client);
do { do {
...@@ -112,7 +109,7 @@ static void on_connection(uv_stream_t* server, int status) { ...@@ -112,7 +109,7 @@ static void on_connection(uv_stream_t* server, int status) {
int uv_tcpserver_create(uv_tcpserver_t** server, uv_loop_t* loop, uv_tcpserver_settings_t* settings) { int uv_tcpserver_create(uv_tcpserver_t** server, uv_loop_t* loop, uv_tcpserver_settings_t* settings) {
int r; int r;
uv_tcpserver_t* ptr = malloc(sizeof * ptr); uv_tcpserver_t* ptr = malloc(sizeof *ptr);
if (!ptr) return UV_ENOMEM; if (!ptr) return UV_ENOMEM;
r = uv_tcp_init(loop, &ptr->tcp); r = uv_tcp_init(loop, &ptr->tcp);
if (r) { if (r) {
...@@ -163,7 +160,7 @@ static void after_write(uv_write_t* req, int status) { ...@@ -163,7 +160,7 @@ static void after_write(uv_write_t* req, int status) {
int uv_tcpserver_send_to_cli(uv_tcpserver_client_context_t* cli, const char* buf, size_t len) { int uv_tcpserver_send_to_cli(uv_tcpserver_client_context_t* cli, const char* buf, size_t len) {
int r; int r;
write_req_t* req; write_req_t* req;
req = malloc(sizeof * req); req = malloc(sizeof *req);
if (!req) return UV_ENOMEM; if (!req) return UV_ENOMEM;
req->buf.base = malloc(len); req->buf.base = malloc(len);
if (!req->buf.base) { if (!req->buf.base) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#pragma once #pragma once
#include <uv.h> #include <uv.h>
#include "mybuf.h" #include "mybuf.h"
#include "uv_tcp.h" #include "uv_tcp.h"
...@@ -14,9 +15,9 @@ extern "C" { ...@@ -14,9 +15,9 @@ extern "C" {
typedef struct uv_tcpserver_s uv_tcpserver_t; typedef struct uv_tcpserver_s uv_tcpserver_t;
typedef struct uv_tcpserver_client_context_s uv_tcpserver_client_context_t; typedef struct uv_tcpserver_client_context_s uv_tcpserver_client_context_t;
typedef void(*uv_tcpserver_on_connection_t)(uv_tcpserver_client_context_t* client, int connected); typedef void (*uv_tcpserver_on_connection_t)(uv_tcpserver_client_context_t* client, int connected);
typedef uv_tcp_parse_result_t(*uv_tcpserver_on_parse_t)(uv_tcpserver_client_context_t* client, const char* buf, size_t len, size_t* ate); typedef uv_tcp_parse_result_t (*uv_tcpserver_on_parse_t)(uv_tcpserver_client_context_t* client, const char* buf, size_t len, size_t* ate);
typedef void(*uv_tcpserver_on_server_shutdown_t)(uv_tcpserver_t* server); typedef void (*uv_tcpserver_on_server_shutdown_t)(uv_tcpserver_t* server);
typedef struct uv_tcpserver_settings_s uv_tcpserver_settings_t; typedef struct uv_tcpserver_settings_s uv_tcpserver_settings_t;
int uv_tcpserver_create(uv_tcpserver_t** server, uv_loop_t* loop, uv_tcpserver_settings_t* settings); int uv_tcpserver_create(uv_tcpserver_t** server, uv_loop_t* loop, uv_tcpserver_settings_t* settings);
...@@ -28,12 +29,6 @@ void uv_tcpserver_close_cli(uv_tcpserver_client_context_t* cli); ...@@ -28,12 +29,6 @@ void uv_tcpserver_close_cli(uv_tcpserver_client_context_t* cli);
void uv_tcpserver_free_cli_ctx(uv_tcpserver_client_context_t* cli); void uv_tcpserver_free_cli_ctx(uv_tcpserver_client_context_t* cli);
int uv_tcpserver_send_to_cli(uv_tcpserver_client_context_t* cli, const char* buf, size_t len); int uv_tcpserver_send_to_cli(uv_tcpserver_client_context_t* cli, const char* buf, size_t len);
struct uv_tcpserver_s { struct uv_tcpserver_s {
void* data; void* data;
uv_tcp_t tcp; uv_tcp_t tcp;
......
#ifndef __UVLIB_H__
#define __UVLIB_H__
#pragma once
#include "list.h"
#include "mybuf.h"
#include "uv_httpc.h"
#include "uv_httpd.h"
#include "uv_log.h"
#include "uv_tcpclient.h"
#include "uv_tcpserver.h"
#ifdef _WIN32
#define UVLIB_DIR "G:/dev_libs/ademco/"
#ifdef UVLIB_USE_MT
#define UVLIB_NAME "uvlib_mt.lib"
#else
#define UVLIB_NAME "uvlib.lib"
#endif
#ifdef _WIN64
#ifdef _DEBUG
#pragma comment(lib, UVLIB_DIR "x64/Debug/" UVLIB_NAME)
#else
#pragma comment(lib, UVLIB_DIR "x64/Release/" UVLIB_NAME)
#endif
#else // WIN32
#ifdef _DEBUG
#pragma comment(lib, UVLIB_DIR "Debug/" UVLIB_NAME)
#else
#pragma comment(lib, UVLIB_DIR "Release/" UVLIB_NAME)
#endif
#endif
#endif // _WIN32
#endif
...@@ -115,18 +115,17 @@ int hbIsValidZoneStrict(HbMachineType type, uint16_t zone) { ...@@ -115,18 +115,17 @@ int hbIsValidZoneStrict(HbMachineType type, uint16_t zone) {
} }
int hbMachineIsSelling(HbMachineType type) { int hbMachineIsSelling(HbMachineType type) {
return type == HMT_NETMOD return type == HMT_GPRS_IOT ||
|| type == HMT_GPRS type == HMT_NETMOD ||
|| type == HMT_GPRS_IOT type == HMT_GPRS ||
|| type == HMT_IOT type == HMT_IOT ||
|| type == HMT_LCD type == HMT_LCD ||
|| type == HMT_WIRED type == HMT_WIRED ||
|| type == HMT_TRUE_COLOR type == HMT_TRUE_COLOR ||
|| type == HMT_3_SECTION type == HMT_3_SECTION ||
|| type == HMT_GPRS_PHONE type == HMT_GPRS_PHONE ||
|| type == HMT_NB type == HMT_NB ||
|| type == HMT_WIFI2 type == HMT_WIFI2;
;
} }
int hbMachineCanArm(HbMachineType type) { int hbMachineCanArm(HbMachineType type) {
...@@ -142,37 +141,32 @@ int hbMachineCanEnterSettings(HbMachineType type) { ...@@ -142,37 +141,32 @@ int hbMachineCanEnterSettings(HbMachineType type) {
} }
int hbMachineCanHalfArm(HbMachineType type) { int hbMachineCanHalfArm(HbMachineType type) {
return type == HMT_NETMOD return type == HMT_NETMOD || type == HMT_LCD;
|| type == HMT_LCD
;
} }
int hbMachineCanReportSignalStrength(HbMachineType type) { int hbMachineCanReportSignalStrength(HbMachineType type) {
return type == HMT_GPRS return type == HMT_GPRS ||
|| type == HMT_GPRS_IOT type == HMT_GPRS_IOT ||
|| type == HMT_IOT type == HMT_IOT ||
|| type == HMT_LCD type == HMT_LCD ||
|| type == HMT_TRUE_COLOR type == HMT_TRUE_COLOR ||
|| type == HMT_3_SECTION type == HMT_3_SECTION ||
|| type == HMT_GPRS_PHONE type == HMT_GPRS_PHONE ||
|| type == HMT_NB type == HMT_NB;
;
} }
int hbMachineCanReportBySMS(HbMachineType type) { int hbMachineCanReportBySMS(HbMachineType type) {
return type == HMT_GPRS return type == HMT_GPRS ||
|| type == HMT_LCD type == HMT_LCD ||
|| type == HMT_TRUE_COLOR type == HMT_TRUE_COLOR ||
|| type == HMT_3_SECTION type == HMT_3_SECTION ||
|| type == HMT_GPRS_PHONE type == HMT_GPRS_PHONE;
;
} }
int hbMachineHasWiredZone(HbMachineType type) { int hbMachineHasWiredZone(HbMachineType type) {
return type == HMT_NETMOD return type == HMT_NETMOD ||
|| type == HMT_TRUE_COLOR type == HMT_TRUE_COLOR ||
|| type == HMT_3_SECTION type == HMT_3_SECTION;
;
} }
AdemcoZone hbWiredZoneMin(HbMachineType type) { AdemcoZone hbWiredZoneMin(HbMachineType type) {
...@@ -464,10 +458,10 @@ int hbCheckSum(const uint8_t* data, size_t len) { ...@@ -464,10 +458,10 @@ int hbCheckSum(const uint8_t* data, size_t len) {
} }
#define copy_data_to_com \ #define copy_data_to_com \
if (cd) { \ if (cd) { \
cd->len = len & 0xFF; \ cd->len = len & 0xFF; \
memcpy(cd->data, data, len & 0xFF); \ memcpy(cd->data, data, len & 0xFF); \
} }
HbComRequestType hbComParseRequest(const uint8_t* data, size_t len, HbComData* cd) { HbComRequestType hbComParseRequest(const uint8_t* data, size_t len, HbComData* cd) {
do { do {
......
/* /*
* Hengbo COM library * Hengbo COM library
* captainwong * captainwong
* 2022-8-12 rewrited this C version * 2022-8-12 rewrited this C version
*/ */
#ifndef __HB_COM_H__ #ifndef __HB_COM_H__
#define __HB_COM_H__ #define __HB_COM_H__
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "ademco.h" #include "ademco.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -33,7 +32,7 @@ typedef enum HbMachineStatus { ...@@ -33,7 +32,7 @@ typedef enum HbMachineStatus {
HMS_SETTING, // 设置 HMS_SETTING, // 设置
HMS_COUNT, HMS_COUNT,
HMS_INVALID = -1, HMS_INVALID = -1,
}HbMachineStatus; } HbMachineStatus;
typedef enum HbMachineType { typedef enum HbMachineType {
//! 0 WiFi主机 (已停用) //! 0 WiFi主机 (已停用)
...@@ -65,7 +64,7 @@ typedef enum HbMachineType { ...@@ -65,7 +64,7 @@ typedef enum HbMachineType {
HMT_COUNT, HMT_COUNT,
HMT_INVALID = -1, HMT_INVALID = -1,
}HbMachineType; } HbMachineType;
typedef enum HbZoneProperty { typedef enum HbZoneProperty {
//! 匪警全局 //! 匪警全局
...@@ -104,27 +103,27 @@ typedef enum HbZoneProperty { ...@@ -104,27 +103,27 @@ typedef enum HbZoneProperty {
HZP_COUNT, HZP_COUNT,
HZP_INVALID = -1, HZP_INVALID = -1,
}HbZoneProperty; } HbZoneProperty;
typedef struct HbZoneAndProperty { typedef struct HbZoneAndProperty {
AdemcoZone zone; AdemcoZone zone;
HbZoneProperty prop; HbZoneProperty prop;
}HbZoneAndProperty; } HbZoneAndProperty;
typedef struct HbMachineTimePoint { typedef struct HbMachineTimePoint {
uint8_t hour; uint8_t hour;
uint8_t minute; uint8_t minute;
}HbMachineTimePoint; } HbMachineTimePoint;
typedef struct HbTimer { typedef struct HbTimer {
HbMachineTimePoint armAt; HbMachineTimePoint armAt;
HbMachineTimePoint disarmAt; HbMachineTimePoint disarmAt;
}HbTimer; } HbTimer;
typedef union HbMachineTimer { typedef union HbMachineTimer {
HbTimer timer[2]; // 2 set of timer HbTimer timer[2]; // 2 set of timer
uint8_t data[8]; uint8_t data[8];
}HbMachineTimer; } HbMachineTimer;
// 串口透传数据最大长度 // 串口透传数据最大长度
#define HB_COM_DATA_MAX_LEN 64 #define HB_COM_DATA_MAX_LEN 64
...@@ -133,7 +132,7 @@ typedef union HbMachineTimer { ...@@ -133,7 +132,7 @@ typedef union HbMachineTimer {
typedef struct HbComData { typedef struct HbComData {
uint8_t data[HB_COM_DATA_MAX_LEN]; uint8_t data[HB_COM_DATA_MAX_LEN];
uint8_t len; uint8_t len;
}HbComData; } HbComData;
// 发给主机 // 发给主机
typedef enum HbComRequestType { typedef enum HbComRequestType {
...@@ -152,7 +151,7 @@ typedef enum HbComRequestType { ...@@ -152,7 +151,7 @@ typedef enum HbComRequestType {
HbComReq_RD_acct, // 读取主机账号 HbComReq_RD_acct, // 读取主机账号
HbComReq_WR_acct, // 写入主机账号 HbComReq_WR_acct, // 写入主机账号
HbComReq_Invalid = -1, HbComReq_Invalid = -1,
}HbComRequestType; } HbComRequestType;
// 主机回应 // 主机回应
typedef enum HbComResponseType { typedef enum HbComResponseType {
...@@ -169,7 +168,7 @@ typedef enum HbComResponseType { ...@@ -169,7 +168,7 @@ typedef enum HbComResponseType {
HbComResp_AF, // 三区段主机布撤防命令回应 HbComResp_AF, // 三区段主机布撤防命令回应
HbComResp_B1, // 三区段主机状态回应 HbComResp_B1, // 三区段主机状态回应
HbComResp_Invalid = -1, HbComResp_Invalid = -1,
}HbComResponseType; } HbComResponseType;
//! 索要主机状态 EB AB 3F A0 75 //! 索要主机状态 EB AB 3F A0 75
#define HbComReq_A0_len 5 #define HbComReq_A0_len 5
...@@ -184,19 +183,22 @@ typedef enum HbComResponseType { ...@@ -184,19 +183,22 @@ typedef enum HbComResponseType {
#define HbComReq_A1_data "\xEB\xAB\x3F\xA1\x76" #define HbComReq_A1_data "\xEB\xAB\x3F\xA1\x76"
//! 回应主机防区 EB BA 3F PN P0 A2 [Z, P]xN P1 SUM //! 回应主机防区 EB BA 3F PN P0 A2 [Z, P]xN P1 SUM
#define HbComResp_A2_len_min 8 // 无防区数据时长度最小为8 // 无防区数据时长度最小为8
#define HbComResp_A2_max_zone 20 // 最多可以包含 20 个防区 #define HbComResp_A2_len_min 8
#define HbComResp_A2_len_max (HbComResp_A2_len_min + HbComResp_A2_max_zone * 2) // 一包数据最多有8+20*2=48个字节 // 最多可以包含 20 个防区
#define HbComResp_A2_max_zone 20
// 一包数据最多有8+20*2=48个字节
#define HbComResp_A2_len_max (HbComResp_A2_len_min + HbComResp_A2_max_zone * 2)
typedef enum HbComResp_A2_p1 { typedef enum HbComResp_A2_p1 {
HbComResp_A2_p1_nomore = 0xFF, // 无更多防区 HbComResp_A2_p1_nomore = 0xFF, // 无更多防区
HbComResp_A2_p1_more = 0x00, // 还有更多防区 HbComResp_A2_p1_more = 0x00, // 还有更多防区
}HbComResp_A2_p1; } HbComResp_A2_p1;
#define HbComResp_A2_head "\xEB\xBA\x3F\x08\xCC\xA2" #define HbComResp_A2_head "\xEB\xBA\x3F\x08\xCC\xA2"
typedef struct HbComResp_A2_Iter { typedef struct HbComResp_A2_Iter {
HbComData com; HbComData com;
uint8_t i, total; uint8_t i, total;
HbComResp_A2_p1 p1; HbComResp_A2_p1 p1;
}HbComResp_A2_Iter; } HbComResp_A2_Iter;
//! 索要更多主机防区 EB AB 3F A2 77 //! 索要更多主机防区 EB AB 3F A2 77
//! 仅应在收到ZoneResponse的param非0xFF时发送,以索要全部防区 //! 仅应在收到ZoneResponse的param非0xFF时发送,以索要全部防区
...@@ -212,10 +214,11 @@ typedef enum HbComReq_A3_p3 { ...@@ -212,10 +214,11 @@ typedef enum HbComReq_A3_p3 {
HbComReq_A3_p3_learn = 0x01, //! 学码 HbComReq_A3_p3_learn = 0x01, //! 学码
HbComReq_A3_p3_stop = 0x02, //! 停止学码 HbComReq_A3_p3_stop = 0x02, //! 停止学码
HbComReq_A3_p3_modify = 0x03, //! 修改防区属性 HbComReq_A3_p3_modify = 0x03, //! 修改防区属性
}HbComReq_A3_op; } HbComReq_A3_op;
//! 学码开始回应 EB BA 3F 07 P0 A3 5A //! 学码开始回应 EB BA 3F 07 P0 A3 5A
//! 因为学码时主机要等待外部无线信号(用户触发探测器),因此先回应A3表示已经开始学码,学码成功时回 ZoneOpResponse A4 //! 因为学码时主机要等待外部无线信号(用户触发探测器),
//! 因此先回应A3表示已经开始学码,学码成功时回 ZoneOpResponse A4
#define HbComResp_A3_len 7 #define HbComResp_A3_len 7
#define HbComResp_A3_data "\xEB\xBA\x3F\x07\xCC\xA3\x5A" #define HbComResp_A3_data "\xEB\xBA\x3F\x07\xCC\xA3\x5A"
...@@ -227,7 +230,7 @@ typedef enum HbComResp_A4_p3 { ...@@ -227,7 +230,7 @@ typedef enum HbComResp_A4_p3 {
HbComResp_A4_p3_ok = 0x01, //! 成功 HbComResp_A4_p3_ok = 0x01, //! 成功
HbComResp_A4_p3_dup = 0x02, //! 失败--重码 HbComResp_A4_p3_dup = 0x02, //! 失败--重码
HbComResp_A4_p3_ne = 0x03, //! 失败--防区未对码 not exists HbComResp_A4_p3_ne = 0x03, //! 失败--防区未对码 not exists
}HbComResp_A4_p3; } HbComResp_A4_p3;
//! 获取主机定时器 EB AB 3F A5 7A //! 获取主机定时器 EB AB 3F A5 7A
#define HbComReq_A5_len 5 #define HbComReq_A5_len 5
...@@ -262,7 +265,7 @@ typedef enum HbComResp_AB_p2 { ...@@ -262,7 +265,7 @@ typedef enum HbComResp_AB_p2 {
HbComResp_AB_p2_close = 0, // 防区失联关 HbComResp_AB_p2_close = 0, // 防区失联关
HbComResp_AB_p2_open = 1, // 防区失联开 HbComResp_AB_p2_open = 1, // 防区失联开
HbComResp_AB_p2_reject = 2, // 拒绝操作 HbComResp_AB_p2_reject = 2, // 拒绝操作
}HbComResp_AB_p2; } HbComResp_AB_p2;
//! 索要防区探头遗失/失联 第一次索要 EB AB 3F AC 81 //! 索要防区探头遗失/失联 第一次索要 EB AB 3F AC 81
#define HbComReq_AC_len 5 #define HbComReq_AC_len 5
...@@ -273,30 +276,33 @@ typedef enum HbComResp_AB_p2 { ...@@ -273,30 +276,33 @@ typedef enum HbComResp_AB_p2 {
#define HbComReq_AD_data "\xEB\xAB\x3F\xAD\x82" #define HbComReq_AD_data "\xEB\xAB\x3F\xAD\x82"
//! 索要防区探头遗失/失联回应 EB BA 3F PN P0 AD P1 DATA P2 SUM //! 索要防区探头遗失/失联回应 EB BA 3F PN P0 AD P1 DATA P2 SUM
#define HbComResp_AD_len_min 9 // 无防区失联数据时一包长度最小为9 // 无防区失联数据时一包长度最小为9
#define HbComResp_AD_max_zone 20 // 一包最多包含20个防区 #define HbComResp_AD_len_min 9
#define HbComResp_AD_len_max (HbComResp_AD_len_min + HbComResp_AD_max_zone * 2) // 一包最多有 9 + 20 *2 = 49 个字节 // 一包最多包含20个防区
#define HbComResp_AD_max_zone 20
// 一包最多有 9 + 20 *2 = 49 个字节
#define HbComResp_AD_len_max (HbComResp_AD_len_min + HbComResp_AD_max_zone * 2)
typedef enum HbComResp_AD_p1 { typedef enum HbComResp_AD_p1 {
HbComResp_AD_p1_single = 0xF0, // 防区号以单字节表示 HbComResp_AD_p1_single = 0xF0, // 防区号以单字节表示
HbComResp_AD_p1_double = 0xF1, // 防区号以双字节表示 HbComResp_AD_p1_double = 0xF1, // 防区号以双字节表示
}HbComResp_AD_p1; } HbComResp_AD_p1;
typedef enum HbComResp_AD_p2 { typedef enum HbComResp_AD_p2 {
HbComResp_AD_p2_nomore = 0xFF, // 无更多防区 HbComResp_AD_p2_nomore = 0xFF, // 无更多防区
HbComResp_AD_p2_more = 0x00, // 还有更多防区 HbComResp_AD_p2_more = 0x00, // 还有更多防区
}HbComResp_AD_p2; } HbComResp_AD_p2;
#define HbComResp_AD_head "\xEB\xBA\x3F\x09\xCC\xAD" #define HbComResp_AD_head "\xEB\xBA\x3F\x09\xCC\xAD"
typedef enum HbCom_3sec_status { typedef enum HbCom_3sec_status {
HbCom_3sec_arm = 0x00, // 布防(成功) HbCom_3sec_arm = 0x00, // 布防(成功)
HbCom_3sec_disarm = 0x01, // 撤防(成功) HbCom_3sec_disarm = 0x01, // 撤防(成功)
}HbCom_3sec_status; } HbCom_3sec_status;
typedef enum HbCom_3sec_which { typedef enum HbCom_3sec_which {
HbCom_3sec_machine, // 主机 HbCom_3sec_machine, // 主机
HbCom_3sec_section1, // 区段1 HbCom_3sec_section1, // 区段1
HbCom_3sec_section2, // 区段2 HbCom_3sec_section2, // 区段2
HbCom_3sec_section3, // 区段3 HbCom_3sec_section3, // 区段3
}HbCom_3sec_which; } HbCom_3sec_which;
//! 三区段主机布撤防命令 EB CB 3F 08 AE P1 P2 SUM //! 三区段主机布撤防命令 EB CB 3F 08 AE P1 P2 SUM
#define HbComReq_AE_len 8 #define HbComReq_AE_len 8
...@@ -318,7 +324,6 @@ typedef enum HbCom_3sec_which { ...@@ -318,7 +324,6 @@ typedef enum HbCom_3sec_which {
#define hbComResp_B1_status2(d) ((((d)[6] >> 2) & 0x03) == HbCom_3sec_arm ? HMS_ARM : HMS_DISARM) #define hbComResp_B1_status2(d) ((((d)[6] >> 2) & 0x03) == HbCom_3sec_arm ? HMS_ARM : HMS_DISARM)
#define hbComResp_B1_status3(d) ((((d)[6]) & 0x03) == HbCom_3sec_arm ? HMS_ARM : HMS_DISARM) #define hbComResp_B1_status3(d) ((((d)[6]) & 0x03) == HbCom_3sec_arm ? HMS_ARM : HMS_DISARM)
//! 读取主机账号 //! 读取主机账号
#define HbComReq_RD_acct_len 7 #define HbComReq_RD_acct_len 7
#define HbComReq_RD_acct_data "\xEB\xBA\x3F\x07\x00\x4C\x37" #define HbComReq_RD_acct_data "\xEB\xBA\x3F\x07\x00\x4C\x37"
...@@ -337,8 +342,7 @@ typedef enum HbCom_3sec_which { ...@@ -337,8 +342,7 @@ typedef enum HbCom_3sec_which {
static const HbZoneProperty hbZoneProperties[12] = { static const HbZoneProperty hbZoneProperties[12] = {
HZP_BUGLAR, HZP_EMERGENCY, HZP_FIRE, HZP_DURESS, HZP_GAS, HZP_WATER, HZP_SUB_MACHINE, HZP_BUGLAR, HZP_EMERGENCY, HZP_FIRE, HZP_DURESS, HZP_GAS, HZP_WATER, HZP_SUB_MACHINE,
HZP_REMOTE_CONTROL, HZP_BUGLAR_HALF, HZP_SHIELD, HZP_DOOR_RING, HZP_BYPASS HZP_REMOTE_CONTROL, HZP_BUGLAR_HALF, HZP_SHIELD, HZP_DOOR_RING, HZP_BYPASS};
};
// return available count // return available count
ADEMCO_EXPORT_SYMBOL int hbGetAvailableZoneProperties(HbMachineType type, HbZoneProperty props[12]); ADEMCO_EXPORT_SYMBOL int hbGetAvailableZoneProperties(HbMachineType type, HbZoneProperty props[12]);
...@@ -435,7 +439,8 @@ ADEMCO_EXPORT_SYMBOL HbComResp_A2_p1 hbComResp_A2_Iter_next(HbComResp_A2_Iter* i ...@@ -435,7 +439,8 @@ ADEMCO_EXPORT_SYMBOL HbComResp_A2_p1 hbComResp_A2_Iter_next(HbComResp_A2_Iter* i
ADEMCO_EXPORT_SYMBOL void hbComMakeRespA0_getMachineStatus(HbComData* data, HbMachineStatus status, HbMachineType type); ADEMCO_EXPORT_SYMBOL void hbComMakeRespA0_getMachineStatus(HbComData* data, HbMachineStatus status, HbMachineType type);
// zones and props length is count // zones and props length is count
// if count is 0, p1 wil be set to HbComResp_A2_p1_nomore // if count is 0, p1 wil be set to HbComResp_A2_p1_nomore
ADEMCO_EXPORT_SYMBOL void hbComMakeRespA2_getMachineZones(HbComData* data, size_t count, AdemcoZone* zones, HbZoneProperty* props, HbComResp_A2_p1 p1); ADEMCO_EXPORT_SYMBOL void hbComMakeRespA2_getMachineZones(HbComData* data, size_t count,
AdemcoZone* zones, HbZoneProperty* props, HbComResp_A2_p1 p1);
// 学码开始,等待探测器无线信号中 // 学码开始,等待探测器无线信号中
ADEMCO_EXPORT_SYMBOL void hbComMakeRespA3_waitingSignal(HbComData* data); ADEMCO_EXPORT_SYMBOL void hbComMakeRespA3_waitingSignal(HbComData* data);
ADEMCO_EXPORT_SYMBOL void hbComMakeRespA4_modifyMachineZone(HbComData* data, AdemcoZone zone, HbZoneProperty prop, HbComResp_A4_p3 p3); ADEMCO_EXPORT_SYMBOL void hbComMakeRespA4_modifyMachineZone(HbComData* data, AdemcoZone zone, HbZoneProperty prop, HbComResp_A4_p3 p3);
...@@ -449,8 +454,11 @@ ADEMCO_EXPORT_SYMBOL void hbComMakeRespAB_modifyMachineZoneLostConfig(HbComData* ...@@ -449,8 +454,11 @@ ADEMCO_EXPORT_SYMBOL void hbComMakeRespAB_modifyMachineZoneLostConfig(HbComData*
ADEMCO_EXPORT_SYMBOL void hbComMakeRespAD_getMachineZoneLostConfig(HbComData* data, HbComResp_AD_p1 p1, size_t count, AdemcoZone* zones, HbComResp_AD_p2 p2); ADEMCO_EXPORT_SYMBOL void hbComMakeRespAD_getMachineZoneLostConfig(HbComData* data, HbComResp_AD_p1 p1, size_t count, AdemcoZone* zones, HbComResp_AD_p2 p2);
ADEMCO_EXPORT_SYMBOL void hbComMakeRespAF_set3SectionMachineStatus(HbComData* data, HbCom_3sec_which p1, HbCom_3sec_status status); ADEMCO_EXPORT_SYMBOL void hbComMakeRespAF_set3SectionMachineStatus(HbComData* data, HbCom_3sec_which p1, HbCom_3sec_status status);
ADEMCO_EXPORT_SYMBOL void hbComMakeRespB1_get3SectionMachineStatus(HbComData* data, HbMachineStatus statusMachine, ADEMCO_EXPORT_SYMBOL void hbComMakeRespB1_get3SectionMachineStatus(HbComData* data, HbMachineStatus statusMachine,
HbMachineStatus statusSec1, HbMachineStatus statusSec2, HbMachineStatus statusSec3); HbMachineStatus statusSec1,
ADEMCO_EXPORT_SYMBOL void hbComDataToAdemcoXData(const HbComData* const data, AdemcoXDataSegment* xdata, AdemcoXDataLengthFormat xlf, AdemcoXDataTransform xtr); HbMachineStatus statusSec2,
HbMachineStatus statusSec3);
ADEMCO_EXPORT_SYMBOL void hbComDataToAdemcoXData(const HbComData* const data, AdemcoXDataSegment* xdata,
AdemcoXDataLengthFormat xlf, AdemcoXDataTransform xtr);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
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