I should get ID from socket but this code is not giving the correct one. Can someone tell me what is wrong in my code? (see below for more information)
for (int i = 0; i < numberOfSRecords; i++) {
socketReader.read(cbuf, 0, 4);
String Param_Codes_In_HEX =
Integer.toHexString(0x000000ff & cbuf[2]) +
Integer.toHexString(0x000000ff & cbuf[1]) +
Integer.toHexString(0x000000ff & cbuf[0]);
System.out.println("Param_Codes_In_HEX: "+Param_Codes_In_HEX);
int paramCode = Integer.parseInt(Param_Codes_In_HEX, 16);
if ((0x000000ff & cbuf[3]) ==0) {
EnumParamCodes enumParamCode =
EnumConverterUtil.getEnumFor(EnumParamCodes.class, paramCode);
System.out.println("Param_code " + paramCode + ": " + enumParamCode);
}
else if((0x000000ff & cbuf[3]) ==64)
{
paramCode = 0x0000ffff & paramCode ;
EnumParamCodes enumParamCode = EnumConverterUtil.getEnumFor(EnumParamCodes.class, paramCode);
System.out.println("Param_code " + paramCode + ": " + enumParamCode);
}
else if ((0x000000ff & cbuf[3]) ==128) {
paramCode = 0x00ffffff & paramCode ;
EnumAlarm enumParamCodeAlarm = EnumConverterUtil.getEnumFor(EnumAlarm.class, paramCode);
System.out.println("Param_code " + paramCode + ": " + enumParamCodeAlarm);
}
else{
System.out.println("Error in the body of message");
}
}
Note:
• For Numerical and Enumerative Parameters (ActualValue), the
Param_code corresponds to the ID in the Parameters section
• For Numerical and Enumerative Parameters (SetValue), the
Param_code corresponds to 0x40000000 + the ID in the Parameters
section
• For Alarm Parameters, the Param_code corresponds to 0x80000000
+ the ID in the Parameters section
this should get the 0 padding for you