<commit_before>#include "backend.h"
//#define QS_LOG_DISABLE
#include "QsLog.h"

Backend::Backend(QObject *parent) :
	QObject(parent)
{
}

void Backend::modbusRequest(ADU * const modbusRequest)
{
	ADU * const reply =  modbusRequest;
	uint functionCode = modbusRequest->getFunctionCode();
	QByteArray data = modbusRequest->getData();

	switch(functionCode)
	{
	case PDU::ReadHoldingRegisters : //03 (0x03) Read Holding Registers
	{
		QLOG_TRACE() << "PDU::ReadHoldingRegisters";
		QLOG_TRACE() << "data = " << data.toHex().toUpper();
		int startAddress = modbusRequest->getAddres();
		quint16 quantity = modbusRequest->getQuantity();
		QLOG_TRACE() << "startAddress = " << startAddress;
		QLOG_TRACE() << "quantity = " << quantity;

		if (quantity == 0 || quantity > 125) {
			QLOG_ERROR() << "Illegal Data Value. Raising exception";
			modbusRequest->setExceptionCode(PDU::IllegalDataValue);
		} else {
			QByteArray replyData;
			emit getValues(startAddress, modbusRequest->getUnitID(), quantity, replyData);
			if (replyData.isEmpty()) {
				QLOG_ERROR() << "Illegal Data Address. Raising exception";
				modbusRequest->setExceptionCode(PDU::IllegalDataAddress);
			} else {
				reply->setData(replyData);
				QLOG_DEBUG() << replyData.toHex().toUpper();
			}
		}
		break;
	}
	default:
		QLOG_ERROR() << "Unknown Function. Raising exception";
		modbusRequest->setExceptionCode(PDU::IllegalFunction);
		break;
	}
	emit modbusReply(reply);
}<commit_msg>backend: Made error messages more verbose<commit_after>#include "backend.h"
//#define QS_LOG_DISABLE
#include "QsLog.h"

Backend::Backend(QObject *parent) :
	QObject(parent)
{
}

void Backend::modbusRequest(ADU * const modbusRequest)
{
	ADU * const reply =  modbusRequest;
	uint functionCode = modbusRequest->getFunctionCode();
	QByteArray data = modbusRequest->getData();

	switch(functionCode)
	{
	case PDU::ReadHoldingRegisters : //03 (0x03) Read Holding Registers
	{
		QLOG_TRACE() << "PDU::ReadHoldingRegisters";
		QLOG_TRACE() << "data = " << data.toHex().toUpper();
		int startAddress = modbusRequest->getAddres();
		quint16 quantity = modbusRequest->getQuantity();
		QLOG_TRACE() << "startAddress = " << startAddress;
		QLOG_TRACE() << "quantity = " << quantity;

		if (quantity == 0 || quantity > 125) {
			QLOG_ERROR() << "Requested quantity" << quantity << "invalid for function" << functionCode;
			modbusRequest->setExceptionCode(PDU::IllegalDataValue);
		} else {
			QByteArray replyData;
			emit getValues(startAddress, modbusRequest->getUnitID(), quantity, replyData);
			if (replyData.isEmpty()) {
				QLOG_ERROR() << "Not existing address" << startAddress << "or gap(s) in range with quantity" << quantity << "for function" << functionCode;
				modbusRequest->setExceptionCode(PDU::IllegalDataAddress);
			} else {
				reply->setData(replyData);
				QLOG_DEBUG() << replyData.toHex().toUpper();
			}
		}
		break;
	}
	default:
		QLOG_ERROR() << "Unknown function " << functionCode;
		modbusRequest->setExceptionCode(PDU::IllegalFunction);
		break;
	}
	emit modbusReply(reply);
}
{'fraction_non_alphanumeric': 0.14829396325459318, 'fraction_numerical': 0.007217847769028871, 'mean_word_length': 5.0858283433133735, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '702952', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1007, 'n_words': 199}