2022-08-13 07:12:56 -04:00
|
|
|
# Bitmask calculator
|
|
|
|
|
|
|
|
<style>
|
|
|
|
div.box{
|
|
|
|
width: 90%;
|
|
|
|
}
|
2022-08-13 09:06:42 -04:00
|
|
|
table {
|
|
|
|
border: 1px solid #222;
|
|
|
|
}
|
2022-08-13 07:12:56 -04:00
|
|
|
</style>
|
2022-08-13 09:06:42 -04:00
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
<script type="text/javascript">
|
2022-10-07 11:59:15 -04:00
|
|
|
// 1660727162
|
2022-08-13 09:06:42 -04:00
|
|
|
var bitmaskDescArr = [];
|
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
function dec2bin(dec) {
|
|
|
|
return reverse((dec >>> 0).toString(2));
|
|
|
|
}
|
|
|
|
function reverse(str) {
|
|
|
|
return str.split("").reverse().join("");
|
|
|
|
}
|
|
|
|
|
2022-08-13 09:06:42 -04:00
|
|
|
async function loadBitmask(){
|
|
|
|
// using the function:
|
|
|
|
removeAll(document.getElementById('paramSelect'));
|
2022-08-13 07:12:56 -04:00
|
|
|
|
|
|
|
url = document.getElementById("built").value;
|
2022-08-13 09:06:42 -04:00
|
|
|
console.log("fetching: "+ url);
|
|
|
|
if (url == ""){
|
2022-08-13 07:12:56 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-13 09:06:42 -04:00
|
|
|
const response = await fetch(url,{
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'text/plain'
|
|
|
|
}
|
|
|
|
})
|
2022-08-13 07:12:56 -04:00
|
|
|
.then(response => response.text())
|
|
|
|
.then(data => {
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const xml = parser.parseFromString(data, "application/xml");
|
|
|
|
|
|
|
|
var params = xml.getElementsByTagName("param");
|
2022-08-13 09:06:42 -04:00
|
|
|
console.log("retrieved "+ params.length +" params")
|
|
|
|
for (var i = 0; i < params.length; i++) {
|
2022-10-07 11:59:15 -04:00
|
|
|
var param = params[i].attributes.name.nodeValue; //works, param name
|
2022-08-13 09:06:42 -04:00
|
|
|
param = param.replace("ArduPlane:","");
|
2022-08-13 07:12:56 -04:00
|
|
|
|
|
|
|
if(params[i].childNodes[1]){
|
|
|
|
if( typeof params[i].childNodes[1].attributes.name == "object"){
|
|
|
|
if(params[i].childNodes[1].attributes.name.nodeValue && params[i].childNodes[1].attributes.name.nodeValue == "Bitmask"){
|
|
|
|
|
|
|
|
var bitmaskDescTxt = params[i].textContent.trim();
|
|
|
|
bitmaskDescArr[param] = bitmaskDescTxt.split(',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-13 09:06:42 -04:00
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
})
|
|
|
|
.catch(console.error);
|
2022-08-13 09:06:42 -04:00
|
|
|
|
|
|
|
// console.log(bitmaskDescArr.length);
|
|
|
|
drawSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function drawSelect(){
|
|
|
|
bitmaskDescArr.sort();
|
|
|
|
Object.keys(bitmaskDescArr)
|
|
|
|
.sort()
|
|
|
|
.forEach(function(p, i) {
|
|
|
|
// console.log(p);
|
|
|
|
var el = document.createElement("option");
|
|
|
|
el.textContent = p;
|
|
|
|
el.value = p;
|
|
|
|
document.getElementById("paramSelect").appendChild(el);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeAll(selectBox) {
|
|
|
|
while (selectBox.options.length > 0) {
|
|
|
|
selectBox.remove(0);
|
|
|
|
}
|
2022-08-13 07:12:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function bitbox(bit){
|
|
|
|
dec = parseInt(document.getElementById("decimal").value);
|
2022-08-13 09:06:42 -04:00
|
|
|
if(!dec ){dec = parseInt(0);}
|
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
if(document.getElementById(bit).checked == true){
|
|
|
|
dec += parseInt(bit);
|
|
|
|
}else{
|
|
|
|
dec -= parseInt(bit);
|
|
|
|
}
|
|
|
|
document.getElementById("decimal").value = dec;
|
|
|
|
parseBitmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseBitmask() {
|
|
|
|
console.log("found "+Object.keys(bitmaskDescArr).length+" bitmask parameters");
|
|
|
|
|
|
|
|
document.getElementById("result").innerHTML="";
|
|
|
|
var tbl = document.createElement('table');
|
2022-08-13 09:06:42 -04:00
|
|
|
tbl.style="border: 1px solid black; width: 100%";
|
2022-08-13 07:12:56 -04:00
|
|
|
var tbdy = document.createElement('tbody');
|
|
|
|
|
2022-10-07 11:59:15 -04:00
|
|
|
binarybitmask=dec2bin(document.getElementById("decimal").value);
|
|
|
|
if(!binarybitmask){binarybitmask = parseInt(0);}
|
|
|
|
console.log("binarybitmask: "+binarybitmask);
|
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
var param = document.getElementById("paramSelect").value;
|
|
|
|
|
2022-10-07 11:59:15 -04:00
|
|
|
for (var option= 0; option < bitmaskDescArr[param].length; option++) {
|
2022-08-13 07:12:56 -04:00
|
|
|
|
2022-10-07 11:59:15 -04:00
|
|
|
var bit = parseInt(bitmaskDescArr[param][option].split(":",1)); //extract the first number before : of description
|
|
|
|
var enabled = binarybitmask[bit]; // check if it is enabled
|
|
|
|
if(!enabled){enabled=0};
|
|
|
|
var singleBitDecvalue = Math.pow(2,bit); // convert the bit to a decimal
|
2022-08-13 07:12:56 -04:00
|
|
|
|
2022-10-07 11:59:15 -04:00
|
|
|
var tr = document.createElement('tr');
|
2022-08-13 07:12:56 -04:00
|
|
|
var td = document.createElement('td');
|
|
|
|
td.style="border: 1px solid black;";
|
2022-10-07 11:59:15 -04:00
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
var checkbox = document.createElement('input');
|
|
|
|
checkbox.type = "checkbox";
|
|
|
|
checkbox.id = singleBitDecvalue;
|
|
|
|
checkbox.setAttribute("onclick","bitbox("+singleBitDecvalue+")");
|
|
|
|
|
2022-10-07 11:59:15 -04:00
|
|
|
if (enabled == "1"){
|
2022-08-13 07:12:56 -04:00
|
|
|
checkbox.checked = true;
|
|
|
|
}else{
|
|
|
|
checkbox.checked = false;
|
|
|
|
}
|
2022-10-07 11:59:15 -04:00
|
|
|
|
2022-08-13 07:12:56 -04:00
|
|
|
td.appendChild(checkbox);
|
|
|
|
tr.appendChild(td);
|
|
|
|
|
|
|
|
var td = document.createElement('td');
|
2022-10-07 11:59:15 -04:00
|
|
|
td.appendChild(document.createTextNode(bitmaskDescArr[param][option]));
|
|
|
|
if (enabled == "1"){
|
2022-08-13 07:12:56 -04:00
|
|
|
td.style = "border: 1px solid black; color: green";
|
|
|
|
}else{
|
|
|
|
td.style = "border: 1px solid black; color: red";
|
|
|
|
}
|
|
|
|
tr.appendChild(td);
|
|
|
|
|
|
|
|
var td = document.createElement('td');
|
|
|
|
td.style="border: 1px solid black; color: grey";
|
2022-10-07 11:59:15 -04:00
|
|
|
td.appendChild(document.createTextNode(singleBitDecvalue));
|
2022-08-13 07:12:56 -04:00
|
|
|
tr.appendChild(td);
|
|
|
|
|
|
|
|
tbdy.appendChild(tr);
|
|
|
|
tbl.appendChild(tbdy);
|
|
|
|
}
|
|
|
|
document.getElementById("result").appendChild(tbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="box">
|
|
|
|
<div id="input">
|
|
|
|
<select id="built" onChange="loadBitmask();">
|
2022-08-13 09:06:42 -04:00
|
|
|
<option value='https://arducustom.github.io/v/dev/ArduPlane/apm.pdef.xml'>ArduCustom Plane master</option>
|
|
|
|
<option value='https://arducustom.github.io/v/10.0/ArduPlane/apm.pdef.xml'>ArduCustom Plane v10</option>
|
|
|
|
<option value='https://arducustom.github.io/v/9.0/ArduPlane/apm.pdef.xml'>ArduCustom Plane v9.0</option>
|
2022-08-13 07:12:56 -04:00
|
|
|
</select>
|
|
|
|
<select id="paramSelect" onChange="parseBitmask();">
|
|
|
|
</select>
|
|
|
|
<input type="text" id="decimal" value="1" oninput="parseBitmask();">
|
|
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<div id="result">
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-13 09:06:42 -04:00
|
|
|
<script type="text/javascript">
|
|
|
|
loadBitmask();
|
|
|
|
</script>
|
2022-08-13 07:12:56 -04:00
|
|
|
|
|
|
|
_(Many thanks to mfoos for writing this note.)_
|
|
|
|
|
|
|
|
* * *
|
|
|
|
|
|
|
|
<p style="font-size:80%; font-style: italic">
|
2022-10-07 11:59:15 -04:00
|
|
|
Last updated on October 07, 2022. For any questions/feedback,
|
2022-08-13 07:12:56 -04:00
|
|
|
email me at <a href="mailto:hi@stavros.io">hi@stavros.io</a>.
|
|
|
|
</p>
|