Added Logout

This commit is contained in:
Gerhard Hoffmann 2024-06-14 12:50:12 +02:00
parent bc00d25ded
commit fc94e603c5
2 changed files with 58 additions and 5 deletions

View File

@ -175,12 +175,49 @@ void MessageHelper::createLoginMessage() {
}
}
QByteArrayList const &MessageHelper::createLoginMessageChunksToSend(char etx) {
void MessageHelper::createLogoutMessage() {
m_logoutMessage.clear();
m_logoutMessage.push_back((char)0x85); // 5 in 0x85 is the size
m_logoutMessage = m_loginMessage.append(QByteArray("Logout"));
m_loginMessage.push_back((char)0x04);
m_loginMessage = m_loginMessage.append(QByteArray("Time"));
m_loginMessage.push_back((char)0x00);
m_loginMessage.push_back((char)0x13);
QDateTime current = QDateTime::currentDateTime();
// TODO: wieder entfernen
current.setTime(QTime(12, 0, 0));
current.setDate(QDate(2024, 6, 12));
QByteArray time(current.toString(Qt::ISODate).toStdString().c_str());
time[10] = ' ';
m_logoutMessage = m_logoutMessage.append(time);
m_loginMessage.push_back((char)0x00);
if (DBG_LEVEL >= DBG_INFORMATION) {
qCritical() << DBG_HEADER << "loginMessage" << m_logoutMessage.toHex(':');
}
}
QByteArrayList const &MessageHelper::createMessageChunksToSend(AsyncPosCommand cmd, char etx) {
QByteArray encryptedPacketID(QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08"));
m_messageChunkList.clear();
switch (cmd) {
case (int)MessageHelper::AsyncPosCommand::LOGIN:
createLoginMessage();
createRawPacket(PacketType::POS_ECR, encryptedPacketID, m_loginMessage);
break;
case (int)MessageHelper::AsyncPosCommand::LOGOUT:
createLogoutMessage();
createRawPacket(PacketType::POS_ECR, encryptedPacketID, m_logoutMessage);
break;
default:;
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << m_rawPacket.toHex(':');
@ -296,6 +333,14 @@ QByteArrayList const &MessageHelper::createLoginMessageChunksToSend(char etx) {
return m_messageChunkList;
}
QByteArrayList MessageHelper::createLoginMessageChunksToSend(char etx) {
return createMessageChunksToSend(AsyncPosCommand::LOGIN, etx);
}
QByteArrayList MessageHelper::createLogoutMessageChunksToSend(char etx) {
return createMessageChunksToSend(AsyncPosCommand::LOGOUT, etx);
}
bool MessageHelper::insertEncryptedPacketID(QByteArray const &encryptedPacketID) {
if (encryptedPacketID.size() == PACKET_ID_SIZE) {
// m_rawPacket has already full length

View File

@ -17,6 +17,11 @@ public:
// POS_HOST_FORMAT_1_UNENCRYPTED = 0x21
};
enum AsyncPosCommand : std::uint8_t {
LOGIN = 0,
LOGOUT = 1
};
explicit MessageHelper(QString const &posID = "T-TPS-SELF2002in",
QString const &apak = "8AC304380E0E476BA2558B75DB9E2516");
explicit MessageHelper(QByteArray const &posID, QString const &apak);
@ -29,8 +34,9 @@ public:
bool insertEncryptedPacketID(QByteArray const &encryptedPacketID);
QByteArrayList const &getMessageChunksToSend();
QByteArrayList const &createLoginMessageChunksToSend(char ext);
QByteArrayList createLoginMessageChunksToSend(char etx);
QByteArrayList createLogoutMessageChunksToSend(char etx);
QByteArrayList const &createMessageChunksToSend(AsyncPosCommand cmd, char etx);
// private:
@ -40,11 +46,13 @@ public:
QByteArray m_messageHeaderPrefix;
QByteArray m_rawPacket; // without leading STX and trailing [ETX(1/2), LRC]
QByteArray m_loginMessage;
QByteArray m_logoutMessage;
QByteArrayList m_messageChunkList;
bool setMessageHeaderPacketType(PacketType packetType);
bool createMessageHeaderPrefix(PacketType packetType, QByteArray const &encryptedPacketID);
void createLoginMessage();
void createLogoutMessage();
static QByteArray const &mask(QByteArray &messageChunk);
static QByteArray const &unMask(QByteArray &messageChunk);