123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- #include <iostream>
- #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<std::thread> 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++<openNum)
- {
- //测试开机函数
- //test_coalface_openater(p_three_rates,time1 * 10);
- test_drivingface_openater(p_three_rates,time1 * 10);
- sleep(1);
- }
- time1 = 100000000;
- 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++<openNum)
- {
- //测试函数 关机
- //test_coalface_openater(p_three_rates,0);
- test_drivingface_openater(p_three_rates,0);
- sleep(1);
- }
- }
- //三率模块中告警回调
- void Handle_ThreeRates_Event_Callback(const int evType, const int evId, uint64_t id
- , double limitVal, double curVal, bool bFalg)
- {
- }
- int main()
- {
- log_init("../etc/log.ini");
- three_rates_impl* p_three_rates = three_rates_impl::_instance();
- card_pos pos;
- init_para para;
- para.driving_face_alarm = Handle_ThreeRates_Event_Callback;
- SendCallBack psaf = Handle_ThreeRates_Event_Callback;
- psaf(1,1,1,1,1,1);
- db_para dpara;
- dpara.Host = "127.0.0.1";
- dpara.User = "root";
- dpara.PWD="123456";
- dpara.DBName="yaxt4";
- dpara.CharSet="utf8";
- dpara.TimeOut=5;
- dpara.PoolSize=10;
- p_three_rates->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;
- }
|