-
Notifications
You must be signed in to change notification settings - Fork 1
/
iodevicelistener.cpp
108 lines (106 loc) · 2.8 KB
/
iodevicelistener.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "iodevicelistener.h"
#include "config.h"
#include"globalinfo.h"
#include"ztpmanager.h"
#include <QTimer>
#include <QDebug>
#include<QNetworkInterface>
#include "ztools.h"
IODeviceListener::IODeviceListener(QObject *parent) :
QObject(parent),cs1(CS1_GPIO,GPIO::H),cs2(CS2_GPIO,GPIO::H),cs3(CS3_GPIO,GPIO::H),
cs4(CS4_GPIO,GPIO::H),slm1(SLM1_GPIO,GPIO::L),slm2(SLM2_GPIO,GPIO::L)
{
comZtpManager = new ZTPManager;
cs_slm_timer_id = startTimer(1000);
if(cs_slm_timer_id == 0)
qDebug("Create cs_slm_timer_id failed!!");
else
qDebug("Create cs_slm_timer_id success!!");
// cs_slm_Timer = new QTimer;
// cs_slm_Timer->setInterval(1000);
// connect(cs_slm_Timer,SIGNAL(timeout()),this,SLOT(onCsSlmTimeout()));
// cs_slm_Timer->setSingleShot(false);
// cs_slm_Timer->start();
}
void IODeviceListener::timerEvent(QTimerEvent* event)
{
if(event->timerId() == cs_slm_timer_id)
{
onCsSlmTimeout();
}
}
QString IODeviceListener::getCs(int ind)
{
bool res;
switch (ind)
{
case 1:
res = cs1.isValid();
break;
case 2:
res = cs2.isValid();
break;
case 3:
res = cs3.isValid();
break;
case 4:
res = cs4.isValid();
break;
default:
res = false;
break;
}
return res?"Y":"N";
}
QString IODeviceListener::getSlm(int ind)
{
bool res;
switch (ind)
{
case 1:
res = slm1.isValid();
break;
case 2:
res = slm2.isValid();
break;
default:
res = false;
break;
}
return res?"OPEN":"CLOSE";
}
void IODeviceListener::onCsSlmTimeout()
{
//GlobalInfo::getInstance()->debugStack.appendStack(QThread::currentThreadId(),"ready entry onCsSlmTimeout");
static int sec = 0;
if(++sec >= 10)
{
qDebug(" onCsSlmTimeout");
sec = 0;
}
QString sta_cs1 = getCs(1);
QString sta_cs2 = getCs(2);
QString sta_cs3 = getCs(3);
QString sta_cs4 = getCs(4);
QString sta_slm1 = getSlm(1);
QString sta_slm2 = getSlm(2);
ZTPprotocol ztp;
ztp.addPara("T","SLM_STATE");
ztp.addPara("CAR_ID",QString::number( ZTools::getCarID()));//车厢号
ztp.addPara("SLM1",sta_slm1);
ztp.addPara("SLM2",sta_slm2);
comZtpManager->SendOneZtp(ztp,QHostAddress(BROADCAST_IP),3320);
ztp.clear();
ztp.addPara("T","CS_STATE");
ztp.addPara("CAR_ID",QString::number( ZTools::getCarID()));//车厢号
ztp.addPara("CS1",sta_cs1);
ztp.addPara("CS2",sta_cs2);
ztp.addPara("CS3",sta_cs3);
ztp.addPara("CS4",sta_cs4);
comZtpManager->SendOneZtp(ztp,QHostAddress(BROADCAST_IP),3321);
//GlobalInfo::getInstance()->debugStack.appendStack(QThread::currentThreadId(),"leave onCsSlmTimeout");
}
IODeviceListener::~IODeviceListener()
{
// delete cs_slm_Timer;
}