Closed DanielDocekalFHTW closed 6 years ago
The KNX bus has no idea about which GA uses which DPT. You have to tell calimero the DPT, then you can convert it accordingly. For the most common types, you find the converters here: https://github.com/calimero-project/calimero-core/tree/master/src/tuwien/auto/calimero/dptxlator
As i mentioned my problem is not the conversion from KNX encoded to human read able data. I already used the DPTXlator to get the according Data right. My question was if i there is a way to "map" the human readable the DPTXlator returns to boolean values (true/false). At the moment i made a workaround for the 1.xxx DPT's
private void print(final String svc, final ProcessEvent e) {
try {
System.out.println( e.getSourceAddr() + "->"
+ e.getDestination() + " " + svc + ": "
+ DataUnitBuilder.toHex(e.getASDU(), ""));
String id=DPM.get(e.getDestination()).getDPT();
DPTXlator t;
t = TranslatorTypes.createTranslator(0,id);
t.setAppendUnit(false);
t.setData(e.getASDU());
String s=t.getValue();
System.out.println("translation complete DPID:"+id+"Value:"+s);
Boolean b=true;
Float f=(float) -1;
if(id.startsWith("1")){
Integer val=Integer.valueOf(DataUnitBuilder.toHex(e.getASDU(), ""));
b=Integer.valueOf(val).equals(1);
System.out.println("bool");
}
else{
f=Float.valueOf(s);
System.out.println("float");
}
System.out.println("DPT ID:"+id+"B:"+b+"||F:"+f);
} catch (KNXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Use can use DPTXlatorBoolean::getValueBoolean
. Also note, that in cases a numeric representation makes sense (including booleans), you can use DPTXlator::getNumericValue
.
Thank you very much, this did the magic.
Hello, i have more a question than an issue.
Is there an easy method or way to convert the data received from my KNX Network to java Types. To explain this more, i already translated them from hex to a string already my problem is for further use i need strictly boolean vlaues(true/false), since Java isn't able to detect "on"(DPT 1.001) as "true" (for example) i need another way.
Is there an Method implemented already that i didn't find or has someone found a work around or is my bet on creating a mapping?
Greetings, Daniel