Can you string replace in Virtual Parameters?

Here is some of the partial code from a Virtual Parameter:

  let sig = declare("InternetGatewayDevice.WANDevice.1.X_3GPP_LTEInterfaceConfig.RadioModule.DownlinkStdDevRSRP", {value: now}).value[0];
  let tul = declare("InternetGatewayDevice.WANDevice.1.X_3GPP_LTEInterfaceConfig.RadioModule.UplinkMCS", {value: now}).value[0];
  let tdl = declare("InternetGatewayDevice.WANDevice.1.X_3GPP_LTEInterfaceConfig.RadioModule.DownlinkMCS", {value: now}).value[0];
  signal = sig+" ["+tul+"/"+tdl+"]";
  signal = signal.replace("QAM", ""); <----THIS DOESN"T WORK

From the above code I get this from signal:
-84.80/-108.50/-104.00/-86.00 [QAM16(23)/QAM64(28)]

To save screen space on index page, I want to remove at least QAM from it, to look like this:
-84.80/-108.50/-104.00/-86.00 [16(23)/64(28)]

Can this be done in Virtual Parameters?

Your issue is probably further down in your vparam. The text concat works fine. Paste the full contents of your vparam if you’d like further assistance.

This is the part that doesn’t work. If I have this in the vparam TITAN area, it doesn’t return anything for TITAN case.

Here is the whole thing, in it’s working form, without the replace part:

const now = Date.now();
let productClass = declare("DeviceID.ProductClass", {value: 1}).value[0];
let signal = "";

switch(productClass) {
  case "TITAN4000":
  let sig = declare("InternetGatewayDevice.WANDevice.1.X_3GPP_LTEInterfaceConfig.RadioModule.DownlinkStdDevRSRP", {value: now}).value[0];
  let tul = declare("InternetGatewayDevice.WANDevice.1.X_3GPP_LTEInterfaceConfig.RadioModule.UplinkMCS", {value: now}).value[0];
  let tdl = declare("InternetGatewayDevice.WANDevice.1.X_3GPP_LTEInterfaceConfig.RadioModule.DownlinkMCS", {value: now}).value[0];
  signal = sig+" ["+tul+"/"+tdl+"]";
    break;
  default:
  let bsa = declare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP0", {value: now}).value[0];
  let bsb = declare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.RSRP1", {value: now}).value[0];
  let bul = declare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.UL_Mcs", {value: now}).value[0];
  let bdl = declare("InternetGatewayDevice.WEB_GUI.Network.LTE_Setting.Status.DL_Mcs", {value: now}).value[0];
 signal = bsa+"/"+bsb+" ["+bul+"/"+bdl+"]";
} 
log(productClass+" signal="+signal);
return {writable: false, value: [signal, "xsd:string"]};

In the TITAN case area, I want to return the signal with the QAM text removed.

.replace(‘QAM’, ‘’) replaces the first instance of QAM. You need a global regex to replace QAM everywhere. Try this:

signal = `${sig} [${tul}/${tdl}]`.replace(/QAM/g, '');

The backtick ` tells the JavaScript engine to use string interpolation instead of string concatenation. To me, this makes things look cleaner.

Here is some code to demonstrate the issue and the solution:

let sig = '-84.80/-108.50/-104.00/-86.00';
let tul = 'QAM16(23)';
let tdl = 'QAM64(28)';
let signal = `${sig} [${tul}/${tdl}]`;
console.log('Initial:        ' + signal);
console.log('Simple replace: ' + signal.replace('QAM', ''));
console.log('Global regex:   ' + signal.replace(/QAM/g, ''));
Initial:        -84.80/-108.50/-104.00/-86.00 [QAM16(23)/QAM64(28)]
Simple replace: -84.80/-108.50/-104.00/-86.00 [16(23)/QAM64(28)]
Global regex:   -84.80/-108.50/-104.00/-86.00 [16(23)/64(28)]
2 Likes

That works great! Thanks a bunch for the help and the code cleanup, it does look better and and easier to understand that way.

With what you showed me, I ended up adding a bit more regex to it:

signal = `${sig} [${tul}/${tdl}]`.replace(/-|\.\d\d|QAM\d*\(|QPSK\d*\(|\)/g, '');

That removes all different things QAM could be, and gets rid of junk I didn’t want on the index page.
from:
-84.80/-108.50/-104.00/-86.00 [QAM16(23)/QAM64(28)]
to:
84/108/104/86 [23/28]

That save a bunch of screen space!

Ciao may you drive me where I can read the log printed into vparam code?
I have tryied log(…); and console.log(…); it does not return error, but I do not know where the output goes
in genieacs-cwmp-access.log I’m able to see the log(…); sent from provisioning script but I guess there is way also to catch from vparam.
sorry for the dum question.

Please create your own thread instead of resurrecting an 18 month old thread.