Skip to content

Commit

Permalink
first implementation of bare flasher
Browse files Browse the repository at this point in the history
  • Loading branch information
egzumer committed Oct 4, 2023
1 parent 8e268ac commit d0847f5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 121 deletions.
105 changes: 16 additions & 89 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta property="og:title" content=UVMOD - Online Quansheng Firmware Patcher>
<meta property="og:site_name" content=UVMOD>
<meta property="og:title" content=UVTools - Online Quansheng Programming Tools>
<meta property="og:site_name" content=UVTools>
<meta property="og:url" content=https://whosmatt.github.io/uvmod />
<meta property="og:description"
content="Web-based tool to generate and flash customizable modded firmware, edit the configuration, and flash open source firmware for various Quansheng handheld radios.">
<meta property="og:type" content=website>
<meta property="og:image" content=https://whosmatt.github.io/uvmod/img/banner.webp>

<title>UVMOD</title>
<title>UVTools</title>

<link rel="icon" type="image/x-icon" href="img/favicon.ico">
<!-- Custom fonts for this template-->
Expand Down Expand Up @@ -125,8 +125,8 @@
<div id="wrapper animated--grow-in" class="wrapper">

<!-- Sidebar -->
<div id="navbar-placeholder" class="sidebar toggled"></div>
<script src="js/navbar.js"></script>
<!-- <div id="navbar-placeholder" class="sidebar toggled"></div>
<script src="js/navbar.js"></script> -->

<!-- Content Wrapper -->
<div id="content-wrapper" class="w-100">
Expand Down Expand Up @@ -170,15 +170,6 @@ <h6 class="m-0 font-weight-bold text-primary">Flasher</h6>
</a>
</div>

<div class="mt-2 d-flex">
<a id="batCalButton" class="btn btn-primary btn-icon-split w-100">
<span class="icon text-white-50">
<i class="fab fa-battery-empty"></i>
</span>
<span class="text w-100">Calibrate battery</span>
</a>
</div>

</div>

</div>
Expand Down Expand Up @@ -212,84 +203,20 @@ <h6 class="m-0 font-weight-bold text-primary">Flasher</h6>
<script src="js/qsSerial.js"></script>
<script src="js/modframework.js"></script>
<script src="js/tool_patcher.js"></script>
<script src="js/libuvk5.js"></script>
<script src="js/batt_calibrator.js"></script>
<!-- <script src="js/libuvk5.js"></script>
<script src="js/batt_calibrator.js"></script> -->

<!-- Easter egg, click the title -->
<script>
const marqueediv = document.getElementById("marquee");

(function ($, window, undefined) {
$.fn.marqueeify = function (options) {
var settings = $.extend({
horizontal: true,
vertical: true,
speed: 100, // In pixels per second
container: $(this).parent(),
bumpEdge: function () { }
}, options);

return this.each(function () {
var containerWidth, containerHeight, elWidth, elHeight, move, getSizes,
$el = $(this);

getSizes = function () {
containerWidth = settings.container.outerWidth();
containerHeight = settings.container.outerHeight();
elWidth = $el.outerWidth();
elHeight = $el.outerHeight();
};

move = {
right: function () {
$el.animate({ left: (containerWidth - elWidth) }, {
duration: ((containerWidth / settings.speed) * 1000), queue: false, easing: "linear", complete: function () {
settings.bumpEdge();
move.left();
}
});
},
left: function () {
$el.animate({ left: 0 }, {
duration: ((containerWidth / settings.speed) * 1000), queue: false, easing: "linear", complete: function () {
settings.bumpEdge();
move.right();
}
});
},
down: function () {
$el.animate({ top: (containerHeight - elHeight) }, {
duration: ((containerHeight / settings.speed) * 1000), queue: false, easing: "linear", complete: function () {
settings.bumpEdge();
move.up();
}
});
},
up: function () {
$el.animate({ top: 0 }, {
duration: ((containerHeight / settings.speed) * 1000), queue: false, easing: "linear", complete: function () {
settings.bumpEdge();
move.down();
}
});
}
};
getSizes();
if (settings.horizontal) {
move.right();
}
if (settings.vertical) {
move.down();
}

// Make that shit responsive!
$(window).resize(function () {
getSizes();
});
});
};
})(jQuery, window);

