Access general device attributes (device>settings>attributes) from protocol decoder class?

Hi, I have edited the MegastekProtocolDecoder (like added wifi data for LBS support) and also added the MegastekProtocolEncoder.

But does anybody know if I can access the (custom) device Attributes which are set on Settings > Device > Attributes, from the <protocolname>ProtocolDecoder class? I like there to have the possibility to get the saved offset for RSSI values if they are stored for the device.

But everything what I have tried did failed to acces those values.

Thanks.

Anton Tananaeva year ago

You should be able to access the device. And I'm pretty sure there are some examples in the code.

What have you tried?

With your small tip I did manage to get it done.

Because the custom device attribute what I have set, is set a number, I did try to get it out as a number and not as a string. But now I have tried other methods, and that works.

Not as clean as I was looking for, but this works for now and is fail proof.

int WiFi_RSSI_Offset;
Device device = getCacheManager().getObject(Device.class, position.getDeviceId());	   
Object Object_RSSI_Offset = device.getAttributes().get("WiFi_RSSI_Offset");
if (Object_RSSI_Offset != null) {
    try {
       WiFi_RSSI_Offset = Integer.parseInt(Object_RSSI_Offset.toString());
    }
    catch (NumberFormatException e) {
       WiFi_RSSI_Offset = 0;
    }
} else {
    WiFi_RSSI_Offset = 0;
}