2014-12-06 91 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())