#include #include "three_rates_impl.h" #include "struct_def.h" #include "operating_rate.h" #include "worktime_rate.h" #include "log.h" //采煤机开机率测试 void test_coalface_openater(three_rates_impl * r ,int times ) { card_pos pos; pos.work_type_id = 25; pos.rec_time = time(nullptr); pos.type = 4; pos.id = 1192; // 采煤机 pos.x = 3119 ; pos.y = -489.2 ; pos.vibration = times ; r->put(pos); } //采煤机工作测试 void test_coalface_work(three_rates_impl * r,int times ) { static double head_x = 3119; static double head_y = -489.2; static double tail_x = 3268; //static double tail_y = -489.2; static bool bPositive = true; static double cur_x = head_x; card_pos pos; pos.work_type_id = 25; pos.vibration = 100; pos.rec_time = time(nullptr); pos.type = 4; pos.id = 1192; // 采煤机 if (bPositive) { pos.x = (times + 3) / 3 == 0 ? cur_x - 1 : cur_x + times % 5 ; cur_x = pos.x; if (cur_x >= tail_x) { cur_x = tail_x; bPositive = false; } } else { pos.x = (times + 3) / 3 == 0 ? cur_x + 1 : cur_x - times % 5 ; cur_x = pos.x; if (cur_x <= head_x) { cur_x = head_x; bPositive = true; } } pos.y = head_y ; r->put(pos); } void test_drivingface_openater(three_rates_impl * r ,int times ) { card_pos pos; pos.map_id = 5; pos.work_type_id = 26; pos.rec_time = time(nullptr); pos.dpt_id = 56; pos.type = 5; pos.id = 1307; // 工作面6 : 卡1307 pos.x = 2325.9 ; pos.y = 75 ; pos.vibration = times ; r->put(pos); } //掘进机工作测试 void test_drivingface_work(three_rates_impl * r ,int times) { static double g_y = 585;//75; card_pos pos; pos.map_id = 5; pos.running_stat = 1; pos.biz_stat = 1; pos.vibration = 100 ; pos.rec_time = time(nullptr); pos.dpt_id = 56; pos.type = 5; pos.id = 1307; // 掘进机 pos.x = 2325.9 ; g_y = g_y + (double )(rand() % 10 - (times % 3 == 0 ? 5 : 3) )/20 ; pos.y = g_y ; pos.work_type_id = 26; pos.reader_id = 2; pos.reader_x = 2000; pos.reader_y = 1000; r->put(pos); } void test_checkdrivingfaceInfo(three_rates_impl * r ,int t) { static int g_last_time = 0; if (g_last_time == 0 || t - g_last_time >= 2) { g_last_time = t; ChangedDBDate d; d.edit_type_id = 2; d.webname = "drivingface"; //参数 d.param = "6"; r->update_db_data(d.webname,d.param,d.edit_type_id); } } #define MAX_TEST_THREAD 10 struct STestQueue { std::unique_ptr m_thread; three_rates_impl * m_three_rates; int id; int m_num; bool m_stop; bool m_run; STestQueue() { id = m_num = 0; m_stop = false; m_three_rates = nullptr; m_thread = nullptr; m_run = false; } }; STestQueue g_TestQueue[MAX_TEST_THREAD]; void test_queue_work(void * data) { STestQueue* p = (STestQueue*) data; while (true) { if(p->m_stop) { break; } card_pos pos ; pos.id = p->id; p->m_three_rates->put(pos); p->m_num++; usleep(1000 * 10); } } void test_queue(three_rates_impl* p_three) { for (int i = 0 ; i< MAX_TEST_THREAD ; ++i) { g_TestQueue[i].id = i+1; g_TestQueue[i].m_three_rates = p_three; g_TestQueue[i].m_stop = false; g_TestQueue[i].m_run = true; g_TestQueue[i].m_thread.reset(new std::thread(std::bind(&test_queue_work,&g_TestQueue[i]))); g_TestQueue[i].m_thread->detach(); } } void test_stop_queue() { for (int i = 0 ; i< MAX_TEST_THREAD ; ++i) { if (!g_TestQueue[i].m_run) continue; g_TestQueue[i].m_stop = true; } sleep(2); } void test_print_queue(three_rates_impl* p_three) { //打印 for (int i = 0 ; i< MAX_TEST_THREAD ; ++i) { if (!g_TestQueue[i].m_run) continue; int recvNum = g_TestQueue[i].m_three_rates->m_card_sync_num[g_TestQueue[i].id]; printf("Id = %d : sendNum=%d - recvNum=%d = %d \n" ,g_TestQueue[i].id, g_TestQueue[i].m_num, recvNum ,recvNum - g_TestQueue[i].m_num); } } void test_three_rates(three_rates_impl* p_three_rates) { //test_queue(p_three_rates); int openNum = 2; int time1 = 0; srand((int)time(nullptr)); while(time1++0) { //测试函数 //test_coalface_work(p_three_rates,time1); test_drivingface_work(p_three_rates,time1); test_checkdrivingfaceInfo(p_three_rates,time(0)); sleep(1); //std::this_thread::sleep_for (std::chrono::milliseconds(1)); } sleep(3); time1 = 0; while(time1++setRunSoFile(false); p_three_rates->init(para,dpara); p_three_rates->start(); bool ret = p_three_rates->GetVehicleState(1198); cout << "Three_rates Vehicle:1198 state=: " << ret << endl; //功能测试 test_three_rates(p_three_rates); cout << "Three_rates_module Stop ......" << endl; //停止队列测试 test_stop_queue(); p_three_rates->stop(); //打印队列 test_print_queue(p_three_rates); return 0; }