feat support webserver for edu-arm32 board

This commit is contained in:
Liu_Weichao 2024-01-03 14:20:37 +08:00
parent 9e962d2cf2
commit 87c4c585d9
17 changed files with 123 additions and 31 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;

View File

@ -50,7 +50,7 @@ export SRC_DIR:= $(SRC_APP_DIR) $(SRC_KERNEL_DIR)
export LIBCC
export MUSL_DIR := $(KERNEL_ROOT)/lib/musllib
export LWIP_DIR := $(KERNEL_ROOT)/resources/ethernet
export MONGOOSE_DIR := $(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose/lib
export MONGOOSE_DIR := $(KERNEL_ROOT)/../../APP_Framework/Applications/webserver/lib
PART:=
@ -75,10 +75,6 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
PART += COMPILE_LWIP
endif
ifeq ($(CONFIG_USE_MONGOOSE), y)
# PART += COMPILE_MONGOOSE
endif
ifeq ($(CONFIG_MCUBOOT_BOOTLOADER), y)
PART += COMPILE_BOOTLOADER
else ifeq ($(CONFIG_MCUBOOT_APPLICATION), y)
@ -141,7 +137,7 @@ COMPILE_MONGOOSE:
done
@cp link_mongoose.mk build/Makefile
@$(MAKE) -C build TARGET=mongoose.a LINK_FLAGS=LFLAGS
@cp build/mongoose.a $(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose/mongoose.a
@cp build/mongoose.a $(KERNEL_ROOT)/../../APP_Framework/Applications/webserver/mongoose.a
@rm build/Makefile build/make.obj
COMPILE_KERNEL:

View File

@ -211,7 +211,7 @@ CONFIG_ADD_XIZI_FEATURES=y
#
# config stack size and priority of main task
#
CONFIG_MAIN_KTASK_STACK_SIZE=1024
CONFIG_MAIN_KTASK_STACK_SIZE=2048
CONFIG_MAIN_KTASK_PRIORITY=16
#

View File

@ -15,4 +15,8 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
export LINK_LWIP := $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a
endif
ifeq ($(CONFIG_APPLICATION_WEBSERVER), y)
export LINK_MONGOOSE := $(KERNEL_ROOT)/../../APP_Framework/Applications/webserver/mongoose.a
endif
export ARCH = arm

View File

@ -75,6 +75,7 @@ Modification:
static stc_sd_handle_t gSdHandle;
static int sd_lock = -1;
static int is_mount_ok = 0;
static void SdCardConfig(void)
{
@ -214,11 +215,13 @@ static struct SdioDevDone dev_done =
*/
static int MountSDCardFs(enum FilesystemType fs_type)
{
if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, fs_type, "/") == 0)
if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, fs_type, "/") == 0) {
KPrintf("Sd card mount to '/'");
else
is_mount_ok = 1;
} else {
KPrintf("Sd card mount to '/' failed!");
is_mount_ok = 0;
}
return 0;
}
#endif
@ -253,9 +256,17 @@ static void SdCardDetach(void)
#ifdef MOUNT_SDCARD_FS
UnmountFileSystem("/");
is_mount_ok = 0;
#endif
}
int GetSdMountStatus(void)
{
if(!is_mount_ok)
KPrintf("SD card is not inserted or failed to mount, please check!\r\n");
return is_mount_ok;
}
static uint8 SdCardReadCd(void)
{
en_pin_state_t sd_cd_state = GPIO_ReadInputPins(SDIOC_CD_PORT, SDIOC_CD_PIN);

View File

@ -16,6 +16,7 @@ menuconfig BSP_USING_UART3
menuconfig BSP_USING_UART4
bool "Enable USART4 for RS485"
default y
select BSP_USING_RS485
if BSP_USING_UART4
config SERIAL_BUS_NAME_4
string "serial bus 4 name"
@ -28,6 +29,10 @@ menuconfig BSP_USING_UART4
default "usart4_dev4"
endif
config BSP_USING_RS485
bool
default n
menuconfig BSP_USING_UART6
bool "Enable USART6"
default n

View File

@ -15,8 +15,8 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
export LINK_LWIP := $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a
endif
ifeq ($(CONFIG_USE_MONGOOSE), y)
export LINK_MONGOOSE := $(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose/mongoose.a
ifeq ($(CONFIG_APPLICATION_WEBSERVER), y)
export LINK_MONGOOSE := $(KERNEL_ROOT)/../../APP_Framework/Applications/webserver/mongoose.a
endif
export ARCH = arm

View File

@ -39,7 +39,7 @@ ifeq ($(CONFIG_CRYPTO), y)
APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/security/crypto/include #
endif
ifeq ($(CONFIG_USE_MONGOOSE),y)
ifeq ($(CONFIG_APPLICATION_WEBSERVER),y)
APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose #
endif