link: add CRC check to BFM

This commit is contained in:
Florent Kermarrec 2014-12-02 20:02:43 +01:00
parent f2757ef8dd
commit ed97f378ff
1 changed files with 12 additions and 2 deletions

View File

@ -102,7 +102,17 @@ class BFM(Module):
return p return p
def check_crc(self, packet): def check_crc(self, packet):
# Todo from C Code or Python Code stdin = ""
for v in packet[:-1]:
stdin += "0x%08x " %v
stdin += "exit"
with subprocess.Popen("./crc", stdin=subprocess.PIPE, stdout=subprocess.PIPE) as process:
process.stdin.write(stdin.encode("ASCII"))
out, err = process.communicate()
crc = int(out.decode("ASCII"), 16)
if packet[-1] != crc:
return []
else:
return packet[:-1] return packet[:-1]
def packet_callback(self, packet): def packet_callback(self, packet):