|
|
@@ -9,7 +9,8 @@
|
|
|
#include "datadef.h"
|
|
|
|
|
|
#define TIMER_INTERVAL 1000
|
|
|
-typedef void (*http_fn_t)(void *arg);
|
|
|
+#define ONCE_SEND_CH_CNT 10
|
|
|
+
|
|
|
|
|
|
typedef struct mg_mgr mg_mgr_t;
|
|
|
typedef struct mg_tls_opts mg_tls_t;
|
|
|
@@ -40,6 +41,9 @@ static int is_ws(mg_conn_t *c)
|
|
|
}
|
|
|
static int ws_send(mg_conn_t *c, void *data, int len, int isbin)
|
|
|
{
|
|
|
+ if(!c || !data || len<=0) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
LOGD("____ws_send, len: %d\n", len);
|
|
|
mg_ws_send(c, data, len, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT);
|
|
|
|
|
|
@@ -68,47 +72,37 @@ static int ws_send_pkt(web_handle_t *h, mg_conn_t *c, uint8_t type, void *data,
|
|
|
|
|
|
static void send_powerc(web_handle_t *h, mg_conn_t *c)
|
|
|
{
|
|
|
- int i,xlen,offset;
|
|
|
- pkt_hdr_t *hdr=NULL;
|
|
|
- power_data_t pd=power_data_get();
|
|
|
-
|
|
|
- for(i=0; i<pd.chs; i++) {
|
|
|
- ws_send_pkt(h, c, PKT_TYPE_POWER_CH, &pd.pch[i], sizeof(power_ch_t), 1);
|
|
|
- }
|
|
|
-}
|
|
|
-static void send_powerc_once(web_handle_t *h, mg_conn_t *c)
|
|
|
-{
|
|
|
- int i,xlen,offset;
|
|
|
+ int i,j,xlen,offset,times,left;
|
|
|
pkt_hdr_t *hdr=NULL;
|
|
|
power_data_t pd=power_data_get();
|
|
|
|
|
|
- pd.chs = 8;
|
|
|
- if(pd.chs==0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- xlen = pd.chs*sizeof(power_ch_t)+sizeof(pkt_hdr_t);
|
|
|
- if(!h->buf || h->buflen<xlen) {
|
|
|
- if(h->buf) free(h->buf);
|
|
|
- h->buf = malloc(xlen);
|
|
|
- if(h->buf) {
|
|
|
- h->buflen = xlen;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!h->buf) {
|
|
|
+ if(pd.chs==0 || h->buf==NULL ) {
|
|
|
return;
|
|
|
}
|
|
|
hdr = (pkt_hdr_t*)h->buf;
|
|
|
-
|
|
|
+
|
|
|
hdr->magic = PKT_MAGIC;
|
|
|
hdr->type = PKT_TYPE_POWER_CH;
|
|
|
hdr->nack = 0;
|
|
|
- hdr->dlen = xlen-sizeof(pkt_hdr_t);
|
|
|
- for(i=0; i<pd.chs; i++) {
|
|
|
+
|
|
|
+ times = pd.chs/ONCE_SEND_CH_CNT;
|
|
|
+ for(i=0; i<times; i++) {
|
|
|
+ for(j=0; j<ONCE_SEND_CH_CNT; j++) {
|
|
|
+ offset = j*sizeof(power_ch_t);
|
|
|
+ memcpy(hdr->data+offset, &pd.pch[i*ONCE_SEND_CH_CNT+j], sizeof(power_ch_t));
|
|
|
+ }
|
|
|
+ xlen = ONCE_SEND_CH_CNT*sizeof(power_ch_t)+sizeof(pkt_hdr_t);
|
|
|
+ hdr->dlen = xlen-sizeof(pkt_hdr_t);
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ left = pd.chs%ONCE_SEND_CH_CNT;
|
|
|
+ for(i=0; i<left; i++) {
|
|
|
offset = i*sizeof(power_ch_t);
|
|
|
- memcpy(hdr->data+offset, &pd.pch[i], sizeof(power_ch_t));
|
|
|
+ memcpy(hdr->data+offset, &pd.pch[pd.chs-left+i], sizeof(power_ch_t));
|
|
|
}
|
|
|
+ xlen = (pd.chs%ONCE_SEND_CH_CNT)*sizeof(power_ch_t)+sizeof(pkt_hdr_t);
|
|
|
+ hdr->dlen = xlen-sizeof(pkt_hdr_t);
|
|
|
ws_send(c, h->buf, xlen, 1);
|
|
|
}
|
|
|
|
|
|
@@ -182,7 +176,7 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
|
|
|
}
|
|
|
else {
|
|
|
LOGD("_____ send_powerc\n");
|
|
|
- send_powerc_once(h, c);
|
|
|
+ send_powerc(h, c);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -325,7 +319,7 @@ int web_init(void)
|
|
|
memset(h, 0, sizeof(web_handle_t));
|
|
|
h->list = list_init(&lc);
|
|
|
|
|
|
- h->buflen = sizeof(pkt_hdr_t)+sizeof(power_ch_t)+32;
|
|
|
+ h->buflen = sizeof(pkt_hdr_t)+sizeof(power_ch_t)*ONCE_SEND_CH_CNT+8;
|
|
|
h->buf = (char*)malloc(h->buflen);
|
|
|
|
|
|
thread_start(THREAD_ID_WEB, web_thread, h);
|