|
|
@@ -44,9 +44,27 @@ typedef struct {
|
|
|
}web_handle_t;
|
|
|
static web_handle_t webHandle={0};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-static int ws_send(web_handle_t *h, struct mg_connection *c, uint8_t type, void *data, int len, int isbin)
|
|
|
+static int is_ws(struct mg_connection *c)
|
|
|
+{
|
|
|
+ int r=0;
|
|
|
+#ifdef USE_MG716
|
|
|
+ r = c->is_websocket;
|
|
|
+#else
|
|
|
+ r = (c->flags & MG_F_IS_WEBSOCKET)?1:0;
|
|
|
+#endif
|
|
|
+}
|
|
|
+static int ws_send(struct mg_connection *c, void *data, int len, int isbin)
|
|
|
+{
|
|
|
+ LOGD("____ws_send, len: %d\n", len);
|
|
|
+#ifdef USE_MG716
|
|
|
+ mg_ws_send(c, data, len, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT);
|
|
|
+#else
|
|
|
+ mg_send_websocket_frame(c, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT, data, len);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int ws_send_pkt(web_handle_t *h, struct mg_connection *c, uint8_t type, void *data, int len, int isbin)
|
|
|
{
|
|
|
pkt_hdr_t *hdr=NULL;
|
|
|
|
|
|
@@ -61,48 +79,62 @@ static int ws_send(web_handle_t *h, struct mg_connection *c, uint8_t type, void
|
|
|
hdr->nack = 0;
|
|
|
hdr->dlen = len;
|
|
|
memcpy(hdr->data, data, len);
|
|
|
-#ifdef USE_MG716
|
|
|
- mg_ws_send(c, hdr, len+sizeof(pkt_hdr_t), isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT);
|
|
|
-#else
|
|
|
- mg_send_websocket_frame(c, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT, hdr, len+sizeof(pkt_hdr_t));
|
|
|
-#endif
|
|
|
+
|
|
|
+ ws_send(c, hdr, len+sizeof(pkt_hdr_t), isbin);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
static void send_powerc(web_handle_t *h, struct mg_connection *c)
|
|
|
{
|
|
|
- int i,r;
|
|
|
+ int i,xlen,offset;
|
|
|
+ pkt_hdr_t *hdr=NULL;
|
|
|
power_data_t pd=power_data_get();
|
|
|
|
|
|
+ //pd.chs = 2;
|
|
|
+ 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) {
|
|
|
+ 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++) {
|
|
|
- ws_send(h, c, PKT_TYPE_POWER_CH, &pd.pch[i], sizeof(power_ch_t), 1);
|
|
|
+ offset = i*sizeof(power_ch_t);
|
|
|
+ memcpy(hdr->data+offset, &pd.pch[i], sizeof(power_ch_t));
|
|
|
}
|
|
|
+ ws_send(c, h->buf, xlen, 1);
|
|
|
}
|
|
|
static void send_powert(web_handle_t *h, struct mg_connection *c)
|
|
|
{
|
|
|
int i,r;
|
|
|
power_data_t pd=power_data_get();
|
|
|
|
|
|
- if(r==0) {
|
|
|
- ws_send(h, c, PKT_TYPE_POWER_TOTAL, &pd.ttl, sizeof(power_total_t), 1);
|
|
|
- }
|
|
|
+ ws_send_pkt(h, c, PKT_TYPE_POWER_TOTAL, &pd.ttl, sizeof(power_total_t), 1);
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int is_websocket(struct mg_connection *c)
|
|
|
-{
|
|
|
- int r=0;
|
|
|
-#ifdef USE_MG716
|
|
|
- r = c->is_websocket;
|
|
|
-#else
|
|
|
- r = (c->flags & MG_F_IS_WEBSOCKET)?1:0;
|
|
|
-#endif
|
|
|
-}
|
|
|
+
|
|
|
static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, struct mg_connection *c)
|
|
|
{
|
|
|
int r=0;
|
|
|
|
|
|
- if (!is_websocket(c)) {
|
|
|
+ if (!is_ws(c)) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -285,7 +317,7 @@ static void timer_fn(void *arg)
|
|
|
#else
|
|
|
for (c = mg_next(&h->mgr, NULL); c != NULL; c = mg_next(&h->mgr, c)) {
|
|
|
#endif
|
|
|
- ws_send(h, c, n->tp, n->buf, n->dlen, 1);
|
|
|
+ ws_send_pkt(h, c, n->tp, n->buf, n->dlen, 1);
|
|
|
}
|
|
|
list_back_node(h->list, ln);
|
|
|
}
|
|
|
@@ -295,9 +327,8 @@ static void web_thread(void *arg)
|
|
|
struct mg_connection *nc;
|
|
|
const char *http_addr="http://[::]:80";
|
|
|
const char *https_addr="https://[::]:443";
|
|
|
- //thread_handle_t *th=(thread_handle_t*)arg;
|
|
|
- //web_handle_t *h=(web_handle_t*)th->attr->arg;
|
|
|
- web_handle_t *h=&webHandle;
|
|
|
+ thread_handle_t *th=(thread_handle_t*)arg;
|
|
|
+ web_handle_t *h=(web_handle_t*)th->attr->arg;
|
|
|
|
|
|
#ifdef USE_MG716
|
|
|
mg_log_set(MG_LL_DEBUG);
|
|
|
@@ -306,7 +337,7 @@ static void web_thread(void *arg)
|
|
|
//sys_get_path(mh->rootDir, WEB_ROOT);
|
|
|
strcpy(h->rootDir, "/web");
|
|
|
|
|
|
- mg_timer_add(&h->mgr, TIMER_INTERVAL, MG_TIMER_REPEAT, timer_fn, h);
|
|
|
+ //mg_timer_add(&h->mgr, TIMER_INTERVAL, MG_TIMER_REPEAT, timer_fn, h);
|
|
|
if (mg_http_listen(&h->mgr, http_addr, http_fn, NULL) == NULL) {
|
|
|
MG_ERROR(("cannot listen on %s\n", http_addr));
|
|
|
}
|
|
|
@@ -329,8 +360,7 @@ static void web_thread(void *arg)
|
|
|
h->opts.enable_directory_listing = "yes";
|
|
|
#endif
|
|
|
|
|
|
- //while(th->quit==0) {
|
|
|
- while(1) {
|
|
|
+ while(th->quit==0) {
|
|
|
mg_mgr_poll(&h->mgr, 300);
|
|
|
}
|
|
|
mg_mgr_free(&h->mgr);
|
|
|
@@ -348,7 +378,6 @@ int web_init(void)
|
|
|
h->buflen = sizeof(pkt_hdr_t)+sizeof(power_ch_t)+32;
|
|
|
h->buf = (char*)malloc(h->buflen);
|
|
|
|
|
|
- //web_thread(0);
|
|
|
thread_start(THREAD_ID_WEB, web_thread, h);
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -363,251 +392,6 @@ int web_post(int type, void *data, int len)
|
|
|
return list_append(h->list, type, data, len);
|
|
|
}
|
|
|
|
|
|
-#if 1
|
|
|
-void WWDG_IRQHandler() {
|
|
|
- LOGD("___0\n");
|
|
|
-}
|
|
|
-void PVD_IRQHandler() {
|
|
|
- LOGD("___1\n");
|
|
|
-}
|
|
|
-void TAMP_STAMP_IRQHandler(){
|
|
|
- LOGD("___2\n");
|
|
|
-}
|
|
|
-void RTC_WKUP_IRQHandler(){
|
|
|
- LOGD("___3\n");
|
|
|
-}
|
|
|
-void FLASH_IRQHandler(){
|
|
|
- LOGD("___4\n");
|
|
|
-}
|
|
|
-void RCC_IRQHandler(){
|
|
|
- LOGD("___5\n");
|
|
|
-}
|
|
|
-//void EXTI0_IRQHandler(){
|
|
|
-// LOGD("___6\n");
|
|
|
-//}
|
|
|
-//void EXTI1_IRQHandler(){
|
|
|
-// LOGD("___7\n");
|
|
|
-//}
|
|
|
-//void EXTI2_IRQHandler(){
|
|
|
-// LOGD("___8\n");
|
|
|
-//}
|
|
|
-//void EXTI3_IRQHandler(){
|
|
|
-// LOGD("___9\n");
|
|
|
-//}
|
|
|
-//void EXTI4_IRQHandler(){
|
|
|
-// LOGD("___a\n");
|
|
|
-//}
|
|
|
-void DMA1_Stream0_IRQHandler(){
|
|
|
- LOGD("___b\n");
|
|
|
-}
|
|
|
-void DMA1_Stream1_IRQHandler(){
|
|
|
- LOGD("___c\n");
|
|
|
-}
|
|
|
-void DMA1_Stream2_IRQHandler(){
|
|
|
- LOGD("___d\n");
|
|
|
-}
|
|
|
-void DMA1_Stream3_IRQHandler(){
|
|
|
- LOGD("___e\n");
|
|
|
-}
|
|
|
-void DMA1_Stream4_IRQHandler(){
|
|
|
- LOGD("___f\n");
|
|
|
-}
|
|
|
-void DMA1_Stream5_IRQHandler(){
|
|
|
- LOGD("___g\n");
|
|
|
-}
|
|
|
-void DMA1_Stream6_IRQHandler(){
|
|
|
- LOGD("___h\n");
|
|
|
-}
|
|
|
-void ADC_IRQHandler(){
|
|
|
- LOGD("___i\n");
|
|
|
-}
|
|
|
-void CAN1_TX_IRQHandler(){
|
|
|
- LOGD("___j\n");
|
|
|
-}
|
|
|
-void CAN1_RX0_IRQHandler(){
|
|
|
- LOGD("___k\n");
|
|
|
-}
|
|
|
-void CAN1_RX1_IRQHandler(){
|
|
|
- LOGD("___l\n");
|
|
|
-}
|
|
|
-void CAN1_SCE_IRQHandler(){
|
|
|
- LOGD("___m\n");
|
|
|
-}
|
|
|
-//void EXTI9_5_IRQHandler(){
|
|
|
-// LOGD("___n\n");
|
|
|
-//}
|
|
|
-void TIM1_BRK_TIM9_IRQHandler(){
|
|
|
- LOGD("___o\n");
|
|
|
-}
|
|
|
-void TIM1_UP_TIM10_IRQHandler(){
|
|
|
- LOGD("___p\n");
|
|
|
-}
|
|
|
-void TIM1_TRG_COM_TIM11_IRQHandler(){
|
|
|
- LOGD("___q\n");
|
|
|
-}
|
|
|
-void TIM1_CC_IRQHandler(){
|
|
|
- LOGD("___r\n");
|
|
|
-}
|
|
|
-void TIM2_IRQHandler(){
|
|
|
- LOGD("___s\n");
|
|
|
-}
|
|
|
-void TIM3_IRQHandler(){
|
|
|
- LOGD("___t\n");
|
|
|
-}
|
|
|
-void TIM4_IRQHandler(){
|
|
|
- LOGD("___u\n");
|
|
|
-}
|
|
|
-void I2C1_EV_IRQHandler(){
|
|
|
- LOGD("___v\n");
|
|
|
-}
|
|
|
-void I2C1_ER_IRQHandler(){
|
|
|
- LOGD("___w\n");
|
|
|
-}
|
|
|
-void I2C2_EV_IRQHandler(){
|
|
|
- LOGD("___x\n");
|
|
|
-}
|
|
|
-void I2C2_ER_IRQHandler(){
|
|
|
- LOGD("___y\n");
|
|
|
-}
|
|
|
-void SPI1_IRQHandler(){
|
|
|
- LOGD("___z\n");
|
|
|
-}
|
|
|
-void SPI2_IRQHandler(){
|
|
|
- LOGD("___a1\n");
|
|
|
-}
|
|
|
-//void USART1_IRQHandler(){
|
|
|
-// LOGD("___a2\n");
|
|
|
-//}
|
|
|
-//void USART2_IRQHandler(){
|
|
|
-// LOGD("___a3\n");
|
|
|
-//}
|
|
|
-//void USART3_IRQHandler(){
|
|
|
-// LOGD("___a4\n");
|
|
|
-//}
|
|
|
-//void EXTI15_10_IRQHandler(){
|
|
|
-// LOGD("___a5\n");
|
|
|
-//}
|
|
|
-void RTC_Alarm_IRQHandler(){
|
|
|
- LOGD("___a6\n");
|
|
|
-}
|
|
|
-void OTG_FS_WKUP_IRQHandler(){
|
|
|
- LOGD("___a7\n");
|
|
|
-}
|
|
|
-void TIM8_BRK_TIM12_IRQHandler(){
|
|
|
- LOGD("___a8\n");
|
|
|
-}
|
|
|
-void TIM8_UP_TIM13_IRQHandler(){
|
|
|
- LOGD("___a9\n");
|
|
|
-}
|
|
|
-void TIM8_TRG_COM_TIM14_IRQHandler(){
|
|
|
- LOGD("___aa\n");
|
|
|
-}
|
|
|
-void TIM8_CC_IRQHandler(){
|
|
|
- LOGD("___ab\n");
|
|
|
-}
|
|
|
-void DMA1_Stream7_IRQHandler(){
|
|
|
- LOGD("___ac\n");
|
|
|
-}
|
|
|
-void FMC_IRQHandler(){
|
|
|
- LOGD("___ad\n");
|
|
|
-}
|
|
|
-//void SDIO_IRQHandler(){
|
|
|
-// LOGD("___ae\n");
|
|
|
-//}
|
|
|
-void TIM5_IRQHandler(){
|
|
|
- LOGD("___af\n");
|
|
|
-}
|
|
|
-void SPI3_IRQHandler(){
|
|
|
- LOGD("___ag\n");
|
|
|
-}
|
|
|
-void UART4_IRQHandler(){
|
|
|
- LOGD("___ah\n");
|
|
|
-}
|
|
|
-void UART5_IRQHandler(){
|
|
|
- LOGD("___b1\n");
|
|
|
-}
|
|
|
-void TIM6_DAC_IRQHandler(){
|
|
|
- LOGD("___b2\n");
|
|
|
-}
|
|
|
-void TIM7_IRQHandler(){
|
|
|
- LOGD("___b3\n");
|
|
|
-}
|
|
|
-void DMA2_Stream0_IRQHandler(){
|
|
|
- LOGD("___b4\n");
|
|
|
-}
|
|
|
-void DMA2_Stream1_IRQHandler(){
|
|
|
- LOGD("___b5\n");
|
|
|
-}
|
|
|
-void DMA2_Stream2_IRQHandler(){
|
|
|
- LOGD("___b6\n");
|
|
|
-}
|
|
|
-void DMA2_Stream3_IRQHandler(){
|
|
|
- LOGD("___b7\n");
|
|
|
-}
|
|
|
-void DMA2_Stream4_IRQHandler(){
|
|
|
- LOGD("___b8\n");
|
|
|
-}
|
|
|
-//void ETH_IRQHandler(){
|
|
|
-// LOGD("___b9\n");
|
|
|
-//}
|
|
|
-void ETH_WKUP_IRQHandler(){
|
|
|
- LOGD("___c1\n");
|
|
|
-}
|
|
|
-void CAN2_TX_IRQHandler(){
|
|
|
- LOGD("___c2\n");
|
|
|
-}
|
|
|
-void CAN2_RX0_IRQHandler(){
|
|
|
- LOGD("___c3\n");
|
|
|
-}
|
|
|
-void CAN2_RX1_IRQHandler(){
|
|
|
- LOGD("___c4\n");
|
|
|
-}
|
|
|
-void CAN2_SCE_IRQHandler(){
|
|
|
- LOGD("___c5\n");
|
|
|
-}
|
|
|
-void OTG_FS_IRQHandler(){
|
|
|
- LOGD("___c6\n");
|
|
|
-}
|
|
|
-void DMA2_Stream5_IRQHandler(){
|
|
|
- LOGD("___c7\n");
|
|
|
-}
|
|
|
-void DMA2_Stream6_IRQHandler(){
|
|
|
- LOGD("___c8\n");
|
|
|
-}
|
|
|
-void DMA2_Stream7_IRQHandler(){
|
|
|
- LOGD("___c9\n");
|
|
|
-}
|
|
|
-//void USART6_IRQHandler(){
|
|
|
-// LOGD("___d1\n");
|
|
|
-//}
|
|
|
-void I2C3_EV_IRQHandler(){
|
|
|
- LOGD("___d2\n");
|
|
|
-}
|
|
|
-void I2C3_ER_IRQHandler(){
|
|
|
- LOGD("___d3\n");
|
|
|
-}
|
|
|
-void OTG_HS_EP1_OUT_IRQHandler(){
|
|
|
- LOGD("___d4\n");
|
|
|
-}
|
|
|
-void OTG_HS_EP1_IN_IRQHandler(){
|
|
|
- LOGD("___d5\n");
|
|
|
-}
|
|
|
-void OTG_HS_WKUP_IRQHandler(){
|
|
|
- LOGD("___d6\n");
|
|
|
-}
|
|
|
-void OTG_HS_IRQHandler(){
|
|
|
- LOGD("___d7\n");
|
|
|
-}
|
|
|
-void DCMI_IRQHandler(){
|
|
|
- LOGD("___d8\n");
|
|
|
-}
|
|
|
-void HASH_RNG_IRQHandler(){
|
|
|
- LOGD("___d9\n");
|
|
|
-}
|
|
|
-void FPU_IRQHandler(){
|
|
|
- LOGD("___e1\n");
|
|
|
-}
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|