I developed a little SNMP driver to read some key parameters of a MDM5010 Newtec in a table. It can read the tables indeed but some values are returned in IEEE 754 format like that:
2 VT_ARRAY|VT_VARIANT (1)
0 VT_BSTR : 40.DC.D6.08 which correspond to: 6.901126861572265625
How can I convert this string in double? Here below the XML for that parameter. In the SNMP part, the type is "octetstring" which I guess is correct. But in <Measurment> the type is "String" resulting to the display above. So, is there a quick way to convert that string to a double number?
--------------------------------------------------------------------------
<Param id="1003" trending="true">
<Name>ntcDvbDmdsMonDvbS2EsNo</Name>
<Description>Es No (Ntc Dvb Dmds Mon Dvb S 2)</Description>
<Information>
<Subtext>
<![CDATA[Received Es/No Header]]>
</Subtext>
</Information>
<Type>read</Type>
<Interprete>
<RawType>other</RawType>
<Type>string</Type>
<LengthType>next param</LengthType>
</Interprete>
<SNMP>
<Enabled>true</Enabled>
<OID type="complete">1.3.6.1.4.1.5835.5.2.8800.1.14.1.3</OID>
<Type>octetstring</Type>
</SNMP>
<Display>
<RTDisplay>true</RTDisplay>
<Units>dB</Units>
</Display>
<Measurement>
<Type>string</Type>
</Measurement>
</Param>
Hi,
I don't think that there is a direct conversion available from the xml tags.
The conversion will probably have to be done through a conversion via a QAction:
-Hide the column with parameter 1003 (set width to 0)
-Add a new numeric parameter as a new column to the end of the table (ColumnOption type="retrieved" in the table)
-Add a QAction to trigger on changes of the table (row="true"), and in that QAction read out the value of parameter 1003, convert the value with a converter that is able to translate IEEE754 and set the converted double value in the newly created parameter.
Possible pitfall: when DataMiner recognizes all ASCII character values in an octetstring it will convert it to the ASCII character. E.g. if the octetstring has value 31.32.33.34 and this is read out in a qaction it will be returned as string "1234" instead of "31.32.33.34" so in that case there will be some detection needed to change it back in the octetstring format
Hi Dominique, as newly created parameter “1014” is part of a table it’s also needed to provide the primary key of the row that is tried to be set. The call that is now executed is protocol.SetParameter() but this call is intended for a standalone parameter. For a table cell it should be something that looks like this: protocol.SetParameterIndexByKey(1000, protocol.RowKey(), 14, 6.91);
Where:
-1000 = parameter id of the table
-protocol.RowKey() = primary key value of the row that needs to be set, this call gets the key for which the qaction was triggered, if other rows need to be set then this could be replaced with an other string value
-14 = one based column index of the column parameter that will be set (this is the idx=”” columnoption attribute value +1 added)
-6.91 = value to be set in the parameter
TIP: instead of providing the raw numbers for pid and column, the “Parameter.” object can also be used which makes everything more readable
PITFALL: I saw in the example that a string “6.91” is used to fill in a double value, best is to use a real double value because that is independent of the server cultural setting. In some countries a dot is the decimal separator while in other countries a comma is the decimal separator
I could evenutally display my test value at the right place. So I know at least the QAction is triggered. But now I have some trouble to recover the string I need to convert in double. After various search in our installed driver, it came up to something like this to recover it:
string sKey = Convert.ToString(protocol.RowKey());
int iTrigger = protocol.GetTriggerParameter();
object oKeyVal = protocol.GetParameterIndexByKey(iTrigger, sKey, 2);
string s_raw_data = Convert.ToString(oKeyVal);
And 2 is the column index of the 1003 parameter I want to recover. However, it doesn’t seem to work …
-Is the column index 2 defined in the columnoption attribute of the table for parameter 1003 like this: idx=”2″? If that is the case then it should be GetParameterIndexByKey(iTrigger, sKey, 3) as the idx attribute is zero based and the call GetParameterIndexByKey is one based (so there should be +1).
-Instead of having to call GetTriggerParameter(), you can simply fill in the parameter id of the table e.g. int iTrigger = 1000; (but best is to work with the Parameter object like was written in my previous answer)
Hi Laurens,
Indeed idx=”2″ so I set the GetParameter..; like this in it works:
object oKeyVal = protocol.GetParameterIndexByKey(iTrigger, sKey, 3);
So the issue is now fixed 🙂 Thank you very much for your help. Here below the complete code of the QAction which convert an “octectstring” representing a IEEE754 format number to double. I hope this can be useful for others:
public class QAction
{
///
/// Sets
///
/// Link with Skyline Dataminer
public static void Run(SLProtocol protocol)
{
string sKey = Convert.ToString(protocol.RowKey());
int iTrigger = protocol.GetTriggerParameter();
try
{
long raw_data = 0x0; // raw IEEE754 data
long s;
char c;
object oKeyVal = protocol.GetParameterIndexByKey(iTrigger, sKey, 3);
string s_raw_data = Convert.ToString(oKeyVal);
for (int i = 0; i = 0x30 && c <= 0x39)
{
raw_data <= 0x41 && c <= 0x46)
{
raw_data <> 24;
long n2 = (raw_data & 0xFF0000) >> 16;
long n1 = (raw_data & 0xFF00) >> 8;
long n0 = (raw_data & 0xFF);
double sign, exp, mantissa, value;
sign = Convert.ToDouble(-2 * ((n3 & 0x80) >> 7) + 1);
exp = Convert.ToDouble(((n3 & 0x7f) <> 7) – 127);
mantissa = Convert.ToDouble((0x800000 + ((n2 & 0x7f) << 16) + (n1 << 8) + n0)) / 0x800000;
value = sign * mantissa * Math.Pow(2, exp);
string s_data = Convert.ToString(value);
protocol.SetParameterIndexByKey(1000, protocol.RowKey(), 14, s_data);
}
catch (Exception ex)
{
protocol.Log(string.Format(NumberFormatInfo.InvariantInfo, "QA{0}: (Sets) {1}", protocol.QActionID, ex.ToString()), LogType.Error, LogLevel.NoLogging);
}
}
Thank you Laurens, this is what I was thinking. So I started to adapt an existing QAction I formely develop to convert IEEE754 to double. But in this case, it looks like the QAction is never triggered. In short, I created table “1000”:
Added additional column as retrieved:
and added the corresponding parameter “1014”, decription “Es/No”.
QAction declaration with row=”true”:
Just to make sure it is triggered, I just assign a test value to parameter 1014 as follow:
protocol.SetParameter(1014,”6.91″);
In the table, the additional column appears indeed with title “Es/No”, however, the value under never appears and stays as “No Initialized”. In this particular case, I should see the value I assigned i.e. 6.91? Or I am missing something?