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

WIP: compile parameters without errors

parent 09d720de
/** /**
* @file FILENAME * @file parameters.cpp
* @brief BRIEF DESCRIPTION * @brief Provides interface to global camera parameters
* @copyright Copyright (C) YEAR Elphel Inc. * @copyright Copyright (C) 2017 Elphel Inc.
* @author AUTHOR <EMAIL> * @author AUTHOR <EMAIL>
* *
* @par License: * @par License:
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "parameters.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
...@@ -28,15 +26,18 @@ ...@@ -28,15 +26,18 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.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; using namespace std;
#undef PARAMETERS_DEBUG //#undef PARAMETERS_DEBUG
//#define PARAMETERS_DEBUG #define PARAMETERS_DEBUG
#ifdef PARAMETERS_DEBUG #ifdef PARAMETERS_DEBUG
#define D(a) a #define D(a) a
...@@ -44,23 +45,46 @@ using namespace std; ...@@ -44,23 +45,46 @@ using namespace std;
#define D(a) #define D(a)
#endif #endif
//Parameters *Parameters::_parameters = NULL;
Parameters *Parameters::_parameters = NULL; static const char *ctl_file_names[] = {
DEV393_PATH(DEV393_FRAMEPARS0), DEV393_PATH(DEV393_FRAMEPARS1),
Parameters::Parameters(void) { DEV393_PATH(DEV393_FRAMEPARS2), DEV393_PATH(DEV393_FRAMEPARS3)
fd_fparmsall = open("/dev/frameparsall", O_RDWR); };
if(fd_fparmsall < 0)
throw("can't open /dev/frameparsall"); Parameters::Parameters(int port) {
//! now try to mmap string 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) if ((port >= 0) && (port < SENSOR_PORTS)) {
throw("Error in mmap /dev/frameparsall"); 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; framePars = frameParsAll->framePars;
globalPars = frameParsAll->globalPars; globalPars = frameParsAll->globalPars;
} }
Parameters::~Parameters(void) { 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); close(fd_fparmsall);
} }
...@@ -71,7 +95,8 @@ Parameters::~Parameters(void) { ...@@ -71,7 +95,8 @@ Parameters::~Parameters(void) {
* @return parameter value * @return parameter value
*/ */
unsigned long Parameters::getGPValue(unsigned long GPNumber) { 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) { ...@@ -80,11 +105,11 @@ unsigned long Parameters::getGPValue(unsigned long GPNumber) {
* @param value - value to set * @param value - value to set
*/ */
void Parameters::setGValue(unsigned long GNumber, unsigned long value) { void Parameters::setGValue(unsigned long GNumber, unsigned long value) {
GLOBALPARS(GNumber) = value; GLOBALPARS_SNGL(GNumber) = value;
} }
unsigned long Parameters::getFrameValue(unsigned long FPNumber) { 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) { bool Parameters::daemon_enabled(void) {
...@@ -92,17 +117,5 @@ bool Parameters::daemon_enabled(void) { ...@@ -92,17 +117,5 @@ bool Parameters::daemon_enabled(void) {
} }
void Parameters::setPValue(unsigned long *val_array, int count) { 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); this->write(val_array, sizeof(unsigned long) * count);
} }
//------------------------------------------------------------------------------
/** /**
* @file FILENAME * @file parameters.h
* @brief BRIEF DESCRIPTION * @brief Provides interface to global camera parameters
* @copyright Copyright (C) YEAR Elphel Inc. * @copyright Copyright (C) 2017 Elphel Inc.
* @author AUTHOR <EMAIL> * @author AUTHOR <EMAIL>
* *
* @par License: * @par License:
...@@ -24,34 +24,21 @@ ...@@ -24,34 +24,21 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <string> #include <string>
#include <elphel/c313a.h>
using namespace std; 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 { class Parameters {
public: public:
/* // inline static Parameters *instance(void) {
enum vevent { // if(_parameters == NULL)
VEVENT0, // _parameters = new Parameters();
DAEMON_DISABLED, // return _parameters;
FPS_CHANGE, // }
SIZE_CHANGE Parameters(int port);
};
*/
inline static Parameters *instance(void) {
if(_parameters == NULL)
_parameters = new Parameters();
return _parameters;
}
~Parameters(void); ~Parameters(void);
// unsigned long get
/// interface to global camera parameters /// interface to global camera parameters
unsigned long getGPValue(unsigned long GPNumber); unsigned long getGPValue(unsigned long GPNumber);
void setGValue(unsigned long GNumber, unsigned long value); void setGValue(unsigned long GNumber, unsigned long value);
...@@ -61,15 +48,13 @@ public: ...@@ -61,15 +48,13 @@ public:
bool daemon_enabled(void); bool daemon_enabled(void);
void setPValue(unsigned long *val_array, int count); void setPValue(unsigned long *val_array, int count);
protected: protected:
static Parameters *_parameters; // static Parameters *_parameters;
Parameters(void);
struct framepars_all_t *frameParsAll; struct framepars_all_t *frameParsAll;
struct framepars_t *framePars; struct framepars_t *framePars;
unsigned long *globalPars; unsigned long *globalPars;
int fd_fparmsall; int fd_fparmsall;
int sensor_port;
}; };
//extern Video *video;
#endif // _VIDEO__H_ #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