quick and dirty hack for as openDTU installer

This commit is contained in:
Dominik Kuhn 2023-04-04 21:33:58 +02:00
parent e8d66b62bf
commit 56834c20fe
9 changed files with 2655 additions and 173 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}

BIN
binary_blob/boot_app0.bin Normal file

Binary file not shown.

BIN
binary_blob/bootloader.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
binary_blob/partitions.bin Normal file

Binary file not shown.

View File

@ -44,7 +44,7 @@
</div> </div>
<div id="files"> <div id="files">
<table class="table table-striped" id="fileTable"> <!-- <table class="table table-striped" id="fileTable">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
<th>Flash Address</th> <th>Flash Address</th>
@ -54,8 +54,8 @@
</thead> </thead>
<tbody id="tableBody"> <tbody id="tableBody">
</tbody> </tbody>
</table> </table> -->
<input class="btn btn-info btn-sm" type="button" id="addFile" value="Add File" /> <!-- <input class="btn btn-info btn-sm" type="button" id="addFile" value="Add File" /> -->
<input class="btn btn-info btn-sm" type="button" id="programButton" value="Program" /> <input class="btn btn-info btn-sm" type="button" id="programButton" value="Program" />
</div> </div>
<output id="list"></output> <output id="list"></output>

411
index.js
View File

