Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Hundemeier/sacn
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas committed Apr 26, 2020
2 parents dfc1c9b + 30e5ad0 commit dd9053a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sacn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from sacn.messages.universe_discovery import UniverseDiscoveryPacket

import logging
logging.getLogger(__name__).addHandler(logging.NullHandler())
logging.getLogger('sacn').addHandler(logging.NullHandler())
9 changes: 5 additions & 4 deletions sacn/receiving/receiver_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def __init__(self, socket, callbacks: Dict[any, list]):
self.lastDataTimestamps: dict = {}
# store the last sequence number of a universe here:
self.lastSequence: dict = {}
self.logger = logging.getLogger('sacn')
super().__init__(name='sACN input/receiver thread')

def run(self):
logging.info(f'Started new sACN receiver thread')
self.logger.info(f'Started new sACN receiver thread')
self.socket.settimeout(0.1) # timeout as 100ms
self.enabled_flag = True
while self.enabled_flag:
Expand All @@ -49,7 +50,7 @@ def run(self):
tmp_packet = DataPacket.make_data_packet(raw_data)
except: # try to make a DataPacket. If it fails just go over it
continue
logging.debug(f'Received sACN packet:\n{tmp_packet}')
self.logger.debug(f'Received sACN packet:\n{tmp_packet}')

self.check_for_stream_terminated_and_refresh_timestamp(tmp_packet)
self.refresh_priorities(tmp_packet)
Expand All @@ -58,7 +59,7 @@ def run(self):
if not self.is_legal_sequence(tmp_packet): # check for bad sequence number
continue
self.fire_callbacks_universe(tmp_packet)
logging.info('Stopped sACN receiver thread')
self.logger.info('Stopped sACN receiver thread')

def check_for_timeouts(self) -> None:
# check all DataTimestamps for timeouts
Expand Down Expand Up @@ -145,7 +146,7 @@ def fire_callbacks_universe(self, packet: DataPacket) -> None:
if packet.universe not in self.previousData.keys() or \
self.previousData[packet.universe] is None or \
self.previousData[packet.universe] != packet.dmxData:
logging.debug('')
self.logger.debug('')
# set previous data and inherit callbacks
self.previousData[packet.universe] = packet.dmxData
for callback in self.callbacks[packet.universe]:
Expand Down
16 changes: 10 additions & 6 deletions sacn/sending/output_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def __init__(self, cid: tuple, source_name: str, outputs: dict, bind_address,
self._socket: socket.socket = None
self.universeDiscovery: bool = universe_discovery
self.manual_flush: bool = False
self.logger = logging.getLogger('sacn')

def run(self):
logging.info('Started sACN sender thread.')
self.logger.info('Started sACN sender thread.')
self._socket = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
try:
Expand All @@ -41,9 +42,9 @@ def run(self):

try:
self._socket.bind((self._bindAddress, self._bind_port))
logging.info(f'Bind sender thread to IP:{self._bindAddress} Port:{self._bind_port}')
self.logger.info(f'Bind sender thread to IP:{self._bindAddress} Port:{self._bind_port}')
except:
logging.exception(f'Could not bind to IP:{self._bindAddress} Port:{self._bind_port}')
self.logger.exception(f'Could not bind to IP:{self._bindAddress} Port:{self._bind_port}')

last_time_uni_discover = 0
self.enabled_flag = True
Expand All @@ -70,7 +71,7 @@ def run(self):
time.sleep(time_to_sleep)
# this sleeps nearly exactly so long that the loop is called every 1/fps seconds
self._socket.close()
logging.info('Stopped sACN sender thread')
self.logger.info('Stopped sACN sender thread')

def send_out(self, output: Output):
# 1st: Destination (check if multicast)
Expand All @@ -97,8 +98,11 @@ def send_uni_discover_packets(self): # hint: on windows a bind address must be

def send_packet(self, packet, destination: str):
MESSAGE = bytearray(packet.getBytes())
self._socket.sendto(MESSAGE, (destination, DEFAULT_PORT))
logging.debug(f'Send out Packet to {destination}:{DEFAULT_PORT} with following content:\n{packet}')
try:
self._socket.sendto(MESSAGE, (destination, DEFAULT_PORT))
self.logger.debug(f'Send out Packet to {destination}:{DEFAULT_PORT} with following content:\n{packet}')
except OSError as e:
self.logger.warning('Failed to send packet', exc_info=e)

def send_out_all_universes(self):
"""
Expand Down

0 comments on commit dd9053a

Please sign in to comment.