some refactor
This commit is contained in:
32
others/include/additions/additions.h
Normal file
32
others/include/additions/additions.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by sjturm on 19-5-17.
|
||||
//
|
||||
|
||||
#ifndef _ADDITIONS_H_
|
||||
#define _ADDITIONS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <serial/serial.h>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <camera/wrapper_head.h>
|
||||
|
||||
#define ENEMY_BLUE 0
|
||||
#define ENEMY_RED 1
|
||||
|
||||
struct mcu_data{
|
||||
float curr_yaw;
|
||||
float curr_pitch;
|
||||
uint8_t state;
|
||||
uint8_t mark;
|
||||
uint8_t use_classifier;
|
||||
uint8_t enemy_color;
|
||||
float mark_yaw;
|
||||
float mark_pitch;
|
||||
};
|
||||
|
||||
extern mcu_data mcuData;
|
||||
|
||||
void uartReceive(Serial *pSerial);
|
||||
void initVideoWriter(cv::VideoWriter& video, const std::string &armor_filename_prefix);
|
||||
|
||||
#endif /* _ADDITIONS_H_ */
|
||||
50
others/src/additions/additions.cpp
Normal file
50
others/src/additions/additions.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Created by sjturm on 19-5-17.
|
||||
//
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <additions/additions.h>
|
||||
#include <log.h>
|
||||
#include <opencv2/videoio/videoio_c.h>
|
||||
|
||||
#define RECEIVE_LOG_LEVEL LOG_NOTHING
|
||||
|
||||
void uartReceive(Serial* pSerial) {
|
||||
char buffer[100];
|
||||
int cnt = 0;
|
||||
LOGM("data receive start!");
|
||||
while (true) {
|
||||
char byte;
|
||||
while (pSerial->ReadData((uint8_t*)&byte, 1) && byte!='\n') {
|
||||
buffer[cnt++] = byte;
|
||||
if (cnt >= 100) {
|
||||
LOG(RECEIVE_LOG_LEVEL, "data receive over flow!");
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
if (cnt == sizeof(mcuData)) {
|
||||
memcpy(&mcuData, buffer, sizeof(mcuData));
|
||||
}
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void initVideoWriter(cv::VideoWriter& video, const std::string &armor_filename_prefix){
|
||||
std::ifstream in_1(armor_filename_prefix + "cnt.txt");
|
||||
int cnt_1 = 0;
|
||||
if (in_1.is_open())
|
||||
{
|
||||
in_1 >> cnt_1;
|
||||
in_1.close();
|
||||
}
|
||||
std::string armor_file_name = armor_filename_prefix + std::to_string(cnt_1) + ".avi";
|
||||
cnt_1++;
|
||||
std::ofstream out_1(armor_filename_prefix + "cnt.txt");
|
||||
if (out_1.is_open()) {
|
||||
out_1 << cnt_1 << std::endl;
|
||||
out_1.close();
|
||||
}
|
||||
video.open(armor_file_name, CV_FOURCC('P', 'I', 'M', '1'), 90, cv::Size(640, 480), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user