-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmakepacket.cpp
300 lines (276 loc) · 8.58 KB
/
makepacket.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include "makepacket.h"
#include "ui_makepacket.h"
MakePacket::MakePacket(QWidget *parent) :
QDialog(parent),
ui(new Ui::MakePacket)
{
ui->setupUi(this);
//报文名称初始化
packetsName.resize(packetNum);
packetsName[0] = "信号采集板采集报文";
packetsName[1] = "设备间主控箱控制报文";
packetsName[2] = "采集模块状态报文";
packetsName[3] = "轨旁控制箱状态监测报文";
packetsName[4] = "板卡信息报文";
gatherPacket = new GatherPacket(this);
controlPacket = new ControlPacket(this);
stPacket = new StatePacket(this);
testPacket = new TestPacket(this);
infoPacket = new InfoPacket(this);
on_comboBox_currentIndexChanged(0);
}
MakePacket::~MakePacket()
{
delete ui;
}
/**
*函数名:选择的报文变化回调
*函数参数:NULL
*函数作用:NULL
*函数返回值:NULL
*备注:NULL
*/
void MakePacket::on_comboBox_currentIndexChanged(int index)
{
switch (index)
{
case 0:
{
controlPacket->hide();
stPacket->hide();
testPacket->hide();
infoPacket->hide();
this->setFixedHeight(gatherPacket->size().height()+100);
gatherPacket->move(10,40);
gatherPacket->show();
break;
}
case 1:
{
gatherPacket->hide();
stPacket->hide();
testPacket->hide();
infoPacket->hide();
this->setFixedHeight(controlPacket->size().height()+100);
controlPacket->move(10,40);
controlPacket->show();
break;
}
case 2:
{
gatherPacket->hide();
controlPacket->hide();
stPacket->hide();
testPacket->hide();
this->setFixedHeight(stPacket->size().height()+100);
stPacket->move(10,40);
stPacket->show();
break;
}
case 3:
{
gatherPacket->hide();
controlPacket->hide();
stPacket->hide();
infoPacket->hide();
this->setFixedHeight(testPacket->size().height()+100);
testPacket->move(10,40);
testPacket->show();
break;
}
case 4:
{
gatherPacket->hide();
controlPacket->hide();
stPacket->hide();
testPacket->hide();
this->setFixedHeight(infoPacket->size().height()+100);
infoPacket->move(10,40);
infoPacket->show();
break;
}
default:
break;
}
}
/***********************************************/
// z 函数名称:生成报文
// h 函数作用:NULL
// u 函数参数:NULL
// x 函数返回值:NULL
// y 备注:NULL
/***********************************************/
void MakePacket::on_pushButton_2_clicked()
{
//获取id
DWORD id = 0x00000000;
int packetType = ui->comboBox->currentIndex()+1;
int aimAddr = ui->comboBox_2->currentIndex()+1;
if(aimAddr==6)
{
aimAddr = 31;
}
int sourAddr = ui->comboBox_3->currentIndex()+1;
if(sourAddr==6)
{
sourAddr = 31;
}
id = id | ((packetType<<24)&0x1F000000);
id = id | ((aimAddr<<16)&0x001F0000);
id = id | ((sourAddr<<8)&0x00001F00);
//获取data
switch (ui->comboBox->currentIndex())
{
case 0://采集报文
{
VCI_CAN_OBJ obj = gatherPacket->getObj();
QString idStr = QString("%1").arg(id,8,16,QLatin1Char('0'));
ui->lineEdit->setText(idStr.toUpper());
QByteArray dataBa;dataBa.resize(obj.DataLen);memcpy(dataBa.data(),obj.Data,dataBa.size());
QString dataStr = dataBa.toHex().toUpper();
//qDebug()<<dataStr;
RET_IF_NOT_EAQU(Mymethod::GetInstance()->addSpaceInQString(dataStr),RET_OK);
ui->lineEdit_2->setText(dataStr.toUpper());
break;
}
case 1://控制报文
{
VCI_CAN_OBJ obj = controlPacket->getObj();
QString idStr = QString("%1").arg(id,8,16,QLatin1Char('0'));
ui->lineEdit->setText(idStr.toUpper());
QByteArray dataBa;dataBa.resize(obj.DataLen);memcpy(dataBa.data(),obj.Data,dataBa.size());
QString dataStr = dataBa.toHex().toUpper();
//qDebug()<<dataStr;
RET_IF_NOT_EAQU(Mymethod::GetInstance()->addSpaceInQString(dataStr),RET_OK);
ui->lineEdit_2->setText(dataStr.toUpper());
break;
}
case 2://状态报文
{
VCI_CAN_OBJ obj = stPacket->getObj();
QString idStr = QString("%1").arg(id,8,16,QLatin1Char('0'));
ui->lineEdit->setText(idStr.toUpper());
QByteArray dataBa;dataBa.resize(obj.DataLen);memcpy(dataBa.data(),obj.Data,obj.DataLen);
QString dataStr = dataBa.toHex().toUpper();
//qDebug()<<dataStr;
RET_IF_NOT_EAQU(Mymethod::GetInstance()->addSpaceInQString(dataStr),RET_OK);
ui->lineEdit_2->setText(dataStr.toUpper());
break;
}
case 3://监测报文
{
VCI_CAN_OBJ obj = testPacket->getObj();
QString idStr = QString("%1").arg(id,8,16,QLatin1Char('0'));
ui->lineEdit->setText(idStr.toUpper());
QByteArray dataBa;dataBa.resize(obj.DataLen);memcpy(dataBa.data(),obj.Data,dataBa.size());
QString dataStr = dataBa.toHex().toUpper();
//qDebug()<<dataStr;
RET_IF_NOT_EAQU(Mymethod::GetInstance()->addSpaceInQString(dataStr),RET_OK);
ui->lineEdit_2->setText(dataStr.toUpper());
break;
}
case 4://板卡信息
{
VCI_CAN_OBJ obj = infoPacket->getObj();
QString idStr = QString("%1").arg(id,8,16,QLatin1Char('0'));
ui->lineEdit->setText(idStr.toUpper());
QByteArray dataBa;dataBa.resize(obj.DataLen);memcpy(dataBa.data(),obj.Data,dataBa.size());
QString dataStr = dataBa.toHex().toUpper();
//qDebug()<<dataStr;
RET_IF_NOT_EAQU(Mymethod::GetInstance()->addSpaceInQString(dataStr),RET_OK);
ui->lineEdit_2->setText(dataStr.toUpper());
break;
}
default:
break;
}
}
/***********************************************/
// z 函数名称:添加发送帧
// h 函数作用:NULL
// u 函数参数:NULL
// x 函数返回值:NULL
// y 备注:NULL
/***********************************************/
void MakePacket::on_pushButton_clicked()
{
VCI_CAN_OBJ obj;
memset(&obj,0,sizeof(obj));
//ID
obj.ID = ui->lineEdit->text().toUInt(nullptr,Z_HEX);
//发送类型
if(ui->checkBox->isChecked())
{
obj.SendType = CAN_SEND_SELF;
}
else
{
obj.SendType = CAN_SEND_NORMAL;
}
//数据类型
obj.RemoteFlag = CAN_DATA_INFO;
//是否扩展帧
obj.ExternFlag = CAN_FRAM_EXTERN;
//数据长度
obj.DataLen = ui->lineEdit_2->text().remove(QRegExp("\\s")).size()/2;
//数据
QByteArray ba;
QString tmpStr = ui->lineEdit_2->text();
RET_IF_NOT_EAQU(Mymethod::GetInstance()->getBytesFromQString(tmpStr,ba),RET_OK);
memcpy(obj.Data,ba.data(),obj.DataLen);
//构造发送给主界面显示的结构体
CAN_SEND_FRAME_STRUCT info;
//报文类型
if( ui->comboBox->currentIndex() > (int)packetsName.size())
{
qDebug()<<"err in:"<<__FILE__<<" at:"<<__LINE__;
return;
}
info.packetTyepStr = packetsName[ui->comboBox->currentIndex()];
info.idStr = QString("%1").arg(obj.ID,8,16,QLatin1Char('0'));
QByteArray dataBa;dataBa.resize(obj.DataLen);memcpy(dataBa.data(),obj.Data,obj.DataLen);
info.dataStr = dataBa.toHex().toUpper();
info.sourceStr = QString::number(Mymethod::GetInstance()->getSourceAdres(obj.ID));
info.aimStr = QString::number(Mymethod::GetInstance()->getAimAdres(obj.ID));
info.timeStr = QString::number(ui->lineEdit_3->text().toInt());
if(0==ui->comboBox->currentIndex())
{
PackeManager pm(GATHER_PACKET);
pm.setPacket(obj);
info.meaningStr = pm.getMeaningByType();
}
else if(1==ui->comboBox->currentIndex())
{
PackeManager pm(CONTROL_PACKET);
pm.setPacket(obj);
info.meaningStr = pm.getMeaningByType();
}
else if(2==ui->comboBox->currentIndex())
{
PackeManager pm(STATE_PACKET);
pm.setPacket(obj);
info.meaningStr = pm.getMeaningByType();
}
else if(3==ui->comboBox->currentIndex())
{
PackeManager pm(TESTING_PACKET);
pm.setPacket(obj);
info.meaningStr = pm.getMeaningByType();
}
else if(4==ui->comboBox->currentIndex())
{
PackeManager pm(INFO_PACKET);
pm.setPacket(obj);
info.meaningStr = pm.getMeaningByType();
}
else
{
QMessageBox::warning(this,"错误","错误的报文类型");
}
if(ui->checkBox->isChecked())
{
info.isSendToSelf = true;
}
info.sendCount = (int)ui->lineEdit_4->text().toUInt();//发送次数
emit this->addSendFramSignal(info);
}