Skip to content

Commit

Permalink
Factor out processResponse() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Mar 29, 2018
1 parent 617430c commit 8d89ddf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
10 changes: 10 additions & 0 deletions pyxcp/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,13 @@ def closeConnection(self):
def listen(self):
pass

def processResponse(self, response):
if len(response) < self.HEADER_SIZE:
raise types.FrameSizeError("Frame too short.")
self.logger.debug("<- {}\n".format(hexDump(response)))
packetLen, self.counterReceived = struct.unpack(self.HEADER, response[ : 4])
xcpPDU = response[4 : ]
if len(xcpPDU) != packetLen:
raise types.FrameSizeError("Size mismatch.")
self.resQueue.put(xcpPDU)

9 changes: 1 addition & 8 deletions pyxcp/transport/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,7 @@ def listen(self):
except Exception as e:
self.logger.error(str(e))
continue
if len(response) < self.HEADER_SIZE:
raise types.FrameSizeError("Frame too short.")
self.logger.debug("<- {}\n".format(hexDump(response)))
packetLen, self.counterReceived = struct.unpack(Eth.HEADER, response[ : 4])
xcpPDU = response[4 : ]
if len(xcpPDU) != packetLen:
raise types.FrameSizeError("Size mismatch.")
self.resQueue.put(xcpPDU)
self.processResponse(response)

def send(self, frame):
self.sock.send(frame)
Expand Down
10 changes: 2 additions & 8 deletions pyxcp/transport/sxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,8 @@ def listen(self):
self.timing.stop()
response = rawLength + response

if len(response) < self.HEADER_SIZE:
raise types.FrameSizeError("Frame too short.")
self.logger.debug("<- {}\n".format(hexDump(response)))
packetLen, self.counterReceived = struct.unpack(SxI.HEADER, response[ : 4])
xcpPDU = response[4 : ]
if len(xcpPDU) != packetLen:
raise types.FrameSizeError("Size mismatch.")
self.resQueue.put(xcpPDU)
self.processResponse(response)


def send(self, frame):
self.port.write(frame)
Expand Down

0 comments on commit 8d89ddf

Please sign in to comment.