def main():
    #res = dissectResponse(INFO_RESP)
    print dumpHex(apdu.createGetInfoAPDU(defs.ADPUClass.MEASURERED_DATA, infoReqValues))
    res = dissectResponse(DATA_RESP)
    print hex(checkCrc(DATA_REQ)), hex(checkCrc(DATA_RESP))
    res = dissectResponse(CONF_RESP)
    print res
Exemple #2
0
    crc = calcuteCrc(pdu)
    pdu.extend(bytes(crc))

    arr = array.array('B', pdu)
    # TODO: arr.tostring() for I/O!
    return arr



def createConnectRequestPDU(sourceAddr):
    return createGetValuesPDU(
        Header(defs.SD_DATA_REQUEST, defs.CONNECTION_REQ_ADDR, sourceAddr),
        measurements =  ['unit_family', 'unit_type'],
        protocolData =  ['df_buf_len',  'unit_bus_mode'],
        parameter =     ['unit_addr',   'group_addr']
    )


if __name__ == '__main__':
    print dumpHex(createConnectRequestPDU(0x01))

    print dumpHex(createSetCommandsPDU(Header(defs.SD_DATA_REQUEST, 0x20, 0x04), ['REMOTE', 'START']))

    print dumpHex(createSetValuesPDU(Header(defs.SD_DATA_REQUEST, 0x20, 0x04), references = [('ref_rem', 0xa5, )]))

    print dumpHex(createGetInfoPDU(
        Header(defs.SD_DATA_REQUEST, 0x20, 0x04),
        measurements = ['h', 'q', 'p', 'speed', 'energy_hi'])
    )
        Item("unit_addr", 0x20, None),
        Item("group_addr", 0xf7, None),
    },
    defs.ADPUClass.REFERENCE_VALUES: {},
    defs.ADPUClass.ASCII_STRINGS: {},
}

class TestDataPool(unittest.TestCase):
    def testCorrectnessOfKeys(self):
        for klass, values in DATA_POOL.items():
            di = dataitems.DATAITEMS_FOR_CLASS[klass]
            for value in values:
                if not value.name in di:
                    raise KeyError('invalid datapoint "%s"' % value.name)


print dumpHex(apdu.createGetMeasuredDataAPDU(dataReqValues))

def main():
    #res = dissectResponse(INFO_RESP)
    print dumpHex(apdu.createGetInfoAPDU(defs.ADPUClass.MEASURERED_DATA, infoReqValues))
    res = dissectResponse(DATA_RESP)
    print hex(checkCrc(DATA_REQ)), hex(checkCrc(DATA_RESP))
    res = dissectResponse(CONF_RESP)
    print res

if __name__ == '__main__':
    main()
    unittest.main()