Fix overlapping address range error on reconnect

pull/18/head
Melissa LeBlanc-Williams 5 years ago
parent 8b48de402e
commit 0f238400cd

@ -227,9 +227,9 @@ class EspLoader {
return macAddr;
};
debugMsg(...values) {
debugMsg(debugLevel, ...values) {
if (this.debug) {
this._debugMsg(...values);
this._debugMsg(debugLevel, ...values);
}
}
@ -259,7 +259,7 @@ class EspLoader {
*/
async readRegister(reg) {
if (this.debug) {
this.debugMsg("Reading from Register " + this.toHex(reg, 8));
this.debugMsg(1, "Reading from Register " + this.toHex(reg, 8));
}
let packet = struct.pack("<I", reg);
await this.sendCommand(ESP_READ_REG, packet);
@ -273,7 +273,7 @@ class EspLoader {
*/
async writeRegister(reg, value) {
if (this.debug) {
this.debugMsg("Writing to Register " + this.toHex(reg, 8));
this.debugMsg(1, "Writing to Register " + this.toHex(reg, 8));
}
let packet = struct.pack("<I", reg);
return (await this.checkCommand(ESP_WRITE_REG, packet))[0];
@ -362,9 +362,9 @@ class EspLoader {
let status = data.slice(-statusLen, data.length);
data = data.slice(0, -statusLen);
if (this.debug) {
this.debugMsg("status", status);
this.debugMsg("value", value);
this.debugMsg("data", data);
this.debugMsg(1, "status", status);
this.debugMsg(1, "value", value);
this.debugMsg(1, "data", data);
}
if (status[0] == 1) {
if (status[1] == ROM_INVALID_RECV_MSG) {
@ -402,7 +402,7 @@ class EspLoader {
let packet = struct.pack("<BBHI", 0x00, opcode, buffer.length, checksum);
packet = packet.concat(buffer);
packet = this.slipEncode(packet);
this.debugMsg("Writing " + packet.length + " byte" + (packet.length == 1 ? "" : "s") + ":", packet);
this.debugMsg(2, "Writing " + packet.length + " byte" + (packet.length == 1 ? "" : "s") + ":", packet);
await this.writeToStream(packet);
};
@ -500,17 +500,17 @@ class EspLoader {
}
if (readBytes.length == 0) {
let waitingFor = partialPacket === null ? "header" : "content";
this.debugMsg("Timed out waiting for packet " + waitingFor);
this.debugMsg(1, "Timed out waiting for packet " + waitingFor);
throw new SlipReadError("Timed out waiting for packet " + waitingFor);
}
this.debugMsg("Read " + readBytes.length + " bytes: " + this.hexFormatter(readBytes));
this.debugMsg(2, "Read " + readBytes.length + " bytes: " + this.hexFormatter(readBytes));
for (let b of readBytes) {
if (partialPacket === null) { // waiting for packet header
if (b == 0xc0) {
partialPacket = [];
} else {
this.debugMsg("Read invalid data: " + this.hexFormatter(readBytes));
this.debugMsg("Remaining data in serial buffer: " + this.hexFormatter(inputBuffer));
this.debugMsg(1, "Read invalid data: " + this.hexFormatter(readBytes));
this.debugMsg(1, "Remaining data in serial buffer: " + this.hexFormatter(inputBuffer));
throw new SlipReadError('Invalid head of packet (' + this.toHex(b) + ')');
}
} else if (inEscape) { // part-way through escape sequence
@ -520,14 +520,14 @@ class EspLoader {
} else if (b == 0xdd) {
partialPacket.push(0xdb);
} else {
this.debugMsg("Read invalid data: " + this.hexFormatter(readBytes));
this.debugMsg("Remaining data in serial buffer: " + this.hexFormatter(inputBuffer));
this.debugMsg(1, "Read invalid data: " + this.hexFormatter(readBytes));
this.debugMsg(1, "Remaining data in serial buffer: " + this.hexFormatter(inputBuffer));
throw new SlipReadError('Invalid SLIP escape (0xdb, ' + this.toHex(b) + ')');
}
} else if (b == 0xdb) { // start of escape sequence
inEscape = true;
} else if (b == 0xc0) { // end of packet
this.debugMsg("Received full packet: " + this.hexFormatter(partialPacket))
this.debugMsg(2, "Received full packet: " + this.hexFormatter(partialPacket))
return partialPacket;
partialPacket = null;
} else { // normal byte in packet
@ -917,7 +917,7 @@ class EspLoader {
stub = await this.getStubCode();
}
if (this.syncStubDetected) {
if (this.syncStubDetected || this.IS_STUB) {
this.logMsg("Stub is already running. No upload is necessary.");
return this.stubClass;
}
@ -956,13 +956,14 @@ class EspLoader {
throw "Failed to start stub. Unexpected response: " + p;
}
this.logMsg("Stub is now running...");
this.stubClass = new EspStubLoader({
let stubLoader = new EspStubLoader({
updateProgress: this.updateProgress,
logMsg: this.logMsg,
debugMsg: this._debugMsg,
debug: this.debug,
});
return this.stubClass;
stubLoader.stubClass = stubLoader;
return stubLoader;
}
}

@ -35,11 +35,13 @@ let currentBoard;
let buttonState = 0;
document.addEventListener('DOMContentLoaded', () => {
let debug = false;
let debug = 0;
var getParams = {}
location.search.substr(1).split("&").forEach(function(item) {getParams[item.split("=")[0]] = item.split("=")[1]})
if (getParams["debug"] !== undefined) {
debug = getParams["debug"] == "1" || getParams["debug"].toLowerCase() == "true";
if (getParams["debug"] == "1" || getParams["debug"] == "2") {
debug = parseInt(getParams["debug"]);
}
}
espTool = new EspLoader({
@ -78,6 +80,9 @@ document.addEventListener('DOMContentLoaded', () => {
loadAllSettings();
updateTheme();
logMsg("Adafruit WebSerial ESPTool loaded.");
if (debug) {
logMsg("Debugging Level " + debug + " Enabled.");
}
});
/**
@ -146,7 +151,7 @@ function logMsg(text) {
}
}
function debugMsg(...args) {
function debugMsg(debugLevel, ...args) {
function getStackTrace() {
let stack = new Error().stack;
stack = stack.split("\n").map(v => v.trim());
@ -165,18 +170,24 @@ function debugMsg(...args) {
return trace;
}
if (debugLevel > espTool.debug) {
return;
}
let stack = getStackTrace();
stack.shift();
let top = stack.shift();
let prefix = '<span class="debug-function">[' + top.func + ":" + top.pos + ']</span> ';
for (let arg of args) {
if (typeof arg == "string") {
if (arg === undefined) {
logMsg(prefix + "undefined");
} else if (arg === null) {
logMsg(prefix + "null");
} else if (typeof arg == "string") {
logMsg(prefix + arg);
} else if (typeof arg == "number") {
logMsg(prefix + arg);
} else if (typeof arg == "boolean") {
logMsg(prefix + arg ? "true" : "false");
logMsg(prefix + (arg ? "true" : "false"));
} else if (Array.isArray(arg)) {
logMsg(prefix + "[" + arg.map(value => espTool.toHex(value)).join(", ") + "]");
} else if (typeof arg == "object" && (arg instanceof Uint8Array)) {

Loading…
Cancel
Save