Commit 8e2cab1b authored by Andrey Filippov's avatar Andrey Filippov

Version working on NC393

parent ddb2fa15
......@@ -10,3 +10,5 @@ generated*
sysroots
bitbake-logs
/temp/
*.o
*.cgi
# Runs 'make', 'make install', and 'make clean' in specified subdirectories
SUBDIRS := src
INSTALLDIRS = $(SUBDIRS:%=install-%)
CLEANDIRS = $(SUBDIRS:%=clean-%)
#TARGETDIR=$(DESTDIR)/www/pages
all: $(SUBDIRS)
@echo "make all top"
$(SUBDIRS):
$(MAKE) -C $@
install: $(INSTALLDIRS)
@echo "make install top"
$(INSTALLDIRS):
$(MAKE) -C $(@:install-%=%) install
clean: $(CLEANDIRS)
@echo "make clean top"
$(CLEANDIRS):
$(MAKE) -C $(@:clean-%=%) clean
.PHONY: all install clean $(SUBDIRS) $(INSTALLDIRS) $(CLEANDIRS)
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.python.pydev.PyDevBuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>elphel-apps-histograms</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/SCP apps-histograms to target.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/org.python.pydev.PyDevBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
PROGS = pnghist.cgi
SRCS = pnghist.c
OBJS = pnghist.o
#OBJS = $(SRC:.c=.o)
#CFLAGS += -Wall -I$(ELPHEL_KERNEL_DIR)/include/uapi/elphel
CFLAGS += -Wall -I$(STAGING_DIR_HOST)/usr/include-uapi
#LDLIBS += -lpng -lm -lz
LDLIBS += -lpng -lm
INSTALL = install
INSTMODE = 0755
INSTDOCS = 0644
OWN = -o root -g root
#SYSCONFDIR = /etc/
#BINDIR = /usr/bin/
#WWW_PAGES = /www/pages
#CGIDIR = $(prefix)/usr/html
CGIDIR = /www/pages
all: $(PROGS)
$(PROGS): $(OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
install: $(PROGS) $(PHPSCRIPTS) $(CONFIGS)
$(INSTALL) $(OWN) -d $(DESTDIR)
$(INSTALL) $(OWN) -d $(DESTDIR)$(CGIDIR)
$(INSTALL) $(OWN) -m $(INSTMODE) $(PROGS) $(DESTDIR)$(CGIDIR)
clean:
rm -rf $(PROGS) *.o *~
#TODO: implement automatic dependencies!
#camogm.c:$(STAGING_DIR_HOST)/usr/include-uapi/elphel/x393_devices.h
AXIS_USABLE_LIBS = UCLIBC GLIBC
AXIS_AUTO_DEPEND = yes
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
# makefile for libpng using gcc (generic, static library)
# Copyright (C) 2000 Cosmin Truta
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
# For conditions of distribution and use, see copyright notice in png.h
# Location of the zlib library and include files
#ZLIBINC = zlib
#ZLIBLIB = zlib
PNGINC = libpng
PNGLIB = libpng
#ZLIB = zlib
PNGLIB = libpng
INCDIR = $(AXIS_KERNEL_DIR)/include
INSTDIR = $(prefix)/usr/local/bin
CGIDIR = $(prefix)/usr/html
INSTMODE = 0755
INSTDOCMODE = 0644
INSTOWNER = root
INSTGROUP = root
#PGMNAME = pnghist
# Compiler, linker, lib and other tools
# CC = gcc
LD = $(CC)
LN= $(CC)
AR = ar rcs
RANLIB = ranlib
RM = rm -f
CDEBUG = -g -DPNG_DEBUG=5
LDDEBUG =
CRELEASE = -O2
LDRELEASE = -s
CFLAGS += -Wall -g -I$(INCDIR) -I$(AXIS_KERNEL_DIR)/include
LDFLAGS += -L$(LIBDIR)
CFLAGS += -Wall -g -I$(INCDIR) -I$(PNGINC) -I$(AXIS_KERNEL_DIR)/include
LDFLAGS += -L. -L$(PNGLIB) -L$(LIBDIR) -lpng -lz -lm
ifndef UCLIBC
# -lm - to use math library
LDLIBS = -lcrypt -lm
endif
# Variables
PROGS=pnghist.cgi
PNGSRCS = $(PNGLIB)/png.c $(PNGLIB)/pngerror.c $(PNGLIB)/pngget.c $(PNGLIB)/pngmem.c $(PNGLIB)/pngpread.c \
$(PNGLIB)/pngread.c $(PNGLIB)/pngrio.c $(PNGLIB)/pngrtran.c $(PNGLIB)/pngrutil.c $(PNGLIB)/pngset.c \
$(PNGLIB)/pngtrans.c $(PNGLIB)/pngwio.c $(PNGLIB)/pngwrite.c $(PNGLIB)/pngwtran.c $(PNGLIB)/pngwutil.c
PNGOBJS = $(PNGLIB)/png.o $(PNGLIB)/pngerror.o $(PNGLIB)/pngget.o $(PNGLIB)/pngmem.o $(PNGLIB)/pngpread.o \
$(PNGLIB)/pngread.o $(PNGLIB)/pngrio.o $(PNGLIB)/pngrtran.o $(PNGLIB)/pngrutil.o $(PNGLIB)/pngset.o \
$(PNGLIB)/pngtrans.o $(PNGLIB)/pngwio.o $(PNGLIB)/pngwrite.o $(PNGLIB)/pngwtran.o $(PNGLIB)/pngwutil.o
SRCS = pnghist.c $(PNGSRCS) $(ZSRCS)
OBJS = pnghist.o $(PNGOBJS) $(ZOBJS)
#LIBS = $(PNGLIB)/libpng.a $(ZLIB)/libz.a
LIBS = $(PNGLIB)/libpng.a
# Targets
#all: dependency $(PROGS) $(PNGLIB)/libpng.a $(ZLIB)/libz.a
all: dependency $(PROGS)
$(PNGLIB)/libpng.a: $(PNGOBJS)
$(AR) $@ $(PNGOBJS)
$(RANLIB) $@
#$(ZLIB)/libz.a: $(ZOBJS)
# $(AR) $@ $(ZOBJS)
# -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
pnghist.cgi: pnghist.o $(PNGLIB)/libpng.a
$(LD) $^ $(LDLIBS) -o $@ $(LDFLAGS)
cris-strip -s $@
install: $(LIBS) $(PROGS)
$(INSTALL) -d $(INSTDIR)
$(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) pnghist.cgi $(CGIDIR)
clean:
$(RM) $(PNGLIB)/*.o $(PNGLIB)/*~ $(PNGLIB)/*.bak $(PNGLIB)/libpng.a $(PNGLIB)/pngtest $(PNGLIB)/pngout.png \
*.o *~ *.bak dependency $(PROGS)
configsubs:
......@@ -2,7 +2,7 @@
** -----------------------------------------------------------------------------**
** pnghist.c
**
** Copyright (C) 2006-2008 Elphel, Inc.
** Copyright (C) 2006-2016 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
** This program is free software: you can redistribute it and/or modify
......@@ -19,6 +19,9 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
......@@ -29,14 +32,20 @@
#include <fcntl.h>
#include <math.h>
#include <asm/elphel/autoexp.h>
//#include <elphel/autoexp.h>
// http://stackoverflow.com/questions/2442335/libpng-boostgil-png-infopp-null-not-found
// libpng 1.4 dropped definitions of png_infopp_NULL and int_p_NULL. So add
#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include <sys/mman.h>
#include <asm/elphel/c313a.h>
#include <elphel/c313a.h>
#include <elphel/x393_devices.h>
//#include "zlib.h"
#include "libpng/png.h"
//#include <libpng16/png.h>
#include <png.h>
#define HIST_SIZE 256 * 4 * 4
#define HPNG_PLOT_BARS 1
......@@ -47,7 +56,11 @@
#define QRY_MAXPARAMS 64
//#define THIS_DEBUG 1
#define THIS_DEBUG 0
// lighttpd requires the following setting to enable logging of the cgi program errors:
// ## where cgi stderr output is redirected
// server.breakagelog = "/www/logs/lighttpd_stderr.log"
char copyQuery [4096];
const char *uri;
......@@ -71,9 +84,13 @@ struct autoexp_t autoexp;
int write_png(int height, int data[1024], int mode, int colors);
int main(int argc, char *argv[])
{
int sensor_port=0;
int subchannel = 0;
int fd_histogram_cache;
struct histogram_stuct_t * histogram_cache; /// array of histogram
const char histogram_driver_name[]="/dev/histogram_cache";
const char histogram_driver_name[]=DEV393_PATH(DEV393_HISTOGRAM);
//#define DEV393_HISTOGRAM ("histogram_cache","histograms_operations",138,18,"0666","c") ///< Access to acquired/calculated histograms for all ports/channels/colors
int hists[1536];
int rava[256];
int i,j,k,a,l;
......@@ -129,6 +146,9 @@ int main(int argc, char *argv[])
/// Sample from camvc.html
///http://192.168.0.9/pnghist.cgi?sqrt=1&scale=5&average=5&height=128&fillz=1&linterpz=0&draw=2&colors=41
///FIXME: Some bump on low red - what is it?
//sensor_port
if((v = paramValue(gparams, "sensor_port")) != NULL) sensor_port=strtol(v, NULL, 10);
if((v = paramValue(gparams, "subchannel")) != NULL) subchannel=strtol(v, NULL, 10);
if((v = paramValue(gparams, "height")) != NULL) png_height=strtol(v, NULL, 10);
if((v = paramValue(gparams, "draw")) != NULL) mode= (mode & 0xfc) | (strtol(v, NULL, 10) & 3);
if((v = paramValue(gparams, "fillz")) != NULL) mode= (mode & (~HPNG_FILL_ZEROS)) | (strtol(v, NULL, 10)?HPNG_FILL_ZEROS:0);
......@@ -150,7 +170,7 @@ int main(int argc, char *argv[])
fflush(stdout);
return -1;
}
//! now try to mmap
// now try to mmap
histogram_cache = (struct histogram_stuct_t *) mmap(0, sizeof (struct histogram_stuct_t) * HISTOGRAM_CACHE_NUMBER , PROT_READ, MAP_SHARED, fd_histogram_cache, 0);
if((int)histogram_cache == -1) {
fprintf(stdout, "Pragma: no-cache\n");
......@@ -159,7 +179,35 @@ int main(int argc, char *argv[])
fflush(stdout);
return -1;
}
// Select sensor port and subchannel
if ((sensor_port< 0) || (sensor_port > 3) || (subchannel < 0) || (subchannel > 3)){
fprintf(stdout, "Pragma: no-cache\n");
fprintf(stdout, "Content-Type: text/plain\n\n");
fprintf(stdout, "Wrong sensor port and/or subchannel number: %s\n", histogram_driver_name);
fflush(stdout);
return -1;
}
if (((i = lseek(fd_histogram_cache, LSEEK_HIST_SET_CHN + (sensor_port <<2) +subchannel, SEEK_END)))<0){ // set port/subchannel to use
fprintf(stdout, "Pragma: no-cache\n");
fprintf(stdout, "Content-Type: text/plain\n\n");
fprintf(stdout, "port/subchannel combination does not exist: %s\n", histogram_driver_name);
fflush(stdout);
return -1;
}
#if 0
if ((offset & ~0xf) == LSEEK_HIST_SET_CHN){
p = (offset >> 2) & 3;
s = (offset >> 0) & 3;
if (get_hist_index(p,s)<0)
return -ENXIO; // invalid port/channel combination
privData->port = p;
privData->subchannel = s;
if((v = paramValue(gparams, "sensor_port")) != NULL) sensor_port=strtol(v, NULL, 10);
if((v = paramValue(gparams, "subchannel")) != NULL) subchannel=strtol(v, NULL, 10);
#endif
/// Now find the index of the most recently available histogram (maybe will wait a little if it is not yet available for the current frame - use previous?)
lseek(fd_histogram_cache, LSEEK_HIST_WAIT_C, SEEK_END); /// wait for all histograms, not just Y (G1)
lseek(fd_histogram_cache, LSEEK_HIST_NEEDED + 0xf0, SEEK_END); /// forward and cumulative histograms are needed
......@@ -188,6 +236,7 @@ int main(int argc, char *argv[])
fprintf (stderr," %05x",hists[i]);
}
fprintf (stderr,"\n\n\n");
fflush(stderr);
#endif
if ((mode & (HPNG_FILL_ZEROS | HPNG_LIN_INTERP)) | (rav>1)) { // spread between zeros - needed at high digital gains (near black with low gammas)
......@@ -259,7 +308,6 @@ int main(int argc, char *argv[])
//#define HPNG_PLOT_BARS 1
//#define HPNG_CONNECT_DOTS 2
int write_png(int png_height, int data[1536], int mode, int colors)
{
// FILE *fp;
......@@ -406,7 +454,7 @@ int write_png(int png_height, int data[1536], int mode, int colors)
png_set_PLTE(png_ptr,
info_ptr,
palette,
PNG_MAX_PALETTE_LENGTH);
sizeof(cpalette)/3); // PNG_MAX_PALETTE_LENGTH);
png_set_tRNS(png_ptr,
info_ptr,
trans,
......@@ -524,10 +572,10 @@ int write_png(int png_height, int data[1536], int mode, int colors)
// png_uint_32 k, height, width;
// png_byte image[height][width*bytes_per_pixel];
// png_bytep row_pointers[height];
#if 0
if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
png_error (png_ptr, "Image is too tall to process in memory");
#endif
for (k = 0; k < height; k++)
row_pointers[k] = (png_bytep) image + k*width*bytes_per_pixel;
......
#!/usr/bin/env python
# encoding: utf-8
from __future__ import division
from __future__ import print_function
"""
# @file used_files.py
# @brief Extract file access data after build, modify CDT project configuration
# (.cproject) accordingly
# @copyright Copyright (C) 2016, Elphel.inc.
# @param <b>License</b>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
@author: Andrey Filippov
@license: GPLv3.0+
@contact: andrey@elphel.coml
@deffield updated: Updated
"""
__author__ = "Andrey Filippov"
__copyright__ = "Copyright 2016, Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Andrey Filippov"
__email__ = "andrey@elphel.com"
__status__ = "Development"
import sys
import os
import time
import xml.etree.ElementTree as ET
'''
TODO:Automate, find out why separate touch commands are needed
Run this program twice:
1-st run ./used_files.py linux -1
and save shown timestamp
Then run (some mystery here)
touch src/drivers/ata/ahci_elphel.c
touch src/drivers/elphel/sensor_common.c
Wait 5 seconds and run (in a different console with appropriate sourcing)
bitbake linux-xlnx -c compile -f
Then again
./used_files.py linux <timestamp_from_the_first_run>
If somethong went wrong you will need to resore .cproject from eclipse_project_setup directory
For php:
bitbake php -c cleansstate
bitbake php -c unpack -f
bitbake php -c configure -f
./used_files.py php -1
bitbake php -c compile -f
./used_files.py php 1471044836.8
Doing:
bitbake php -c compile -f
./used_files.py php -1
bitbake php -c compile -f
./used_files.py php 1471044836.8
Corrupts make process
'''
def file_tree(flist): # Each file in list is a file, no directories
ftree={}
for p in flist:
node = ftree
seg_list=p.split(os.sep)
last_i=len(seg_list)-1
for i,segm in enumerate(seg_list):
if not segm in node:
if i == last_i:
node[segm] = None
else:
node[segm] = {}
node=node[segm]
return ftree
def exclude_list(ftree, flist):
mark = "*" # no file/dir name can be "*"
def list_tree_recursive(root):
rslt = []
if not mark in root:
return [[""]] # convert to trailing "/" for directories
for n in root:
if not n == mark:
if root[n] is None:
rslt.append([n])
else:
for l in list_tree_recursive(root[n]):
rslt.append([n]+l)
return rslt
ftree[mark]=None # mark top level dir
for p in flist:
node = ftree
for segm in p.split(os.sep)[:-1]:
node=node[segm]
node[mark]=None # [mark] means used in flist
del node[p.split(os.sep)[-1]]
#print (ftree)
# for k in ftree:
# print(k)
#Now prune unused directories
#prune_recursive(ftree) # (assuming root is used)
# now create list
files_list_list = list_tree_recursive(ftree)
# print (files_list_list)
#converrt to file paths
pl = []
for l in files_list_list:
pl.append(os.path.join(*(l[1:])))
pl = sorted (pl)
return pl
def proc_tree():
DEBUG = True
extensions = [".h",".c",".cpp"]
exclude_start = ["linux"+os.sep+"scripts"+os.sep,"linux"+os.sep+"source"+os.sep+"scripts"+os.sep]
delta_t = 3 # seconds
try:
root_path = sys.argv[1]
except:
print ("Calling %s <root directory path> [timestamp]"%(os.path.basename(sys.argv[0])))
try:
start_time = float(sys.argv[2])
except:
start_time = 0.0
touch_files= start_time < 0.0
print ("root_path = %s"%(root_path))
# root_path = "/home/eyesis/git/poky/linux-elphel/linux/"
lstFiles = []
# Append files to a list
for path, _, files in os.walk(root_path, followlinks = True):
for f in files:
for ext in extensions:
if f.endswith(ext):
lstFiles.append(os.path.join(path, f))
break
all_tree= file_tree(sorted(lstFiles))
include_lst=[]
lst_a = []
latest_at=0
for p in lstFiles:
if touch_files:
if os.path.islink(p):
try:
os.utime(os.path.realpath(p), None)
except:
print("missing linked file: %s"%(os.path.realpath(p)))
else:
os.utime(p, None)
else:
# at = time.ctime(os.stat(p).st_atime)
try:
at = os.stat(p).st_atime
l = None
except:
at = 0
if os.path.islink(p):
try:
l = os.path.realpath(p)
at = os.stat(l).st_atime
except:
at = 0 # missing file
latest_at = max((latest_at,at))
if at > (start_time + delta_t):
#Scripts/lexers result in problems
exclude=False
for exStr in exclude_start:
if p.startswith(exStr):
exclude=True
break
if exclude:
break
#exclude_start
lst_a.append([p,at,l])
include_lst.append(p)
if touch_files:
print (len(lstFiles), "last time = ", time.time())
return
excluding = exclude_list(all_tree, include_lst)
# print (all_tree)
# print (sorted(include_lst))
# print ("|".join(excluding))
if DEBUG:
with open("all_sources.lst","w" ) as f:
for p in sorted(lstFiles):
try:
at = os.stat(p).st_atime
except:
at = 0
lnk=""
if os.path.islink(p):
try:
at = os.stat(os.path.realpath(p)).st_atime
except:
at = 0
lnk = os.path.realpath(p)
print (p,at,lnk, file=f)
with open("excluding.lst","w" ) as f:
for p in excluding:
print (p, file=f)
with open("including.lst","w" ) as f:
for p in include_lst:
print (p, file=f)
# include_tree= file_tree(sorted(include_lst))
# print(include_tree)
root_dir=include_lst[0].split(os.sep)[0]
print ("root_dir=",root_dir)
xml= ET.parse(".cproject")
root=xml.getroot()
# for child in root:
# print(child.tag, child.attrib)
for child in root.iter('sourceEntries'):
for gchild in child:
print(gchild.tag)
for child in root.iter('sourceEntries'):
for gchild in child:
if gchild.tag == 'entry':
attr = gchild.attrib
try:
if (attr['kind'] == 'sourcePath') and (attr['name'] == root_dir):
child.remove (gchild)
print ("Removed existing entry ",gchild.tag)
break
except:
print ("error matching attributes for ",gchild.tag)
pass
break #after first 'sourceEntries' - should be just one?
ET.SubElement(child, 'entry', {"flags":"VALUE_WORKSPACE_PATH", "kind":"sourcePath", "name":root_dir, "excluding":"|".join(excluding)})
for child in root.iter('sourceEntries'):
for gchild in child:
print(gchild.tag)
oneliner= ET.tostring(root)
#overwrites original .cproject, may change to somethong different
with open(".cproject", "wr") as f:
f.write("""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>""")
f.write(oneliner)
print (len(lstFiles), len(lst_a), "last access time = ",latest_at)
if __name__ == '__main__':
proc_tree()
"""
make clean # otherwise compiled files are preserved
bitbake apps-histograms -c cleansstate
bitbake apps-histograms -c unpack -f
bitbake apps-histograms -c configure -f
./used_files.py sysroots/elphel393/usr/include-uapi -1
bitbake apps-histograms -c compile -f
./used_files.py sysroots/elphel393/usr/include-uapi 1473297567.42
eyesis@eyesis-SH87R:~/git/elphel393/rootfs-elphel/elphel-apps-histograms$ ./used_files.py sysroots/elphel393/usr -1
root_path = sysroots/elphel393/usr
5615 last time = 1473300068.01
eyesis@eyesis-SH87R:~/git/elphel393/rootfs-elphel/elphel-apps-histograms$ ./used_files.py sysroots/elphel393/usr 1473300068.01
root_path = sysroots/elphel393/usr
root_dir= sysroots
entry
entry
entry
entry
entry
5615 84 last access time = 1473300080.1
"""
\ No newline at end of file
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