Explorar el Código

20210616, 调度流程 取车流程 完整版 debug

huli hace 4 años
padre
commit
8fb324b185

+ 2 - 2
dispatch/carrier.cpp

@@ -299,7 +299,7 @@ Error_manager Carrier::check_and_read_memory_to_task(std::shared_ptr<Task_Base>
 				Error_manager t_error(CARRIER_RESPONS_ERROR, MINOR_ERROR, "m_respons_status is error");
 				tp_carrier_task->set_task_error_manager(t_error);
 			}
-
+/*
 			std::cout << " huli test :::: " << "  {{{{{{{{{{{{{{{{{{{{{   33333333333333333333333333333333333333333 }}}}}}}}}}}}}}}}}}}}}}}}}}= " << 333 << std::endl;
 			std::cout << " huli test :::: " << " m_request_key = " << m_request_key << std::endl;
 			std::cout << " huli test :::: " << " m_request_x = " << m_request_x << std::endl;
@@ -330,7 +330,7 @@ Error_manager Carrier::check_and_read_memory_to_task(std::shared_ptr<Task_Base>
 			std::cout << " huli test :::: " << " m_actual_y2 = " << m_actual_y2 << std::endl;
 			std::cout << " huli test :::: " << " m_actual_clamp_motion1 = " << m_actual_clamp_motion1 << std::endl;
 			std::cout << " huli test :::: " << "  {{{{{{{{{{{{{{{{{{{{{{{{{{{{  44444444444444444444444444444444444444444 }}}}}}}}}}}}}}}}}}}}}}}}= " << 444 << std::endl;
-
+*/
 			return Error_code::SUCCESS;
 		}
 			//返回没有收到数据

+ 2 - 2
dispatch/catcher.cpp

@@ -286,7 +286,7 @@ Error_manager Catcher::check_and_read_memory_to_task(std::shared_ptr<Task_Base>
 				Error_manager t_error(CATCHER_RESPONS_ERROR, MINOR_ERROR, "m_respons_status is error");
 				tp_catcher_task->set_task_error_manager(t_error);
 			}
-
+/*
 			std::cout << " huli test :::: " << " [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[     111111111111111111111111    ]]]]]]]]]]]]]]]]]]]]]]]]]]]] = " << 111 << std::endl;
 			std::cout << " huli test :::: " << " m_request_key = " << m_request_key << std::endl;
 			std::cout << " huli test :::: " << " m_request_x = " << m_request_x << std::endl;
@@ -318,7 +318,7 @@ Error_manager Catcher::check_and_read_memory_to_task(std::shared_ptr<Task_Base>
 			std::cout << " huli test :::: " << " m_actual_clamp_motion1 = " << m_actual_clamp_motion1 << std::endl;
 
 			std::cout << " huli test :::: " << " [[[[[[[[[[[[[[[[[[[[[[[[[[[[   2222222222222222222222222222222222222222  ]]]]]]]]]]]]]]]]]]]]]]]]]]] = " << 222 << std::endl;
-
+*/
 
 			return Error_code::SUCCESS;
 		}

+ 29 - 18
dispatch/dispatch_device_base.cpp

