Browse Source

process of recive newData and some test added

mode-button
nasi 3 years ago
parent
commit
1af6a8cee0
  1. 100
      logic/include/model/ButtonHelper.h
  2. 22
      logic/include/model/Console.h
  3. 2
      logic/include/model/DataSender.h
  4. 25
      logic/include/model/Led.h
  5. 8
      logic/include/model/PushButton.h
  6. 6
      logic/include/model/RotaryButton.h
  7. 143
      logic/src/model/Console.cpp
  8. 14
      logic/src/model/Led.cpp
  9. 16
      logic/src/model/PushButton.cpp
  10. 14
      logic/src/model/RotaryButton.cpp
  11. 2
      network/UdpDataSender.cpp
  12. 2
      network/UdpDataSender.h
  13. 2
      test/TestDataSender.h
  14. 216
      test/tst_console.cpp

100
logic/include/model/ButtonHelper.h

@ -2,64 +2,80 @@
#define BUTTONHELPER_H #define BUTTONHELPER_H
#define PUSH_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ #define PUSH_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \ private: \
PushButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ PushButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
public: \ void init ## CAPITAL_NAME() \
void press ## CAPITAL_NAME() \ { \
{ \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
auto arr = _ ## SMALL_NAME.press(); \ connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
_dataSender->send(arr); \ } \
} \ public: \
void release ## CAPITAL_NAME() \ void press ## CAPITAL_NAME() \
{ \ { \
auto arr = _ ## SMALL_NAME.release(); \ auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \ _dataSender->send(arr); \
} \ } \
signals: \ void release ## CAPITAL_NAME() \
void SMALL_NAME ## LedChanged(int value) { \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/ /*************************************************************************************************/
#define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ #define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \ private: \
PushButton _ ## SMALL_NAME{FUNC_CODE}; \ PushButton _ ## SMALL_NAME{FUNC_CODE}; \
public: \ void init ## CAPITAL_NAME() \
void press ## CAPITAL_NAME() \ { \
{ \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
auto arr = _ ## SMALL_NAME.press(); \ connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
_dataSender->send(arr); \ } \
} \ public: \
void release ## CAPITAL_NAME() \ void press ## CAPITAL_NAME() \
{ \ { \
auto arr = _ ## SMALL_NAME.release(); \ auto arr = _ ## SMALL_NAME.press(); \
_dataSender->send(arr); \ _dataSender->send(arr); \
} \ } \
signals: \ void release ## CAPITAL_NAME() \
void SMALL_NAME ## LedChanged(int value) { \
auto arr = _ ## SMALL_NAME.release(); \
_dataSender->send(arr); \
} \
Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
/*************************************************************************************************/ /*************************************************************************************************/
#define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ #define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \
private: \ private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \
public: \ void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
} \
public: \
void rotate ## CAPITAL_NAME(int value) \ void rotate ## CAPITAL_NAME(int value) \
{ \ { \
auto arr = _ ## SMALL_NAME.rotate(value); \ auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \ _dataSender->send(arr); \
} \ } \
signals: \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
void SMALL_NAME ## LedChanged(int value)
/*************************************************************************************************/ /*************************************************************************************************/
#define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ #define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \
private: \ private: \
RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \ RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \
public: \ void init ## CAPITAL_NAME() \
{ \
connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData);\
connect(_ ## SMALL_NAME.getLed(), SIGNAL(ledChanged(char)), this, SIGNAL(SMALL_NAME ## LedChanged(char)));\
} \
public: \
void rotate ## CAPITAL_NAME(int value) \ void rotate ## CAPITAL_NAME(int value) \
{ \ { \
auto arr = _ ## SMALL_NAME.rotate(value); \ auto arr = _ ## SMALL_NAME.rotate(value); \
_dataSender->send(arr); \ _dataSender->send(arr); \
} \ } \
signals: \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value)
void SMALL_NAME ## LedChanged(int value)
#endif //BUTTONHELPER_H #endif //BUTTONHELPER_H

22
logic/include/model/Console.h

@ -1,6 +1,15 @@
#ifndef CONSOLE_H #ifndef CONSOLE_H
#define CONSOLE_H #define CONSOLE_H
#define DataLength 8
#define PacketAppDirection 0x01
#define EchoDataLength 0x02
#define EchoType 0x06
#define EchoFunctionCode 0xA4
#define ZeroValue 0x00
#include <QObject> #include <QObject>
#include "ButtonHelper.h" #include "ButtonHelper.h"
@ -28,7 +37,7 @@ class Console : public QObject
PUSH_BUTTON(Exit, exit, EXIT_FC, static_cast<char>(EXIT_LED_FC)); PUSH_BUTTON(Exit, exit, EXIT_FC, static_cast<char>(EXIT_LED_FC));
PUSH_BUTTON(Freeze, freeze, FREEZE_FC, static_cast<char>(FREEZE_LED_FC)); PUSH_BUTTON(Freeze, freeze, FREEZE_FC, static_cast<char>(FREEZE_LED_FC));
PUSH_BUTTON(Pointer, pointer, POINTER_FC, static_cast<char>(POINTER_LED_FC)); PUSH_BUTTON(Pointer, pointer, POINTER_FC, static_cast<char>(POINTER_LED_FC));
PUSH_BUTTON(Auto, auto, AUTOSET_FC, static_cast<char>(AUTOSET_LED_FC)); PUSH_BUTTON(AutoSet, autoSet, AUTOSET_FC, static_cast<char>(AUTOSET_LED_FC));
PUSH_BUTTON(Abc, abc, ABC_FC, static_cast<char>(ABC_LED_FC)); PUSH_BUTTON(Abc, abc, ABC_FC, static_cast<char>(ABC_LED_FC));
PUSH_BUTTON(FourD, fourD, FOUR_D_FC, static_cast<char>(FOUR_D_LED_FC)); PUSH_BUTTON(FourD, fourD, FOUR_D_FC, static_cast<char>(FOUR_D_LED_FC));
PUSH_BUTTON(Clear, clear, CLEAR_FC, static_cast<char>(CLEAR_LED_FC)); PUSH_BUTTON(Clear, clear, CLEAR_FC, static_cast<char>(CLEAR_LED_FC));
@ -101,16 +110,19 @@ class Console : public QObject
private: private:
DataSender* _dataSender; DataSender* _dataSender;
Logger* _logger; Logger* _logger;
QString _message;
QByteArray _newData;
public: public:
Console(); Console();
void injectDataSender(DataSender* sender); void injectDataSender(DataSender* sender);
void injectLogger(Logger* logger); void injectLogger(Logger* logger);
void newData(QByteArray data); void newData(QByteArray data);
bool hasValidDataFormat(); void hasValidDataFormat(const QByteArray& data);
bool isEchoPacket(); bool isEchoPacket(const QByteArray& data);
void initializeButtons();
signals:
void dataReady(QByteArray data);
}; };

2
logic/include/model/DataSender.h

@ -6,7 +6,7 @@
class DataSender class DataSender
{ {
public: public:
virtual int send(const QByteArray& data) = 0; virtual bool send(const QByteArray& data) = 0;
virtual ~DataSender(){} virtual ~DataSender(){}
}; };

25
logic/include/model/Led.h

@ -1,23 +1,34 @@
#ifndef LED_H #ifndef LED_H
#define LED_H #define LED_H
#define LedOFF 0x00
#define LedColorWhite 0x01
#define LedColorGreen 0x02
#define FunctionCode 3
#define LedColor 4
#include <QObject> #include <QObject>
#include "Logger.h"
class Led : public QObject class Led : public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
char _functionCode; char _functionCode;
bool _hasLed; bool _hasLed;
Logger* _logger;
public: public:
Led(); Led();
Led(char functionCode); Led(char functionCode);
void newData(QByteArray data);
signals: signals:
void ledChanged(char value); void ledChanged(char value);
public slots:
void newData(QByteArray data);
}; };
#endif //LED_H #endif //LED_H

8
logic/include/model/PushButton.h

@ -1,6 +1,14 @@
#ifndef PUSHBUTTON_H #ifndef PUSHBUTTON_H
#define PUSHBUTTON_H #define PUSHBUTTON_H
#define DataLength 8
#define ConsoleDirection 0x00
#define PushButtonDataLength 0x01
#define PushButtonType 0x04
#define PushButtonPush 0x01
#define PushButtonRelease 0x00
#define TimeTag 0x00
#include "Led.h" #include "Led.h"
class PushButton class PushButton

6
logic/include/model/RotaryButton.h

@ -1,6 +1,12 @@
#ifndef RotaryButton_H #ifndef RotaryButton_H
#define RotaryButton_H #define RotaryButton_H
#define DataLength 8
#define ConsoleDirection 0x00
#define RotaryDataLength 0X02
#define RotaryType 0x05
#define TimeTag 0x00
#include "Led.h" #include "Led.h"
class RotaryButton class RotaryButton

143
logic/src/model/Console.cpp

@ -5,6 +5,7 @@
Console::Console() Console::Console()
{ {
initializeButtons();
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -16,74 +17,140 @@ void Console::injectDataSender(DataSender* sender)
/*************************************************************************************************/ /*************************************************************************************************/
void Console::newData(QByteArray data) void Console::newData(QByteArray data)
{ {
_newData = data; try
if(hasValidDataFormat())
{ {
if(isEchoPacket()) hasValidDataFormat(data);
if(isEchoPacket(data))
{ {
//send echo response _dataSender->send(data);
_dataSender->send(_newData);
} }
else else
{ {
// call all buttons newData emit dataReady(data);
} }
} }
else catch (const std::exception& e)
{ {
_logger->log(_message); _logger->log(e.what());
} }
} }
/*************************************************************************************************/ /*************************************************************************************************/
bool Console::hasValidDataFormat() void Console::hasValidDataFormat(const QByteArray& data)
{ {
if(_newData.isNull() | _newData.isEmpty() | _newData.size() !=8) if(data.isNull() || data.size() != DataLength)
{
_message = "Data is not Correct";
return false;
}
if(_newData[0] != static_cast<char>(0X00))
{ {
_message = "Data direction is not From App"; throw std::runtime_error("Data is not Correct");
return false;
} }
if(!(_newData[1] == static_cast<char>(0X01) || _newData[1] == static_cast<char>(0X02))) if(data[0] != static_cast<char>(PacketAppDirection))
{ {
_message = "data length is not correct"; throw std::runtime_error("Data direction is not From App");
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() bool Console::isEchoPacket(const QByteArray& data)
{ {
QByteArray echoPacket; QByteArray echoPacket;
echoPacket.resize(8); echoPacket.resize(DataLength);
echoPacket[0] = 0x01; echoPacket[0] = PacketAppDirection;
echoPacket[1] = 0x02; echoPacket[1] = EchoDataLength;
echoPacket[2] = 0x06; echoPacket[2] = EchoType;
echoPacket[3] = static_cast<char>(0xA4); echoPacket[3] = static_cast<char>(EchoFunctionCode);
echoPacket[4] = 0x00; echoPacket[4] = ZeroValue;
echoPacket[5] = 0x00; echoPacket[5] = ZeroValue;
echoPacket[6] = 0x00; echoPacket[6] = ZeroValue;
echoPacket[7] = 0x00; echoPacket[7] = ZeroValue;
for(int i=0 ; i<_newData.length() ; i++) for(int i=0 ; i<data.length() ; i++)
{ {
if (_newData[i] != echoPacket[i]) if (data[i] != echoPacket[i])
{ {
return false; return false;
} }
} }
return true; return true;
} }
/*************************************************************************************************/
void Console::initializeButtons()
{
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();
}

14
logic/src/model/Led.cpp

@ -14,5 +14,19 @@ Led::Led(char functionCode)
void Led::newData(QByteArray data) void Led::newData(QByteArray data)
{ {
try {
if(!(data[LedColor] == static_cast<char>(LedOFF) || data[LedColor] == static_cast<char>(LedColorWhite) || data[LedColor] == static_cast<char>(LedColorGreen)))
{
throw std::runtime_error("Led state color is not correct");
}
if(data[FunctionCode] == _functionCode)
{
emit ledChanged(data[LedColor]);
}
} catch (const std::exception& e)
{
_logger->log(e.what());
}
} }

16
logic/src/model/PushButton.cpp

@ -5,15 +5,15 @@ QByteArray PushButton::generateCode(bool isPressed)
{ {
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(DataLength);
arr[0] = 0x00; arr[0] = ConsoleDirection;
arr[1] = 0x01; arr[1] = PushButtonDataLength;
arr[2] = 0x04; arr[2] = PushButtonType;
arr[3] = _functionCode; arr[3] = _functionCode;
arr[4] = isPressed ? 0x01 : 0x00; arr[4] = isPressed ? PushButtonPush : PushButtonRelease;
arr[5] = 0x00; arr[5] = TimeTag;
arr[6] = 0x00; arr[6] = TimeTag;
arr[7] = 0x00; arr[7] = TimeTag;
return arr; return arr;
} }

14
logic/src/model/RotaryButton.cpp

@ -23,15 +23,15 @@ QByteArray RotaryButton::rotate(int value)
{ {
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(DataLength);
arr[0] = 0x00; arr[0] = ConsoleDirection;
arr[1] = 0X02; arr[1] = RotaryDataLength;
arr[2] = 0X05; arr[2] = RotaryType;
arr[3] = _functionCode; arr[3] = _functionCode;
arr[4] = static_cast<char>(value >> 8); arr[4] = static_cast<char>(value >> DataLength);
arr[5] = static_cast<char>(value); arr[5] = static_cast<char>(value);
arr[6] = 0x00; arr[6] = TimeTag;
arr[7] = 0x00; arr[7] = TimeTag;
return arr; return arr;
} }

2
network/UdpDataSender.cpp

@ -1,7 +1,7 @@
#include "UdpDataSender.h" #include "UdpDataSender.h"
#include <QDebug> #include <QDebug>
int UdpDataSender::send(const QByteArray &data) bool UdpDataSender::send(const QByteArray &data)
{ {
qDebug() << "Just a little test"; qDebug() << "Just a little test";
} }

2
network/UdpDataSender.h

@ -6,7 +6,7 @@
class UdpDataSender : public DataSender class UdpDataSender : public DataSender
{ {
public: public:
int send(const QByteArray &data) override; bool send(const QByteArray &data) override;
~UdpDataSender() override; ~UdpDataSender() override;
}; };

2
test/TestDataSender.h

@ -8,7 +8,7 @@ class TestDataSender : public DataSender
public: public:
QByteArray consoleData; QByteArray consoleData;
int send(const QByteArray &data) override bool send(const QByteArray &data) override
{ {
consoleData = data; consoleData = data;
return data.length(); return data.length();

216
test/tst_console.cpp

@ -3,24 +3,31 @@
#include "TestDataSender.h" #include "TestDataSender.h"
#include "model/Console.h" #include "model/Console.h"
#include <QSignalSpy>
class ConsoleTest : public QObject class ConsoleTest : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
ConsoleTest(); ConsoleTest();
~ConsoleTest(); ~ConsoleTest();
//uncrustify off //uncrustify off
private slots: private slots:
//uncrustify on //uncrustify on
void pressDual_test_case(); void pressDual_test_case();
void releaseDual_test_case(); void releaseDual_test_case();
void pressQuad_test_case(); void sendDatatoDual_test_case();
void releaseQuad_test_case();
void pressQuad_test_case();
void releaseQuad_test_case();
void rotateJs1NoLed_test_case(); void rotateJs1NoLed_test_case();
void rotatFocusWithLed_test_case(); void rotatFocusWithLed_test_case();
void echoSignalTest();
}; };
/*************************************************************************************************/ /*************************************************************************************************/
@ -36,89 +43,120 @@ ConsoleTest::~ConsoleTest()
/*************************************************************************************************/ /*************************************************************************************************/
void ConsoleTest::pressDual_test_case() void ConsoleTest::pressDual_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.pressDual(); c.pressDual();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1D; arr[3] = 0x1D;
arr[4] = 0x01; arr[4] = 0x01;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
/*************************************************************************************************/ /*************************************************************************************************/
void ConsoleTest::releaseDual_test_case() void ConsoleTest::releaseDual_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.releaseDual(); c.releaseDual();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1D; arr[3] = 0x1D;
arr[4] = 0x00; arr[4] = 0x00;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::sendDatatoDual_test_case()
{
Console c;
auto t = new TestDataSender;
c.injectDataSender(t);
QSignalSpy spy(&c, SIGNAL(dualLedChanged(char)));
QByteArray arr;
char ledValue = 0x01;
arr.resize(8);
arr[0] = 0x01;
arr[1] = 0x01;
arr[2] = 0x03;
arr[3] = static_cast<char>(0x82);
arr[4] = ledValue;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
c.newData(arr);
auto result = spy.takeFirst()[0].value<QByteArray>();
QCOMPARE(result[0], ledValue);
} }
/*************************************************************************************************/ /*************************************************************************************************/
void ConsoleTest::pressQuad_test_case() void ConsoleTest::pressQuad_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.pressQuad(); c.pressQuad();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1C; arr[3] = 0x1C;
arr[4] = 0x01; arr[4] = 0x01;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
/*************************************************************************************************/ /*************************************************************************************************/
void ConsoleTest::releaseQuad_test_case() void ConsoleTest::releaseQuad_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.releaseQuad(); c.releaseQuad();
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
arr[0] = 0x00; arr[0] = 0x00;
arr[1] = 0x01; arr[1] = 0x01;
arr[2] = 0x04; arr[2] = 0x04;
arr[3] = 0x1C; arr[3] = 0x1C;
arr[4] = 0x00; arr[4] = 0x00;
arr[5] = 0x00; arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
/*************************************************************************************************/
void ConsoleTest::rotateJs1NoLed_test_case() void ConsoleTest::rotateJs1NoLed_test_case()
{ {
Console c; Console c;
@ -141,12 +179,13 @@ void ConsoleTest::rotateJs1NoLed_test_case()
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
/*************************************************************************************************/
void ConsoleTest::rotatFocusWithLed_test_case() void ConsoleTest::rotatFocusWithLed_test_case()
{ {
Console c; Console c;
auto t = new TestDataSender; auto t = new TestDataSender;
c.injectDataSender(t); c.injectDataSender(t);
c.rotateFocus(4000); c.rotateFocus(40000);
QByteArray arr; QByteArray arr;
arr.resize(8); arr.resize(8);
@ -154,14 +193,39 @@ void ConsoleTest::rotatFocusWithLed_test_case()
arr[1] = 0x02; arr[1] = 0x02;
arr[2] = 0x05; arr[2] = 0x05;
arr[3] = 0x51; arr[3] = 0x51;
arr[4] = static_cast<char>(4000 >> 8); arr[4] = static_cast<char>(40000 >> 8);
arr[5] = static_cast<char>(4000); arr[5] = static_cast<char>(40000);
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t->consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::echoSignalTest()
{
Console c;
auto t = new TestDataSender;
c.injectDataSender(t);
QByteArray arr;
arr.resize(8);
arr[0] = 0x01;
arr[1] = 0x02;
arr[2] = 0x06;
arr[3] = static_cast<char>(0xA4);
arr[4] = 0x00;
arr[5] = 0x00;
arr[6] = 0x00; arr[6] = 0x00;
arr[7] = 0x00; arr[7] = 0x00;
c.newData(arr);
QCOMPARE(t->consoleData, arr); QCOMPARE(t->consoleData, arr);
} }
/*************************************************************************************************/
QTEST_APPLESS_MAIN(ConsoleTest) QTEST_APPLESS_MAIN(ConsoleTest)
#include "tst_console.moc" #include "tst_console.moc"

Loading…
Cancel
Save