vodafone-station-cli
Version:
Access your Vodafone Station from the comfort of the command line.
314 lines (313 loc) • 11.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixWithinOneMonth = exports.ToleratedDeviation = exports.CompliesToSpecifications = exports.FixImmediately = exports.DownstreamDeviationUnknown = exports.DownstreamDeviation4096QAM = exports.DownstreamDeviation2048QAM = exports.DownstreamDeviation1024QAM = exports.DownstreamDeviation256QAM = exports.DownstreamDeviation64QAM = exports.UpstreamDeviationOFDMA = exports.UpstreamDeviationSCQAM = exports.SEVERITY_COLORS = void 0;
exports.colorize = colorize;
exports.downstreamDeviation = downstreamDeviation;
exports.downstreamDeviationFactory = downstreamDeviationFactory;
exports.upstreamDeviationFactory = upstreamDeviationFactory;
exports.upstreamDeviation = upstreamDeviation;
exports.checkSignalToNoise = checkSignalToNoise;
const constants_1 = require("./constants");
// based on https://www.vodafonekabelforum.de/viewtopic.php?t=32353
class DocsisDiagnose {
docsisStatus;
constructor(docsisStatus) {
this.docsisStatus = docsisStatus;
}
get diagnose() {
return {
downstream: this.checkDownstream(),
downstreamOfdm: this.checkOfdmDownstream(),
time: this.docsisStatus.time,
upstream: this.checkUpstream(),
upstreamOfdma: this.checkOfdmaUpstream(),
};
}
checkDownstream() {
return this.docsisStatus.downstream
.map(channel => ({ ...channel, diagnose: downstreamDeviation(channel) }));
}
checkDownstreamSNR() {
return this.docsisStatus.downstream
.map(channel => ({ ...channel, diagnose: checkSignalToNoise(channel) }));
}
checkOfdmaUpstream() {
return this.docsisStatus.upstreamOfdma
.map(channel => ({ ...channel, diagnose: upstreamDeviation(channel) }));
}
checkOfdmDownstream() {
return this.docsisStatus.downstreamOfdm
.map(channel => ({ ...channel, diagnose: downstreamDeviation(channel) }));
}
checkOfdmDownstreamSNR() {
return this.docsisStatus.downstreamOfdm
.map(channel => ({ ...channel, diagnose: checkSignalToNoise(channel) }));
}
checkUpstream() {
return this.docsisStatus.upstream
.map(channel => ({ ...channel, diagnose: upstreamDeviation(channel) }));
}
hasDeviations() {
return [
this.checkDownstream(),
this.checkDownstreamSNR(),
this.checkOfdmDownstream(),
this.checkOfdmDownstreamSNR(),
this.checkUpstream(),
this.checkOfdmaUpstream(),
]
.flat()
.some(({ diagnose }) => diagnose.deviation);
}
printDeviationsConsole() {
if (this.hasDeviations() === false) {
return colorize('green', 'Hooray no deviations found!');
}
const down = [...this.checkDownstream(), ...this.checkOfdmDownstream()]
.filter(downstream => downstream.diagnose.deviation)
.map(down => colorize(down.diagnose.color, `ch${down.channelId}pl`));
const downSnr = [...this.checkDownstreamSNR(),
...this.checkOfdmDownstreamSNR()]
.filter(downstream => downstream.diagnose.deviation)
.map(down => colorize(down.diagnose.color, `ch${down.channelId}snr`));
const up = [...this.diagnose.upstream, ...this.diagnose.upstreamOfdma]
.filter(upstream => upstream.diagnose.deviation)
.map(upstream => colorize(upstream.diagnose.color, `ch${upstream.channelId}pl`)).join(', ');
return [
'Legend: pl = power level | snr = signal to noise ratio',
`Colors: ${colorize(exports.FixWithinOneMonth.color, exports.FixWithinOneMonth.description)} | ${colorize(exports.FixImmediately.color, exports.FixImmediately.description)}`,
`DOWN: ${[...down, ...downSnr].join(', ')}`,
`UP: ${up}`,
].join('\n');
}
}
exports.default = DocsisDiagnose;
exports.SEVERITY_COLORS = {
green: '\u001B[32m',
red: '\u001B[31m',
yellow: '\u001B[33m',
};
function colorize(severity, message) {
const color = exports.SEVERITY_COLORS[severity] ?? exports.SEVERITY_COLORS.green;
const colorStop = '\u001B[0m';
return `${color}${message}${colorStop}`;
}
class UpstreamDeviationSCQAM {
channelType = 'SC-QAM';
modulation = '64QAM';
check(powerLevel) {
if (powerLevel <= 35)
return exports.FixImmediately;
if (powerLevel > 35 && powerLevel <= 37)
return exports.FixWithinOneMonth;
if (powerLevel > 37 && powerLevel <= 41)
return exports.ToleratedDeviation;
if (powerLevel > 41 && powerLevel <= 47)
return exports.CompliesToSpecifications;
if (powerLevel > 47 && powerLevel <= 51)
return exports.ToleratedDeviation;
if (powerLevel > 51 && powerLevel <= 53)
return exports.FixWithinOneMonth;
if (powerLevel > 53)
return exports.FixImmediately;
throw new Error(`PowerLevel is not within supported range. PowerLevel: ${powerLevel}`);
}
}
exports.UpstreamDeviationSCQAM = UpstreamDeviationSCQAM;
class UpstreamDeviationOFDMA {
channelType = 'OFDMA';
modulation = '64QAM';
check(powerLevel) {
if (powerLevel <= 38)
return exports.FixImmediately;
if (powerLevel > 38 && powerLevel <= 40)
return exports.FixWithinOneMonth;
if (powerLevel > 40 && powerLevel <= 44)
return exports.ToleratedDeviation;
if (powerLevel > 44 && powerLevel <= 47)
return exports.CompliesToSpecifications;
if (powerLevel > 47 && powerLevel <= 48)
return exports.ToleratedDeviation;
if (powerLevel > 48 && powerLevel <= 50)
return exports.FixWithinOneMonth;
if (powerLevel > 50)
return exports.FixImmediately;
if (powerLevel === constants_1.BAD_MODEM_POWER_LEVEL)
return exports.FixImmediately;
throw new Error(`PowerLevel is not within supported range. PowerLevel: ${powerLevel}`);
}
}
exports.UpstreamDeviationOFDMA = UpstreamDeviationOFDMA;
function downstreamDeviation({ modulation, powerLevel }) {
const deviation = downstreamDeviationFactory(modulation);
return deviation.check(powerLevel);
}
class DownstreamDeviation64QAM {
modulation = '64QAM';
check(powerLevel) {
if (powerLevel >= -60 && powerLevel <= -14)
return exports.FixImmediately;
if (powerLevel > -14 && powerLevel <= -12)
return exports.FixWithinOneMonth;
if (powerLevel > -12 && powerLevel <= -10)
return exports.ToleratedDeviation;
if (powerLevel > -10 && powerLevel <= 7)
return exports.CompliesToSpecifications;
if (powerLevel > 7 && powerLevel <= 12)
return exports.ToleratedDeviation;
if (powerLevel > 12 && powerLevel <= 14)
return exports.FixWithinOneMonth;
if (powerLevel >= 14.1)
return exports.FixImmediately;
throw new Error(`PowerLevel is not within supported range. PowerLevel: ${powerLevel}`);
}
}
exports.DownstreamDeviation64QAM = DownstreamDeviation64QAM;
class DownstreamDeviation256QAM {
delegate = new DownstreamDeviation64QAM();
modulation = '256QAM';
check(powerLevel) {
const adjustedPowerLevel = powerLevel - 6 <= -60 ? powerLevel : powerLevel - 6;
return this.delegate.check(adjustedPowerLevel);
}
}
exports.DownstreamDeviation256QAM = DownstreamDeviation256QAM;
class DownstreamDeviation1024QAM {
delegate = new DownstreamDeviation64QAM();
modulation = '1024QAM';
check(powerLevel) {
const adjustedPowerLevel = powerLevel - 8 <= -60 ? powerLevel : powerLevel - 8;
return this.delegate.check(adjustedPowerLevel);
}
}
exports.DownstreamDeviation1024QAM = DownstreamDeviation1024QAM;
class DownstreamDeviation2048QAM {
delegate = new DownstreamDeviation64QAM();
modulation = '2048QAM';
check(powerLevel) {
const adjustedPowerLevel = powerLevel - 10 <= -60 ? powerLevel : powerLevel - 10;
return this.delegate.check(adjustedPowerLevel);
}
}
exports.DownstreamDeviation2048QAM = DownstreamDeviation2048QAM;
class DownstreamDeviation4096QAM {
delegate = new DownstreamDeviation64QAM();
modulation = '4096QAM';
check(powerLevel) {
const adjustedPowerLevel = powerLevel - 12 <= -60 ? powerLevel : powerLevel - 12;
return this.delegate.check(adjustedPowerLevel);
}
}
exports.DownstreamDeviation4096QAM = DownstreamDeviation4096QAM;
class DownstreamDeviationUnknown {
modulation = 'Unknown';
check(_powerLevel) {
return exports.FixImmediately;
}
}
exports.DownstreamDeviationUnknown = DownstreamDeviationUnknown;
exports.FixImmediately = {
color: 'red',
description: 'Fix immediately',
deviation: true,
};
exports.CompliesToSpecifications = {
color: 'green',
description: 'Complies to specifications',
deviation: false,
};
exports.ToleratedDeviation = {
color: 'green',
description: 'Tolerated deviation',
deviation: false,
};
exports.FixWithinOneMonth = {
color: 'yellow',
description: 'Fix within one Month',
deviation: true,
};
function downstreamDeviationFactory(modulation) {
switch (modulation) {
case '64QAM': {
return new DownstreamDeviation64QAM();
}
case '256QAM': {
return new DownstreamDeviation256QAM();
}
case '1024QAM': {
return new DownstreamDeviation1024QAM();
}
case '2048QAM': {
return new DownstreamDeviation2048QAM();
}
case '4096QAM': {
return new DownstreamDeviation4096QAM();
}
case 'Unknown': {
return new DownstreamDeviationUnknown();
}
default: {
throw new Error(`Unsupported modulation ${modulation}`);
}
}
}
function upstreamDeviationFactory(channelType) {
switch (channelType) {
case 'OFDMA': {
return new UpstreamDeviationOFDMA();
}
case 'SC-QAM': {
return new UpstreamDeviationSCQAM();
}
default: {
throw new Error(`Unsupported channel type ${channelType}`);
}
}
}
function upstreamDeviation({ channelType, powerLevel }) {
const deviation = upstreamDeviationFactory(channelType);
return deviation.check(powerLevel);
}
function checkSignalToNoise({ modulation, snr }) {
let snrOffsetForModulation;
switch (modulation) {
case '64QAM': {
snrOffsetForModulation = 0;
break;
}
case '256QAM': {
snrOffsetForModulation = 6;
break;
}
case '1024QAM': {
snrOffsetForModulation = 12;
break;
}
case '2048QAM': {
snrOffsetForModulation = 15;
break;
}
case '4096QAM': {
snrOffsetForModulation = 18;
break;
}
case 'Unknown': {
// For unknown modulation, we can't determine proper SNR deviation
// so we return FixImmediately to indicate a problem
return exports.FixImmediately;
}
default: {
throw new Error(`Unsupported modulation ${modulation}`);
}
}
const adjustedSNR = snr - snrOffsetForModulation;
if (adjustedSNR <= 24)
return exports.FixImmediately;
if (adjustedSNR > 24 && adjustedSNR <= 26)
return exports.FixWithinOneMonth;
if (adjustedSNR > 26 && adjustedSNR <= 27)
return exports.ToleratedDeviation;
if (adjustedSNR > 27)
return exports.CompliesToSpecifications;
throw new Error(`SignalToNoiseRation is not within supported range. SNR: ${snr}`);
}