|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace MIVA
|
|
|
{
|
|
|
+ ThreadPool poolInfer(4,ThreadPool::PRIORITY_HIGHEST, false);
|
|
|
+
|
|
|
std::shared_ptr<UserApp> UserApp::CreateNew(){
|
|
|
return std::make_shared<UserApp>();
|
|
|
}
|
|
@@ -113,6 +115,11 @@ namespace MIVA
|
|
|
[&](const Buffer::Ptr &pBuf){
|
|
|
this->ListenNettyData(pBuf);
|
|
|
});
|
|
|
+
|
|
|
+ // 监听关门广播
|
|
|
+ NoticeCenter::Instance().addListener(0, NOTICE_CLOSED,[&](){
|
|
|
+ this->ListenClosed();
|
|
|
+ });
|
|
|
|
|
|
InfoL << "System initialization is successful!";
|
|
|
return OK;
|
|
@@ -126,14 +133,12 @@ namespace MIVA
|
|
|
// 启动任务
|
|
|
void UserApp::StartTask()
|
|
|
{
|
|
|
- // 创建推理线程池
|
|
|
- ThreadPool poolInfer(4,ThreadPool::PRIORITY_HIGHEST, false);
|
|
|
-
|
|
|
// 挂起任务一
|
|
|
+
|
|
|
poolInfer.async([&](){
|
|
|
- if(m_Infer != NULL) m_Infer->StartTask();
|
|
|
+ if(this->m_Infer != NULL) m_Infer->StartTask();
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// 挂起函数回调
|
|
|
this->m_udpClient->setOnRead([&](const Buffer::Ptr &buf, struct sockaddr *addr , int){
|
|
|
this->ListenPISData(buf, addr);
|
|
@@ -153,29 +158,25 @@ namespace MIVA
|
|
|
return true;
|
|
|
}, nullptr);
|
|
|
|
|
|
- // 启动任务
|
|
|
- poolInfer.start();
|
|
|
InfoL << "Task started successfully!";
|
|
|
}
|
|
|
|
|
|
// 监听推理广播
|
|
|
void UserApp::ListenInfer(int Source_id, int num)
|
|
|
{
|
|
|
- static int ret = 0;
|
|
|
- if(ret == 0){
|
|
|
+ if(this->play == true){
|
|
|
this->m_timer2 = std::make_shared<Timer>(3.0f,[&](){
|
|
|
// 暂停任务
|
|
|
this->m_Infer->PauseTask();
|
|
|
return false;
|
|
|
}, nullptr);
|
|
|
- ret++;
|
|
|
+ this->play = false;
|
|
|
}
|
|
|
char ctime[80];
|
|
|
vector<vector<std::string>> sqlRet;
|
|
|
getDataTime(ctime);
|
|
|
|
|
|
int id = this->DataList[Source_id].Id;
|
|
|
- // Source_id +=1;
|
|
|
SqlWriter updataSql("UPDATE MIVA_DB.DataSources SET Num = '?',DataTime = '?' WHERE Id = '?';");
|
|
|
updataSql << num << ctime << id << sqlRet;
|
|
|
}
|
|
@@ -229,9 +230,6 @@ namespace MIVA
|
|
|
void UserApp::ListenNettyData(const Buffer::Ptr &pBuf)
|
|
|
{
|
|
|
// 对Netty端的接口
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
// 处理PIS系统的数据
|
|
|
void UserApp::ListenPISData(const Buffer::Ptr &buf, struct sockaddr *addr)
|
|
@@ -240,23 +238,27 @@ namespace MIVA
|
|
|
vector<vector<std::string>> sqlRet;
|
|
|
// 接受到PIS发送的数据
|
|
|
PIDSServerResultMsg serverResultMag;
|
|
|
+ InfoL << "wwwww";
|
|
|
// 反序列化
|
|
|
if(serverResultMag.Deserialization((uint8_t *)(buf->data()), buf->size()) == OK)
|
|
|
{
|
|
|
// 将收到的第一条PIS系统的数据作为空载荷
|
|
|
// 同步
|
|
|
+ char ctime[80];
|
|
|
if(num == 0){
|
|
|
- SqlWriter updataSql("UPDATE MIVA_DB.CarData SET NoLoad = '?' WHERE CarId = '?';");
|
|
|
for(int id=1; id <= 6 ; id ++){
|
|
|
- updataSql << serverResultMag.DynamicLoad[id] << id << sqlRet;
|
|
|
+ SqlWriter updataSql("UPDATE MIVA_DB.CarData SET NoLoad = '?',dataTime = '?' WHERE CarId = '?';");
|
|
|
+ getDataTime(ctime);
|
|
|
+ updataSql << serverResultMag.DynamicLoad[id] << ctime << id << sqlRet;
|
|
|
}
|
|
|
num++;
|
|
|
}else
|
|
|
{
|
|
|
// 记录动态载荷
|
|
|
- SqlWriter updataSql("UPDATE MIVA_DB.CarData SET DynamicLoad = '?' WHERE CarId = '?';");
|
|
|
for(int id=1; id <= 6 ; id ++){
|
|
|
- updataSql << serverResultMag.DynamicLoad[id] << id << sqlRet;
|
|
|
+ SqlWriter updataSql("UPDATE MIVA_DB.CarData SET DynamicLoad = '?', dataTime = '?' WHERE CarId = '?';");
|
|
|
+ getDataTime(ctime);
|
|
|
+ updataSql << serverResultMag.DynamicLoad[id] << ctime << id << sqlRet;
|
|
|
}
|
|
|
}
|
|
|
// 获取到关好门的信号
|
|
@@ -267,7 +269,6 @@ namespace MIVA
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//赋值struct sockaddr
|
|
|
void UserApp::makeAddr(struct sockaddr *out,const char *ip,uint16_t port){
|
|
|
struct sockaddr_in &servaddr = *((struct sockaddr_in *)out);
|
|
@@ -276,14 +277,26 @@ namespace MIVA
|
|
|
servaddr.sin_addr.s_addr = inet_addr(ip);
|
|
|
bzero(&(servaddr.sin_zero), sizeof servaddr.sin_zero);
|
|
|
}
|
|
|
-
|
|
|
//监听关门信号
|
|
|
void UserApp::ListenClosed()
|
|
|
{
|
|
|
- // 收到关门信号
|
|
|
+ static int num = 0;
|
|
|
+ if(num == 0){
|
|
|
+ // 创建推理线程池
|
|
|
+ poolInfer.start();
|
|
|
+ num++;
|
|
|
+ }else{
|
|
|
+ if(this->m_Infer != NULL) m_Infer->RestartTask();
|
|
|
+ this->play = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 监听推理数据
|
|
|
+ void UserApp::ListenInferData()
|
|
|
+ {
|
|
|
+ // 监听推理结束
|
|
|
// 获取CarId、空载荷值、动态载荷值
|
|
|
std::map<int, CarData> carDatas;
|
|
|
-
|
|
|
+
|
|
|
vector<vector<string>> sqlRet;
|
|
|
SqlWriter sqlSelect0("SELECT CarId,NoLoad,DynamicLoad FROM MIVA_DB.`CarData`");
|
|
|
sqlSelect0 << sqlRet;
|
|
@@ -297,7 +310,7 @@ namespace MIVA
|
|
|
data.loadData.DynamicLoad = atoi(line[2].c_str());
|
|
|
carDatas[atoi(line[0].c_str())] = data;
|
|
|
}
|
|
|
- SqlWriter sqlSelect1("SELECT CarId,Uri,Num FROM MIVA_DB.`DataSources` WHERE Play = 1");
|
|
|
+ SqlWriter sqlSelect1("SELECT CarId,Uri,Num FROM MIVA_DB.`DataSources` WHERE Play = 1;");
|
|
|
sqlRet.clear();
|
|
|
sqlSelect1 << sqlRet;
|
|
|
for (auto &line : sqlRet)
|
|
@@ -313,7 +326,7 @@ namespace MIVA
|
|
|
std::map<int, CarData>::iterator iter;
|
|
|
for(iter=carDatas.begin(); iter!=carDatas.end(); iter++)
|
|
|
{
|
|
|
- SqlWriter sqlUpdata("UPDATA MIVA_DB.CarData SET Grade = '?',DataTime = '?', Num = '?' WHERE CarId = '?'");
|
|
|
+ SqlWriter sqlUpdata("UPDATE MIVA_DB.CarData SET Grade = '?', Num = '?', dataTime = '?' WHERE CarId = '?';");
|
|
|
|
|
|
int sum = 0;
|
|
|
std::list<CarInferData>::iterator it;
|
|
@@ -322,20 +335,20 @@ namespace MIVA
|
|
|
}
|
|
|
int result = DataCalculation(iter->second.loadData.NoLoad, iter->second.loadData.DynamicLoad, sum);
|
|
|
int grade = GradeDetermination(result);
|
|
|
-
|
|
|
char ctime[80];
|
|
|
getDataTime(ctime);
|
|
|
// 更新数据
|
|
|
- sqlUpdata << grade << ctime << result << iter->first << sqlRet;
|
|
|
+ sqlUpdata << grade << result << ctime << iter->first << sqlRet;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 数据计算
|
|
|
uint32_t UserApp::DataCalculation(uint32_t noLoad, uint32_t dynamicLoad, int num)
|
|
|
{
|
|
|
- uint32_t result;
|
|
|
+ uint32_t result = 0;
|
|
|
|
|
|
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -345,7 +358,7 @@ namespace MIVA
|
|
|
// 等级1 - 4
|
|
|
uint8_t grade = 1;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
return grade;
|
|
|
}
|
|
|
|