Skip to content

Commit

Permalink
Add counterSend, counterReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Mar 22, 2018
1 parent ed90ce8 commit 902f783
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
25 changes: 22 additions & 3 deletions pyxcp/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,32 @@
from ..timing import Timing


class ConfigType:
"""Configuration base class.
JSON...
"""

def __init__(self):
pass

def __repr__(self):
"""
Returns
-------
dict: Descr.
"""


class BaseTransport(metaclass = abc.ABCMeta):

def __init__(self, config = {}, loglevel = 'WARN'):
def __init__(self, config = ConfigType(), loglevel = 'WARN'):
self.parent = None
self.closeEvent = threading.Event()
self.logger = Logger("transport.Base")
self.logger.setLevel(loglevel)
self.counter = 0
self.counterSend = 0
self.counterReceived = 0
self.timing = Timing()
self.resQueue = queue.Queue()
self.daqQueue = queue.Queue()
Expand All @@ -67,7 +85,8 @@ def finishListener(self):

def request(self, cmd, *data):
self.logger.debug(cmd.name)
header = struct.pack("<HH", len(data) + 1, self.counter)
header = struct.pack("<HH", len(data) + 1, self.counterSend)
self.counterSend += 1
frame = header + bytearray([cmd, *data])
self.logger.debug("-> {}".format(hexDump(frame)))
self.timing.start()
Expand Down
5 changes: 2 additions & 3 deletions pyxcp/transport/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""

import queue
import selectors
import socket
import struct
Expand Down Expand Up @@ -61,7 +60,7 @@ def listen(self):
if self.closeEvent.isSet() or self.sock.fileno() == -1:
return
sel = self.selector.select(0.1)
for key, events in sel:
for _, events in sel:
if events & selectors.EVENT_READ:
if self.connected:
length = struct.unpack("<H", self.sock.recv(2))[0]
Expand All @@ -79,7 +78,7 @@ def listen(self):
if len(response) < self.HEADER_SIZE:
raise types.FrameSizeError("Frame too short.")
self.logger.debug("<- {}\n".format(hexDump(response)))
packetLen, seqNo = struct.unpack(Eth.HEADER, response[ : 4])
packetLen, self.counterReceived = struct.unpack(Eth.HEADER, response[ : 4])
xcpPDU = response[4 : ]
if len(xcpPDU) != packetLen:
raise types.FrameSizeError("Size mismatch.")
Expand Down
2 changes: 1 addition & 1 deletion pyxcp/transport/sxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def listen(self):
if len(response) < self.HEADER_SIZE:
raise types.FrameSizeError("Frame too short.")
self.logger.debug("<- {}\n".format(hexDump(response)))
packetLen, seqNo = struct.unpack(SxI.HEADER, response[ : 4])
packetLen, self.counterReceived = struct.unpack(SxI.HEADER, response[ : 4])
xcpPDU = response[4 : ]
if len(xcpPDU) != packetLen:
raise types.FrameSizeError("Size mismatch.")
Expand Down

0 comments on commit 902f783

Please sign in to comment.