Commit b450cec4 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. Camera class

2. Storing data in classes
3. Get status of cameras and update UI
parent 5a0ac704
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<link rel="stylesheet" href="/stylesheets/style.css"> <link rel="stylesheet" href="/stylesheets/style.css">
<script type='text/javascript' src='node_modules/jquery/dist/jquery.js'></script> <script type='text/javascript' src='node_modules/jquery/dist/jquery.js'></script>
<script type='text/javascript' src='javascripts/e393.js'></script>
<script type='text/javascript' src='javascripts/index.js'></script> <script type='text/javascript' src='javascripts/index.js'></script>
</head> </head>
...@@ -81,6 +82,7 @@ ...@@ -81,6 +82,7 @@
<!--<button id='testbutton1'>List slaves</button>--> <!--<button id='testbutton1'>List slaves</button>-->
<button id='testbutton2'>Get states</button> <button id='testbutton2'>Get states</button>
<button id='testbutton3'>Test wget</button> <button id='testbutton3'>Test wget</button>
<button id='testbutton4'>RunStatus</button>
</div> </div>
<div id='mstable'> <div id='mstable'>
<table class='slave_table'> <table class='slave_table'>
...@@ -93,6 +95,7 @@ ...@@ -93,6 +95,7 @@
<tr valign='top'> <tr valign='top'>
<th colspan='2' style='text-align:center;'>Slave</th> <th colspan='2' style='text-align:center;'>Slave</th>
<th style='text-align:center;'>IP</th> <th style='text-align:center;'>IP</th>
<th style='text-align:center;'>Free space</th>
<th style='text-align:center;'>State</th> <th style='text-align:center;'>State</th>
</tr> </tr>
</table> </table>
......
class E393_Port {
constructor(options){
let defaults = {
index: 0,
sensor: ["none","none","none","none"],
mux: "none",
parameters: {
wb_en: 0,
autoexp_on: 0,
compressor_run: 0,
sensor_run: 0,
color: 0,
quality: 0,
expos: 0,
woi_width: 0,
woi_height: 0,
trig: 0,
trig_master: 0,
trig_period: 0,
trig_condition: 0,
trig_out: 0,
gainr: 0,
gaing: 0,
gainb: 0,
gaingb: 0
},
timestamps: []
};
if ($.isXMLDoc(options)){
this._data = $.extend(defaults,{});
this._data.index = parseInt($(options).attr("index"));
this._data.sensor = $(options).attr("sensor").split(",").map(v => v.trim());
let self = this;
let pars = $(options).find("parameters");
$(pars).children().each(function(){
let name = this.nodeName;
let value = parseInt($(this).text());
self._data.parameters[name] = value;
});
let ts = $(options).find("timestamps");
/*
$(ts).children().each(function(){
self._data.timestamps.push({
frame: parseInt($(this).attr("frame")),
ts: parseFloat($(this).attr("ts")),
ptr: parseInt($(this).attr("ptr")),
});
});
*/
this.update_timestamps(ts);
//this._data.parameters.wb_en = parseInt($(pars).find("wb_en"));
//this._data.parameters.autoexp_on = parseInt($(pars).find("autoexp_on"));
}else{
this._data = $.extend(defaults,options);
}
this.index = this._data.index;
this.sensor = this._data.sensor;
this.mux = this._data.mux;
this.parameters = this._data.parameters;
this.timestamps = this._data.timestamps;
}
// update timestamps
update_timestamps(ts){
let self = this;
this._data.timestamps = [];
$(ts).children().each(function(){
self._data.timestamps.push({
frame: parseInt($(this).attr("frame")),
ts: parseFloat($(this).attr("ts")),
ptr: parseInt($(this).attr("ptr")),
});
});
}
}
class E393 {
// options can be an xmldoc
constructor(options){
let defaults = {
master_port: "N/A",
systime: "",
systimestamp: 0,
uptime: "",
temperature: {
cpu: 0,
b10389: 0,
sda: 0,
sdb: 0
},
storage: "",
recorder: "",
gps: "",
ports: [
new E393_Port({index:0}),
new E393_Port({index:1}),
new E393_Port({index:2}),
new E393_Port({index:3})
]
}
if ($.isXMLDoc(options)){
this._data = $.extend(defaults,{});
this._data.master_port = parseInt($(options).find("master_port").text());
this._data.systime = $(options).find("systime").text();
this._data.systimestamp = $(options).find("systimestamp").text();
this._data.uptime = $(options).find("uptime").text();
this._data.gps = $(options).find("gps").text().trim();
this._data.storage = $(options).find("storage").text().trim();
this._data.recorder = $(options).find("recorder").text().trim();
this._data.temperature.cpu = parseFloat($(options).find("temperature").find("cpu").text());
this._data.temperature.b10389 = parseFloat($(options).find("temperature").find("b10389").text());
this._data.temperature.sda = parseFloat($(options).find("temperature").find("sda").text());
this._data.temperature.sdb = parseFloat($(options).find("temperature").find("sdb").text());
let self = this;
$(options).find("port").each(function(){
let index = parseInt($(this).attr("index"));
self._data.ports[index] = new E393_Port(this);
});
}else{
this._data = $.extend(defaults,options);
}
this.master_port = this._data.master_port;
this.systime = this._data.systime;
this.systimestamp = this._data.systimestamp;
this.uptime = this._data.uptime;
this.temperature = this._data.temperature;
this.storage = this._data.storage;
this.recorder = this._data.recorder;
this.gps = this._data.gps;
this.ports = this._data.ports;
}
}
...@@ -13,9 +13,82 @@ let appData = { ...@@ -13,9 +13,82 @@ let appData = {
} }
let States = { let States = {
recording: false recording: false,
parsinit: false
}; };
let Cams = [];
async function a_init(){
let res;
// url
res = await a_parse_url();
parse_cmd_ifconfig_init(res);
// detect
res = await a_detect_10393s();
parse_detect_10393s(res);
// read params
res = await a_read_params();
parse_read_params(res);
// update interface
update_ui();
console.log("Done");
}
function update_ui(){
let pars = {
color : undefined,
quality: undefined,
trig_period: undefined,
wb_en: undefined,
autoexp_on: undefined
}
for (let p in pars){
for(let i=0;i<Cams.length;i++){
for(let j=0;j<Cams[i].ports.length;j++){
let tmp = Cams[i].ports[j].parameters[p];
// init
if (pars[p]===undefined){
pars[p] = tmp;
// this is an exclusion
// TODO: fix and remove later
}else if (pars[p]===1){
pars[p] = tmp;
// after init
}else{
// not all are "none"
if (!Cams[i].ports[j].sensor.every(v => v === "none")){
// comparing init to others
if ((pars[p]!==tmp)&&(tmp!==1)){
console.log("Warning! "+p+" is not the same across all cameras/ports");
}
}
}
}
}
}
const format = format_num2str(pars.color);
const quality = pars.quality;
const fps = fps_period2fps(pars.trig_period);
$("#set_format .input-par").val(format);
$("#set_quality .input-par").val(quality);
$("#set_fps .input-par").val(fps);
button_switch($('#toggle_awb') , pars.wb_en);
button_switch($('#toggle_aexp'), pars.autoexp_on);
}
function init(){ function init(){
// css // css
...@@ -28,7 +101,14 @@ function init(){ ...@@ -28,7 +101,14 @@ function init(){
//}); //});
update_master_node(); update_master_node();
parse_url();
// this one is async
a_init().then(async () => {
console.log("Tadam!");
});
init_controls(); init_controls();
init_awb_toggle(); init_awb_toggle();
init_aexp_toggle(); init_aexp_toggle();
...@@ -109,21 +189,171 @@ function init(){ ...@@ -109,21 +189,171 @@ function init(){
'cat sensor33' 'cat sensor33'
].join(';'); ].join(';');
send_command(cmd, appData.slaves_selected,parse_cmd_testing); //send_command(cmd, appData.slaves_selected,parse_cmd_testing);
mtest();
});
$('#testbutton4').on('click', function(e){
let cmd = wget_rq("camogm_interface.php?cmd=run_status");
send_command(cmd, appData.slaves_selected,parse_cmd_run_status);
});
}
async function a_read_params(){
let cmd = wget_rq("diagnostics.php");
let targets = appData.slaves_selected;
let result = await a_send_command(cmd,targets);
return result;
}
async function a_detect_10393s(){
let targets = appData.slaves_selected;
let path = "/sys/devices/soc0/elphel393-detect_sensors@0";
let cmd = [
'cd '+path,
'cat port_mux0',
'cat sensor00',
'cat sensor01',
'cat sensor02',
'cat sensor03',
'cat port_mux1',
'cat sensor10',
'cat sensor11',
'cat sensor12',
'cat sensor13',
'cat port_mux2',
'cat sensor20',
'cat sensor21',
'cat sensor22',
'cat sensor23',
'cat port_mux3',
'cat sensor30',
'cat sensor31',
'cat sensor32',
'cat sensor33'
].join(';');
let result = await a_send_command(cmd,targets);
return result;
}
function detect_10393s(){
let path = "/sys/devices/soc0/elphel393-detect_sensors@0";
let cmd = [
'cd '+path,
'cat port_mux0',
'cat sensor00',
'cat sensor01',
'cat sensor02',
'cat sensor03',
'cat port_mux1',
'cat sensor10',
'cat sensor11',
'cat sensor12',
'cat sensor13',
'cat port_mux2',
'cat sensor20',
'cat sensor21',
'cat sensor22',
'cat sensor23',
'cat port_mux3',
'cat sensor30',
'cat sensor31',
'cat sensor32',
'cat sensor33'
].join(';');
send_command(cmd, appData.slaves_selected,parse_detect_10393s);
}
function wget_rq(cmd){
return "wget -qO- -o /dev/null 'http://localhost/"+cmd+"'";
}
function parse_cmd_run_status(res){
$(res).find('response').each(function(){
const xmlstate = state_str2xml(this);
console.log(xmlstate);
if ($(xmlstate).find("state").text()==="off"){
let cmd = wget_rq("camogm_interface.php?cmd=run_camogm");
send_command(cmd, appData.slaves_selected);
}
}); });
} }
function state_str2xml(res){
let state = $(res).find('state').text();
let xmlstate;
try{
xmlstate = $.parseXML(`${state}`);
}
catch(e){
xmlstate = $.parseXML(`<document>${state}</document>`);
}
return xmlstate;
}
let refresh_hist_intvl; let refresh_hist_intvl;
//let parse_detect_10393s = parse_cmd_testing;
function parse_detect_10393s(res){
parse_cmd_testing(res);
// now read parameters
}
function parse_read_params(res){
// reset init state
//States.parsinit = false;
$(res).find('response').each(function(){
const name = $(this).find('node').text();
let state = $(this).find('state').text();
const x = state_str2xml(this);
if ($(x).find("error").length!=0){
$("tr."+name+" .slave_state").html("<b style='color:DarkOrange;'>not 10393</b>");
}else{
if ($(x).find("camera").length==1) {
Cams.push(new E393(x));
}
}
});
}
function parse_cmd_testing(res){ function parse_cmd_testing(res){
$(res).find('response').each(function(){ $(res).find('response').each(function(){
const name = $(this).find('node').text(); const name = $(this).find('node').text();
let state = $(this).find('state').text(); let state = $(this).find('state').text();
const xmlstate = $.parseXML(`<document>${state}</document>`); const xmlstate = state_str2xml(this);
if ($(xmlstate).find("error").length!=0){ if ($(xmlstate).find("error").length!=0){
console.log(name+" is not 10393"); console.log(name+" is not 10393");
...@@ -160,8 +390,8 @@ function parse_cmd_testing(res){ ...@@ -160,8 +390,8 @@ function parse_cmd_testing(res){
}); });
// now we can init histograms // now we can init histograms
init_histograms(); //init_histograms();
refresh_hist_intvl = setInterval(refresh_histograms,100); //refresh_hist_intvl = setInterval(refresh_histograms,100);
} }
...@@ -170,7 +400,7 @@ function init_histograms(){ ...@@ -170,7 +400,7 @@ function init_histograms(){
for (let i in appData['slaves']){ for (let i in appData['slaves']){
let sname = appData['slaves'][i]; let sname = appData['slaves'][i];
if (appData.nc10393[sname]===undefined){ if (appData.nc10393[sname]===undefined){
console.log(sname+" is probably not a 10393"); console.log(sname+" is not 10393");
}else{ }else{
// new row // new row
...@@ -239,13 +469,14 @@ function parse_cmd_ifconfig_init(res){ ...@@ -239,13 +469,14 @@ function parse_cmd_ifconfig_init(res){
update_slave_list(name); update_slave_list(name);
update_ip_list(ip); update_ip_list(ip);
//detect_10393s();
/* /*
let html = [ let html = [
'<div class=\''+name+'\'>', '<div class=\''+name+'\'>',
'<input class=\'slave_checkbox\' type=\'checkbox\' checked />', '<input class=\'slave_checkbox\' type=\'checkbox\' checked />',
'<label class=\'lbl_name\'>'+name+'</label>', '<label class=\'slave_name\'>'+name+'</label>',
'(<label class=\'lbl_ip\'>'+ip+'</label>)', '(<label class=\'slave_ip\'>'+ip+'</label>)',
'</div>' '</div>'
].join('\n'); ].join('\n');
*/ */
...@@ -257,10 +488,13 @@ function parse_cmd_ifconfig_init(res){ ...@@ -257,10 +488,13 @@ function parse_cmd_ifconfig_init(res){
' <input class=\'slave_checkbox\' type=\'checkbox\' checked />', ' <input class=\'slave_checkbox\' type=\'checkbox\' checked />',
' </td>', ' </td>',
' <td>', ' <td>',
' <div class=\'lbl_name\'>'+name+'</div>', ' <div class=\'slave_name\'>'+name+'</div>',
' </td>',
' <td>',
' <div class=\'slave_ip\'>'+ip+'</div>',
' </td>', ' </td>',
' <td>', ' <td>',
' <div class=\'lbl_ip\'>'+ip+'</div>', ' <div class=\'slave_free_space\'>-</div>',
' </td>', ' </td>',
' <td>', ' <td>',
' <div class=\'slave_state\'>-</div>', ' <div class=\'slave_state\'>-</div>',
...@@ -268,7 +502,7 @@ function parse_cmd_ifconfig_init(res){ ...@@ -268,7 +502,7 @@ function parse_cmd_ifconfig_init(res){
'</tr>' '</tr>'
].join('\n'); ].join('\n');
console.log(html); //console.log(html);
$("#mstable .slave_table tbody").append(html); $("#mstable .slave_table tbody").append(html);
...@@ -319,6 +553,38 @@ function send_command(cmd,targets,callback){ ...@@ -319,6 +553,38 @@ function send_command(cmd,targets,callback){
return 0; return 0;
} }
async function a_send_command(cmd,targets){
let res;
let targets_str = "";
if (Array.isArray(targets)){
targets_str = targets.join(',');
}else if (typeof targets === 'string' || targets instanceof String){
targets_str = targets;
}else{
targets_str = "";
}
try {
res = await $.ajax({
type: "POST",
url: '/api/cmd',
data: {
master: appData.master,
targets: targets_str,
cmd: cmd
},
dataType: "xml"
});
return res;
} catch (error) {
console.error(error);
}
}
function update_slave_list(name){ function update_slave_list(name){
appData.slaves.push(name); appData.slaves.push(name);
appData.slaves_selected.push(name); appData.slaves_selected.push(name);
...@@ -387,6 +653,27 @@ function parse_url(){ ...@@ -387,6 +653,27 @@ function parse_url(){
} }
async function a_parse_url(){
let res;
let parameters=location.href.replace(/\?/ig,"&").split("&");
for (let i=0;i<parameters.length;i++) parameters[i]=parameters[i].split("=");
for (let i=1;i<parameters.length;i++) {
switch (parameters[i][0]) {
case "master":
update_master_node(parameters[i][1]);
//send_command('ifconfig', appData.slaves, parse_cmd_ifconfig_init);
res = await a_send_command('ifconfig', appData.slaves);
//parse_cmd_ifconfig_init(res);
break;
}
}
return res;
}
function rewrite_url(){ function rewrite_url(){
let baseURL = ""; let baseURL = "";
...@@ -495,3 +782,36 @@ function button_switch(btn,state){ ...@@ -495,3 +782,36 @@ function button_switch(btn,state){
} }
} }
// helper functions
function fps_period2fps(period){
// the tick is 10ns, so:
return (1e8/period).toFixed(2);
}
function format_str2num(str){
let num;
switch(str){
case "jp4" : num = 5; break;
case "jpeg": num = 0; break;
default: num = -1;
}
return num;
}
function format_num2str(num){
let str;
switch(num){
case 0 : str = "jpeg"; break;
case 5 : str = "jp4"; break;
default: str = "unknown";
}
return str;
}
...@@ -61,7 +61,7 @@ input[type="checkbox"], input[type="radio"] { ...@@ -61,7 +61,7 @@ input[type="checkbox"], input[type="radio"] {
text-align: center; text-align: center;
} }
.lbl_name, .lbl_ip{ .slave_name, .slave_ip{
font-weight: normal; font-weight: normal;
} }
...@@ -166,6 +166,7 @@ input[type="checkbox"], input[type="radio"] { ...@@ -166,6 +166,7 @@ input[type="checkbox"], input[type="radio"] {
padding: 0px 10px; padding: 0px 10px;
} }
.slave_state{ .slave_state,
.slave_free_space{
text-align:center; text-align:center;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment