httpServer.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. @file httpServer.h
  3. @brief Define constants and functions related HTTP Web server.
  4. */
  5. #include <stdint.h>
  6. #ifndef __HTTPSERVER_H__
  7. #define __HTTPSERVER_H__
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. // HTTP Server debug message enable
  12. #define _HTTPSERVER_DEBUG_
  13. #define INITIAL_WEBPAGE "index.html"
  14. #define M_INITIAL_WEBPAGE "m/index.html"
  15. #define MOBILE_INITIAL_WEBPAGE "mobile/index.html"
  16. /* Web Server Content Storage Select */
  17. //#define _USE_SDCARD_
  18. #ifndef _USE_SDCARD_
  19. //#define _USE_FLASH_
  20. #endif
  21. #if !defined(_USE_SDCARD_) && !defined(_USE_FLASH_)
  22. #define _NOTUSED_STORAGE_
  23. #endif
  24. /* Watchdog timer */
  25. //#define _USE_WATCHDOG_
  26. /*********************************************
  27. * HTTP Process states list
  28. *********************************************/
  29. #define STATE_HTTP_IDLE 0 /* IDLE, Waiting for data received (TCP established) */
  30. #define STATE_HTTP_REQ_INPROC 1 /* Received HTTP request from HTTP client */
  31. #define STATE_HTTP_REQ_DONE 2 /* The end of HTTP request parse */
  32. #define STATE_HTTP_RES_INPROC 3 /* Sending the HTTP response to HTTP client (in progress) */
  33. #define STATE_HTTP_RES_DONE 4 /* The end of HTTP response send (HTTP transaction ended) */
  34. /*********************************************
  35. * HTTP Simple Return Value
  36. *********************************************/
  37. #define HTTP_FAILED 0
  38. #define HTTP_OK 1
  39. #define HTTP_RESET 2
  40. /*********************************************
  41. * HTTP Content NAME length
  42. *********************************************/
  43. #define MAX_CONTENT_NAME_LEN 128
  44. /*********************************************
  45. * HTTP Timeout
  46. *********************************************/
  47. #define HTTP_MAX_TIMEOUT_SEC 3 // Sec.
  48. typedef enum
  49. {
  50. NONE, ///< Web storage none
  51. CODEFLASH, ///< Code flash memory
  52. SDCARD, ///< SD card
  53. DATAFLASH ///< External data flash memory
  54. }StorageType;
  55. typedef struct _st_http_socket
  56. {
  57. uint8_t sock_status;
  58. uint8_t file_name[MAX_CONTENT_NAME_LEN];
  59. uint32_t file_start;
  60. uint32_t file_len;
  61. uint32_t file_offset; // (start addr + sent size...)
  62. uint8_t storage_type; // Storage type; Code flash, SDcard, Data flash ...
  63. }st_http_socket;
  64. // Web content structure for file in code flash memory
  65. #define MAX_CONTENT_CALLBACK 20
  66. typedef struct _httpServer_webContent
  67. {
  68. uint8_t * content_name;
  69. uint32_t content_len;
  70. uint8_t * content;
  71. }httpServer_webContent;
  72. void httpServer_init(uint8_t * tx_buf, uint8_t * rx_buf, uint8_t cnt, uint8_t * socklist);
  73. void reg_httpServer_cbfunc(void(*mcu_reset)(void), void(*wdt_reset)(void));
  74. void httpServer_run(uint8_t seqnum);
  75. void reg_httpServer_webContent(uint8_t * content_name, uint8_t * content);
  76. uint8_t find_userReg_webContent(uint8_t * content_name, uint16_t * content_num, uint32_t * file_len);
  77. uint16_t read_userReg_webContent(uint16_t content_num, uint8_t * buf, uint32_t offset, uint16_t size);
  78. uint8_t display_reg_webContent_list(void);
  79. /*
  80. * @brief HTTP Server 1sec Tick Timer handler
  81. * @note SHOULD BE register to your system 1s Tick timer handler
  82. */
  83. void httpServer_time_handler(void);
  84. uint32_t get_httpServer_timecount(void);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif