adding some more logging. enableing cross compiling.

master
Steffen Pohle 3 years ago
parent 3f93d5ab9f
commit 94216b0741

@ -10,24 +10,57 @@ APP = simpleskycam
include Makefile.config
-include Makefile.rules
OBJECTS := $(OBJECTS) gui.oo main.oo error.oo \
OBJECTS := $(OBJECTS) gui.oo main.oo error.oo debug.oo \
video.oo videoframe.oo \
videodev.oo videodev-v4l2.oo videodev-dumpfile.oo videodev-simulation.oo \
videodev.oo videodev-dumpfile.oo videodev-simulation.oo \
convert.oo filter.oo detect.oo histogram.oo pid.oo \
posctl.oo json.oo configuration.oo ser.oo dng.oo debayer.oo
posctl.oo json.oo configuration.oo debayer.oo
DISTNAME=simpleskycam-$(VERSION)
DEPENDFILE=.depend
#
# add configuration for debug_angles
#
ifeq ($(DEBUG_ANGLES),1)
CPPFLAGS := $(CPPFLAGS)
OBJECTS := $(OBJECTS) debug-angles.oo
endif
#
#
# compile and use DNG files
#
ifeq ($(USE_DNG),1)
LDFLAGS := $(LDFLAGS) -ltiff
OBJECTS := $(OBJECTS) dng.oo
endif
#
#
# compile and use DNG files
#
ifeq ($(USE_SER),1)
OBJECTS := $(OBJECTS) ser.oo
endif
#
ifeq ($(TARGET),)
noconfig: configlinux help
endif
all: dep Makefile.rules $(TARGET)
all: Makefile.rules $(TARGET)
help:
echo "set up configuration"
echo " make configlinux to generate the linix build"
echo " make configcross to generate the windows build using cross tools."
echo " "
echo " make checkdumpfile to create a test tool for videodumps."
checkdumpfile: checkdumpfile.cc
@ -53,13 +86,40 @@ config: Makefile.rules
ifeq ($(USE_SVBONY),1)
echo "#define USE_SVBONY" >> config.h
endif
ifeq ($(USE_SER),1)
echo "#define USE_SER" >> config.h
endif
ifeq ($(USE_DNG),1)
echo "#define USE_DNG" >> config.h
endif
ifeq ($(USE_V4L2),1)
echo "#define USE_V4L2" >> config.h
endif
echo "" >> config.h
ifeq ($(DEBUG_ANGLES),1)
echo "#define DEBUG_ANGLES" >> config.h
endif
ifeq ($(DEBUG_POSCTL),1)
echo "#define DEBUG_POSCTL" >> config.h
endif
echo "" >> config.h
echo "#endif" >> config.h
buildwindows: clean
make configcross
make $(TARGET) -j 9
mkdir SimpleSkyCam-$(VERSION)
cp *.exe SimpleSkyCam-$(VERSION)/
cp simpleskycam.ui SimpleSkyCam-$(VERSION)/
cp README.md SimpleSkyCam-$(VERSION)/
cp ChangeLog SimpleSkyCam-$(VERSION)/
cp LICENSE SimpleSkyCam-$(VERSION)/
./copydlls.sh
./copyshare.sh
mv *.dll SimpleSkyCam-$(VERSION)/
mv share SimpleSkyCam-$(VERSION)/
$(TARGET): $(OBJECTS)
$(CPP) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LIBS)
@ -94,9 +154,6 @@ dist: clean
tar cvzf $(DISTNAME).tgz $(DISTNAME)
rm -rf $(DISTNAME)
dep:
$(CXX) -M `ls *.cc` $(CPPFLAGS) > $(DEPENDFILE)
.PHONY: all
.PHONY: count
.PHONY: clean

@ -3,7 +3,10 @@
# configurations should be made in here.
# set one of these variables to 0 to disable the function.
#
USE_SVBONY = 1
DEBUG_ANGLES = 0
USE_SVBONY = 0
USE_DNG = 0
USE_SER = 0
DEBUG_ANGLES = 1
DEBUG_POSCTL = 1

