YACWC
20
old/af_client.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import socket
|
||||
import os
|
||||
|
||||
# Client socket file
|
||||
client_socket_file = '/tmp/server_socket_use2'
|
||||
|
||||
# Create a UDP socket
|
||||
client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
|
||||
# Bind the socket to the file
|
||||
client_socket.connect(client_socket_file)
|
||||
|
||||
while True:
|
||||
# Receive data from the server
|
||||
data, _ = client_socket.recvfrom(1024)
|
||||
print("Received from server:", data.decode())
|
||||
|
||||
# Close the socket
|
||||
client_socket.close()
|
||||
|
||||
21
old/af_server.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import socket
|
||||
import os
|
||||
|
||||
# Server socket file
|
||||
server_socket_file = '/tmp/server_socket_use2'
|
||||
|
||||
# Create a UDP socket
|
||||
server_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
|
||||
# Bind the socket to the file
|
||||
server_socket.bind(server_socket_file)
|
||||
|
||||
while True:
|
||||
# Send a message to the client
|
||||
message = b"Hello, client!"
|
||||
server_socket.sendto(message, server_socket_file)
|
||||
|
||||
# Close the socket
|
||||
server_socket.close()
|
||||
|
||||
|
||||
BIN
old/bins.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
old/bins2.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
old/bins2O.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
old/bins2OS[O.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
old/crap.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
old/crap2.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
old/crap5.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
old/crap6.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
40
old/serial_monitor.py
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
|
||||
#baud_rates_test = (2400, 4800, 9600, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 153600, 230400, 256000)
|
||||
baud_rates_test = [57600]
|
||||
|
||||
|
||||
cmd_line = '/home/thebears/sr/bin/sigrok-cli --config samplerate=12M --driver=fx2lafw --continuous'
|
||||
cmd_start = cmd_line
|
||||
#'-P uart:baudrate=57600:tx=D0 -P uart:baudrate=9600:tx=D0 -A uart=tx-data:tx-warning'
|
||||
cmd_split = cmd_line.split()
|
||||
for x in baud_rates_test:
|
||||
cmd_split.append('-P')
|
||||
cmd_split.append(f'uart:baudrate={str(x)}:tx=D0')
|
||||
|
||||
cmd_split.append('-A')
|
||||
cmd_split.append('uart=tx-data:tx-warning')
|
||||
|
||||
|
||||
import io
|
||||
import time
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
command_to_run = cmd_split
|
||||
#command_to_run = ['/bin/bash','/home/thebears/Source/serial_monitor_variable/run_me.sh']
|
||||
process = subprocess.Popen(command_to_run,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
|
||||
idx = 0
|
||||
while True:
|
||||
stuff = process.stdout.readline()
|
||||
if len(stuff) == 0:
|
||||
break
|
||||
print(idx,stuff)
|
||||
idx+=1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
51
old/socket_server.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import socket
|
||||
import os
|
||||
|
||||
# Set the path for the Unix socket
|
||||
socket_path = '/tmp/my_socket'
|
||||
|
||||
# remove the socket file if it already exists
|
||||
try:
|
||||
os.unlink(socket_path)
|
||||
except OSError:
|
||||
if os.path.exists(socket_path):
|
||||
raise
|
||||
|
||||
# Create the Unix socket server
|
||||
server = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
|
||||
# Bind the socket to the path
|
||||
server.bind(socket_path)
|
||||
import time
|
||||
from datetime import datetime
|
||||
while True:
|
||||
time.sleep(0.25)
|
||||
print("Sending")
|
||||
server.sendto(("Hello "+str(datetime.now())).encode(), socket_path)
|
||||
|
||||
|
||||
# Listen for incoming connections
|
||||
server.listen(1)
|
||||
|
||||
# accept connections
|
||||
print('Server is listening for incoming connections...')
|
||||
connection, client_address = server.accept()
|
||||
|
||||
try:
|
||||
print('Connection from', str(connection).split(", ")[0][-4:])
|
||||
|
||||
# receive data from the client
|
||||
while True:
|
||||
data = connection.recv(1024)
|
||||
if not data:
|
||||
break
|
||||
print('Received data:', data.decode())
|
||||
|
||||
# Send a response back to the client
|
||||
response = 'Hello from the server!'
|
||||
connection.sendall(response.encode())
|
||||
finally:
|
||||
# close the connection
|
||||
connection.close()
|
||||
# remove the socket file
|
||||
os.unlink(socket_path)
|
||||
15
old/sovket_client.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import socket
|
||||
|
||||
|
||||
socket_path = '/tmp/my_socket'
|
||||
|
||||
|
||||
# Create the Unix socket server
|
||||
client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
|
||||
|
||||
client.bind(socket_path)
|
||||
client.send("hello".encode())
|
||||
while True:
|
||||
data, addr = client.recvfrom(1024)
|
||||
print(data)
|
||||
22
old/udp_server.py
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
import socket
|
||||
|
||||
MCAST_GRP = '239.255.255.255'
|
||||
MCAST_PORT = 5007
|
||||
# regarding socket.IP_MULTICAST_TTL
|
||||
# ---------------------------------
|
||||
# for all packets sent, after two hops on the network the packet will not
|
||||
# be re-sent/broadcast (see https://www.tldp.org/HOWTO/Multicast-HOWTO-6.html)
|
||||
MULTICAST_TTL = 2
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
|
||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL)
|
||||
|
||||
# For Python 3, change next line to 'sock.sendto(b"robot", ...' to avoid the
|
||||
# "bytes-like object is required" msg (https://stackoverflow.com/a/42612820)
|
||||
|
||||
from datetime import datetime
|
||||
import time
|
||||
for i in range(100):
|
||||
dsend = str(i)+' '+str(datetime.now())
|
||||
sock.sendto(dsend.encode(), (MCAST_GRP, MCAST_PORT))
|
||||