Commit 3a04d19e authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

test scripts to get raw files

parent 673481b1
...@@ -2,7 +2,9 @@ PYTHONROOT=$(DESTDIR)/usr/local/bin ...@@ -2,7 +2,9 @@ PYTHONROOT=$(DESTDIR)/usr/local/bin
OWN = -o root -g root OWN = -o root -g root
INSTPYTHON = 0755 INSTPYTHON = 0755
#INSTALL = install #INSTALL = install
PYTHON_SCRIPTS = tests.py PYTHON_SCRIPTS = tests.py \
elphel_framepars.py \
raw.py
all: all:
@echo "make all in python_tests" @echo "make all in python_tests"
......
# Read frames' parameters. For Elphel NC393 cameras
__copyright__ = "Copyright 2018, Elphel, Inc."
__license__ = "GPL-3.0+"
__email__ = "oleg@elphel.com"
import mmap
import struct
class Pars:
# parameters
P_WOI_WIDTH = 26
P_WOI_HEIGHT = 27
# ...
P_FRAME = 136
# constants
## frame params queue length
MAX_FRAMES = 16
## 4 bytes per param
BYTE_MODE = 4
## params per frame from queue
PARS_SIZE = 1024
## all mem
MMAP_SIZE = MAX_FRAMES*BYTE_MODE*PARS_SIZE # bytes
ENDIAN = "<" # little, ">" for big
FRMT_BYTES = {1:'B',2:'H',4:'L',8:'Q'}
FMT = ENDIAN+FRMT_BYTES[BYTE_MODE]
def __init__(self,filename=""):
with open(filename,"r+b") as fp:
self.data = mmap.mmap(fp.fileno(), self.MMAP_SIZE, offset = 0) # mmap all data
def value(self,param,frame):
offset = (frame%self.MAX_FRAMES)*self.PARS_SIZE*self.BYTE_MODE
offset += (param%self.PARS_SIZE)*self.BYTE_MODE
data = self.data[offset:offset+self.BYTE_MODE]
res = struct.unpack_from(self.FMT,data)[0]
return res
#MAIN
if __name__ == "__main__":
print("Test")
a = Pars('/dev/frameparsall0')
print(" port 0, frame #: "+format(a.value(Pars.P_FRAME,0),'#08x'))
print(" port 0, frame width: "+format(a.value(Pars.P_WOI_WIDTH,0),'#08x'))
print(" port 0, frame height: "+format(a.value(Pars.P_WOI_HEIGHT,0),'#08x'))
#!/usr/bin/env python
from __future__ import division
from __future__ import print_function
# test and code samples related getting to raw pixels values
__author__ = "Elphel"
__copyright__ = "Copyright 2018, Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Oleg K Dzhimiev"
__email__ = "oleg@elphel.com"
__status__ = "Development"
import mmap
import struct
import os
import sys
import subprocess
# globals
MEMPATH = "/sys/devices/soc0/elphel393-mem@0"
VMEMPATH = "/sys/devices/soc0/elphel393-videomem@0"
BUF_PRE = MEMPATH+"/buffer_pages_raw_chn"
MEM_PRE = VMEMPATH+"/membridge_start"
VFRAME_PRE = VMEMPATH+"/video_frame_number"
VMDEV_PRE = "/dev/image_raw"
# not used here
MEMSTATUS = VMEMPATH+"/membridge_status"
# buffer size in 4k pages
# 4096 equals 16MB
# or just calculate based on image sizes
BUF_SIZE = 4096
# sbuf - buffer in system memory = cpu RAM
# vbuf - buffer in fpga memory = video memory
def set_sbuf_size(port):
cmd = "echo "+str(BUF_SIZE)+" > "+BUF_PRE+str(port)
subprocess.call(cmd,shell=True)
def set_vbuf_position(port,pos):
cmd = "echo "+str(pos)+" > "+VFRAME_PRE
subprocess.call(cmd,shell=True)
def copy_vbuf_to_sbuf(port,frame_number):
cmd = "echo "+str(frame_number)+" > "+MEM_PRE+str(port)
subprocess.call(cmd,shell=True)
def save_pixel_array(port,fname):
cmd = "cat "+VMDEV_PRE+str(port)+" > "+fname
subprocess.call(cmd,shell=True)
print("Memory dumped into "+fname)
# MAIN
for i in range(2):
set_sbuf_size(i)
set_vbuf_position(i,0)
copy_vbuf_to_sbuf(i,0)
save_pixel_array(i,"/tmp/port"+str(i)+".raw")
print("Now scp raw files to pc and run bayer2rgb\n")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment