mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
add uxplay-beacon.py for windows
This commit is contained in:
@@ -5,7 +5,7 @@ uxplay-beacon.py \- Python (>= 3.6) script for a Bluetooth LE Service-Discovery
|
||||
.B uxplay-beacon.py
|
||||
[\fI\, -h, --help] + more options.
|
||||
.SH DESCRIPTION
|
||||
UxPlay 1.72: Standalone Python Script for managing Bluetooth LE Service Discovery.
|
||||
UxPlay 1.72: Standalone Python Script for Bluetooth LE Service Discovery (DBus).
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B
|
||||
@@ -8,8 +8,8 @@
|
||||
import gi
|
||||
try:
|
||||
from gi.repository import GLib
|
||||
except ImportError:
|
||||
print(f"ImportError: failed to import GLib")
|
||||
except ImportError as e:
|
||||
print(f"ImportError: {e}, failed to import GLib")
|
||||
|
||||
|
||||
import dbus
|
||||
@@ -196,6 +196,7 @@ import sys
|
||||
import psutil
|
||||
import struct
|
||||
import socket
|
||||
import time
|
||||
|
||||
# global variables
|
||||
beacon_is_running = False
|
||||
@@ -222,7 +223,10 @@ def stop_beacon():
|
||||
global beacon_is_running
|
||||
beacon_off()
|
||||
beacon_is_running = False
|
||||
|
||||
|
||||
def pid_is_running(pid):
|
||||
return psutil.pid_exists(pid)
|
||||
|
||||
def check_process_name(pid, pname):
|
||||
try:
|
||||
process = psutil.Process(pid)
|
||||
@@ -260,10 +264,13 @@ def check_file_exists(file_path):
|
||||
port = struct.unpack('<H', data)[0]
|
||||
data = file.read(4)
|
||||
pid = struct.unpack('<I', data)[0]
|
||||
data = file.read()
|
||||
pname = data.split(b'\0',1)[0].decode('utf-8')
|
||||
last_element_of_pname = os.path.basename(pname)
|
||||
test = check_process_name(pid, last_element_of_pname)
|
||||
if not pid_is_running(pid):
|
||||
test = False
|
||||
else :
|
||||
data = file.read()
|
||||
pname = data.split(b'\0',1)[0].decode('utf-8')
|
||||
last_element_of_pname = os.path.basename(pname)
|
||||
test = check_process_name(pid, last_element_of_pname)
|
||||
if test == True:
|
||||
if not beacon_is_running:
|
||||
beacon_is_pending_on = True
|
||||
@@ -294,7 +301,6 @@ def process_input(value):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
#check AdvInterval
|
||||
def check_adv_intrvl(min, max):
|
||||
if not (100 <= min):
|
||||
@@ -323,8 +329,8 @@ def main(file_path, ipv4_str_in, advmin_in, advmax_in, index_in):
|
||||
print(f'Error: {e}')
|
||||
raise SystemExit(1)
|
||||
|
||||
GLib.timeout_add_seconds(5, on_timeout, file_path)
|
||||
GLib.timeout_add_seconds(1, check_pending)
|
||||
GLib.timeout_add_seconds(1, on_timeout, file_path)
|
||||
GLib.timeout_add(200, check_pending)
|
||||
mainloop = GLib.MainLoop()
|
||||
mainloop.run()
|
||||
except KeyboardInterrupt:
|
||||
|
||||
39
Bluetooth_LE_beacon/winrt/uxplay-beacon.1
Normal file
39
Bluetooth_LE_beacon/winrt/uxplay-beacon.1
Normal file
@@ -0,0 +1,39 @@
|
||||
.TH UXPLAY 1 2025-10-26 "UxPlay 1.72" "User Commands"
|
||||
.SH NAME
|
||||
uxplay-beacon.py \- Python (>= 3.6) script for a Bluetooth LE Service-Discovery beacon.
|
||||
.SH SYNOPSIS
|
||||
.B uxplay-beacon.py
|
||||
[\fI\, -h, --help] + more options.
|
||||
.SH DESCRIPTION
|
||||
UxPlay 1.72: Standalone Python Script for Bluetooth LE Service Discovery (Windows).
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B
|
||||
\fB\--file\fR fn Specify alternate configuration file
|
||||
.TP
|
||||
\fB\--path\fR fn Specify non-default Bluetooth LE data file used by uxplay
|
||||
.TP
|
||||
\fB\--ipv4\fR ip Override automatically-obtained ipv4 address for contacting UxPlay
|
||||
.TP
|
||||
\fB \-h, --help\fR Show help text.
|
||||
.SH
|
||||
FILES
|
||||
Options in beacon configuration file ~/.uxplay.beacon
|
||||
.TP
|
||||
are applied first (command-line options may modify them). Format:
|
||||
.TP
|
||||
one option per line, with initial "--"; lines beginning with "#" ignored.
|
||||
.SH
|
||||
AUTHORS
|
||||
.TP
|
||||
Various, see website or distribution.
|
||||
.SH
|
||||
COPYRIGHT
|
||||
.TP
|
||||
Various, see website or distribution. License: GPL v3+:
|
||||
.TP
|
||||
GNU GPL version 3 or later. (some parts LGPL v.2.1+ or MIT).
|
||||
.SH
|
||||
SEE ALSO
|
||||
.TP
|
||||
Website: <https://github.com/FDH2/UxPlay>
|
||||
@@ -38,8 +38,10 @@ import asyncio
|
||||
publisher = None
|
||||
|
||||
def on_status_changed(sender, args):
|
||||
global publisher
|
||||
print(f"Publisher status change to: {args.status.name}")
|
||||
|
||||
if args.status.name == "STOPPED":
|
||||
publisher = None
|
||||
|
||||
def create_airplay_service_discovery_advertisement_publisher(ipv4_str, port):
|
||||
assert port > 0
|
||||
@@ -73,7 +75,7 @@ async def publish_advertisement():
|
||||
|
||||
def setup_beacon(ipv4_str, port):
|
||||
#index will be ignored
|
||||
print(f"setup_beacon port {ipv4_str}:{port}")
|
||||
print(f"setup_beacon for {ipv4_str}:{port}")
|
||||
create_airplay_service_discovery_advertisement_publisher(ipv4_str, port)
|
||||
|
||||
def beacon_on():
|
||||
@@ -89,8 +91,6 @@ def beacon_on():
|
||||
def beacon_off():
|
||||
global publisher
|
||||
publisher.stop()
|
||||
print(f"Current Publisher Status: {publisher.status.name}")
|
||||
publisher = None
|
||||
|
||||
#==generic code (non-winrt) below here =============
|
||||
|
||||
@@ -100,6 +100,7 @@ import sys
|
||||
import psutil
|
||||
import struct
|
||||
import socket
|
||||
import time
|
||||
|
||||
# global variables
|
||||
beacon_is_running = False
|
||||
@@ -121,6 +122,9 @@ def stop_beacon():
|
||||
beacon_off()
|
||||
beacon_is_running = False
|
||||
|
||||
def pid_is_running(pid):
|
||||
return psutil.pid_exists(pid)
|
||||
|
||||
def check_process_name(pid, pname):
|
||||
try:
|
||||
process = psutil.Process(pid)
|
||||
@@ -158,10 +162,13 @@ def check_file_exists(file_path):
|
||||
port = struct.unpack('<H', data)[0]
|
||||
data = file.read(4)
|
||||
pid = struct.unpack('<I', data)[0]
|
||||
data = file.read()
|
||||
pname = data.split(b'\0',1)[0].decode('utf-8')
|
||||
last_element_of_pname = os.path.basename(pname)
|
||||
test = check_process_name(pid, last_element_of_pname)
|
||||
if not pid_is_running(pid):
|
||||
test = False
|
||||
else:
|
||||
data = file.read()
|
||||
pname = data.split(b'\0',1)[0].decode('utf-8')
|
||||
last_element_of_pname = os.path.basename(pname)
|
||||
test = check_process_name(pid, last_element_of_pname)
|
||||
if test == True:
|
||||
if not beacon_is_running:
|
||||
beacon_is_pending_on = True
|
||||
@@ -185,8 +192,8 @@ def main(file_path, ipv4_str_in):
|
||||
|
||||
try:
|
||||
while True:
|
||||
GLib.timeout_add_seconds(2, on_timeout, file_path)
|
||||
GLib.timeout_add_seconds(1, check_pending)
|
||||
GLib.timeout_add_seconds(1, on_timeout, file_path)
|
||||
GLib.timeout_add(200, check_pending)
|
||||
mainloop = GLib.MainLoop()
|
||||
mainloop.run()
|
||||
except KeyboardInterrupt:
|
||||
@@ -194,7 +201,6 @@ def main(file_path, ipv4_str_in):
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not sys.version_info >= (3,6):
|
||||
print("uxplay-beacon.py requires Python 3.6 or higher")
|
||||
|
||||
@@ -78,10 +78,18 @@ install( FILES uxplay.service DESTINATION ${CMAKE_INSTALL_DOCDIR}/systemd )
|
||||
if (DBUS_FOUND)
|
||||
install( FILES Bluetooth_LE_beacon/dbus/uxplay-beacon.py
|
||||
DESTINATION bin
|
||||
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
|
||||
install( FILES uxplay-beacon.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
|
||||
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
|
||||
install( FILES Bluetooth_LE_beacon/dbus/uxplay-beacon.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
install( FILES Bluetooth_LE_beacon/winrt/uxplay-beacon.py
|
||||
DESTINATION bin
|
||||
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
|
||||
install( FILES Bluetooth_LE_beacon/winrt/uxplay-beacon.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# uninstall target
|
||||
if(NOT TARGET uninstall)
|
||||
|
||||
Reference in New Issue
Block a user