Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
SergejPr committed Oct 13, 2018
2 parents 5272efc + a2d35df commit 4f8bf64
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions NooLite_F/MTRF64/MTRF64USBAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def __repr__(self):

_LOGGER = logging.getLogger("MTRF64USBAdapter")
_LOGGER.setLevel(logging.WARNING)
_LOGGER.addHandler(logging.StreamHandler())
_LOGGER_HANDLER = logging.StreamHandler()
_LOGGER_HANDLER.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s", "%Y-%m-%d %H:%M:%S"))
_LOGGER.addHandler(_LOGGER_HANDLER)


class MTRF64USBAdapter(object):
Expand All @@ -113,6 +115,7 @@ class MTRF64USBAdapter(object):
_read_thread = None
_command_response_queue = Queue()
_incoming_queue = Queue()
_send_lock = Lock()
_listener_thread = None
_listener = None
_is_released = False
Expand Down Expand Up @@ -142,26 +145,25 @@ def send(self, data: OutgoingData) -> [IncomingData]:
responses = []

packet = self._build(data)
_LOGGER.debug("Send:\n - request: {0},\n - packet: {1}".format(data, packet))

with self._command_response_queue.mutex:
with self._send_lock:
_LOGGER.debug("Send:\n - request: {0},\n - packet: {1}".format(data, packet))
self._command_response_queue.queue.clear()
self._serial.write(packet)

try:
while True:
response = self._command_response_queue.get(timeout=2)
responses.append(response)
if response.count == 0:
break

except Empty as err:
_LOGGER.error("Error receiving response: {0}".format(err))

# For NooLite.TX we should make a bit delay. Adapter send the response without waiting until command was delivered.
# So if we send new command until previous command was sent to module, adapter will ignore new command. Note:
if data.mode == Mode.TX or data.mode == Mode.RX:
sleep(0.2)
self._serial.write(packet)

try:
while True:
response = self._command_response_queue.get(timeout=2)
responses.append(response)
if response.count == 0:
break

except Empty as err:
_LOGGER.error("Error receiving response: {0}.".format(err))

# For NooLite.TX we should make a bit delay. Adapter send the response without waiting until command was delivered.
# So if we send new command until previous command was sent to module, adapter will ignore new command. Note:
if data.mode == Mode.TX or data.mode == Mode.RX:
sleep(0.2)

return responses

Expand Down

0 comments on commit 4f8bf64

Please sign in to comment.