Edit the existing Javascript file to add read and write register requests that call the
peek &
poke CGI scripts and update the webpage accordingly. Lines 37-80 show the additions.
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js
// Requests
var uptime_req;
var timer_req;
var write_req;
var read_req;
// Receive data & update webpage accordingly
function GotUptime() {
if (uptime_req.readyState == 4 && uptime_req.status == 200) {
txtObj = document.getElementById("uptime_text");
if (txtObj !== null) {
txtObj.innerHTML = uptime_req.responseText;
}
}
}
// Setup request and ask for data return
function GetUpTime() {
if (window.XMLHttpRequest) {
uptime_req = new XMLHttpRequest();
uptime_req.abort();
uptime_req.onreadystatechange = GotUptime;
uptime_req.open("POST", "/cgi-bin/uptime.cgi", true);
uptime_req.send(null);
}
}
// Setup/Cancel timer request
function SetTimeout(obj) {
clearInterval(timer_req);
var interval = obj.value;
if (interval > 0) {
timer_req = setInterval("GetUpTime()", 1000 * interval);
}
}
// Receive data & update webpage accordingly
function GotWrite() {
if (write_req.readyState == 4 && write_req.status == 200) {
if (write_req.responseText.substr(0,6) == "Error:") {
document.getElementById("wstatus").innerHTML = "Failed";
} else {
document.getElementById("wstatus").innerHTML = "Success";
}
}
}
// Setup request and ask for data return
function WebWrite(form) {
if (window.XMLHttpRequest) {
write_req = new XMLHttpRequest();
write_req.abort();
write_req.onreadystatechange = GotWrite;
write_req.open("POST", "/cgi-bin/poke?" + form.waddr.value + "&" + form.wdata.value, true);
write_req.send(null);
}
}
// Receive data & update webpage accordingly
function GotRead() {
if (read_req.readyState == 4 && read_req.status == 200) {
if (read_req.responseText.substr(0,6) == "Error:") {
document.getElementById("rstatus").innerHTML = "Failed";
} else {
document.getElementById("rstatus").innerHTML = "Success";
document.getElementById("rdata").value = read_req.responseText.toUpperCase();
}
}
}
// Setup request and ask for data return
function WebRead(form) {
if (window.XMLHttpRequest) {
read_req = new XMLHttpRequest();
read_req.abort();
read_req.onreadystatechange = GotRead;
read_req.open("POST", "/cgi-bin/peek?" + form.raddr.value, true);
read_req.send(null);
}
}
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0012/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js -O os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js
Check out the changes.
steve@Desktop:~/projects/zedboard_linux$ git difftool os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js