Delete OTA html and added it into the github.io repo

This commit is contained in:
atc1441
2022-01-20 20:02:16 +01:00
parent 60e7e30fb1
commit 82164e10d0
2 changed files with 3 additions and 329 deletions

View File

@@ -1,329 +0,0 @@
<title>ATC_TLSR_Paper BLE control</title>
</head>
<body>
<script>
let gattServer;
let Theservice;
let writeCharacteristic;
let busy = false;
let imgArray;
let imgArrayLen = 0;
let uploadPart = 0;
function delay(delayInms) {
return new Promise(resolve => {
setTimeout(() => {
resolve(2);
}, delayInms);
});
}
function resetVariables() {
busy = false;
gattServer = null;
Theservice = null;
writeCharacteristic = null;
document.getElementById("log").value = '';
}
function decimalToHex(d, padding) {
var hex = Number(d).toString(16);
padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
while (hex.length < padding) {
hex = "0" + hex;
}
return hex;
}
function handleError(error) {
console.log(error);
resetVariables();
}
async function sendCommand(cmd) {
if (writeCharacteristic) {
await writeCharacteristic.writeValue(cmd);
}
}
function readFlash(readAddress) {
hex_address = decimalToHex(readAddress, 8);
addLog("Reading address: " + hex_address + " now");
raw_cmd = "04" + hex_address;
addLog("Sending: " + raw_cmd);
cmd = hexToBytes(raw_cmd);
sendCommand(cmd);
console.log('CMD was Send');
}
function readRam(readAddress) {
hex_address = decimalToHex(readAddress, 8);
addLog("Reading address: " + hex_address + " now");
raw_cmd = "05" + hex_address;
addLog("Sending: " + raw_cmd);
cmd = hexToBytes(raw_cmd);
sendCommand(cmd).then(() => {
console.log('CMD was Send');
})
.catch(handleError);
}
function writeFW(writeAddress, data) {
}
var fwSizeComplete = 0;
var fwBytesTransmited = 0;
// Sending a 0x100 long dataset to a bank at given address
async function sendPart(address, data) {
hex_address = decimalToHex(address, 8);
var part_len = 36;
while (data.length) {
var cur_part_len = part_len;
if (data.length < part_len)
cur_part_len = data.length;
var data_part = data.substring(0, cur_part_len);
data = data.substring(cur_part_len);
console.log("Sub Part: " + "03" + data_part);
await sendCommand(hexToBytes("03" + data_part));
fwBytesTransmited += cur_part_len;
setStatus('Current part: ' + fwBytesTransmited/2 + " All: " + fwSizeComplete/2);
}
await sendCommand(hexToBytes("02" + hex_address));
console.log("Writing bank: " + hex_address);
await delay(50);
}
async function eraseFwArea(){
var fwAreaSize = 0x20000;
var fwCurAddress = 0x20000;
while (fwCurAddress < (0x20000 + fwAreaSize)) {
hex_address = decimalToHex(fwCurAddress, 8);
console.log("Erasing block: " + hex_address);
await sendCommand(hexToBytes("01" + hex_address));
fwCurAddress += 0x1000;
}
}
async function doCRCcheck(localCRC){
await sendCommand(hexToBytes("06"));
}
async function doFinalFlash(crc){
addLog("Sending Final flash: "+ "07C001CEED"+crc);
await sendCommand(hexToBytes("07C001CEED"+crc));
}
function calculateCRC(localData){
var checkPosistion = 0;
var outCRC = 0;
addLog(Number("0x"+localData.substring(checkPosistion,checkPosistion+2)));
while (checkPosistion < 0x40000) {
if(checkPosistion < localData.length)
outCRC += Number("0x"+localData.substring(checkPosistion,checkPosistion+2));
else
outCRC += 0xff;
checkPosistion+=2;
}
return decimalToHex(outCRC & 0xffff,4);
}
async function sendFile(address, data) {
var part_len = 0x200;
var addressOffset = 0;
var inCRC = calculateCRC(data);
addLog("File CRC = " + inCRC);
fwSizeComplete = data.length;
fwBytesTransmited = 0;
await eraseFwArea();
while (data.length) {
var cur_part_len = part_len;
if (data.length < part_len)
cur_part_len = data.length;
var data_part = data.substring(0, cur_part_len);
data = data.substring(cur_part_len);
await sendPart(address + addressOffset, data_part);
addressOffset += cur_part_len / 2;
}
await doFinalFlash(inCRC);
}
function sendcmd(cmdTXT) {
console.log('SendCMDnow');
let cmd = hexToBytes(cmdTXT);
addLog('Send CMD: ' + cmdTXT);
console.log('Send CMD: ');
console.log(cmdTXT);
console.log('Send CMD bytes: ');
console.log(cmd);
sendCommand(cmd).then(() => {
console.log('CMD was Send');
})
.catch(handleError);
}
function sendimg(cmdIMG) {
imgArray = cmdIMG.replace(/(?:\r\n|\r|\n|,|0x| )/g, '');
imgArrayLen = imgArray.length;
uploadPart = 0;
console.log('Sending image ' + imgArrayLen);
sendCommand(hexToBytes("0000")).then(() => {
sendCommand(hexToBytes("020000")).then(() => {
sendIMGpart();
})
})
.catch(handleError);
}
function sendIMGpart() {
if (imgArray.length > 0) {
let currentpart = "03" + imgArray.substring(0, 38);
imgArray = imgArray.substring(38);
setStatus('Current part: ' + uploadPart++);
console.log('Curr Part: ' + currentpart);
sendCommand(hexToBytes(currentpart)).then(() => {
sendIMGpart();
})
} else {
console.log('Last Part: ' + imgArray);
sendCommand(hexToBytes("01")).then(() => {
console.log('Update was send');
})
}
}
function disconnect() {
resetVariables();
console.log('Disconnected.');
addLog('Disconnected.');
document.getElementById("connectbutton").innerHTML = 'Connected';
}
function handleNotify(data) {
addLog("Got bytes: " + bytesToHex(data.buffer));
}
function connect() {
if (gattServer != null && gattServer.connected) {
disconnect();
} else {
console.log('Connecting...');
addLog('Connecting...');
if (writeCharacteristic == null) {
navigator.bluetooth.requestDevice({
optionalServices: ['0000221f-0000-1000-8000-00805f9b34fb'],
acceptAllDevices: true
})
.then(device => {
console.log('> ' + device.name);
console.log('Connecting to GATT Server...');
return device.gatt.connect();
})
.then(server => {
console.log('> Found GATT server');
gattServer = server;
return gattServer.getPrimaryService('0000221f-0000-1000-8000-00805f9b34fb');
})
.then(service => {
console.log('> Found service');
Theservice = service;
return Theservice.getCharacteristic('0000331f-0000-1000-8000-00805f9b34fb');
})
.then(characteristic => {
console.log('> Found write characteristic');
addLog('> Found write characteristic');
document.getElementById("connectbutton").innerHTML = 'Disconnected';
writeCharacteristic = characteristic;
return writeCharacteristic.startNotifications().then(() => {
writeCharacteristic.addEventListener('characteristicvaluechanged', event => {
var value = event.target.value;
handleNotify(value);
});
});
return;
})
.catch(handleError);
} else {
}
}
}
function setStatus(statusText) {
document.getElementById("status").innerHTML = statusText;
}
function addLog(logTXT) {
document.getElementById("log").innerHTML += logTXT + '<br>';
}
function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return new Uint8Array(bytes);
}
function bytesToHex(data) {
return new Uint8Array(data).reduce(function (memo, i) {
return memo + ("0" + i.toString(16)).slice(-2);
}, "");
}
window.onload = function() {
document.querySelector("#file").addEventListener("change", function() {
var reader = new FileReader();
reader.onload = function() {
firmwareArray = bytesToHex(this.result);
if(firmwareArray.substring(16,24)!="4b4e4c54"){
alert("Select file is no telink firmware .bin");
addLog("Select file is no telink firmware .bin");
firmwareArray = "";
return;
}
addLog("File was selected, size: " + firmwareArray.length / 2 + " bytes");
document.getElementById("cmdIMAGE").value = firmwareArray;
addLog("File CRC = " + calculateCRC(document.getElementById("cmdIMAGE").value));
}
if (this.files[0] != null)
reader.readAsArrayBuffer(this.files[0]);
else
addLog("No file selected");
}, false);
}
function resetFileSelector(){
document.getElementById("file").value = '';
};
</script>
Welcome to ATCnetz.de ATC_TLSR_Paper BLE control,<br>Click connect and select the TLSR E-Paper display you want to
talk to.<br><br>
The ATC_TLSR_Paper Firmware can be found here: <a href="https://github.com/atc1441/ATC_TLSR_Paper"
target="_blank">https://github.com/atc1441/ATC_TLSR_Paper</a><br><br>
<button id="connectbutton" type="button" onclick="connect();">Connect</button><br><br>
<input type="text" id="positionText" value="20000">
<button type="button"
onclick="readFlash(Number('0x'+document.getElementById(&quot;positionText&quot;).value));">readFlash</button><br>
<input type="text" id="positionTextRam" value="0">
<button type="button"
onclick="readRam(Number('0x'+document.getElementById(&quot;positionTextRam&quot;).value));">readRam</button><br>
<br>
<br>
<input type="text" id="cmdTXT" value="0055">
<button type="button" onclick="sendcmd(document.getElementById(&quot;cmdTXT&quot;).value);">SendCMD</button><br><br>
<button id="w_fw_button" type="button" onclick="writeFW(0x20000,'1212123234321234');">Write FW</button><br>
<div id="status">Upload status</div><br>
Please select a .bin file you want to flash to the Telink BLE device.<br><br>
Select Firmware: <input type="file" accept=".bin" id="file" onclick="resetFileSelector();"/><br><br>
<button type="button" onclick="sendFile(0x20000,document.getElementById(&quot;cmdIMAGE&quot;).value);">Send Firmware</button>
<button type="button" onclick="doFinalFlash();">final flash</button><br>
<textarea id="cmdIMAGE" rows="12" cols="100"></textarea><br>
<div id="log"><br></div>
</body>
</html>

View File

@@ -16,6 +16,9 @@ https://atc1441.github.io/ATC_TLSR_Paper_UART_Flasher.html
WebBluetooth Image Uploader:
https://atc1441.github.io/ATC_TLSR_Paper_Image_Upload.html
WebBluetooth Firmware OTA Flashing:
https://atc1441.github.io/ATC_TLSR_Paper_OTA_writing.html
#### Compiling:
Python needs to be installed
##### Windows: