提交 35ce4dd4 编写于 作者: V v_zhangshouxu

1.修改依赖版本

2.对模块进行精简
3.增加output_result_zmq input_result_zmq 模块
4.增加支持自动补全的脚本auto_completion.sh
上级 87842bce
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
......@@ -17,16 +17,6 @@
#define M_2PI (M_PI * 2)
// MATH_CHECK_INDEXES modifies some objects (e.g. SoloGimbalEKF) to
// include more debug information. It is also used by some functions
// to add extra code for debugging purposes. If you wish to activate
// this, do it here or as part of the top-level Makefile -
// e.g. Tools/Replay/Makefile
#ifndef MATH_CHECK_INDEXES
#define MATH_CHECK_INDEXES (0)
#endif
#ifndef DEG_TO_RAD
#define DEG_TO_RAD (M_PI / 180.0f)
#endif
......@@ -34,8 +24,6 @@
#ifndef RAD_TO_DEG
#define RAD_TO_DEG (180.0 / M_PI)
#endif
// Centi-degrees to radians
static const double DEGX100 = 5729.57795;
// GPS Specific double precision conversions
// The precision here does matter when using the wsg* functions for converting
......@@ -44,69 +32,4 @@ static const double DEG_TO_RAD_DOUBLE = asin(1) / 90;
static const double RAD_TO_DEG_DOUBLE = 90 / asin(1);
// acceleration due to gravity in m/s/s
static const double GRAVITY_MSS = 9.80665;
// radius of earth in meters
static const double RADIUS_OF_EARTH = 6378100;
// convert a longitude or latitude point to meters or centimeters.
// Note: this does not include the longitude scaling which is dependent upon location
static const double LATLON_TO_M = 0.01113195;
static const double LATLON_TO_CM = 1.113195;
static const double G_ACCEL = (9.80151);
static const double RHO = (1.225);
/* WGS84 reference ellipsoid constants */
// Semi-major axis of the Earth, in meters.
static const double WGS84_A = 6356752.3142 / 0.996647189335;
//Inverse flattening of the Earth
static const double WGS84_IF = 2982572.23563;
// The flattening of the Earth
static const double WGS84_F = (1.0 / WGS84_IF);
// Semi-minor axis of the Earth in meters
static const double WGS84_B = 6356752.3142;
// Eccentricity of the Earth
static const double WGS84_E = (sqrt(2 * (1.0 / 298.257223563) - (1.0 / 298.257223563) *
(1.0 / 298.257223563)));
// Polar Radius of Curvature
static const double WGS84_C = 639.95936258;
static const double WGS84_E2(WGS84_E * WGS84_E);
static const double WGS84_A2(WGS84_A * WGS84_A);
static const double WGS84_B2(WGS84_B * WGS84_B);
static const double WGS84_AB2(WGS84_A2 * WGS84_B2);
// air density at 15C at sea level in kg/m^3
static const double AIR_DENSITY_SEA_LEVEL = 1.225;
static const double C_TO_KELVIN = 273.15;
// Gas Constant is from Aerodynamics for Engineering Students, Third Edition, E.L.Houghton and N.B.Carruthers
static const double ISA_GAS_CONSTANT = 287.26;
static const double ISA_LAPSE_RATE = 0.0065;
/*
use AP_ prefix to prevent conflict with OS headers, such as NuttX
clock.h
*/
#define AP_NSEC_PER_SEC 1000000000ULL
#define AP_NSEC_PER_USEC 1000ULL
#define AP_USEC_PER_SEC 1000000ULL
#define AP_USEC_PER_MSEC 1000ULL
#define AP_MSEC_PER_SEC 1000ULL
#define AP_SEC_PER_WEEK (7ULL * 86400ULL)
#define AP_MSEC_PER_WEEK (AP_SEC_PER_WEEK * AP_MSEC_PER_SEC)
#endif
......@@ -13,6 +13,7 @@ enum LogLevel{
FATAL = 4,
DIRECT = 9999
};
class LogInterface{
public:
LogInterface(const std::function<void(const std::stringstream&)> logging_func,
......
......@@ -6,12 +6,14 @@
// TimerElement 模块的触发判断函数,设置其判断精度, 默认为2ms
class TimerTrigger : public basic::PipeElement {
public:
TimerTrigger() : PipeElement(false, "TimerTrigger") {
TimerTrigger(int precision = 2000) : PipeElement(false, "TimerTrigger"), _precision(precision) {
}
private:
virtual void thread_func() {
std::this_thread::sleep_for(std::chrono::microseconds(2000));
std::this_thread::sleep_for(std::chrono::microseconds(_precision));
Messager::publish("timer_trigger");
}
int64_t _precision;
};
\ No newline at end of file
......@@ -16,11 +16,11 @@ protected:
};
private:
std::map<std::string, std::string> strings;
std::map<std::string, int> ints;
std::map<std::string, long> longs;
std::map<std::string, float> floats;
std::map<std::string, double> doubles;
std::map<std::string, std::vector<double> > vec_doubles;
// std::map<std::string, int> ints;
// std::map<std::string, long> longs;
// std::map<std::string, float> floats;
// std::map<std::string, double> doubles;
// std::map<std::string, std::vector<double> > vec_doubles;
public:
std::string get_string_data(const std::string& key) {
if (strings.find(key) == strings.end()) {
......@@ -30,85 +30,85 @@ public:
return strings[key];
}
int get_int_data(const std::string& key) {
if (ints.find(key) == ints.end()) {
ERROR() << "Int data has no key named " << key;
throw std::runtime_error("key_not_found");
}
// int get_int_data(const std::string& key) {
// if (ints.find(key) == ints.end()) {
// ERROR() << "Int data has no key named " << key;
// throw std::runtime_error("key_not_found");
// }
return ints[key];
}
long get_long_data(const std::string& key) {
if (longs.find(key) == longs.end()) {
ERROR() << "Long data has no key named " << key;
throw std::runtime_error("key_not_found");
}
// return ints[key];
// }
// long get_long_data(const std::string& key) {
// if (longs.find(key) == longs.end()) {
// ERROR() << "Long data has no key named " << key;
// throw std::runtime_error("key_not_found");
// }
return longs[key];
}
// return longs[key];
// }
float get_float_data(const std::string& key) {
if (floats.find(key) == floats.end()) {
ERROR() << "Float data has no key named " << key;
throw std::runtime_error("key_not_found");
}
// float get_float_data(const std::string& key) {
// if (floats.find(key) == floats.end()) {
// ERROR() << "Float data has no key named " << key;
// throw std::runtime_error("key_not_found");
// }
return floats[key];
}
// return floats[key];
// }
double get_double_data(const std::string& key) {
if (doubles.find(key) == doubles.end()) {
ERROR() << "Double data has no key named " << key;
throw std::runtime_error("key_not_found");
}
// double get_double_data(const std::string& key) {
// if (doubles.find(key) == doubles.end()) {
// ERROR() << "Double data has no key named " << key;
// throw std::runtime_error("key_not_found");
// }
return doubles[key];
}
// return doubles[key];
// }
std::vector<double> get_double_vector_data(const std::string& key) {
if (vec_doubles.find(key) == vec_doubles.end()) {
ERROR() << "Double vector data has no key named " << key;
throw std::runtime_error("key_not_found");
}
return vec_doubles[key];
}
// std::vector<double> get_double_vector_data(const std::string& key) {
// if (vec_doubles.find(key) == vec_doubles.end()) {
// ERROR() << "Double vector data has no key named " << key;
// throw std::runtime_error("key_not_found");
// }
// return vec_doubles[key];
// }
void set_string_data(const std::string& key, const std::string& value) {
strings[key] = value;
}
void set_int_data(const std::string& key, int value) {
ints[key] = value;
}
void set_long_data(const std::string& key, long value) {
longs[key] = value;
}
void set_float_data(const std::string& key, float value) {
floats[key] = value;
}
void set_double_data(const std::string& key, double value) {
doubles[key] = value;
}
void set_double_vector_data(const std::string& key, std::vector<double> value) {
vec_doubles[key] = value;
}
// void set_int_data(const std::string& key, int value) {
// ints[key] = value;
// }
// void set_long_data(const std::string& key, long value) {
// longs[key] = value;
// }
// void set_float_data(const std::string& key, float value) {
// floats[key] = value;
// }
// void set_double_data(const std::string& key, double value) {
// doubles[key] = value;
// }
// void set_double_vector_data(const std::string& key, std::vector<double> value) {
// vec_doubles[key] = value;
// }
bool has_string_key(std::string key) {
return strings.find(key) != strings.end();
}
bool has_int_key(std::string key) {
return ints.find(key) != ints.end();
}
bool has_long_key(std::string key) {
return longs.find(key) != longs.end();
}
bool has_float_key(std::string key) {
return floats.find(key) != floats.end();
}
bool has_double_key(std::string key) {
return doubles.find(key) != doubles.end();
}
bool has_double_vector_key(std::string key) {
return vec_doubles.find(key) != vec_doubles.end();
}
// bool has_int_key(std::string key) {
// return ints.find(key) != ints.end();
// }
// bool has_long_key(std::string key) {
// return longs.find(key) != longs.end();
// }
// bool has_float_key(std::string key) {
// return floats.find(key) != floats.end();
// }
// bool has_double_key(std::string key) {
// return doubles.find(key) != doubles.end();
// }
// bool has_double_vector_key(std::string key) {
// return vec_doubles.find(key) != vec_doubles.end();
// }
};
......@@ -98,15 +98,6 @@ public:
return get_current_us() / 1000000;
}
// 判断经纬度是否合理
static bool is_legal_lonlat(const double &longitude, const double &latitude) {
if (longitude >= 73 && longitude <= 135 && latitude >= 0 && latitude <= 50) {
return true;
}
return false;
}
// 读取文件path,以string输出,string格式限制大小<2G
static std::string get_file_text(const std::string& path){
std::ifstream ifs(path);
......@@ -389,7 +380,7 @@ public:
}
// 返回文件大小
static int64_t get_file_size(const std::string& path){
static int64_t get_file_size(const std::string& path) {
std::ifstream in(path);
in.seekg(0, std::ios::end);
return in.tellg();
......@@ -418,6 +409,7 @@ public:
return fd;
}
// 删除文件或文件夹, 成功返回0, 失败返回-1
static int remove_rf(const char *dir) {
char cur_dir[] = ".";
char up_dir[] = "..";
......@@ -425,7 +417,7 @@ public:
struct dirent *dp;
struct stat dir_stat;
if (access(dir, F_OK) != 0) { //文化是否存在
if (access(dir, F_OK) != 0) { //文件不存在
return 0;
}
......
......@@ -52,7 +52,7 @@ public:
initial_log();
Diagnose::register_server("load_plugin", [&](const std::string& name){
Diagnose::register_server("load_plugin", [&](const std::string& name) {
std::string message;
if (DlUtils::try_load_plugin(name.c_str(), message)){
DlUtils::run_plugin(name.c_str());
......@@ -60,7 +60,7 @@ public:
return message;
});
}
static bool try_load_plugin(const char* name, std::string& message){
static bool try_load_plugin(const char* name, std::string& message) {
std::string lib_folder = appPref.get_string_data("lib_folder");
std::string lib_file = lib_folder + "/lib";
lib_file += name;
......
#pragma once
#include<geo/geo.hpp>
#include <utils/app_util.hpp>
class GpsHelper {
public:
GpsHelper() {
_geo = geo::instance();
}
bool is_initialized() const{
static bool& is_init = _geo->_map_projection_reference_point.init_done;
return is_init;
}
void initial(const double& lon, const double& lat){
if (!_geo->get_map_projection_reference().init_done) {
_geo->global_to_local_init(lat, lon, 0, AppUtil::get_current_ms());
}
}
void lonlat_2_mercator(const double& lon, const double& lat, double& x, double& y) const {
double z = 0;
_geo->global_to_local(lat, lon, -z, &x, &y, &z);
}
void mercator_2_lonlat(const double& x, const double& y, double& lon, double& lat) const {
double z = 0;
_geo->local_to_global(x, y, -z, &lat, &lon, &z);
}
double get_distance_point_2_point(const double& lon1, const double& lat1,
const double& lon2, const double& lat2){
return _geo->get_distance_to_next_waypoint(lat1, lon1, lat2, lon2);
}
private:
geo* _geo;
};
cmake_minimum_required(VERSION 2.8)
project(input_result_zmq)
set(CMAKE_CXX_STANDARD 11)
add_definitions(-DLOAD_PLUGIN=load_${PROJECT_NAME})
add_definitions(-DRUN_PLUGIN=run_${PROJECT_NAME})
add_definitions(-DUNLOAD_PLUGIN=unload_${PROJECT_NAME})
find_package(Protobuf REQUIRED)
find_package(Glog REQUIRED)
find_package(Zmq REQUIRED)
include_directories(
${ZMQ_INCLUDE_DIR}
${GLOG_INCLUDE_DIR}
${CORELIB_INCLUDE_DIR}
${PROTOBUF_INCLUDE_DIR}
${DATA_INCLUDE_DIR}
)
ADDLIB(${PROJECT_NAME} src
${ZMQ_LIBRARIES}
proto_data
)
#include "input_result_zmq.h"
#include <log/logging.h>
#include <data/data_info.pb.h>
#include <data/qnxproc.pb.h>
#include <google/protobuf/text_format.h>
#include <message/messager.hpp>
#include <utils/app_preference.hpp>
// TODO: 死循环, CPU占用问题
InputResultZmqElement::InputResultZmqElement() : basic::PipeElement(false, "InputResultZmq"){
auto input_result_url = appPref.get_string_data("zmq.input_result_url");
_zmq_subscriber.subscribe(input_result_url);
_zmq_subscriber.set_recv_timeout(100);
_zmq_buffer.resize(200 * 1024);
}
void InputResultZmqElement::thread_func()
{
int size = _zmq_subscriber.receive(_zmq_buffer);
if (size > 0) {
message::BytesItem bytes;
std::string sub_str = _zmq_buffer.substr(0, size);
bytes.ParseFromString(sub_str);
if (bytes.id() == 3001){
std::string data = bytes.data();
Messager::publish("log_remote", "[remote]" + data);
} else if (bytes.id() == 3002){
QnxProcList result;
result.ParseFromString(bytes.data());
Messager::publish("performance_result", result);
}
}
}
InputResultZmqElement::~InputResultZmqElement() {
}
void InputResultZmqElement::thread_closing()
{
_zmq_subscriber.shutdown();
}
#include <pipe/timer_element.hpp>
#include <zmq/zmq.hpp>
#include <core/double_buffer_data.hpp>
#include <data/road_level_result.pb.h>
class InputResultZmqElement : public basic::PipeElement
{
public:
InputResultZmqElement();
virtual ~InputResultZmqElement();
private:
ZmqSubscriber _zmq_subscriber;
std::string _zmq_buffer;
DoubleBufferData<message::RoadLevelResult> _buffered_road_result;
private:
virtual void thread_func() override;
// PipeElement interface
private:
virtual void thread_closing() override;
};
#include "input_result_zmq.h"
#include <pipe/pipe_controller.hpp>
PipeController g_controllor;
extern "C"{
void LOAD_PLUGIN(){
g_controllor.add_element<InputResultZmqElement>();
}
void RUN_PLUGIN(){
g_controllor.start();
}
void UNLOAD_PLUGIN(){
g_controllor.stop();
g_controllor.wait();
}
}
cmake_minimum_required(VERSION 2.8)
project(output_result_zmq)
set(CMAKE_CXX_STANDARD 11)
add_definitions(-DLOAD_PLUGIN=load_${PROJECT_NAME})
add_definitions(-DRUN_PLUGIN=run_${PROJECT_NAME})
add_definitions(-DUNLOAD_PLUGIN=unload_${PROJECT_NAME})
find_package(Protobuf REQUIRED)
find_package(Glog REQUIRED)
find_package(Zmq REQUIRED)
include_directories(
${ZMQ_INCLUDE_DIR}
${GLOG_INCLUDE_DIR}
${CORELIB_INCLUDE_DIR}
${PROTOBUF_INCLUDE_DIR}
${DATA_INCLUDE_DIR}
)
ADDLIB(${PROJECT_NAME} src
${ZMQ_LIBRARIES}
proto_data
)
#include "output_result_zmq.h"
#include <log/logging.h>
#include <data/qnxproc.pb.h>
#include <google/protobuf/text_format.h>
#include <message/messager.hpp>
#include <utils/app_preference.hpp>
OutputResultZmqElement::OutputResultZmqElement() : basic::PipeElement(true, "OutputResultZmq"){
auto output_result_url = appPref.get_string_data("zmq.output_result_url");
_zmq_publisher.register_publisher(output_result_url);
auto log_func = [&](const std::string& log){
auto data_info = std::make_shared<message::BytesItem>();
data_info->set_data(log);
data_info->set_id(3001);
_buffered_data.push_data(data_info);
submit();
};
Messager::subcribe<std::string>("log_debug", log_func);
Messager::subcribe<std::string>("log_info", log_func);
Messager::subcribe<std::string>("log_warning", log_func);
Messager::subcribe<std::string>("log_error", log_func);
Messager::subcribe<std::string>("log_fatal", log_func);
Messager::subcribe<std::string>("log_direct", log_func);
Messager::subcribe<QnxProcList>(
"performance_result",
[this](const QnxProcList &data) {
auto data_info = std::make_shared<message::BytesItem>();
auto data_str = data.SerializeAsString();
data_info->set_data(data_str);
data_info->set_id(3002);
_buffered_data.push_data(data_info);
submit();
});
}
void OutputResultZmqElement::thread_func()
{
auto buffer_data = _buffered_data.get_data();
for (const auto& data : buffer_data){
std::string buffer;
data->SerializeToString(&buffer);
_zmq_publisher.publish(buffer);
}
}
OutputResultZmqElement::~OutputResultZmqElement(){
}
void OutputResultZmqElement::thread_closing()
{
_zmq_publisher.shutdown();
}
#include <pipe/pipe_element.hpp>
#include <zmq/zmq.hpp>
#include <data/data_info.pb.h>
#include <core/double_buffered_vector.hpp>
class OutputResultZmqElement : public basic::PipeElement
{
public:
OutputResultZmqElement();
virtual ~OutputResultZmqElement();
private:
ZmqPublisher _zmq_publisher;
DoubleBufferedVector<std::shared_ptr<message::BytesItem>> _buffered_data;
private:
virtual void thread_func() override;
// PipeElement interface
private:
virtual void thread_closing() override;
};
#include "output_result_zmq.h"
#include <pipe/pipe_controller.hpp>
PipeController g_controllor;
extern "C"{
void LOAD_PLUGIN(){
g_controllor.add_element<OutputResultZmqElement>();
}
void RUN_PLUGIN(){
g_controllor.start();
}
void UNLOAD_PLUGIN(){
g_controllor.stop();
g_controllor.wait();
}
}
package message;
message Double {
required string name = 1;
required double data = 2;
}
message Doubles {
required string name = 1;
repeated double data = 2;
}
message Long {
required string name = 1;
required int64 data = 2;
}
message Longs {
required string name = 1;
repeated int64 data = 2;
}
message String {
required string name = 1;
required string data = 2;
}
message BytesItem {
required int32 id = 1;
required bytes data = 2;
}
\ No newline at end of file
......@@ -26,6 +26,9 @@ ServerLogElement::ServerLogElement() :
Messager::subcribe<std::string>("log_fatal", [&](const std::string& log){
error(log);
});
Messager::subcribe<std::string>("log_remote", [&](const std::string& log){
info(log);
});
}
void ServerLogElement::initial()
......
# 功能
# 支持定位程序 run.sh 启动的自动补全. 如输入 ./run.sh -r [Tab][Tab] 会出现可选列表
#
# 使用方法
# source auto_completion.sh
#
# 可以将这条命令加在 ~/.bashrc 中,启动窗口自动执行
function auto_completion() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="linux_test linaro_iv_test linaro_someip_client linaro_iv linaro_2_linux_iv_test linux_someip_service linaro_someip_iv linaro_someip_service"
if [[ $prev == "-r" ]] || [[ $prev == "-nr" ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
fi
return 0
}
complete -F auto_completion run.sh
文件模式从 100644 更改为 100755
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册