Browse Source

增加测试代码

zx 4 years ago
parent
commit
f877164c78

+ 0 - 10
communication/communication_socket_base.cpp

@@ -249,18 +249,9 @@ void Communication_socket_base::receive_data_thread(Communication_socket_base* c
 			if ( t_receive_string.length()>0 )
 			{
 				//如果这里接受到了消息, 在这提前解析消息最前面的Base_msg (消息公共内容), 用于后续的check
-				std::cout<<"  recieve  length "<<t_receive_string.length()<<std::endl;
 				message::Base_msg t_base_msg;
 				if( t_base_msg.ParseFromString(t_receive_string) )
 				{
-				    std::cout<<"   TYPE ====   "<<t_base_msg.base_info().msg_type()<<std::endl;
-
-				    message::Measure_response_msg response;
-				    if(response.ParseFromString(t_receive_string))
-				        std::cout<<response.DebugString()<<std::endl;
-                    else
-                        std::cout<<"   response EROR************************"<<std::endl;
-
 					//第一次解析之后转化为, Communication_message, 自定义的通信消息格式
 					Communication_message  * tp_communication_message = new Communication_message;
 					tp_communication_message->reset(t_base_msg.base_info(), t_receive_string);
@@ -289,7 +280,6 @@ void Communication_socket_base::receive_data_thread(Communication_socket_base* c
 						tp_communication_message = NULL;
 					}
 
-
 				}
 				//解析失败, 就当做什么也没发生, 认为接收消息无效,
 			}

+ 25 - 8
lidar_locate/Locate_communicator.cpp

@@ -95,6 +95,10 @@ Error_manager Locate_communicator::locate_request(message::Measure_request_msg&
     return Error_manager(RESPONSE_TIMEOUT,MINOR_ERROR,"measure request timeout");
 }
 
+message::Measure_status_msg Locate_communicator::get_statu()
+{
+
+}
 
 Error_manager Locate_communicator::execute_msg(Communication_message* p_msg)
 {
@@ -103,17 +107,30 @@ Error_manager Locate_communicator::execute_msg(Communication_message* p_msg)
 
 
     //测量response消息
-    if(p_msg->get_message_type()==Communication_message::eLocate_response_msg)
+    switch (p_msg->get_message_type())
     {
-        message::Measure_response_msg response;
-        response.ParseFromString(p_msg->get_message_buf());
-        ///查询请求表是否存在
-        if(m_response_table.find(response.command_id())==m_response_table.end())
+        ///测量结果反馈消息
+        case Communication_message::eLocate_response_msg:
         {
-            return Error_manager(LOCATER_MSG_RESPONSE_HAS_NO_REQUEST,NEGLIGIBLE_ERROR,"measure response without request");
+            message::Measure_response_msg response;
+            response.ParseFromString(p_msg->get_message_buf());
+            ///查询请求表是否存在
+            if(m_response_table.find(response.command_id())==m_response_table.end())
+            {
+                return Error_manager(LOCATER_MSG_RESPONSE_HAS_NO_REQUEST,NEGLIGIBLE_ERROR,"measure response without request");
+            }
+            ////更新表
+            m_response_table[response.command_id()]=response;
+            break;
+        }
+        ///测量系统状态
+        case Communication_message::eLocate_status_msg:
+        {
+            m_measure_statu_msg=*p_msg;
+            break;
         }
-        ////更新表
-        m_response_table[response.command_id()]=response;
     }
+
+
 }
 

+ 2 - 0
lidar_locate/Locate_communicator.h

@@ -21,6 +21,7 @@ public:
     virtual ~Locate_communicator();
     Error_manager locate_request(message::Measure_request_msg& request,message::Measure_response_msg& result);
 
+    message::Measure_status_msg get_statu();
 
 protected:
     Locate_communicator();
@@ -30,6 +31,7 @@ protected:
 protected:
 
     thread_safe_map<int,message::Measure_response_msg>         m_response_table;
+    Communication_message                                       m_measure_statu_msg;
 };
 
 

+ 56 - 0
test/Locate_client.cpp

@@ -0,0 +1,56 @@
+//
+// Created by zx on 2020/7/3.
+//
+
+#include <iostream>
+#include <nnxx/message>
+#include <nnxx/socket.h>
+#include <nnxx/bus.h>
+
+#include "measure_message.pb.h"
+#include <thread>
+int main()
+{
+    nnxx::socket socket{ nnxx::SP, nnxx::BUS };
+    socket.bind("tcp://127.0.0.1:9006");
+    socket.connect("tcp://127.0.0.1:9005");
+    int n=0;
+
+    while(1)
+    {
+        std::string t_receive_string = socket.recv<std::string>(1);
+        if(t_receive_string.length()>0) {
+
+            message::Base_info base_msg;
+            message::Measure_response_msg response;
+            message::Measure_request_msg request;
+
+            message::Error_manager error_code;
+            request.ParseFromString(t_receive_string);
+
+            base_msg.set_msg_type(message::eLocate_response_msg);
+            base_msg.set_sender(message::eMeasurer);
+            base_msg.set_receiver(message::eMain);
+
+
+            response.set_command_id(request.command_id());
+            response.set_terminal_id(4);
+            response.mutable_base_info()->CopyFrom(base_msg);
+
+
+            error_code.set_error_code(n++);
+            response.mutable_error_manager()->CopyFrom(error_code);
+
+            std::cout<<response.DebugString()<<std::endl;
+
+            socket.send(response.SerializeAsString());
+
+            std::cout<<" response length : "<<response.SerializeAsString().length()<<std::endl;
+
+
+        }
+        std::this_thread::yield();
+
+    }
+
+}

+ 57 - 0
test/test_locate_sample.cpp

@@ -0,0 +1,57 @@
+//
+// Created by zx on 2020/7/3.
+//
+#include <iostream>
+#include "../lidar_locate/Locate_communicator.h";
+#include <unistd.h>
+#include "../tool/thread_safe_list.h"
+int main()
+{
+
+    Locate_communicator* pLocator=Locate_communicator::get_instance_pointer();
+
+    pLocator->communication_bind("tcp://127.0.0.1:9005");
+    pLocator->communication_connect("tcp://127.0.0.1:9006");
+
+    pLocator->communication_run();
+    int k=1;
+    Thread_safe_list<std::string*> list;
+    /*nnxx::socket socket{ nnxx::SP, nnxx::BUS };
+    socket.bind("tcp://127.0.0.1:9005");
+    socket.connect("tcp://127.0.0.1:9006");*/
+
+    while(1) {
+        message::Measure_request_msg request;
+        message::Base_info base_msg;
+
+
+        request.mutable_base_info()->CopyFrom(base_msg);
+        request.mutable_base_info()->set_msg_type(message::eLocate_request_msg);
+        request.mutable_base_info()->set_sender(message::eMain);
+        request.mutable_base_info()->set_receiver(message::eMeasurer);
+        request.mutable_base_info()->set_timeout_ms(1000);
+
+        request.set_command_id(222);
+        request.set_terminal_id(0);
+        message::Measure_response_msg response;
+
+       message::Measure_request_msg request_1;
+        std::string str=request.SerializeAsString();
+
+        //socket.send(request_1.SerializeAsString());
+
+        Error_manager code=pLocator->locate_request(request,response);
+        if(code!=SUCCESS)
+        {
+            std::cout<<code.to_string()<<std::endl;
+        }
+        else if(request.command_id()==response.command_id()){
+            std::cout<<" Success request command :"<<request.command_id()<<std::endl;
+        }
+        k++;
+
+        usleep(1000*500);
+    }
+
+    return 0;
+}