Skip to content

Commit

Permalink
Customizable community and ports
Browse files Browse the repository at this point in the history
  • Loading branch information
kennymc-c committed Nov 16, 2024
1 parent 5c84b0d commit 2fd9858
Showing 4 changed files with 48 additions and 193 deletions.
29 changes: 29 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=175

[MESSAGES CONTROL]

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once).You can also use "--disable=all" to
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"

disable=
global-statement,
too-many-instance-attributes,
too-many-arguments,
too-many-public-methods,
fixme # temporary

[STRING]

# This flag controls whether inconsistent-quotes generates a warning when the
# character used as a quote delimiter is used inconsistently within a module.
check-quote-consistency=yes
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ Python **3** library to query and control Sony Projectors using SDCP (PJ Talk) p
* Query lamp hours
* Query model name and serial number
* Show response error message from the projector
* Set a custom PJ Talk community & UDP advertisement SDAP port and TCP SDCP port

## Protocol Documentation

@@ -69,6 +70,12 @@ my_known_projector = pysdcp.Projector('10.1.2.3')
my_known_projector.set_HDMI_input(2)
```

You can also set a custom PJ Talk community and tcp/udp port. By default "SONY" will be used as the community and 53862 as udp port for SDAP advertisement and 53484 as tcp port for SDCP

```python
my_known_projector = pysdcp.Projector(ip='10.1.2.3', community="THEATER", udp_port=53860, tcp_port=53480)
```

### Commands from protocol.py

While you can use the build in functions like get_power() or set_HDMI_input() you can also directly send any command from protocol.py like this
184 changes: 0 additions & 184 deletions pysdcp/protocol.py

This file was deleted.

21 changes: 12 additions & 9 deletions pysdcp_extended/__init__.py
Original file line number Diff line number Diff line change
@@ -80,13 +80,16 @@ def decode_text_field(buf):


class Projector:
def __init__(self, ip: str = None):
def __init__(self, ip: str = None, community: str = "SONY", udp_port: int = 53862, tcp_port: int = 53484):
"""
Base class for projector communication.
Enables communication with Projector, Sending commands and Querying Power State
:param ip: str, IP address for projector. if given, will create a projector with default values to communicate
:param ip: str, IP address for projector. If given, will create a projector with default values to communicate
with projector on the given ip. i.e. "10.0.0.5"
:param community: str, PJ Talk Community for the projector. If not given "SONY" will be used
:param udp_port: int, SDAP Advertisement UDP port. If not given 53862 will be used
:param tcp_port: int, PJ Talk/SDCP TCP port. If not given 53484 will be used
"""
self.info = ProjInfo(
product_name=None,
@@ -103,13 +106,13 @@ def __init__(self, ip: str = None):
# Create projector from known ip
# Set default values to enable immediately communication with known project (ip)
self.ip = ip
self.header = Header(category=10, version=2, community="SONY")
self.header = Header(category=10, version=2, community=community)
self.is_init = True

# Default ports
self.UDP_IP = ""
self.UDP_PORT = 53862
self.TCP_PORT = 53484
self.UDP_PORT = udp_port
self.TCP_PORT = tcp_port
self.TCP_TIMEOUT = 2
self.UDP_TIMEOUT = 31

@@ -140,7 +143,7 @@ def _send_command(self, action, command, data=None, timeout=None):
raise Exception("Timeout while trying to send command {}".format(command)) from e

if len(my_buf) != sent:
raise ConnectionError(
raise ConnectionError(
"Failed sending entire buffer to projector. Sent {} out of {} !".format(sent, len(my_buf)))

#Check if command is an simulated ir command without a response from the projector and always return true to avoid a timeout
@@ -179,7 +182,7 @@ def find_projector(self, udp_ip: str = None, udp_port: int = None, timeout=None)
sock.settimeout(timeout)
try:
SDAP_buffer, addr = sock.recvfrom(1028)
except socket.timeout as e:
except socket.timeout:
return False

self.header, self.info = process_SDAP(SDAP_buffer)
@@ -201,8 +204,8 @@ def get_pjinfo(self, udp_ip: str = None, udp_port: int = None, timeout=None):
sock.settimeout(timeout)
try:
SDAP_buffer, addr = sock.recvfrom(1028)
except socket.timeout:
raise Exception("Timeout while waiting for data from projector")
except socket.timeout as e:
raise Exception("Timeout while waiting for data from projector") from e

serial = unpack('>I', SDAP_buffer[20:24])[0]
model = decode_text_field(SDAP_buffer[8:20])

0 comments on commit 2fd9858

Please sign in to comment.