Created
May 19, 2022 06:36
-
-
Save zeroping/8a4db13974969424b28a2d322cba9fc8 to your computer and use it in GitHub Desktop.
A tool for setting the time of some Tascam wifi-enabled audio recorders.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import socket | |
import time | |
import sys | |
import coloredlogs | |
import logging | |
import datetime | |
global logger | |
def setupLogging(namein, levelString='WARN'): | |
#logger = logging.getLogger(__name__) | |
logger = logging.getLogger(namein) | |
coloredlogs.install(level=levelString, logger=logger) | |
logger.setLevel(levelString) | |
return logger | |
logger = setupLogging("seg", "INFO") | |
logger.info(f"Starting tascam time setting tool") | |
def findRecorders(): | |
recorderList = [] | |
# ask recorders to ping | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) as sendsock: | |
message = b'DRPING' | |
try: | |
sendsock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
logger.debug('sending ping request') | |
sendsock.sendto(message, ("255.255.255.255", 62481)) | |
except: | |
logger.error(f'failed to get UDP port?' ) | |
# now listen for responses on UDP | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) as rxsocket: | |
server_address = ('', 62482) | |
logger.info(f'listening for pings on port {server_address[1]}') | |
rxsocket.bind(server_address) | |
rxsocket.settimeout(3) | |
logger.debug('waiting to receive message') | |
try: | |
while True: | |
data, address = rxsocket.recvfrom(4096) | |
logger.debug(f'received {data} bytes from {address}') | |
textdata = data.decode('UTF-8') | |
splitted = textdata.split('\t') | |
recorderList.append(splitted) | |
except TimeoutError: | |
logger.debug(f'ping timeout' ) | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) as sendsock: | |
message = b'ENDE:' | |
try: | |
sendsock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
logger.debug('sending ping end') | |
sendsock.sendto(message, ("255.255.255.255", 62482)) | |
except: | |
logger.error(f'failed to get UDP port?' ) | |
for rec in recorderList: | |
logger.info(f'found {rec[0]} at {rec[1]}') | |
return recorderList | |
def setTime(ip_string): | |
logger.info(f'setting time for recorder at {ip_string}' ) | |
#create an INET, STREAMing socket (IPv4, TCP/IP) | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client: | |
logger.debug('Socket Created') | |
APP_PORT = 8010 | |
client.settimeout(0.2) | |
client.connect((ip_string,APP_PORT)) | |
logger.debug(f'Socket Connected to {ip_string}' ) | |
try: | |
data = client.recv(1024) | |
logger.debug(f'received {data.hex()}') | |
except TimeoutError: | |
logger.debug(f' pre-send data timeout' ) | |
now = datetime.datetime.now() | |
yearoffset = 1792 #apparently 1792 is 0? Or there are other settings wrapped up in here? | |
# TODO figure out if any of these other values are important | |
timeSetBytes = bytes([0x44, 0x52, 0x30, 0x41, 0x07, 0x00, 0x07, \ | |
now.year-yearoffset, now.month, now.day, \ | |
now.hour, now.minute, now.second, 0]) | |
try: | |
client.send(timeSetBytes) | |
except socket.error: | |
logger.error('failed to send data') | |
return | |
logger.debug('sent time data') | |
try: | |
for i in range(10): | |
data = client.recv(1024) | |
logger.debug(f'received {data.hex()}') | |
except TimeoutError: | |
logger.debug(f' response data timeout' ) | |
recorderList = findRecorders() | |
for rec in recorderList: | |
if 'DR-22WL' in rec[0]: | |
setTime(rec[1]) | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment