UnionComDLL/unioncom.h

317 lines
8.5 KiB
C++

#ifndef UNIONCOM_H
#define UNIONCOM_H
#include <QWidget>
#include <QStandardItemModel>
#include <QTableWidgetItem>
#include "ProjectSettings.h"
#include "ui_unioncom.h"
#include <QEvent>
#define microsecondToMilliseconds(x) x/1000%1000
#define microsecondToSeconds(x) x/1000/1000%60
#define microsecondToMinutes(x) x/1000/1000/60%60
#define microsecondToHours(x) x/1000/1000/60/60
extern "C" __declspec(dllexport) QWidget* init(QWidget *parent);
class MyEvent : public QEvent
{
public:
MyEvent(const QString& message, const short msgType) : QEvent(QEvent::User) {_message = message; _msgType = msgType;}
~MyEvent() {}
QString message() const {return _message;}
short msgType() const {return _msgType;}
private:
QString _message;
short _msgType;
};
namespace Ui {
class UnionCOM;
}
class RxCanEvent : public QEvent
{
public:
static const QEvent::Type EventType = static_cast<QEvent::Type>(2000);
RxCanEvent(const SLCAN_MESSAGE& msg, const QTime timeEvent, const unsigned long long time_stamp) : QEvent(RxCanEvent::EventType) {_msg = msg; _time = timeEvent; _time_stamp = time_stamp;}
~RxCanEvent(){}
SLCAN_MESSAGE msg() const {return _msg;}
QTime time() const {return _time;}
unsigned long long time_stamp() const {return _time_stamp;}
private:
SLCAN_MESSAGE _msg;
QTime _time;
unsigned long long _time_stamp;
};
class UnionCOM : public QWidget
{
Q_OBJECT
public:
struct mcrs_kit{
Qt::CheckState EID;
DWORD ID;
Qt::CheckState RTR;
Qt::CheckState IsHEX;
byte DLC;
QString Name;
QString Mcrs;
int Count;
Qt::CheckState IsPeriod;
int Period;
} MacrosMain[15];
bool InitMcrsSetting = TRUE;
DWORD ID; //идентификатор устройства
SLCAN_MESSAGE outMsg; //буфер для отправки сообщения
SLCAN_MESSAGE inputMsg[FRAMES]; //буфер для приёма сообщения
SLCAN_EVENT inputEvents[FRAMES];
HSLCAN device;
SLCAN_BITRATE br;
DWORD cntrInput;
SLCAN_STATE DeviceState;
void Connect_Notification();
void Disconnect_Notification();
void Emergency_Disconnect_Notification();
void AfterDisconnection();
void AfterConnection();
void pushMcrs_CAN(int index);
void sendCMD_CAN();
void sendCMDHEX_CAN();
void sendFile_CAN();
void pushMcrs_RS(int index);
void sendCMD_RS();
void sendCMDHEX_RS();
void sendFile_RS();
void TimeToReadEvents();
void gotors();
explicit UnionCOM(QWidget *parent = nullptr);
~UnionCOM();
void startMCRSTX(int index);
bool TimeToStopCANRead;
bool canReadingInThread;
void stopCANReadThread();
bool notTimeToStopPeriodMcrs[15];
private slots:
void rxErrorTimer_anotherSec();
void txErrorTimer_anotherSec();
void on_cboxTypeConnection_currentIndexChanged(int index);
void on_buttonConnect_clicked();
void on_buttonDisconnect_clicked();
void on_buttonSendCMD_clicked();
void on_buttonSendCMDHex_clicked();
void on_buttonSendFile_clicked();
// void on_buttonSDCard_clicked();
// void on_buttonReturnToBootloader_clicked();
void on_buttonLoadFile_clicked();
void on_boxDataCount_currentIndexChanged(int index);
void on_buttonSetMcrs_clicked();
void on_buttonStopMacros_01_clicked() {stopMcrs(1);};
void on_buttonStopMacros_02_clicked() {stopMcrs(2);};
void on_buttonStopMacros_03_clicked() {stopMcrs(3);};
void on_buttonStopMacros_04_clicked() {stopMcrs(4);};
void on_buttonStopMacros_05_clicked() {stopMcrs(5);};
void on_buttonStopMacros_06_clicked() {stopMcrs(6);};
void on_buttonStopMacros_07_clicked() {stopMcrs(7);};
void on_buttonStopMacros_08_clicked() {stopMcrs(8);};
void on_buttonStopMacros_09_clicked() {stopMcrs(9);};
void on_buttonStopMacros_10_clicked() {stopMcrs(10);};
void on_buttonStopMacros_11_clicked() {stopMcrs(11);};
void on_buttonStopMacros_12_clicked() {stopMcrs(12);};
void on_buttonStopMacros_13_clicked() {stopMcrs(13);};
void on_buttonStopMacros_14_clicked() {stopMcrs(14);};
void on_buttonStopMacros_15_clicked() {stopMcrs(15);};
void on_buttonMacros_01_clicked() {isTxIdle_MCRS(1);};
void on_buttonMacros_02_clicked() {isTxIdle_MCRS(2);};
void on_buttonMacros_03_clicked() {isTxIdle_MCRS(3);};
void on_buttonMacros_04_clicked() {isTxIdle_MCRS(4);};
void on_buttonMacros_05_clicked() {isTxIdle_MCRS(5);};
void on_buttonMacros_06_clicked() {isTxIdle_MCRS(6);};
void on_buttonMacros_07_clicked() {isTxIdle_MCRS(7);};
void on_buttonMacros_08_clicked() {isTxIdle_MCRS(8);};
void on_buttonMacros_09_clicked() {isTxIdle_MCRS(9);};
void on_buttonMacros_10_clicked() {isTxIdle_MCRS(10);};
void on_buttonMacros_11_clicked() {isTxIdle_MCRS(11);};
void on_buttonMacros_12_clicked() {isTxIdle_MCRS(12);};
void on_buttonMacros_13_clicked() {isTxIdle_MCRS(13);};
void on_buttonMacros_14_clicked() {isTxIdle_MCRS(14);};
void on_buttonMacros_15_clicked() {isTxIdle_MCRS(15);};
void on_buttonSaveMcrsKit_clicked();
void on_buttonLoadMcrsKit_clicked();
void on_buttonClearLogger_clicked();
void on_checkModbusEnabled_stateChanged(int arg1);
void stepToStartCMDTX();
void stepToStartCMDHEXTX();
void stepToStartSendFile();
void on_buttonRXErrorCountErase_clicked();
void on_buttonTXErrorCountErase_clicked();
void appendToLogger(QString msgToLogger);
void on_buttonCRC_clicked();
void on_checkHEXRTR_stateChanged(int arg1);
void on_checkHEXEID_stateChanged(int arg1);
void on_lineHEXID_textChanged(const QString &arg1);
void on_pushButton_clicked();
void on_requestBox_stateChanged(int arg1);
signals:
void isTxFinished();
void notifToLogger(QString msgToLogger);
private:
QString errors_RS(int ConnectionError);
bool event(QEvent* event);
int OldCountOfRXError = 0;
int OldCountOfTXError = 0;
short counterOfLoggerMSG = 0;
void deleteTopLine();
int SLCAN_MODE;
void isTxIdle_MCRS(int index);
void isTxIdle_CMD();
void isTxIdle_CMDHEX();
void isTxIdle_FILE();
void startSendFile();
void startCMDTX();
void startCMDHEXTX();
bool isIdle = TRUE;
bool userTXInterruption = FALSE;
void stopMcrs(int index);
void (UnionCOM::*ptrButtonMcrs[15])(){&UnionCOM::on_buttonMacros_01_clicked,
&UnionCOM::on_buttonMacros_02_clicked, &UnionCOM::on_buttonMacros_03_clicked,
&UnionCOM::on_buttonMacros_04_clicked, &UnionCOM::on_buttonMacros_05_clicked,
&UnionCOM::on_buttonMacros_06_clicked, &UnionCOM::on_buttonMacros_07_clicked,
&UnionCOM::on_buttonMacros_08_clicked, &UnionCOM::on_buttonMacros_09_clicked,
&UnionCOM::on_buttonMacros_10_clicked, &UnionCOM::on_buttonMacros_11_clicked,
&UnionCOM::on_buttonMacros_12_clicked, &UnionCOM::on_buttonMacros_13_clicked,
&UnionCOM::on_buttonMacros_14_clicked, &UnionCOM::on_buttonMacros_15_clicked};
bool CheckFile(qint64 StatusOfRead, char *buffer, qint64 MaxByteToRead);
unsigned int Counter_of_suc_transmit=0;
unsigned int TX_error_counter = 0;
QLineEdit *HEXByteField[8];
QPushButton *McrsButtons[15];
QPushButton *McrsStopButtons[15];
void readData();
QTimer *TimerReadEvents;
QTimer *TransferEndTimer;
QTimer *McrsPeriodTransfer[15];
QTimer *timeFromTXErrorClear;
QTimer *timeFromRXErrorClear;
void rxErrorTimer_clear();
void txErrorTimer_clear();
BOOL UsartFileLoading = 0;
QString fileName;
QString BufferForLoadFile;
void EndOfUSARTLoadFile();
void clearMSG();
BYTE writeMSG();
void Device_Error(PSLCAN_STATE DeviceState);
void openCAN();
void Init();
void SettingWidget();
void openSerialPort();
QLabel *m_status = nullptr;
QSerialPort *m_serial = nullptr;
void tableInit();
QStandardItemModel* RxCanModel;
QStandardItemModel* RxCanRequesterModel;
union Requester_ID{
struct RequesterStandardID
{
uint Device:8;
uint SensorID:11;
uint SensorType:5;
uint DataType:4;
uint Route:1;
}Standard;
struct RequesterModbusID
{
uint Device:8;
uint CountReg:8;
uint StrAdr:8;
uint DataType:4;
uint Route:1;
}Modbus;
uint ID_All:29;
}RequesterID;
Ui::UnionCOM *ui;
};
#endif // UNIONCOM_H