2,新增“Apps”; 3,新增“Common”; 4,新增“FileList”; 5,新增“MediaX”; 6,新增“OpenSource”; 7,新增“Samples”; 8,新增“SoftwareBusinessLines”.
1460 lines
38 KiB
C++
1460 lines
38 KiB
C++
#include "mainwindow.h"
|
||
#include "ui_mainwindow.h"
|
||
|
||
#include <QFile>
|
||
#include <QMessageBox>
|
||
#include <QFileDialog>
|
||
#include <QString>
|
||
#include <QDebug>
|
||
|
||
#include "commonhelper.h"
|
||
#include "frameless_helper.h"
|
||
|
||
#include <mmsystem.h>
|
||
#pragma comment(lib, "winmm")
|
||
|
||
#include "CAN/ECanVci.h"
|
||
|
||
unsigned short CRC_Verify(unsigned char* cBuffer, unsigned int iStartLen, unsigned int iEndLen)
|
||
{
|
||
unsigned int i = 0, j = 0;
|
||
unsigned short wCrc = 0x0000;
|
||
unsigned short wCrc_Cs = 0x0000;
|
||
unsigned short wPolynom = 0x8005;
|
||
|
||
for (i = iStartLen; i < iEndLen + 1; i++)
|
||
{
|
||
wCrc_Cs = cBuffer[i] << 8;
|
||
wCrc ^= (wCrc_Cs & 0xff00);
|
||
|
||
for (j = 0; j < 8; j++)
|
||
{
|
||
if (wCrc & 0x8000)
|
||
{
|
||
wCrc = (wCrc << 1)^wPolynom;
|
||
}
|
||
else
|
||
{
|
||
wCrc = wCrc << 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
return wCrc;
|
||
}
|
||
|
||
MainWindow::MainWindow(QWidget* parent) :
|
||
QMainWindow(parent),
|
||
ui(new Ui::MainWindow)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
this->setWindowTitle(tr(" "));
|
||
|
||
void* p = nullptr;
|
||
|
||
// OpenGLView
|
||
//this->setAttribute(Qt::WA_Mapped);
|
||
|
||
// byte szCrcTest[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||
// int nCrc = CRC_Verify(szCrcTest, 0, 7);
|
||
// int jj = 0;
|
||
|
||
//
|
||
m_bMousePressed = false;
|
||
|
||
//
|
||
m_bThreadRunning_ReceiveData_CAN = false;
|
||
m_ptrThread_ReceiveData_CAN = nullptr;
|
||
|
||
//
|
||
m_bConnectCAN = false;
|
||
|
||
// 初始化界面
|
||
InitStyle();
|
||
|
||
//
|
||
//this->setFixedWidth(660);
|
||
//ui->wgtTitleBar->setFixedWidth(650);
|
||
|
||
m_ptrDataModel_Msg = std::shared_ptr<QStandardItemModel>(new QStandardItemModel(0, 1, ui->m_listView_Msg));
|
||
ui->m_listView_Msg->setModel(m_ptrDataModel_Msg.get());
|
||
|
||
//
|
||
m_varCaptureData.InitQueue(1920 * 1080 * 4, 6);
|
||
|
||
// 加载信号槽函数连接
|
||
Connect();
|
||
|
||
m_nCAN_DevType = USBCAN1;
|
||
m_nCAN_DeviceIndex = 0;
|
||
|
||
m_eDeviceType = eDeviceType_NULL;
|
||
|
||
//
|
||
m_ptrCanUpgrade_CM1K10A = std::shared_ptr<CanUpgrade_CM1K10A>(new CanUpgrade_CM1K10A(this));
|
||
m_ptrCanUpgrade_CM1K12G = std::shared_ptr<CanUpgrade_CM1K12G>(new CanUpgrade_CM1K12G(this));
|
||
m_ptrCanUpgrade_CM1K12G_Private = std::shared_ptr<CanUpgrade_CM1K12G_Private>(new CanUpgrade_CM1K12G_Private(this));
|
||
|
||
//
|
||
m_ptrUpgradeData = nullptr;
|
||
m_nUpgradeDataSize = 0;
|
||
m_bReady_Upgrade = false;
|
||
|
||
m_bUploading = false;
|
||
m_bWritingIn = false;
|
||
m_bUpgradeProgress = false;
|
||
m_dUpgradeProgress = 0;
|
||
|
||
m_bRefreshUpgradeStatus = false;
|
||
m_eUpgradeStatus = eUpgradeStatus_Ready;
|
||
m_nUpgradeStatus_Counter = 0;
|
||
|
||
m_bUploadFinished = false;
|
||
|
||
//
|
||
m_bRecord = false;
|
||
m_nLastRecvTimeStamp = 0;
|
||
m_nRecordCount = 0;
|
||
}
|
||
|
||
MainWindow::~MainWindow()
|
||
{
|
||
//
|
||
StopThread_ReceiveData_CAN();
|
||
|
||
Disconnect();
|
||
|
||
if (m_varFileRecorder.isOpen())
|
||
{
|
||
m_varFileRecorder.close();
|
||
}
|
||
|
||
delete ui;
|
||
}
|
||
|
||
void MainWindow::Connect()
|
||
{
|
||
// 通用
|
||
connect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
connect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
connect(ui->m_pushButton_ConnectCAN, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
connect(ui->m_pushButton_ResetCAN, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
connect(ui->m_pushButton_SendData, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
connect(ui->m_pushButton_ClearMsg, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
connect(ui->m_pushButton_BrowseFile, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
connect(ui->m_pushButton_Upload, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
connect(ui->m_pushButton_WriteIn, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
connect(ui->m_checkBox_Record, &QCheckBox::clicked, this, &MainWindow::OnChecked);
|
||
|
||
//
|
||
connect(ui->m_comboBox_DeviceType, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||
this, &MainWindow::OnComboxIndexChanged);
|
||
|
||
|
||
//
|
||
connect(&m_varTimer_RefreshUI, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
m_varTimer_RefreshUI.setTimerType(Qt::PreciseTimer);
|
||
m_varTimer_RefreshUI.start(40);
|
||
|
||
connect(&m_varTimer_RefreshMsgList, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
m_varTimer_RefreshMsgList.setTimerType(Qt::PreciseTimer);
|
||
m_varTimer_RefreshMsgList.start(1);
|
||
|
||
connect(&m_varTimer_RefreshUpgradeStatus, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
m_varTimer_RefreshUpgradeStatus.setTimerType(Qt::PreciseTimer);
|
||
m_varTimer_RefreshUpgradeStatus.start(20);
|
||
}
|
||
|
||
void MainWindow::Disconnect()
|
||
{
|
||
// 通用
|
||
disconnect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
disconnect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
disconnect(ui->m_pushButton_ConnectCAN, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
disconnect(ui->m_pushButton_ResetCAN, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
disconnect(ui->m_pushButton_SendData, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
disconnect(ui->m_pushButton_ClearMsg, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
disconnect(ui->m_pushButton_BrowseFile, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
disconnect(ui->m_pushButton_Upload, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
disconnect(ui->m_pushButton_WriteIn, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
//
|
||
disconnect(ui->m_checkBox_Record, &QCheckBox::clicked, this, &MainWindow::OnChecked);
|
||
|
||
//
|
||
disconnect(ui->m_comboBox_DeviceType, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||
this, &MainWindow::OnComboxIndexChanged);
|
||
|
||
//
|
||
m_varTimer_RefreshUI.stop();
|
||
disconnect(&m_varTimer_RefreshUI, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
|
||
m_varTimer_RefreshMsgList.stop();
|
||
disconnect(&m_varTimer_RefreshMsgList, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
|
||
m_varTimer_RefreshUpgradeStatus.stop();
|
||
disconnect(&m_varTimer_RefreshUpgradeStatus, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
}
|
||
|
||
void MainWindow::OnButtonClicked()
|
||
{
|
||
// 最小化
|
||
if (sender() == ui->m_pushButton_MinMenu)
|
||
{
|
||
this->showMinimized();
|
||
}
|
||
|
||
// 退出程序
|
||
if (sender() == ui->m_pushButton_CloseMenu)
|
||
{
|
||
qApp->exit();
|
||
}
|
||
|
||
// 连接CAN设备
|
||
if (sender() == ui->m_pushButton_ConnectCAN)
|
||
{
|
||
int nDeviceIndex = ui->m_comboBox_DeviceIndex->currentIndex();
|
||
|
||
ConnectCAN(nDeviceIndex);
|
||
}
|
||
|
||
// 重置CAN设备
|
||
if (sender() == ui->m_pushButton_ResetCAN)
|
||
{}
|
||
|
||
// 发送数据
|
||
if (sender() == ui->m_pushButton_SendData)
|
||
{
|
||
SendData_CAN();
|
||
//SendData_CAN("711", "00 00 00 00 00 00 00 AA");
|
||
//byte szData[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA};
|
||
//SendData_CAN(0x711, szData, 8);
|
||
}
|
||
|
||
// 清空消息
|
||
if (sender() == ui->m_pushButton_ClearMsg)
|
||
{
|
||
m_ptrDataModel_Msg->removeRows(0, m_ptrDataModel_Msg->rowCount());
|
||
}
|
||
|
||
// 浏览文件
|
||
if (sender() == ui->m_pushButton_BrowseFile)
|
||
{
|
||
BrowseFile();
|
||
}
|
||
|
||
// 升级
|
||
if (sender() == ui->m_pushButton_Upload)
|
||
{
|
||
UpgradeFile();
|
||
}
|
||
|
||
// 写入
|
||
if (sender() == ui->m_pushButton_WriteIn)
|
||
{
|
||
WriteIn();
|
||
}
|
||
}
|
||
|
||
void MainWindow::OnChecked(bool bChecked)
|
||
{
|
||
int jj = 0;
|
||
|
||
if (bChecked)
|
||
{
|
||
if (m_varFileRecorder.isOpen())
|
||
{
|
||
m_varFileRecorder.close();
|
||
}
|
||
|
||
QString strFilePath = "./CanData_Recv_";
|
||
QString strTm = QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz");
|
||
strFilePath += strTm;
|
||
strFilePath += ".csv";
|
||
|
||
m_varFileRecorder.setFileName(strFilePath);
|
||
m_varFileRecorder.open(QIODevice::ReadWrite | QIODevice::Text);
|
||
|
||
QString str = "time,timespan,frame_id,data0,data1,data2,data3,data4,data5,data6,data7\n";
|
||
m_varFileRecorder.write(str.toStdString().c_str());
|
||
|
||
m_bRecord = true;
|
||
}
|
||
else
|
||
{
|
||
if (m_varFileRecorder.isOpen())
|
||
{
|
||
m_varFileRecorder.close();
|
||
}
|
||
|
||
m_bRecord = false;
|
||
}
|
||
|
||
|
||
return;
|
||
}
|
||
|
||
void MainWindow::OnComboxIndexChanged(int nIndex)
|
||
{
|
||
if (sender() == ui->m_comboBox_DeviceType)
|
||
{
|
||
if (eDeviceType_CM1K10A == (eDeviceType)(ui->m_comboBox_DeviceType->currentIndex() + 1))
|
||
{
|
||
ui->m_comboBox_Baud->setCurrentIndex(3); // 500Kbps
|
||
}
|
||
else //if (eDeviceType_CM1K12G == (eDeviceType)(ui->m_comboBox_DeviceType->currentIndex() + 1) )
|
||
{
|
||
ui->m_comboBox_Baud->setCurrentIndex(0); // 1000Kbps
|
||
}
|
||
}
|
||
}
|
||
|
||
void MainWindow::InitStyle()
|
||
{
|
||
m_bMousePressed = false;
|
||
|
||
//安装事件监听器,让标题栏识别鼠标双击
|
||
ui->lblTitle->installEventFilter(this);
|
||
/*
|
||
this->setWindowFlags(/*Qt::FramelessWindowHint |*
|
||
Qt::WindowTitleHint |
|
||
Qt::WindowSystemMenuHint);
|
||
*/
|
||
FramelessHelper* pHelper = new FramelessHelper(this);
|
||
pHelper->activateOn(this); //激活当前窗体
|
||
pHelper->setTitleHeight(ui->wgtTitleBar->height()); //设置窗体的标题栏高度
|
||
|
||
CommonHelper::SetStyle("blue");//"blue"//"dark"
|
||
}
|
||
|
||
bool MainWindow::eventFilter(QObject* obj, QEvent* event)
|
||
{
|
||
//if (ui->lblTitle == obj)
|
||
{
|
||
if (event->type() == QEvent::MouseButtonPress)
|
||
{
|
||
|
||
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||
|
||
if (mouseEvent->button() == Qt::LeftButton)
|
||
{
|
||
m_bMousePressed = true;
|
||
m_ptMouse = mouseEvent->globalPos() - pos();
|
||
mouseEvent->accept();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
else if (event->type() == QEvent::MouseMove)
|
||
{
|
||
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||
|
||
if (m_bMousePressed && this->windowState() != Qt::WindowMaximized)
|
||
{
|
||
if (mouseEvent->globalY() <= qApp->desktop()->availableGeometry().bottom())
|
||
{
|
||
move(mouseEvent->globalPos() - m_ptMouse);
|
||
mouseEvent->accept();
|
||
}
|
||
else
|
||
{
|
||
qApp->desktop()->cursor().setPos(
|
||
qApp->desktop()->cursor().pos().x(),
|
||
qApp->desktop()->availableGeometry().bottom()
|
||
);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
else if (event->type() == QEvent::MouseButtonRelease)
|
||
{
|
||
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||
|
||
if (mouseEvent->button() == Qt::LeftButton)
|
||
{
|
||
m_bMousePressed = false;
|
||
mouseEvent->accept();
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return QMainWindow::eventFilter(obj, event);
|
||
}
|
||
|
||
bool MainWindow::ConnectCAN(int nDeviceIndex)
|
||
{
|
||
bool bConnectCAN = !m_bConnectCAN;
|
||
m_nCAN_DeviceIndex = nDeviceIndex;
|
||
|
||
if (bConnectCAN)
|
||
{
|
||
INIT_CONFIG init_config;
|
||
int baud = ui->m_comboBox_Baud->currentIndex();
|
||
|
||
init_config.AccCode = 0;
|
||
init_config.AccMask = 0xffffff;
|
||
init_config.Filter = 0;
|
||
|
||
switch (baud)
|
||
{
|
||
case 0: //1000
|
||
init_config.Timing0 = 0;
|
||
init_config.Timing1 = 0x14;
|
||
break;
|
||
case 1: //800
|
||
init_config.Timing0 = 0;
|
||
init_config.Timing1 = 0x16;
|
||
break;
|
||
case 2: //666
|
||
init_config.Timing0 = 0x80;
|
||
init_config.Timing1 = 0xb6;
|
||
break;
|
||
case 3: //500
|
||
init_config.Timing0 = 0;
|
||
init_config.Timing1 = 0x1c;
|
||
break;
|
||
case 4://400
|
||
init_config.Timing0 = 0x80;
|
||
init_config.Timing1 = 0xfa;
|
||
break;
|
||
case 5://250
|
||
init_config.Timing0 = 0x01;
|
||
init_config.Timing1 = 0x1c;
|
||
break;
|
||
case 6://200
|
||
init_config.Timing0 = 0x81;
|
||
init_config.Timing1 = 0xfa;
|
||
break;
|
||
case 7://125
|
||
init_config.Timing0 = 0x03;
|
||
init_config.Timing1 = 0x1c;
|
||
break;
|
||
case 8://100
|
||
init_config.Timing0 = 0x04;
|
||
init_config.Timing1 = 0x1c;
|
||
break;
|
||
case 9://80
|
||
init_config.Timing0 = 0x83;
|
||
init_config.Timing1 = 0xff;
|
||
break;
|
||
case 10://50
|
||
init_config.Timing0 = 0x09;
|
||
init_config.Timing1 = 0x1c;
|
||
break;
|
||
}
|
||
|
||
init_config.Mode = 0;
|
||
|
||
if (STATUS_OK != OpenDevice(m_nCAN_DevType, m_nCAN_DeviceIndex, 0))
|
||
{
|
||
AddMsg("Open device fault!", true);
|
||
|
||
return false;
|
||
}
|
||
|
||
AddMsg("Open device Success", true);
|
||
|
||
|
||
if (STATUS_OK != InitCAN(m_nCAN_DevType, m_nCAN_DeviceIndex, 0, &init_config))
|
||
{
|
||
AddMsg("Init CAN fault!", true);
|
||
|
||
CloseDevice(m_nCAN_DevType, m_nCAN_DeviceIndex);
|
||
|
||
return false;
|
||
}
|
||
|
||
AddMsg("Init Success", true);
|
||
|
||
//m_connect=1;
|
||
//AfxBeginThread(ReceiveThread,this);
|
||
StartThread_ReceiveData_CAN();
|
||
|
||
//start
|
||
if (1 == StartCAN(m_nCAN_DevType, m_nCAN_DeviceIndex, 0))
|
||
{
|
||
AddMsg("Start Success", true);
|
||
}
|
||
else
|
||
{
|
||
AddMsg("Start Fault", true);
|
||
}
|
||
|
||
//
|
||
m_eDeviceType = (eDeviceType)(ui->m_comboBox_DeviceType->currentIndex() + 1);
|
||
|
||
//
|
||
ui->m_comboBox_Baud->setEnabled(false);
|
||
ui->m_pushButton_ConnectCAN->setText("Disconnect");
|
||
|
||
ui->m_comboBox_DeviceType->setEnabled(false);
|
||
ui->m_comboBox_DeviceIndex->setEnabled(false);
|
||
|
||
ui->m_comboBox_FrameType->setEnabled(true);
|
||
ui->m_comboBox_FrameFormat->setEnabled(true);
|
||
ui->m_lineEdit_FrameID->setEnabled(true);
|
||
ui->m_lineEdit_FrameData->setEnabled(true);
|
||
ui->m_pushButton_SendData->setEnabled(true);
|
||
|
||
ui->m_pushButton_BrowseFile->setEnabled(true);
|
||
ui->m_pushButton_Upload->setEnabled(true);
|
||
|
||
ui->m_checkBox_Record->setEnabled(true);
|
||
}
|
||
else
|
||
{
|
||
StopThread_ReceiveData_CAN();
|
||
|
||
CloseDevice(m_nCAN_DevType, m_nCAN_DeviceIndex);
|
||
|
||
AddMsg("Close Device", true);
|
||
|
||
ui->m_comboBox_Baud->setEnabled(true);
|
||
ui->m_pushButton_ConnectCAN->setText("Connect");
|
||
|
||
ui->m_comboBox_DeviceType->setEnabled(true);
|
||
ui->m_comboBox_DeviceIndex->setEnabled(true);
|
||
|
||
ui->m_comboBox_FrameType->setEnabled(false);
|
||
ui->m_comboBox_FrameFormat->setEnabled(false);
|
||
ui->m_lineEdit_FrameID->setEnabled(false);
|
||
ui->m_lineEdit_FrameData->setEnabled(false);
|
||
ui->m_pushButton_SendData->setEnabled(false);
|
||
|
||
ui->m_pushButton_BrowseFile->setEnabled(false);
|
||
ui->m_pushButton_Upload->setEnabled(false);
|
||
ui->m_pushButton_WriteIn->setEnabled(false);
|
||
|
||
ui->m_checkBox_Record->setEnabled(false);
|
||
}
|
||
|
||
m_bConnectCAN = bConnectCAN;
|
||
|
||
return true;
|
||
}
|
||
|
||
bool MainWindow::SendData_CAN()
|
||
{
|
||
if (!m_bConnectCAN)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
CAN_OBJ frameinfo;
|
||
char szFrameID[9];
|
||
unsigned char FrameID[4] = {0, 0, 0, 0};
|
||
memset(szFrameID, '0', 9);
|
||
unsigned char Data[8];
|
||
char szData[25];
|
||
BYTE datalen = 0;
|
||
|
||
if (ui->m_lineEdit_FrameID->text().isEmpty() ||
|
||
(ui->m_lineEdit_FrameData->text().isEmpty() && ui->m_comboBox_FrameType->currentIndex() == 0))
|
||
{
|
||
AddMsg("请输入数据", true);
|
||
|
||
return false;
|
||
}
|
||
|
||
if (ui->m_lineEdit_FrameID->text().length() > 8)
|
||
{
|
||
AddMsg("ID值超过范围", true);
|
||
|
||
return false;
|
||
}
|
||
|
||
if (ui->m_lineEdit_FrameData->text().length() > 24)
|
||
{
|
||
AddMsg("数据长度超过范围,最大为8个字节", true);
|
||
|
||
return false;
|
||
}
|
||
|
||
if (ui->m_comboBox_FrameType->currentIndex() == 0)
|
||
{
|
||
if (ui->m_lineEdit_FrameData->text().length() % 3 == 1)
|
||
{
|
||
AddMsg("数据格式不对,请重新输入", true);
|
||
|
||
return false;
|
||
}
|
||
}
|
||
|
||
const int c_nLength_FrameID = ui->m_lineEdit_FrameID->text().length();
|
||
memcpy(&szFrameID[8 - c_nLength_FrameID], ui->m_lineEdit_FrameID->text().toLatin1().data(), c_nLength_FrameID);
|
||
strtodata((unsigned char*)szFrameID, FrameID, 4, 0);
|
||
|
||
datalen = (ui->m_lineEdit_FrameData->text().length() + 1) / 3;
|
||
strcpy(szData, /*(LPCTSTR)*/ui->m_lineEdit_FrameData->text().toStdString().c_str());
|
||
strtodata((unsigned char*)szData, Data, datalen, 1);
|
||
|
||
frameinfo.SendType = 0;
|
||
frameinfo.DataLen = datalen;
|
||
memcpy(&frameinfo.Data, Data, datalen);
|
||
|
||
frameinfo.RemoteFlag = ui->m_comboBox_FrameFormat->currentIndex();//m_ComboSendFrmFmt.GetCurSel();
|
||
frameinfo.ExternFlag = ui->m_comboBox_FrameType->currentIndex();//m_ComboSendFrmType.GetCurSel();
|
||
|
||
if (frameinfo.ExternFlag == 1)
|
||
{
|
||
frameinfo.ID = ((DWORD)FrameID[0] << 24) + ((DWORD)FrameID[1] << 16) + ((DWORD)FrameID[2] << 8) +
|
||
((DWORD)FrameID[3]);
|
||
}
|
||
else
|
||
{
|
||
frameinfo.ID = ((DWORD)FrameID[2] << 8) + ((DWORD)FrameID[3]);
|
||
}
|
||
|
||
QString strSendMsg = "Send: ID:0x";
|
||
strSendMsg += ui->m_lineEdit_FrameID->text();
|
||
strSendMsg += " Data:";
|
||
strSendMsg += ui->m_lineEdit_FrameData->text();
|
||
|
||
AddMsg(strSendMsg, true);
|
||
|
||
if (Transmit(m_nCAN_DevType, m_nCAN_DeviceIndex, 0, &frameinfo, 1) == 1)
|
||
{
|
||
//AddMsg("写入成功", true);
|
||
}
|
||
else
|
||
{
|
||
AddMsg("写入失败", true);
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool MainWindow::SendData_CAN(const QString& strFrameID_HexStr, const QString& strFrameData_HexStr, bool bAddMsg)
|
||
{
|
||
if (!m_bConnectCAN)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
CAN_OBJ frameinfo;
|
||
char szFrameID[9];
|
||
unsigned char FrameID[4] = {0, 0, 0, 0};
|
||
memset(szFrameID, '0', 9);
|
||
unsigned char Data[8];
|
||
char szData[25];
|
||
BYTE datalen = 0;
|
||
|
||
const int c_nLength_FrameID = strFrameID_HexStr.length();
|
||
memcpy(&szFrameID[8 - c_nLength_FrameID], strFrameID_HexStr.toLatin1().data(), c_nLength_FrameID);
|
||
strtodata((unsigned char*)szFrameID, FrameID, 4, 0);
|
||
|
||
datalen = (strFrameData_HexStr.length() + 1) / 3;
|
||
strcpy(szData, /*(LPCTSTR)*/strFrameData_HexStr.toStdString().c_str());
|
||
strtodata((unsigned char*)szData, Data, datalen, 1);
|
||
|
||
frameinfo.SendType = 0;
|
||
frameinfo.DataLen = datalen;
|
||
memcpy(&frameinfo.Data, Data, datalen);
|
||
|
||
frameinfo.RemoteFlag = 0;//ui->m_comboBox_FrameFormat->currentIndex();//m_ComboSendFrmFmt.GetCurSel();
|
||
frameinfo.ExternFlag = 0;//ui->m_comboBox_FrameType->currentIndex();//m_ComboSendFrmType.GetCurSel();
|
||
|
||
if (frameinfo.ExternFlag == 1)
|
||
{
|
||
frameinfo.ID = ((DWORD)FrameID[0] << 24) + ((DWORD)FrameID[1] << 16) + ((DWORD)FrameID[2] << 8) +
|
||
((DWORD)FrameID[3]);
|
||
}
|
||
else
|
||
{
|
||
frameinfo.ID = ((DWORD)FrameID[2] << 8) + ((DWORD)FrameID[3]);
|
||
}
|
||
|
||
QString strSendMsg = "Send: ID:0x";
|
||
strSendMsg += strFrameID_HexStr;
|
||
strSendMsg += " Data:";
|
||
strSendMsg += strFrameData_HexStr;
|
||
|
||
if (bAddMsg)
|
||
{
|
||
AddMsg(strSendMsg, bAddMsg);
|
||
}
|
||
|
||
if (Transmit(m_nCAN_DevType, m_nCAN_DeviceIndex, 0, &frameinfo, 1) == 1)
|
||
{
|
||
if (bAddMsg)
|
||
{
|
||
//AddMsg("写入成功", bAddMsg);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (bAddMsg)
|
||
{
|
||
AddMsg("写入失败", bAddMsg);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool MainWindow::SendData_CAN(int nFrameID_Hex, const byte* pFrameData, int nFrameDataLen, bool bAddMsg)
|
||
{
|
||
QString strFrameID_HexStr = QString("%1").arg(nFrameID_Hex, 0, 0x10);
|
||
QString strFrameData_HexStr = "";
|
||
|
||
for (int i = 0; i < nFrameDataLen; i++)
|
||
{
|
||
strFrameData_HexStr += QString("%1 ").arg(pFrameData[i], 2, 0x10, QChar('0'));
|
||
}
|
||
|
||
strFrameData_HexStr = strFrameData_HexStr.trimmed();
|
||
|
||
return SendData_CAN(strFrameID_HexStr, strFrameData_HexStr, bAddMsg);
|
||
}
|
||
|
||
void MainWindow::AddMsg(const QString& strMsg, bool bAddMsg)
|
||
{
|
||
if (!bAddMsg)
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_mutexMsgList.lock();
|
||
m_strMsgList.push_back(strMsg);
|
||
m_mutexMsgList.unlock();
|
||
}
|
||
|
||
bool MainWindow::BrowseFile()
|
||
{
|
||
QFileDialog varFileDialog(this);
|
||
|
||
//文件窗体头部数据设置
|
||
varFileDialog.setWindowTitle(tr("读取视频文件"));
|
||
// varFileDialog.setWindowTitle(tr("读取raw文件"));
|
||
varFileDialog.setDirectory(tr(""));
|
||
|
||
QString strExt = tr("Bit Files (*.bit);;"
|
||
"All Files (*.*) )");
|
||
varFileDialog.setNameFilter(strExt); //限定文件打开格式
|
||
|
||
//varFileDialog.exec() 表示打开的窗口如果不关闭,那么就不能操作除这个窗口外的其他窗口
|
||
if (QFileDialog::Accepted != varFileDialog.exec())
|
||
{
|
||
return false;
|
||
}
|
||
|
||
//
|
||
QString strFilePath = varFileDialog.selectedFiles()[0]; //将选中的文件名存储到strDir中
|
||
|
||
ui->m_lineEdit_UpgradeFile->setText(strFilePath);
|
||
|
||
QFile varFile(strFilePath);
|
||
|
||
varFile.open(QIODevice::ReadOnly);
|
||
|
||
m_nUpgradeDataSize = varFile.size();
|
||
m_ptrUpgradeData.reset();
|
||
m_ptrUpgradeData = std::shared_ptr<byte>(new byte[m_nUpgradeDataSize + 1]);
|
||
|
||
varFile.read((char*)m_ptrUpgradeData.get(), m_nUpgradeDataSize);
|
||
|
||
varFile.close();
|
||
|
||
QString strFileInfo = QString("FileSize: %1 B PacketSize: 2048 B PacketCount: %2")
|
||
.arg(m_nUpgradeDataSize)
|
||
.arg((m_nUpgradeDataSize + 2047) / 2048);
|
||
|
||
ui->m_label_FileInfo->setText(strFileInfo);
|
||
|
||
m_bReady_Upgrade = true;
|
||
|
||
//
|
||
ui->m_progressBar_Upgrade->setValue(0);
|
||
|
||
return true;
|
||
}
|
||
|
||
bool MainWindow::UpgradeFile()
|
||
{
|
||
if (!m_bReady_Upgrade)
|
||
{
|
||
CommonHelper::ShowMessageBoxInfo("请提前读取升级文件!", this);
|
||
|
||
return false;
|
||
}
|
||
|
||
m_bUploading = !m_bUploading;
|
||
|
||
if (m_bUploading)
|
||
{
|
||
m_eUpgradeStatus = eUpgradeStatus_Uploading;
|
||
|
||
if (eDeviceType_CM1K10A == m_eDeviceType) // CM1K10A
|
||
{
|
||
/*
|
||
* 发送升级指令帧
|
||
*/
|
||
SendData_CAN("711", "AA 00 00 00 00 00 00 00", true);
|
||
}
|
||
else if (eDeviceType_CM1K12G == m_eDeviceType) // CM1K12G
|
||
{
|
||
/*
|
||
* 发送升级指令帧
|
||
*/
|
||
SendData_CAN("711", "AA 04 00 00 00 00 00 00", true);
|
||
}
|
||
else //if (eDeviceType_CM1K12G_Private == m_eDeviceType) // CM1K12G_Private
|
||
{
|
||
/*
|
||
* 发送升级指令帧
|
||
*/
|
||
SendData_CAN("711", "AA 04 00 00 00 00 00 00", true);
|
||
}
|
||
|
||
ui->m_pushButton_Upload->setText("Stop Upload");
|
||
}
|
||
else
|
||
{
|
||
m_eUpgradeStatus = eUpgradeStatus_Ready;
|
||
|
||
if (eDeviceType_CM1K10A == m_eDeviceType) // CM1K10A
|
||
{
|
||
}
|
||
else if (eDeviceType_CM1K12G == m_eDeviceType) // CM1K12G
|
||
{
|
||
m_ptrCanUpgrade_CM1K12G->StopUpload();
|
||
}
|
||
else //if (eDeviceType_CM1K12G_Private == m_eDeviceType) // CM1K12G_Private
|
||
{
|
||
m_ptrCanUpgrade_CM1K12G_Private->StopUpload();
|
||
}
|
||
|
||
ui->m_pushButton_Upload->setText("Upload");
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
void MainWindow::WriteIn()
|
||
{
|
||
m_bWritingIn = !m_bWritingIn;
|
||
|
||
if (m_bWritingIn)
|
||
{
|
||
m_eUpgradeStatus = eUpgradeStatus_Preparing;
|
||
|
||
if (eDeviceType_CM1K10A == m_eDeviceType) // CM1K10A
|
||
{
|
||
/*
|
||
* 发送烧写指令帧
|
||
*/
|
||
SendData_CAN("716", "AA 00 00 00 00 00 00 00", true);
|
||
}
|
||
else if (eDeviceType_CM1K12G == m_eDeviceType) // CM1K12G
|
||
{
|
||
/*
|
||
* 发送烧写指令帧
|
||
*/
|
||
SendData_CAN("716", "AA 04 00 00 00 00 00 00", true);
|
||
}
|
||
else //if (eDeviceType_CM1K12G_Private == m_eDeviceType) // CM1K12G_Private
|
||
{
|
||
/*
|
||
* 发送烧写指令帧
|
||
*/
|
||
SendData_CAN("716", "AA 04 00 00 00 00 00 00", true);
|
||
}
|
||
|
||
ui->m_pushButton_WriteIn->setText("Writing");
|
||
}
|
||
else
|
||
{
|
||
ui->m_pushButton_WriteIn->setText("WriteIn");
|
||
}
|
||
}
|
||
|
||
bool MainWindow::GetUpgradeData(byte** pUpgradeData, int& nUpgradeDataSize)
|
||
{
|
||
if (!m_bReady_Upgrade)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
*pUpgradeData = m_ptrUpgradeData.get();
|
||
nUpgradeDataSize = m_nUpgradeDataSize;
|
||
|
||
return true;
|
||
}
|
||
|
||
void MainWindow::OnCallBack_DispatchMsg(eMainWindow_DispatchMsg eDispatchMsg, void* pParams, void* pOwner)
|
||
{
|
||
MainWindow* pMainWindow = reinterpret_cast<MainWindow*>(pOwner);
|
||
|
||
if (nullptr == pMainWindow)
|
||
{
|
||
return;
|
||
}
|
||
|
||
pMainWindow->DispatchMsg(eDispatchMsg, pParams);
|
||
}
|
||
|
||
void MainWindow::DispatchMsg(eMainWindow_DispatchMsg eDispatchMsg, void* pParams)
|
||
{
|
||
switch (eDispatchMsg)
|
||
{
|
||
case eMainWindow_DispatchMsg_RefreshUpgradeProgress:
|
||
{
|
||
m_bUpgradeProgress = true;
|
||
m_dUpgradeProgress = *((double*)pParams);
|
||
|
||
break;
|
||
}
|
||
case eMainWindow_DispatchMsg_UploadFinished:
|
||
{
|
||
m_bUploadFinished = true;
|
||
m_eUpgradeStatus = eUpgradeStatus_UploadFinished;
|
||
|
||
break;
|
||
}
|
||
default:
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//-----------------------------------------------------
|
||
//参数:
|
||
//str:要转换的字符串
|
||
//data:储存转换过来的数据串
|
||
//len:数据长度
|
||
//函数功能:字符串转换为数据串
|
||
//-----------------------------------------------------
|
||
int MainWindow::strtodata(unsigned char* str, unsigned char* data, int len, int flag)
|
||
{
|
||
unsigned char cTmp = 0;
|
||
int i = 0;
|
||
|
||
for (int j = 0; j < len; j++)
|
||
{
|
||
if (chartoint(str[i++], &cTmp))
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
data[j] = cTmp;
|
||
|
||
if (chartoint(str[i++], &cTmp))
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
data[j] = (data[j] << 4) + cTmp;
|
||
|
||
if (flag == 1)
|
||
{
|
||
i++;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
//-----------------------------------------------------
|
||
//参数:
|
||
//chr:要转换的字符
|
||
//cint:储存转换过来的数据
|
||
//函数功能:字符转换为数据
|
||
//-----------------------------------------------------
|
||
int MainWindow::chartoint(unsigned char chr, unsigned char* cint)
|
||
{
|
||
unsigned char cTmp;
|
||
cTmp = chr - 48;
|
||
|
||
if (cTmp >= 0 && cTmp <= 9)
|
||
{
|
||
*cint = cTmp;
|
||
|
||
return 0;
|
||
}
|
||
|
||
cTmp = chr - 65;
|
||
|
||
if (cTmp >= 0 && cTmp <= 5)
|
||
{
|
||
*cint = (cTmp + 10);
|
||
|
||
return 0;
|
||
}
|
||
|
||
cTmp = chr - 97;
|
||
|
||
if (cTmp >= 0 && cTmp <= 5)
|
||
{
|
||
*cint = (cTmp + 10);
|
||
|
||
return 0;
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
void MainWindow::OnTimer()
|
||
{
|
||
if (sender() == &m_varTimer_RefreshUI)
|
||
{
|
||
if (m_bUploadFinished)
|
||
{
|
||
m_bUploadFinished = false;
|
||
|
||
ui->m_pushButton_Upload->setText("Upload");
|
||
ui->m_pushButton_Upload->setEnabled(false);
|
||
|
||
ui->m_pushButton_WriteIn->setEnabled(true);
|
||
|
||
//
|
||
ui->m_progressBar_Upgrade->setValue(100);
|
||
ui->m_label_UpgradeStatus->setText("Status: Upload Finished");
|
||
}
|
||
}
|
||
|
||
if (sender() == &m_varTimer_RefreshMsgList)
|
||
{
|
||
/*
|
||
* Record Count
|
||
*/
|
||
if (m_bRecord)
|
||
{
|
||
static int s_nRecordCount = 0;
|
||
s_nRecordCount++;
|
||
|
||
if (0 == s_nRecordCount % 20)
|
||
{
|
||
s_nRecordCount = 0;
|
||
QString strRecordCount = QString("RecordCount: %1").arg(m_nRecordCount);
|
||
|
||
ui->m_label_RecordCount->setText(strRecordCount);
|
||
}
|
||
}
|
||
|
||
/*
|
||
* msg list
|
||
*/
|
||
QString strMsg;
|
||
|
||
m_mutexMsgList.lock();
|
||
|
||
if (m_strMsgList.empty())
|
||
{
|
||
m_mutexMsgList.unlock();
|
||
|
||
return;
|
||
}
|
||
|
||
strMsg = m_strMsgList.front();
|
||
m_strMsgList.pop_front();
|
||
|
||
m_mutexMsgList.unlock();
|
||
|
||
if (nullptr == m_ptrDataModel_Msg.get())
|
||
{
|
||
return;
|
||
}
|
||
|
||
while (m_ptrDataModel_Msg->rowCount() > 9999)
|
||
{
|
||
m_ptrDataModel_Msg->removeRow(0);
|
||
}
|
||
|
||
const int c_nRowCount = m_ptrDataModel_Msg->rowCount();
|
||
|
||
m_ptrDataModel_Msg->insertRow(c_nRowCount + 0);
|
||
m_ptrDataModel_Msg->setData(m_ptrDataModel_Msg->index(c_nRowCount + 0, 0), QVariant(strMsg));
|
||
|
||
ui->m_listView_Msg->scrollToBottom();
|
||
}
|
||
|
||
if (sender() == &m_varTimer_RefreshUpgradeStatus)
|
||
{
|
||
/*
|
||
* upgrade progress
|
||
*/
|
||
QString strStatus = "";
|
||
|
||
switch (m_eUpgradeStatus)
|
||
{
|
||
case eUpgradeStatus_Ready:
|
||
{
|
||
if (m_bRefreshUpgradeStatus)
|
||
{
|
||
m_bRefreshUpgradeStatus = false;
|
||
|
||
strStatus = "Status: Ready";
|
||
ui->m_label_UpgradeStatus->setText(strStatus);
|
||
}
|
||
|
||
break;
|
||
}
|
||
case eUpgradeStatus_Uploading:
|
||
{
|
||
if (m_bUpgradeProgress)
|
||
{
|
||
m_bUpgradeProgress = false;
|
||
int nProgress = 100 * (m_dUpgradeProgress + 0.005);
|
||
|
||
ui->m_progressBar_Upgrade->setValue(nProgress);
|
||
}
|
||
|
||
m_nUpgradeStatus_Counter++;
|
||
int nUpgradeStatus_Counter = m_nUpgradeStatus_Counter / 15;
|
||
|
||
if (nUpgradeStatus_Counter % 5 == 4)
|
||
{
|
||
m_nUpgradeStatus_Counter = 0;
|
||
nUpgradeStatus_Counter = 0;
|
||
}
|
||
|
||
switch (nUpgradeStatus_Counter)
|
||
{
|
||
case 1:
|
||
{
|
||
strStatus = "Status: Uploading.";
|
||
break;
|
||
}
|
||
case 2:
|
||
{
|
||
strStatus = "Status: Uploading..";
|
||
break;
|
||
}
|
||
case 3:
|
||
{
|
||
strStatus = "Status: Uploading...";
|
||
break;
|
||
}
|
||
default:
|
||
{
|
||
strStatus = "Status: Uploading";
|
||
break;
|
||
}
|
||
}
|
||
|
||
ui->m_label_UpgradeStatus->setText(strStatus);
|
||
|
||
break;
|
||
}
|
||
case eUpgradeStatus_UploadFinished:
|
||
{
|
||
break;
|
||
}
|
||
case eUpgradeStatus_Preparing:
|
||
{
|
||
break;
|
||
}
|
||
case eUpgradeStatus_Writing:
|
||
{
|
||
break;
|
||
}
|
||
case eUpgradeStatus_Writen_Succeed:
|
||
{
|
||
if (m_bRefreshUpgradeStatus)
|
||
{
|
||
m_bRefreshUpgradeStatus = false;
|
||
}
|
||
|
||
break;
|
||
}
|
||
case eUpgradeStatus_Writen_Failed:
|
||
{
|
||
if (m_bRefreshUpgradeStatus)
|
||
{
|
||
m_bRefreshUpgradeStatus = false;
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
bool MainWindow::RecordRecvData(CAN_OBJ varFrameInfo)
|
||
{
|
||
if (!m_bRecord)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
if (!m_varFileRecorder.isOpen())
|
||
{
|
||
return false;
|
||
}
|
||
|
||
QString tmpstr = "", str = "";
|
||
|
||
// 时间戳
|
||
str = QString("%1").arg(varFrameInfo.TimeStamp);
|
||
str += ",";
|
||
|
||
// 时间间隔
|
||
UINT nTimeSpan = varFrameInfo.TimeStamp - m_nLastRecvTimeStamp;
|
||
m_nLastRecvTimeStamp = varFrameInfo.TimeStamp;
|
||
|
||
str += QString("%1").arg(nTimeSpan);
|
||
str += ",";
|
||
|
||
// 帧ID
|
||
tmpstr.sprintf(("0x%x "), varFrameInfo.ID);
|
||
str += tmpstr;
|
||
str += ",";
|
||
|
||
// 数据
|
||
if (varFrameInfo.RemoteFlag == 0)
|
||
{
|
||
QString strT = "";
|
||
|
||
if (varFrameInfo.DataLen > 8)
|
||
{
|
||
varFrameInfo.DataLen = 8;
|
||
}
|
||
|
||
for (int j = 0; j < varFrameInfo.DataLen; j++)
|
||
{
|
||
tmpstr.sprintf(("0x%02x,"), varFrameInfo.Data[j]);
|
||
strT += tmpstr;
|
||
}
|
||
|
||
tmpstr = strT.left(strT.length() - 1);
|
||
}
|
||
|
||
str += tmpstr;
|
||
str += "\n";
|
||
|
||
m_varFileRecorder.write(str.toStdString().c_str());
|
||
|
||
return true;
|
||
}
|
||
|
||
void MainWindow::ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner)
|
||
{
|
||
MainWindow* pThis = reinterpret_cast<MainWindow*>(pOwner);
|
||
|
||
if (NULL == pThis)
|
||
{
|
||
return;
|
||
}
|
||
|
||
(pThis->*pRunFun)();
|
||
}
|
||
|
||
void MainWindow::ThreadFun_ReceiveData_CAN()
|
||
{
|
||
timeBeginPeriod(1);
|
||
|
||
std::chrono::system_clock::time_point tm2_2 = std::chrono::system_clock::now();
|
||
|
||
int nTimeOutCount = 0;
|
||
|
||
int nFrameCount_LivePacket = 0;
|
||
|
||
m_nRecordCount = 0;
|
||
|
||
while (m_bThreadRunning_ReceiveData_CAN)
|
||
{
|
||
CAN_OBJ frameinfo[50];
|
||
|
||
int nRecvFrameCount = 1;
|
||
|
||
QString str, tmpstr;
|
||
|
||
nRecvFrameCount = Receive(m_nCAN_DevType, m_nCAN_DeviceIndex, 0, frameinfo, 50, 100);
|
||
|
||
if (nRecvFrameCount > 0)
|
||
{
|
||
for (int i = 0; i < nRecvFrameCount; i++)
|
||
{
|
||
if (RecordRecvData(frameinfo[i]))
|
||
{
|
||
m_nRecordCount++;
|
||
|
||
continue;
|
||
}
|
||
|
||
// display msg
|
||
bool c_bDisplayMsg = true;
|
||
|
||
if (c_bDisplayMsg)
|
||
{
|
||
if (eDeviceType_CM1K10A == m_eDeviceType) // CM1K10A
|
||
{
|
||
if (0x80 == frameinfo[i].ID)
|
||
{
|
||
nFrameCount_LivePacket++;
|
||
|
||
if (0 != nFrameCount_LivePacket % 10)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
nFrameCount_LivePacket = 0;
|
||
}
|
||
}
|
||
else if (eDeviceType_CM1K12G == m_eDeviceType) // CM1K12G
|
||
{
|
||
if (0x650 == frameinfo[i].ID)
|
||
{
|
||
nFrameCount_LivePacket++;
|
||
|
||
if (0 != nFrameCount_LivePacket % 30)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
nFrameCount_LivePacket = 0;
|
||
}
|
||
}
|
||
else //if(eDeviceType_CM1K12G_Private == m_eDeviceType) // CM1K12G_Private
|
||
{
|
||
if (0x650 == frameinfo[i].ID)
|
||
{
|
||
nFrameCount_LivePacket++;
|
||
|
||
if (0 != nFrameCount_LivePacket % 200)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
nFrameCount_LivePacket = 0;
|
||
}
|
||
}
|
||
|
||
str = "Recv: ";
|
||
|
||
if (frameinfo[i].TimeFlag == 0)
|
||
{
|
||
tmpstr = "Time: ";
|
||
}
|
||
else
|
||
{
|
||
tmpstr.sprintf(("Time:%08x "), frameinfo[i].TimeStamp);
|
||
}
|
||
|
||
str += tmpstr;
|
||
tmpstr.sprintf(("ID:0x%x "), frameinfo[i].ID);
|
||
str += tmpstr;
|
||
str += "Format:";
|
||
|
||
if (frameinfo[i].RemoteFlag == 0)
|
||
{
|
||
tmpstr = "Data ";
|
||
}
|
||
else
|
||
{
|
||
tmpstr = "Romte ";
|
||
}
|
||
|
||
str += tmpstr;
|
||
str += "Type:";
|
||
|
||
if (frameinfo[i].ExternFlag == 0)
|
||
{
|
||
tmpstr = "Stand ";
|
||
}
|
||
else
|
||
{
|
||
tmpstr = "Extend ";
|
||
}
|
||
|
||
str += tmpstr;
|
||
|
||
AddMsg(str, true);
|
||
//box->InsertString(box->GetCount(),str);
|
||
|
||
if (frameinfo[i].RemoteFlag == 0)
|
||
{
|
||
str = "Data:";
|
||
|
||
if (frameinfo[i].DataLen > 8)
|
||
{
|
||
frameinfo[i].DataLen = 8;
|
||
}
|
||
|
||
for (int j = 0; j < frameinfo[i].DataLen; j++)
|
||
{
|
||
tmpstr.sprintf(("%02x "), frameinfo[i].Data[j]);
|
||
str += tmpstr;
|
||
}
|
||
|
||
AddMsg(str, true);
|
||
//box->InsertString(box->GetCount(),str);
|
||
}
|
||
}
|
||
|
||
// process msg
|
||
if (m_bUploading)
|
||
{
|
||
if (eDeviceType_CM1K10A == m_eDeviceType) // CM1K10A
|
||
{
|
||
m_ptrCanUpgrade_CM1K10A->DoData_CAN(frameinfo[i]);
|
||
}
|
||
else if (eDeviceType_CM1K12G == m_eDeviceType)// CM1K12G
|
||
{
|
||
m_ptrCanUpgrade_CM1K12G->DoData_CAN(frameinfo[i]);
|
||
}
|
||
else //if (eDeviceType_CM1K12G_Private == m_eDeviceType)// CM1K12G_Private
|
||
{
|
||
m_ptrCanUpgrade_CM1K12G_Private->DoData_CAN(frameinfo[i]);
|
||
}
|
||
}
|
||
}
|
||
} // if (nRecvFrameCount > 0)
|
||
else
|
||
{
|
||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||
}
|
||
}
|
||
|
||
timeEndPeriod(1);
|
||
}
|
||
|
||
bool MainWindow::StartThread_ReceiveData_CAN()
|
||
{
|
||
StopThread_ReceiveData_CAN();
|
||
|
||
//
|
||
m_bThreadRunning_ReceiveData_CAN = true;
|
||
m_ptrThread_ReceiveData_CAN = new std::thread(std::bind(&MainWindow::ThreadEntry, &MainWindow::ThreadFun_ReceiveData_CAN, (void*)this));
|
||
|
||
return true;
|
||
}
|
||
|
||
void MainWindow::StopThread_ReceiveData_CAN()
|
||
{
|
||
//
|
||
if (m_bThreadRunning_ReceiveData_CAN)
|
||
{
|
||
m_bThreadRunning_ReceiveData_CAN = false;
|
||
|
||
if (nullptr != m_ptrThread_ReceiveData_CAN)
|
||
{
|
||
m_ptrThread_ReceiveData_CAN->join();
|
||
|
||
delete m_ptrThread_ReceiveData_CAN;
|
||
m_ptrThread_ReceiveData_CAN = nullptr;
|
||
}
|
||
}
|
||
}
|