CMXX - Firmware update improvements
This commit is contained in:
@@ -64,7 +64,7 @@ async function listenToPort() {
|
||||
|
||||
var item = serialResultsDiv.innerHTML;
|
||||
x = Array.from(new Set(item.split(";"))).toString();
|
||||
if (x.indexOf("SN=") > 0 && x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("FWDATE=") >0 && x.indexOf("STATE=") > 0)
|
||||
if (x.indexOf("SN=") > 0 && x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("HEX_FW=") >0 && x.indexOf("STATE=") > 0)
|
||||
{
|
||||
progressBar("60", "Reading device completed", "#04AA6D");
|
||||
setTimeout(getDeviceData, 4000);
|
||||
@@ -100,16 +100,17 @@ async function getDeviceData(){
|
||||
fw = fw.replace(/^0+/, '');
|
||||
}
|
||||
|
||||
if (x.indexOf("FWDATE=") > 0){
|
||||
var a = x.indexOf("FWDATE=");
|
||||
var b = a + 7;
|
||||
var c = b + 10;
|
||||
fwdate = x.substring(b,c);
|
||||
fwdate = fwdate.replaceAll('-', '');
|
||||
if (x.indexOf("HEX_FW=") > 0){
|
||||
var startIndex = x.indexOf("HEX_FW=");
|
||||
var valueStart = startIndex + 7; //
|
||||
// Find the closing quotation mark
|
||||
var valueEnd = x.indexOf("\"", valueStart);
|
||||
// Extract the value
|
||||
hex_fw = x.substring(valueStart, valueEnd);
|
||||
}
|
||||
|
||||
//Check if HW is retrieved from device
|
||||
if (x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("FWDATE=") >0){
|
||||
if (x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("HEX_FW=") >0){
|
||||
var a = x.indexOf("HW=");
|
||||
var b = a + 3;
|
||||
var c = b + 8;
|
||||
@@ -126,13 +127,13 @@ async function getDeviceData(){
|
||||
hw = 'R'+f;
|
||||
sw = 'R'+f;
|
||||
}
|
||||
|
||||
//GET THE COMMITCODE
|
||||
commitCode = compareCommitCodes(hex_fw,fw);
|
||||
|
||||
fw_name = fwdate+'_Firmware_'+fw+'_'+sw;
|
||||
console.log(fw_name);
|
||||
getServiceID().then(firmwareUpdate);
|
||||
progressBar("80", "checking for available firmware", "#04AA6D");
|
||||
setTimeout(checkAvailableFirmware, 5000);
|
||||
console.log(hw);
|
||||
}
|
||||
else {
|
||||
progressBar("80", "Reading of device not successful, please try again", "#ff6666");
|
||||
@@ -143,7 +144,7 @@ async function getDeviceData(){
|
||||
function firmwareUpdate(data){
|
||||
|
||||
var serialnumber = serial;
|
||||
var action = '/v2/products_software/sn='+serialnumber+'&version='+fw_name+'&hw_version='+hw;
|
||||
var action = '/v2/products_software/sn='+serialnumber+'&version='+commitCode+'&hw_version='+hw;
|
||||
var url = link+action;
|
||||
|
||||
var bearer = 'Bearer ' + data;
|
||||
@@ -171,6 +172,43 @@ function firmwareUpdate(data){
|
||||
|
||||
}
|
||||
|
||||
function findShortGitCommitHash(string) {
|
||||
// Step 1: Find all hexadecimal sequences
|
||||
const hexSequencePattern = /[0-9a-f]+/gi;
|
||||
const allHexMatches = string.match(hexSequencePattern) || [];
|
||||
|
||||
// Step 2: Filter to only include those with exactly 6 or 7 characters
|
||||
const commitHashes = allHexMatches.filter(match => match.length === 6 || match.length === 7);
|
||||
|
||||
return commitHashes;
|
||||
}
|
||||
|
||||
function compareCommitCodes(stringA, stringB) {
|
||||
// Get commit codes from both strings
|
||||
const commitCodesA = findShortGitCommitHash(stringA);
|
||||
const commitCodesB = findShortGitCommitHash(stringB);
|
||||
|
||||
// Case 1: Check if there are matching commit codes between A and B
|
||||
for (const codeA of commitCodesA) {
|
||||
if (commitCodesB.includes(codeA)) {
|
||||
return codeA; // Return the first matching commit code
|
||||
}
|
||||
}
|
||||
|
||||
// Case 2: If A has commit code but B doesn't
|
||||
if (commitCodesA.length > 0 && commitCodesB.length === 0) {
|
||||
return commitCodesA[0]; // Return the first commit code from A
|
||||
}
|
||||
|
||||
// Case 3: If A has no commit code but B does
|
||||
if (commitCodesA.length === 0 && commitCodesB.length > 0) {
|
||||
return commitCodesB[0]; // Return the first commit code from B
|
||||
}
|
||||
|
||||
// Case 4: Neither has commit code
|
||||
return "";
|
||||
}
|
||||
|
||||
function checkAvailableFirmware(){
|
||||
|
||||
if (typeof firmwarelocation !== 'undefined') {
|
||||
@@ -182,33 +220,24 @@ function checkAvailableFirmware(){
|
||||
//document.getElementById("updateAvailabe").style.display = "none";
|
||||
progressBar("100", "No firmware found for this device", "#ff6666");
|
||||
}
|
||||
else{
|
||||
var item2 = serialResultsDiv.innerHTML;
|
||||
z = Array.from(new Set(item2.split(";"))).toString();
|
||||
|
||||
if (z.indexOf("FW=") > 0){
|
||||
const latest_fw_provided = hex_fw.split("_");
|
||||
var latest_fw = latest_fw_provided[2].toUpperCase();
|
||||
console.log(latest_fw);
|
||||
var element = document.getElementById("Device_output");
|
||||
console.log(element);
|
||||
|
||||
if (z.indexOf(latest_fw) > 0){
|
||||
readBar.innerHTML = 'Latest Firmware already on device';
|
||||
else {
|
||||
var element = document.getElementById("Device_output");
|
||||
|
||||
//COMPARE commitCODE from DEVICE with RETURNED CODE FROM API
|
||||
if (commitCode.toUpperCase() == upgraded_version.toUpperCase()){
|
||||
readBar.innerHTML = 'Latest Firmware already on device';
|
||||
|
||||
if (typeof(element) != 'undefined' && element != null)
|
||||
{
|
||||
document.getElementById("Device_output").style.display = "none";
|
||||
}
|
||||
if (typeof(element) != 'undefined' && element != null)
|
||||
{
|
||||
document.getElementById("Device_output").style.display = "none";
|
||||
}
|
||||
else {
|
||||
readBar.innerHTML = 'Firmware available';
|
||||
|
||||
if (typeof(element) != 'undefined' && element != null){
|
||||
document.getElementById("Device_output").style.display = "block";
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
readBar.innerHTML = 'Firmware available';
|
||||
|
||||
if (typeof(element) != 'undefined' && element != null){
|
||||
document.getElementById("Device_output").style.display = "block";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user