Exemplo n.º 1
0
        /// <inheritdoc />
        protected override bool RetrieveRxSignalStrength()
        {
            Stopwatch durationWatch = Stopwatch.StartNew();

            DeviceSpecificOid singleOid;

            if (this.OidLookup.TryGetValue(RetrievableValuesEnum.RxSignalStrengthImmediateOid, out singleOid) && !singleOid.Oid.IsNull)
            {
                this.RxSignalStrengthBacking = this.LowerSnmpLayer.QueryAsInt(singleOid.Oid, "RSSI single value");
                this.RecordCachableOid(CachableValueMeanings.WirelessRxSignalStrength, singleOid.Oid);
            }
            else
            {
                RetrievableValuesEnum[] valuesToQuery =
                {
                    RetrievableValuesEnum.RxSignalStrengthCh0AppendMacAndInterfaceId,
                    RetrievableValuesEnum.RxSignalStrengthCh1AppendMacAndInterfaceId,
                    RetrievableValuesEnum.RxSignalStrengthCh2AppendMacAndInterfaceId
                };

                DeviceSpecificOid[] deviceSpecificOids = new DeviceSpecificOid[valuesToQuery.Length];
                DeviceSpecificOid[] oidValues;
                if (!this.OidLookup.TryGetValues(out oidValues, valuesToQuery))
                {
                    log.Warn($"Not even one supported OID has been found for getting the stream-specific RX level. RxSignalStrength for device '{this.DeviceAddress}', interface ID {this.InterfaceId}, cannot be retrieved.");
                    this.RxSignalStrengthBacking = double.NegativeInfinity;
                    return(true);
                }

                var clientSpecificOids = oidValues.Where(oid => oid != null).Select(oid => {
                    var interfaceTypeOid = oid.Oid + this.RemoteMacString.HexStringToByteArray().ToDottedDecimalOid() + new Oid(new int[] { this.InterfaceId.Value });

                    return(interfaceTypeOid);
                });

                var queryResults = this.LowerSnmpLayer.QueryAsInt(clientSpecificOids, "wireless peer info, RX signal strength");

                this.RecordCachableOids(CachableValueMeanings.WirelessRxSignalStrength, clientSpecificOids);

                // Note: As the SNMP cannot return -infinity MikroTik devices return 0.
                //       Hence we effectively skip 0 values here assuming that stream is not in use.
                this.RxSignalStrengthBacking = queryResults.Values.Where(v => v != 0).DecibelLogSum();
            }

            durationWatch.Stop();

            this.localQueryDuration += durationWatch.Elapsed;

            return(true);
        }
        /// <inheritdoc />
        public bool TryGetValues(out DeviceSpecificOid[] oidValues, params RetrievableValuesEnum[] valuesToQuery)
        {
            bool atLeastOneFound = false;

            oidValues = new DeviceSpecificOid[valuesToQuery.Length];
            for (int i = 0; i < valuesToQuery.Length; i++)
            {
                DeviceSpecificOid value;
                if (this.localLookup.TryGetValue(valuesToQuery[i], out value))
                {
                    atLeastOneFound = true;
                    oidValues[i]    = value;
                }
                else
                {
                    oidValues[i] = null;
                }
            }

            return(atLeastOneFound);
        }
 /// <inheritdoc />
 public bool TryGetValue(RetrievableValuesEnum key, out DeviceSpecificOid value)
 {
     return(this.localLookup.TryGetValue(key, out value));
 }