@@ -118,79 +118,81 @@ Error_manager Dispatch_device_base::check_task_type(std::shared_ptr<Task_Base> p
 //判断能否执行任务
 Error_manager Dispatch_device_base::check_task_level(Dispatch_task_level dispatch_task_level)
 {
-//	std::cout << " huli test :::: " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
+	std::cout << " huli test ::::79798798798798 " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
 	//加锁
 	std::unique_lock<std::mutex> t_lock(m_lock);
+	std::cout << " huli test ::::1312312312312312 " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
+std::cout << " huli test :::: " << " 123123123213 = " << 123123123213 << std::endl;
 	//只有当状态 不是正在执行当前等级的任务,并且当前等级的任务为空. 此时返回成功, 才能接受新的任务
 	if ( m_dispatch_device_status >= DISPATCH_DEVICE_READY && m_dispatch_device_status <= DISPATCH_DEVICE_THREE_LEVEL_WORK )
-	{
+	{std::cout << " huli test :::: " << " 123123123213 = " << 1 << std::endl;
 		switch ( dispatch_task_level )
-		{
+		{std::cout << " huli test :::: " << " 123123123213 = " << 2 << std::endl;
 			case DISPATCH_TASK_ONE_LEVEL:
-			{
+			{std::cout << " huli test :::: " << " 123123123213 = " << 3 << std::endl;
 				if ( mp_device_one_level_task.get() == NULL )
-				{
+				{std::cout << " huli test :::: " << " 123123123213 = " << 4 << std::endl;
 					//一级任务直接插入
 					if (  m_dispatch_device_status == DISPATCH_DEVICE_READY ||
 						  m_dispatch_device_status == DISPATCH_DEVICE_TWO_LEVEL_OVER ||
 						  m_dispatch_device_status == DISPATCH_DEVICE_TWO_LEVEL_WORK ||
 						  m_dispatch_device_status == DISPATCH_DEVICE_THREE_LEVEL_OVER ||
 						  m_dispatch_device_status == DISPATCH_DEVICE_THREE_LEVEL_WORK )
-					{
+					{std::cout << " huli test :::: " << " 123123123213 = " << 5 << std::endl;
 						return Error_code::SUCCESS;
 					}
 					else
-					{
+					{std::cout << " huli test :::: " << " 123123123213 = " << 6 << std::endl;
 						return Error_manager(Error_code::DISPATCH_DEVICE_TASK_LEVEL_ERROR, Error_level::MINOR_ERROR,
 											 " Dispatch_device_base::check_task_level 1 error ");
 					}
 				}
 				else
-				{
+				{std::cout << " huli test :::: " << " 123123123213 = " << 7 << std::endl;
 					return Error_manager(Error_code::DISPATCH_DEVICE_TASK_REPEAT, Error_level::MINOR_ERROR,
 										 " Dispatch_device_base::check_task_level 2 error ");
 				}
 				break;
 			}
 			case DISPATCH_TASK_TWO_LEVEL:
-			{
+			{std::cout << " huli test :::: " << " 123123123213 = " << 8 << std::endl;
 				if ( mp_device_two_level_task.get() == NULL )
-				{
+				{std::cout << " huli test :::: " << " 123123123213 = " << 9 << std::endl;
 					//二级任务如果打断了一级任务, 那么要通知一级任务暂停, 后续一级任务会重新执行
 					if (  m_dispatch_device_status == DISPATCH_DEVICE_READY )
-					{
+					{std::cout << " huli test :::: " << " 123123123213 = " << 10 << std::endl;
 						return Error_code::SUCCESS;
 					}
 					else if ( ( m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_WORK ||
 								m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_OVER ) && mp_device_one_level_task.get() != NULL)
-					{
+					{std::cout << " huli test :::: " << " 123123123213 = " << 11 << std::endl;
 						mp_device_one_level_task->set_task_statu(Task_Base::Task_statu::TASK_STOP);
 						return Error_code::SUCCESS;
 					}
 					else
-					{
+					{std::cout << " huli test :::: " << " 123123123213 = " << 12 << std::endl;
 						return Error_manager(Error_code::DISPATCH_DEVICE_TASK_LEVEL_ERROR, Error_level::MINOR_ERROR,
 											 " Dispatch_device_base::check_task_level 3  error ");
 					}
 				}
 				else
-				{
+				{std::cout << " huli test :::: " << " 123123123213 = " << 13 << std::endl;
 					return Error_manager(Error_code::DISPATCH_DEVICE_TASK_REPEAT, Error_level::MINOR_ERROR,
 										 " Dispatch_device_base::check_task_level 4 error ");
 				}
 				break;
 			}
 			case DISPATCH_TASK_THREE_LEVEL:
-			{
+			{std::cout << " huli test :::: " << " 123123123213 = " << 14 << std::endl;
 				if ( ( m_dispatch_device_status == DISPATCH_DEVICE_READY ||
 					 m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_OVER ) && mp_device_three_level_task.get() == NULL)
-				{
+				{std::cout << " huli test :::: " << " 123123123213 = " << 15 << std::endl;
 					return Error_code::SUCCESS;
 				}
 				break;
 			}
 			default:
-			{
+			{std::cout << " huli test :::: " << " 123123123213 = " << 16 << std::endl;
 				return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
 									 "  Dispatch_device_base::check_task 5 PARAMETER_ERROR ");
 				break;
@@ -200,13 +202,14 @@ Error_manager Dispatch_device_base::check_task_level(Dispatch_task_level dispatc
 							 " Dispatch_device_base::check_task is busy 6 ");
 	}
 	else
-	{
+	{std::cout << " huli test :::: " << " 123123123213 = " << 17 << std::endl;
 //		std::cout << " huli test :::: " << " 777777777777777777777777777777777777 = " << 777 << std::endl;
 //		std::cout << " huli test :::: " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
 //		std::cout << " huli test :::: " << " id = " << m_device_id << std::endl;
 	    return Error_manager(Error_code::DISPATCH_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
 	    					" Dispatch_device_base::check_task 7 error ");
 	}
+	std::cout << " huli test :::: " << " 123123123213 = " << 18 << std::endl;
 	return Error_code::SUCCESS;
 }
 
@@ -749,6 +752,14 @@ void Dispatch_device_base::execute_thread_fun()
 							m_device_two_level_command_key.clear();
 							m_device_two_level_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
 							m_dispatch_device_status = DISPATCH_DEVICE_ONE_LEVEL_WORK;
+
+							std::cout << " huli test :::: " << " 1111111111111111111555555555555555555555555555555555555555555555555555555555555555555555555555 = " << 15 << std::endl;
+							std::cout << " huli test :::: " << " 111111111111111111155555555555555555555555555555555 = " << 15 << std::endl;
+
+							std::cout << " huli test :::: " << " get_device_id() = " << get_device_id() << std::endl;
+
+							std::cout << " huli test :::: " << " 111111111111111111155555555555555555555555555555555 = " << 15 << std::endl;
+							std::cout << " huli test :::: " << " 1111111111111111111555555555555555555555555555555555555555555555555555555555555555555555555555 = " << 15 << std::endl;
 						}
 							//任务单重新创建, 调度创建的新的任务,那么回去继续工作
 						else if (  mp_device_two_level_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED )

+ 1 - 1
dispatch/dispatch_manager.cpp

@@ -348,7 +348,7 @@ Error_manager Dispatch_manager::send_dispatch_response_msg_with_error(message::D
 
 	t_dispatch_response_msg.mutable_error_manager()->set_error_code(error.get_error_code());
 	t_dispatch_response_msg.mutable_error_manager()->set_error_level((message::Error_level)error.get_error_level());
-	t_dispatch_response_msg.mutable_error_manager()->set_error_description(error.get_error_description(), error.get_description_length());
+	t_dispatch_response_msg.mutable_error_manager()->set_error_description(error.get_error_description());
 
 	System_communication::get_instance_references().encapsulate_msg(t_dispatch_response_msg.SerializeAsString());
 	return Error_code::SUCCESS;

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 402 - 123
dispatch/dispatch_process.cpp


+ 3 - 4
dispatch/dispatch_process.h

@@ -1,5 +1,7 @@
 
-
+#define MAIN_TEST 1
+//#define PROCESS_TEST 1
+#define TIME_TEST 1
 
 
 /*
@@ -39,9 +41,6 @@
 #include "../tool/point3D_tool.h"
 #include <atomic>
 
-//#define MAIN_TEST 1
-//#define PROCESS_TEST 1
-#define TIME_TEST 1
 
 
 //调度流程 存车

+ 0 - 536
error_code/dispatch.error_code.h

@@ -1,536 +0,0 @@
-
-//Error_code是错误码的底层通用模块,
-//功能:用作故障分析和处理。
-
-//用法:所有的功能接口函数return错误管理类,
-//然后上层判断分析错误码,并进行故障处理。
-
-
-
-#ifndef TEST_ERROR_ERROR_CODE_H
-#define TEST_ERROR_ERROR_CODE_H
-
-#include <string>
-#include <string.h>
-#include<iostream>
-
-//错误管理类转化为字符串 的前缀,固定长度为58
-//这个是由显示格式来确定的,如果要修改格式或者 Error_code长度超过8位,Error_level长度超过2位,折需要重新计算
-#define ERROR_NAMAGER_TO_STRING_FRONT_LENGTH   58
-
-//进程加锁的状态,
-enum Lock_status
-{
-    UNLOCK      = 0,
-    LOCK        = 1,
-};
-
-//设备使能状态,
-enum Able_status
-{
-    UNABLE      = 0,
-    ENABLE      = 1,
-};
-
-//数据是否为空
-enum Empty_status
-{
-    NON_EMPTY   = 0,
-    EMPTY       = 1,
-};
-
-
-//错误码的枚举,用来做故障分析
-enum Error_code
-{
-    //成功,没有错误,默认值0
-    SUCCESS                         = 0x00000000,
-
-
-    //基本错误码,
-    ERROR                           = 0x00000001,//错误
-    PARTIAL_SUCCESS                 = 0x00000002,//部分成功
-    WARNING                         = 0x00000003,//警告
-    FAILED                          = 0x00000004,//失败
-
-    NODATA                          = 0x00000010,//没有数据,传入参数容器内部没有数据时,
-	INVALID_MESSAGE					= 0x00000011, //无效的消息,
-	PARSE_FAILED					= 0x00000012,//解析失败
-
-    TASK_TIMEOVER					= 0x00000020,//任务超时
-	RESPONSE_TIMEOUT                = 0x00000021,//答复超时
-
-    POINTER_IS_NULL                 = 0x00000101,//空指针
-    PARAMETER_ERROR                 = 0x00000102,//参数错误,传入参数不符合规范时,
-    POINTER_MALLOC_FAIL             = 0x00000103,//手动分配内存失败
-
-    CLASS_BASE_FUNCTION_CANNOT_USE  = 0x00000201,//基类函数不允许使用,必须使用子类的
-
-	CONTAINER_IS_TERMINATE			= 0x00000301,//容器被终止
-
-
-
-
-//    错误码的规范,
-//    错误码是int型,32位,十六进制。
-//    例如0x12345678
-//    12表示功能模块,例如:laser雷达模块               	框架制定
-//    34表示文件名称,例如:laser_livox.cpp             框架制定
-//    56表示具体的类,例如:class laser_livox           个人制定
-//    78表示类的函数,例如:laser_livox::start();       个人制定
-//    注:错误码的制定从1开始,不要从0开始,
-//        0用作错误码的基数,用来位运算,来判断错误码的范围。
-
-//    laser扫描模块
-    LASER_ERROR_BASE                = 0x01000000,
-
-//    laser_base基类
-	LASER_BASE_ERROR_BASE			= 0x01010000,
-    LASER_TASK_PARAMETER_ERROR      = 0x01010001,   //雷达基类模块, 任务输入参数错误
-    LASER_CONNECT_FAILED,							//雷达基类模块, 连接失败
-	LASER_START_FAILED,								//雷达基类模块, 开始扫描失败
-	LASER_CHECK_FAILED,								//雷达基类模块, 检查失败
-	LASER_STATUS_BUSY,								//雷达基类模块, 状态正忙
-	LASER_STATUS_ERROR,								//雷达基类模块, 状态错误
-	LASER_TASK_OVER_TIME,							//雷达基类模块, 任务超时
-	LASER_QUEUE_ERROR,								//雷达基类模块, 数据缓存错误
-
-
-//    laser_livox.cpp的错误码
-    LIVOX_ERROR_BASE                = 0x01020000,
-    LIVOX_START_FAILE,								//livox模块,开始扫描失败
-	LIVOX_TASK_TYPE_ERROR,							//livox模块,任务类型错误
-	lIVOX_CANNOT_PUSH_DATA,							//livox模块,不能添加扫描的数据
-	lIVOX_CHECK_FAILED,								//livox模块,检查失败
-	lIVOX_STATUS_BUSY,								//livox模块,状态正忙
-	lIVOX_STATUS_ERROR,								//livox模块,状态错误
-
-	//laser_manager 雷达管理模块
-	LASER_MANAGER_ERROR_BASE						= 0x01030000,
-	LASER_MANAGER_READ_PROTOBUF_ERROR,				//雷达管理模块,读取参数错误
-	LASER_MANAGER_STATUS_BUSY,						//雷达管理模块,状态正忙
-	LASER_MANAGER_STATUS_ERROR,						//雷达管理模块,状态错误
-	LASER_MANAGER_TASK_TYPE_ERROR,					//雷达管理模块,任务类型错误
-	LASER_MANAGER_IS_NOT_READY,						//雷达管理模块,不在准备状态
-	LASER_MANAGER_TASK_OVER_TIME,					//雷达管理模块,任务超时
-	LASER_MANAGER_LASER_INDEX_ERRPR,				//雷达管理模块,雷达索引错误,编号错误。
-	LASER_MANAGER_LASER_INDEX_REPEAT,				//雷达管理模块,需要扫描的雷达索引重复,可忽略的错误,提示作用
-
-//livox_driver 雷达livox驱动模块
-	LIVOX_DRIVER_ERROR_BASE							= 0x01040000,
-	LIVOX_DRIVER_SN_REPEAT,							//livox驱动模块, 雷达广播码重复
-	LIVOX_DRIVER_SN_ERROR,							//livox驱动模块, 雷达广播码错误
-	LIVOX_SKD_INIT_FAILED,							//livox驱动模块, livox_sdk初始化失败
-	LIVOX_DRIVER_NOT_READY,							//livox驱动模块, livox没有准备好.
-
-
-
-
-     //PLC error code  ...
-    PLC_ERROR_BASE                  = 0x02010000,
-    PLC_UNKNOWN_ERROR,
-    PLC_EMPTY_TASK,
-    PLC_IP_PORT_ERROR,
-    PLC_SLAVE_ID_ERROR,
-    PLC_CONNECTION_FAILED,
-    PLC_READ_FAILED,
-    PLC_WRITE_FAILED,
-    PLC_NOT_ENOUGH_DATA_ERROR,
-
-
-
-    //locate 定位模块,
-	LOCATER_ERROR_BASE                				= 0x03000000,
-
-	//LASER_MANAGER 定位管理模块
-	LOCATER_MANAGER_ERROR_BASE                		= 0x03010000,
-	LOCATER_MANAGER_READ_PROTOBUF_ERROR,				//定位管理模块,读取参数错误
-	LOCATER_MANAGER_STATUS_BUSY,						//定位管理模块,状态正忙
-	LOCATER_MANAGER_STATUS_ERROR,						//定位管理模块,状态错误
-	LOCATER_MANAGER_TASK_TYPE_ERROR,					//定位管理模块,任务类型错误
-	LOCATER_MANAGER_IS_NOT_READY,						//定位管理模块,不在准备状态
-	LOCATER_MANAGER_CLOUD_MAP_ERROR,					//定位管理模块,任务输入点云map的error
-	LOCATER_MANAGER_TASK_OVER_TIME,						//定位管理模块,任务超时
-
-
-	//Locater.cpp error from 0x0301000-0x030100FF
-	LOCATER_TASK_INIT_CLOUD_EMPTY ,
-    LOCATER_TASK_ERROR,
-    LOCATER_TASK_INPUT_CLOUD_UNINIT,
-    LOCATER_INPUT_CLOUD_EMPTY,
-    LOCATER_YOLO_UNINIT,
-    LOCATER_POINTSIFT_UNINIT,
-    LOCATER_3DCNN_UNINIT,
-    LOCATER_INPUT_YOLO_CLOUD_EMPTY,
-    LOCATER_Y_OUT_RANGE_BY_PLC,
-    LOCATER_MEASURE_HEIGHT_CLOUD_UNINIT,
-    LOCATER_MEASURE_HEIGHT_CLOUD_EMPTY,
-    LOCATER_INPUT_CLOUD_UNINIT,
-
-
-    //point sift from 0x03010100-0x030101FF
-    LOCATER_SIFT_INIT_FAILED=0x03010100,
-    LOCATER_SIFT_INPUT_CLOUD_UNINIT,
-	LOCATER_SIFT_INPUT_CLOUD_EMPTY,
-	LOCATER_SIFT_GRID_ERROR,
-	LOCATER_SIFT_SELECT_ERROR,
-	LOCATER_SIFT_CLOUD_VERY_LITTLE,
-	LOCATER_SIFT_CREATE_INPUT_DATA_FAILED,
-	LOCATER_SIFT_PREDICT_FAILED,
-	LOCATER_SIFT_PREDICT_TIMEOUT,
-	LOCATER_SIFT_PREDICT_NO_WHEEL_POINT,
-	LOCATER_SIFT_PREDICT_NO_CAR_POINT,
-
-    LOCATER_SIFT_FILTE_OBS_FAILED,
-    LOCATER_SIFT_INPUT_BOX_PARAMETER_FAILED,
-
-//    //yolo from 0x03010200-0x030102FF
-//        LOCATER_YOLO_DETECT_FAILED=0x03010200,
-//    LOCATER_YOLO_DETECT_NO_TARGET,
-//    LOCATER_YOLO_PARAMETER_INVALID,
-//    LOCATER_YOLO_INPUT_CLOUD_UNINIT,
-
-    //3dcnn from 0x03010300-0x030103FF
-    LOCATER_3DCNN_INIT_FAILED=0x03010300,
-    LOCATER_3DCNN_INPUT_CLOUD_UNINIT,
-	LOCATER_3DCNN_INPUT_CLOUD_EMPTY,
-	LOCATER_3DCNN_INPUT_CLOUD_MAP_ERROR,
-	LOCATER_3DCNN_PCA_OUT_ERROR,
-	LOCATER_3DCNN_EXTRACT_RECT_ERROR,
-	LOCATER_3DCNN_RECT_SIZE_ERROR,
-
-    LOCATER_3DCNN_PREDICT_FAILED,
-    LOCATER_3DCNN_VERIFY_RECT_FAILED_3,
-    LOCATER_3DCNN_VERIFY_RECT_FAILED_4,
-    LOCATER_3DCNN_KMEANS_FAILED,
-    LOCATER_3DCNN_IIU_FAILED,
-    LOCATER_3DCNN_PCA_OUT_CLOUD_EMPTY,
-
-    //System_manager error from 0x04010000-0x0401FFFF
-    SYSTEM_READ_PARAMETER_ERROR=0x04010100,
-    SYSTEM_PARAMETER_ERROR,
-    SYSTEM_INPUT_TERMINOR_NO_LASERS,
-
-    //terminor_command_executor.cpp from 0x04010200-0x040102FF
-    TERMINOR_NOT_READY=0x04010200,
-    TERMINOR_INPUT_LASER_NULL,
-    TERMINOR_NOT_CONTAINS_LASER,
-    TERMINOR_INPUT_PLC_NULL,
-    TERMINOR_INPUT_LOCATER_NULL,
-    TERMINOR_CREATE_WORKING_THREAD_FAILED,
-    TERMINOR_FORCE_QUIT,
-    TERMINOR_LASER_TIMEOUT,
-    TERMINOR_POST_PLC_TIMEOUT,
-    TERMINOR_CHECK_RESULTS_ERROR,
-
-    ////Hardware limit from 0x05010000 - 0x0501ffff
-    ///railing.cpp from 0x05010100-0x050101ff
-    HARDWARE_LIMIT_LEFT_RAILING=0x05010100,         //左栏杆限制
-    HARDWARE_LIMIT_RAILING_PARAMETER_ERROR,
-    HARDWARE_LIMIT_RAILING_ERROR,
-    HARDWARE_LIMIT_CENTER_X_LEFT,
-    HARDWARE_LIMIT_CENTER_X_RIGHT,
-    HARDWARE_LIMIT_CENTER_Y_TOP,
-    HARDWARE_LIMIT_CENTER_Y_BOTTOM,
-    HARDWARE_LIMIT_HEIGHT_OUT_RANGE,
-    HARDWARE_LIMIT_ANGLE_OUT_RANGE,
-    //termonal_limit from 0x05010200-0x050102ff
-    HARDWARE_LIMIT_TERMINAL_LEFT_ERROR,
-    HARDWARE_LIMIT_TERMINAL_RIGHT_ERROR,
-    HARDWARE_LIMIT_TERMINAL_LR_ERROR,
-
-
-
-    WANJI_LIDAR_DEVICE_ERROR_BASE=0x06080000,						//万集设备模块,错误基类
-	WANJI_LIDAR_DEVICE_STATUS_BUSY,									//万集设备模块,状态正忙
-	WANJI_LIDAR_DEVICE_STATUS_ERROR,								//万集设备模块,状态错误
-	WANJI_LIDAR_DEVICE_TASK_TYPE_ERROR,								//万集设备模块,任务类型错误
-	WANJI_LIDAR_DEVICE_TASK_OVER_TIME,								//万集设备模块,任务超时
-	WANJI_LIDAR_DEVICE_NO_CLOUD,									//万集设备模块,没有点云
-
-
-	//wj_lidar error from 0x06010000-0x0601FFFF
-	WJ_LIDAR_COMMUNICATION_ERROR_BASE=0x06010000,
-	WJ_LIDAR_COMMUNICATION_UNINITIALIZED,							//万集通信,未初始化
-	WJ_LIDAR_COMMUNICATION_DISCONNECT,								//万集通信,断连
-	WJ_LIDAR_COMMUNICATION_FAULT,									//万集通信,故障
-	WJ_LIDAR_CONNECT_FAILED,
-    WJ_LIDAR_UNINITIALIZED,
-    WJ_LIDAR_READ_FAILED,
-    WJ_LIDAR_WRITE_FAILED,
-    WJ_LIDAR_GET_CLOUD_TIMEOUT,
-
-    //wj lidar protocol error from 0x06020000-0x0602FFFF
-        WJ_PROTOCOL_ERROR_BASE=0x06020000,
-	WJ_PROTOCOL_STATUS_BUSY,										//万集解析, 状态正忙
-	WJ_PROTOCOL_STATUS_ERROR,										//系统执行模块, 状态错误
-    WJ_PROTOCOL_INTEGRITY_ERROR,
-    WJ_PROTOCOL_PARSE_FAILED,
-    WJ_PROTOCOL_EMPTY_PACKAGE,
-    WJ_PROTOCOL_EXCEED_MAX_SIZE,
-
-    //wj region detect error from 0x06030000-0x0603FFFF
-	WJ_REGION_ERROR_BASE					= 0x06030000,
-	WJ_REGION_EMPTY_CLOUD,
-	WJ_REGION_EMPTY_NO_WHEEL_INFORMATION,
-    WJ_REGION_RECTANGLE_ANGLE_ERROR,
-    WJ_REGION_RECTANGLE_SIZE_ERROR,
-    WJ_REGION_RECTANGLE_SYMMETRY_ERROR,
-    WJ_REGION_CLUSTER_SIZE_ERROR,
-
-    //wj manager error from 0x06040000-0x0604FFFF
-    WJ_MANAGER_UNINITIALIZED=0x06040000,
-    WJ_MANAGER_LIDAR_DISCONNECTED,
-    WJ_MANAGER_PLC_DISCONNECTED,
-    WJ_MANAGER_EMPTY_CLOUD,
-	WJ_MANAGER_READ_PROTOBUF_ERROR,								//万集管理模块,读取参数错误
-	WJ_MANAGER_INIT_REPEAT,										//万集管理模块,重复初始化
-	WJ_MANAGER_TASK_TYPE_ERROR,									//万集管理模块,任务类型错误
-	WJ_MANAGER_STATUS_BUSY,										//万集管理模块,状态正忙
-	WJ_MANAGER_STATUS_ERROR,									//万集管理模块,状态错误
-	WJ_MANAGER_LASER_INDEX_ERRPR,								//万集管理模块,雷达索引错误,编号错误。
-	WJ_MANAGER_LASER_INDEX_REPEAT,								//万集管理模块,需要扫描的雷达索引重复,可忽略的错误,提示作用
-	WJ_MANAGER_TASK_OVER_TIME,									//万集管理模块,任务超时
-
-
-	WJ_LIDAR_TASK_EMPTY_RESULT=0x06050000,
-    WJ_LIDAR_TASK_EMPTY_TASK,
-    WJ_LIDAR_TASK_WRONG_TYPE,
-    WJ_LIDAR_TASK_INVALID_TASK,
-    WJ_LIDAR_TASK_MEASURE_FAILED,
-
-
-
-    //task module, 任务模块  error from 0x10010000-0x1001FFFF
-	TASK_MODULE_ERROR_BASE 							= 0x10010000,
-	TASK_TYPE_IS_UNKNOW,
-	TASK_NO_RECEIVER,
-
-
-	//Communication module, 通信模块
-	COMMUNICATION_BASE_ERROR_BASE					= 0x11010000,
-	COMMUNICATION_READ_PROTOBUF_ERROR,				//模块,读取参数错误
-	COMMUNICATION_BIND_ERROR,
-	COMMUNICATION_CONNECT_ERROR,
-	COMMUNICATION_ANALYSIS_TIME_OUT,									//解析超时,
-	COMMUNICATION_EXCUTER_IS_BUSY,										//处理器正忙, 请稍等
-
-
-	//system module, 系统模块
-	SYSTEM_EXECUTOR_ERROR_BASE						= 0x12010000,		//系统执行模块,
-	SYSTEM_EXECUTOR_PARSE_ERROR,										//系统执行模块, 解析消息错误
-	SYSTEM_EXECUTOR_STATUS_BUSY,										//系统执行模块, 状态正忙
-	SYSTEM_EXECUTOR_STATUS_ERROR,										//系统执行模块, 状态错误
-	SYSTEM_EXECUTOR_CHECK_ERROR,										//系统执行模块, 检查错误
-
-	LOCATER_MSG_TABLE_NOT_EXIST ,
-    LOCATER_MSG_RESPONSE_TYPE_ERROR,
-    LOCATER_MSG_RESPONSE_INFO_ERROR,
-    LOCATER_MSG_REQUEST_INVALID,
-    LOCATER_MSG_RESPONSE_HAS_NO_REQUEST,
-
-	//Dispatch_manager 调度管理模块 错误码
-	DISPATCH_MANAGER_ERROR_BASE						= 0x13010000,
-	DISPATCH_MANAGER_READ_PROTOBUF_ERROR,				//调度管理模块,读取参数错误
-	DISPATCH_MANAGER_STATUS_BUSY,						//调度管理模块,状态正忙
-	DISPATCH_MANAGER_STATUS_ERROR,						//调度管理模块,状态错误
-	DISPATCH_MANAGER_TASK_TYPE_ERROR,					//调度管理模块,任务类型错误
-	DISPATCH_MANAGER_IS_NOT_READY,						//调度管理模块,不在准备状态
-
-	CARRIER_ERROR_BASE								= 0x13020000,
-	CARRIER_READ_PROTOBUF_ERROR,				//搬运器模块,读取参数错误
-	CARRIER_STATUS_BUSY,						//搬运器模块,状态正忙
-	CARRIER_STATUS_ERROR,						//搬运器模块,状态错误
-	CARRIER_STATUS_DISCONNECT,					//搬运器模块,状态断连
-	CARRIER_TASK_TYPE_ERROR,					//搬运器模块,任务类型错误
-	CARRIER_TASK_OVER_TIME,						//搬运器模块,任务超时
-	CARRIER_IS_NOT_READY,						//搬运器模块,不在准备状态
-	CARRIER_RESPONS_ERROR,						//搬运器模块,指令的执行失败
-	CARRIER_TASK_NOTHINGNESS,					//搬运器模块,任务不存在
-
-
-
-
-	//snap7 通信模块 错误码
-	SNAP7_ERROR_BASE								= 0x1401000,
-	SNAP7_READ_PROTOBUF_ERROR,							//snap7通信模块,读取参数错误
-	SNAP7_CONNECT_ERROR,								//snap7通信模块,连接错误
-	SNAP7_DISCONNECT_ERROR,								//snap7通信模块,断连错误
-	SNAP7_READ_ERROR,									//snap7通信模块,读取错误
-	SNAP7_WRITE_ERROR,									//snap7通信模块,写入错误
-	SNAP7_ANALYSIS_TIME_OUT,									//解析超时,
-	SNAP7_EXCUTER_IS_BUSY,										//处理器正忙, 请稍等
-};
-
-//错误等级,用来做故障处理
-enum Error_level
-{
-//    正常,没有错误,默认值0
-    NORMAL                = 0,
-
-
-//    轻微故障,可忽略的故障,NEGLIGIBLE_ERROR
-//    提示作用,不做任何处理,不影响代码的流程,
-//    用作一些不重要的事件,即使出错也不会影响到系统功能,
-//    例如:文件保存错误,等
-    NEGLIGIBLE_ERROR      = 1,
-
-
-//    一般故障,MINOR_ERROR
-//    用作底层功能函数的错误返回,表示该功能函数执行失败,
-//    返回给应用层之后,需要做故障分析和处理,
-//    例如:雷达数据传输失败,应用层就需要进行重新扫描,或者重连,或者重置参数等。
-    MINOR_ERROR           = 2,
-
-
-//    严重故障,MAJOR_ERROR
-//    用作应用层的任务事件的结果,表示该功能模块失败。
-//    通常是底层函数返回一般故障之后,应用层无法处理并解决故障,此时就要进行故障升级,
-//    从一般故障升级为严重故障,然后进行回退流程,回退已经执行的操作,最终回到故障待机状态。
-//    需要外部清除故障,并复位至正常待机状态,才能恢复功能的使用。
-//    例如:雷达扫描任务失败,且无法自动恢复。
-    MAJOR_ERROR           = 3,
-
-
-//    致命故障,CRITICAL_ERROR
-//    系统出现致命错误。导致系统无法正常运行,
-//    此时系统应该紧急停机,执行紧急流程,快速停机。
-//    此时不允许再执行任何函数和任务指令,防止系统故障更加严重。
-//    也不需要做任何错误处理了,快速执行紧急流程。
-//    例如:内存错误,进程挂死,关键设备失控,监控设备报警,等
-    CRITICAL_ERROR        = 4,
-};
-
-
-class Error_manager
-{
-public://外部接口函数
-    //构造函数
-    Error_manager();
-    //拷贝构造
-    Error_manager(const Error_manager & error_manager);
-    //赋值构造
-    Error_manager(Error_code error_code, Error_level error_level = NORMAL,
-                  const char* p_error_description = NULL, int description_length = 0);
-    //赋值构造
-    Error_manager(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
-    //析构函数
-    ~Error_manager();
-
-    //初始化
-    void error_manager_init();
-    //初始化
-    void error_manager_init(Error_code error_code, Error_level error_level = NORMAL,
-                            const char* p_error_description = NULL, int description_length = 0);
-    //初始化
-    void error_manager_init(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
-    //重置
-    void error_manager_reset(Error_code error_code, Error_level error_level = NORMAL,
-                             const char* p_error_description = NULL, int description_length = 0);
-    //重置
-    void error_manager_reset(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
-    //重置
-    void error_manager_reset(const Error_manager & error_manager);
-    //清除所有内容
-    void error_manager_clear_all();
-
-    //重载=
-    Error_manager& operator=(const Error_manager & error_manager);
-    //重载=,支持Error_manager和Error_code的直接转化,会清空错误等级和描述
-    Error_manager& operator=(Error_code error_code);
-    //重载==
-    bool operator==(const Error_manager & error_manager);
-    //重载==,支持Error_manager和Error_code的直接比较
-    bool operator==(Error_code error_code);
-    //重载!=
-    bool operator!=(const Error_manager & error_manager);
-    //重载!=,支持Error_manager和Error_code的直接比较
-    bool operator!=(Error_code error_code);
-	//重载<<,支持cout<<
-	friend std::ostream & operator<<(std::ostream &out, Error_manager &error_manager);
-
-
-    //获取错误码
-    Error_code get_error_code();
-    //获取错误等级
-    Error_level get_error_level();
-    //获取错误描述的指针,(浅拷贝)
-    char* get_error_description();
-
-	int get_description_length();
-
-    //复制错误描述,(深拷贝)
-    //output:p_error_description     错误描述的字符串指针,不可以为NULL,必须要有实际的内存
-    //output:description_length      错误描述的字符串长度,不可以为0,长度最好足够大,一般256即可。
-    void copy_error_description(const char* p_error_description, int description_length);
-    //复制错误描述,(深拷贝)
-    //output:error_description_string     错误描述的string
-    void copy_error_description(std::string & error_description_string);
-
-    //设置错误码
-    void set_error_code(Error_code error_code);
-    //比较错误等级并升级,取高等级的结果
-    void set_error_level_up(Error_level error_level);
-    //比较错误等级并降级,取低等级的结果
-    void set_error_level_down(Error_level error_level);
-    //错误等级,设定到固定值
-    void set_error_level_location(Error_level error_level);
-    //设置错误描述
-    void set_error_description(const char* p_error_description, int description_length = 0);
-    //设置错误描述
-    void set_error_description(std::string & error_description_string);
-
-    //尾部追加错误描述
-    void add_error_description(const char* p_error_description, int description_length = 0);
-    //尾部追加错误描述
-    void add_error_description(std::string & error_description_string);
-
-    //比较错误是否相同,
-    // 注:只比较错误码和等级
-	bool is_equal_error_manager(const Error_manager & error_manager);
-	//比较并覆盖错误,讲低级错误转为字符串存放于描述中,
-	//如果错误相同,则保留this的,将输入参数转入描述。
-	void compare_and_cover_error(const Error_manager & error_manager);
-	//比较并覆盖错误,讲低级错误转为字符串存放于描述中,
-	//如果错误相同,则保留this的,将输入参数转入描述。
-	void compare_and_cover_error( Error_manager * p_error_manager);
-
-	//将所有的错误信息,格式化为字符串,用作日志打印。
-    //output:p_error_description     错误汇总的字符串指针,不可以为NULL,必须要有实际的内存
-    //output:description_length      错误汇总的字符串长度,不可以为0,长度最好足够大,一般256即可。
-    void translate_error_to_string(char* p_error_aggregate, int aggregate_length);
-    //output:error_description_string     错误汇总的string
-    void translate_error_to_string(std::string & error_aggregate_string);
-    //错误码转字符串的简易版,可支持cout<<
-    //return     错误汇总的string
-    std::string to_string();
-
-
-
-protected:
-    Error_code              m_error_code;               //错误码
-    Error_level             m_error_level;              //错误等级
-    char*                   pm_error_description;       //错误描述
-    int                     m_description_length;       //错误描述的字符长度
-
-protected://内部功能函数
-public:
-    //释放错误描述的内存,
-    void free_description();
-
-    //重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
-    //input:p_error_description     错误描述的字符串指针,可以为NULL,
-    //input:description_length      错误描述的字符串长度,如果为0,则从p_error_description里面获取有效的长度
-    void reallocate_memory_and_copy_string(const char* p_error_description, int description_length = 0);
-
-    //重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
-    //input:error_aggregate_string     错误描述的string
-    void reallocate_memory_and_copy_string(std::string & error_aggregate_string);
-};
-
-
-
-
-#endif //TEST_ERROR_ERROR_CODE_H
-
-

+ 67 - 227
error_code/error_code.cpp

@@ -15,45 +15,38 @@ Error_manager::Error_manager()
 {
     m_error_code = SUCCESS;
     m_error_level = NORMAL;
-    pm_error_description = 0;
-    m_description_length = 0;
-    return ;
 }
 //拷贝构造
 Error_manager::Error_manager(const Error_manager & error_manager)
 {
     this->m_error_code = error_manager.m_error_code;
     this->m_error_level = error_manager.m_error_level;
-    pm_error_description = NULL;
-    m_description_length = 0;
-    reallocate_memory_and_copy_string(error_manager.pm_error_description, error_manager.m_description_length);
+	this->m_error_description=error_manager.m_error_description;
     return ;
 }
 //赋值构造
 Error_manager::Error_manager(Error_code error_code, Error_level error_level,
-    const char* p_error_description, int description_length)
+    const char* p_error_description)
 {
     m_error_code = error_code;
     m_error_level = error_level;
-    pm_error_description = NULL;
-    m_description_length = 0;
-    reallocate_memory_and_copy_string(p_error_description, description_length);
-    return ;
+    if(p_error_description!= nullptr)
+	{
+		m_error_description=std::string(p_error_description);
+	}
+	return ;
 }
 //赋值构造
 Error_manager::Error_manager(Error_code error_code, Error_level error_level , std::string & error_aggregate_string)
 {
     m_error_code = error_code;
     m_error_level = error_level;
-    pm_error_description = NULL;
-    m_description_length = 0;
-    reallocate_memory_and_copy_string(error_aggregate_string);
-    return ;
+    m_error_description=error_aggregate_string;
+	return ;
 }
 //析构函数
 Error_manager::~Error_manager()
 {
-    free_description();
 }
 
 //初始化
@@ -62,44 +55,49 @@ void Error_manager::error_manager_init()
     error_manager_clear_all();
     return;
 }
-//初始化
-void Error_manager::error_manager_init(Error_code error_code, Error_level error_level, const char* p_error_description, int description_length)
+void Error_manager::error_manager_init(Error_code error_code, Error_level error_level, const char* p_error_description)
 {
     m_error_code = error_code;
     m_error_level = error_level;
-    reallocate_memory_and_copy_string(p_error_description, description_length);
-    return ;
+	if(p_error_description!= nullptr)
+	{
+		m_error_description=std::string(p_error_description);
+	}
+	return ;
 }
 //初始化
 void Error_manager::error_manager_init(Error_code error_code, Error_level error_level , std::string & error_aggregate_string)
 {
     m_error_code = error_code;
     m_error_level = error_level;
-    reallocate_memory_and_copy_string(error_aggregate_string);
+    m_error_description=error_aggregate_string;
     return ;
 }
 //重置
-void Error_manager::error_manager_reset(Error_code error_code, Error_level error_level, const char* p_error_description, int description_length)
+void Error_manager::error_manager_reset(Error_code error_code, Error_level error_level, const char* p_error_description)
 {
     m_error_code = error_code;
     m_error_level = error_level;
-    reallocate_memory_and_copy_string(p_error_description, description_length);
-    return ;
+	if(p_error_description!= nullptr)
+	{
+		m_error_description=std::string(p_error_description);
+	}
+	return ;
 }
 //重置
 void Error_manager::error_manager_reset(Error_code error_code, Error_level error_level , std::string & error_aggregate_string)
 {
     m_error_code = error_code;
     m_error_level = error_level;
-    reallocate_memory_and_copy_string(error_aggregate_string);
-    return ;
+    m_error_description=error_aggregate_string;
+	return;
 }
 //重置
 void Error_manager::error_manager_reset(const Error_manager & error_manager)
 {
     this->m_error_code = error_manager.m_error_code;
     this->m_error_level = error_manager.m_error_level;
-    reallocate_memory_and_copy_string(error_manager.pm_error_description, error_manager.m_description_length);
+	this->m_error_description=error_manager.m_error_description;
     return ;
 }
 //清除所有内容
@@ -107,7 +105,7 @@ void Error_manager::error_manager_clear_all()
 {
     m_error_code = SUCCESS;
     m_error_level = NORMAL;
-    free_description();
+	m_error_description.clear();
 	return;
 }
 
@@ -177,51 +175,28 @@ Error_level Error_manager::get_error_level()
     return m_error_level;
 }
 //获取错误描述的指针,(浅拷贝)
-char* Error_manager::get_error_description()
-{
-    return pm_error_description;
-}
-
-int Error_manager::get_description_length()
+std::string Error_manager::get_error_description()
 {
-	return m_description_length;
+    return m_error_description;
 }
 
 //复制错误描述,(深拷贝)
 //output:p_error_description     错误描述的字符串指针,不可以为NULL,必须要有实际的内存
 //output:description_length      错误描述的字符串长度,不可以为0,长度最好足够大,一般256即可。
-void Error_manager::copy_error_description(const char* p_error_description, int description_length)
+void Error_manager::copy_error_description(const char* p_error_description)
 {
-    if(p_error_description != NULL && pm_error_description != NULL)
+    if(p_error_description != NULL)
     {
-        char *pt_source = (char *)p_error_description;
-        char* pt_destination = pm_error_description;
-
-        int t_length_min = m_description_length;
-        if(m_description_length > description_length)
-        {
-            t_length_min = description_length;
-        }
-
-        for(int i=0;i<t_length_min; i++)
-        {
-            *pt_destination = *pt_source;
-            pt_destination++;
-            pt_source++;
-        }
+        m_error_description=std::string(p_error_description);
     }
-
-    return;
+	return;
 }
 //复制错误描述,(深拷贝)
 //output:error_description_string     错误描述的string
 void Error_manager::copy_error_description(std::string & error_description_string)
 {
-    if( (!error_description_string.empty() ) && pm_error_description != NULL)
-    {
-        error_description_string = pm_error_description;
-    }
-    return;
+    m_error_description=error_description_string;
+	return;
 }
 
 //设置错误码
@@ -255,65 +230,33 @@ void Error_manager::set_error_level_location(Error_level error_level)
     return;
 }
 //设置错误描述
-void Error_manager::set_error_description(const char* p_error_description, int description_length)
+void Error_manager::set_error_description(const char* p_error_description)
 {
-    reallocate_memory_and_copy_string(p_error_description, description_length);
-    return ;
+	if(p_error_description != NULL)
+	{
+		m_error_description=std::string(p_error_description);
+	}
+	return;
 }
 //设置错误描述
 void Error_manager::set_error_description(std::string & error_description_string)
 {
-    reallocate_memory_and_copy_string(error_description_string);
-    return ;
+	m_error_description = error_description_string;
+	return ;
 }
 
 //尾部追加错误描述
-void Error_manager::add_error_description(const char* p_error_description, int description_length)
+void Error_manager::add_error_description(const char* p_error_description)
 {
     if(p_error_description !=NULL)
     {
-        char* pt_description_front = pm_error_description;
-        int t_description_front_length = m_description_length;
-        char* pt_description_back = (char *)p_error_description;
-        int t_description_back_length = 0;
-
-        if(description_length == 0)
-        {
-            t_description_back_length = 0;
-            while (*pt_description_back != '\0')
-            {
-                t_description_back_length++;
-                pt_description_back++;
-            }
-            t_description_back_length++;
-            pt_description_back = (char *)p_error_description;
-        }
-        else
-        {
-            t_description_back_length = description_length;
-        }
-
-        int t_description_new_length = t_description_front_length + 5 + t_description_back_length - 1;
-        char* pt_description_new =  (char*) malloc(t_description_new_length );
-
-        sprintf(pt_description_new, "%s ### %s", pt_description_front, pt_description_back);
-        free_description();
-        pm_error_description = pt_description_new;
-        m_description_length = t_description_new_length;
+        m_error_description+=std::string(p_error_description);
     }
-    return ;
 }
 //尾部追加错误描述
 void Error_manager::add_error_description(std::string & error_description_string)
 {
-    if( ! error_description_string.empty() )
-    {
-        std::string t_description_string = pm_error_description ;
-        t_description_string += (" ### "+ error_description_string);
-
-        reallocate_memory_and_copy_string(t_description_string);
-    }
-	return;
+    m_error_description+=error_description_string;
 }
 
 //比较错误是否相同,
@@ -345,24 +288,17 @@ void Error_manager::compare_and_cover_error(const Error_manager & error_manager)
     else
     {
         Error_manager t_error_manager_new;
-        char* pt_string_inside = NULL;
-        int t_string_inside_length = 0;
+        std::string pt_string_inside ;
         if(this->m_error_level < error_manager.m_error_level)
         {
-            t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + this->m_description_length;
-            pt_string_inside = (char*)malloc(t_string_inside_length);
-            translate_error_to_string(pt_string_inside, t_string_inside_length);
-
+            translate_error_to_string(pt_string_inside);
             error_manager_reset(error_manager);
-            add_error_description(pt_string_inside,t_string_inside_length);
+            add_error_description(pt_string_inside);
         }
         else
         {
-            t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + error_manager.m_description_length;
-            pt_string_inside = (char*)malloc(t_string_inside_length);
-			((Error_manager & )error_manager).translate_error_to_string(pt_string_inside, t_string_inside_length);
-
-            add_error_description(pt_string_inside,t_string_inside_length);
+			((Error_manager&)error_manager).translate_error_to_string(pt_string_inside);
+            add_error_description(pt_string_inside);
         }
     }
 	return;
@@ -377,93 +313,48 @@ void Error_manager::compare_and_cover_error( Error_manager * p_error_manager)
 	}
 	else if (p_error_manager->m_error_code == SUCCESS)
 	{
-		//
+		return;
 	}
 	else
 	{
 		Error_manager t_error_manager_new;
-		char* pt_string_inside = NULL;
-		int t_string_inside_length = 0;
+		std::string pt_string_inside;
 		if(this->m_error_level < p_error_manager->m_error_level)
 		{
-			t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + this->m_description_length;
-			pt_string_inside = (char*)malloc(t_string_inside_length);
-			translate_error_to_string(pt_string_inside, t_string_inside_length);
-
+			translate_error_to_string(pt_string_inside);
 			error_manager_reset(*p_error_manager);
-			add_error_description(pt_string_inside,t_string_inside_length);
+			add_error_description(pt_string_inside);
 		}
 		else
 		{
-			t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + p_error_manager->m_description_length;
-			pt_string_inside = (char*)malloc(t_string_inside_length);
-			p_error_manager->translate_error_to_string(pt_string_inside, t_string_inside_length);
-
-			add_error_description(pt_string_inside,t_string_inside_length);
+			p_error_manager->translate_error_to_string(pt_string_inside);
+			add_error_description(pt_string_inside);
 		}
 	}
-	return;
 }
 
-//将所有的错误信息,格式化为字符串,用作日志打印。
-//output:p_error_description     错误汇总的字符串指针,不可以为NULL,必须要有实际的内存
-//output:description_length      错误汇总的字符串长度,不可以为0,长度最好足够大,一般256即可。
-void Error_manager::translate_error_to_string(char* p_error_aggregate, int aggregate_length )
-{
-    char t_string_array[ERROR_NAMAGER_TO_STRING_FRONT_LENGTH] = {0};
-    char* pt_index_front = t_string_array;
-    char* pt_index_back = pm_error_description;
-    char* pt_index = p_error_aggregate;
-
-    sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:", m_error_code , m_error_level );
 
-    int t_length_min = m_description_length + ERROR_NAMAGER_TO_STRING_FRONT_LENGTH -1;
-    if(t_length_min > aggregate_length)
-    {
-        t_length_min = aggregate_length;
-    }
-
-    for(int i=0;i<t_length_min; i++)
-    {
-        if(i < ERROR_NAMAGER_TO_STRING_FRONT_LENGTH -1)
-        {
-            *pt_index = *pt_index_front;
-            pt_index++;
-            pt_index_front++;
-        }
-        else
-        {
-            *pt_index = *pt_index_back;
-            pt_index++;
-            pt_index_back++;
-        }
-    }
-	return;
-}
 //output:error_description_string     错误汇总的string
 void Error_manager::translate_error_to_string(std::string & error_aggregate_string)
 {
-    char t_string_array[ERROR_NAMAGER_TO_STRING_FRONT_LENGTH] = {0};
-    sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:", m_error_code , m_error_level );
+    char t_string_array[255] = {0};
+    sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:",
+            m_error_code , m_error_level);
 
     error_aggregate_string = t_string_array ;
-    if(pm_error_description != NULL)
-    {
-        error_aggregate_string += pm_error_description;
-    }
-    else
-    {
-        //error_aggregate_string += "NULL";
-    }
+	error_aggregate_string+= m_error_description;
 	return;
 }
 //错误码转字符串的简易版,可支持cout<<
 //return     错误汇总的string
 std::string Error_manager::to_string()
 {
-    std::string t_string;
-    translate_error_to_string(t_string);
-    return t_string;
+	char t_string_array[255] = {0};
+	sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:",
+            m_error_code , m_error_level);
+    std::string error_aggregate_string = t_string_array ;
+	error_aggregate_string+= m_error_description;
+	return error_aggregate_string;
 }
 
 
@@ -472,13 +363,6 @@ std::string Error_manager::to_string()
 //释放错误描述的内存,
 void Error_manager::free_description()
 {
-    if(pm_error_description != NULL)
-    {
-        free (pm_error_description);
-        pm_error_description = NULL;
-    }
-    m_description_length = 0;
-	return;
 }
 
 //重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
@@ -486,40 +370,6 @@ void Error_manager::free_description()
 //input:description_length      错误描述的字符串长度,如果为0,则从p_error_description里面获取有效的长度
 void Error_manager::reallocate_memory_and_copy_string(const char* p_error_description, int description_length)
 {
-    free_description();
-
-    if(p_error_description != NULL)
-    {
-        char* pt_source = (char *)p_error_description;
-        char* pt_destination = NULL;
-
-        if(description_length == 0)
-        {
-            m_description_length = 0;
-            while (*pt_source != '\0')
-            {
-                m_description_length++;
-                pt_source++;
-            }
-            m_description_length++;
-            pt_source = (char *)p_error_description;
-        }
-        else
-        {
-            m_description_length = description_length;
-        }
-
-        pm_error_description =  (char*) malloc(m_description_length );
-        pt_destination = pm_error_description;
-
-        for(int i=0;i<m_description_length; i++)
-        {
-            *pt_destination = *pt_source;
-            pt_destination++;
-            pt_source++;
-        }
-    }
-
     return;
 }
 
@@ -528,17 +378,7 @@ void Error_manager::reallocate_memory_and_copy_string(const char* p_error_descri
 //input:error_aggregate_string     错误描述的string
 void Error_manager::reallocate_memory_and_copy_string(std::string & error_aggregate_string)
 {
-    free_description();
-
-    if( ! error_aggregate_string.empty())
-    {
-        m_description_length = error_aggregate_string.length()+1;
-
-        pm_error_description =  (char*) malloc( m_description_length );
-
-        strcpy(pm_error_description ,   error_aggregate_string.c_str()  );
-    }
-	return;
+    return;
 }
 
 

+ 8 - 15
error_code/error_code.h

@@ -473,7 +473,7 @@ public://外部接口函数
     Error_manager(const Error_manager & error_manager);
     //赋值构造
     Error_manager(Error_code error_code, Error_level error_level = NORMAL,
-                  const char* p_error_description = NULL, int description_length = 0);
+                  const char* p_error_description = NULL);
     //赋值构造
     Error_manager(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
     //析构函数
@@ -483,12 +483,12 @@ public://外部接口函数
     void error_manager_init();
     //初始化
     void error_manager_init(Error_code error_code, Error_level error_level = NORMAL,
-                            const char* p_error_description = NULL, int description_length = 0);
+                            const char* p_error_description = NULL);
     //初始化
     void error_manager_init(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
     //重置
     void error_manager_reset(Error_code error_code, Error_level error_level = NORMAL,
-                             const char* p_error_description = NULL, int description_length = 0);
+                             const char* p_error_description = NULL);
     //重置
     void error_manager_reset(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
     //重置
@@ -517,14 +517,12 @@ public://外部接口函数
     //获取错误等级
     Error_level get_error_level();
     //获取错误描述的指针,(浅拷贝)
-    char* get_error_description();
-
-	int get_description_length();
+    std::string get_error_description();
 
     //复制错误描述,(深拷贝)
     //output:p_error_description     错误描述的字符串指针,不可以为NULL,必须要有实际的内存
     //output:description_length      错误描述的字符串长度,不可以为0,长度最好足够大,一般256即可。
-    void copy_error_description(const char* p_error_description, int description_length);
+    void copy_error_description(const char* p_error_description);
     //复制错误描述,(深拷贝)
     //output:error_description_string     错误描述的string
     void copy_error_description(std::string & error_description_string);
@@ -538,12 +536,12 @@ public://外部接口函数
     //错误等级,设定到固定值
     void set_error_level_location(Error_level error_level);
     //设置错误描述
-    void set_error_description(const char* p_error_description, int description_length = 0);
+    void set_error_description(const char* p_error_description);
     //设置错误描述
     void set_error_description(std::string & error_description_string);
 
     //尾部追加错误描述
-    void add_error_description(const char* p_error_description, int description_length = 0);
+    void add_error_description(const char* p_error_description);
     //尾部追加错误描述
     void add_error_description(std::string & error_description_string);
 
@@ -557,10 +555,6 @@ public://外部接口函数
 	//如果错误相同,则保留this的,将输入参数转入描述。
 	void compare_and_cover_error( Error_manager * p_error_manager);
 
-	//将所有的错误信息,格式化为字符串,用作日志打印。
-    //output:p_error_description     错误汇总的字符串指针,不可以为NULL,必须要有实际的内存
-    //output:description_length      错误汇总的字符串长度,不可以为0,长度最好足够大,一般256即可。
-    void translate_error_to_string(char* p_error_aggregate, int aggregate_length);
     //output:error_description_string     错误汇总的string
     void translate_error_to_string(std::string & error_aggregate_string);
     //错误码转字符串的简易版,可支持cout<<
@@ -572,8 +566,7 @@ public://外部接口函数
 protected:
     Error_code              m_error_code;               //错误码
     Error_level             m_error_level;              //错误等级
-    char*                   pm_error_description;       //错误描述
-    int                     m_description_length;       //错误描述的字符长度
+    std::string             m_error_description;
 
 protected://内部功能函数
 public:

+ 2 - 2
system/system_executor.cpp

@@ -319,7 +319,7 @@ void System_executor::execute_for_measure(std::string command_key, int terminal_
 	t_measure_response_msg.set_terminal_id(terminal_id);
 	t_measure_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
 	t_measure_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
-	t_measure_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description(), t_error.get_description_length());
+	t_measure_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
 
 	t_measure_response_msg.mutable_locate_information()->set_locate_x(0);
 	t_measure_response_msg.mutable_locate_information()->set_locate_y(0);
@@ -360,7 +360,7 @@ void System_executor::execute_for_dispatch(std::string command_key, Dispatch_man
 	t_dispatch_response_msg.set_command_key(command_key);
 	t_dispatch_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
 	t_dispatch_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
-	t_dispatch_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description(), t_error.get_description_length());
+	t_dispatch_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
 
 	std::string t_msg = t_dispatch_response_msg.SerializeAsString();
 	System_communication::get_instance_references().encapsulate_msg(t_msg);