mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-01-19 08:08:25 +00:00
🐛 Fix LVGL / MKS WiFi long filename (#25483)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
88da531e5d
commit
d0669527c4
5 changed files with 472 additions and 449 deletions
|
@ -298,10 +298,8 @@ void lv_fill_rect(lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2, lv
|
|||
W25QXX.init(SPI_QUARTER_SPEED);
|
||||
}
|
||||
|
||||
#define TICK_CYCLE 1
|
||||
|
||||
uint16_t getTickDiff(uint16_t curTick, uint16_t lastTick) {
|
||||
return TICK_CYCLE * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick));
|
||||
uint16_t getTickDiff(const uint16_t curTick, const uint16_t lastTick) {
|
||||
return (TICK_CYCLE) * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick));
|
||||
}
|
||||
|
||||
static bool get_point(int16_t *x, int16_t *y) {
|
||||
|
|
|
@ -55,11 +55,11 @@
|
|||
#define WIFI_IO1_SET() WRITE(WIFI_IO1_PIN, HIGH);
|
||||
#define WIFI_IO1_RESET() WRITE(WIFI_IO1_PIN, LOW);
|
||||
|
||||
extern uint8_t Explore_Disk(char *path, uint8_t recu_level);
|
||||
uint8_t Explore_Disk(const char * const path, const uint8_t recu_level, const bool with_longnames);
|
||||
|
||||
extern uint8_t commands_in_queue;
|
||||
extern uint8_t sel_id;
|
||||
extern uint16_t getTickDiff(uint16_t curTick, uint16_t lastTick);
|
||||
uint16_t getTickDiff(const uint16_t curTick, const uint16_t lastTick);
|
||||
|
||||
volatile SZ_USART_FIFO WifiRxFifo;
|
||||
|
||||
|
@ -114,33 +114,34 @@ extern CLOUD_PARA cloud_para;
|
|||
extern bool once_flag, flash_preview_begin, default_preview_flg, gcode_preview_over;
|
||||
extern bool flash_dma_mode;
|
||||
|
||||
uint32_t getWifiTick() { return millis(); }
|
||||
millis_t getWifiTick() { return millis(); }
|
||||
|
||||
uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick) {
|
||||
return (lastTick <= curTick ? curTick - lastTick : 0xFFFFFFFF - lastTick + curTick) * TICK_CYCLE;
|
||||
millis_t getWifiTickDiff(const millis_t lastTick, const millis_t curTick) {
|
||||
return (TICK_CYCLE) * (lastTick <= curTick ? curTick - lastTick : 0xFFFFFFFFUL - lastTick + curTick);
|
||||
}
|
||||
|
||||
void wifi_delay(int n) {
|
||||
const uint32_t start = getWifiTick();
|
||||
while (getWifiTickDiff(start, getWifiTick()) < (uint32_t)n)
|
||||
void wifi_delay(const uint16_t n) {
|
||||
const millis_t start = getWifiTick();
|
||||
while (getWifiTickDiff(start, getWifiTick()) < millis_t(n))
|
||||
hal.watchdog_refresh();
|
||||
}
|
||||
|
||||
void wifi_reset() {
|
||||
uint32_t start = getWifiTick();
|
||||
const millis_t start = getWifiTick();
|
||||
WIFI_RESET();
|
||||
while (getWifiTickDiff(start, getWifiTick()) < 500) { /* nada */ }
|
||||
WIFI_SET();
|
||||
}
|
||||
|
||||
void mount_file_sys(uint8_t disk_type) {
|
||||
if (disk_type == FILE_SYS_SD) {
|
||||
TERN_(SDSUPPORT, card.mount());
|
||||
}
|
||||
else if (disk_type == FILE_SYS_USB) {
|
||||
void mount_file_sys(const uint8_t disk_type) {
|
||||
switch (disk_type) {
|
||||
case FILE_SYS_SD: TERN_(SDSUPPORT, card.mount()); break;
|
||||
case FILE_SYS_USB: break;
|
||||
}
|
||||
}
|
||||
|
||||
#define ILLEGAL_CHAR_REPLACE 0x5F // '_'
|
||||
|
||||
static bool longName2DosName(const char *longName, char *dosName) {
|
||||
uint8_t i = FILENAME_LENGTH;
|
||||
while (i) dosName[--i] = '\0';
|
||||
|
@ -152,18 +153,24 @@ static bool longName2DosName(const char *longName, char *dosName) {
|
|||
strcat_P(dosName, PSTR(".GCO"));
|
||||
return dosName[0] != '\0';
|
||||
}
|
||||
else {
|
||||
|
||||
// Fail for illegal characters
|
||||
if (c < 0x21 || c == 0x7F) // Check size, non-printable characters
|
||||
c = ILLEGAL_CHAR_REPLACE; // replace non-printable chars with underscore '_'
|
||||
else {
|
||||
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
|
||||
while (uint8_t b = pgm_read_byte(p++)) if (b == c) return false;
|
||||
if (c < 0x21 || c == 0x7F) return false; // Check size, non-printable characters
|
||||
dosName[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a')); // Uppercase required for 8.3 name
|
||||
while (const uint8_t b = pgm_read_byte(p++))
|
||||
if (b == c) c = ILLEGAL_CHAR_REPLACE; // replace illegal chars with underscore '_'
|
||||
}
|
||||
|
||||
dosName[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a')); // Uppercase required for 8.3 name
|
||||
|
||||
if (i >= 5) {
|
||||
strcat_P(dosName, PSTR("~1.GCO"));
|
||||
return dosName[0] != '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return dosName[0] != '\0'; // Return true if any name was set
|
||||
}
|
||||
|
||||
|
@ -562,8 +569,8 @@ static bool longName2DosName(const char *longName, char *dosName) {
|
|||
|
||||
#if ENABLED(MKS_WIFI_MODULE)
|
||||
|
||||
int raw_send_to_wifi(uint8_t *buf, int len) {
|
||||
if (buf == 0 || len <= 0) return 0;
|
||||
int raw_send_to_wifi(uint8_t * const buf, const int len) {
|
||||
if (buf == nullptr || len <= 0) return 0;
|
||||
for (int i = 0; i < len; i++) WIFISERIAL.write(*(buf + i));
|
||||
return len;
|
||||
}
|
||||
|
@ -701,13 +708,13 @@ int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int send_to_wifi(uint8_t * const buf, const int len) { return package_to_wifi(WIFI_TRANS_INF, buf, len); }
|
||||
|
||||
#define SEND_OK_TO_WIFI send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n"))
|
||||
int send_to_wifi(uint8_t *buf, int len) { return package_to_wifi(WIFI_TRANS_INF, buf, len); }
|
||||
inline void send_ok_to_wifi() { send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n")); }
|
||||
|
||||
void set_cur_file_sys(int fileType) { gCfgItems.fileSysType = fileType; }
|
||||
|
||||
void get_file_list(char *path) {
|
||||
void get_file_list(const char * const path, const bool with_longnames) {
|
||||
if (!path) return;
|
||||
|
||||
if (gCfgItems.fileSysType == FILE_SYS_SD) {
|
||||
|
@ -716,7 +723,7 @@ void get_file_list(char *path) {
|
|||
else if (gCfgItems.fileSysType == FILE_SYS_USB) {
|
||||
// udisk
|
||||
}
|
||||
Explore_Disk(path, 0);
|
||||
Explore_Disk(path, 0, with_longnames);
|
||||
}
|
||||
|
||||
char wait_ip_back_flag = 0;
|
||||
|
@ -795,7 +802,7 @@ typedef struct {
|
|||
uint8_t tail;
|
||||
} ESP_PROTOC_FRAME;
|
||||
|
||||
static int cut_msg_head(uint8_t *msg, uint16_t msgLen, uint16_t cutLen) {
|
||||
static int cut_msg_head(uint8_t * const msg, const uint16_t msgLen, uint16_t cutLen) {
|
||||
if (msgLen < cutLen) return 0;
|
||||
|
||||
else if (msgLen == cutLen) {
|
||||
|
@ -811,25 +818,31 @@ static int cut_msg_head(uint8_t *msg, uint16_t msgLen, uint16_t cutLen) {
|
|||
return msgLen - cutLen;
|
||||
}
|
||||
|
||||
uint8_t Explore_Disk(char *path , uint8_t recu_level) {
|
||||
char tmp[200];
|
||||
uint8_t Explore_Disk(const char * const path, const uint8_t recu_level, const bool with_longnames) {
|
||||
char Fstream[200];
|
||||
|
||||
if (!path) return 0;
|
||||
|
||||
const uint8_t fileCnt = card.get_num_Files();
|
||||
|
||||
MediaFile file;
|
||||
MediaFile *diveDir;
|
||||
for (uint8_t i = 0; i < fileCnt; i++) {
|
||||
card.getfilename_sorted(SD_ORDER(i, fileCnt));
|
||||
ZERO(tmp);
|
||||
strcpy(tmp, card.filename);
|
||||
|
||||
ZERO(Fstream);
|
||||
strcpy(Fstream, tmp);
|
||||
strcpy(Fstream, card.filename);
|
||||
|
||||
if (card.flag.filenameIsDir && recu_level <= 10)
|
||||
strcat_P(Fstream, PSTR(".DIR"));
|
||||
|
||||
strcat_P(Fstream, PSTR(" 0")); // report 0 file size
|
||||
|
||||
if (with_longnames) {
|
||||
strcat_P(Fstream, PSTR(" "));
|
||||
strcat_P(Fstream, card.longest_filename());
|
||||
}
|
||||
|
||||
strcat_P(Fstream, PSTR("\r\n"));
|
||||
send_to_wifi((uint8_t*)Fstream, strlen(Fstream));
|
||||
}
|
||||
|
@ -837,25 +850,36 @@ uint8_t Explore_Disk(char *path , uint8_t recu_level) {
|
|||
return fileCnt;
|
||||
}
|
||||
|
||||
static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
||||
int8_t tempBuf[100] = { 0 };
|
||||
uint8_t *tmpStr = 0;
|
||||
int cmd_value;
|
||||
volatile int print_rate;
|
||||
if (strchr((char *)cmd_line, '\n') && (strchr((char *)cmd_line, 'G') || strchr((char *)cmd_line, 'M') || strchr((char *)cmd_line, 'T'))) {
|
||||
tmpStr = (uint8_t *)strchr((char *)cmd_line, '\n');
|
||||
if (tmpStr) *tmpStr = '\0';
|
||||
|
||||
tmpStr = (uint8_t *)strchr((char *)cmd_line, '\r');
|
||||
if (tmpStr) *tmpStr = '\0';
|
||||
// Only accept commands with a linefeed
|
||||
char * const lfStr = strchr((char *)cmd_line, '\n');
|
||||
if (!lfStr) return;
|
||||
|
||||
tmpStr = (uint8_t *)strchr((char *)cmd_line, '*');
|
||||
if (tmpStr) *tmpStr = '\0';
|
||||
// Only accept commands with G, M, or T somewhere
|
||||
const char * const gStr = strchr((char *)cmd_line, 'G');
|
||||
const char * const mStr = strchr((char *)cmd_line, 'M');
|
||||
const char * const tStr = strchr((char *)cmd_line, 'T');
|
||||
if (!(gStr || mStr || tStr)) return;
|
||||
|
||||
tmpStr = (uint8_t *)strchr((char *)cmd_line, 'M');
|
||||
if (tmpStr) {
|
||||
cmd_value = atoi((char *)(tmpStr + 1));
|
||||
tmpStr = (uint8_t *)strchr((char *)tmpStr, ' ');
|
||||
// Replace the linefeed with nul terminator
|
||||
*lfStr = '\0';
|
||||
|
||||
// Terminate on the first cr, if any
|
||||
char * const crStr = strchr((char *)cmd_line, '\r');
|
||||
if (crStr) *crStr = '\0';
|
||||
|
||||
// Terminate on the checksum marker, if any
|
||||
char * const aStr = strchr((char *)cmd_line, '*');
|
||||
if (aStr) *aStr = '\0';
|
||||
|
||||
// Handle some M commands here
|
||||
if (mStr) {
|
||||
cmd_value = atoi(mStr + 1);
|
||||
char * const spStr = strchr(mStr, ' ');
|
||||
|
||||
switch (cmd_value) {
|
||||
|
||||
|
@ -863,62 +887,61 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
file_writer.fileTransfer = 0;
|
||||
if (uiCfg.print_state == IDLE) {
|
||||
int index = 0;
|
||||
|
||||
if (tmpStr == 0) {
|
||||
if (spStr == nullptr) {
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
send_to_wifi((uint8_t *)(STR_BEGIN_FILE_LIST "\r\n"), strlen(STR_BEGIN_FILE_LIST "\r\n"));
|
||||
get_file_list((char *)"0:/");
|
||||
get_file_list("0:/", false);
|
||||
send_to_wifi((uint8_t *)(STR_END_FILE_LIST "\r\n"), strlen(STR_END_FILE_LIST "\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
break;
|
||||
}
|
||||
|
||||
while (tmpStr[index] == ' ') index++;
|
||||
while (mStr[index] == ' ') index++;
|
||||
|
||||
if (gCfgItems.wifi_type == ESP_WIFI) {
|
||||
char *path = (char *)tempBuf;
|
||||
|
||||
if (strlen((char *)&tmpStr[index]) < 80) {
|
||||
char * const path = (char *)tempBuf;
|
||||
if (strlen(&mStr[index]) < 80) {
|
||||
send_to_wifi((uint8_t *)(STR_BEGIN_FILE_LIST "\r\n"), strlen(STR_BEGIN_FILE_LIST "\r\n"));
|
||||
|
||||
if (strncmp((char *)&tmpStr[index], "1:", 2) == 0)
|
||||
if (strncmp(&mStr[index], "1:", 2) == 0)
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
else if (strncmp((char *)&tmpStr[index], "0:", 2) == 0)
|
||||
else if (strncmp(&mStr[index], "0:", 2) == 0)
|
||||
gCfgItems.fileSysType = FILE_SYS_USB;
|
||||
|
||||
strcpy((char *)path, (char *)&tmpStr[index]);
|
||||
get_file_list(path);
|
||||
strcpy(path, &mStr[index]);
|
||||
const bool with_longnames = strchr(mStr, 'L') != nullptr;
|
||||
get_file_list(path, with_longnames);
|
||||
send_to_wifi((uint8_t *)(STR_END_FILE_LIST "\r\n"), strlen(STR_END_FILE_LIST "\r\n"));
|
||||
}
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 21: SEND_OK_TO_WIFI; break; // Init SD card
|
||||
case 21: send_ok_to_wifi(); break; // Init SD card
|
||||
|
||||
case 23:
|
||||
// Select the file
|
||||
if (uiCfg.print_state == IDLE) {
|
||||
int index = 0;
|
||||
while (tmpStr[index] == ' ') index++;
|
||||
while (mStr[index] == ' ') index++;
|
||||
|
||||
if (strstr_P((char *)&tmpStr[index], PSTR(".g")) || strstr_P((char *)&tmpStr[index], PSTR(".G"))) {
|
||||
if (strlen((char *)&tmpStr[index]) < 80) {
|
||||
if (strstr_P(&mStr[index], PSTR(".g")) || strstr_P(&mStr[index], PSTR(".G"))) {
|
||||
if (strlen(&mStr[index]) < 80) {
|
||||
ZERO(list_file.file_name[sel_id]);
|
||||
ZERO(list_file.long_name[sel_id]);
|
||||
uint8_t has_path_selected = 0;
|
||||
|
||||
if (gCfgItems.wifi_type == ESP_WIFI) {
|
||||
if (strncmp_P((char *)&tmpStr[index], PSTR("1:"), 2) == 0) {
|
||||
if (strncmp_P(&mStr[index], PSTR("1:"), 2) == 0) {
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
has_path_selected = 1;
|
||||
}
|
||||
else if (strncmp_P((char *)&tmpStr[index], PSTR("0:"), 2) == 0) {
|
||||
else if (strncmp_P(&mStr[index], PSTR("0:"), 2) == 0) {
|
||||
gCfgItems.fileSysType = FILE_SYS_USB;
|
||||
has_path_selected = 1;
|
||||
}
|
||||
else if (tmpStr[index] != '/')
|
||||
else if (mStr[index] != '/')
|
||||
strcat_P((char *)list_file.file_name[sel_id], PSTR("/"));
|
||||
|
||||
if (file_writer.fileTransfer == 1) {
|
||||
|
@ -926,25 +949,25 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
uint8_t fileName[sizeof(list_file.file_name[sel_id])];
|
||||
fileName[0] = '\0';
|
||||
if (has_path_selected == 1) {
|
||||
strcat((char *)fileName, (char *)&tmpStr[index + 3]);
|
||||
strcat((char *)fileName, &mStr[index + 3]);
|
||||
strcat_P((char *)list_file.file_name[sel_id], PSTR("/"));
|
||||
}
|
||||
else strcat((char *)fileName, (char *)&tmpStr[index]);
|
||||
else strcat((char *)fileName, &mStr[index]);
|
||||
if (!longName2DosName((const char *)fileName, dosName))
|
||||
strcpy_P(list_file.file_name[sel_id], PSTR("notValid"));
|
||||
strcat((char *)list_file.file_name[sel_id], dosName);
|
||||
strcat((char *)list_file.long_name[sel_id], dosName);
|
||||
strcat((char *)list_file.long_name[sel_id], (const char *)fileName);
|
||||
}
|
||||
else {
|
||||
strcat((char *)list_file.file_name[sel_id], (char *)&tmpStr[index]);
|
||||
strcat((char *)list_file.long_name[sel_id], (char *)&tmpStr[index]);
|
||||
strcat((char *)list_file.file_name[sel_id], &mStr[index]);
|
||||
strcat((char *)list_file.long_name[sel_id], &mStr[index]);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
strcpy(list_file.file_name[sel_id], (char *)&tmpStr[index]);
|
||||
strcpy(list_file.file_name[sel_id], &mStr[index]);
|
||||
|
||||
char *cur_name=strrchr(list_file.file_name[sel_id],'/');
|
||||
char *cur_name = strrchr(list_file.file_name[sel_id],'/');
|
||||
|
||||
card.openFileRead(cur_name);
|
||||
|
||||
|
@ -954,7 +977,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
send_to_wifi((uint8_t *)"file.open failed\r\n", strlen("file.open failed\r\n"));
|
||||
strcpy_P(list_file.file_name[sel_id], PSTR("notValid"));
|
||||
}
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1025,7 +1048,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
lv_draw_printing();
|
||||
}
|
||||
}
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
break;
|
||||
|
||||
case 25:
|
||||
|
@ -1044,13 +1067,13 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
else
|
||||
default_preview_flg = true;
|
||||
lv_draw_printing();
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
}
|
||||
break;
|
||||
|
||||
case 26:
|
||||
// Stop print file
|
||||
if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED) || (uiCfg.print_state == REPRINTING)) {
|
||||
if (uiCfg.print_state == WORKING || uiCfg.print_state == PAUSED || uiCfg.print_state == REPRINTING) {
|
||||
stop_print_time();
|
||||
|
||||
clear_cur_ui();
|
||||
|
@ -1061,13 +1084,13 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
|
||||
lv_draw_ready_print();
|
||||
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
}
|
||||
break;
|
||||
|
||||
case 27:
|
||||
// Report print rate
|
||||
if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)|| (uiCfg.print_state == REPRINTING)) {
|
||||
if (uiCfg.print_state == WORKING || uiCfg.print_state == PAUSED|| uiCfg.print_state == REPRINTING) {
|
||||
print_rate = uiCfg.totalSend;
|
||||
ZERO(tempBuf);
|
||||
sprintf_P((char *)tempBuf, PSTR("M27 %d\r\n"), print_rate);
|
||||
|
@ -1080,10 +1103,10 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
if (uiCfg.print_state == IDLE) {
|
||||
|
||||
int index = 0;
|
||||
while (tmpStr[index] == ' ') index++;
|
||||
while (mStr[index] == ' ') index++;
|
||||
|
||||
if (strstr_P((char *)&tmpStr[index], PSTR(".g")) || strstr_P((char *)&tmpStr[index], PSTR(".G"))) {
|
||||
strcpy((char *)file_writer.saveFileName, (char *)&tmpStr[index]);
|
||||
if (strstr_P(&mStr[index], PSTR(".g")) || strstr_P(&mStr[index], PSTR(".G"))) {
|
||||
strcpy((char *)file_writer.saveFileName, &mStr[index]);
|
||||
|
||||
if (gCfgItems.fileSysType == FILE_SYS_SD) {
|
||||
ZERO(tempBuf);
|
||||
|
@ -1100,7 +1123,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
card.openFileWrite(cur_name);
|
||||
if (card.isFileOpen()) {
|
||||
ZERO(file_writer.saveFileName);
|
||||
strcpy((char *)file_writer.saveFileName, (char *)&tmpStr[index]);
|
||||
strcpy((char *)file_writer.saveFileName, &mStr[index]);
|
||||
ZERO(tempBuf);
|
||||
sprintf_P((char *)tempBuf, PSTR("Writing to file: %s\r\n"), (char *)file_writer.saveFileName);
|
||||
wifi_ret_ack();
|
||||
|
@ -1122,7 +1145,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
ZERO(tempBuf);
|
||||
if (cmd_value == 105) {
|
||||
|
||||
SEND_OK_TO_WIFI;
|
||||
send_ok_to_wifi();
|
||||
|
||||
char *outBuf = (char *)tempBuf;
|
||||
char tbuf[34];
|
||||
|
@ -1173,7 +1196,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
break;
|
||||
|
||||
case 992:
|
||||
if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)) {
|
||||
if (uiCfg.print_state == WORKING || uiCfg.print_state == PAUSED) {
|
||||
ZERO(tempBuf);
|
||||
sprintf_P((char *)tempBuf, PSTR("M992 %d%d:%d%d:%d%d\r\n"), print_time.hours/10, print_time.hours%10, print_time.minutes/10, print_time.minutes%10, print_time.seconds/10, print_time.seconds%10);
|
||||
wifi_ret_ack();
|
||||
|
@ -1182,7 +1205,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
break;
|
||||
|
||||
case 994:
|
||||
if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)) {
|
||||
if (uiCfg.print_state == WORKING || uiCfg.print_state == PAUSED) {
|
||||
ZERO(tempBuf);
|
||||
if (strlen((char *)list_file.file_name[sel_id]) > (100 - 1)) return;
|
||||
sprintf_P((char *)tempBuf, PSTR("M994 %s;%d\n"), list_file.file_name[sel_id], (int)gCfgItems.curFilesize);
|
||||
|
@ -1192,28 +1215,34 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
break;
|
||||
|
||||
case 997:
|
||||
if (uiCfg.print_state == IDLE) {
|
||||
#define SENDIDLE "M997 IDLE\r\n"
|
||||
#define SENDPRINTING "M997 PRINTING\r\n"
|
||||
#define SENDPAUSE "M997 PAUSE\r\n"
|
||||
switch (uiCfg.print_state) {
|
||||
default: break;
|
||||
case IDLE:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)"M997 IDLE\r\n", strlen("M997 IDLE\r\n"));
|
||||
}
|
||||
else if (uiCfg.print_state == WORKING) {
|
||||
send_to_wifi((uint8_t *)SENDIDLE, strlen(SENDIDLE));
|
||||
break;
|
||||
case WORKING:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)"M997 PRINTING\r\n", strlen("M997 PRINTING\r\n"));
|
||||
}
|
||||
else if (uiCfg.print_state == PAUSED) {
|
||||
send_to_wifi((uint8_t *)SENDPRINTING, strlen(SENDPRINTING));
|
||||
break;
|
||||
case PAUSED:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)"M997 PAUSE\r\n", strlen("M997 PAUSE\r\n"));
|
||||
}
|
||||
else if (uiCfg.print_state == REPRINTING) {
|
||||
send_to_wifi((uint8_t *)SENDPAUSE, strlen(SENDPAUSE));
|
||||
break;
|
||||
case REPRINTING:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)"M997 PAUSE\r\n", strlen("M997 PAUSE\r\n"));
|
||||
send_to_wifi((uint8_t *)SENDPAUSE, strlen(SENDPAUSE));
|
||||
break;
|
||||
}
|
||||
if (!uiCfg.command_send) get_wifi_list_command_send();
|
||||
break;
|
||||
|
||||
case 998:
|
||||
if (uiCfg.print_state == IDLE) {
|
||||
const int v = atoi((char *)tmpStr);
|
||||
const int v = atoi(mStr);
|
||||
if (v == 0 || v == 1) set_cur_file_sys(v);
|
||||
wifi_ret_ack();
|
||||
}
|
||||
|
@ -1221,25 +1250,25 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
|
||||
case 115:
|
||||
ZERO(tempBuf);
|
||||
SEND_OK_TO_WIFI;
|
||||
send_to_wifi((uint8_t *)"FIRMWARE_NAME:Robin_nano\r\n", strlen("FIRMWARE_NAME:Robin_nano\r\n"));
|
||||
send_ok_to_wifi();
|
||||
#define SENDFW "FIRMWARE_NAME:Robin_nano\r\n"
|
||||
send_to_wifi((uint8_t *)SENDFW, strlen(SENDFW));
|
||||
break;
|
||||
|
||||
default:
|
||||
strcat_P((char *)cmd_line, PSTR("\n"));
|
||||
|
||||
if (espGcodeFifo.wait_tick > 5) {
|
||||
const uint32_t left = espGcodeFifo.r > espGcodeFifo.w
|
||||
? espGcodeFifo.r - espGcodeFifo.w - 1
|
||||
: WIFI_GCODE_BUFFER_SIZE + espGcodeFifo.r - espGcodeFifo.w - 1;
|
||||
uint32_t left = espGcodeFifo.r - espGcodeFifo.w - 1;
|
||||
if (espGcodeFifo.r > espGcodeFifo.w) left += WIFI_GCODE_BUFFER_SIZE;
|
||||
|
||||
if (left >= strlen((const char *)cmd_line)) {
|
||||
for (uint32_t index = 0; index < strlen((const char *)cmd_line); index++) {
|
||||
espGcodeFifo.Buffer[espGcodeFifo.w] = cmd_line[index] ;
|
||||
espGcodeFifo.w = (espGcodeFifo.w + 1) % WIFI_GCODE_BUFFER_SIZE;
|
||||
espGcodeFifo.Buffer[espGcodeFifo.w] = cmd_line[index];
|
||||
espGcodeFifo.w = (espGcodeFifo.w + 1) % (WIFI_GCODE_BUFFER_SIZE);
|
||||
}
|
||||
if (left - WIFI_GCODE_BUFFER_LEAST_SIZE >= strlen((const char *)cmd_line))
|
||||
SEND_OK_TO_WIFI;
|
||||
if (left - (WIFI_GCODE_BUFFER_LEAST_SIZE) >= strlen((const char *)cmd_line))
|
||||
send_ok_to_wifi();
|
||||
else
|
||||
need_ok_later = true;
|
||||
}
|
||||
|
@ -1248,26 +1277,25 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
// Add another linefeed to the command, terminate with null
|
||||
strcat_P((char *)cmd_line, PSTR("\n"));
|
||||
|
||||
if (espGcodeFifo.wait_tick > 5) {
|
||||
const uint32_t left_g = espGcodeFifo.r > espGcodeFifo.w
|
||||
? espGcodeFifo.r - espGcodeFifo.w - 1
|
||||
: WIFI_GCODE_BUFFER_SIZE + espGcodeFifo.r - espGcodeFifo.w - 1;
|
||||
uint32_t left_g = espGcodeFifo.r - espGcodeFifo.w - 1;
|
||||
if (espGcodeFifo.r > espGcodeFifo.w) left_g += WIFI_GCODE_BUFFER_SIZE;
|
||||
|
||||
if (left_g >= strlen((const char *)cmd_line)) {
|
||||
for (uint32_t index = 0; index < strlen((const char *)cmd_line); index++) {
|
||||
espGcodeFifo.Buffer[espGcodeFifo.w] = cmd_line[index] ;
|
||||
espGcodeFifo.w = (espGcodeFifo.w + 1) % WIFI_GCODE_BUFFER_SIZE;
|
||||
if (left_g >= strlen((char * const)cmd_line)) {
|
||||
for (uint32_t index = 0; index < strlen((char * const)cmd_line); index++) {
|
||||
espGcodeFifo.Buffer[espGcodeFifo.w] = cmd_line[index];
|
||||
espGcodeFifo.w = (espGcodeFifo.w + 1) % (WIFI_GCODE_BUFFER_SIZE);
|
||||
}
|
||||
if (left_g - WIFI_GCODE_BUFFER_LEAST_SIZE >= strlen((const char *)cmd_line))
|
||||
SEND_OK_TO_WIFI;
|
||||
if (left_g - (WIFI_GCODE_BUFFER_LEAST_SIZE) >= strlen((char * const)cmd_line))
|
||||
send_ok_to_wifi();
|
||||
else
|
||||
need_ok_later = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t charAtArray(const uint8_t *_array, uint32_t _arrayLen, uint8_t _char) {
|
||||
|
@ -1281,7 +1309,7 @@ void get_wifi_list_command_send() {
|
|||
raw_send_to_wifi(cmd_wifi_list, COUNT(cmd_wifi_list));
|
||||
}
|
||||
|
||||
static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
static void net_msg_handle(const uint8_t * const msg, const uint16_t msgLen) {
|
||||
int wifiNameLen, wifiKeyLen, hostLen, id_len, ver_len;
|
||||
|
||||
if (msgLen <= 0) return;
|
||||
|
@ -1316,7 +1344,7 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
|||
}
|
||||
}
|
||||
|
||||
cloud_para.state =msg[10 + wifiNameLen + wifiKeyLen];
|
||||
cloud_para.state = msg[10 + wifiNameLen + wifiKeyLen];
|
||||
hostLen = msg[11 + wifiNameLen + wifiKeyLen];
|
||||
if (cloud_para.state) {
|
||||
if (hostLen < 96) {
|
||||
|
@ -1356,7 +1384,7 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
|||
}
|
||||
}
|
||||
|
||||
static void wifi_list_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
static void wifi_list_msg_handle(const uint8_t * const msg, const uint16_t msgLen) {
|
||||
int wifiNameLen,wifiMsgIdex = 1;
|
||||
int8_t wifi_name_is_same = 0;
|
||||
int8_t i, j;
|
||||
|
@ -1415,16 +1443,15 @@ static void wifi_list_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
|||
}
|
||||
}
|
||||
|
||||
static void gcode_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
static void gcode_msg_handle(const uint8_t * const msg, const uint16_t msgLen) {
|
||||
uint8_t gcodeBuf[100] = { 0 };
|
||||
char *index_s, *index_e;
|
||||
|
||||
if (msgLen <= 0) return;
|
||||
|
||||
index_s = (char *)msg;
|
||||
index_e = (char *)strchr((char *)msg, '\n');
|
||||
char *index_s = (char *)msg,
|
||||
*index_e = strchr((char *)msg, '\n');
|
||||
if (*msg == 'N') {
|
||||
index_s = (char *)strchr((char *)msg, ' ');
|
||||
index_s = strchr((char *)msg, ' ');
|
||||
while (*index_s == ' ') index_s++;
|
||||
}
|
||||
while ((index_e != 0) && ((int)index_s < (int)index_e)) {
|
||||
|
@ -1435,7 +1462,7 @@ static void gcode_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
|||
}
|
||||
while ((*index_e == '\r') || (*index_e == '\n')) index_e++;
|
||||
index_s = index_e;
|
||||
index_e = (char *)strchr(index_s, '\n');
|
||||
index_e = strchr(index_s, '\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1482,8 +1509,8 @@ void utf8_2_unicode(uint8_t *source, uint8_t Len) {
|
|||
COPY(source, FileName_unicode);
|
||||
}
|
||||
|
||||
static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
uint8_t fileNameLen = *msg;
|
||||
static void file_first_msg_handle(const uint8_t * const msg, const uint16_t msgLen) {
|
||||
const uint8_t fileNameLen = *msg;
|
||||
|
||||
if (msgLen != fileNameLen + 5) return;
|
||||
|
||||
|
@ -1565,8 +1592,8 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
|||
|
||||
#define FRAG_MASK ~_BV32(31)
|
||||
|
||||
static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
uint32_t frag = *((uint32_t *)msg);
|
||||
static void file_fragment_msg_handle(const uint8_t * const msg, const uint16_t msgLen) {
|
||||
const uint32_t frag = *((uint32_t *)msg);
|
||||
if ((frag & FRAG_MASK) != (uint32_t)(lastFragment + 1)) {
|
||||
ZERO(public_buf);
|
||||
file_writer.write_index = 0;
|
||||
|
@ -1842,7 +1869,7 @@ void wifi_rcv_handle() {
|
|||
}
|
||||
if (need_ok_later && !queue.ring_buffer.full()) {
|
||||
need_ok_later = false;
|
||||
send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n"));
|
||||
send_ok_to_wifi();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1872,7 +1899,7 @@ void wifi_rcv_handle() {
|
|||
|
||||
if (wifiTransError.flag == 0x1) {
|
||||
wifiTransError.now_tick = getWifiTick();
|
||||
if (getWifiTickDiff(wifiTransError.start_tick, wifiTransError.now_tick) > WAIT_ESP_TRANS_TIMEOUT_TICK) {
|
||||
if (getWifiTickDiff(wifiTransError.start_tick, wifiTransError.now_tick) > (WAIT_ESP_TRANS_TIMEOUT_TICK)) {
|
||||
wifiTransError.flag = 0;
|
||||
WIFI_IO1_RESET();
|
||||
}
|
||||
|
@ -1992,7 +2019,7 @@ void get_wifi_commands() {
|
|||
|
||||
char wifi_char = espGcodeFifo.Buffer[espGcodeFifo.r];
|
||||
|
||||
espGcodeFifo.r = (espGcodeFifo.r + 1) % WIFI_GCODE_BUFFER_SIZE;
|
||||
espGcodeFifo.r = (espGcodeFifo.r + 1) % (WIFI_GCODE_BUFFER_SIZE);
|
||||
|
||||
/**
|
||||
* If the character ends the line
|
||||
|
|
|
@ -179,14 +179,14 @@ extern CLOUD_PARA cloud_para;
|
|||
|
||||
extern WIFI_GCODE_BUFFER espGcodeFifo;
|
||||
|
||||
uint32_t getWifiTick();
|
||||
uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick);
|
||||
millis_t getWifiTick();
|
||||
millis_t getWifiTickDiff(const millis_t lastTick, const millis_t curTick);
|
||||
|
||||
void mks_esp_wifi_init();
|
||||
extern int cfg_cloud_flag;
|
||||
int send_to_wifi(uint8_t *buf, int len);
|
||||
int send_to_wifi(uint8_t * const buf, const int len);
|
||||
void wifi_looping();
|
||||
int raw_send_to_wifi(uint8_t *buf, int len);
|
||||
int raw_send_to_wifi(uint8_t * const buf, const int len);
|
||||
int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len);
|
||||
void get_wifi_list_command_send();
|
||||
void get_wifi_commands();
|
||||
|
|
|
@ -38,10 +38,8 @@
|
|||
|
||||
extern SZ_USART_FIFO WifiRxFifo;
|
||||
|
||||
extern int readUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len);
|
||||
extern int writeUsartFifo(SZ_USART_FIFO * fifo, int8_t * buf, int32_t len);
|
||||
void esp_port_begin(uint8_t interrupt);
|
||||
void wifi_delay(int n);
|
||||
void wifi_delay(const uint16_t n);
|
||||
|
||||
#define ARRAY_SIZE(a) sizeof(a) / sizeof((a)[0])
|
||||
|
||||
|
@ -246,7 +244,7 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t
|
|||
|
||||
const size_t headerLength = 8;
|
||||
|
||||
uint32_t startTime = getWifiTick();
|
||||
const millis_t startTime = getWifiTick();
|
||||
uint8_t hdr[headerLength];
|
||||
uint16_t hdrIdx = 0;
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ typedef struct {
|
|||
UploadState state;
|
||||
uint32_t retriesPerBaudRate;
|
||||
uint32_t connectAttemptNumber;
|
||||
uint32_t lastAttemptTime;
|
||||
uint32_t lastResetTime;
|
||||
millis_t lastAttemptTime;
|
||||
millis_t lastResetTime;
|
||||
uint32_t uploadBlockNumber;
|
||||
uint32_t uploadNextPercentToReport;
|
||||
EspUploadResult uploadResult;
|
||||
|
|
Loading…
Reference in a new issue