dawn-common.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. 'require baseclass';
  3. 'require rpc';
  4. let callDawnGetNetwork, callDawnGetHearingMap, callHostHints;
  5. callDawnGetNetwork = rpc.declare({
  6. object: 'dawn',
  7. method: 'get_network',
  8. expect: { }
  9. });
  10. callDawnGetHearingMap = rpc.declare({
  11. object: 'dawn',
  12. method: 'get_hearing_map',
  13. expect: { }
  14. });
  15. callHostHints = rpc.declare({
  16. object: 'luci-rpc',
  17. method: 'getHostHints',
  18. expect: { }
  19. });
  20. function isDawnRPCAvailable() {
  21. return rpc.list("dawn").then(function(signatures) {
  22. return 'dawn' in signatures && 'get_network' in signatures.dawn && 'get_hearing_map' in signatures.dawn;
  23. });
  24. }
  25. function getAvailableText(available) {
  26. return ( available ? _('Available') : _('Not available') );
  27. }
  28. function getYesText(yes) {
  29. return ( yes ? _('Yes') : _('No') );
  30. }
  31. function getChannelFromFrequency(freq) {
  32. if (freq <= 2400) {
  33. return 0;
  34. }
  35. else if (freq == 2484) {
  36. return 14;
  37. }
  38. else if (freq < 2484) {
  39. return (freq - 2407) / 5;
  40. }
  41. else if (freq >= 4910 && freq <= 4980) {
  42. return (freq - 4000) / 5;
  43. }
  44. else if (freq <= 45000) {
  45. return (freq - 5000) / 5;
  46. }
  47. else if (freq >= 58320 && freq <= 64800) {
  48. return (freq - 56160) / 2160;
  49. }
  50. else {
  51. return 0;
  52. }
  53. }
  54. function getFormattedNumber(num, decimals, divider = 1) {
  55. return (num/divider).toFixed(decimals);
  56. }
  57. function getHostnameFromMAC(hosthints, mac) {
  58. return ( hosthints[mac] && hosthints[mac].name ? hosthints[mac].name + ' (' + mac + ')' : mac );
  59. }
  60. function getDawnServiceNotRunningErrorMessage() {
  61. return E('div', { 'class': 'alert-message fade-in warning' }, [
  62. E('h4', _('DAWN service unavailable')),
  63. E('p', _('Unable to query the DAWN service via ubus, the service appears to be stopped.')),
  64. E('a', { 'href': L.url('admin/system/startup') }, _('Check Startup services'))
  65. ]);
  66. }
  67. return L.Class.extend({
  68. callDawnGetNetwork: callDawnGetNetwork,
  69. callDawnGetHearingMap: callDawnGetHearingMap,
  70. callHostHints: callHostHints,
  71. isDawnRPCAvailable: isDawnRPCAvailable,
  72. getAvailableText: getAvailableText,
  73. getYesText: getYesText,
  74. getChannelFromFrequency: getChannelFromFrequency,
  75. getFormattedNumber: getFormattedNumber,
  76. getHostnameFromMAC: getHostnameFromMAC,
  77. getDawnServiceNotRunningErrorMessage: getDawnServiceNotRunningErrorMessage
  78. });