def parse_ascii(self, string):
        self.error_crc = True
        self.error_format = True

        #
        #   Check CRC
        #
        data = check_strip_crc( string )
        if data == None:
            print 'ERROR: CRC error'
            return
        self.error_crc = False
        
        #
        #   Check format
        #
        data = split_string( data )
        if data[0][0] != 'APWR':
            print 'ERROR: Format error'
            return

        if len(data[1]) == 8 and \
                len(data[2]) == 4 and \
                len(data[3]) == 3 and \
                len(data[4]) == 3 and \
                len(data[5]) == 4 and \
                len(data[6]) == 1:
            pass
        else:
            print 'ERROR: Format Error 2'
            return
        self.error_format = False

        #
        #   Fill data
        #
        try:
            self.relay_A_req   = data[1][0] != '_'
            self.relay_A_state = data[1][1] != '_'
            self.relay_B_req   = data[1][2] != '_'
            self.relay_B_state = data[1][3] != '_'
            self.relay_C_req   = data[1][4] != '_'
            self.relay_C_state = data[1][5] != '_'
            self.relay_D_req   = data[1][6] != '_'
            self.relay_D_state = data[1][7] != '_'
        
            self.regulator_A_req   = data[2][0] != '_'
            self.regulator_A_state = data[2][1] != '_'
            self.regulator_B_req   = data[2][2] != '_'
            self.regulator_B_state = data[2][3] != '_'
        
            self.vbatt_error = data[3][0] != '_'
            self.regA_error  = data[3][1] != '_'
            self.regB_error  = data[3][2] != '_'

            self.comms_crc_error = data[4][0] != '_'
            self.comms_format_error = data[4][1] != '_'
            self.comms_param_error = data[4][2] != '_'

            self.track_left = int(data[5][0])
            self.track_right = int(data[5][1])
            self.turrent_yaw = int(data[5][2])
            self.turrent_pitch = int(data[5][3])

            #self.regA_voltage  = float(data[6][0]) / 1000
            #self.regB_voltage  = float(data[6][1]) / 1000
            self.vbatt_voltage = float(data[6][0]) / 1000
        except:
            print 'ERROR: Format error 3'
            self.error_format = True
def parse_power( string ):
    ps = PowerStatus()
    ps.error_crc = True
    ps.error_format = True
    ps.error_timeout = True

    #
    #   Check CRC
    #
    data = check_strip_crc( string )
    if data == None:
        print 'ERROR: CRC error'
        return ps
    ps.error_crc = False

    #
    #   Check format
    #
    data = split_string( data )
    if data[0][0] != 'APWR':
        print 'ERROR: Format error'
        return ps

    if len(data[1]) == 8 and \
            len(data[2]) == 4 and \
            len(data[3]) == 3 and \
            len(data[4]) == 2 and \
            len(data[5]) == 3:
        pass
    else:
        print 'ERROR: Format Error 2'
        return ps
    ps.error_format = False

    #
    #   Fill data
    #
    ps.relay_A_req   = data[1][0] != '_'
    ps.relay_A_state = data[1][1] != '_'
    ps.relay_B_req   = data[1][2] != '_'
    ps.relay_B_state = data[1][3] != '_'
    ps.relay_C_req   = data[1][4] != '_'
    ps.relay_C_state = data[1][5] != '_'
    ps.relay_D_req   = data[1][6] != '_'
    ps.relay_D_state = data[1][7] != '_'
        
    ps.regulator_A_req   = data[2][0] != '_'
    ps.regulator_A_state = data[2][1] != '_'
    ps.regulator_B_req   = data[2][2] != '_'
    ps.regulator_B_state = data[2][3] != '_'
        
    ps.vbatt_error = data[3][0] != '_'
    ps.regA_error  = data[3][1] != '_'
    ps.regB_error  = data[3][2] != '_'

    ps.comms_crc_error = data[4][0] != '_'
    ps.comms_format_error = data[4][0] != '_'
        
    ps.regA_voltage  = float(data[5][0]) / 1000
    ps.regB_voltage  = float(data[5][1]) / 1000
    ps.vbatt_voltage = float(data[5][2]) / 1000

    return ps