CMXX - Firmware update improvements

This commit is contained in:
“VeLiTi”
2025-03-12 12:40:35 +01:00
parent faf5a5156b
commit ecc045f98a
8 changed files with 6452 additions and 4877 deletions

View File

@@ -229,17 +229,24 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) {
}
else {
//GET HW + SW from object
$hw_version = $post_content['testdetails']['logdetails']['HW'];
$sw_version = $post_content['testdetails']['logdetails']['HEX_FW'];
$hw_version = $post_content['testdetails']['logdetails']['HW'] ?? '';
$fw_version = $post_content['testdetails']['logdetails']['FW'] ?? '';
$sw_version = $post_content['testdetails']['logdetails']['HEX_FW'] ?? '';
//GET COMMITCODE
$commitCode = compareCommitCodes($sw_version,$fw_version);
//IF COMMITCODE IS EMPTY THEN RETURN HEX_FW
$sw_version = ($commitCode != '' || !empty($commitCode)) ? $commitCode : $sw_version;
}
//check SW_VERSION for filetype
//check SW_VERSION for filetype HEX_FW can contain extension
$version_file_type = strtolower(substr($sw_version, -4)); // filetype
if ($version_file_type[0] == '.'){
$sw_version = substr($sw_version, 0, -4);
}
//Update Equipment record
$sql = "UPDATE equipment SET hw_version = ?, sw_version = ? $whereclause";
$stmt = $pdo->prepare($sql);

View File

@@ -215,8 +215,15 @@ if (isset($post_content['sn']) && isset($post_content['payload'])){
}
else {
//GET HW + SW from object
$hw_version = $post_content['payload']['logdetails']['HW'];
$sw_version = $post_content['payload']['logdetails']['HEX_FW'];
$hw_version = $post_content['testdetails']['logdetails']['HW'] ?? '';
$fw_version = $post_content['testdetails']['logdetails']['FW'] ?? '';
$sw_version = $post_content['testdetails']['logdetails']['HEX_FW'] ?? '';
//GET COMMITCODE
$commitCode = compareCommitCodes($sw_version,$fw_version);
//IF COMMITCODE IS EMPTY THEN RETURN HEX_FW
$sw_version = ($commitCode != '' || !empty($commitCode)) ? $commitCode : $sw_version;
}
//check SW_VERSION for filetype

View File

@@ -3401,7 +3401,7 @@ class ShoppingCartCalculator {
private function getTaxRate() {
$sql = "SELECT rate FROM taxes WHERE country = ?";
$sql = "SELECT rate FROM taxes WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->execute([$this->selected_country]);
$tax = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -3557,7 +3557,7 @@ class ShoppingCartCalculator {
}
private function calculateTaxTotal($amount_to_tax) {
$sql = "SELECT rate FROM taxes WHERE country = ?";
$sql = "SELECT rate FROM taxes WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->execute([$this->selected_country]);
$tax = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -3866,4 +3866,47 @@ function createGiftCart($pdo, $orderID, $giftcard_categoryID,$accounthierarchy){
}
}
}
//=======================================
// findGitCommitHash
//=======================================
function findShortGitCommitHash($string) {
// Step 1: Find all hexadecimal sequences
preg_match_all('/[0-9a-f]+/i', $string, $matches);
$allHexMatches = $matches[0] ?? [];
// Step 2: Filter to only include those with exactly 6 or 7 characters
$commitHashes = array_filter($allHexMatches, function($match) {
return strlen($match) === 6 || strlen($match) === 7;
});
return array_values($commitHashes); // Re-index array
}
function compareCommitCodes($stringA, $stringB) {
// Get commit codes from both strings
$commitCodesA = findShortGitCommitHash($stringA);
$commitCodesB = findShortGitCommitHash($stringB);
// Case 1: Check if there are matching commit codes between A and B
foreach ($commitCodesA as $codeA) {
if (in_array($codeA, $commitCodesB)) {
return $codeA; // Return the first matching commit code
}
}
// Case 2: If A has commit code but B doesn't
if (count($commitCodesA) > 0 && count($commitCodesB) === 0) {
return $commitCodesA[0]; // Return the first commit code from A
}
// Case 3: If A has no commit code but B does
if (count($commitCodesA) === 0 && count($commitCodesB) > 0) {
return $commitCodesB[0]; // Return the first commit code from B
}
// Case 4: Neither has commit code
return "";
}

View File

@@ -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";
}
}
}
}

View File

