70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
|
|
#include "channel_crc.h"
|
||
|
|
#include "ui_channel_crc.h"
|
||
|
|
#include "config_mgr.h"
|
||
|
|
#include "data_config.h"
|
||
|
|
|
||
|
|
ChannelCRC::ChannelCRC(QWidget *parent) :
|
||
|
|
QWidget(parent),
|
||
|
|
ui(new Ui::ChannelCRC)
|
||
|
|
{
|
||
|
|
ui->setupUi(this);
|
||
|
|
|
||
|
|
initable();
|
||
|
|
m_tcpClient = MyTcpClient::instance();
|
||
|
|
connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &)));
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
ChannelCRC::~ChannelCRC()
|
||
|
|
{
|
||
|
|
delete ui;
|
||
|
|
}
|
||
|
|
void ChannelCRC::initable()
|
||
|
|
{
|
||
|
|
headerStr = QObject::tr("板卡,通道1,通道2,通道3,通道4");
|
||
|
|
myHeader = new TableHeaderView(Qt::Horizontal, ui->tableView);
|
||
|
|
model = new QStandardItemModel(ui->tableView);
|
||
|
|
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||
|
|
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||
|
|
QStringList headerList = headerStr.split(",");
|
||
|
|
model->setHorizontalHeaderLabels(headerList);
|
||
|
|
model->setColumnCount(headerList.size());
|
||
|
|
ui->tableView->setModel(model);
|
||
|
|
}
|
||
|
|
|
||
|
|
void ChannelCRC::on_pushButton_get_clicked()
|
||
|
|
{
|
||
|
|
model->removeRows(0, model->rowCount());
|
||
|
|
int rows = 0;
|
||
|
|
for (int slot = 1; slot <= SLOT_NUM; slot ++ ) {
|
||
|
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
|
||
|
|
if(base_ptr == nullptr)
|
||
|
|
continue;
|
||
|
|
if(base_ptr->card_type_ == kCardVibSingle ||
|
||
|
|
base_ptr->card_type_ == kCardSpeedSingle ||
|
||
|
|
base_ptr->card_type_ == kCardKeyphaseSingle){
|
||
|
|
for (int ch = 1 ; ch <= 4 ; ch ++ ) {
|
||
|
|
model->setRowCount(rows + 1);
|
||
|
|
model->setData(model->index(rows,0,QModelIndex()),slot);
|
||
|
|
rows_slot[slot] = rows;
|
||
|
|
|
||
|
|
GetChannelCRCCountReq get_ch_crc_req = { {0xAA, 0x55, 0xAA}, kGetChannelCRCValue, 1,(uint8_t)slot,(uint8_t)ch };
|
||
|
|
int length = sizeof(GetChannelCRCCountReq);
|
||
|
|
qint64 bytesWritten = m_tcpClient->sendData((char*)&get_ch_crc_req, length);
|
||
|
|
m_tcpClient->waitForRead();
|
||
|
|
qDebug() << "bytesWritten: " << bytesWritten;
|
||
|
|
}
|
||
|
|
rows ++ ;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
void ChannelCRC::readData(const QByteArray &data) {
|
||
|
|
uint8_t cmd = data[3];
|
||
|
|
if (cmd == kGetChannelCRCValue) {
|
||
|
|
GetChannelCRCCountRsp get_ch_crc_rsp;
|
||
|
|
memcpy(&get_ch_crc_rsp, data.data(), sizeof(GetChannelCRCCountRsp));
|
||
|
|
qDebug() << "get_ch_crc_rsp code" << get_ch_crc_rsp.code << get_ch_crc_rsp.card_id << get_ch_crc_rsp.channel_id << get_ch_crc_rsp.count << rows_slot[(int)get_ch_crc_rsp.card_id] ;
|
||
|
|
model->setData(model->index(rows_slot[(int)get_ch_crc_rsp.card_id],((int)get_ch_crc_rsp.channel_id),QModelIndex()),get_ch_crc_rsp.count);
|
||
|
|
}
|
||
|
|
}
|