Commit 99b601c4 authored by Andrey Filippov's avatar Andrey Filippov

initial commit - cloned from NC353

parents
html/*
attic/*
/.project
/.cproject
/.pydevproject
/.externalToolBuilders
/.settings
.directory
generated*
sysroots
bitbake-logs
/temp/
This diff is collapsed.
# elphel-apps-autoexposure
#!/bin/bash
args="$@"
while (( "$#" )); do
shift
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Launching bitbake $args"
cd $DIR/../../poky
. ./oe-init-build-env
bitbake $args | sed -u 's@| @@'
exit 0
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
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)
clean:
rm -rf $(PROGS) *.o core
configsubs:
This diff is collapsed.
/*!***************************************************************************
*! FILE NAME : aexp_corr.h
*! DESCRIPTION: Autoexposure part of the autoexposure/white balance/hdr daemon
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: aexp_corr.h,v $
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.2 2008/11/18 19:30:16 elphel
*! Added initialization of the "next" frame - otherwise it wait _very_ long if the camera frame number is reset
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*!
*/
#ifndef __H_AUTOEXPOSURE_AEXP_CORR__
#define __H_AUTOEXPOSURE_AEXP_CORR__
void initAexpCorr(void);
int aexpCorr(int color, int frame, int target_frame);
#endif
This diff is collapsed.
/*!***************************************************************************
*! FILE NAME : aexp_utils.h
*! DESCRIPTION: Daemon to adjust camera exposure and white balance
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: aexp_utils.h,v $
*! Revision 1.2 2008/12/01 02:32:48 elphel
*! Updated white balance to use new gains
*!
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*!
*/
#ifndef __H_AUTOEXPOSURE_AEXP_UTILS__
#define __H_AUTOEXPOSURE_AEXP_UTILS__
unsigned long get_imageParamsThat (int indx, unsigned long frame);
int get_imageParamsThatValid(int indx, unsigned long frame);
int setGammaIndex(int color);
long getPercentile(unsigned long frame,int color, unsigned long fraction,int request_colors);
int recalibrateDim(void);
unsigned long gammaDirect (unsigned long x);
unsigned long gammaReverse (unsigned long x);
int waitRequstPrevHist(unsigned long next_frame);
int poorLog(int x);
int poorExp(int x);
#define get_imageParamsThis(x) ( framePars[this_frame & PARS_FRAMES_MASK].pars[x])
#endif
This diff is collapsed.
/*!***************************************************************************
*! FILE NAME : autoexposure.h
*! DESCRIPTION:
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: autoexposure.h,v $
*! Revision 1.2 2009/02/25 17:47:51 spectr_rain
*! removed deprecated dependency
*!
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*/
#ifndef __H_AUTOEXPOSURE__
#define __H_AUTOEXPOSURE__
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
//#include <ctype.h>
//#include <getopt.h>
#include <time.h>
#include <string.h>
#include <syslog.h>
#include <netinet/in.h>
#include <sys/mman.h> /* mmap */
#include <sys/ioctl.h>
#include <asm/elphel/c313a.h>
#include <asm/elphel/exifa.h>
#include <asm/byteorder.h>
#include "aexp_utils.h"
#include "aexp_corr.h"
#include "white_balance.h"
#include "hdr_control.h"
#include "globalsinit.h"
//#if ELPHEL_DEBUG
#define THIS_DEBUG 1
//#else
// #define THIS_DEBUG 0
//#endif
//#define ELP_FERR(x) printf(stderr,"%s:%d:%s: ERROR ",__FILE__,__LINE__,__FUNCTION__); x
#if THIS_DEBUG
#define MDF0(x) { if (autoexposure_debug & (1 << 0)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF1(x) { if (autoexposure_debug & (1 << 1)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF2(x) { if (autoexposure_debug & (1 << 2)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
// #define MDF2(x)
#define MDF3(x) { if (autoexposure_debug & (1 << 3)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
// #define MDF3(x)
#define MDF4(x) { if (autoexposure_debug & (1 << 4)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF5(x) { if (autoexposure_debug & (1 << 5)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF6(x) { if (autoexposure_debug & (1 << 6)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF7(x) { if (autoexposure_debug & (1 << 7)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#else
#define MDF0(x)
#define MDF1(x)
#define MDF2(x)
#define MDF3(x)
#define MDF4(x)
#define MDF5(x)
#define MDF6(x)
#define MDF7(x)
#endif
#define START_SKIP_FRAMES 8 // don't try autoexposure until this number of frames after startup
#define get_imageParamsThis(x) ( framePars[this_frame & PARS_FRAMES_MASK].pars[x])
#define min(x,y) ((x<y)?x:y)
//#define get_imageParamsThis(x) ( framePars[this_frame & PARS_FRAMES_MASK].pars[x])
#define RECALIBRATE_AHEAD 3 // Darken frame 3 ahead of current to measure histograms
#define EXPOS_AHEAD 3 // minimal frames ahead of the current to set VEXPOS
#define DEFAULT_AE_PERIOD_CHANGE 4
#define DEFAULT_AE_PERIOD_NOCHANGE 1
#define DEFAULT_WB_PERIOD_CHANGE 16
#define DEFAULT_WB_PERIOD_NOCHANGE 4
#define RECALIBRATE_AFTER 2 // number of dim frames
#define DEFAULT_BLACK_CALIB 0xa00
#define HDR_PATTERN1_8 0xaa
#define HDR_PATTERN2_8 0x66
#define HDR_PATTERN1 (HDR_PATTERN1_8 | (HDR_PATTERN1_8 << 8) | (HDR_PATTERN1_8 << 16) | (HDR_PATTERN1_8 << 24))
#define HDR_PATTERN2 (HDR_PATTERN2_8 | (HDR_PATTERN2_8 << 8) | (HDR_PATTERN2_8 << 16) | (HDR_PATTERN2_8 << 24))
#define DEFAULT_WB_WHITELEV 0xfae1 // 98%
#define DEFAULT_WB_WHITEFRAC 0x028f // 1%
#define PERCENTILE_SHIFT 16
#define PERCENTILE_1 (1 << PERCENTILE_SHIFT)
#endif
/*!***************************************************************************
*! FILE NAME : globalsinit.c
*! DESCRIPTION: Opens files, mmap-s data structures, initializes variables
*! For the autoexposure daemon
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: globalsinit.c,v $
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.2 2008/11/18 19:30:16 elphel
*! Added initialization of the "next" frame - otherwise it wait _very_ long if the camera frame number is reset
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*!
*/
#include "autoexposure.h"
int fd_fparmsall, fd_histogram_cache, fd_gamma_cache;
struct framepars_all_t *frameParsAll;
struct framepars_t *framePars;
unsigned long *globalPars;
struct framepars_past_t *pastPars;
struct histogram_stuct_t * histogram_cache; /// array of histograms
/// gamma cache is needed to re-linearize the data
struct gamma_stuct_t * gamma_cache; /// array of gamma structures
int hist_index; /// to preserve it between calls
int gamma_index; /// to preserve it between calls
int aex_recover_cntr;
unsigned long this_frame;
int autoexposure_debug;
/**
* @brief open required files, mmap theurt data structures
* 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";
///Frame parameters file open/mmap (read/write)
fd_fparmsall= open(framepars_driver_name, O_RDWR);
if (fd_fparmsall <0) {
ELP_FERR(fprintf(stderr, "Open failed: (%s)\r\n", framepars_driver_name));
return -1;
}
frameParsAll = (struct framepars_all_t *) mmap(0, sizeof (struct framepars_all_t) * HISTOGRAM_CACHE_NUMBER , PROT_READ | PROT_WRITE, MAP_SHARED, fd_fparmsall, 0);
if((int) frameParsAll == -1) {
ELP_FERR(fprintf(stderr, "problems with mmap: %s\n", framepars_driver_name));
close (fd_fparmsall);
return -1;
}
framePars = frameParsAll->framePars;
pastPars = frameParsAll->pastPars;
globalPars= frameParsAll->globalPars;
///Histogrames file open/mmap (readonly)
fd_histogram_cache= open(histogram_driver_name, O_RDONLY);
if (fd_histogram_cache <0) {
ELP_FERR(fprintf(stderr, "Open failed: (%s)\r\n", histogram_driver_name));
close (fd_fparmsall);
return -1;
}
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) {
ELP_FERR(fprintf(stderr, "problems with mmap: %s\n", histogram_driver_name));
close (fd_fparmsall);
close (fd_histogram_cache);
return -1;
}
///Gamma tables file open/mmap (readonly)
fd_gamma_cache= open(gamma_driver_name, O_RDWR);
if (fd_gamma_cache <0) {
ELP_FERR(fprintf(stderr, "Open failed: (%s)\r\n", gamma_driver_name));
close (fd_fparmsall);
close (fd_histogram_cache);
return -1;
}
gamma_cache = (struct gamma_stuct_t *) mmap(0, sizeof (struct gamma_stuct_t) * GAMMA_CACHE_NUMBER , PROT_READ, MAP_SHARED, fd_gamma_cache, 0);
if((int) gamma_cache == -1) {
ELP_FERR(fprintf(stderr, "problems with mmap: %s\n", gamma_driver_name));
close (fd_fparmsall);
close (fd_histogram_cache);
close (fd_gamma_cache);
return -1;
}
return 0; /// All initialized
}
/**
* @brief give a chance for other applications to initialize P_* parameters related to autoexposure functionality
* so the daemon itself can be started early
* @return just 0 for now
*/
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);
return 1 ; /// used default, no real calibration
}
//#define P_AUTOEXP_EXP_MAX 81 //unsigned long exp_max; /* 100 usec == 1 etc... */
initAexpCorr();
initWhiteBalanceCorr();
return 0;
}
/*!***************************************************************************
*! FILE NAME : globalsinit.h
*! DESCRIPTION: Daemon to adjust camera exposure and white balance
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: globalsinit.h,v $
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*!
*/
#ifndef __H_AUTOEXPOSURE_GLOBALSINIT__
#define __H_AUTOEXPOSURE_GLOBALSINIT__
/// Global variables
extern int fd_fparmsall;
extern int fd_histogram_cache;
extern int fd_gamma_cache;
extern struct framepars_all_t * frameParsAll;
extern struct framepars_t * framePars;
extern unsigned long * globalPars;
extern struct framepars_past_t * pastPars;
extern struct histogram_stuct_t * histogram_cache; /// array of histograms
/// gamma cache is needed to re-linearize the data
extern struct gamma_stuct_t * gamma_cache; /// array of gamma structures
extern int hist_index; /// to preserve it between calls
extern int gamma_index; /// to preserve it between calls
extern int aex_recover_cntr;
extern unsigned long this_frame;
extern int autoexposure_debug;
int initFilesMmap(void);
int initParams(int daemon_bit);
#endif
/*!***************************************************************************
*! FILE NAME : hdr_control.c
*! DESCRIPTION: HDR part of the autoexposure/white balance/hdr daemon
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: hdr_control.c,v $
*! Revision 1.4 2011/05/20 21:42:04 elphel
*! different debug levels
*!
*! Revision 1.3 2010/12/16 16:52:15 elphel
*! working on HDR autoexposure
*!
*! Revision 1.2 2010/12/15 16:46:44 elphel
*! autoexposure correction: hdr synchronization
*!
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*!
*/
#include "autoexposure.h"
//#define P_HDR_DUR 168 // 0 - HDR 0ff, >1 - duration of same exposure (currently 1 or 2 - for free running)
//#define P_HDR_VEXPOS 169 // if less than 0x10000 - number of lines of exposure, >=10000 - relative to "normal" exposure
int exposureHDR (int frame, int target_frame) {
unsigned long write_data[4];
int target_frame8=target_frame & PARS_FRAMES_MASK;
int HDR_mode;
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)));
if ((HDR_mode<1) || (HDR_mode>2)) {
ELP_FERR(fprintf(stderr, "Wrong HDR mode %d (only 1 or 2 are supported)\n",HDR_mode));
return -1;
}
/// maybe expos (not vexpos!) was just written by autoexposure, not yet recalculated from expos to vexpos
switch (HDR_mode) {
case 1:
lseek(fd_fparmsall, frame+1 +LSEEK_FRAME_WAIT_ABS, SEEK_END);
break;
case 2:
lseek(fd_fparmsall, frame+2 +LSEEK_FRAME_WAIT_ABS, SEEK_END);
break;
}
vexpos= framePars[target_frame8].pars[P_VEXPOS];
vexpos_HDR=framePars[target_frame8].pars[P_HDR_VEXPOS];
if (vexpos_HDR>=0x10000) vexpos_HDR= (((long long) vexpos_HDR) * vexpos) >> 16;
write_data[0]= FRAMEPARS_SETFRAME;
write_data[2]= P_VEXPOS; // | FRAMEPAIR_FORCE_NEWPROC ?
/// program next two frames after target_frame
MDF1(fprintf(stderr,">>>>>HDR_mode=%d, write: %08lx %08lx %08lx %08lx\n",HDR_mode,write_data[0],write_data[1],write_data[2],write_data[3]));
switch (HDR_mode) {
case 1:
write_data[1]= target_frame+1;
write_data[3]= vexpos_HDR;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
MDF1(fprintf(stderr,"write: %08lx %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
if (rslt < sizeof(write_data)) return -errno;
write_data[1]= target_frame+2;
write_data[3]= vexpos;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) return -errno;
MDF5(fprintf(stderr,"write: %08lx %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
break;
case 2:
write_data[1]= target_frame+2;
write_data[3]= vexpos_HDR;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) return -errno;
MDF1(fprintf(stderr,"write: %08lx %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
break;
}
/// skip 2 frames from 'frame' (use absolute to add tolerance against being too late)
lseek(fd_fparmsall, frame + 2+LSEEK_FRAME_WAIT_ABS, SEEK_END);
switch (HDR_mode) {
case 1:
write_data[1]= target_frame+3;
write_data[3]= vexpos_HDR;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) return -errno;
MDF1(fprintf(stderr,"write: %08lx %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
write_data[1]= target_frame+4;
write_data[3]= vexpos;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) return -errno;
MDF1(fprintf(stderr,"write: %08lx %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
break;
case 2:
write_data[1]= target_frame+4;
write_data[3]= vexpos;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) return -errno;
MDF1(fprintf(stderr,"write: %08lx %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
break;
}
return 1;
}
/**
* @brief in HDR mode - wait until we get a histogram from a normal frame (only needed to re-sync after long delays
* uses global variables for files and mmap-ed data so they are accessible everywhere
* @return 0 - OK, <0 - problems opening/mma-ing
* BUG: Does not seem to work at all !
*/
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)));
switch (mode) {
case 0: return 0;
case 1: patt=HDR_PATTERN1;
break;
case 2: patt=HDR_PATTERN2;
break;
default: return -1;
}
patt >>= (frame & PARS_FRAMES_MASK);
if (patt & 1) return 0;
skip=0;
while (patt && !(patt & 1)) {
patt >>= 1;
skip++;
}
lseek(fd_histogram_cache, LSEEK_HIST_WAIT_Y, SEEK_END); /// wait for Y only
lseek(fd_histogram_cache, LSEEK_HIST_NEEDED + 0, SEEK_END); /// nothing needed, just waiting for some frames to be skipped
// 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)));
return 1;
}
/*!***************************************************************************
*! FILE NAME : hdr_control.h
*! DESCRIPTION: HDR part of the autoexposure/white balance/hdr daemon
*! Copyright (C) 2008 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: hdr_control.h,v $
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.1 2008/11/15 23:08:24 elphel
*! 8.0.alpha17 - split autoexposure source file
*!
*!
*/
#ifndef __H_AUTOEXPOSURE_HDR_CONTROL__
#define __H_AUTOEXPOSURE_HDR_CONTROL__
int skipHDR(int mode, unsigned long frame);
int exposureHDR (int frame, int target_frame);
#endif
This diff is collapsed.
/*!***************************************************************************
*! FILE NAME : temperature.h
*! DESCRIPTION:
*! Copyright (C) 2012 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
*! 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/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: temperature.h,v $
*! Revision 1.1 2012/04/08 04:10:36 elphel
*! rev. 8.2.2 - added temperature measuring daemon, related parameters for logging SFE and system temperatures
*!
*/
#ifndef __H_TEMPERATURE__
#define __H_TEMPERATURE__
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
//#include <ctype.h>
//#include <getopt.h>
#include <time.h>
#include <string.h>
#include <syslog.h>
#include <netinet/in.h>
#include <sys/mman.h> /* mmap */
#include <sys/ioctl.h>
#include <asm/elphel/c313a.h>
//#include <asm/elphel/exifa.h>
#include <asm/byteorder.h>
//#if ELPHEL_DEBUG
#define THIS_DEBUG 1
//#else
// #define THIS_DEBUG 0
//#endif
//#define ELP_FERR(x) printf(stderr,"%s:%d:%s: ERROR ",__FILE__,__LINE__,__FUNCTION__); x
#if THIS_DEBUG
#define MDF0(x) { if (temperature_debug & (1 << 0)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF1(x) { if (temperature_debug & (1 << 1)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF2(x) { if (temperature_debug & (1 << 2)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
// #define MDF2(x)
#define MDF3(x) { if (temperature_debug & (1 << 3)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
// #define MDF3(x)
#define MDF4(x) { if (temperature_debug & (1 << 4)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF5(x) { if (temperature_debug & (1 << 5)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF6(x) { if (temperature_debug & (1 << 6)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#define MDF7(x) { if (temperature_debug & (1 << 7)) {fprintf(stderr,"%s:%d:%s: ",__FILE__,__LINE__,__FUNCTION__);x;} }
#else
#define MDF0(x)
#define MDF1(x)
#define MDF2(x)
#define MDF3(x)
#define MDF4(x)
#define MDF5(x)
#define MDF6(x)
#define MDF7(x)
#endif
#define get_imageParamsThis(x) ( framePars[this_frame & PARS_FRAMES_MASK].pars[x])
#define min(x,y) ((x<y)?x:y)
#endif
This diff is collapsed.
/*!***************************************************************************
*! FILE NAME : white_balance.h
*! DESCRIPTION: White balance part of the autoexposure/white balance/hdr daemon
*! Copyright (C) 2008 Elphel, Inc.