mirror of
https://github.com/korneliuszo/lumiax-controller.git
synced 2026-03-28 19:22:33 +01:00
Initial commit
This commit is contained in:
15
scripts/aaa.py
Executable file
15
scripts/aaa.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import tlay2_client
|
||||
import socket
|
||||
|
||||
conn = tlay2_client.Tlay2_out(0)
|
||||
|
||||
while True:
|
||||
packet = conn.recv()
|
||||
if packet == b'[SUBSCRIBED]\n':
|
||||
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
s.connect(("127.0.0.1",4444))
|
||||
s.send(b"reset\n")
|
||||
s.close()
|
||||
27
scripts/tlay2_client.py
Normal file
27
scripts/tlay2_client.py
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
import socket
|
||||
|
||||
class Tlay2_out():
|
||||
def __init__(self,fnaddr):
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.s.bind(("127.255.255.255",12349))
|
||||
self.fnaddr = fnaddr
|
||||
def recv(self):
|
||||
while True:
|
||||
buff=self.s.recv(1024)
|
||||
if buff[0] == self.fnaddr:
|
||||
return buff[1:]
|
||||
|
||||
class Tlay2_msg():
|
||||
def __init__(self,fnaddr):
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.s.connect(("127.0.0.1",12348))
|
||||
self.s.settimeout(2)
|
||||
self.fnaddr = bytes([fnaddr])
|
||||
def msgout(self,payload):
|
||||
self.s.send(self.fnaddr+payload)
|
||||
def msg(self,payload):
|
||||
self.msgout(payload)
|
||||
return self.s.recv(1024)[1:]
|
||||
10
scripts/tlay2_dbgout.py
Executable file
10
scripts/tlay2_dbgout.py
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import tlay2_client
|
||||
|
||||
conn = tlay2_client.Tlay2_out(0)
|
||||
|
||||
while True:
|
||||
packet = conn.recv()
|
||||
print(packet)
|
||||
74
scripts/tlay2_server.py
Executable file
74
scripts/tlay2_server.py
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import serial
|
||||
import crcmod
|
||||
import threading
|
||||
import socket
|
||||
import os
|
||||
|
||||
ser = serial.Serial(sys.argv[1], 115200)
|
||||
|
||||
crc8 = crcmod.predefined.mkCrcFun('crc-8')
|
||||
|
||||
connections = {}
|
||||
|
||||
my_mutex = threading.Event()
|
||||
my_mutex.set()
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.bind(("127.0.0.1",12348))
|
||||
|
||||
s2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s2.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
s2.connect(("127.255.255.255",12349))
|
||||
|
||||
def udprecv():
|
||||
global connections
|
||||
global my_mutex
|
||||
curid = 1
|
||||
while True:
|
||||
data, addr = s.recvfrom(1024)
|
||||
#print("Sending:",data)
|
||||
buff=b''
|
||||
data = bytes([curid]) + data
|
||||
data += bytes([crc8(data)])
|
||||
connections[curid]= addr
|
||||
curid+=1
|
||||
if curid == 256:
|
||||
curid = 1
|
||||
for byte in data:
|
||||
if byte == 0x0a or byte == 0xdc:
|
||||
buff+=bytes([0xdc])
|
||||
byte ^= 0x80
|
||||
buff+=bytes([byte])
|
||||
buff+=b'\n'
|
||||
my_mutex.wait(1.5)
|
||||
my_mutex.clear()
|
||||
ser.write(buff)
|
||||
|
||||
|
||||
t1 = threading.Thread(target = udprecv)
|
||||
|
||||
t1.start()
|
||||
|
||||
buff=b""
|
||||
while True:
|
||||
c= ser.read()
|
||||
if c == b'\n':
|
||||
if len(buff) < 3:
|
||||
print("Too short packet",buff)
|
||||
elif crc8(buff) != 0:
|
||||
print("CRC ERROR")
|
||||
else:
|
||||
#print("Recv:",buff[1:-1])
|
||||
if buff[0] == 0:
|
||||
s2.send(buff[1:-1])
|
||||
else:
|
||||
my_mutex.set()
|
||||
s.sendto(buff[1:-1],connections[buff[0]])
|
||||
buff = b""
|
||||
continue
|
||||
if c == b"\xdc":
|
||||
c = bytes([(ser.read()[0] ^ 0x80)])
|
||||
buff+=c
|
||||
Reference in New Issue
Block a user