@ -28,6 +28,7 @@ let transport;
let chip = null; let chip = null;
let esploader; let esploader;
let file1 = null; let file1 = null;
// let temp_bin_file = null;
let connected = false; let connected = false;
disconnectButton.style.display = 'none'; disconnectButton.style.display = 'none';
@ -51,8 +52,96 @@ function handleFileSelect(evt) {
})(file); })(file);
reader.readAsBinaryString(file); reader.readAsBinaryString(file);
} }
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
function SyncFileReader(file) {
let self = this;
let ready = false;
let result = '';
const sleep = function (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
self.readAsBinaryString = async function() {
while (ready === false) {
await sleep(100);
}
return result;
}
const reader = new FileReader();
reader.onloadend = function(evt) {
result = evt.target.result;
if( result ){
console.log(result);
}
ready = true;
};
reader.readAsBinaryString(file);
}
// function binary_reader_helper(file) {
// var ready = false;
// var result = '';
// var check = function() {
// if (ready === true) {
// // do what you want with the result variable
// return;
// }
// setTimeout(check, 1000);
// }
// check();
// var reader = new FileReader();
// reader.onloadend = function(evt) {
// // file is loaded
// result = evt.target.result;
// ready = true;
// };
// reader.readAsBinaryString(file);
// return (' ' + reader.result).slice(1);
// // let reader = new FileReader();
// // reader.onload = function(evt) {
// // var bin = evt.target.result; //get file content
// // // do sth with text
// // console.log(bin);
// // // temp_bin_file = (' ' + bin).slice(1);
// // // var li = document.createElement("li");
// // // li.innerHTML = name;
// // // ul.appendChild(li);
// // };
// // reader.onloadend = () => {
// // console.log("DONE", reader.readyState); // readyState will be 2
// // };
// }
let espLoaderTerminal = { let espLoaderTerminal = {
clean() { clean() {
term.clear(); term.clear();
@ -119,54 +208,54 @@ eraseButton.onclick = async () => {
} }
}; };
addFile.onclick = () => { // addFile.onclick = () => {
var rowCount = table.rows.length; // var rowCount = table.rows.length;
var row = table.insertRow(rowCount); // var row = table.insertRow(rowCount);
//Column 1 - Offset // //Column 1 - Offset
var cell1 = row.insertCell(0); // var cell1 = row.insertCell(0);
var element1 = document.createElement('input'); // var element1 = document.createElement('input');
element1.type = 'text'; // element1.type = 'text';
element1.id = 'offset' + rowCount; // element1.id = 'offset' + rowCount;
element1.value = '0x1000'; // element1.value = '0x1000';
cell1.appendChild(element1); // cell1.appendChild(element1);
// Column 2 - File selector // // Column 2 - File selector
var cell2 = row.insertCell(1); // var cell2 = row.insertCell(1);
var element2 = document.createElement('input'); // var element2 = document.createElement('input');
element2.type = 'file'; // element2.type = 'file';
element2.id = 'selectFile' + rowCount; // element2.id = 'selectFile' + rowCount;
element2.name = 'selected_File' + rowCount; // element2.name = 'selected_File' + rowCount;
element2.addEventListener('change', handleFileSelect, false); // element2.addEventListener('change', handleFileSelect, false);
cell2.appendChild(element2); // cell2.appendChild(element2);
// Column 3 - Progress // // Column 3 - Progress
var cell3 = row.insertCell(2); // var cell3 = row.insertCell(2);
cell3.classList.add('progress-cell'); // cell3.classList.add('progress-cell');
cell3.style.display = 'none'; // cell3.style.display = 'none';
cell3.innerHTML = `<progress value="0" max="100"></progress>`; // cell3.innerHTML = `<progress value="0" max="100"></progress>`;
// Column 4 - Remove File // // Column 4 - Remove File
var cell4 = row.insertCell(3); // var cell4 = row.insertCell(3);
cell4.classList.add('action-cell'); // cell4.classList.add('action-cell');
if (rowCount > 1) { // if (rowCount > 1) {
var element4 = document.createElement('input'); // var element4 = document.createElement('input');
element4.type = 'button'; // element4.type = 'button';
var btnName = 'button' + rowCount; // var btnName = 'button' + rowCount;
element4.name = btnName; // element4.name = btnName;
element4.setAttribute('class', 'btn'); // element4.setAttribute('class', 'btn');
element4.setAttribute('value', 'Remove'); // or element1.value = "button"; // element4.setAttribute('value', 'Remove'); // or element1.value = "button";
element4.onclick = function () { // element4.onclick = function () {
removeRow(row); // removeRow(row);
}; // };
cell4.appendChild(element4); // cell4.appendChild(element4);
} // }
}; // };
function removeRow(row) { // function removeRow(row) {
const rowIndex = Array.from(table.rows).indexOf(row); // const rowIndex = Array.from(table.rows).indexOf(row);
table.deleteRow(rowIndex); // table.deleteRow(rowIndex);
} // }
// to be called on disconnect - remove any stale references of older connections if any // to be called on disconnect - remove any stale references of older connections if any
function cleanUp() { function cleanUp() {
@ -255,39 +344,220 @@ function validate_program_inputs() {
} }
programButton.onclick = async () => { programButton.onclick = async () => {
const alertMsg = document.getElementById('alertmsg'); // const alertMsg = document.getElementById('alertmsg');
const err = validate_program_inputs(); // const err = validate_program_inputs();
if (err != 'success') { // if (err != 'success') {
alertMsg.innerHTML = '<strong>' + err + '</strong>'; // alertMsg.innerHTML = '<strong>' + err + '</strong>';
alertDiv.style.display = 'block'; // alertDiv.style.display = 'block';
return; // return;
} // }
// Hide error message // Hide error message
alertDiv.style.display = 'none'; // alertDiv.style.display = 'none';
let temp_bin_file = null;
const fileArray = []; const fileArray = [];
const progressBars = []; // const progressBars = [];
for (let index = 1; index < table.rows.length; index++) { // for (let index = 1; index < table.rows.length; index++) {
const row = table.rows[index]; // const row = table.rows[index];
const offSetObj = row.cells[0].childNodes[0]; // const offSetObj = row.cells[0].childNodes[0];
const offset = parseInt(offSetObj.value); // const offset = parseInt(offSetObj.value);
const fileObj = row.cells[1].childNodes[0]; // const fileObj = row.cells[1].childNodes[0];
const progressBar = row.cells[2].childNodes[0]; // const progressBar = row.cells[2].childNodes[0];
progressBar.value = 0; // progressBar.value = 0;
progressBars.push(progressBar); // progressBars.push(progressBar);
row.cells[2].style.display = 'initial'; // row.cells[2].style.display = 'initial';
row.cells[3].style.display = 'none'; // row.cells[3].style.display = 'none';
fileArray.push({ data: fileObj.data, address: offset }); // fileArray.push({ data: fileObj.data, address: offset });
// }
// ###################################################################
// ###################################################################
let response = await fetch("/binary_blob/bootloader.bin");
if(response.status != 200) {
throw new Error("Server Error");
}
// read response stream as text
// let text_data = await response.text();
let blob_data = await response.blob();
if(!blob_data) {
throw new Error("Can't read file to flash as blob !")
} }
let file = new File( [blob_data], "bootloader.bin", {
type: "text/plain",
});
// let reader = new FileReader();
// reader.onload = (function (theFile) {
// return function (e) {
// file1 = e.target.result;
// };
// })(file);
// reader.onloadend = function (theFile){
// file1 = this.result;
// console.log(this.result);
// };
console.log( file );
let fileReader = new SyncFileReader(file);
temp_bin_file = await fileReader.readAsBinaryString();
if( !temp_bin_file ){
temp_bin_file = await fileReader.readAsBinaryString();
if( temp_bin_file ){
console.log( temp_bin_file );
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x1000 });
}
}else{
console.log( temp_bin_file );
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x1000 });
}
temp_bin_file = null;
// ###################################################################
// ###################################################################
response = await fetch("/binary_blob/partitions.bin");
if(response.status != 200) {
throw new Error("Server Error");
}
blob_data = await response.blob();
if(!blob_data) {
throw new Error("Can't read file to flash as blob !")
}
file = new File( [blob_data], "partitions.bin", {
type: "text/plain",
});
console.log( file );
fileReader = new SyncFileReader(file);
temp_bin_file = await fileReader.readAsBinaryString();
if( !temp_bin_file ){
temp_bin_file = await fileReader.readAsBinaryString();
if( temp_bin_file ){
console.log( temp_bin_file );
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x8000 });
}
}else{
console.log( temp_bin_file );
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x8000 });
}
temp_bin_file = null;
// ###################################################################
// ###################################################################
response = await fetch("/binary_blob/boot_app0.bin");
if(response.status != 200) {
throw new Error("Server Error");
}
blob_data = await response.blob();
if(!blob_data) {
throw new Error("Can't read file to flash as blob !")
}
file = new File( [blob_data], "boot_app0.bin", {
type: "text/plain",
});
console.log( file );
fileReader = new SyncFileReader(file);
temp_bin_file = await fileReader.readAsBinaryString();
if( !temp_bin_file ){
temp_bin_file = await fileReader.readAsBinaryString();
if( temp_bin_file ){
console.log( temp_bin_file );
fileArray.push({ data: temp_bin_file , address: 0xe000 });
}
}else{
console.log( temp_bin_file );
fileArray.push({ data: temp_bin_file , address: 0xe000 });
}
temp_bin_file = null;
// ###################################################################
// ###################################################################
response = await fetch("/binary_blob/opendtu-generic.bin");
if(response.status != 200) {
throw new Error("Server Error");
}
blob_data = await response.blob();
if(!blob_data) {
throw new Error("Can't read file to flash as blob !")
}
file = new File( [blob_data], "opendtu-gernic.bin", {
type: "text/plain",
});
console.log( file );
fileReader = new SyncFileReader(file);
temp_bin_file = await fileReader.readAsBinaryString();
if( !temp_bin_file ){
temp_bin_file = await fileReader.readAsBinaryString();
if( temp_bin_file ){
console.log( temp_bin_file );
fileArray.push({ data: temp_bin_file , address: 0x10000 });
}
}else{
console.log( temp_bin_file );
fileArray.push({ data: temp_bin_file , address: 0x10000 });
}
temp_bin_file = null;
sleep(3000)
console.log(fileArray)
try { try {
await esploader.write_flash( await esploader.write_flash(
fileArray, fileArray,
@ -296,9 +566,7 @@ programButton.onclick = async () => {
undefined, undefined,
false, false,
true, true,
(fileIndex, written, total) => { null,
progressBars[fileIndex].value = (written / total) * 100;
},
(image) => CryptoJS.MD5(CryptoJS.enc.Latin1.parse(image)), (image) => CryptoJS.MD5(CryptoJS.enc.Latin1.parse(image)),
); );
} catch (e) { } catch (e) {
@ -306,11 +574,12 @@ programButton.onclick = async () => {
term.writeln(`Error: ${e.message}`); term.writeln(`Error: ${e.message}`);
} finally { } finally {
// Hide progress bars and show erase buttons // Hide progress bars and show erase buttons
for (let index = 1; index < table.rows.length; index++) { // for (let index = 1; index < table.rows.length; index++) {
table.rows[index].cells[2].style.display = 'none'; // table.rows[index].cells[2].style.display = 'none';
table.rows[index].cells[3].style.display = 'initial'; // table.rows[index].cells[3].style.display = 'initial';
} // }
} }
}; };
addFile.onclick(); // addFile.onclick();

2394
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,8 @@
"url": "https://github.com/espressif/esptool-js/issues" "url": "https://github.com/espressif/esptool-js/issues"
}, },
"dependencies": { "dependencies": {
"browser-sync": "^2.29.1",
"lodash": "^4.17.21",
"pako": "^2.1.0", "pako": "^2.1.0",
"tslib": "^2.4.1" "tslib": "^2.4.1"
}, },