32 lines
No EOL
908 B
Python
32 lines
No EOL
908 B
Python
# Copyright (C) 2024 Minecon724
|
|
# Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
|
# in the project root for the full license text.
|
|
|
|
import socket, struct
|
|
|
|
ENDPOINT = ("127.0.0.1", 57931)
|
|
|
|
def get_power(repeater_id: int) -> int | None:
|
|
message = repeater_id & 0x7FFFFFF0
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
sock.sendto(message.to_bytes(4), ENDPOINT)
|
|
|
|
return struct.unpack(">b", sock.recvfrom(1)[0])[0]
|
|
|
|
def set_power(repeater_id: int, power: int):
|
|
message = repeater_id & 0x7FFFFFF0
|
|
message |= 0x80000000
|
|
message |= power & 0xF
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
sock.sendto(message.to_bytes(4), ENDPOINT)
|
|
|
|
repeater_id = 235459920
|
|
|
|
print("Reading from repeater")
|
|
power = get_power(repeater_id)
|
|
print("Read power:", power)
|
|
|
|
print("Powering repeater with power 10")
|
|
set_power(repeater_id, 10) |