|
@@ -15,98 +15,115 @@
|
|
|
#include <thread>
|
|
|
#include "threadSafeQueue.h"
|
|
|
|
|
|
-std::mutex lock;
|
|
|
-
|
|
|
-threadsafe_queue<std::string> license_queue;
|
|
|
#include "Terminal_communication.h"
|
|
|
+#include "store_terminal.h"
|
|
|
+#include "pickup_terminal.h"
|
|
|
+#include "pathcreator.h"
|
|
|
|
|
|
-void pickup()
|
|
|
+GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
|
|
|
{
|
|
|
- message::Base_info base_msg;
|
|
|
- message::Pickup_command_request_msg request;
|
|
|
-
|
|
|
- base_msg.set_msg_type(message::ePickup_command_request_msg);
|
|
|
- base_msg.set_sender(message::eTerminor);
|
|
|
- base_msg.set_receiver(message::eMain);
|
|
|
- request.mutable_base_info()->CopyFrom(base_msg);
|
|
|
-
|
|
|
- int command_id = rand() % 900000 + 100000;
|
|
|
- char license[255] = {0};
|
|
|
- sprintf(license, "鄂A%d", command_id);
|
|
|
-
|
|
|
- request.set_terminal_id(command_id % 6);
|
|
|
- message::Car_info car_info;
|
|
|
- car_info.set_license(license);
|
|
|
- car_info.set_car_height(1.5);
|
|
|
- car_info.set_car_width(1.7);
|
|
|
- request.mutable_car_info()->CopyFrom(car_info);
|
|
|
-
|
|
|
- message::Pickup_command_response_msg response;
|
|
|
- Error_manager code=Terminal_communication::get_instance_pointer()->pickup_request(request,response);
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- std::cout<<code.to_string()<<std::endl;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(response.code().error_code()!=0)
|
|
|
- {
|
|
|
- std::cout<<response.code().error_description()<<std::endl;
|
|
|
- }
|
|
|
- }
|
|
|
+ time_t tt;
|
|
|
+ time( &tt );
|
|
|
+ tt = tt + 8*3600; // transform the time zone
|
|
|
+ tm* t= gmtime( &tt );
|
|
|
+ char buf[255]={0};
|
|
|
+ sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump_client.txt",
|
|
|
+ t->tm_year + 1900,
|
|
|
+ t->tm_mon + 1,
|
|
|
+ t->tm_mday,
|
|
|
+ t->tm_hour,
|
|
|
+ t->tm_min,
|
|
|
+ t->tm_sec);
|
|
|
+
|
|
|
+ FILE* tp_file=fopen(buf,"w");
|
|
|
+ fprintf(tp_file,data,strlen(data));
|
|
|
+ fclose(tp_file);
|
|
|
|
|
|
}
|
|
|
|
|
|
+void init_glog()
|
|
|
+{
|
|
|
+ time_t tt = time(0);//时间cuo
|
|
|
+ struct tm* t = localtime(&tt);
|
|
|
+
|
|
|
+ char strYear[255]={0};
|
|
|
+ char strMonth[255]={0};
|
|
|
+ char strDay[255]={0};
|
|
|
+
|
|
|
+ sprintf(strYear,"%04d", t->tm_year+1900);
|
|
|
+ sprintf(strMonth,"%02d", t->tm_mon+1);
|
|
|
+ sprintf(strDay,"%02d", t->tm_mday);
|
|
|
+
|
|
|
+ char buf[255]={0};
|
|
|
+ getcwd(buf,255);
|
|
|
+ char strdir[255]={0};
|
|
|
+ sprintf(strdir,"%s/log_client/%s/%s/%s", buf,strYear,strMonth,strDay);
|
|
|
+ PathCreator creator;
|
|
|
+ creator.Mkdir(strdir);
|
|
|
+
|
|
|
+ char logPath[255] = { 0 };
|
|
|
+ sprintf(logPath, "%s/", strdir);
|
|
|
+ FLAGS_max_log_size = 100;
|
|
|
+ FLAGS_logbufsecs = 0;
|
|
|
+ google::InitGoogleLogging("LidarMeasurement");
|
|
|
+ google::SetStderrLogging(google::INFO);
|
|
|
+ google::SetLogDestination(0, logPath);
|
|
|
+ google::SetLogFilenameExtension("zxlog");
|
|
|
+ google::InstallFailureSignalHandler();
|
|
|
+ google::InstallFailureWriter(&shut_down_logging);
|
|
|
+ FLAGS_colorlogtostderr = true; // Set log color
|
|
|
+ FLAGS_logbufsecs = 0; // Set log output speed(s)
|
|
|
+ FLAGS_max_log_size = 1024; // Set max log file size(GB)
|
|
|
+ FLAGS_stop_logging_if_full_disk = true;
|
|
|
+}
|
|
|
+
|
|
|
int main() {
|
|
|
+ init_glog();
|
|
|
Terminal_communication::get_instance_pointer()->communication_connect("tcp://127.0.0.1:9001");
|
|
|
Terminal_communication::get_instance_pointer()->communication_run();
|
|
|
+ usleep(2000*1000);
|
|
|
+ threadsafe_queue<message::Car_info> input_queue;
|
|
|
+ threadsafe_queue<message::Car_info> output_queue;
|
|
|
+
|
|
|
+ const int n_input=6;
|
|
|
+ const int n_output=6;
|
|
|
+ std::vector<store_terminal*> input_terminals;
|
|
|
+ std::vector<pickup_terminal*> output_terminals;
|
|
|
+ for(int i=0;i<n_input;++i)
|
|
|
+ {
|
|
|
+ store_terminal* store=new store_terminal(i);
|
|
|
+ store->init(&input_queue,&output_queue);
|
|
|
+ input_terminals.push_back(store);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i=0;i<n_output;++i)
|
|
|
+ {
|
|
|
+ pickup_terminal* picker=new pickup_terminal(i);
|
|
|
+ picker->init(&output_queue);
|
|
|
+ output_terminals.push_back(picker);
|
|
|
+ }
|
|
|
|
|
|
int n = 0;
|
|
|
bool run = true;
|
|
|
Error_manager code;
|
|
|
- //std::thread* pth=new std::thread(cancel_thread);
|
|
|
while (run) {
|
|
|
- pickup();
|
|
|
- /*message::Base_info base_msg;
|
|
|
- message::Store_command_request_msg request;
|
|
|
|
|
|
- base_msg.set_msg_type(message::eStore_command_request_msg);
|
|
|
- base_msg.set_sender(message::eTerminor);
|
|
|
- base_msg.set_receiver(message::eMain);
|
|
|
- request.mutable_base_info()->CopyFrom(base_msg);
|
|
|
-
|
|
|
- int command_id = rand() % 900000 + 100000;
|
|
|
+ int license_id = rand() % 90000 + 10000;
|
|
|
+ char C=rand()%10+'A';
|
|
|
char license[255] = {0};
|
|
|
- sprintf(license, "鄂A%d", command_id);
|
|
|
-
|
|
|
- request.set_terminal_id(command_id % 6);
|
|
|
+ sprintf(license, "鄂%c%d",C, license_id);
|
|
|
message::Car_info car_info;
|
|
|
car_info.set_license(license);
|
|
|
car_info.set_car_height(1.5);
|
|
|
car_info.set_car_width(1.7);
|
|
|
- request.mutable_car_info()->CopyFrom(car_info);
|
|
|
- message::Locate_information locate_info;
|
|
|
- locate_info.set_locate_x(0.9);
|
|
|
- locate_info.set_locate_y(2.25);
|
|
|
- locate_info.set_locate_angle(90.0);
|
|
|
- locate_info.set_locate_wheel_base(2.7);
|
|
|
- locate_info.set_locate_width(1.7);
|
|
|
- locate_info.set_locate_height(1.5);
|
|
|
- locate_info.set_locate_correct(true);
|
|
|
- request.mutable_locate_information()->CopyFrom(locate_info);
|
|
|
-
|
|
|
- message::Store_command_response_msg response;
|
|
|
- code=Terminal_communication::get_instance_pointer()->store_request(request,response);
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- std::cout<<code.to_string()<<std::endl;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("N:%08d\n",n++);
|
|
|
- }*/
|
|
|
- //每两秒发送一次
|
|
|
- usleep(1000*1000);
|
|
|
+ input_queue.push(car_info);
|
|
|
+
|
|
|
+ int in_count=input_queue.size();
|
|
|
+ int out_count=output_queue.size();
|
|
|
+
|
|
|
+ //暂停 5-15s 代替
|
|
|
+ int delay=in_count*200;
|
|
|
+ usleep(1000*delay+1);
|
|
|
std::this_thread::yield();
|
|
|
}
|
|
|
}
|