Compare commits

..

No commits in common. "7811684badf9482f578713764b10d41245c18416" and "264df430ade9cb489f5afe7c02c4644a400bfbc3" have entirely different histories.

8 changed files with 35 additions and 39 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
*.zip *.zip
.vscode .vscode
.idea .idea
*.bin

View File

@ -4,29 +4,12 @@ local function getTextY(line)
end end
function love.draw2() function love.draw2()
local width, height = love.graphics.getDimensions()
-- Set background -- Set background
love.graphics.setBackgroundColor(0, 0, 0) love.graphics.setBackgroundColor(0, 0, 0)
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
-- Draw camera feed
if BotState.camfeed then if BotState.camfeed then
local imageWidth = BotState.camfeed:getWidth() love.graphics.draw(BotState.camfeed)
local imageHeight = BotState.camfeed:getHeight()
local scaleWidth = width / imageWidth
local scaleHeight = height / imageHeight
local scale = math.min(scaleWidth, scaleHeight)
local scaledWidth = imageWidth * scale
local scaledHeight = imageHeight * scale
love.graphics.draw(BotState.camfeed,
(width - scaledWidth) / 2, (height - scaledHeight) / 2,
0,
scale, scale
)
end end
-- Draw time -- Draw time

View File

@ -1074,6 +1074,7 @@ function client_mt:_apply_network_timeout()
-- replace connection recv_func with coroutine-based version -- replace connection recv_func with coroutine-based version
local sync_recv_func = conn.recv_func local sync_recv_func = conn.recv_func
conn.recv_func = function(totalSize, ...) conn.recv_func = function(totalSize, ...)
print("Args: ("..(1+#{...})..")", totalSize, ...)
while true do while true do
local allData = "" local allData = ""
while true do while true do
@ -1177,6 +1178,7 @@ function client_mt:_receive_packet()
return false, "network connection is not opened" return false, "network connection is not opened"
end end
-- parse packet -- parse packet
print("Calling ", conn.recv_func)
local packet, err = self._parse_packet(conn.recv_func) local packet, err = self._parse_packet(conn.recv_func)
if not packet then if not packet then
return false, err return false, err

View File

@ -25,7 +25,12 @@ end
-- Send data to network connection -- Send data to network connection
function luasocket.send(conn, data, i, j) function luasocket.send(conn, data, i, j)
conn.sock:settimeout(nil, "t") conn.sock:settimeout(nil, "t")
print("Sending bytes ", #data, i, j)
local ok, err = conn.sock:send(data, i, j) local ok, err = conn.sock:send(data, i, j)
if err == "timeout" then
print("Oops, got timeout")
print(debug.traceback())
end
conn.sock:settimeout(conn.timeout, "t") conn.sock:settimeout(conn.timeout, "t")
-- print(" luasocket.send:", ok, err, require("mqtt.tools").hex(data)) -- print(" luasocket.send:", ok, err, require("mqtt.tools").hex(data))
return ok, err return ok, err
@ -34,16 +39,25 @@ end
-- Receive given amount of data from network connection -- Receive given amount of data from network connection
function luasocket.receive(conn, size) function luasocket.receive(conn, size)
local ok, err = conn.sock:receive(size) local ok, err = conn.sock:receive(size)
--if ok then if ok then
-- print(" luasocket.receive good:", size, #ok, require("mqtt.tools").hex(ok)) if #ok ~= size then
--elseif err ~= "timeout" then assert(false, "bad size")
-- print(" luasocket.receive fail:", ok, err) end
--end if #ok > 100 then
print(" luasocket.receive good:", size, #ok, "(long)")
else
--print(debug.traceback())
print(" luasocket.receive good:", size, #ok, require("mqtt.tools").hex(ok))
end
elseif err ~= "timeout" then
print(" luasocket.receive fail:", ok, err)
end
return ok, err return ok, err
end end
-- Set connection's socket to non-blocking mode and set a timeout for it -- Set connection's socket to non-blocking mode and set a timeout for it
function luasocket.settimeout(conn, timeout) function luasocket.settimeout(conn, timeout)
print("Setting timeout to " .. timeout)
conn.timeout = timeout conn.timeout = timeout
conn.sock:settimeout(timeout, "t") conn.sock:settimeout(timeout, "t")
end end

View File

@ -490,12 +490,16 @@ function protocol.start_parse_packet(read_func)
len, err = parse_var_length(read_func) len, err = parse_var_length(read_func)
if not len then if not len then
return false, "failed to parse remaining length: "..err return false, "failed to parse remaining length: "..err
else
print("Variable length is: " .. len)
end end
-- create packet parser instance (aka input) -- create packet parser instance (aka input)
local input = {1, available = 0} -- input data offset and available size local input = {1, available = 0} -- input data offset and available size
if len > 0 then if len > 0 then
print("Reading payload body")
data, err = read_func(len) data, err = read_func(len)
print("Reading payload body done")
else else
data = "" data = ""
end end
@ -516,6 +520,7 @@ function protocol.start_parse_packet(read_func)
return res return res
end end
print("Available data is: " .. input.available)
return ptype, flags, input return ptype, flags, input
end end

View File

@ -2,15 +2,15 @@ FROM alpine:3.20.1
RUN apk add --no-cache git meson alpine-sdk cmake linux-headers python3 python3-dev \ RUN apk add --no-cache git meson alpine-sdk cmake linux-headers python3 python3-dev \
py3-yaml py3-jinja2 py3-ply py3-pybind11 py3-pybind11-dev py3-paho-mqtt py3-yaml py3-jinja2 py3-ply py3-pybind11 py3-pybind11-dev py3-paho-mqtt
#RUN apk add --no-cache libcamera libcamera-tools libcamera-v4l2 python3 python3-dev \
# cython py3-setuptools alpine-sdk ffmpeg ffmpeg-dev
WORKDIR /libcamera WORKDIR /libcamera
ADD libcamera /libcamera ADD libcamera /libcamera
RUN meson setup --prefix /usr build && ninja -C build install RUN meson setup --prefix /usr build && ninja -C build install
RUN apk add --no-cache py3-pillow
WORKDIR /app WORKDIR /app
COPY mfb.py /app COPY mfb.py /app
COPY spider-cam.py /app COPY spider-cam.py /app
CMD ["python3", "spider-cam.py"] CMD ["python3", "spider-cam.py"]

View File

@ -3,12 +3,10 @@ import paho.mqtt.client as mqtt
import selectors import selectors
import sys import sys
import time import time
import io
from PIL import Image
import mfb import mfb
image_count = 9999 image_count = 0
def camera_name(camera): def camera_name(camera):
return camera.id return camera.id
@ -18,18 +16,12 @@ def handle_camera_event(cm):
for req in reqs: for req in reqs:
process_request(req) process_request(req)
def sendImage(plane):
image = Image.frombytes("RGBA", (800, 600), plane.tobytes())
pngBytes = io.BytesIO()
image.save(pngBytes, "png")
mqttc.publish("spider/telemetry/camfeed", pngBytes.getvalue())
def process_request(request): def process_request(request):
global camera, image_count global camera, image_count
global mqttc global mqttc
image_count += 1 image_count += 1
if image_count > 30: if image_count > 50:
image_count = 0 image_count = 0
print(f'Request completed: {request}') print(f'Request completed: {request}')
@ -45,7 +37,7 @@ def process_request(request):
'/'.join([str(p.bytes_used) for p in metadata.planes])) '/'.join([str(p.bytes_used) for p in metadata.planes]))
with mfb.MappedFrameBuffer(buffer) as mappedBuffer: with mfb.MappedFrameBuffer(buffer) as mappedBuffer:
for plane in mappedBuffer.planes: for plane in mappedBuffer.planes:
sendImage(plane) mqttc.publish("spider/telemetry/camfeed", plane[0:256000].tobytes())
request.reuse() request.reuse()
camera.queue_request(request) camera.queue_request(request)
@ -119,4 +111,4 @@ def main():
mqttc.disconnect() mqttc.disconnect()
mqttc.loop_stop() mqttc.loop_stop()
sys.exit(main()) sys.exit(main())

1
spider-image.bin Normal file

File diff suppressed because one or more lines are too long