/**
******************************************************************************
成都浩然电子有限公司
电话：028-86127089       0755-86066647
传真：028-86127039
网址：http://www.hschip.com
日期：2016-03

硬件平台： 浩然电子评估板  HS-EVBW7500P
W7500P/W7500技术交流QQ群： 723052786
本测试为外网测试，请保证W7500的网线可以访问Internet
******************************************************************************
*/

#include <stdio.h>
#include "W7500x.h"
#include "ip_config.h"
#include "time_delay.h"
#include "bsp_uart.h"
#include "bsp_gpio.h"

#include "httpServer.h"
#include "httpParser.h"
#include "httpUtil.h"
#include "webpage.h"
#include "netbios.h"

#define _MAIN_DEBUG_

uint8_t test_buf[2048];
uint8_t socknumlist[] = {2, 3, 4, 5, 6, 7};

#define TICKRATE_HZ1 (1000)		/* 1 ticks per millisecond, for SysTick */
#define TICKRATE_HZ2 (1)		/* 1 ticks per second, for Timer0 */

uint8_t RX_BUF[DATA_BUF_SIZE];
uint8_t TX_BUF[DATA_BUF_SIZE];
int main()
{
    SystemInit();     												 		/* 系统内部时钟初始化 */ 
		delay_init();																	/* 系统滴答时钟配置*/ 
//		UART_Configuration();													/*初始化串口通信:115200@8-n-1*/	   
		S_UART_Init(115200);													 /* Configure UART2 */
		LED_GPIO_Configuration();
		phy_init();																		/*PHY初始化设置 */
		set_w7500_ip();
    printf(" TEST- START \r\n"); 
	/* HTTP Server Initialization  */
	httpServer_init(TX_BUF, RX_BUF, MAX_HTTPSOCK, socknumlist);		// Tx/Rx buffers (1kB)
	reg_httpServer_cbfunc(NVIC_SystemReset, NULL); 					// Callback: MCU Reset

	{
		/* Web content registration (web content in webpage.h, Example web pages) */

		// Index page and netinfo / base64 image demo
		reg_httpServer_webContent((uint8_t *)"index.html", (uint8_t *)index_page);				// index.html 		: Main page example
		reg_httpServer_webContent((uint8_t *)"netinfo.html", (uint8_t *)netinfo_page);			// netinfo.html 	: Network information example page
		reg_httpServer_webContent((uint8_t *)"netinfo.js", (uint8_t *)WIZwiki_W7500_web_netinfo_js);	// netinfo.js 		: JavaScript for Read Network configuration 	(+ ajax.js)
		//reg_httpServer_webContent((uint8_t *)"img.html", (uint8_t *)img_page);					// img.html 		: Base64 Image data example page

		// Example #1
		reg_httpServer_webContent((uint8_t *)"dio.html", (uint8_t *)dio_page);					// dio.html 		: Digital I/O control example page
		reg_httpServer_webContent((uint8_t *)"dio.js", (uint8_t *)WIZwiki_W7500_web_dio_js);			// dio.js 			: JavaScript for digital I/O control 	(+ ajax.js)

		// Example #2
		//reg_httpServer_webContent((uint8_t *)"ain.html", (uint8_t *)ain_page);					// ain.html 		: Analog input monitor example page
		//reg_httpServer_webContent((uint8_t *)"ain.js", (uint8_t *)WIZwiki_W7500_web_ain_js);			// ain.js 			: JavaScript for Analog input monitor	(+ ajax.js)

		// Example #3
		//reg_httpServer_webContent((uint8_t *)"ain_gauge.html", (uint8_t *)ain_gauge_page);		// ain_gauge.html 	: Analog input monitor example page; using Google Gauge chart
		//reg_httpServer_webContent((uint8_t *)"ain_gauge.js", (uint8_t *)ain_gauge_js);			// ain_gauge.js 	: JavaScript for Google Gauge chart		(+ ajax.js)

		// AJAX JavaScript functions
		reg_httpServer_webContent((uint8_t *)"ajax.js", (uint8_t *)WIZwiki_W7500_web_ajax_js);			// ajax.js			: JavaScript for AJAX request transfer

		#ifdef _MAIN_DEBUG_
		display_reg_webContent_list();
		#endif
	}

	/* Main loop ***************************************/
    while(1)
    {
			do_netbios();
			httpServer_run(0); 	// HTTP Server handler
		}
}


