Use dynamic linebfr
This commit is contained in:
parent
2dfb5666b9
commit
f4103bc386
|
|
@ -1931,7 +1931,7 @@ static float probe_pt(float x, float y, float z_before) {
|
||||||
#define EECHUNKSIZE 32
|
#define EECHUNKSIZE 32
|
||||||
// :<count><offset><type><data><cksum>EOL
|
// :<count><offset><type><data><cksum>EOL
|
||||||
#define EELINESIZE (1 + 2 + 4 + 2 + (2 * EECHUNKSIZE) + 2 + 1)
|
#define EELINESIZE (1 + 2 + 4 + 2 + (2 * EECHUNKSIZE) + 2 + 1)
|
||||||
static char linebfr[EELINESIZE + 1];
|
static char *linebfr;
|
||||||
|
|
||||||
static uint16_t bfrVal(char *ptr, uint8_t len)
|
static uint16_t bfrVal(char *ptr, uint8_t len)
|
||||||
{
|
{
|
||||||
|
|
@ -1966,6 +1966,10 @@ void gcode_M767() {
|
||||||
card.initsd();
|
card.initsd();
|
||||||
// Overwrite existing
|
// Overwrite existing
|
||||||
card.openFile((char *)"eesave.hex", false, true);
|
card.openFile((char *)"eesave.hex", false, true);
|
||||||
|
linebfr = (char *)malloc(EELINESIZE + 1);
|
||||||
|
if (!linebfr)
|
||||||
|
kill();
|
||||||
|
|
||||||
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
||||||
int8_t cksum = EECHUNKSIZE;
|
int8_t cksum = EECHUNKSIZE;
|
||||||
nch = sprintf_P(linebfr, PSTR(":%02X%04X00"), EECHUNKSIZE, ofs);
|
nch = sprintf_P(linebfr, PSTR(":%02X%04X00"), EECHUNKSIZE, ofs);
|
||||||
|
|
@ -1978,12 +1982,14 @@ void gcode_M767() {
|
||||||
|
|
||||||
nch += sprintf_P(linebfr + nch, PSTR("%02X\n"), (-cksum) & 0xFF);
|
nch += sprintf_P(linebfr + nch, PSTR("%02X\n"), (-cksum) & 0xFF);
|
||||||
if (card.write_buf(linebfr, nch) != nch) {
|
if (card.write_buf(linebfr, nch) != nch) {
|
||||||
|
free(linebfr);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNRPGM(MSG_SD_ERR_WRITE_TO_FILE);
|
SERIAL_ERRORLNRPGM(MSG_SD_ERR_WRITE_TO_FILE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(linebfr);
|
||||||
// Close file
|
// Close file
|
||||||
card.closefile(false);
|
card.closefile(false);
|
||||||
SERIAL_ECHOLNPGM("EEPROM saved");
|
SERIAL_ECHOLNPGM("EEPROM saved");
|
||||||
|
|
@ -2035,13 +2041,19 @@ void gcode_M768() {
|
||||||
if (!card.isFileOpen())
|
if (!card.isFileOpen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
linebfr = (char *)malloc(EELINESIZE + 1);
|
||||||
if (card.read_buf(linebfr, EELINESIZE) != EELINESIZE)
|
if (!linebfr)
|
||||||
return;
|
kill();
|
||||||
|
|
||||||
|
for (unsigned long ofs = 0; ofs < 4096; ofs += EECHUNKSIZE) {
|
||||||
|
if (card.read_buf(linebfr, EELINESIZE) != EELINESIZE) {
|
||||||
|
free(linebfr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Validate buffer header
|
// Validate buffer header
|
||||||
if ((linebfr[0] != ':') || (bfrVal(&linebfr[1], 2) != EECHUNKSIZE) ||
|
if ((linebfr[0] != ':') || (bfrVal(&linebfr[1], 2) != EECHUNKSIZE) ||
|
||||||
(bfrVal(&linebfr[7], 2) != 0)) {
|
(bfrVal(&linebfr[7], 2) != 0)) {
|
||||||
|
free(linebfr);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Header mis-match");
|
SERIAL_ERRORLNPGM("Header mis-match");
|
||||||
return;
|
return;
|
||||||
|
|
@ -2053,6 +2065,7 @@ void gcode_M768() {
|
||||||
cksum += bfrVal(&linebfr[i], 2);
|
cksum += bfrVal(&linebfr[i], 2);
|
||||||
}
|
}
|
||||||
if (cksum != 0) {
|
if (cksum != 0) {
|
||||||
|
free(linebfr);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Bad checksum");
|
SERIAL_ERRORLNPGM("Bad checksum");
|
||||||
return;
|
return;
|
||||||
|
|
@ -2060,6 +2073,7 @@ void gcode_M768() {
|
||||||
|
|
||||||
addrs = bfrVal(&linebfr[3], 4);
|
addrs = bfrVal(&linebfr[3], 4);
|
||||||
if (addrs > 4064) {
|
if (addrs > 4064) {
|
||||||
|
free(linebfr);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Bad EEPROM offset");
|
SERIAL_ERRORLNPGM("Bad EEPROM offset");
|
||||||
return;
|
return;
|
||||||
|
|
@ -2072,6 +2086,7 @@ void gcode_M768() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// All done with restore
|
// All done with restore
|
||||||
|
free(linebfr);
|
||||||
card.closefile();
|
card.closefile();
|
||||||
SERIAL_ECHOLNPGM("EEPROM restored");
|
SERIAL_ECHOLNPGM("EEPROM restored");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue