Commit 6f34e998 authored by Mikhail Karpenko's avatar Mikhail Karpenko

WIP: compile parameters without errors

parent 09d720de
/**
* @file FILENAME
* @brief BRIEF DESCRIPTION
* @copyright Copyright (C) YEAR Elphel Inc.
* @file parameters.cpp
* @brief Provides interface to global camera parameters
* @copyright Copyright (C) 2017 Elphel Inc.
* @author AUTHOR <EMAIL>
*
* @par License:
......@@ -19,8 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "parameters.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
......@@ -28,15 +26,18 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
#include <string>
#include <elphel/x393_devices.h>
#include <asm/elphel/c313a.h>
#include "parameters.h"
//#include "streamer.h"
#include <iostream>
#include "streamer.h"
using namespace std;
#undef PARAMETERS_DEBUG
//#define PARAMETERS_DEBUG
//#undef PARAMETERS_DEBUG
#define PARAMETERS_DEBUG
#ifdef PARAMETERS_DEBUG
#define D(a) a
......@@ -44,23 +45,46 @@ using namespace std;
#define D(a)
#endif
Parameters *Parameters::_parameters = NULL;
Parameters::Parameters(void) {
fd_fparmsall = open("/dev/frameparsall", O_RDWR);
if(fd_fparmsall < 0)
throw("can't open /dev/frameparsall");
//! now try to mmap
frameParsAll = (struct framepars_all_t *) mmap(0, sizeof (struct framepars_all_t) , PROT_READ | PROT_WRITE , MAP_SHARED, fd_fparmsall, 0);
if((int)frameParsAll == -1)
throw("Error in mmap /dev/frameparsall");
//Parameters *Parameters::_parameters = NULL;
static const char *ctl_file_names[] = {
DEV393_PATH(DEV393_FRAMEPARS0), DEV393_PATH(DEV393_FRAMEPARS1),
DEV393_PATH(DEV393_FRAMEPARS2), DEV393_PATH(DEV393_FRAMEPARS3)
};
Parameters::Parameters(int port) {
string err_msg;
if ((port >= 0) && (port < SENSOR_PORTS)) {
sensor_port = port;
} else {
string port_str = static_cast<ostringstream &>((ostringstream() << dec << port)).str();
err_msg = "port number specified is invalid: " + port_str;
throw invalid_argument(err_msg);
}
fd_fparmsall = open(ctl_file_names[sensor_port], O_RDWR);
if (fd_fparmsall < 0) {
err_msg = "can not open " + *ctl_file_names[sensor_port];
throw std::runtime_error(err_msg);
}
frameParsAll = (struct framepars_all_t *) mmap(0,
sizeof(struct framepars_all_t), PROT_READ | PROT_WRITE, MAP_SHARED,
fd_fparmsall, 0);
if ((int) frameParsAll == -1) {
frameParsAll = NULL;
err_msg = "Error in mmap " + *ctl_file_names[sensor_port];
throw std::invalid_argument(err_msg);
}
framePars = frameParsAll->framePars;
globalPars = frameParsAll->globalPars;
}
Parameters::~Parameters(void) {
if(fd_fparmsall > 0)
if (frameParsAll != NULL) {
munmap(frameParsAll, sizeof(struct framepars_all_t));
frameParsAll = NULL;
}
if (fd_fparmsall > 0)
close(fd_fparmsall);
}
......@@ -71,7 +95,8 @@ Parameters::~Parameters(void) {
* @return parameter value
*/
unsigned long Parameters::getGPValue(unsigned long GPNumber) {
return (GPNumber >= FRAMEPAR_GLOBALS) ? GLOBALPARS(GPNumber) : framePars[GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[GPNumber];
return (GPNumber >= FRAMEPAR_GLOBALS) ? GLOBALPARS_SNGL(GPNumber) :
framePars[GLOBALPARS_SNGL(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[GPNumber];
}
/**
......@@ -80,11 +105,11 @@ unsigned long Parameters::getGPValue(unsigned long GPNumber) {
* @param value - value to set
*/
void Parameters::setGValue(unsigned long GNumber, unsigned long value) {
GLOBALPARS(GNumber) = value;
GLOBALPARS_SNGL(GNumber) = value;
}
unsigned long Parameters::getFrameValue(unsigned long FPNumber) {
return framePars[GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[FPNumber];
return framePars[GLOBALPARS_SNGL(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[FPNumber];
}
bool Parameters::daemon_enabled(void) {
......@@ -92,17 +117,5 @@ bool Parameters::daemon_enabled(void) {
}
void Parameters::setPValue(unsigned long *val_array, int count) {
/*
long target_frame = params->getGPValue(G_THIS_FRAME) + FRAMES_AHEAD_FPS;
write_data[0] = FRAMEPARS_SETFRAME;
write_data[1] = target_frame; /// wait then for that frame to be available on the output plus 2 frames for fps to be stable
write_data[2] = P_FP1000SLIM;
write_data[3] = (unsigned long)fps * 1000;
write_data[4] = P_FPSFLAGS;
write_data[5] = 3;
*/
// long rslt = write(fd_fparmsall, write_data, sizeof(write_data));
this->write(val_array, sizeof(unsigned long) * count);
}
//------------------------------------------------------------------------------
/**
* @file FILENAME
* @brief BRIEF DESCRIPTION
* @copyright Copyright (C) YEAR Elphel Inc.
* @file parameters.h
* @brief Provides interface to global camera parameters
* @copyright Copyright (C) 2017 Elphel Inc.
* @author AUTHOR <EMAIL>
*
* @par License:
......@@ -24,34 +24,21 @@
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <elphel/c313a.h>
using namespace std;
#include <asm/elphel/c313a.h>
//#define FRAMES_AHEAD_FPS 3 /// number of video frames ahead of current to frite FPS limit
//#define FRAMES_SKIP_FPS 3 /// number of video frames to wait after target so circbuf will have at least 2 frames with new fps for calculation
class Parameters {
public:
/*
enum vevent {
VEVENT0,
DAEMON_DISABLED,
FPS_CHANGE,
SIZE_CHANGE
};
*/
inline static Parameters *instance(void) {
if(_parameters == NULL)
_parameters = new Parameters();
return _parameters;
}
// inline static Parameters *instance(void) {
// if(_parameters == NULL)
// _parameters = new Parameters();
// return _parameters;
// }
Parameters(int port);
~Parameters(void);
// unsigned long get
/// interface to global camera parameters
unsigned long getGPValue(unsigned long GPNumber);
void setGValue(unsigned long GNumber, unsigned long value);
......@@ -61,15 +48,13 @@ public:
bool daemon_enabled(void);
void setPValue(unsigned long *val_array, int count);
protected:
static Parameters *_parameters;
Parameters(void);
// static Parameters *_parameters;
struct framepars_all_t *frameParsAll;
struct framepars_t *framePars;
unsigned long *globalPars;
int fd_fparmsall;
int sensor_port;
};
//extern Video *video;
#endif // _VIDEO__H_
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