@@ -28,18 +28,40 @@ $search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
$url = 'index.php?page=catalog'.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/catalog/'.$GET_VALUES;
$catalog = ioServer($api_url,'');
//Decode Payload
if (!empty($catalog)){$catalog = json_decode($catalog,true);}else{$catalog = null;}
//Get all the categories from the database
$categories = ioServer('/v2/categories/','');
$categories = json_decode($categories,true);
//IF CATEGORY IS RECEIVED ONLY GET RELATED PRODUCTS
$url_input = '';
if(isset($_GET['category']) && !isset($_POST['category'])){
$url_input = 'category='.$_GET['category'];
}
if (isset($_POST['category'])){
$filter_input = '';
foreach (array_keys($_POST['category']) as $cat_filter){
$filter_input .= $cat_filter.',';
}
if ($url_input != ''){
$url_input = $url_input.','.substr($filter_input,0, -1);
} else {
$url_input = 'category='.substr($filter_input,0, -1);
}
}
//GET CATALOG DATA
$products = ioServer('/v2/catalog/'.$url_input,'');
$products = json_decode($products,true);
//Return QueryTotal from API
$api_url = '/v2/products/'.$GET_VALUES.'&totals=&salesflag=1&status=1';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = null;}
$query_total = ioServer('/v2/products/'.$GET_VALUES.'&totals=&salesflag=1&status=1','');
$query_total = json_decode($query_total,true);
template_header('Catalog', 'catalog','view');
$view = '
@@ -60,12 +82,182 @@ $view .= ' <div class="msg success">
<i class="fas fa-times"></i>
</div>';
}
$description = json_encode($catalog, JSON_PRETTY_PRINT);
$view .= '
<div class="content-block">
<pre>' . $description . '</pre>
</div>
';
<div class="filtersection">
<!-- Filter Section -->
<div class="filter-section">
<form action="" method="post">
<h2>'.($products_filters_h2 ?? 'Filter Products').'</h2>';
if (count($categories) > 0){
//BUILD UP FILTERS BASED ON CATEGORY ASSIGNMENTS
foreach ($categories as $filters){
if ($filters['parent_id'] == '0' && $filters['status'] == 1 && $filters['filter'] == 1){
$view .= '<div class="filter-group">
<label>'.(${$filters['name']} ?? $filters['name']).'</label> ';
//Iterate through categories for subfilters
foreach ($categories as $subfilter){
if ($filters['rowID'] == $subfilter['parent_id'] && $subfilter['status'] == 1 && $subfilter['filter'] == 1){
$view .= '<div>
<input type="checkbox" id="'.$subfilter['name'].'" name="category['.$subfilter['rowID'].']">
<label for="'.$subfilter['name'].'">'.(${$subfilter['name']} ?? $subfilter['name']).'</label>
</div>';
}
}
$view .= '</div>';
}
}
$view .= '<input type="submit" value="'.($btn_filter ?? 'Filter').'" class="btn" >';
}
$view .= '</form>
</div>
<div class="products content-wrapper"> ';
//ADD CATEGORIES
$view .= ' <div style="margin-top: 30px;display: flex;align-items: center;align-content: center;flex-wrap: nowrap;flex-direction: column;">
<div class="product_category_nav">
';
foreach ($categories as $categorie){
if ($categorie['parent_id'] == '0' && $categorie['status'] == 1 && $categorie['filter'] != 1){
$weburl = url('index.php?page=products&category='.$categorie['rowID'].'');
$view .= '<a href="'.$weburl.'">'.(${$categorie['name']} ?? $categorie['name']).'</a>';
}
}
$view .= '
</div>';
if (isset($_GET['category'])){
$view .= '<div class="product_category_nav">';
foreach ($categories as $categorie){
if ($categorie['parent_id'] == $_GET['category'] && $categorie['status'] == 1 && $categorie['filter'] != 1){
$weburl = url('index.php?page=productsnew&category='.$categorie['rowID'].'');
$view .= '<a href="'.$weburl.'" style="color: #fff;background-color: #555555;font-size: 10px;">'.(${$categorie['name']} ?? $categorie['name']).'</a>';
}
}
$view .= '</div>';
}
$view .= '
</div>';
$view .= '<div class="products-wrapper">';
foreach ($products as $product){
// Ensure product price is a numeric value
$product_price = isset($product['price']) && $product['price'] > 0 ? floatval($product['price']) : 0.00;
//SHOW LARGE PICTURE
$view .= '
<div class="product">
<a href="'.url('index.php?page=product&rowID=' . ($product['url_slug'] ? ($product['url_slug'] ) : $product['rowID'])).'" id="'.$product['rowID'].'A" class="product">
<img src="'.$product['full_path'].'" id="'.$product['rowID'].'" style="max-width: 250px;max-height: 250px;width: auto;height: auto;" alt="'.(${$product['productname']} ?? $product['productname']).'">
</a>';
//CHECK IF CONFIGURATION SETTING IS FOUND AND NOT EMPTY => USE GROUP TO DISPLAY IMAGES
if (isset($product['configurations']) && isset($product['config_setting']) && $product['config_setting'] != ''){
//GET THE CONFIG_SETTING GROuP AND DISPLAY
foreach ($product['configurations'] as $config){
//MATCH ASSIGNMENT WITH CONFIG SETTING
if($config['assignment'] == $product['config_setting']){
$view .= '<div class="" style="display:flex;justify-content: center">';
//GET ALL RELATED ATTRIBUTES
foreach ($config['attributes'] as $attribute){
$option_id = $attribute['attribute_id']; // ID of the LARGE IMAGE
$IMG_small_id = $attribute['full_path']; //URL TO SMALL IMAGE
$IMG_large_id = $attribute['alternative_media_full_path']; //URL TO LARGE IMAGE
// Ensure attribute price is a numeric value
$attribute_price = isset($attribute['price']) ? floatval($attribute['price']) : 0.00;
$option_price = isset($attribute['price'])
// If price modifier is 1, add prices; otherwise, subtract
? ((isset($attribute['price_modifier']) && $attribute['price_modifier'] == 1) ? number_format(floatval($product_price + $attribute_price), 2) : number_format(floatval($product_price - $attribute_price), 2))
// If product price is not zero, format it
: (($product_price != 0.00) ? number_format(floatval($product_price), 2) : '');
$view .= '
<div>
<img class="img_config" src="'.$IMG_small_id.'" id="'.$attribute['item_media'].'" onclick="update(\''.$product['rowID'].'\',\''.$IMG_large_id.'\',\''.url('index.php?page=product&rowID=' . ($product['url_slug'] ? $product['url_slug'].'/'.$option_id : $product['rowID'].'/'.$option_id )).'\',\''.$option_price.'\')" />
</div>';
}
$view .= '</div>';
}
}
} else {
//SHOW SMALL IMAGE
$view .= '<div class="" style="display:flex;justify-content: center">
<div>
<img class="img_config" src="'.$product['full_path'].'"/>
</div>
</div>';
}
//Stock status
$stock_status = (isset($product['quantity']) && $product['quantity'] != 0) ? $product_on_stock : $out_of_stock;
$style = ($stock_status == $product_on_stock) ? 'style="background-color: green;"' : 'style="background-color:gray;font-weight: lighter;"';
$view .= '
<span class="stock">
<p '.$style.'> '.$stock_status.'</p>
</span>';
/*if (free_shipment_indicator){
$shipment = freeShipment($product_price,'span');
$view .= $shipment;
}*/
$option_id ='';
$view .='<a href="'.url('index.php?page=product&rowID=' . ($product['url_slug'] ? $product['url_slug'].$option_id : $product['rowID'])).'" id="'.$product['rowID'].'B" class="product">
<span class="name">'.(${$product['productname']} ?? $product['productname']).'</span>';
if (isset($product_price)){
$view .= '<span class="price" id="'.$product['rowID'].'C">'.(($product_price != 0.00) ? number_format($product_price,2) : '').'';
if (isset($product['rrp']) && $product['rrp'] > 0){
$view .= '<span class="rrp">'.number_format($product['rrp'],2).'</span>';
}
$view .= '</span>';
}
$view .= '
</a>
</div>';
}
$view .= '
</div>';
$view .= '
</div>
</div>';
$view .= '<script>
function update(id_large, IMG_large, option_id, price){
let url_id_a = id_large + \'A\';
let url_id_b = id_large + \'B\';
let url_id_c = id_large + \'C\';
//change picture
document.getElementById(id_large).src = IMG_large;
document.getElementById(url_id_a).href = option_id;
document.getElementById(url_id_b).href = option_id;
document.getElementById(url_id_c).innerHTML = price;
document.getElementById(url_id_c).style = price;
}
</script>';
$view.='<div class="pagination">';
if ($pagination_page > 1) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2770,4 +2770,108 @@ h4.label {
.hidden {
display: none !important;
}
/*CATALOG VIEW*/
.stock p {
font-size: 10px;
margin: auto;
padding: 5px;
width: fit-content;
border-radius: 5px;
color: white;
}
.stock p:before {
content : '\1F4E6';
}
.filtersection {
display: flex;
margin: 0 auto;
background: white;
border-radius: 12px;
margin-bottom: 50px;
padding: 10px;
width: 95%;
}
.filter-section {
width: 250px;
padding: 20px;
border-right: 1px solid #e0e0e0;
}
.filter-section h2 {
margin-bottom: 15px;
color: #333;
}
.filter-group {
margin-bottom: 20px;
}
.filter-group label {
margin-bottom: 10px;
}
.filter-group input[type="checkbox"] {
margin-right: 10px;
}
/* Responsive Design */
@media (max-width: 768px) {
.filtersection {
flex-direction: column;
text-align: center;
}
.filter-section {
width: 100%;
border-right: none;
border-bottom: 1px solid #e0e0e0;
}
}
main .recentlyadded .products .product, main .products .products-wrapper .product {
display: block;
overflow: hidden;
text-decoration: none;
padding-bottom: 30px;
text-align: center;
margin: 5px;
}
main .recentlyadded .products .product img, main .products .products-wrapper .product img {
transform: scale(1);
transition: transform 1s;
}
main .products .product .name, main .products .products-wrapper .product .name {
display: block;
color: #555555;
padding: 20px 0 2px 0;
text-align: center;
font-family: 'gerb';
word-wrap: break-word;
}
main .products .product .price, main .products .products-wrapper .product .price {
display: block;
color: #999999;
text-align: center;
}
.product .rrp {
color: #BBBBBB;
text-decoration: line-through;
font-size: 22px;
padding-left: 10px;
}
.img_config {
border-radius:5px;
width: 25px;
height: 25px;
margin: 1px;
}