2024-06-13 17:23:47 +02:00
|
|
|
#ifndef MESSAGE_HELPER_H_INCLUDED
|
|
|
|
#define MESSAGE_HELPER_H_INCLUDED
|
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QByteArrayList>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
class MessageHelper {
|
|
|
|
public:
|
|
|
|
enum PacketType : std::uint8_t {
|
|
|
|
POS_ECR = 0,
|
|
|
|
// POS_EXT = 1,
|
|
|
|
MESSAGE_RECEIVED_POSITIVE_ACK = 0x0A,
|
|
|
|
MESSAGE_RECEIVED_NEGATIVE_ACK = 0x0F
|
|
|
|
// POS_HOST_FORMAT_1_ENCRYPTED = 0x11,
|
|
|
|
// POS_HOST_FORMAT_1_UNENCRYPTED = 0x21
|
|
|
|
};
|
|
|
|
|
2024-06-14 12:50:12 +02:00
|
|
|
enum AsyncPosCommand : std::uint8_t {
|
|
|
|
LOGIN = 0,
|
|
|
|
LOGOUT = 1
|
|
|
|
};
|
|
|
|
|
2024-06-13 17:23:47 +02:00
|
|
|
explicit MessageHelper(QString const &posID = "T-TPS-SELF2002in",
|
|
|
|
QString const &apak = "8AC304380E0E476BA2558B75DB9E2516");
|
|
|
|
explicit MessageHelper(QByteArray const &posID, QString const &apak);
|
|
|
|
~MessageHelper();
|
|
|
|
|
|
|
|
|
|
|
|
void createRawPacket(PacketType PacketType,
|
|
|
|
QByteArray const &encryptedPacketId,
|
|
|
|
QByteArray const &message);
|
|
|
|
|
|
|
|
bool insertEncryptedPacketID(QByteArray const &encryptedPacketID);
|
|
|
|
|
2024-06-14 12:50:12 +02:00
|
|
|
QByteArrayList createLoginMessageChunksToSend(char etx);
|
|
|
|
QByteArrayList createLogoutMessageChunksToSend(char etx);
|
|
|
|
QByteArrayList const &createMessageChunksToSend(AsyncPosCommand cmd, char etx);
|
2024-06-13 17:23:47 +02:00
|
|
|
|
|
|
|
// private:
|
|
|
|
|
|
|
|
QByteArray m_posID;
|
2024-06-14 11:54:43 +02:00
|
|
|
QByteArray m_apak;
|
2024-06-13 17:23:47 +02:00
|
|
|
uint8_t m_posIDLength;
|
|
|
|
QByteArray m_messageHeaderPrefix;
|
|
|
|
QByteArray m_rawPacket; // without leading STX and trailing [ETX(1/2), LRC]
|
|
|
|
QByteArray m_loginMessage;
|
2024-06-14 12:50:12 +02:00
|
|
|
QByteArray m_logoutMessage;
|
2024-06-13 17:23:47 +02:00
|
|
|
QByteArrayList m_messageChunkList;
|
|
|
|
|
|
|
|
bool setMessageHeaderPacketType(PacketType packetType);
|
|
|
|
bool createMessageHeaderPrefix(PacketType packetType, QByteArray const &encryptedPacketID);
|
|
|
|
void createLoginMessage();
|
2024-06-14 12:50:12 +02:00
|
|
|
void createLogoutMessage();
|
2024-06-13 17:23:47 +02:00
|
|
|
|
|
|
|
static QByteArray const &mask(QByteArray &messageChunk);
|
|
|
|
static QByteArray const &unMask(QByteArray &messageChunk);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MESSAGE_HELPER_H_INCLUDED
|