예제 #1
0
def getFn(msg, field):
    loc = msgName(msg) + ".MSG_OFFSET + " + str(MsgParser.fieldLocation(field))
    type = "'" + fieldType(field) + "'"
    count = MsgParser.fieldCount(field)
    cleanup = ""
    preface = ""
    if "Enum" in field:
        # find index that corresponds to string input param
        cleanup = reverseEnumLookup(msg, field)
    if count > 1:
        if MsgParser.fieldUnits(field) == "ASCII" and (
                field["Type"] == "uint8" or field["Type"] == "int8"):
            preface += "\n    count = " + str(count) + "\n"
            preface += "    if count > len(self.rawBuffer())-(" + loc + "):\n"
            preface += "        count = len(self.rawBuffer())-(" + loc + ")\n"
            type = "str(count)+'s'"
            count = 1
            cleanup = '''ascii_len = str(value).find("\\\\x00")
    value = str(value)[2:ascii_len]
    '''
        else:
            loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field))
    if "Offset" in field or "Scale" in field:
        cleanup = "value = " + MsgParser.getMath("value", field, "") + "\n    "
    ret = '''\
%s%s
    value = struct.unpack_from(%s, self.rawBuffer(), %s)[0]
    %sreturn value
''' % (fnHdr(field, MsgParser.fieldLocation(field), count,
             "Get" + field["Name"]), preface, type, loc, cleanup)
    return ret
예제 #2
0
def getFn(msg, field):
    loc = msgName(msg) + ".MSG_OFFSET + " + str(MsgParser.fieldLocation(field))
    type = "'"+fieldType(field)+"'"
    count = MsgParser.fieldCount(field)
    cleanup = ""
    preface = ""
    if "Enum" in field:
        # find index that corresponds to string input param
        cleanup = reverseEnumLookup(msg, field)
    if  count > 1:
        if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"):
            preface += "\n    count = " + str(count)+"\n"
            preface += "    if count > len(self.rawBuffer())-("+loc+"):\n"
            preface += "        count = len(self.rawBuffer())-("+loc+")\n"
            type = "str(count)+'s'"
            count = 1
            cleanup = '''ascii_len = str(value).find("\\\\x00")
    value = str(value)[2:ascii_len]
    ''' 
        else:
            loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field))
    if "Offset" in field or "Scale" in field:
        cleanup = "value = " + MsgParser.getMath("value", field, "")+"\n    "
    ret = '''\
%s%s
    value = struct.unpack_from(%s, self.rawBuffer(), %s)[0]
    %sreturn value
''' % (fnHdr(field,MsgParser.fieldLocation(field),count, "Get"+field["Name"]), preface, type, loc, cleanup)
    return ret
예제 #3
0
def getBitsFn(msg, field, bits, bitOffset, numBits):
    access = "(self.Get%s() >> %s) & %s" % (field["Name"], str(bitOffset), MsgParser.Mask(numBits))
    access = MsgParser.getMath(access, bits, "float")
    cleanup = ""
    if "Enum" in bits:
        # find index that corresponds to string input param
        cleanup = reverseEnumLookup(msg, bits)
    ret  = '''\
%s
    value = %s
    %sreturn value
''' % (fnHdr(bits,MsgParser.fieldLocation(field),1,"Get"+MsgParser.BitfieldName(field, bits)), access, cleanup)
    return ret
예제 #4
0
def getBitsFn(msg, field, bits, offset, bitOffset, numBits):
    access = "(self.Get%s() >> %s) & %s" % (field["Name"], str(bitOffset), MsgParser.Mask(numBits))
    access = MsgParser.getMath(access, bits, "float")
    cleanup = ""
    if "Enum" in bits:
        # find index that corresponds to string input param
        cleanup = reverseEnumLookup(msg, bits)
    ret  = '''\
%s
    value = %s
    %sreturn value
''' % (fnHdr(bits,offset,1,"Get"+MsgParser.BitfieldName(field, bits)), access, cleanup)
    return ret