2014-12-06 89 views
-3

請幫助我將Borland C源代碼轉換爲Python。我對任何幫助或建議轉換tool..The代碼我想轉換非常感謝如下(這些都是脈搏血氧儀的serialcommunication參數我想進入我的樹莓派)從Borland C轉換爲python

void decode_data(void) 

    { 
    while (!((val = getccb()) & 0x80)); /* wait for sync bit */ 
    if (val & 0x40) 
     printf(「!Puls!」); /* puls trigger active */ 
    y = getccb(); /* get plethysmogram sample */ 
    val = getccb(); /* get pulse bar sample */ 
    puls_hbit = (val & 0x80)?1:0; /* store bit 7 of pulse */ 
    bar_graph = val & 0x0F; /* store bar_graph value */ 
    printf(「Puls %03u」,0x80*puls_hbit + getccb()); 
             /* print pulse */ 
    printf(「SpO2 %03u」,getccb()); /* print spo2 */ 
    } 

/* getccb() returns the next serial value from a queue that gets filled during the PC´s serial interrupt */ 
+1

這段代碼也不是很長,我不認爲你需要一個特殊的工具。 – rlms 2014-12-06 12:48:53

回答

1

假設你已經有一個getccb()功能在Python的作品,翻譯是非常簡單的:

def decode_data(): 
    while True: 
     val = getccb() 
     if val & 0x80: 
      break 
    if val & 0x40: 
     print "!Puls!" 
    y = getccb() # What's that line for? You never use y again. 
    val = getccb() # Really? getccb() returns different kinds of values each time? 
    puls_hbit = 1 if cal & 0x80 else 0 
    bar_graph = val & 0x0F # What's that line for? You never use bar_graph again... 
    print "Puls {:3}".format(0x80*puls_hbit + getccb()) 
    print "SpO2 {:3}".format(getccb())