syndilights/v2/backend/processing/PixelControl_TCP/network.py

37 lines
1.1 KiB
Python
Raw Normal View History

2015-03-21 20:36:53 +01:00
import jarray
import time
2015-03-22 01:00:32 +01:00
import struct
2015-03-21 20:36:53 +01:00
from data_generator import image2data
2015-04-12 19:37:43 +02:00
def TCPConfigure(cl_class, server, port):
return cl_class(this, server, port)
2015-03-21 20:36:53 +01:00
def receive_config(socket):
2015-03-22 01:00:32 +01:00
max_height = jarray.zeros(4, "b")
max_width = jarray.zeros(4, "b")
max_framerate = jarray.zeros(4, "b")
2015-03-21 20:36:53 +01:00
while True:
available_bytes = socket.available()
if available_bytes > 0:
break
time.sleep(1)
socket.readBytes(max_height)
socket.readBytes(max_width)
socket.readBytes(max_framerate)
2015-03-22 01:00:32 +01:00
max_height = struct.unpack("<i", max_height)[0]
max_width = struct.unpack("<i", max_width)[0]
max_framerate = struct.unpack("<i", max_framerate)[0]
return max_height, max_width, max_framerate
2015-03-21 20:36:53 +01:00
def send_config(socket, height, width, framerate):
2015-03-22 01:00:32 +01:00
socket.write(struct.pack('<i', height))
socket.write(struct.pack('<i', width))
socket.write(struct.pack('<i', framerate))
2015-03-21 20:36:53 +01:00
def send_TCP(socket, data, long_line, type):
if socket is None:
# Dummy mode
return
image2data(data, type, long_line)
2015-03-21 20:36:53 +01:00
socket.write(data)