Log options
This commit is contained in:
parent
b37b336165
commit
7f14b60ba3
19
cmd/main.c
19
cmd/main.c
@ -36,6 +36,11 @@ http_server_options_t http_options = {
|
|||||||
.maxcons = 10
|
.maxcons = 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
log_options_t log_options = {
|
||||||
|
.debug = false,
|
||||||
|
.verbose = false
|
||||||
|
};
|
||||||
|
|
||||||
option_t all_options[] = {
|
option_t all_options[] = {
|
||||||
DEFINE_OPTION_PTR(camera, path, "%s"),
|
DEFINE_OPTION_PTR(camera, path, "%s"),
|
||||||
DEFINE_OPTION(camera, width, uint),
|
DEFINE_OPTION(camera, width, uint),
|
||||||
@ -46,6 +51,8 @@ option_t all_options[] = {
|
|||||||
DEFINE_OPTION(camera, allow_dma, bool),
|
DEFINE_OPTION(camera, allow_dma, bool),
|
||||||
DEFINE_OPTION(http, port, uint),
|
DEFINE_OPTION(http, port, uint),
|
||||||
DEFINE_OPTION(http, maxcons, uint),
|
DEFINE_OPTION(http, maxcons, uint),
|
||||||
|
DEFINE_OPTION(log, debug, bool),
|
||||||
|
DEFINE_OPTION(log, verbose, bool),
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,21 +67,9 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env = getenv("DEBUG")) {
|
|
||||||
log_debug = strstr(env, "1") ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
camera_init(&camera);
|
camera_init(&camera);
|
||||||
camera.options = camera_options;
|
camera.options = camera_options;
|
||||||
|
|
||||||
// //camera.width = 1920; camera.height = 1080;
|
|
||||||
// strcpy(camera.options.path, "/dev/video2"); camera.options.width = 2328; camera.options.height = 1748; camera.options.format = V4L2_PIX_FMT_SRGGB10P; // 1164x874
|
|
||||||
// //camera.width = 4656; camera.height = 3496;
|
|
||||||
// //camera.width = 3840; camera.height = 2160;
|
|
||||||
// //camera.width = 1280; camera.height = 720;
|
|
||||||
// strcpy(camera.options.path, "/dev/video0"); camera.options.width = 1920; camera.options.height = 1080; camera.options.format = V4L2_PIX_FMT_YUYV; camera.options.format = V4L2_PIX_FMT_MJPEG; camera.options.allow_dma = false;
|
|
||||||
// camera.options.nbufs = 1;
|
|
||||||
|
|
||||||
if (camera_open(&camera) < 0) {
|
if (camera_open(&camera) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include "hw/v4l2.h"
|
#include "hw/v4l2.h"
|
||||||
|
|
||||||
int log_debug = 0;
|
|
||||||
|
|
||||||
int xioctl(const char *name, int fd, int request, void *arg)
|
int xioctl(const char *name, int fd, int request, void *arg)
|
||||||
{
|
{
|
||||||
int retries = XIOCTL_RETRIES;
|
int retries = XIOCTL_RETRIES;
|
||||||
|
14
hw/v4l2.h
14
hw/v4l2.h
@ -18,23 +18,13 @@
|
|||||||
|
|
||||||
#include <linux/videodev2.h>
|
#include <linux/videodev2.h>
|
||||||
|
|
||||||
|
#include "opts/log.h"
|
||||||
|
|
||||||
#ifndef CFG_XIOCTL_RETRIES
|
#ifndef CFG_XIOCTL_RETRIES
|
||||||
# define CFG_XIOCTL_RETRIES 4
|
# define CFG_XIOCTL_RETRIES 4
|
||||||
#endif
|
#endif
|
||||||
#define XIOCTL_RETRIES ((unsigned)(CFG_XIOCTL_RETRIES))
|
#define XIOCTL_RETRIES ((unsigned)(CFG_XIOCTL_RETRIES))
|
||||||
|
|
||||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
|
||||||
|
|
||||||
extern int log_debug;
|
|
||||||
|
|
||||||
// assumes that name is first item
|
|
||||||
#define dev_name(dev) (dev ? *(const char**)dev : "?")
|
|
||||||
#define E_LOG_ERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); goto error; } while(0)
|
|
||||||
#define E_LOG_PERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); exit(-1); } while(0)
|
|
||||||
#define E_LOG_INFO(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0)
|
|
||||||
#define E_LOG_VERBOSE(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0)
|
|
||||||
#define E_LOG_DEBUG(dev, _msg, ...) do { if (log_debug) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char buf[10];
|
char buf[10];
|
||||||
} fourcc_string;
|
} fourcc_string;
|
||||||
|
20
opts/log.h
Normal file
20
opts/log.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||||
|
|
||||||
|
typedef struct log_options_s {
|
||||||
|
bool debug;
|
||||||
|
bool verbose;
|
||||||
|
} log_options_t;
|
||||||
|
|
||||||
|
extern log_options_t log_options;
|
||||||
|
|
||||||
|
// assumes that name is first item
|
||||||
|
#define dev_name(dev) (dev ? *(const char**)dev : "?")
|
||||||
|
#define E_LOG_ERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); goto error; } while(0)
|
||||||
|
#define E_LOG_PERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); exit(-1); } while(0)
|
||||||
|
#define E_LOG_INFO(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0)
|
||||||
|
#define E_LOG_VERBOSE(dev, _msg, ...) do { if (log_options.debug || log_options.verbose) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
|
||||||
|
#define E_LOG_DEBUG(dev, _msg, ...) do { if (log_options.debug) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
|
Loading…
x
Reference in New Issue
Block a user