Implement logic core facade
This commit is contained in:
@@ -1,5 +1,67 @@
|
||||
#include "LOGIC/Lgc_Core.h"
|
||||
|
||||
#include "COM/Com_ProtoCodec.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void Lgc_Func_ApplyHelloRsp(
|
||||
Lgc_Core* p_Core,
|
||||
const Packet_HelloRsp& HelloRsp)
|
||||
{
|
||||
p_Core->State.IsConnected = true;
|
||||
p_Core->State.IsHandshakeDone = true;
|
||||
p_Core->State.ProtocolVersion = HelloRsp.ProtocolVersion;
|
||||
p_Core->State.VendorId = HelloRsp.VendorId;
|
||||
p_Core->State.ProductId = HelloRsp.ProductId;
|
||||
p_Core->State.FirmwareMajor = HelloRsp.FirmwareMajor;
|
||||
p_Core->State.FirmwareMinor = HelloRsp.FirmwareMinor;
|
||||
p_Core->State.CapabilityFlags = HelloRsp.CapabilityFlags;
|
||||
p_Core->State.ActiveTransport = Lgc_TransportType::Cdc;
|
||||
p_Core->State.ActiveEndpointName = p_Core->Session.CdcPort.PortName;
|
||||
p_Core->State.ConnectionText = QStringLiteral("CDC connected: %1")
|
||||
.arg(p_Core->Session.CdcPort.PortName);
|
||||
p_Core->State.LastActionText = QStringLiteral("Handshake completed.");
|
||||
}
|
||||
|
||||
void Lgc_Func_UpdateActionText(Lgc_Core* p_Core, const Packet& PacketData)
|
||||
{
|
||||
switch (PacketData.type)
|
||||
{
|
||||
case Com_Type_HelloRsp:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received HelloRsp.");
|
||||
break;
|
||||
case Com_Type_Bitmap:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received Bitmap.");
|
||||
break;
|
||||
case Com_Type_FunctionKeyEvent:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received FunctionKeyEvent.");
|
||||
break;
|
||||
case Com_Type_LedState:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received LedState.");
|
||||
break;
|
||||
case Com_Type_TimeSync:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received TimeSync.");
|
||||
break;
|
||||
case Com_Type_ThemeRgb:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received ThemeRgb.");
|
||||
break;
|
||||
case Com_Type_Ack:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received Ack.");
|
||||
break;
|
||||
case Com_Type_Error:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received Error.");
|
||||
break;
|
||||
default:
|
||||
p_Core->State.LastActionText = QStringLiteral("Received packet type 0x%1.")
|
||||
.arg(static_cast<quint8>(PacketData.type), 2, 16, QLatin1Char('0'))
|
||||
.toUpper();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Lgc_Core_Init(Lgc_Core* p_Core)
|
||||
{
|
||||
if (p_Core == nullptr)
|
||||
@@ -11,6 +73,45 @@ void Lgc_Core_Init(Lgc_Core* p_Core)
|
||||
Lgc_Session_Init(&p_Core->Session);
|
||||
}
|
||||
|
||||
bool Lgc_Core_Start(Lgc_Core* p_Core)
|
||||
{
|
||||
if (p_Core == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Dri_Cdc_Struct_OpenConfig Config;
|
||||
Packet_HelloRsp HelloRsp;
|
||||
if (Lgc_Session_TryStartCdc(&p_Core->Session, Config, &HelloRsp))
|
||||
{
|
||||
Lgc_Func_ApplyHelloRsp(p_Core, HelloRsp);
|
||||
return true;
|
||||
}
|
||||
|
||||
p_Core->State.IsConnected = false;
|
||||
p_Core->State.IsHandshakeDone = false;
|
||||
p_Core->State.ConnectionText = QStringLiteral("No device found.");
|
||||
p_Core->State.LastActionText = QStringLiteral("Handshake failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Lgc_Core_Poll(Lgc_Core* p_Core)
|
||||
{
|
||||
if (p_Core == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Packet PacketData;
|
||||
if (!Lgc_Session_ReadNextPacket(&p_Core->Session, &PacketData))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Lgc_Func_UpdateActionText(p_Core, PacketData);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Lgc_Core_Close(Lgc_Core* p_Core)
|
||||
{
|
||||
if (p_Core == nullptr)
|
||||
@@ -21,3 +122,8 @@ void Lgc_Core_Close(Lgc_Core* p_Core)
|
||||
Lgc_Session_Close(&p_Core->Session);
|
||||
p_Core->State = Lgc_State();
|
||||
}
|
||||
|
||||
const Lgc_State& Lgc_Core_GetState(const Lgc_Core* p_Core)
|
||||
{
|
||||
return p_Core->State;
|
||||
}
|
||||
|
||||
@@ -10,4 +10,7 @@ struct Lgc_Core
|
||||
};
|
||||
|
||||
void Lgc_Core_Init(Lgc_Core* p_Core);
|
||||
bool Lgc_Core_Start(Lgc_Core* p_Core);
|
||||
bool Lgc_Core_Poll(Lgc_Core* p_Core);
|
||||
void Lgc_Core_Close(Lgc_Core* p_Core);
|
||||
const Lgc_State& Lgc_Core_GetState(const Lgc_Core* p_Core);
|
||||
|
||||
Reference in New Issue
Block a user