diff --git a/Source/SkyPortal/Private/SkyPortalSubsystem.cpp b/Source/SkyPortal/Private/SkyPortalSubsystem.cpp index 0c57ea6..9d9ae34 100644 --- a/Source/SkyPortal/Private/SkyPortalSubsystem.cpp +++ b/Source/SkyPortal/Private/SkyPortalSubsystem.cpp @@ -13,7 +13,7 @@ void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection) Super::Initialize(Collection); // Start the status checker thread - StatusChecker = new FPortalStatusChecker(this, 0.01f); // Check every 10 milliseconds + StatusChecker = new FPortalStatusChecker(this, RunnerInterval); StatusCheckerThread = FRunnableThread::Create(StatusChecker, TEXT("PortalStatusCheckerThread"), 0, TPri_AboveNormal); UE_LOG(LogTemp, Log, TEXT("SkyPortalSubsystem Initialized")); @@ -69,18 +69,18 @@ void USkyPortalSubsystem::PortalReady() memset(command.data, 0, write_buf_size); //maybe not needed here command.data[1] = 'R'; - uint8* output; + unsigned char* output; do { PortalHandle->Write(&command); output = PortalHandle->Read(); } while (output[0] != 'R'); unsigned char _PortalId[2] = { output[1],output[2] }; - int32 BE_PortalId = (_PortalId[0] << 8) | _PortalId[1]; // Big-endian format + uint16_t BE_PortalId = (_PortalId[0] << 8) | _PortalId[1]; // Big-endian format uint32 BEU_PortalId = (_PortalId[0] << 8) | _PortalId[1]; // Big-endian format unsigned - int32 LE_PortalId = (_PortalId[1] << 8) | _PortalId[0]; //little endian - uint32 LEU_PortalId = (_PortalId[1] << 8) | _PortalId[0]; //little endian unsigned - PortalId = LE_PortalId; //Need a conversion as uint16 is not supported in BP + uint16_t LE_PortalId = (_PortalId[1] << 8) | _PortalId[0]; //little endian + //uint32 LEU_PortalId = (_PortalId[1] << 8) | _PortalId[0]; //little endian unsigned + PortalId = BEU_PortalId; //Need a conversion as uint16 is not supported in BP } @@ -101,6 +101,25 @@ FPortalStatusData USkyPortalSubsystem::PortalStatus() { return ParsePortalStatus(output); } +SKYPORTAL_API bool USkyPortalSubsystem::RestartRunner() +{ + if (StatusChecker) + { + StatusChecker->Stop(); + StatusCheckerThread->WaitForCompletion(); + + delete StatusCheckerThread; + delete StatusChecker; + StatusChecker = nullptr; + StatusCheckerThread = nullptr; + } + + StatusChecker = new FPortalStatusChecker(this, RunnerInterval); // Check every 10 milliseconds + StatusCheckerThread = FRunnableThread::Create(StatusChecker, TEXT("PortalStatusCheckerThread"), 0, TPri_AboveNormal); + + UE_LOG(LogTemp, Log, TEXT("SkyPortalSubsystem Initialized")); +} + diff --git a/Source/SkyPortal/Public/SkyPortalSubsystem.h b/Source/SkyPortal/Public/SkyPortalSubsystem.h index 5b98595..ba065a1 100644 --- a/Source/SkyPortal/Public/SkyPortalSubsystem.h +++ b/Source/SkyPortal/Public/SkyPortalSubsystem.h @@ -78,7 +78,9 @@ public: UFUNCTION(BlueprintCallable, CallInEditor, meta = (Category = "SkyPortal|Commands")) SKYPORTAL_API FPortalStatusData PortalStatus(); - + /**/ + UFUNCTION(BlueprintCallable, CallInEditor, meta = (Category = "SkyPortal")) + SKYPORTAL_API bool RestartRunner(); /* Change the color of the portal, can separate side and even trap ligth @@ -102,6 +104,9 @@ public: UPROPERTY(BlueprintReadOnly) FPortalStatusData StatusData; + UPROPERTY(BlueprintReadWrite) + float RunnerInterval = 0.01f; //In seconds + /* Different for each portal model. * * SSA :