function MessagePanel(el) {
this.el = el;
this.render();
this.initClearButton();
}
MessagePanel.prototype.supportsMessage = function(message) {
return false;
};
MessagePanel.prototype.render = function() {
};
MessagePanel.prototype.pushMessage = function(message) {
};
// Automatic clearing is not enabled by default.
// Call this method from the constructor to enable.
MessagePanel.prototype.initClearTimer = function() {
var me = this;
if (me.removalInterval) clearInterval(me.removalInterval);
me.removalInterval = setInterval(function () {
me.clearMessages(250);
}, 15000);
};
// Clear all currently shown messages.
MessagePanel.prototype.clearMessages = function(toRemain) {
var $elements = $(this.el).find('tbody tr');
// limit to 1000 entries in the list since browsers get laggy at some point
var toRemove = $elements.length - toRemain;
if (toRemove <= 0) return;
$elements.slice(0, toRemove).remove();
};
// Add CLEAR button to the message list.
MessagePanel.prototype.initClearButton = function() {
var me = this;
me.clearButton = $(
'
Clear
'
);
me.clearButton.css({
position: 'absolute',
top: '10px',
right: '10px'
});
me.clearButton.on('click', function() {
me.clearMessages(0);
});
$(me.el).append(me.clearButton);
};
// Escape HTML code.
MessagePanel.prototype.htmlEscape = function(input) {
return $('').text(input).html()
};
// Scroll to the bottom of the message list.
MessagePanel.prototype.scrollToBottom = function() {
var $t = $(this.el).find('tbody');
$t.scrollTop($t[0].scrollHeight);
};
// Linkify given contents so that clicking them opens given URL.
MessagePanel.prototype.linkify = function(id, url, contents = null) {
// Use ID if contents not given
if (!contents) contents = id;
// Do not linkify empty strings, do not allow empty URLs
if ((id.len <= 0) || !url) return contents;
// Linkify now
return '' + contents + '';
};
// Linkify given contents so that clicking them opens the map with
// the info bubble.
MessagePanel.prototype.linkToMap = function(id, contents = null, attrs = "") {
if (id) {
return ''
+ (contents!=null? contents : id) + '';
} else if (contents != null) {
return '
'
));
};
PageMessagePanel.prototype.pushMessage = function(msg) {
// Get color from the message, default to white
var color = msg.hasOwnProperty('color')? msg.color : "#FFF";
// Append message header (address, time, etc)
var $b = $(this.el).find('tbody');
$b.append($(
'
' +
'
' + msg.address + '
' +
'
' + msg.mode + msg.baud + '
' +
'
' + msg.timestamp + '
' +
'
'
).css('background-color', color).css('color', '#000'));
// Append message body (text)
if (msg.hasOwnProperty('message')) {
$b.append($(
'
'
));
};
HfdlMessagePanel.prototype.pushMessage = function(msg) {
var color = msg.color? msg.color : '#00000000';
var data = msg.type? msg.type : '';
// Only linkify ICAO-compliant flight IDs
var flight =
!msg.flight? ''
: !msg.flight.match(/^[A-Z]{3}[0-9]+[A-Z]*$/)? msg.flight
: this.linkify(msg.flight, this.flight_url);
var aircraft =
msg.aircraft? this.linkify(msg.aircraft, this.flight_url)
: msg.icao? this.linkify(msg.icao, this.modes_url)
: '';
var tstamp =
msg.msgtime? '' + msg.msgtime + ''
: msg.time? msg.time
: '';
// Add location, altitude, speed, etc
var data = '';
if (msg.lat && msg.lon) {
data += '@' + msg.lat.toFixed(4) + ',' + msg.lon.toFixed(4);
}
if (msg.altitude) data += ' ⤒' + msg.altitude + 'ft';
if (msg.vspeed>0) data += ' ↗' + msg.vspeed + 'ft/m';
if (msg.vspeed<0) data += ' ↘' + (-msg.vspeed) + 'ft/m';
if (msg.speed) data += ' →' + msg.speed + 'kt';
if (msg.origin) data += ' ↰' + msg.origin;
if (msg.destination) data += ' ↳' + msg.destination;
// If no location data in the message, use message type as data
if (!data.length && msg.type) data = msg.type;
// Make data point to the map
if (data.length && msg.mapid) data = this.linkToMap(msg.mapid, data);
// Append report
var $b = $(this.el).find('tbody');
$b.append($(
'
' +
'
' + tstamp + '
' +
'
' + flight + '
' +
'
' + aircraft + '
' +
'
' + data + '
' +
'
'
).css('background-color', color).css('color', '#000'));
// Append messsage if present
if (msg.message) {
$b.append($(
'
' + msg.message + '
'
))
}
// Jump list to the last received message
this.scrollToBottom();
};
$.fn.hfdlMessagePanel = function() {
if (!this.data('panel')) {
this.data('panel', new HfdlMessagePanel(this));
}
return this.data('panel');
};
AdsbMessagePanel = function(el) {
MessagePanel.call(this, el);
this.clearButton.css('display', 'none');
this.flight_url = null;
this.modes_url = null;
this.receiver_pos = null;
}
AdsbMessagePanel.prototype = Object.create(MessagePanel.prototype);
AdsbMessagePanel.prototype.supportsMessage = function(message) {
return message['mode'] === 'ADSB-LIST';
};
AdsbMessagePanel.prototype.setReceiverPos = function(pos) {
if (pos.lat && pos.lon) this.receiver_pos = pos;
};
AdsbMessagePanel.prototype.setFlightUrl = function(url) {
this.flight_url = url;
};
AdsbMessagePanel.prototype.setModeSUrl = function(url) {
this.modes_url = url;
};
AdsbMessagePanel.prototype.distanceKm = function(p1, p2) {
// Earth radius in km
var R = 6371.0;
// Convert degrees to radians
var rlat1 = p1.lat * (Math.PI/180);
var rlat2 = p2.lat * (Math.PI/180);
// Compute difference in radians
var difflat = rlat2-rlat1;
var difflon = (p2.lon-p1.lon) * (Math.PI/180);
// Compute distance
d = 2 * R * Math.asin(Math.sqrt(
Math.sin(difflat/2) * Math.sin(difflat/2) +
Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon/2) * Math.sin(difflon/2)
));
return Math.round(d);
};
AdsbMessagePanel.prototype.render = function() {
$(this.el).append($(
'
' +
'
' +
'
Flight
' +
'
Aircraft
' +
'
Squawk
' +
'
Dist
' +
'
Alt (ft)
' +
'
Speed (kt)
' +
'
Signal
' +
'
' +
'' +
'
'
));
};
AdsbMessagePanel.prototype.pushMessage = function(msg) {
// Must have list of aircraft
if (!msg.aircraft) return;
// Create new table body
var body = '';
var odd = false;
msg.aircraft.forEach(entry => {
// Signal strength
var rssi = entry.rssi? entry.rssi + ' dB' : '';
// Flight identificators
var flight =
entry.flight? this.linkify(entry.flight, this.flight_url)
: '';
var aircraft =
entry.aircraft? this.linkify(entry.aircraft, this.flight_url)
: entry.icao? this.linkify(entry.icao, this.modes_url)
: '';
// Altitude and climb / descent
var alt = entry.altitude? '' + entry.altitude : '';
if (entry.vspeed) {
var vspeed = entry.vspeed;
vspeed = vspeed>0? vspeed + '↑' : (-vspeed) + '↓';
alt = vspeed + ' '.repeat(6 - alt.length) + alt;
}
// Speed and direction
var speed = entry.speed? '' + entry.speed : '';
if (entry.course) {
var dir = this.degToCompass(entry.course);
speed = dir + ' '.repeat(5 - speed.length) + speed;
}
// Replace squawk with emergency status, if present
var squawk = entry.squawk? entry.squawk : '';
if (entry.emergency && (entry.emergency!=='NONE')) {
squawk = '
'
+ entry.emergency + '
';
}
// Compute distance to the receiver
var distance = '';
if (this.receiver_pos && entry.lat && entry.lon) {
var id = entry.icao? entry.icao
: entry.aircraft? entry.aircraft
: entry.flight? entry.flight
: null;
distance = this.distanceKm(entry, this.receiver_pos) + ' km';
if (id) distance = this.linkToMap(id, distance);
}
body += '
'
);
};
IsmMessagePanel.prototype.pushMessage = function(msg) {
// Get basic information, assume white color if missing
var address = msg.hasOwnProperty('id')? msg.id : "???";
var device = msg.hasOwnProperty('model')? msg.model : "";
var tstamp = msg.hasOwnProperty('time')? msg.time : "";
var color = msg.hasOwnProperty('color')? msg.color : "#FFF";
// Append message header (address, time, etc)
var $b = $(this.el).find('tbody');
$b.append($(
'
' +
'
' + address + '
' +
'
' + device + '
' +
'
' + tstamp + '
' +
'
'
).css('background-color', color).css('color', '#000'));
// Append attributes in pairs, skip basic information
var last = null;
for (var key in msg) {
if (this.basicInfo.indexOf(key) < 0) {
var cell = this.formatAttr(msg, key);
if (!last) {
last = cell;
} else {
$b.append($('
' + last + cell + '
'));
last = null;
}
}
}
// Last row
if (last) $b.append($('
' + last + '
'));
// Jump list to the last received message
this.scrollToBottom();
};
$.fn.ismMessagePanel = function() {
if (!this.data('panel')) {
this.data('panel', new IsmMessagePanel(this));
}
return this.data('panel');
};
SstvMessagePanel = function(el) {
MessagePanel.call(this, el);
this.initClearTimer();
}
SstvMessagePanel.prototype = Object.create(MessagePanel.prototype);
SstvMessagePanel.prototype.supportsMessage = function(message) {
return message['mode'] === 'SSTV';
};
SstvMessagePanel.prototype.render = function() {
$(this.el).append($(
'
' +
'
' +
'
TV
' +
'
' +
'' +
'
'
));
};
SstvMessagePanel.prototype.pushMessage = function(msg) {
var $b = $(this.el).find('tbody');
if(msg.hasOwnProperty('message')) {
// Append a new debug message text
// See service log for debug output instead
// $b.append($('
' + msg.message + '
'));
// this.scrollToBottom();
}
else if(msg.width>0 && msg.height>0 && !msg.hasOwnProperty('line')) {
var f = msg.frequency>0? ' at ' + Math.floor(msg.frequency/1000) + 'kHz' : '';
var h = '
'));
$b.scrollTop($b[0].scrollHeight);
// Save canvas context and dimensions for future use
this.ctx = $(this.el).find('canvas').get(-1).getContext("2d");
this.width = msg.width;
this.height = msg.height;
}
else if(msg.width>0 && msg.height>0 && msg.line>=0 && msg.hasOwnProperty('pixels')) {
// Will copy pixels to img
var pixels = atob(msg.pixels);
var img = this.ctx.createImageData(msg.width, 1);
// Convert BMP BGR pixels into HTML RGBA pixels
for (var x = 0; x < msg.width; x++) {
img.data[x*4 + 0] = pixels.charCodeAt(x*3 + 2);
img.data[x*4 + 1] = pixels.charCodeAt(x*3 + 1);
img.data[x*4 + 2] = pixels.charCodeAt(x*3 + 0);
img.data[x*4 + 3] = 0xFF;
}
// Render scanline
this.ctx.putImageData(img, 0, msg.line);
}
};
$.fn.sstvMessagePanel = function() {
if (!this.data('panel')) {
this.data('panel', new SstvMessagePanel(this));
}
return this.data('panel');
};
FaxMessagePanel = function(el) {
MessagePanel.call(this, el);
this.initClearTimer();
}
FaxMessagePanel.prototype = Object.create(MessagePanel.prototype);
FaxMessagePanel.prototype.supportsMessage = function(message) {
return message['mode'] === 'Fax';
};
FaxMessagePanel.prototype.render = function() {
$(this.el).append($(
'
' +
'
' +
'
Fax
' +
'
' +
'' +
'
'
));
};
FaxMessagePanel.prototype.pushMessage = function(msg) {
var $b = $(this.el).find('tbody');
if(msg.hasOwnProperty('message')) {
// Append a new debug message text
// See service log for debug output instead
// $b.append($('
' + msg.message + '
'));
// this.scrollToBottom();
}
else if(msg.width>0 && msg.height>0 && !msg.hasOwnProperty('line')) {
var f = msg.frequency>0? ' at ' + Math.floor(msg.frequency/1000) + 'kHz' : '';
var h = '