从Borland C转换为python

时间:2014-12-06 12:27:28

标签: python c

请将Borland C源代码转换为Python时需要帮助。我非常感谢任何帮助或建议的转换工具..我想要转换的代码如下(这些是我希望进入我的Raspberry Pi的脉搏血氧仪的串行通信参数)

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 个答案:

答案 0 :(得分:1)

假设您已经拥有适用于Python的getccb()函数,那么翻译非常简单:

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())