window.onload = function () {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const firmwareURL = urlParams.get('firmwareURL')
if(firmwareURL) {
console.log(firmwareURL);
loadFirmwareFromUrl(firmwareURL);
}
}

</script>

Expand Down
19 changes: 10 additions & 9 deletions js/batt_calibrator.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const batCalButton = document.getElementById('batCalButton');
batCalButton.addEventListener('click', async function () {
await libuvk5.connect();
try {
await libuvk5.get_cfg_mem();
} catch(error){
console.log(error);
}
finally{
libuvk5.disconnect();
}
// loadFirmwareFromUrl("https://github.com/egzumer/uv-k5-firmware-custom/releases/download/v0.6/1o11_fagci_spectrum_v0.6_packed.bin");
// await libuvk5.connect();
// try {
// await libuvk5.get_cfg_mem();
// } catch(error){
// console.log(error);
// }
// finally{
// libuvk5.disconnect();
// }
})
78 changes: 55 additions & 23 deletions js/tool_patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,61 @@ const flashButton = document.getElementById('flashButton');
let rawVersion = null; // stores the raw version data for fwpack.js and qsflash.js
let rawFirmware = null; // stores the raw firmware data for qsflash.js


function loadFW(encoded_firmware)
{
const flashButton = document.getElementById('flashButton');

flashButton.classList.add('disabled');

const unpacked_firmware = unpack(encoded_firmware);

log(`Detected firmware version: ${new TextDecoder().decode(rawVersion.subarray(0, rawVersion.indexOf(0)))}`);

rawFirmware = unpacked_firmware;

// Check size
const current_size = rawFirmware.length;
const max_size = 0xEFFF;
const percentage = (current_size / max_size) * 100;
log(`Firmware uses ${percentage.toFixed(2)}% of available memory (${current_size}/${max_size} bytes).`);
if (current_size > max_size) {
log("WARNING: Firmware is too large and WILL NOT WORK!\nTry disabling mods that take up extra memory.");
return;
}

flashButton.classList.remove('disabled');
}

function loadFirmwareFromUrl(theUrl)
{
document.getElementById('console').value = "";
log("Loading file from url: "+ theUrl+'\n')
fetch('https://proxy.cors.sh/' + theUrl, {
headers: {
'x-cors-api-key': 'temp_2f1bf656ef75047798830d7dbbc09bd6'
}
})
.then(res => {
if (res.ok) {
return res.arrayBuffer();
} else {
log(`Http error: ${res.status}`);
throw new Error(`Http error: ${res.status}`);
}
}).then(encoded_firmware => {
loadFW(new Uint8Array(encoded_firmware));
customFileLabel.textContent = theUrl.substring(theUrl.lastIndexOf('/')+1);
}).catch((error) => {
console.error(error);
log('Error while loading firmware, check log above or developer console for details.');
});
}


// Update text to show filename after file selection
customFileInput.addEventListener('change', function () {
document.getElementById('console').value = "";
// Check if a file is selected
if (this.files.length > 0) {
// Get the name of the selected file and update the label text
Expand All @@ -24,33 +77,12 @@ customFileInput.addEventListener('change', function () {

file
.then((encoded_firmware) => {
document.getElementById('console').value = "";
const flashButton = document.getElementById('flashButton');

flashButton.classList.add('disabled');

const unpacked_firmware = unpack(encoded_firmware);

log(`Detected firmware version: ${new TextDecoder().decode(rawVersion.subarray(0, rawVersion.indexOf(0)))}`);

rawFirmware = unpacked_firmware;

// Check size
const current_size = rawFirmware.length;
const max_size = 0xEFFF;
const percentage = (current_size / max_size) * 100;
log(`Firmware uses ${percentage.toFixed(2)}% of available memory (${current_size}/${max_size} bytes).`);
if (current_size > max_size) {
log("WARNING: Firmware is too large and WILL NOT WORK!\nTry disabling mods that take up extra memory.");
return;
}

flashButton.classList.remove('disabled');
loadFW(encoded_firmware)
})
.catch((error) => {
console.error(error);
log('Error while loading firmware, check log above or developer console for details.');
});
});
} else {
// If no file is selected, reset the label text
customFileLabel.textContent = 'Select firmware file';
Expand Down

0 comments on commit d0847f5

Please sign in to comment.