Merge remote-tracking branch 'upstream/prepare_for_master' into prepare_for_master

This commit is contained in:
xuyanghang
2024-01-09 14:51:31 +08:00
32 changed files with 1310 additions and 57 deletions

View File

@@ -20,5 +20,5 @@ menu "Applications"
source "$APP_DIR/Applications/sensor_app/Kconfig"
source "$APP_DIR/Applications/embedded_database_app/Kconfig"
source "$APP_DIR/Applications/webnet/Kconfig"
source "$APP_DIR/Applications/mongoose/Kconfig"
source "$APP_DIR/Applications/webserver/Kconfig"
endmenu

View File

@@ -40,8 +40,8 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
SRC_DIR += webnet
endif
ifeq ($(CONFIG_USE_MONGOOSE),y)
SRC_DIR += mongoose
ifeq ($(CONFIG_APPLICATION_WEBSERVER),y)
SRC_DIR += webserver
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@@ -22,7 +22,7 @@ extern void ApplicationOtaTaskInit(void);
extern int OtaTask(void);
#endif
#ifdef USE_MONGOOSE
#ifdef APPLICATION_WEBSERVER
extern int webserver(void);
#endif
@@ -38,7 +38,7 @@ int main(void)
OtaTask();
#endif
#ifdef USE_MONGOOSE
#ifdef APPLICATION_WEBSERVER
webserver();
#endif

View File

@@ -1,11 +0,0 @@
menuconfig USE_MONGOOSE
bool "Use mongoose as webserver"
default n
select BSP_USING_SDIO
select BSP_USING_W5500
select BSP_USING_ETHERNET
select SUPPORT_CONNECTION_FRAMEWORK
select CONNECTION_ADAPTER_4G
select ADAPTER_EC200A
select LIB_USING_LORAWAN
select LIB_USING_LORA_RADIO

View File

@@ -0,0 +1,29 @@
menuconfig APPLICATION_WEBSERVER
bool "Application webserver using mongoose"
default n
if APPLICATION_WEBSERVER
choice
prompt "choose board for webserver"
default APPLICATION_WEBSERVER_XISHUTONG_4G
config APPLICATION_WEBSERVER_XISHUTONG_4G
bool "board select xishutong-4g, support dual ethernet port and 4G"
select BSP_USING_SDIO
select BSP_USING_W5500
select BSP_USING_ETHERNET
select SUPPORT_CONNECTION_FRAMEWORK
select CONNECTION_ADAPTER_4G
select ADAPTER_EC200A
select LIB_USING_LORAWAN
select LIB_USING_LORA_RADIO
config APPLICATION_WEBSERVER_XISHUTONG
bool "board select xishutong, support single ethernet port"
select BSP_USING_SDIO
select BSP_USING_LWIP
select LIB_USING_LORAWAN
select LIB_USING_LORA_RADIO
endchoice
endif

View File

@@ -25,6 +25,11 @@ History:
Author: AIIT XUOS Lab
Modification:
1support xishutong-arm32 board, using W5500 to support webserver.
2. Date: 2024-1-3
Author: AIIT XUOS Lab
Modification:
1support xishutong board(single ethernet port), using MAC to support webserver
*************************************************/
@@ -34,7 +39,9 @@ Modification:
#include <sys_arch.h>
#include <lwip/sockets.h>
#include "lwip/sys.h"
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
#include <adapter.h>
#endif
/*******************************************************************************
* Local variable definitions ('static')
@@ -72,9 +79,17 @@ static unsigned int status = 0;
static pthread_t wb_event_task;
/*define device info*/
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
static const char* device_name = "矽数通4G";
static const char* device_type = "xishutong-arm32";
static const char* device_serial_num = "123456789";
#endif
#ifdef APPLICATION_WEBSERVER_XISHUTONG
static const char* device_name = "矽数通";
static const char* device_type = "xishutong-arm32";
static const char* device_serial_num = "123456789";
#endif
/*define webserver info*/
static struct webserver_config {
@@ -231,6 +246,7 @@ static void Rs485Configure(int baud_rate, int data_bit, int stop_bit, int parity
/*******************************************************************************
* Function implementation - define net 4G info
******************************************************************************/
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
static void Net4gGetInfo(char *ip, char *operator, char *signal_strength)
{
//to do
@@ -265,6 +281,7 @@ static void NetMqttDisconnect(void)
{
//to do
}
#endif
/*******************************************************************************
* Function implementation - define net LoRa info
@@ -295,6 +312,7 @@ static void NetLoraDisconnect(void)
/*******************************************************************************
* Function implementation - define net Ethernet info
******************************************************************************/
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
static void TcpClientConnect(void)
{
int cnt = 20;
@@ -372,6 +390,7 @@ static void TcpClientDisconnect(void)
closesocket(socket_fd);
net_ethernet_info.connect_status = 0;
}
#endif
/*******************************************************************************
* Function implementation - define plc info
@@ -403,6 +422,7 @@ static void *WebserverEventTask(void *arg)
while(1) {
if (0 == PrivEventProcess(wb_event, WB_EVENT_ALL, EVENT_OR | EVENT_AUTOCLEAN, 0, &status)) {
switch( status ) {
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
case WB_4G_CONNECT:
Net4gConnect();
break;
@@ -415,18 +435,21 @@ static void *WebserverEventTask(void *arg)
case WB_MQTT_DISCONNECT:
NetMqttDisconnect();
break;
#endif
case WB_LORA_CONNECT:
NetLoraConnect();
break;
case WB_LORA_DISCONNECT:
NetLoraDisconnect();
break;
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
case WB_ETHERNET_CONNECT:
TcpClientConnect();
break;
case WB_ETHERNET_DISCONNECT:
TcpClientDisconnect();
break;
#endif
}
}
}
@@ -522,6 +545,7 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
Rs485Configure(rs485_config.baud_rate, rs485_config.data_bit, rs485_config.stop_bit, rs485_config.parity);
}
/*define net 4G info*/
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
else if (mg_http_match_uri(hm, "/net/get4gInfo")) {
Net4gGetInfo(net_4g_info.map_ip, net_4g_info.operator, net_4g_info.signal_strength);
@@ -569,6 +593,7 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
PrivEvenTrigger(wb_event, WB_MQTT_DISCONNECT);
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{\"status\":\"success\"}\r\n");
}
#endif
/*define net LoRa info*/
else if (mg_http_match_uri(hm, "/net/getLoraInfo")) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
@@ -599,6 +624,7 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{\"status\":\"success\"}\r\n");
}
/*define net Ethernet info*/
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
else if (mg_http_match_uri(hm, "/net/getEthernetInfo")) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m, %m:%m, %m:%m, %m:%m, %m:%m, %m:%m, %m:%m, %m:%m, %m:%d}\n",
@@ -646,6 +672,7 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
PrivEvenTrigger(wb_event, WB_ETHERNET_DISCONNECT);
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{\"status\":\"success\"}\r\n");
}
#endif
/*define plc info*/
else if (mg_http_match_uri(hm, "/control/setPLCInfo")) {
struct mg_str json = hm->body;
@@ -670,23 +697,41 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
static void* do_webserver(void* args)
{
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
p_netdev_webserver = netdev_get_by_name("wz");
if (p_netdev_webserver == NULL) {
MG_INFO(("Did not find wz netdev, use default.\n"));
p_netdev_webserver = NETDEV_DEFAULT;
}
#endif
#ifdef APPLICATION_WEBSERVER_XISHUTONG
p_netdev_webserver = netdev_get_by_name("hd");
if (p_netdev_webserver == NULL) {
MG_INFO(("Did not find hd netdev, use default.\n"));
p_netdev_webserver = NETDEV_DEFAULT;
}
#endif
MG_INFO(("Webserver Use Netdev %s", p_netdev_webserver->name));
webserver_config.ip = strdup(inet_ntoa(*p_netdev_webserver->ip_addr));
webserver_config.mask = strdup(inet_ntoa(*p_netdev_webserver->netmask));
webserver_config.gw = strdup(inet_ntoa(*p_netdev_webserver->gw));
webserver_config.dns = strdup(inet_ntoa(p_netdev_webserver->dns_servers[0]));
#ifdef BSP_USING_RS485
Rs485InitConfigure();
#endif
adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
#endif
//lora init param
net_lora_info.bw = 2;//bw 0:125 kHz 1:250 kHz 2:500 kHz,
net_lora_info.sf = 12;//sf12
net_lora_info.lora_init_flag = 0;
WbEventInit();
struct mg_mgr mgr; // Event manager
@@ -702,9 +747,22 @@ static void* do_webserver(void* args)
int webserver(void)
{
char* params[2] = {"LwipNetworkActive", "-a"};
extern void LwipNetworkActive(int argc, char* argv[]);
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
char* params[2] = {"LwipNetworkActive", "-a"};
LwipNetworkActive(2, params);
#endif
#ifdef APPLICATION_WEBSERVER_XISHUTONG
char* params[3] = {"LwipNetworkActive", "-e", "0"};
LwipNetworkActive(3, params);
extern void LwipSetNetwork(int argc, char* argv[]);
char* ip_params[5] = {"LwipSetNetwork", "-d", "hd", "-i", "192.168.131.88"};
LwipSetNetwork(5, ip_params);
char* gw_params[5] = {"LwipSetNetwork", "-d", "hd", "-g", "192.168.131.1"};
LwipSetNetwork(5, gw_params);
#endif
pthread_attr_t attr;
attr.schedparam.sched_priority = 30;