SkyPortal-plugin/Source/SkyPortal/Public/SkyPortalIO.h

98 lines
2.4 KiB
C
Raw Normal View History

#pragma once
/*
* This is the bridge between hidapi and unreal and contains all the rawdata of the portal
*/
#include "CoreMinimal.h"
#include "hidapi.h"
2024-09-26 13:01:42 +00:00
#include "SkyPortalDefinitions.h"
2024-09-25 22:19:16 +00:00
#include "SkyPortalFigure.h"
#include "SkyPortalIO.generated.h"
2024-09-25 22:19:16 +00:00
#pragma region Definitions
DECLARE_LOG_CATEGORY_EXTERN(LogHIDApi, Log, All);
DECLARE_LOG_CATEGORY_EXTERN(LogSkyportalIO, Log, All);
2024-09-25 15:33:25 +00:00
constexpr auto write_buf_size = 0x21; //buffer size for all the write command on portal. Should always be 0x21 - 33
2024-09-24 22:17:52 +00:00
constexpr auto TIMEOUT = 30000; //milliseconds
/* Portal physicial device IDs */
const int VendorIds[4] = { 0x12ba, 0x54c, 0x1430, 0x1430 };
const int ProductIds[4] = { 0x150, 0x967, 0x1f17 };
2024-09-25 22:19:16 +00:00
#pragma endregion
FPortalStatusData ParsePortalStatus(const uint8* StatusResponse);
EPortalCommand GetPortalCommandFromChar(unsigned char Char);
/* Contain all the data that pass inside hidapi write + the number of bytes in case of successful write
2024-09-26 13:01:42 +00:00
*
2024-09-24 22:17:52 +00:00
* @param data all the block data, should be 0x21 sized
* @param BytesTransferred In case of successful write, print the number of byte transfered. Could be used for verifications
*/
USTRUCT()
struct FWriteBlock {
GENERATED_BODY()
2024-09-25 11:47:11 +00:00
unsigned char data[write_buf_size];
2024-09-24 22:17:52 +00:00
int BytesTransferred;
2024-09-25 11:47:11 +00:00
};
2024-09-24 22:17:52 +00:00
/* This class will contain and handle all the low-lewel functions
* Should be able to be called anywhere
*/
UCLASS()
class USkyPortalIO : public UObject
{
GENERATED_BODY()
public:
2024-09-25 15:33:25 +00:00
// Constructor
USkyPortalIO();
2024-09-24 22:17:52 +00:00
/* hidapi will write error message in here*/
UPROPERTY(BlueprintReadOnly)
FString HidError;
2024-09-24 22:17:52 +00:00
/*Portal ready to be listened or to receive commands*/
UPROPERTY(BlueprintReadOnly)
2024-09-25 15:33:25 +00:00
bool bPortalReady = false;
2024-09-24 22:17:52 +00:00
/* Connect to Portal - will write the PortalDevice var if success */
bool OpenPortalHandle();
2024-09-25 11:47:11 +00:00
/* Send block to portal. In windows, don't use the hidapi */
2024-09-24 22:17:52 +00:00
void Write(FWriteBlock* Block);
2024-09-25 11:47:11 +00:00
/* Send raw command to portal */
void WriteRaw(const TArray<uint8>* block);
2024-09-24 22:17:52 +00:00
/* Listen to portal
* @return The data sended by the portal device
*/
uint8* Read();
2024-09-26 15:52:10 +00:00
/*Trying to read a figure
* @return
*/
unsigned char* QueryBlock(uint8 characterIndex, uint8 block = 0x00);
2024-09-25 15:33:25 +00:00
2024-09-26 13:01:42 +00:00
FigureData ReadFigureBlocks(uint8 FigureIndex);
2024-09-25 15:33:25 +00:00
/* Close connection to Portal*/
2024-09-24 22:17:52 +00:00
void Close();
2024-09-25 22:19:16 +00:00
2024-09-24 22:17:52 +00:00
private:
2024-09-25 11:47:11 +00:00
/*TODO: Should not be here
bool IsFalsePositive() const;
*/
2024-09-24 22:17:52 +00:00
2024-09-25 15:33:25 +00:00
/* Portal device ref, useful for hidapi commands */
2024-09-24 22:17:52 +00:00
hid_device* PortalDevice;
};