diff --git a/htdocs/lib/MessagePanel.js b/htdocs/lib/MessagePanel.js index e0215de0..988f1453 100644 --- a/htdocs/lib/MessagePanel.js +++ b/htdocs/lib/MessagePanel.js @@ -474,7 +474,7 @@ AircraftMessagePanel.prototype.renderAcars = function(acars) { } var details = '

ACARS message

'; if ('flight' in acars) { - details += '
Flight: ' + acars['flight'] + '
'; + details += '
Flight: ' + this.handleFlight(acars['flight']) + '
'; } details += '
Registration: ' + acars['reg'].replace(/^\.+/g, '') + '
'; if ('media-adv' in acars) { @@ -496,9 +496,13 @@ AircraftMessagePanel.prototype.renderAcars = function(acars) { adsc['tags'].forEach(function(tag) { if ('basic_report' in tag) { var basic_report = tag['basic_report']; - details += '
Basic report
'; + details += '
Basic ADS-C report
'; details += '
Position: ' + basic_report['lat'] + ', ' + basic_report['lon'] + '
'; details += '
Altitude: ' + basic_report['alt'] + '
'; + } else if ('cancel_all_contracts' in tag) { + details += '
Cancel all ADS-C contracts
'; + } else if ('cancel_contract' in tag) { + details += '
Cancel ADS-C contract
'; } else { details += '
Unsupported tag
'; } @@ -513,7 +517,11 @@ AircraftMessagePanel.prototype.renderAcars = function(acars) { details += '
' + acars['msg_text'] + '
'; } return details; -} +}; + +AircraftMessagePanel.prototype.handleFlight = function(raw) { + return raw.replace(/^([0-9A-Z]{2})0*([0-9A-Z]+$)/, '$1$2'); +}; HfdlMessagePanel = function(el) { AircraftMessagePanel.call(this, el); @@ -539,6 +547,33 @@ HfdlMessagePanel.prototype.supportsMessage = function(message) { return message['mode'] === 'HFDL'; }; +HfdlMessagePanel.prototype.renderPosition = function(hfnpdu) { + if ('pos' in hfnpdu) { + var pos = hfnpdu['pos']; + var lat = pos['lat'] || 180; + var lon = pos['lon'] || 180; + if (Math.abs(lat) <= 90 && Math.abs(lon) <= 180) { + return '
Position: ' + pos['lat'] + ', ' + pos['lon'] + '
'; + } + } + return ''; +}; + +HfdlMessagePanel.prototype.renderLogon = function(lpdu) { + var details = '' + if (lpdu['ac_info'] && lpdu['ac_info']['icao']) { + details += '
ICAO: ' + lpdu['ac_info']['icao'] + '
'; + } + if (lpdu['hfnpdu']) { + var hfnpdu = lpdu['hfnpdu']; + if (hfnpdu['flight_id'] && hfnpdu['flight_id'] !== '') { + details += '
Flight: ' + this.handleFlight(lpdu['hfnpdu']['flight_id']) + '
' + } + details += this.renderPosition(hfnpdu); + } + return details; +}; + HfdlMessagePanel.prototype.pushMessage = function(message) { var $b = $(this.el).find('tbody'); @@ -550,33 +585,6 @@ HfdlMessagePanel.prototype.pushMessage = function(message) { return a['id']; } - var renderPosition = function(hfnpdu) { - if ('pos' in hfnpdu) { - var pos = hfnpdu['pos']; - var lat = pos['lat'] || 180; - var lon = pos['lon'] || 180; - if (Math.abs(lat) <= 90 && Math.abs(lon) <= 180) { - return '
Position: ' + pos['lat'] + ', ' + pos['lon'] + '
'; - } - } - return ''; - } - - var renderLogon = function(lpdu) { - var details = '' - if (lpdu['ac_info'] && lpdu['ac_info']['icao']) { - details += '
ICAO: ' + lpdu['ac_info']['icao'] + '
'; - } - if (lpdu['hfnpdu']) { - var hfnpdu = lpdu['hfnpdu']; - if (hfnpdu['flight_id'] && hfnpdu['flight_id'] !== '') { - details += '
Flight: ' + lpdu['hfnpdu']['flight_id'] + '
' - } - details += renderPosition(hfnpdu); - } - return details; - } - // TODO remove safety net once parsing is complete try { var payload = message['hfdl']; @@ -601,8 +609,8 @@ HfdlMessagePanel.prototype.pushMessage = function(message) { if (hfnpdu['type']['id'] === 209) { // performance data details = '

Performance data

'; - details += '
Flight: ' + hfnpdu['flight_id'] + '
'; - details += renderPosition(hnpdu); + details += '
Flight: ' + this.handleFlight(hfnpdu['flight_id']) + '
'; + details += this.renderPosition(hfnpdu); } else if (hfnpdu['type']['id'] === 255) { // enveloped data if ('acars' in hfnpdu) { @@ -619,12 +627,12 @@ HfdlMessagePanel.prototype.pushMessage = function(message) { } } else if (lpdu['type']['id'] === 79) { details = '

Logon resume

'; - details += renderLogon(lpdu); + details += this.renderLogon(lpdu); } else if (lpdu['type']['id'] === 95) { details = '

Logon resume confirmation

'; } else if (lpdu['type']['id'] === 143) { details = '

Logon request

'; - details += renderLogon(lpdu); + details += this.renderLogon(lpdu); } else if (lpdu['type']['id'] === 159) { details = '

Logon confirmation

'; if (lpdu['ac_info'] && lpdu['ac_info']['icao']) { @@ -635,7 +643,7 @@ HfdlMessagePanel.prototype.pushMessage = function(message) { } } else if (lpdu['type']['id'] === 191) { details = '

Logon request (DLS)

'; - details += renderLogon(lpdu); + details += this.renderLogon(lpdu); } } } catch (e) {