Searched StackOverflow在Windows 64位編譯Java罐子和RPI執行它的32位
下面的代碼工作正常,當我運行它的Windows 10的64位機器上的一個jar文件,但是當我複製的jar文件到一個RPI,它始終生成錯誤消息錯誤。我嘗試了從上面的鏈接使用JAVAW的建議,但是在RPI上找不到命令。 IOW,校驗和無法在RPI上正確計算。有關如何解決此問題的任何建議?
int messageBody[] = new int[(messageLen/2) - 2];
checkSum = 0;
for (int charPtr = 2; charPtr < messageLen;) {
firstChar = theMessage.charAt(charPtr++);
secondChar = theMessage.charAt(charPtr++);
theValue = ((firstChar >= 'A' ? (firstChar - 'A') + 10 : (firstChar - '0')) << 4)
| (secondChar >= 'A' ? (secondChar - 'A') + 10 : (secondChar - '0'));
if (messagePtr < messageBody.length) {
checkSum += theValue;
messageBody[messagePtr++] = theValue;
continue;
}
// Compute checksum
checkSum = (-checkSum & 0xff);
if (checkSum != theValue) {
System.err.println(System.lineSeparator() + "Check sum on received UPB packet failed -- should be " + checkSum + " but received as " + theValue);
System.err.println(System.lineSeparator() +" BAD MESSAGE[" + theMessage + "], " + theMessage.length() + " bytes");
return;
}
}
這將有助於看到您所看到的錯誤消息。 – SnakeDoc
PA-Feb-2016 18:45:19收到:PU280501FF7A8600D3 收到的UPB數據包的校驗失敗 - 應爲0,但接收爲-551 D3(0xD3)是實際的校驗和。它基於添加0x28,0x05,0x01,0xff,0x7A,0x86和0x00,然後進行2的補碼並最終將結果截斷爲8位 –
從它的外觀來看,你的錯誤實際上只是程序員強加的,as-in不是拋出異常。此外,由於您將校驗和與非校驗和值進行比較,因此看起來您總會遇到此「錯誤」,並且在運行算法的其餘部分後,它們似乎不會相同。此外,如果你期望D3作爲你的校驗和,但是收到了-551或0,那麼顯然你的校驗和算法中有一個錯誤。 – SnakeDoc