eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 7239e54166371a99dd81201b6e2462edd2277a6c
parent e6e7030ba6f7802f5362d43ea9d15a2d181dbb44
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 28 Jan 2026 01:06:20 +0000

rename client files

Diffstat:
Dandroid-termux-client/eculocate.py | 169-------------------------------------------------------------------------------
Randroid-termux-client/README.md -> client/README.md | 0
Aclient/android.py | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 125 insertions(+), 169 deletions(-)

diff --git a/android-termux-client/eculocate.py b/android-termux-client/eculocate.py @@ -1,169 +0,0 @@ -#!/data/data/com.termux/files/usr/bin/python - -import termuxgui as tg -import time -import sys -import socket -import threading -import select -import datetime -from pathlib import Path -import os -from zeroconf import ServiceBrowser, ServiceListener, Zeroconf - -peer_hostname = None -peer_thread = None -bytes_recorded = 0 - -started = False - - -hosts = {} -host_addresses = {} - -class ZListener(ServiceListener): - def __init__(self, activity, parent_widget): - self.activity = activity - self.parent_widget = parent_widget - - def update_service(self, zc: Zeroconf, type_: str, name: str) -> None: - print(f"Service {name} updated") - - def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: - hosts[name] = 0 - print(f"Service {name} removed") - - def add_service(self, zc: Zeroconf, type_: str, name: str) -> None: - info = zc.get_service_info(type_, name) - print(f"Service {name} added, service info: {info}") - hosts[name] = None - host_addresses[name] = (socket.inet_ntoa(info.addresses[0]), info.port) - - -zeroconf = Zeroconf() - - -def output_pathname(): - dir = Path("/storage") / "emulated" / "0" / "eculocate" - dir.mkdir(0o777, False, True) - name = f"{int(time.time())}.raw" - return dir / name - -def recording_thread_main(): - sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - addr = host_addresses[peer_hostname] - print(peer_hostname) - print(addr) - sock.connect(addr) - sock.setblocking(0) - interval = 500 - global bytes_recorded - bytes_recorded = 0 - - with open(output_pathname(), "wb") as outf: - while started: - print("sending subscribe") - b = bytes([interval >> 8, interval & 0xff, 0x54, 0x11, 0, 25] ) - sock.send(b) - timeout = time.time() + 60 - while started and time.time() < timeout: - ready = select.select([sock], [], [], timeout - time.time()) - if ready[0]: - data = sock.recv(4000) - bytes_recorded = bytes_recorded + len(data) - outf.write(data) - outf.flush() - sock.close() - print("recording thread terminated") - -def add_host(activity, name, parent): - selected = (peer_hostname == name) - if selected: - label = f"* {name}" - else: - label = name - button = tg.Button(activity, label, parent) - button.setlinearlayoutparams(0) - button.setheight(tg.View.WRAP_CONTENT) - hosts[name] = button - - -with tg.Connection() as c: - # create a new Activity. By default, a new Task as created. - a = tg.Activity(c) - - # you can find the Task under a.t - - def choose_hostname(hostname): - global peer_hostname - if hostname == None: - started = False - peer_hostname = hostname - refresh_buttons() - - def refresh_buttons(): - for name, widget in hosts.items(): - if name == peer_hostname: - label = f"* {name}" - else: - label = name - widget.settext(label) - if peer_hostname == None: - start_button.settext("----") - else: - start_button.settext("STOP" if started else "START") - - - def start_recording(start_or_stop): - global started - if start_or_stop and peer_hostname != None: - started = True - print("starting record") - peer_thread = threading.Thread(target=recording_thread_main, daemon = True) - peer_thread.start() - else: - print("stopping record") - started = False - - vertical = tg.LinearLayout(a) - instances = tg.LinearLayout(a, vertical) - browser = ServiceBrowser(zeroconf, "_keihin._udp.local.", ZListener(a, instances)) - - tg.Space(a, vertical) - - status = tg.TextView(a, "initializing", vertical) - - tg.Space(a, vertical) - - buttons = tg.LinearLayout(a, vertical, False) - - start_button = tg.Button(a, "(start)", buttons) - start_button.setlinearlayoutparams(0) - start_button.setheight(tg.View.WRAP_CONTENT) - # start_button.setwidth(tg.View.WRAP_CONTENT) - start_button.setgravity(1, 1) - - def update_byte_counter(): - global started - while True: - label = f"recorded {bytes_recorded} bytes" if started else "not recording" - status.settext(label) - time.sleep(1) - for host, button in hosts.items(): - if button == 0: - button.delete() - elif button == None: - add_host(a, host, instances) - - threading.Thread(target = update_byte_counter, daemon = True).start() - - for ev in c.events(): # waits for events from the gui - if ev.type == tg.Event.destroy: - sys.exit() - if ev.type == tg.Event.click: - for k, v in hosts.items(): - if v == ev.value["id"]: - choose_hostname(k) - if ev.value["id"] == start_button: - start_recording(not started) - refresh_buttons() diff --git a/android-termux-client/README.md b/client/README.md diff --git a/client/android.py b/client/android.py @@ -0,0 +1,125 @@ +#!/data/data/com.termux/files/usr/bin/python + +import termuxgui as tg +import time +import sys +import socket +import threading +import select +import datetime +from pathlib import Path +import os +from zeroconf import ServiceBrowser, ServiceListener, Zeroconf + +import eculocate + +peer_hostname = None +peer_thread = None +bytes_recorded = 0 + +started = False + + +hosts = {} +host_addresses = {} + +zeroconf = Zeroconf() + + +def output_pathname(): + dir = Path("/storage") / "emulated" / "0" / "eculocate" + dir.mkdir(0o777, False, True) + name = f"{int(time.time())}.raw" + return dir / name + +def add_host(activity, name, parent): + selected = (peer_hostname == name) + if selected: + label = f"* {name}" + else: + label = name + button = tg.Button(activity, label, parent) + button.setlinearlayoutparams(0) + button.setheight(tg.View.WRAP_CONTENT) + hosts[name] = button + + +with tg.Connection() as c: + # create a new Activity. By default, a new Task as created. + a = tg.Activity(c) + + # you can find the Task under a.t + + def choose_hostname(hostname): + global peer_hostname + if hostname == None: + started = False + peer_hostname = hostname + refresh_buttons() + + def refresh_buttons(): + for name, widget in hosts.items(): + if name == peer_hostname: + label = f"* {name}" + else: + label = name + widget.settext(label) + if peer_hostname == None: + start_button.settext("----") + else: + start_button.settext("STOP" if started else "START") + + + def start_recording(start_or_stop): + global started + if start_or_stop and peer_hostname != None: + started = True + print("starting record") + peer_thread = threading.Thread(eculocate.recorder, daemon = True) + peer_thread.start() + else: + print("stopping record") + started = False + + vertical = tg.LinearLayout(a) + instances = tg.LinearLayout(a, vertical) + browser = ServiceBrowser(zeroconf, "_keihin._udp.local.", ZListener(a, instances)) + + tg.Space(a, vertical) + + status = tg.TextView(a, "initializing", vertical) + + tg.Space(a, vertical) + + buttons = tg.LinearLayout(a, vertical, False) + + start_button = tg.Button(a, "(start)", buttons) + start_button.setlinearlayoutparams(0) + start_button.setheight(tg.View.WRAP_CONTENT) + # start_button.setwidth(tg.View.WRAP_CONTENT) + start_button.setgravity(1, 1) + + def update_byte_counter(): + global started + while True: + label = f"recorded {bytes_recorded} bytes" if started else "not recording" + status.settext(label) + time.sleep(1) + for host, button in hosts.items(): + if button == 0: + button.delete() + elif button == None: + add_host(a, host, instances) + + threading.Thread(target = update_byte_counter, daemon = True).start() + + for ev in c.events(): # waits for events from the gui + if ev.type == tg.Event.destroy: + sys.exit() + if ev.type == tg.Event.click: + for k, v in hosts.items(): + if v == ev.value["id"]: + choose_hostname(k) + if ev.value["id"] == start_button: + start_recording(not started) + refresh_buttons()