소켓에서 ID를 얻어야하지만이 코드가 올바른 것을 제공하지 않습니다. 누군가 내 코드에서 무엇이 잘못되었는지 말해 줄 수 있습니까? Param_code이 수치 및 열거 체에 대한 매개 변수의 ID 섹션바이트를 읽고 자바에서 마스크하기
•에 해당하고, 수치 및 열거 체 매개 변수에 대한 • (ActualValue) :
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");
}
}
주 (자세한 내용은 아래 참조) 매개 변수 (SetValue)에서 Param_code는 0x40000000에 해당하고 매개 변수 섹션의 ID는
입니다. • Alarm Parameters의 경우, Param_code는 0x80000000에 해당합니다. + 매개 변수 섹션의 ID입니다.
답장을 보내 주셔서 감사합니다 : 위와 같이 작성한 코드를 확인합니다. 나는 결과가 다르다는 것을 안다. 내 if 문이 조건 아래에 올바른지? • 옵션 1 : 경우에 따라 Param_code가 ID 에 해당합니다. • 옵션 2 : 때때로 Param_code가 0x40000000 + ID 에 해당합니다. • 옵션 3 : 경우에 따라 Param_code가 0x80000000 + ID – michdraft
에 해당합니다. 비록 당신이 그것을 단순화 할 수 있습니다. if ((0xff & cbuf [3]) == 0x80)로 작성할 수 있습니다. –