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

411
index.js
View File

@ -28,6 +28,7 @@ let transport;
let chip = null;
let esploader;
let file1 = null;
// let temp_bin_file = null;
let connected = false;
disconnectButton.style.display = 'none';
@ -51,8 +52,96 @@ function handleFileSelect(evt) {
})(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 = {
clean() {
term.clear();
@ -119,54 +208,54 @@ eraseButton.onclick = async () => {
}
};
addFile.onclick = () => {
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
// addFile.onclick = () => {
// var rowCount = table.rows.length;
// var row = table.insertRow(rowCount);
//Column 1 - Offset
var cell1 = row.insertCell(0);
var element1 = document.createElement('input');
element1.type = 'text';
element1.id = 'offset' + rowCount;
element1.value = '0x1000';
cell1.appendChild(element1);
// //Column 1 - Offset
// var cell1 = row.insertCell(0);
// var element1 = document.createElement('input');
// element1.type = 'text';
// element1.id = 'offset' + rowCount;
// element1.value = '0x1000';
// cell1.appendChild(element1);
// Column 2 - File selector
var cell2 = row.insertCell(1);
var element2 = document.createElement('input');
element2.type = 'file';
element2.id = 'selectFile' + rowCount;
element2.name = 'selected_File' + rowCount;
element2.addEventListener('change', handleFileSelect, false);
cell2.appendChild(element2);
// // Column 2 - File selector
// var cell2 = row.insertCell(1);
// var element2 = document.createElement('input');
// element2.type = 'file';
// element2.id = 'selectFile' + rowCount;
// element2.name = 'selected_File' + rowCount;
// element2.addEventListener('change', handleFileSelect, false);
// cell2.appendChild(element2);
// Column 3 - Progress
var cell3 = row.insertCell(2);
cell3.classList.add('progress-cell');
cell3.style.display = 'none';
cell3.innerHTML = `<progress value="0" max="100"></progress>`;
// // Column 3 - Progress
// var cell3 = row.insertCell(2);
// cell3.classList.add('progress-cell');
// cell3.style.display = 'none';
// cell3.innerHTML = `<progress value="0" max="100"></progress>`;
// Column 4 - Remove File
var cell4 = row.insertCell(3);
cell4.classList.add('action-cell');
if (rowCount > 1) {
var element4 = document.createElement('input');
element4.type = 'button';
var btnName = 'button' + rowCount;
element4.name = btnName;
element4.setAttribute('class', 'btn');
element4.setAttribute('value', 'Remove'); // or element1.value = "button";
element4.onclick = function () {
removeRow(row);
};
cell4.appendChild(element4);
}
};
// // Column 4 - Remove File
// var cell4 = row.insertCell(3);
// cell4.classList.add('action-cell');
// if (rowCount > 1) {
// var element4 = document.createElement('input');
// element4.type = 'button';
// var btnName = 'button' + rowCount;
// element4.name = btnName;
// element4.setAttribute('class', 'btn');
// element4.setAttribute('value', 'Remove'); // or element1.value = "button";
// element4.onclick = function () {
// removeRow(row);
// };
// cell4.appendChild(element4);
// }
// };
function removeRow(row) {
const rowIndex = Array.from(table.rows).indexOf(row);
table.deleteRow(rowIndex);
}
// function removeRow(row) {
// const rowIndex = Array.from(table.rows).indexOf(row);
// table.deleteRow(rowIndex);
// }
// to be called on disconnect - remove any stale references of older connections if any
function cleanUp() {
@ -255,39 +344,220 @@ function validate_program_inputs() {
}
programButton.onclick = async () => {
const alertMsg = document.getElementById('alertmsg');
const err = validate_program_inputs();
// const alertMsg = document.getElementById('alertmsg');
// const err = validate_program_inputs();
if (err != 'success') {
alertMsg.innerHTML = '<strong>' + err + '</strong>';
alertDiv.style.display = 'block';
return;
}
// if (err != 'success') {
// alertMsg.innerHTML = '<strong>' + err + '</strong>';
// alertDiv.style.display = 'block';
// return;
// }
// Hide error message
alertDiv.style.display = 'none';
// alertDiv.style.display = 'none';
let temp_bin_file = null;
const fileArray = [];
const progressBars = [];
// const progressBars = [];
for (let index = 1; index < table.rows.length; index++) {
const row = table.rows[index];
// for (let index = 1; index < table.rows.length; index++) {
// const row = table.rows[index];
const offSetObj = row.cells[0].childNodes[0];
const offset = parseInt(offSetObj.value);
// const offSetObj = row.cells[0].childNodes[0];
// const offset = parseInt(offSetObj.value);
const fileObj = row.cells[1].childNodes[0];
const progressBar = row.cells[2].childNodes[0];
// const fileObj = row.cells[1].childNodes[0];
// const progressBar = row.cells[2].childNodes[0];
progressBar.value = 0;
progressBars.push(progressBar);
// progressBar.value = 0;
// progressBars.push(progressBar);
row.cells[2].style.display = 'initial';
row.cells[3].style.display = 'none';
// row.cells[2].style.display = 'initial';
// 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 {
await esploader.write_flash(
fileArray,
@ -296,9 +566,7 @@ programButton.onclick = async () => {
undefined,
false,
true,
(fileIndex, written, total) => {
progressBars[fileIndex].value = (written / total) * 100;
},
null,
(image) => CryptoJS.MD5(CryptoJS.enc.Latin1.parse(image)),
);
} catch (e) {
@ -306,11 +574,12 @@ programButton.onclick = async () => {
term.writeln(`Error: ${e.message}`);
} finally {
// Hide progress bars and show erase buttons
for (let index = 1; index < table.rows.length; index++) {
table.rows[index].cells[2].style.display = 'none';
table.rows[index].cells[3].style.display = 'initial';
}
// for (let index = 1; index < table.rows.length; index++) {
// table.rows[index].cells[2].style.display = 'none';
// 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"
},
"dependencies": {
"browser-sync": "^2.29.1",
"lodash": "^4.17.21",
"pako": "^2.1.0",
"tslib": "^2.4.1"
},