Commit 48497380 authored by paopao's avatar paopao

添加日志

parent 619b0959
...@@ -74,7 +74,7 @@ install (TARGETS ${PROJECT_NAME} ...@@ -74,7 +74,7 @@ install (TARGETS ${PROJECT_NAME}
set(MAJOR_VERSION 1) set(MAJOR_VERSION 1)
set(MINOR_VERSION 0) set(MINOR_VERSION 0)
set(PATCH_VERSION 1) set(PATCH_VERSION 2)
set (CPACK_PACKAGE_NAME "ht-${PROJECT_NAME}") set (CPACK_PACKAGE_NAME "ht-${PROJECT_NAME}")
set (CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}") set (CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
......
...@@ -28,7 +28,7 @@ BarrierGateControl::BarrierGateControl(nlohmann::json& config,const std::map<int ...@@ -28,7 +28,7 @@ BarrierGateControl::BarrierGateControl(nlohmann::json& config,const std::map<int
, uart_name_(config["uart"]) , uart_name_(config["uart"])
, report_topic_(config["report_topic"]) , report_topic_(config["report_topic"])
, control_topic_(config["control_topic"]) , control_topic_(config["control_topic"])
,numbarrier_config_map(numbarrier_info_config_map) ,numbarrier_config_map(numbarrier_info_config_map),barrier_gate_Log("Launch.ini")
{ {
init(); init();
} }
...@@ -38,13 +38,28 @@ BarrierGateControl::BarrierGateControl(nlohmann::json& config,const std::map<int ...@@ -38,13 +38,28 @@ BarrierGateControl::BarrierGateControl(nlohmann::json& config,const std::map<int
, uart_name_(config["uart"]) , uart_name_(config["uart"])
, report_topic_(config["report_topic"]) , report_topic_(config["report_topic"])
, control_topic_(config["control_topic"]) , control_topic_(config["control_topic"])
, numbarrier_config_map(numbarrier_info_config_map) , numbarrier_config_map(numbarrier_info_config_map),barrier_gate_Log("Launch.ini")
, command_(command) , command_(command)
{ {
RecordTimeLaunch();
init(); init();
} }
void BarrierGateControl::RecordTimeLaunch()
{
barrier_gate_Log.set_log_file("RecordInfo.log");
if(!barrier_gate_Log.exists())
{
std::cout << "INI文件不存在,正在创建新文件...\n";
if (!barrier_gate_Log.create()) {
std::cerr << "创建INI文件失败\n";
return ;
}
}
}
void BarrierGateControl::exec() void BarrierGateControl::exec()
{ {
__m_running = true; __m_running = true;
...@@ -85,6 +100,7 @@ void BarrierGateControl::exec() ...@@ -85,6 +100,7 @@ void BarrierGateControl::exec()
buffer.resize(containts.size()); buffer.resize(containts.size());
std::copy(containts.begin(), containts.end(), buffer.begin()); std::copy(containts.begin(), containts.end(), buffer.begin());
std::cout << "publish traffic light states: " << containts << std::endl; std::cout << "publish traffic light states: " << containts << std::endl;
barrier_gate_Log.log("publish traffic light states: " + containts );
__m_status_puber->publish(buffer); __m_status_puber->publish(buffer);
} }
} }
...@@ -104,7 +120,7 @@ void BarrierGateControl::exec() ...@@ -104,7 +120,7 @@ void BarrierGateControl::exec()
if(crc[0] == buffer[len - 2] && crc[1] == buffer[len - 1]) if(crc[0] == buffer[len - 2] && crc[1] == buffer[len - 1])
{ {
std::cout << "crc check ok!" << std::endl; std::cout << "crc check ok!" << std::endl;
barrier_gate_Log.log("crc check ok!");
uint8_t func_code = buffer[1]; uint8_t func_code = buffer[1];
gate_code = (buffer[len - 4] << 8 | buffer[len - 3]); gate_code = (buffer[len - 4] << 8 | buffer[len - 3]);
if(func_code == 0x03) if(func_code == 0x03)
...@@ -121,6 +137,7 @@ void BarrierGateControl::exec() ...@@ -121,6 +137,7 @@ void BarrierGateControl::exec()
else else
{ {
std::cout << "unknown func code: " << (int)func_code << std::endl; std::cout << "unknown func code: " << (int)func_code << std::endl;
barrier_gate_Log.log("unknown func code:");
Exc_Barrier(0,gate_code);// 失败 Exc_Barrier(0,gate_code);// 失败
} }
} }
...@@ -159,6 +176,7 @@ void BarrierGateControl::init() ...@@ -159,6 +176,7 @@ void BarrierGateControl::init()
current_gate_= cvt_gate_status(command_); current_gate_= cvt_gate_status(command_);
gate_control(0, current_gate_); gate_control(0, current_gate_);
std::cerr << "init gate_control ..........."<<command_<<"current_gate_=" <<current_gate_ <<std::endl; std::cerr << "init gate_control ..........."<<command_<<"current_gate_=" <<current_gate_ <<std::endl;
barrier_gate_Log.log("init gate_control ..........."+ command_+"current_gate_=" + std::to_string(current_gate_));
} }
void BarrierGateControl::on_control_request(const mqtt_dataio::subscriber_basic::DataBuffer& msg) void BarrierGateControl::on_control_request(const mqtt_dataio::subscriber_basic::DataBuffer& msg)
...@@ -181,6 +199,7 @@ void BarrierGateControl::on_control_request(const mqtt_dataio::subscriber_basic: ...@@ -181,6 +199,7 @@ void BarrierGateControl::on_control_request(const mqtt_dataio::subscriber_basic:
gate_control(0, gate); gate_control(0, gate);
std::cout << "change traffic light status from: " << cvt_gate_status(current_gate_) << " to " << cvt_gate_status(gate) << std::endl; std::cout << "change traffic light status from: " << cvt_gate_status(current_gate_) << " to " << cvt_gate_status(gate) << std::endl;
barrier_gate_Log.log("change traffic light status from: "+ cvt_gate_status(current_gate_) + " to " + cvt_gate_status(gate));
current_gate_ = gate; current_gate_ = gate;
} }
...@@ -209,6 +228,7 @@ void BarrierGateControl::Exc_Barrier(int stateCode,uint16_t changeCode ) ...@@ -209,6 +228,7 @@ void BarrierGateControl::Exc_Barrier(int stateCode,uint16_t changeCode )
current_gate_=(GateState)changeCode; current_gate_=(GateState)changeCode;
std::string barrier_gate_status = cvt_gate_status(changeCode); std::string barrier_gate_status = cvt_gate_status(changeCode);
std::cout << "gate code: " << (int)changeCode << ", barrier gate status: " << barrier_gate_status << std::endl; std::cout << "gate code: " << (int)changeCode << ", barrier gate status: " << barrier_gate_status << std::endl;
barrier_gate_Log.log( "gate code: " + std::to_string((int)changeCode) + ", barrier gate status: " + barrier_gate_status );
return; return;
} }
//成功删除第一个值,取下一个值 //成功删除第一个值,取下一个值
......
...@@ -6,39 +6,8 @@ ...@@ -6,39 +6,8 @@
#include "uart/uart.hpp" #include "uart/uart.hpp"
#include "3th-part/json.hpp" #include "3th-part/json.hpp"
#include <queue> #include <queue>
#include"barrier_gate_log.h"
struct traffic_light_config
{
/* data */
uint16_t id;
std::string type;
std::vector<uint16_t> do_addr;
std::vector<std::string> color;
};
struct roadside_info_config
{
std::string id;
std::string topic;
double longitude;
double latitude;
double altitude;
uint32_t isLight;
};
struct traffic_light_status_config
{
/* data */
uint16_t id;
std::string color;
};
struct traffic_mode_config
{
uint16_t id;
std::vector<traffic_light_status_config> lights;
};
class BarrierGateControl class BarrierGateControl
...@@ -90,6 +59,8 @@ private: ...@@ -90,6 +59,8 @@ private:
void on_control_request(const mqtt_dataio::subscriber_basic::DataBuffer& msg); void on_control_request(const mqtt_dataio::subscriber_basic::DataBuffer& msg);
void RecordTimeLaunch();//记录日志
private: private:
bool __m_running; bool __m_running;
...@@ -97,4 +68,6 @@ private: ...@@ -97,4 +68,6 @@ private:
uint16_t __m_offset_do_addr; uint16_t __m_offset_do_addr;
std::map<int, std::string> numbarrier_config_map; std::map<int, std::string> numbarrier_config_map;
std::queue<BarrierGateControl::roadside_info_barrier>curExcBarrierQueue; std::queue<BarrierGateControl::roadside_info_barrier>curExcBarrierQueue;
Barrier_Gate_Log barrier_gate_Log;//记录日志数据
}; };
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment