You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

166 lines
3.8 KiB

#include "model/Console.h"
#include "model/DataSender.h"
#include "QByteArray"
Console::Console()
{
initializeButtons();
}
/*************************************************************************************************/
void Console::injectDataSender(DataSender* sender)
{
_dataSender = sender;
}
/*************************************************************************************************/
void Console::injectLogger(Logger* logger)
{
_logger = logger;
}
/*************************************************************************************************/
void Console::newData(QByteArray data)
{
try
{
hasValidDataFormat(data);
if(isEchoPacket(data))
{
_dataSender->send(data);
}
else
{
emit dataReady(data, _logger);
}
}
catch(const std::exception& e)
{
_logger->log(e.what());
}
}
/*************************************************************************************************/
void Console::hasValidDataFormat(const QByteArray& data)
{
if(data.size() != PROTOCOL_LENGTH)
{
throw std::runtime_error(("Data length is not Correct, expected 8 got " + QString::number(
data.size())).toStdString());
}
if(data[0] != static_cast<char>(PacketAppDirection))
{
throw std::runtime_error("Data direction is not From App");
}
}
/*************************************************************************************************/
bool Console::isEchoPacket(const QByteArray& data)
{
QByteArray echoPacket;
echoPacket.resize(PROTOCOL_LENGTH);
echoPacket[0] = PacketAppDirection;
echoPacket[1] = EchoDataLength;
echoPacket[2] = EchoType;
echoPacket[3] = static_cast<char>(EchoFunctionCode);
echoPacket[4] = ZeroValue;
echoPacket[5] = ZeroValue;
echoPacket[6] = ZeroValue;
echoPacket[7] = ZeroValue;
for(int i = 0; i < data.length(); i++)
{
if(data[i] != echoPacket[i])
{
return false;
}
}
return true;
}
/*************************************************************************************************/
void Console::initializeButtons()
{
initSlot1();
initSlot2();
initSlot3();
initSlot4();
initDual();
initQuad();
initSingle();
initP1();
initP2();
initP3();
initP4();
initP5();
initP6();
initExit();
initFreeze();
initPointer();
initAutoSet();
initAbc();
initFourD();
initClear();
initThreeD();
initMeasure();
initBodyMark();
initPatient();
initUtils();
initDvd();
initReport();
initProbe();
initArchive();
initEnd();
initXtd();
initBf();
initJs1Top();
initJs2Top();
initJs3Top();
initJs4Top();
initJs5Top();
initDepthTop();
initFocusTop();
initJs1Center();
initJs2Center();
initJs3Center();
initJs4Center();
initJs5Center();
initDepthCenter();
initFocusCenter();
initModePwCenter();
initModeMCenter();
initModePdCenter();
initModeCCenter();
initModeBCenter();
initJs1Bottom();
initJs2Bottom();
initJs3Bottom();
initJs4Bottom();
initJs5Bottom();
initDepthBottom();
initFocusBottom();
initTrackballTop();
initTrackballTopRight();
initTrackballRight();
initTrackballBottomRight();
initTrackballBottom();
initTrackballBottomLeft();
initTrackballLeft();
initTrackballTopLeft();
initJs1();
initJs2();
initJs3();
initJs4();
initJs5();
initDepth();
initFocus();
initModePw();
initModeM();
initModePd();
initModeC();
initModeB();
}