My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wifi_module.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #include "../../../inc/MarlinConfigPre.h"
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #define UART_RX_BUFFER_SIZE 1024
  31. #define UART_FIFO_BUFFER_SIZE 1024
  32. #define WIFI_DECODE_TYPE 1
  33. #define IP_DHCP_FLAG 1
  34. #define WIFI_AP_NAME "TP-LINK_MKS"
  35. #define WIFI_KEY_CODE "makerbase"
  36. #define IP_ADDR "192.168.3.100"
  37. #define IP_MASK "255.255.255.0"
  38. #define IP_GATE "192.168.3.1"
  39. #define IP_DNS "192.168.3.1"
  40. #define AP_IP_DHCP_FLAG 1
  41. #define AP_IP_ADDR "192.168.3.100"
  42. #define AP_IP_MASK "255.255.255.0"
  43. #define AP_IP_GATE "192.168.3.1"
  44. #define AP_IP_DNS "192.168.3.1"
  45. #define IP_START_IP "192.168.3.1"
  46. #define IP_END_IP "192.168.3.255"
  47. #define UDISKBUFLEN 1024
  48. typedef enum {
  49. udisk_buf_empty = 0,
  50. udisk_buf_full,
  51. } UDISK_DATA_BUFFER_STATE;
  52. #define TRANS_RCV_FIFO_BLOCK_NUM 14
  53. typedef struct {
  54. bool receiveEspData;
  55. unsigned char *bufferAddr[TRANS_RCV_FIFO_BLOCK_NUM];
  56. unsigned char *p;
  57. UDISK_DATA_BUFFER_STATE state[TRANS_RCV_FIFO_BLOCK_NUM];
  58. unsigned char read_cur;
  59. unsigned char write_cur;
  60. } WIFI_DMA_RCV_FIFO;
  61. typedef struct {
  62. uint8_t flag; // 0x0: no error; 0x01: error
  63. uint32_t start_tick; // error start time
  64. uint32_t now_tick;
  65. } WIFI_TRANS_ERROR;
  66. extern volatile WIFI_TRANS_ERROR wifiTransError;
  67. typedef struct {
  68. char ap_name[32]; // wifi-name
  69. char keyCode[64]; // wifi password
  70. int decodeType;
  71. int baud;
  72. int mode;
  73. } WIFI_PARA;
  74. typedef struct {
  75. char state;
  76. char hostUrl[96];
  77. int port;
  78. char id[21];
  79. } CLOUD_PARA;
  80. typedef struct {
  81. char dhcp_flag;
  82. char ip_addr[16];
  83. char mask[16];
  84. char gate[16];
  85. char dns[16];
  86. char dhcpd_flag;
  87. char dhcpd_ip[16];
  88. char dhcpd_mask[16];
  89. char dhcpd_gate[16];
  90. char dhcpd_dns[16];
  91. char start_ip_addr[16];
  92. char end_ip_addr[16];
  93. } IP_PARA;
  94. typedef enum {
  95. WIFI_NOT_CONFIG,
  96. WIFI_CONFIG_MODE,
  97. WIFI_CONFIG_DHCP,
  98. WIFI_CONFIG_AP,
  99. WIFI_CONFIG_IP_INF,
  100. WIFI_CONFIG_DNS,
  101. WIFI_CONFIG_TCP,
  102. WIFI_CONFIG_SERVER,
  103. WIFI_CONFIG_REMOTE_PORT,
  104. WIFI_CONFIG_BAUD,
  105. WIFI_CONFIG_COMMINT,
  106. WIFI_CONFIG_OK,
  107. WIFI_GET_IP_OK,
  108. WIFI_RECONN,
  109. WIFI_CONNECTED,
  110. WIFI_WAIT_TRANS_START,
  111. WIFI_TRANS_FILE,
  112. WIFI_CONFIG_DHCPD,
  113. WIFI_COFIG_DHCPD_IP,
  114. WIFI_COFIG_DHCPD_DNS,
  115. WIFI_EXCEPTION,
  116. } WIFI_STATE;
  117. typedef enum {
  118. TRANSFER_IDLE,
  119. TRANSFERRING,
  120. TRANSFER_STORE,
  121. } TRANSFER_STATE;
  122. extern volatile TRANSFER_STATE esp_state;
  123. typedef struct {
  124. char buf[20][80];
  125. int rd_index;
  126. int wt_index;
  127. } QUEUE;
  128. typedef enum {
  129. WIFI_PARA_SET, // 0x0:net parameter
  130. WIFI_PRINT_INF, // 0x1:print message
  131. WIFI_TRANS_INF, // 0x2:Pass through information
  132. WIFI_EXCEP_INF, // 0x3:Exception information
  133. WIFI_CLOUD_CFG, // 0x4:cloud config
  134. WIFI_CLOUD_UNBIND, // 0x5:Unbind ID
  135. } WIFI_RET_TYPE;
  136. typedef struct {
  137. uint32_t uart_read_point;
  138. uint32_t uart_write_point;
  139. //uint8_t uartTxBuffer[UART_FIFO_BUFFER_SIZE];
  140. } SZ_USART_FIFO;
  141. #define WIFI_GCODE_BUFFER_LEAST_SIZE 96
  142. #define WIFI_GCODE_BUFFER_SIZE (WIFI_GCODE_BUFFER_LEAST_SIZE * 3)
  143. typedef struct {
  144. uint8_t wait_tick;
  145. uint8_t Buffer[WIFI_GCODE_BUFFER_SIZE];
  146. uint32_t r;
  147. uint32_t w;
  148. } WIFI_GCODE_BUFFER;
  149. extern volatile WIFI_STATE wifi_link_state;
  150. extern WIFI_PARA wifiPara;
  151. extern IP_PARA ipPara;
  152. extern CLOUD_PARA cloud_para;
  153. extern WIFI_GCODE_BUFFER espGcodeFifo;
  154. uint32_t getWifiTick();
  155. uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick);
  156. void mks_esp_wifi_init();
  157. extern int cfg_cloud_flag;
  158. int send_to_wifi(uint8_t *buf, int len);
  159. void wifi_looping();
  160. int raw_send_to_wifi(uint8_t *buf, int len);
  161. int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len);
  162. void get_wifi_list_command_send();
  163. void get_wifi_commands();
  164. int readWifiBuf(int8_t *buf, int32_t len);
  165. void mks_wifi_firmware_update();
  166. int usartFifoAvailable(SZ_USART_FIFO *fifo);
  167. int readUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len);
  168. void esp_port_begin(uint8_t interrupt);
  169. #ifdef __cplusplus
  170. } /* C-declarations for C++ */
  171. #endif