Commit 7fb56744 authored by Andrey Filippov's avatar Andrey Filippov

made all build for NC393, created project setup files

parent 99b601c4
......@@ -10,3 +10,6 @@ generated*
sysroots
bitbake-logs
/temp/
*.o
*.cgi
bitbake-logs
# 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.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/elphel-apps-autoexposure/run_bitbake.sh}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="apps-autoexposure -c target_scp -f"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>elphel-apps-autoexposure</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-autoexposure to target.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>
AXIS_USABLE_LIBS = UCLIBC GLIBC
AXIS_AUTO_DEPEND = yes
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
#include ".depend"
INSTDIR = $(prefix)/usr/local/sbin/
CONFDIR = $(prefix)/etc/
INSTMODE = 0755
INSTOTHER = 0644
INSTOWNER = root
INSTGROUP = root
INCDIR = $(prefix)/include
PROGS = autoexposure temperature
SRCS = autoexposure.c globalsinit.c aexp_utils.c aexp_corr.c white_balance.c hdr_control.c temperature.c
OBJS = autoexposure.o globalsinit.o aexp_utils.o aexp_corr.o white_balance.o hdr_control.o temperature.o
CFLAGS += -Wall -I$(INCDIR) -I$(AXIS_KERNEL_DIR)/include
#CFLAGS += -Wall -I$(INCDIR) -I$(AXIS_KERNEL_DIR)/include -save-temps -dA -dP
CFLAGS += -Wall -I$(STAGING_DIR_HOST)/usr/include-uapi
INSTALL = install
INSTMODE = 0755
#INSTDOCS = 0644
OWN = -o root -g root
BINDIR = /usr/bin
all: $(PROGS)
autoexposure: autoexposure.o globalsinit.o aexp_utils.o aexp_corr.o white_balance.o hdr_control.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
cris-strip -s $@
temperature: temperature.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
cris-strip -s $@
install: $(PROGS)
$(INSTALL) -d $(INSTDIR)
$(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) $(PROGS) $(INSTDIR)
$(INSTALL) $(OWN) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m $(INSTMODE) $(OWN) $(PROGS) $(DESTDIR)$(BINDIR)
clean:
rm -rf $(PROGS) *.o core
configsubs:
# INSTALL=${ELPHEL393_INSTALL}
# MKNOD=${ELPHEL393_MKNOD}
# DESTDIR=${D}
# ELPHEL_KERNEL_DIR=${STAGING_KERNEL_DIR}
# STAGING_KERNEL_DIR=${STAGING_KERNEL_DIR}
# STAGING_DIR_HOST=${STAGING_DIR_HOST}
# USERADD='${ELPHEL393_USERADD}'
# REMOTE_USER=${REMOTE_USER}
# REMOTE_IP=${REMOTE_IP}
......@@ -58,7 +58,7 @@
#include "autoexposure.h"
void initAexpCorr(void) {
GLOBALPARS(G_NEXT_AE_FRAME)=0; ///NOTE - autoexposure was stuck for a hours when I tried resetting frame number...
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=0; ///NOTE - autoexposure was stuck for a hours when I tried resetting frame number...
}
/**
* @brief Single autoexposure correction step
......@@ -102,27 +102,27 @@ int aexpCorr(int color, int frame, int target_frame) {
int ae_dont_sync=(framePars[target_frame8].pars[P_AE_PERIOD] & 0x10000); /// don't try to synchronize to availble histograms
int i;
int aerr=0; // just to keep compiler happy
int * ae_err= (int *) &(GLOBALPARS(G_AE_INTEGERR)); /// so it will be signed
int * ae_err= (int *) &(GLOBALPARS_SNGL(G_AE_INTEGERR)); /// so it will be signed
if (!ae_period_change) ae_period_change=DEFAULT_AE_PERIOD_CHANGE;
if (!ae_period_nochange) ae_period_nochange=DEFAULT_AE_PERIOD_NOCHANGE;
// unsigned long overexp_scale;
if (!framePars[target_frame & PARS_FRAMES_MASK].pars[P_AUTOEXP_ON]) {
GLOBALPARS(G_NEXT_AE_FRAME)=frame+ae_period_change;
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=frame+ae_period_change;
return 0; /// autoexposure is turned off
}
if (GLOBALPARS(G_NEXT_AE_FRAME)>frame) return 0; /// too early to bother
if (GLOBALPARS_SNGL(G_NEXT_AE_FRAME)>frame) return 0; /// too early to bother
MDF3(fprintf(stderr,"*ae_err=%d\n",*ae_err)); ///======= 0 here
frac=framePars[target_frame & PARS_FRAMES_MASK].pars[P_AEXP_FRACPIX];
// level=framePars[target_frame & PARS_FRAMES_MASK].pars[P_AEXP_LEVEL];
/// get (approximate if not updated) percentile for dim (1 scanline exposure) image -to use as a zero point exposure
dim=(GLOBALPARS((color>1)?G_HIST_DIM_23:G_HIST_DIM_01) >> ((color & 1)? 16 : 0)) & 0xffff;
dim=(GLOBALPARS_SNGL((color>1)?G_HIST_DIM_23:G_HIST_DIM_01) >> ((color & 1)? 16 : 0)) & 0xffff;
/// measure
perc=getPercentile(frame-1,color, frac, 1 << color); ///sets global hist_index, gamma_index
// MDF2(fprintf(stderr,"got histogram for frame: 0x%lx, NOW: 0x%lx\n",histogram_cache[hist_index].frame, GLOBALPARS(G_THIS_FRAME)));
// MDF2(fprintf(stderr,"got histogram for frame: 0x%lx, NOW: 0x%lx\n",histogram_cache[hist_index].frame, GLOBALPARS_SNGL(G_THIS_FRAME)));
if (histogram_cache[hist_index].frame < (frame-1)) { /// histogram is too old - try again
GLOBALPARS(G_NEXT_AE_FRAME)=frame+1;
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=frame+1;
if (ae_dont_sync) return 0; /// will request histogram for this frame
/// repeat up to 8 times trying to get a fresh histogram
for (i=0; i<8; i++) {
......@@ -134,7 +134,7 @@ int aexpCorr(int color, int frame, int target_frame) {
if (histogram_cache[hist_index].frame == (frame-1)) break;
}
if (histogram_cache[hist_index].frame < (frame-1)) { /// histogram is too old - try again
GLOBALPARS(G_NEXT_AE_FRAME)=frame+1;
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=frame+1;
return 0; /// will request histogram for this frame
}
}
......@@ -143,7 +143,7 @@ int aexpCorr(int color, int frame, int target_frame) {
level=gammaReverse (level_gamma);
MDF3(fprintf(stderr,"->>> frame=0x%x, target_frame=0x%x,dim=0x%04x, frac=0x%04x, level=0x%x,level_gamma=0x%x, perc=0x%04x\n",frame,target_frame,dim,frac,level,level_gamma,perc));
if (perc <0) {
GLOBALPARS(G_NEXT_AE_FRAME)=frame+ae_period_change;
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=frame+ae_period_change;
return -1; ///getPercentile() failed
}
///
......@@ -212,7 +212,7 @@ int aexpCorr(int color, int frame, int target_frame) {
MDF3(fprintf(stderr,"old_vexpos=0x%x, new_vexpos=0x%x, aerr=%d, ae_err=%d\n", old_vexpos, new_vexpos, aerr, *ae_err));
if (new_vexpos==old_vexpos) {
MDF3(fprintf(stderr,"No correction: thrshold=%d, aerr=%d\n",error_thresh,aerr)); ///======= 1 here
GLOBALPARS(G_NEXT_AE_FRAME)=frame+ae_period_nochange; /// try again next frame (extend in HDR)
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=frame+ae_period_nochange; /// try again next frame (extend in HDR)
return 0; /// too little error - no change in exposure
}
// *ae_err=0; /// reset error accumulator TODO: If scaled - reduce resudual error, not reset it
......@@ -239,7 +239,7 @@ int aexpCorr(int color, int frame, int target_frame) {
}
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) return -errno;
GLOBALPARS(G_NEXT_AE_FRAME)=frame+ae_period_change;
GLOBALPARS_SNGL(G_NEXT_AE_FRAME)=frame+ae_period_change;
return 1;
}
......@@ -84,13 +84,13 @@ int poorExp(int x) {
int waitRequstPrevHist(unsigned long next_frame) {
unsigned long write_data[4];
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
MDF2(fprintf(stderr,"next_frame=0x%08lx, this_frame=0x%08lx\n",next_frame,this_frame)); ///======= 0 here
if (next_frame <= this_frame) return 0; /// too_late
else if (next_frame > (this_frame+5) ) { /// wait heer as it is too early to schedule histograms
lseek(fd_fparmsall, next_frame-5+LSEEK_FRAME_WAIT_ABS, SEEK_END);
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
}
/// schedule all histograms for next_frame-1
write_data[0]= FRAMEPARS_SETFRAME;
......@@ -102,7 +102,7 @@ int waitRequstPrevHist(unsigned long next_frame) {
/// now wait for that next frame (if needed)
if (next_frame > this_frame ) {
lseek(fd_fparmsall, next_frame+LSEEK_FRAME_WAIT_ABS, SEEK_END);
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
return 1;
}
return 0;
......@@ -131,13 +131,13 @@ long getPercentile(unsigned long frame,int color, unsigned long fraction, int re
if (request_colors) { /// at minimum for the new frame request_colors= 1<<color
if (request_colors & ~ (1<<COLOR_Y_NUMBER)) lseek(fd_histogram_cache, LSEEK_HIST_WAIT_C, SEEK_END); /// wait for all histograms, not just Y (G1)
else lseek(fd_histogram_cache, LSEEK_HIST_WAIT_Y, SEEK_END); /// wait for just Y (G1)
MDF2(fprintf(stderr,"this_frame: 0x%lx, NOW: 0x%lx\n",this_frame, GLOBALPARS(G_THIS_FRAME)));
MDF2(fprintf(stderr,"this_frame: 0x%lx, NOW: 0x%lx\n",this_frame, GLOBALPARS_SNGL(G_THIS_FRAME)));
lseek(fd_histogram_cache, LSEEK_HIST_NEEDED + (request_colors << 8), SEEK_END); /// specify that reverse histogram(s) are needed
hist_index=lseek(fd_histogram_cache, frame, SEEK_SET); /// request histograms for the specified frame
MDF2(fprintf(stderr,"got histogram for frame: 0x%lx, NOW: 0x%lx\n",histogram_cache[hist_index].frame, GLOBALPARS(G_THIS_FRAME)));
MDF2(fprintf(stderr,"got histogram for frame: 0x%lx, NOW: 0x%lx\n",histogram_cache[hist_index].frame, GLOBALPARS_SNGL(G_THIS_FRAME)));
/// histograms for frame will be available 1 frame later
if(hist_index <0) {
ELP_FERR(fprintf(stderr, "Requested histograms for frame %ld (0x%lx) are not available. this_frame=0x%lx, now=0x%lx\n",frame,frame,this_frame,GLOBALPARS(G_THIS_FRAME) ));
ELP_FERR(fprintf(stderr, "Requested histograms for frame %ld (0x%lx) are not available. this_frame=0x%lx, now=0x%lx\n",frame,frame,this_frame,GLOBALPARS_SNGL(G_THIS_FRAME) ));
return -1;
}
}
......@@ -302,7 +302,7 @@ int recalibrateDim(void) {
unsigned long vexpos_was, fraction, dims;
unsigned long write_data[4];
int rslt;
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
MDF1(fprintf(stderr,"this_frame: 0x%lx\n",this_frame));
unsigned long target_frame=this_frame+RECALIBRATE_AHEAD;
vexpos_was= framePars[target_frame & PARS_FRAMES_MASK].pars[P_VEXPOS];
......@@ -321,11 +321,11 @@ int recalibrateDim(void) {
/// no error check here
dims= getPercentile(target_frame,0, fraction, 0xf) & 0xffff; /// all colors are needed. Will skip frames
dims|=getPercentile(target_frame,1, fraction, 0xf) << 16;
GLOBALPARS(G_HIST_DIM_01)=dims;
GLOBALPARS_SNGL(G_HIST_DIM_01)=dims;
dims= getPercentile(target_frame,2, fraction, 0xf) & 0xffff; /// all colors are needed. Will skip frames
dims|=getPercentile(target_frame,3, fraction, 0xf) << 16;
GLOBALPARS(G_HIST_DIM_23)=dims;
MDF1(fprintf(stderr,"dims: 0x%lx NOW: 0x%lx\n",dims, GLOBALPARS(G_THIS_FRAME)));
GLOBALPARS_SNGL(G_HIST_DIM_23)=dims;
MDF1(fprintf(stderr,"dims: 0x%lx NOW: 0x%lx\n",dims, GLOBALPARS_SNGL(G_THIS_FRAME)));
lseek(fd_histogram_cache, target_frame+RECALIBRATE_AFTER, SEEK_SET); ///
return 0;
}
......
......@@ -93,9 +93,13 @@
*!
*/
#include "autoexposure.h"
//#define MAX_SENSORS 4 ///< maximal number of sensor attached (modify some hard-wired constants below if this to be changed)
//#define SENSOR_PORTS 4 ///< Number of sensor ports (each has individual framepars_all_t
int main (int argc, char *argv[]) {
int daemon_bit=0; ///TODO: - make it an argument
int daemon_bit=0;
int sensor_port = 0;
int sensor_subchannel = 0;
// int perc;
int rslt, ae_rslt;
int hdr_mode; /// 0 - off, 1 each other frame, 2 - 2 on, 2 - off
......@@ -103,27 +107,39 @@ int main (int argc, char *argv[]) {
int exp_ahead;
unsigned long next_frame;
const char usage[]= "Usage:\n%s [-b <daemon_bit_number> [-d <debug_bits>]]\n\n"
const char usage[]= "Usage:\n%s -p <sensor port(0..3)> -c <sensor sub channel(0..3)> [-b <daemon_bit_number> [-d <debug_bits>]]\n\n"
"Start autoexposure daemon, bind it to bit <daemon_bit_number> (0..31) in P_DAEMON_EN (ELPHEL_DAEMON_EN in PHP)\n"
"Optional debug_bits (hex number) enable different groups of debug messages (1 group per bit) to stderr\n\n";
// Currently it just verifies that specified keys are at the required positions. TODO: use library to parse
if ((argc < 5) || (strcasecmp(argv[1], "-p")) || (strcasecmp(argv[3], "-c"))){
printf (usage,argv[0]);
return 0;
}
sensor_port = strtol(argv[2], NULL, 16);
sensor_subchannel = strtol(argv[4], NULL, 16);
if ((sensor_port < 0) || (sensor_port >= SENSOR_PORTS) || (sensor_subchannel < 0) || (sensor_subchannel >= MAX_SENSORS) ) {
printf ("Invalid number of port/subchannel\n\n");
printf (usage,argv[0]);
return 0;
}
if (argc < 2) {
daemon_bit=DAEMON_BIT_AUTOEXPOSURE;
} else if ((argc < 3) || (strcasecmp(argv[1], "-b"))) {
if (argc < 6) {
daemon_bit=DAEMON_BIT_AUTOEXPOSURE+sensor_subchannel;
} else if ((argc < 7) || (strcasecmp(argv[5], "-b"))) {
printf (usage,argv[0]);
return 0;
}
if ((argc >=5) && (strcasecmp(argv[3], "-d")==0)) {
autoexposure_debug=strtol(argv[4], NULL, 16);
if ((argc >=9) && (strcasecmp(argv[7], "-d")==0)) {
autoexposure_debug=strtol(argv[8], NULL, 16);
} else autoexposure_debug=1;
daemon_bit=strtol(argv[2], NULL, 10);
daemon_bit=strtol(argv[6], NULL, 10);
if ((daemon_bit<0) || (daemon_bit>31)) {printf ("Invalid bit number %d (should be 0..31)\n", daemon_bit); exit (1);}
fprintf(stderr,"autoexposure started, daemon_bit=0x%x, debug=0x%x\n",daemon_bit,autoexposure_debug);
// MDF1(fprintf(stderr,"\n"));
if (initFilesMmap()<0) exit (1); /// initialization errors
if (initFilesMmap(sensor_port)<0) exit (1); /// initialization errors
if (autoexposure_debug <0) { /// tempoorary hack for testing
GLOBALPARS(G_DEBUG)=0;
GLOBALPARS_SNGL(G_DEBUG)=0;
exit (0);
}
MDF0(fprintf(stderr,"autoexposure started, daemon_bit=0x%x, debug=0x%x\n",daemon_bit,autoexposure_debug));
......@@ -138,26 +154,26 @@ int main (int argc, char *argv[]) {
/// Main loop
while (1) {
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
MDF6(fprintf(stderr,"Waiting for autoexposure daemon to be enabled\n"));
lseek(fd_histogram_cache, LSEEK_DAEMON_HIST_Y+daemon_bit, SEEK_END); /// wait for autoexposure daemon to be enabled (let it sleep if not)
if (GLOBALPARS(G_THIS_FRAME) != this_frame) {
if (GLOBALPARS_SNGL(G_THIS_FRAME) != this_frame) {
///TODO: Make it possible for this_frame to lag slightly (1 frame) to compensate for CPU being busy with other tasks?
/// Need to re-initialize after long sleep
if (initParams(daemon_bit)<0) exit (1); /// initialization errors
}
/// Is exposure black level calibration requested (will produce 2 (or 1, depending on trigger mode?) dark frames
if (GLOBALPARS(G_HIST_DIM_01)==0xffffffff) {
if (GLOBALPARS_SNGL(G_HIST_DIM_01)==0xffffffff) {
rslt=recalibrateDim();
MDF1(fprintf(stderr,"G_HIST_DIM_01: 0x%08lx, G_HIST_DIM_23: 0x%08lx, recalibrateDim()->%d\n",GLOBALPARS(G_HIST_DIM_01),GLOBALPARS(G_HIST_DIM_23),rslt));
this_frame=GLOBALPARS(G_THIS_FRAME);
MDF1(fprintf(stderr,"G_HIST_DIM_01: 0x%08lx, G_HIST_DIM_23: 0x%08lx, recalibrateDim()->%d\n",GLOBALPARS_SNGL(G_HIST_DIM_01),GLOBALPARS_SNGL(G_HIST_DIM_23),rslt));
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
}
/// In HDR mode make sure we skip those different frames;
hdr_mode=get_imageParamsThis(P_HDR_DUR);
if (hdr_mode>2) hdr_mode=2;
if (hdr_mode>0) {
skipHDR(hdr_mode,this_frame);
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
}
exp_ahead=get_imageParamsThis(P_EXP_AHEAD);
if (!exp_ahead) exp_ahead = 3;
......@@ -172,7 +188,7 @@ MDF3(fprintf(stderr, "this_frame= 0x%x, this_frame+exp_ahead= 0x%x, old_vexp= 0x
/// if it is too far ahead, wait some frames
if ((hdr_target_frame-this_frame)>(exp_ahead+1)) {
lseek(fd_fparmsall, (hdr_target_frame-exp_ahead-1)+LSEEK_FRAME_WAIT_ABS, SEEK_END);
this_frame=GLOBALPARS(G_THIS_FRAME);
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME);
}
exp_ahead=hdr_target_frame-this_frame;
}
......@@ -181,9 +197,9 @@ MDF3(fprintf(stderr, "this_frame= 0x%x, this_frame+exp_ahead= 0x%x, old_vexp= 0x
MDF3(fprintf(stderr, "this_frame= 0x%x, this_frame+exp_ahead= 0x%x, old_vexp= 0x%x, old_that_vexpos = 0x%x\n", (int) this_frame,(int) (this_frame+exp_ahead), (int) old_vexp, (int) old_that_vexpos));
if (((ae_rslt=aexpCorr(COLOR_Y_NUMBER, this_frame, this_frame+exp_ahead )))<0) break; /// restart on errors
//GLOBALPARS(G_AE_INTEGERR)
//GLOBALPARS_SNGL(G_AE_INTEGERR)
vexp= framePars[(this_frame+exp_ahead) & PARS_FRAMES_MASK].pars[P_VEXPOS];
next_frame=GLOBALPARS(G_NEXT_AE_FRAME);
next_frame=GLOBALPARS_SNGL(G_NEXT_AE_FRAME);
if (ae_rslt>0) MDF1(fprintf(stderr,"aexpCorr(0x%x, 0x%lx, 0%lx) -> %d, VEXPOS will be 0x%lx (0x%lx , 0x%lx), next_frame=0x%lx\n", COLOR_Y_NUMBER,this_frame,this_frame+exp_ahead,ae_rslt,vexp,old_vexp, old_that_vexpos,next_frame));
/// WB processing
rslt=whiteBalanceCorr(this_frame, this_frame+exp_ahead, ae_rslt );
......@@ -212,11 +228,11 @@ MDF3(fprintf(stderr, "this_frame= 0x%x, this_frame+exp_ahead= 0x%x, old_vexp= 0x
/// histograms are only availble for the previous frame, so this_frame-1
/*
perc=getPercentile(next_frame-1,COLOR_Y_NUMBER, framePars[next_frame & PARS_FRAMES_MASK].pars[P_AEXP_FRACPIX], 1 << COLOR_Y_NUMBER);
MDF6(fprintf(stderr,"FRAME: 0x%lx, COLOR: %d, FRACTION: 0x%04lx RESULT:0x%04x, NOW: 0x%lx\n",next_frame-1,COLOR_Y_NUMBER,framePars[next_frame & PARS_FRAMES_MASK].pars[P_AEXP_FRACPIX],perc,GLOBALPARS(G_THIS_FRAME)));
MDF6(fprintf(stderr,"FRAME: 0x%lx, COLOR: %d, FRACTION: 0x%04lx RESULT:0x%04x, NOW: 0x%lx\n",next_frame-1,COLOR_Y_NUMBER,framePars[next_frame & PARS_FRAMES_MASK].pars[P_AEXP_FRACPIX],perc,GLOBALPARS_SNGL(G_THIS_FRAME)));
*/
}
ELP_FERR(fprintf (stderr,"Restarting autoexposure due to errors, skipping a frame\n"));
lseek(fd_fparmsall, GLOBALPARS(G_THIS_FRAME) + 1+LSEEK_FRAME_WAIT_ABS, SEEK_END);
lseek(fd_fparmsall, GLOBALPARS_SNGL(G_THIS_FRAME) + 1+LSEEK_FRAME_WAIT_ABS, SEEK_END);
}
return 0;
......
......@@ -50,8 +50,9 @@
#include <sys/mman.h> /* mmap */
#include <sys/ioctl.h>
#include <asm/elphel/c313a.h>
#include <asm/elphel/exifa.h>
#include <elphel/c313a.h>
#include <elphel/x393_devices.h>
//#include <elphel/exifa.h>
#include <asm/byteorder.h>
#include "aexp_utils.h"
......@@ -59,6 +60,7 @@
#include "white_balance.h"
#include "hdr_control.h"
#include "globalsinit.h"
//#if ELPHEL_DEBUG
#define THIS_DEBUG 1
//#else
......
......@@ -57,10 +57,16 @@
* uses global variables for files and mmap-ed data so they are accessible everywhere
* @return 0 - OK, <0 - problems opening/mma-ing
*/
int initFilesMmap(void) {
const char framepars_driver_name[]="/dev/frameparsall";
const char histogram_driver_name[]="/dev/histogram_cache";
const char gamma_driver_name[]= "/dev/gamma_cache";
int initFilesMmap(int sensor_port) {
const char *framepars_dev_names[SENSOR_PORTS] = {
DEV393_PATH(DEV393_FRAMEPARS0),
DEV393_PATH(DEV393_FRAMEPARS1),
DEV393_PATH(DEV393_FRAMEPARS2),
DEV393_PATH(DEV393_FRAMEPARS3)};
const char *framepars_driver_name=framepars_dev_names[sensor_port];
const char histogram_driver_name[]=DEV393_PATH(DEV393_HISTOGRAM);
const char gamma_driver_name[]= DEV393_PATH(DEV393_GAMMA);
///Frame parameters file open/mmap (read/write)
fd_fparmsall= open(framepars_driver_name, O_RDWR);
if (fd_fparmsall <0) {
......@@ -118,12 +124,12 @@ int initFilesMmap(void) {
int initParams(int daemon_bit) {
aex_recover_cntr=0;
lseek(fd_histogram_cache, LSEEK_DAEMON_HIST_Y+daemon_bit, SEEK_END); /// wait for autoexposure daemon to be enabled
GLOBALPARS(G_AE_INTEGERR)=0; /// reset running error
GLOBALPARS(G_WB_INTEGERR)=0; /// reset running error
this_frame=GLOBALPARS(G_THIS_FRAME); /// set global frame number
if (GLOBALPARS(G_HIST_DIM_01)==0) {
GLOBALPARS(G_HIST_DIM_01)=DEFAULT_BLACK_CALIB | (DEFAULT_BLACK_CALIB <<16);
GLOBALPARS(G_HIST_DIM_23)=DEFAULT_BLACK_CALIB | (DEFAULT_BLACK_CALIB <<16);
GLOBALPARS_SNGL(G_AE_INTEGERR)=0; /// reset running error
GLOBALPARS_SNGL(G_WB_INTEGERR)=0; /// reset running error
this_frame=GLOBALPARS_SNGL(G_THIS_FRAME); /// set global frame number
if (GLOBALPARS_SNGL(G_HIST_DIM_01)==0) {
GLOBALPARS_SNGL(G_HIST_DIM_01)=DEFAULT_BLACK_CALIB | (DEFAULT_BLACK_CALIB <<16);
GLOBALPARS_SNGL(G_HIST_DIM_23)=DEFAULT_BLACK_CALIB | (DEFAULT_BLACK_CALIB <<16);
return 1 ; /// used default, no real calibration
}
//#define P_AUTOEXP_EXP_MAX 81 //unsigned long exp_max; /* 100 usec == 1 etc... */
......
/*!***************************************************************************
*! FILE NAME : globalsinit.h
*! DESCRIPTION: Daemon to adjust camera exposure and white balance
*! Copyright (C) 2008 Elphel, Inc.
*! Copyright (C) 2008-2016 Elphel, Inc.
*! -----------------------------------------------------------------------------**
*! 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
......@@ -46,7 +46,7 @@
extern unsigned long this_frame;
extern int autoexposure_debug;
int initFilesMmap(void);
int initFilesMmap(int sensor_port);
int initParams(int daemon_bit);
......
......@@ -46,7 +46,7 @@ int exposureHDR (int frame, int target_frame) {
int vexpos, vexpos_HDR;
int rslt;
if (!((HDR_mode=framePars[target_frame8].pars[P_HDR_DUR]))) return 0; /// HDR mode is disabled
MDF5(fprintf(stderr,"frame=0x%x target_frame=0x%x GLOBALPARS(G_THIS_FRAME)=0x%x\n",(int) frame, (int) target_frame, (int)GLOBALPARS(G_THIS_FRAME)));
MDF5(fprintf(stderr,"frame=0x%x target_frame=0x%x GLOBALPARS_SNGL(G_THIS_FRAME)=0x%x\n",(int) frame, (int) target_frame, (int)GLOBALPARS_SNGL(G_THIS_FRAME)));
if ((HDR_mode<1) || (HDR_mode>2)) {
ELP_FERR(fprintf(stderr, "Wrong HDR mode %d (only 1 or 2 are supported)\n",HDR_mode));
......@@ -129,7 +129,7 @@ int exposureHDR (int frame, int target_frame) {
int skipHDR(int mode, unsigned long frame) {
int patt;
int skip;
MDF5(fprintf(stderr,"mode=%d frame=0x%x GLOBALPARS(G_THIS_FRAME)=0x%x\n",(int) mode, (int) frame, (int)GLOBALPARS(G_THIS_FRAME)));
MDF5(fprintf(stderr,"mode=%d frame=0x%x GLOBALPARS_SNGL(G_THIS_FRAME)=0x%x\n",(int) mode, (int) frame, (int)GLOBALPARS_SNGL(G_THIS_FRAME)));
switch (mode) {
case 0: return 0;
......@@ -151,6 +151,6 @@ int skipHDR(int mode, unsigned long frame) {
// lseek(fd_histogram_cache, skip, SEEK_CUR); /// just wait until the Y histogram will available for non-HDR frame
// lseek(fd_histogram_cache, skip-1, SEEK_CUR); /// just wait until the Y histogram will available for non-HDR frame
lseek(fd_histogram_cache, skip, SEEK_CUR); /// just wait until the Y histogram will available for non-HDR frame
MDF5(fprintf(stderr,"mode=%d frame=0x%x skip=%d GLOBALPARS(G_THIS_FRAME)=0x%x\n",(int) mode, (int) frame, (int) skip, (int)GLOBALPARS(G_THIS_FRAME)));
MDF5(fprintf(stderr,"mode=%d frame=0x%x skip=%d GLOBALPARS_SNGL(G_THIS_FRAME)=0x%x\n",(int) mode, (int) frame, (int) skip, (int)GLOBALPARS_SNGL(G_THIS_FRAME)));
return 1;
}
File added
......@@ -57,7 +57,7 @@
const char MCP98242_LT=0x5;
const char MCP98242_RESOL=0x8;
int initFrameParsMmap(void);
int initFrameParsMmap(int sensor_port);
long long getNowTime(void);
int readTemperature(int indx);
int setResolution(int indx);
......@@ -65,30 +65,40 @@ int setResolution(int indx);
int main (int argc, char *argv[]) {
int daemon_bit=DAEMON_BIT_TEMPERATURE;
int sensor_port = 0;
// int rslt;
// unsigned long prev_seconds=0,prev_useconds=0;
// int delta_msec;
// unsigned long next_frame;
const char usage[]= "Usage:\n%s [-b <daemon_bit_number> | -nodaemon [-d <debug_bits>]]\n\n"
const char usage[]= "Usage:\n%s <sensor_port> [-b <daemon_bit_number> | -nodaemon [-d <debug_bits>]]\n\n"
"Start temperature measurement daemon, bind it to bit <daemon_bit_number> (0..31, defaults to %d) in P_DAEMON_EN (ELPHEL_DAEMON_EN in PHP).\n"
"-nodaemon makes the program update temperatures once and exit.\n"
"Optional debug_bits (hex number) enable different groups of debug messages (1 group per bit) to stderr.\n\n";
if (argc < 2) {
printf (usage,argv[0],daemon_bit);
return 0;
}
sensor_port=strtol(argv[1], NULL, 10);
if ((sensor_port < 0) || (sensor_port >= SENSOR_PORTS)) {
printf ("Invalid port number\n\n");
printf (usage,argv[0],daemon_bit);
return 0;
}
if (argc < 3) {
daemon_bit=DAEMON_BIT_TEMPERATURE;
} else if (strcasecmp(argv[1], "-nodaemon")==0) {
} else if (strcasecmp(argv[2], "-nodaemon")==0) {
daemon_bit=-1;
} else if ((argc < 3) || ((strcasecmp(argv[1], "-b") && (strcasecmp(argv[1], "-d"))))) {
} else if ((argc < 4) || ((strcasecmp(argv[2], "-b") && (strcasecmp(argv[2], "-d"))))) {
printf (usage,argv[0],daemon_bit);
return 0;
} else {
daemon_bit=strtol(argv[2], NULL, 10);
daemon_bit=strtol(argv[3], NULL, 10);
}
if ((argc >=2) && (strcasecmp(argv[argc-2], "-d")==0)) {
if ((argc >=3) && (strcasecmp(argv[argc-2], "-d")==0)) {
temperature_debug=strtol(argv[argc-1], NULL, 16);
} else temperature_debug=1;
......@@ -97,9 +107,9 @@ int main (int argc, char *argv[]) {
if (daemon_bit>31) {printf ("Invalid bit number %d (should be 0..31)\n", daemon_bit); exit (1);}
if (daemon_bit>=0) fprintf(stderr,"Temperature monitor started, daemon_bit=0x%x\n",daemon_bit);
else fprintf(stderr,"Temperature monitor in no-daemon mode (single run)\n");
if (initFrameParsMmap()<0) exit (1); /// initialization errors
if (initFrameParsMmap(sensor_port)<0) exit (1); /// initialization errors
// lseek(fd_fparmsall,10+LSEEK_FRAME_WAIT_ABS, SEEK_END); /// skip 3 frames (first got 0 pixels, 2- 0x3fff) - one extra, sometimes it is needed
tempData= (short *) &(GLOBALPARS(G_TEMPERATURE01)); // 2 32-bit words
tempData= (short *) &(GLOBALPARS_SNGL(G_TEMPERATURE01)); // 2 32-bit words
now=getNowTime();
int numTemperatureDevices=0;
......@@ -133,16 +143,16 @@ int main (int argc, char *argv[]) {
/// Main loop
int i;
thatTime=now;
thatFrame=GLOBALPARS(G_THIS_FRAME);
thatFrame=GLOBALPARS_SNGL(G_THIS_FRAME);
// sleep one frame or until enabled
lseek(fd_fparmsall, LSEEK_FRAME_WAIT_REL+1, SEEK_END); /// skip 1 frame before returning (wait up to 255 frames with such command)
while (1) {
MDF6(fprintf(stderr,"Waiting for temperature daemon to be enabled, frame=%ld\n",GLOBALPARS(G_THIS_FRAME)));
MDF6(fprintf(stderr,"Waiting for temperature daemon to be enabled, frame=%ld\n",GLOBALPARS_SNGL(G_THIS_FRAME)));
lseek(fd_fparmsall, LSEEK_DAEMON_FRAME+daemon_bit, SEEK_END); /// wait for temperature daemon to be enabled (let it sleep if not)
now=getNowTime();
MDF3(fprintf(stderr,"Now is %d ms. due is %d ms \n",(int)((now/((long long)1000)) & 0x7fffffff),(int)((due_time/((long long)1000)) & 0x7fffffff)));
thisFrame=GLOBALPARS(G_THIS_FRAME);
thisFrame=GLOBALPARS_SNGL(G_THIS_FRAME);
if (now>=due_time){
MDF3(fprintf(stderr," It is due!\n"));
......@@ -190,15 +200,15 @@ int main (int argc, char *argv[]) {
long long getNowTime(void){
lseek(fd_fparmsall, LSEEK_GET_FPGA_TIME, SEEK_END); /// get FPGA time
long long result=GLOBALPARS(G_SECONDS);
long long result=GLOBALPARS_SNGL(G_SECONDS);
result*=1000000;
result+=GLOBALPARS(G_MICROSECONDS);
MDF4(fprintf(stderr,"getNowTime(): %ld.%06ld, result=%d, == %d ms\n",GLOBALPARS(G_SECONDS),GLOBALPARS(G_MICROSECONDS), (int) (result & 0x7fffffff), (int) ((result/((long long) 1000)) & 0x7fffffff)));
result+=GLOBALPARS_SNGL(G_MICROSECONDS);
MDF4(fprintf(stderr,"getNowTime(): %ld.%06ld, result=%d, == %d ms\n",GLOBALPARS_SNGL(G_SECONDS),GLOBALPARS_SNGL(G_MICROSECONDS), (int) (result & 0x7fffffff), (int) ((result/((long long) 1000)) & 0x7fffffff)));
return result;
}
int readTemperature(int indx){
MDF2(fprintf(stderr, "Measuring temperature data for index=%d, frame # %ld, slaves[index]=%d\n",indx,GLOBALPARS(G_THIS_FRAME),slaves[indx]));
MDF2(fprintf(stderr, "Measuring temperature data for index=%d, frame # %ld, slaves[index]=%d\n",indx,GLOBALPARS_SNGL(G_THIS_FRAME),slaves[indx]));
int result=-1;
int devfd,ctlfd;
......@@ -267,7 +277,7 @@ int main (int argc, char *argv[]) {
close (ctlfd);
}
close (devfd);
MDF1(fprintf(stderr,"Temperature data for index=%d is 0x%x, frame # %ld\n",indx, result, GLOBALPARS(G_THIS_FRAME)));
MDF1(fprintf(stderr,"Temperature data for index=%d is 0x%x, frame # %ld\n",indx, result, GLOBALPARS_SNGL(G_THIS_FRAME)));
return result;
/*
......@@ -299,14 +309,14 @@ MDF2(fprintf(stderr, "Measuring temperature failed\n"));
close (ctlfd);
}
close (devfd);
MDF2(fprintf(stderr,"Temperature data for index=%d is 0x%x, frame # %ld\n",indx, result, GLOBALPARS(G_THIS_FRAME)));
MDF2(fprintf(stderr,"Temperature data for index=%d is 0x%x, frame # %ld\n",indx, result, GLOBALPARS_SNGL(G_THIS_FRAME)));
return result;
*/
}
int setResolution(int indx){
MDF2(fprintf(stderr, "Setting full temperature resolution for index=%d, frame # %ld, slaves[index]=%d\n",indx,GLOBALPARS(G_THIS_FRAME),slaves[indx]));
MDF2(fprintf(stderr, "Setting full temperature resolution for index=%d, frame # %ld, slaves[index]=%d\n",indx,GLOBALPARS_SNGL(G_THIS_FRAME),slaves[indx]));
int devfd,ctlfd;
unsigned char data8[2];
if (indx<1) return 0; // no resolution settings fro system temperature, only for SFE
......@@ -348,8 +358,13 @@ MDF2(fprintf(stderr, "Measuring temperature failed\n"));
* uses global variables for files and mmap-ed data so they are accessible everywhere
* @return 0 - OK, <0 - problems opening/mma-ing
*/
int initFrameParsMmap(void) {
const char framepars_driver_name[]="/dev/frameparsall";
int initFrameParsMmap(int sensor_port) {
const char *framepars_dev_names[SENSOR_PORTS] = {
DEV393_PATH(DEV393_FRAMEPARS0),
DEV393_PATH(DEV393_FRAMEPARS1),
DEV393_PATH(DEV393_FRAMEPARS2),
DEV393_PATH(DEV393_FRAMEPARS3)};
const char *framepars_driver_name=framepars_dev_names[sensor_port];
///Frame parameters file open/mmap (read/write)
fd_fparmsall= open(framepars_driver_name, O_RDWR);
if (fd_fparmsall <0) {
......
......@@ -44,7 +44,9 @@
#include <sys/mman.h> /* mmap */
#include <sys/ioctl.h>
#include <asm/elphel/c313a.h>
#include <elphel/c313a.h>
#include <elphel/x393_devices.h>
//#include <asm/elphel/exifa.h>
#include <asm/byteorder.h>
......
......@@ -58,7 +58,7 @@
#include "autoexposure.h"
void initWhiteBalanceCorr(void) {
GLOBALPARS(G_NEXT_WB_FRAME)=0;
GLOBALPARS_SNGL(G_NEXT_WB_FRAME)=0;
}
#define MIN_LEVEL_TO_ADJUST 0x1000 /// 1/16 of the full scale
#define MIN_PIXELS_TO_ADJUST 0x100 /// one 32x32 block, 1 color
......@@ -74,7 +74,7 @@ void initWhiteBalanceCorr(void) {
/// TODO: SupportT P_WB_MASK - now it is just ON/OFF. NOTE:When the bit is off it should be scaled with the G1 color!
int whiteBalanceCorr(int frame, int target_frame, int ae_rslt) {
MDF3(fprintf(stderr,"frame=0x%x, target_frame=0x%x G_WB_INTEGERR=0x%08lx\n",frame,target_frame,GLOBALPARS(G_WB_INTEGERR))); ///======= 0 here
MDF3(fprintf(stderr,"frame=0x%x, target_frame=0x%x G_WB_INTEGERR=0x%08lx\n",frame,target_frame,GLOBALPARS_SNGL(G_WB_INTEGERR))); ///======= 0 here
int rslt;
int colors;
unsigned long write_data[18];
......@@ -101,7 +101,7 @@ int whiteBalanceCorr(int frame, int target_frame, int ae_rslt) {
int wb_period_nochange=(framePars[target_frame8].pars[P_WB_PERIOD] >> 8 ) & 0xff; /// next byte
int wb_dont_sync= (framePars[target_frame8].pars[P_WB_PERIOD] & 0x10000); /// don't try to synchronize to availble histograms
int aerr=0; // just to keep compiler happy
// int * wb_err= (int *) &(GLOBALPARS(G_WB_INTEGERR)); /// so it will be signed
// int * wb_err= (int *) &(GLOBALPARS_SNGL(G_WB_INTEGERR)); /// so it will be signed
static int wb_err[4]; /// individual per-color. Maybe make visible outside? Or not?
if (!wb_period_change) wb_period_change= DEFAULT_WB_PERIOD_CHANGE;
......@@ -109,11 +109,11 @@ int whiteBalanceCorr(int frame, int target_frame, int ae_rslt) {
if (!((colors=framePars[target_frame8].pars[P_WB_CTRL] & 0x0f)) || !(framePars[target_frame8].pars[P_WB_CTRL] & (1<<WB_CTRL_BIT_EN))) {
GLOBALPARS(G_NEXT_WB_FRAME)=frame+wb_period_change;
GLOBALPARS_SNGL(G_NEXT_WB_FRAME)=frame+wb_period_change;
return 0; /// white balance is off (mask==0)
}
if (GLOBALPARS(G_NEXT_WB_FRAME) > frame) return 0; /// too early to bother
MDF3(fprintf(stderr,"G_WB_INTEGERR=0x%08lx\n",GLOBALPARS(G_WB_INTEGERR))); ///======= 0 here
if (GLOBALPARS_SNGL(G_NEXT_WB_FRAME) > frame) return 0; /// too early to bother
MDF3(fprintf(stderr,"G_WB_INTEGERR=0x%08lx\n",GLOBALPARS_SNGL(G_WB_INTEGERR))); ///======= 0 here
colors |= (1 << COLOR_Y_NUMBER);
/// Get the histogram (including percentiles)
lseek(fd_histogram_cache, LSEEK_HIST_WAIT_C, SEEK_END); /// wait for all histograms, not just Y (G1)
......@@ -126,7 +126,7 @@ int whiteBalanceCorr(int frame, int target_frame, int ae_rslt) {
if (histogram_cache[hist_index].frame < (frame-1)) { /// histogram is too old - try again
GLOBALPARS(G_NEXT_WB_FRAME)=frame+1;
GLOBALPARS_SNGL(G_NEXT_WB_FRAME)=frame+1;
if (wb_dont_sync) return 0; /// will request histogram for this frame
/// repeat up to 8 times trying to get a fresh histogram
for (i=0; i<8; i++) {
......@@ -138,7 +138,7 @@ int whiteBalanceCorr(int frame, int target_frame, int ae_rslt) {
if (histogram_cache[hist_index].frame == (frame-1)) break;
}
if (histogram_cache[hist_index].frame < (frame-1)) { /// histogram is too old - try again
GLOBALPARS(G_NEXT_WB_FRAME)=frame+1;
GLOBALPARS_SNGL(G_NEXT_WB_FRAME)=frame+1;
return 0; /// will request histogram for this frame
}
}
......@@ -295,7 +295,7 @@ int whiteBalanceCorr(int frame, int target_frame, int ae_rslt) {
}
rslt=write(fd_fparmsall, write_data, (i << 2));
if (rslt < (i << 2)) return -errno;
GLOBALPARS(G_NEXT_WB_FRAME)=frame+framePars[target_frame8].pars[P_WB_PERIOD]; /// modify overall next_frame
GLOBALPARS_SNGL(G_NEXT_WB_FRAME)=frame+framePars[target_frame8].pars[P_WB_PERIOD]; /// modify overall next_frame
return 1;
/// TODO: add error integration, don't rush for instant changes?
......
#!/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-autoexposure -c cleansstate
bitbake apps-autoexposure -c unpack -f
bitbake apps-autoexposure -c configure -f
./used_files.py sysroots -1
bitbake apps-autoexposure -c compile -f
./used_files.py sysroots 1473297567.42
eyesis@eyesis-SH87R:~/git/elphel393/rootfs-elphel/elphel-apps-autoexposure$ ./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-autoexposure$ ./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