@ -0,0 +1,13 @@
include Makefile.config
TARGET = $(APP).exe
CROSSENV = /opt/W64-cross-compile/
CPP = /usr/bin/x86_64-w64-mingw32-g++
CPPFLAGS = -ggdb -Wall -O0 `PKG_CONFIG_PATH=$(CROSSENV)/lib/pkgconfig pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -DBUILD_WINDOWS=1 -Wdeprecated
INCLUDES =
LDFLAGS = -lws2_32 -ljpeg
LIBS = `PKG_CONFIG_PATH=$(CROSSENV)/lib/pkgconfig pkg-config --libs gtk+-3.0 gmodule-export-2.0` -L/usr/lib -mwindows
OBJECTS := $(OBJECTS) windows.oo

@ -1,13 +1,14 @@
include Makefile.config
USE_V4L2 = 1
TARGET = $(APP)
CPP = c++
CPPFLAGS = -std=c++11 -pg -ggdb -Wall -Werror -O0 `pkg-config --cflags gtk+-3.0 gmodule-export-2.0` -Wl,--export-dynamic -I/usr/include -DBUILD_LINUX=1
INCLUDES =
LDFLAGS =
LIBS = `pkg-config --libs gtk+-3.0 gmodule-export-2.0` -L/usr/lib -ljpeg -ltiff -pg
LIBS = `pkg-config --libs gtk+-3.0 gmodule-export-2.0` -L/usr/lib -ljpeg -pg
OBJECTS =
@ -23,13 +24,11 @@ endif
#
# add configuration for debug_angles
# add makefile configuration for svbony cams
#
ifeq ($(DEBUG_ANGLES),1)
CPPFLAGS := $(CPPFLAGS)
OBJECTS := $(OBJECTS) debug-angles.oo
ifeq ($(USE_V4L2),1)
OBJECTS := $(OBJECTS) videodev-v4l2.oo
endif
#

@ -11,7 +11,10 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef BUILD_WINDOWS
#else
#include <arpa/inet.h>
#endif
#include <string>

@ -4,7 +4,12 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#ifdef BUILD_WINDOWS
#include "windows.h"
#else
#include <arpa/inet.h>
#endif
#include "convert.h"
#include "gui.h"
@ -72,11 +77,15 @@ int convert_debug_open(uint32_t pixelformat, int srcw, int srch) {
printf ("%s:%d try to create folder\n", __FILE__, __LINE__);
// create folder
// FIXME: how to do thin on windows
#ifdef BUILD_WINDOWS
if ((mkdir (config.debugpath)) == -1) {
#else
if ((mkdir (config.debugpath, 0777)) == -1) {
#endif
printf ("%s:%d could not create debug folder.\n", __FILE__, __LINE__);
return -1;
}
if ((convert_debug_fd = creat (fullfname, 0666)) == -1) {
printf ("%s:%d could again not create file '%s'. Error:%s\n", __FILE__, __LINE__, fullfname, strerror(errno));
return -1;

@ -0,0 +1,38 @@
#!/bin/bash
CROSS_DEST_DIR=/opt/W64-cross-compile/lib
CROSS_COMPILER_DIR=/usr/x86_64-w64-mingw32/lib
CROSS_GCC_DIR=/usr/lib/gcc/x86_64-w64-mingw32/10-win32
cp -v $CROSS_COMPILER_DIR/zlib1.dll ./
# copy dll dependencys
copy_dependency() {
local I
for I in `strings $1 | grep -i '\.dll$' | grep -e "^lib"`
do
if [ -e ./$I ]
then
echo "File Exist"
elif [ -e $CROSS_COMPILER_DIR/$I ]
then
cp -v $CROSS_COMPILER_DIR/$I ./
copy_dependency $CROSS_COMPILER_DIR/$I
elif [ -e $CROSS_GCC_DIR/$I ]
then
cp -v $CROSS_GCC_DIR/$I ./
copy_dependency $CROSS_GCC_DIR/$I
elif [ -e $CROSS_DEST_DIR/$I ]
then
cp -v $CROSS_DEST_DIR/$I ./
copy_dependency $CROSS_DEST_DIR/$I
fi
done
}
copy_dependency simpleskycam.exe

@ -0,0 +1,10 @@
#!/bin/bash
CROSS_PREFIX=/opt/W64-cross-compile
mkdir share
cp -rf $CROSS_PREFIX/share/glib-2.0 share/glib-2.0
cp -rf $CROSS_PREFIX/share/gtk-2.0 share/gtk-4.0
cp -rf $CROSS_PREFIX/share/gtk-3.0 share/gtk-3.0
cp -rf $CROSS_PREFIX/share/icons share/icons

@ -0,0 +1,58 @@
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <sys/time.h>
#include <fcntl.h>
#include "debug.h"
GMutex debug_mutex;
#define LEN 2048
void debug_init() {
g_mutex_init (&debug_mutex);
}
void debug_tofile(char *fname, char *fmt, ...) {
static struct timeval tv;
static int firstrun = 1;
struct timeval tv1;
va_list args;
char buffer[LEN];
int fd, len;
long long int ms;
std::string s = setlocale(LC_ALL, NULL);
setlocale (LC_ALL, "C");
g_mutex_lock(&debug_mutex);
if (firstrun) {
gettimeofday(&tv,NULL);
firstrun = 0;
}
gettimeofday(&tv1,NULL);
ms = ((tv1.tv_sec - tv.tv_sec) * 1000) +
((tv1.tv_usec - tv.tv_usec) / 1000);
#ifdef BUILD_WINDOWS
fd = open(fname, O_WRONLY | O_APPEND | O_CREAT);
#else
fd = open(fname, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
#endif
if (fd < 0) errorexit((char*)"%s:%d could not open debug '%s' file. Error:%s\n", __FILE__, __LINE__, fname, strerror(errno));
snprintf (buffer, 32, "%lld,", ms);
len = strlen (buffer);
va_start (args, fmt);
vsnprintf (buffer+len, LEN-1-len, fmt, args);
va_end (args);
buffer[LEN-1] = 0;
write (fd, buffer, strlen(buffer));
close (fd);
g_mutex_unlock(&debug_mutex);
setlocale (LC_ALL, s.c_str());
}

@ -17,4 +17,7 @@ extern void debug_angles_motionevent(GdkEvent *event);
extern void debug_angles_btnpress(GdkEvent *event);
#endif
extern void debug_init();
extern void debug_tofile(char *fname, char *fmt, ...);
#endif

@ -1,6 +1,7 @@
#ifndef _DNG_H_
#define _DNG_H_
/*
Example usage of the class:
---------------------------

@ -4,6 +4,10 @@
*
*****************************************************************************************/
#ifndef BUILD_WINDOWS
#include <execinfo.h>
#endif
#include <string>
#include <stdlib.h>
#include <string.h>
@ -57,3 +61,42 @@ void errormessage_display (char *window, char *title, char *fmt,...) {
};
/*
* print error message and the backtrace
*/
#define SIZE 100
void errorexit (char *fmt,...) {
//
// error message
va_list args;
char text[4096];
va_start (args, fmt);
vsnprintf (text, 4096, fmt, args);
va_end (args);
printf ("***************************\n");
printf (" ERROR\n");
printf ("***************************\n");
printf ("%s", text);
//
// backtrace
int j, nptrs;
void *buffer[SIZE];
char **s;
#ifndef BUILD_WINDOWS
nptrs = backtrace(buffer, SIZE);
if ((s = (char**) backtrace_symbols(buffer, nptrs)) == NULL) {
for (j = 0; j < nptrs; j++) printf ("%-5d %p\n", j, buffer[j]);
}
else {
for (j = 0; j < nptrs; j++) printf ("%-5d %s\n", j, s[j]);
}
#endif
exit (-1);
}

@ -5,7 +5,6 @@
*****************************************************************************************/
#include <sys/time.h>
#include <execinfo.h>
#include <math.h>
#include "simpleskycam.h"
@ -15,8 +14,6 @@
#include "filter.h"
#include "detect.h"
#include "convert.h"
#include "ser.h"
#include "dng.h"
/**************************************************************************
* global variables
@ -93,41 +90,6 @@ float get_cycletime(struct timeval *t) {
}
/*
* print error message and the backtrace
*/
#define SIZE 100
void errorexit (char *fmt,...) {
//
// error message
va_list args;
char text[4096];
va_start (args, fmt);
vsnprintf (text, 4096, fmt, args);
va_end (args);
printf ("***************************\n");
printf (" ERROR\n");
printf ("***************************\n");
printf ("%s", text);
//
// backtrace
int j, nptrs;
void *buffer[SIZE];
char **s;
nptrs = backtrace(buffer, SIZE);
if ((s = (char**) backtrace_symbols(buffer, nptrs)) == NULL) {
for (j = 0; j < nptrs; j++) printf ("%-5d %p\n", j, buffer[j]);
}
else {
for (j = 0; j < nptrs; j++) printf ("%-5d %s\n", j, s[j]);
}
exit (-1);
}
void calc_vec2anglelen(position_f_2d *p, vector_2d *v) {
if (v == NULL || p == NULL) return;

@ -127,7 +127,7 @@ double PID::Update(double target, double value) {
void PID::SetParam (double mi, double ma, double p, double i, double d) {
Kp = p;
Ki = i/1000000.0;
Kd = d;
Kd = d/1000000.0;
Min = mi;
Max = ma;
Start();
@ -137,7 +137,7 @@ void PID::SetParam (double mi, double ma, double p, double i, double d) {
void PID::GetParam (double *mi, double *ma, double *p, double *i, double *d) {
if (p != NULL) *p = Kp;
if (i != NULL) *i = Ki*1000000.0;
if (d != NULL) *d = Kd;
if (d != NULL) *d = Kd*1000000.0;
if (mi != NULL) *mi = Min;
if (ma != NULL) *ma = Max;
};

@ -20,6 +20,10 @@
#include "histogram.h"
#include "error.h"
#ifdef BUILD_WINDOWS
#include "windows.h"
#endif
extern PosCtl posctl;
extern Simulation simulation;
@ -565,6 +569,11 @@ gboolean cb_thread_posctl (gpointer data) {
PosCtl::PosCtl() {
mode = POSCTL_MODE_OFF;
#ifdef DEBUG_POSCTL
debug_tofile((char*)"posctl.log", (char*)"\n");
debug_tofile((char*)"posctl.log", (char*)"mode,posX,posY,targetX,targetY,dx,dy,axis1.pv,axis1.op,axis1.kp,axis1.ki,axis1.kd,axis2.pv,axis2.op,axis2.kp,axis2.ki,axis2.kd\n");
#endif
calib_mode = POSCTL_CALIB_MODE_OFF;
device_fd = -1;
device = "";
@ -728,6 +737,13 @@ void PosCtl::CalibModeFinish() {
* Loop, if new data is aviable
*/
void PosCtl::Loop (int posx, int posy) {
#ifdef DEBUG_POSCTL
static int lastmode = -1;
double kp0,ki0,kd0, kp1,ki1,kd1;
if (lastmode != mode && mode != POSCTL_MODE_CONTROL) {
debug_tofile((char*)"posctl.log", (char*)"%d,,,,,,,,,,,,,,,,", mode);
}
#endif
//
// calibration mode?
if (mode == POSCTL_MODE_CALIB) {
@ -774,6 +790,15 @@ void PosCtl::Loop (int posx, int posy) {
axis_op[0] = pid_axis[0].Update(0.0, axis_pv[0]);
axis_op[1] = pid_axis[1].Update(0.0, axis_pv[1]);
#ifdef DEBUG_POSCTL
pid_axis[0].GetParam(NULL, NULL, &kp0, &ki0, &kd0);
pid_axis[1].GetParam(NULL, NULL, &kp1, &ki1, &kd1);
debug_tofile((char*)"posctl.log", (char*)"%d,%d,%d,%d,%d,%d,%d,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g\n",
mode, posx, posy, target_pos.x, target_pos.y, posx - target_pos.x, posy - target_pos.y,
axis_pv[0], axis_op[0],kp0,ki0,kd0,
axis_pv[1], axis_op[1],kp1,ki1,kd1);
#endif
if (OutputWriteValue(0, axis_op[0]) || OutputWriteValue(1, axis_op[1]))
mode = POSCTL_MODE_OFF;
@ -790,6 +815,10 @@ void PosCtl::Loop (int posx, int posy) {
target_pos.y = posy;
UnLockMutex();
}
#ifdef DEBUG_POSCTL
lastmode = mode;
#endif
};
@ -847,7 +876,8 @@ int PosCtl::WriteTTY (char * outbuf) {
int PosCtl::ReadTTY (char * inbuf, int length) {
ssize_t len;
// FIXME: how to use the com/usb-com port on windows.
#ifndef BUILD_WINDOWS
// make device non-blocking
fcntl(device_fd, F_SETFL, fcntl(device_fd, F_GETFL) | O_NONBLOCK);
@ -874,7 +904,7 @@ int PosCtl::ReadTTY (char * inbuf, int length) {
// make device blocking
fcntl(device_fd, F_SETFL, fcntl(device_fd, F_GETFL) & ~O_NONBLOCK);
#endif
return 0;
}
@ -886,7 +916,8 @@ int PosCtl::OutputWriteValue (int axis, double value) {
simulation.AxisSetValue(axis, value);
return 0;
}
// FIXME: how to use the com/usb-com port on windows.
#ifndef BUILD_WINDOWS
if (device_fd <= 0) if (OutputOpen() != 0) return -1;
//
@ -902,7 +933,7 @@ int PosCtl::OutputWriteValue (int axis, double value) {
WriteTTY(outbuf);
ReadTTY(outbuf, sizeof(outbuf) - 1);
#endif
return 0;
};

@ -307,7 +307,9 @@ void cb_video_btnrefreshlist (GtkWidget *widget, gpointer data) {
devlist.clear();
VideoDev_Dumpfile vdef1; vdef1.GetDeviceList(&devlist);
#ifdef USE_V4L2
VideoDev_V4L2 vdef2; vdef2.GetDeviceList(&devlist);
#endif
#ifdef USE_SVBONY
VideoDev_SVBCam vdef3; vdef3.GetDeviceList(&devlist);
#endif
@ -353,11 +355,13 @@ void cb_video_btnrec (GtkWidget *widget, gpointer data) {
//
// load the selected driver
if (driver.compare("V4L2") == 0) videodev = new VideoDev_V4L2;
if (driver.compare("VIDEODUMP") == 0) videodev = new VideoDev_Dumpfile;
#ifdef USE_V4L2
else if (driver.compare("V4L2") == 0) videodev = new VideoDev_V4L2;
#endif
#ifdef USE_SVBONY
else if (driver.compare("SVBCAM") == 0) videodev = new VideoDev_SVBCam;
#endif
else if (driver.compare("VIDEODUMP") == 0) videodev = new VideoDev_Dumpfile;
else if (driver.compare("SIMULATION") == 0) videodev = new VideoDev_Simulation;
else videodev = new VideoDev;
@ -578,7 +582,7 @@ void cb_vidctrl_scale_change (GtkRange *range, gpointer data) {
GtkWidget *grid = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "vidctrl-grid"));
GtkWidget *scale = NULL;
GtkWidget *label = NULL;
int idx = (long int)data;
int64_t idx = (int64_t)data;
double value;
label = gtk_grid_get_child_at(GTK_GRID(grid), 0, idx);
@ -597,7 +601,7 @@ void cb_vidctrl_entry_change (GtkWidget *widget, gpointer data) {
GtkWidget *grid = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "vidctrl-grid"));
GtkWidget *label = NULL;
GtkWidget *entry = NULL;
int idx = (long int)data;
int64_t idx = (int64_t)data;
int value;
label = gtk_grid_get_child_at(GTK_GRID(grid), 0, idx);
@ -789,11 +793,13 @@ void cb_video_cbox_videodev (GtkWidget *widget, gpointer data) {
//
// load the selected driver
if (driver.compare("V4L2") == 0) videodev = new VideoDev_V4L2;
if (driver.compare("DUMMY") == 0) videodev = new VideoDev;
#ifdef USE_V4L2
else if (driver.compare("V4L2") == 0) videodev = new VideoDev_V4L2;
#endif
#ifdef USE_SVBONY
else if (driver.compare("SVBCAM") == 0) videodev = new VideoDev_SVBCam;
#endif
else if (driver.compare("DUMMY") == 0) videodev = new VideoDev;
else videodev = new VideoDev;
videodev->GetDeviceFormats(device, &lst_format);

@ -11,7 +11,6 @@
#include <list>
#include <stdint.h>
#include <jpeglib.h>
#include <linux/videodev2.h>
#include <setjmp.h>
#include "json.h"

@ -16,7 +16,9 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#ifndef BUILD_WINDOWS
#include <linux/videodev2.h>
#endif
#include <list>
#include <string>

@ -15,7 +15,14 @@
#include <dirent.h>
#include <ctype.h>
#include <fcntl.h>
#ifdef BUILD_WINDOWS
#include <winsock2.h>
#include <io.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#endif
#include <sys/stat.h>
@ -66,16 +73,19 @@ int VideoDev_Dumpfile::GetDeviceList(std::list<std::string> *list) {
}
while ((de = readdir (dir))) {
#ifndef BUILD_WINDOWS
if (de->d_type & DT_REG) {
#endif
for (i = 0; i < 255 && de->d_name[i] != 0; i++) fname[i] = toupper(de->d_name[i]);
fname[i] = 0;
if (strstr (fname, ".VIDEODUMP") != NULL) {
device = (std::string) "VIDEODUMP " + (std::string) de->d_name;
list->push_back(device);
}
#ifndef BUILD_WINDOWS
}
#endif
}
closedir(dir);
return 1;

@ -10,13 +10,13 @@
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
// #include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
// #include <sys/mman.h>
// #include <linux/videodev2.h>
#include <list>
#include <string>

@ -7,10 +7,15 @@
************************************************************************************/
#include <ctype.h>
#ifdef BUILD_WINDOWS
#include "windows.h"
#else
#include <arpa/inet.h>
#endif
#include <sys/stat.h>
#include <math.h>
#include "debug.h"
#include "convert.h"
#include "configuration.h"
#include "videodev-simulation.h"
@ -191,48 +196,69 @@ Simulation::Simulation() {
posY = h/2;
running = 0;
#ifdef DEBUG_POSCTL
debug_tofile((char*)"simulation.log", (char*)"\n");
debug_tofile((char*)"simulation.log", (char*)"dAngle,dLen,x,y,dx,dy,timedelay,a1.defAngle,a1.defLen,a1.v,a1.dx,a1.dy,a2.defAngle,a2.defLen,a2.v,a2.dx,a2.dy,finalX,finalY\n");
#endif
Reset();
};
void Simulation::Reset() {
int i;
static int _first_run = 1;
LockMutex();
time_t t = time(NULL);
srandom (t);
//
// object movement
dAngle = 360.0 * (double)random() / (double) RAND_MAX;
dLen = 1.0 + 5.0 * (double)random() / (double) RAND_MAX;
printf ("%s:%d %s dAngle:%f dLen:%f\n", __FILE__, __LINE__, __FUNCTION__, dAngle, dLen);
//
// axis movement
i = 0;
axis[i % 2].defAngle = dAngle + (10.0 * (double)random() / ((double) RAND_MAX)) - 5.0;
axis[i % 2].defLen = dLen + (3.0 * (double)random() / ((double) RAND_MAX) - 1.5);
axis[i % 2].v = 1.0;
axis[i % 2].active = 1;
i++;
axis[i % 2].defAngle = dAngle + (10.0 * (double)random() / ((double) RAND_MAX)) + 85.0;
axis[i % 2].defLen = dLen + (3.0 * (double)random() / ((double) RAND_MAX) - 1.5);
axis[i % 2].v = 1.0;
axis[i % 2].active = 1;
srand (t);
if (_first_run) {
//
// object movement
dAngle = 360.0 * (double)rand() / (double) RAND_MAX;
dLen = 1.0 + 5.0 * (double)rand() / (double) RAND_MAX;
printf ("%s:%d %s dAngle:%f dLen:%f\n", __FILE__, __LINE__, __FUNCTION__, dAngle, dLen);
//
// axis movement
i = 0;
axis[i % 2].defAngle = 180.0 + dAngle + (10.0 * (double)rand() / ((double) RAND_MAX)) - 5.0;
axis[i % 2].defLen = dLen + (3.0 * (double)rand() / ((double) RAND_MAX) - 1.5);
axis[i % 2].v = 1.0;
axis[i % 2].active = 1;
i++;
axis[i % 2].defAngle = 180.0 + dAngle + (10.0 * (double)rand() / ((double) RAND_MAX)) + 85.0;
axis[i % 2].defLen = dLen + (3.0 * (double)rand() / ((double) RAND_MAX) - 1.5);
axis[i % 2].v = 1.0;
axis[i % 2].active = 1;
// normalize angle between 0..360°
for (i = 0; i < 2; i++) {
while (axis[i].defAngle < 0.0) axis[i].defAngle += 360.0;
while (axis[i].defAngle > 360.0) axis[i].defAngle -= 360.0;
}
}
else {
dAngle +=45.0;
axis[0].defAngle += 45.0;
axis[1].defAngle += 45.0;
}
printf ("%s:%d %s Axis1: %f° Len:%f Axis2: %f° Len:%f\n", __FILE__, __LINE__, __FUNCTION__,
axis[0].defAngle,axis[0].defLen, axis[1].defAngle,axis[1].defLen);
UnLockMutex();
_first_run = 0;
}
Simulation::~Simulation() {
LockMutex ();
running = 0;
UnLockMutex ();
};
@ -248,7 +274,10 @@ void Simulation::ThreadProcess() {
int r = 1;
struct timeval tv;
double ms;
double dx, dy;
double dx[3], dy[3];
#ifdef DEBUG_POSCTL
double x, y;
#endif
get_cycletime (&tv);
if (running) return;
@ -263,25 +292,40 @@ void Simulation::ThreadProcess() {
// simulate rotation movement
// calculate movement
dx = sindeg(dAngle) * dLen * ms;
dy = -cosdeg(dAngle) * dLen * ms;
posX += dx;
posY += dy;
dx[0] = sindeg(dAngle) * dLen * ms;
dy[0] = -cosdeg(dAngle) * dLen * ms;
//
// simulate motor axis movement
for (int i = 0; i < 2; i++)
if (axis[i].active) {
dx = sindeg(axis[i].defAngle) * axis[i].defLen * (1.0 + axis[i].v) * ms;
dy = -cosdeg(axis[i].defAngle) * axis[i].defLen * (1.0 + axis[i].v) * ms;
posX -= dx;
posY -= dy;
dx[i+1] = sindeg(axis[i].defAngle) * axis[i].defLen * (1.0 + axis[i].v) * ms;
dy[i+1] = -cosdeg(axis[i].defAngle) * axis[i].defLen * (1.0 + axis[i].v) * ms;
}
else {
dx[i+1] = 0.0;
dy[i+1] = 0.0;
}
// this is needed for debugging
#ifdef DEBUG_POSCTL
x = posX; y = posY;
#endif
posX = posX + dx[0] + dx[1] + dx[2];
posY = posY + dy[0] + dy[1] + dy[2];
if (posX < 0) posX = w - 1.0;
if (posY < 0) posY = h - 1.0;
if (posX > w) posX = 0.0;
if (posY > h) posY = 0.0;
#ifdef DEBUG_POSCTL
debug_tofile((char*)"simulation.log", (char*)"%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g\n",
dAngle, dLen, x, y, dx[0], dy[0], ms,
axis[0].defAngle,axis[0].defLen,axis[0].v,dx[1],dy[1],
axis[1].defAngle,axis[1].defLen,axis[1].v,dx[2],dy[2],
posX, posY
);
#endif
r = running;
UnLockMutex();
} while (r);

@ -10,13 +10,13 @@
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
//#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
//#include <sys/mman.h>
//#include <linux/videodev2.h>
#include <list>
#include <string>

@ -1,5 +1,8 @@
#include "convert.h"
#ifdef USE_V4L2
#include "videodev-v4l2.h"
VideoDev_V4L2::VideoDev_V4L2() {
@ -576,3 +579,4 @@ int VideoDev_V4L2::GetDevCtrl(unsigned int id, int *value) {
};
#endif

@ -9,14 +9,12 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <errno.h>
#include <getopt.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <jpeglib.h>
#include <list>

@ -156,9 +156,12 @@ public:
};
#include "videodev-v4l2.h"
#include "videodev-dumpfile.h"
#include "videodev-simulation.h"
#ifdef USE_V4L2
#include "videodev-v4l2.h"
#endif
#ifdef USE_SVBONY
#include "videodev-svbcam.h"
#endif

@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdarg.h>
#include "windows.h"
void strfromd (char* dest, int len, char *fmt,...) {
va_list args;
va_start (args, fmt);
vsnprintf (dest, len-1, fmt, args);
va_end (args);
dest[len-1] = 0;
}

@ -0,0 +1,69 @@
#ifndef _WINDOWS_H_
#define _WINDOWS_H_
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#define WIN32_LEAN_AND_MEAN
#define _NTDDI_VERSION_FROM_WIN32_WINNT2(ver) ver##0000
#define _NTDDI_VERSION_FROM_WIN32_WINNT(ver) _NTDDI_VERSION_FROM_WIN32_WINNT2(ver)
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x501
#endif
#ifndef NTDDI_VERSION
# define NTDDI_VERSION _NTDDI_VERSION_FROM_WIN32_WINNT(_WIN32_WINNT)
#endif
// #include <winsock.h>
#include <winsock2.h>
#include <io.h>
#include <ws2tcpip.h>
#include <string.h>
#define socklen_t size_t
#ifndef bzero
#define bzero(__z__, __x__) memset (__z__, 0x0, __x__)
#endif
#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
#endif
#endif
extern void strfromd (char* dest, int len, char *fmt,...);
#define __u32 uint32_t
/*
* since this application is ported from linux and uses some linux based definitions
* we needed to copy some of the definitions and information.
*
* the following part comes from the Video 4 Linux 2 source more details can be found
* at https://linuxtv.org.
*/
#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */
#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */
#define V4L2_PIX_FMT_VYUY v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */
#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */
#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */
#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */
#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */
#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
#define V4L2_PIX_FMT_SGRBG16 v4l2_fourcc('G', 'R', '1', '6') /* 16 GRGR.. BGBG.. */
#define v4l2_fourcc(a, b, c, d)\
((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
#define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1U << 31))
#endif
Loading…
Cancel
Save