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.
 
 
 
 

89 lines
2.2 KiB

#include "model/Console.h"
#include "model/DataSender.h"
#include "QByteArray"
Console::Console()
{
}
/*************************************************************************************************/
void Console::injectDataSender(DataSender* sender)
{
_dataSender = sender;
}
/*************************************************************************************************/
void Console::newData(QByteArray data)
{
_newData = data;
if(hasValidDataFormat())
{
if(isEchoPacket())
{
//send echo response
_dataSender->send(_newData);
}
else
{
// call all buttons newData
}
}
else
{
_logger->log(_message);
}
}
/*************************************************************************************************/
bool Console::hasValidDataFormat()
{
if(_newData.isNull() | _newData.isEmpty() | _newData.size() !=8)
{
_message = "Data is not Correct";
return false;
}
if(_newData[0] != static_cast<char>(0X00))
{
_message = "Data direction is not From App";
return false;
}
if(!(_newData[1] == static_cast<char>(0X01) || _newData[1] == static_cast<char>(0X02)))
{
_message = "data length is not correct";
return false;
}
/* if(!(data[2] == static_cast<char>(0X04) || data[2] == static_cast<char>(0X05) || data[2] == static_cast<char>(0X06)))
{
_logger->log("Data type is not : pushButton:4, Rotary:5, Special: 6");
return false;
}*/
return true;
}
/*************************************************************************************************/
bool Console::isEchoPacket()
{
QByteArray echoPacket;
echoPacket.resize(8);
echoPacket[0] = 0x01;
echoPacket[1] = 0x02;
echoPacket[2] = 0x06;
echoPacket[3] = static_cast<char>(0xA4);
echoPacket[4] = 0x00;
echoPacket[5] = 0x00;
echoPacket[6] = 0x00;
echoPacket[7] = 0x00;
for(int i=0 ; i<_newData.length() ; i++)
{
if (_newData[i] != echoPacket[i])
{
return false;
}
}
return true;
}