converting from Borland C to python

94 views Asked by At

Please I need helpin converting a Borland C source code into Python. I be very grateful for any help or proposed conversion tool..The code I want to convert is the following (these are serialcommunication parameters of a pulse oximeter i wish to enter into my 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

There are 1 answers

0
Tim Pietzcker On

Assuming that you already have a getccb() function that works in Python, the translation is pretty straightforward:

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