2016-10-09 63 views
2

剛剛完成一個新的衛星數據處理中心,並準備好使用從軌道衛星發送的實時數據進行初始測試。由於屏幕上顯示了第一條消息,並且您注意到許多數據值超出範圍。
例如,在終端屏幕上定義爲「增量時間」,它似乎超出了預期的範圍[0.01到10,000.00秒],但顯示的值(作爲雙精度)是[-4.12318024e- 028秒]。在對基於原始字節的數據流進行進一步調查之後,您會發現從該衛星發送的此雙字的原始數據爲[0xC0 0x83 0xA1 0xCA 0x66 0x55 0x40 0xBA]。在其中一箇舊的終端上,該數據顯示正確並在預期範圍內。衛星數據處理錯誤

a. [5] What caused this problem? 
b. [5] If this is the real problem, what should the actual value be? 

回答

0

啊,失效模式分析。確實非常重要!

那麼,其他終端正確顯示數據 - >終端和數據存在不兼容。

Big Endian,little endian也許?我期待「舊」終端是小端,因爲它可能已經用C編碼了。現在你可以解釋數據了。

下面是一些代碼

#include <stdio.h> 

union myW { 
    double x; 
    // Recieved as:[0xC0 0x83 0xA1 0xCA 0x66 0x55 0x40 0xBA] 
    unsigned char d[8] = {0x83, 0xC0,0xCA, 0xA1, 0x55, 0x66, 0xBA, 0x40}; 
}; 

union myBad { 
    double x; 
    // Recieved as:[0xC0 0x83 0xA1 0xCA 0x66 0x55 0x40 0xBA] 
    unsigned char d[8] = {0xC0, 0x83,0xA1, 0xCA, 0x66, 0x55, 0x40, 0xBA}; 
}; 


int main(void) 
{ 
    myW value; 
    value.x = 1.0; // check how reasonable number looks like 

    printf("Something reasonable: \n"); 
    for(int i = 0; i < 8; i++) 
    { 
     printf("%u ", value.d[i]); 
    } 

    myW received; 
    printf("\nWhat shouldve been displayed:\n"); 
    for(int i = 0; i < 8; i++) 
    { 
     printf("%u ", received.d[i]); 
    } 
    printf("\n%f\n", received.x); 

    myBad bad; 
    printf("\nBad output as:\n"); 
    for(int i = 0; i < 8; i++) 
    { 
     printf("%u ", bad.d[i]); 
    } 
    printf("\n%0.30f\n", bad.x); 
} 

輸出:

Something reasonable: 
0 0 0 0 0 0 240 63 
What shouldve been displayed:: 
131 192 202 161 85 102 186 64 
6758.334500 

Bad output as: 
192 131 161 202 102 85 64 186 
-0.000000000000000000000000000412 

編譯時的g ++

+0

我試圖反向字節+反向位+ XOR 0x80的,並且結果是'2.39' ..但是......你不這麼認爲,因爲這是一個問題,結果可能是更加「圓潤」的東西,比如'20.0'或者一些了不起的東西,比如'3.14159' ... –

+0

你爲什麼這麼期待?因爲這是一個「學術」問題?它在預期範圍內! [0.01至10,000.00秒] – Makketronix