统一跨平台时间函数接口。

This commit is contained in:
xinyang
2019-07-31 14:51:01 +08:00
parent 01882b97c6
commit 98bc5ef95b
23 changed files with 87 additions and 95 deletions

View File

@@ -6,8 +6,8 @@
#define _ADDITIONS_H_
#include <stdint.h>
#include <sys/time.h>
#include <serial/serial.h>
#include <systime.h>
#include <serial.h>
#include <opencv2/core.hpp>
struct mcu_data {
@@ -41,7 +41,7 @@ void extract(cv::Mat &gimbal_src, cv::Mat &chassis_src);
void extract(cv::Mat &gimbal_src);
double getTimeIntervalms(const timeval &now, const timeval &last);
float getTimeIntervalms(const systime &now, const systime &last);
template<class type, int length>
class RoundQueue {

View File

@@ -7,7 +7,7 @@
#ifndef VIDEO_TEST1_CAMERA_WRAPPER_H
#define VIDEO_TEST1_CAMERA_WRAPPER_H
#include <additions/additions.h>
#include <additions.h>
#include <opencv2/core/core.hpp>
#include <camera/wrapper_head.h>

23
others/include/systime.h Normal file
View File

@@ -0,0 +1,23 @@
//
// Created by xinyang on 19-7-31.
//
#ifndef _PLATFORM_H_
#define _PLATFORM_H_
typedef struct{
int second;
int millisecond;
} systime;
void getsystime(systime &t);
#if defined(Linux)
#include <sys/time.h>
#elif defined(Windows)
#include <Windows.h>
#else
#error "nonsupport platform."
#endif
#endif /* _PLATFORM_H_ */

View File

@@ -9,7 +9,7 @@
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/videoio/videoio_c.h>
#include <additions/additions.h>
#include <additions.h>
#include <camera/camera_wrapper.h>
#include <energy/energy.h>
#include <armor_finder/armor_finder.h>
@@ -170,6 +170,6 @@ void extract(cv::Mat &gimbal_src) {//图像预处理将视频切成640×480
}
}
double getTimeIntervalms(const timeval& now, const timeval &last){
return (now.tv_sec-last.tv_sec)*1000.0 + (now.tv_usec-last.tv_usec)/1000.0;
float getTimeIntervalms(const systime &now, const systime &last){
return (now.second-last.second)*1000.0 + (now.millisecond-last.millisecond);
}

View File

@@ -4,8 +4,8 @@
#include <iostream>
#include <camera/camera_wrapper.h>
#include <log.h>
#include <additions/additions.h>
#include <options/options.h>
#include <additions.h>
#include <options.h>
#include <config/setconfig.h>
using namespace std;
@@ -86,35 +86,7 @@ bool CameraWrapper::init() {
CameraLoadParameter(h_camera, PARAMETER_TEAM_A);
CameraSetAeState(h_camera, false);
CameraSetExposureTime(h_camera, CAMERA_EXPOSURE * 1000);
#ifndef WITH_TIME_BASED_CAMERA_GAIN
CameraSetAnalogGain(h_camera, gain);
#else
#include <sys/time.h>
timeval tv;
int gain;
gettimeofday(&tv, nullptr);
float hour = (tv.tv_sec % (3600 * 24)) / 3600.0;
if (6 <= hour && hour < 10) {
gain = 20;
LOGM("Set gain to morning 20");
} else if (10 <= hour && hour < 16) {
gain = 10;
LOGM("Set gain to day 10");
} else if (16 <= hour && hour < 17) {
gain = 20;
LOGM("Set gain to early evening 20");
} else if (17 <= hour && hour < 18) {
gain = 40;
LOGM("Set gain to evening 40");
} else {
gain = 50;
LOGM("Set gain to early night 50");
}
CameraSetAnalogGain(h_camera, gain);
#endif
#endif
double t;
int g;
@@ -204,10 +176,10 @@ bool CameraWrapper::readProcessed(cv::Mat &src) {
}
bool CameraWrapper::readCallback(cv::Mat &src) {
timeval ts, te;
gettimeofday(&ts, NULL);
systime ts, te;
getsystime(ts);
while(src_queue.empty()){
gettimeofday(&te, NULL);
getsystime(te);
if(getTimeIntervalms(te, ts) > 500){
return false;
}

View File

@@ -2,7 +2,7 @@
// Created by xinyang on 19-3-27.
//
#include <options/options.h>
#include <options.h>
#include <log.h>
#include <cstring>

View File

@@ -1,5 +1,5 @@
#include <serial/serial.h>
#include <options/options.h>
#include <serial.h>
#include <options.h>
#include <iostream>
//#define LOG_LEVEL LOG_NONE