Skip to content

Commit

Permalink
update sources to UE4 4.21
Browse files Browse the repository at this point in the history
add udp port selection to bp
add function to reset new data flag
add demo server app for trackir
  • Loading branch information
tsky1971 committed Dec 23, 2018
1 parent 542dc1b commit 478face
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 17 deletions.
Binary file added AppTrackIRServer2.7z
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions CG221Connector/Binaries/Win64/UE4Editor.modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"BuildId": "4541578",
"Modules":
{
"CG211Connector": "UE4Editor-CG211Connector.dll"
}
}
11 changes: 6 additions & 5 deletions CG221Connector/Source/CG211Connector/CG211Connector.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

public class CG211Connector : ModuleRules
{
public CG211Connector(TargetInfo Target)
public CG211Connector(ReadOnlyTargetRules Target) : base(Target)
{

PublicIncludePaths.AddRange(
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
"CG211Connector/Public"
"CG211Connector/Public",

// ... add public include paths required here ...
}
Expand Down Expand Up @@ -43,7 +44,7 @@ public CG211Connector(TargetInfo Target)
"ShaderCore",
"HeadMountedDisplay",
"Slate",
"SlateCore",
"SlateCore"
// ... add other public dependencies that you statically link with here ...
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

#include "CG211ConnectorPrivatePCH.h"
#include "CG221TrackIRComponent.h"

#include "oscpkt.hh"
#include "CG211ConnectorPrivatePCH.h"


FCriticalSection g_CriticalSectionTrackIR;
FTrackIR g_TrackIR;
Expand All @@ -40,6 +40,7 @@ UCG221TrackIRComponent::UCG221TrackIRComponent(const FObjectInitializer & Object
PrimaryComponentTick.bCanEverTick = true;
bWantsInitializeComponent = true;
bAutoActivate = true;
UdpPort = 2000;
SetComponentTickEnabled(true);
}

Expand All @@ -55,12 +56,12 @@ void UCG221TrackIRComponent::InitializeComponent()
{
Super::InitializeComponent();
UE_LOG(CG221ConnectorLog, Warning, TEXT("UCG221TrackIRComponent::InitializeComponent()"));
g_TrackIR.NewDataFlag = false;
bNewDataFlag = false;

if (m_pSocket != NULL) {
DestroySocket(m_pSocket);
}
m_pSocket = CreateUdpSocket(7000);
m_pSocket = CreateUdpSocket(UdpPort);

}

Expand All @@ -69,7 +70,7 @@ void UCG221TrackIRComponent::UninitializeComponent()
{
Super::UninitializeComponent();
UE_LOG(CG221ConnectorLog, Warning, TEXT("UCG221TrackIRComponent::UninitializeComponent()"));
g_TrackIR.NewDataFlag = false;
bNewDataFlag = false;

if (m_pSocket != NULL) {
DestroySocket(m_pSocket);
Expand All @@ -91,17 +92,16 @@ void UCG221TrackIRComponent::TickComponent(float DeltaTime, ELevelTick TickType,
//UE_LOG(CG221ConnectorLog, Warning, TEXT("UCG221TrackIRComponent::TickComponent()"));

ReceivePayloads(m_pSocket);

if (TrackIRData.NewDataFlag == false) {
#ifdef _DEBUG
if (bNewDataFlag == false) {
TrackIRData.NPX = 0.1f;
TrackIRData.NPY = 0.2f;
TrackIRData.NPZ = 0.3f;
TrackIRData.NPPitch = 1.0f;
TrackIRData.NPYaw = 2.0f;
TrackIRData.NPRoll = 3.0f;
}


#endif

}

Expand Down Expand Up @@ -184,8 +184,8 @@ bool UCG221TrackIRComponent::ReceivePayloads(FSocket *_pSocket)
float tempFloat;
while ((pr.isOk()) && (msg = pr.popMessage()) != 0) {
if (msg->match("/TRACKIR").popStr(tempStr).isOkNoMoreArgs()) {
TrackIRData.NewDataFlag = true;

bNewDataFlag = true;
TrackIRData.TimeStamp = FDateTime::Now();
//UE_LOG(CG221ConnectorLog, Warning, TEXT("search TrackIR found = %s"), UTF8_TO_TCHAR(tempStr.c_str()));
}
if (msg->match("/NPX").popFloat(tempFloat).isOkNoMoreArgs()) {
Expand Down Expand Up @@ -218,4 +218,10 @@ bool UCG221TrackIRComponent::ReceivePayloads(FSocket *_pSocket)
} // if

return result;
}
}

bool UCG221TrackIRComponent::ResetNewDataFlag()
{
bNewDataFlag = false;
return bNewDataFlag;
}
112 changes: 112 additions & 0 deletions CG221Connector/Source/CG211Connector/Public/CG221TrackIRComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
Copyright (c) 2015, tsky
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

#pragma once

#include "Sockets.h"
#include "SocketSubsystem.h"
#include "Networking.h"
#include "SharedPointer.h"
#include "Components/ActorComponent.h"
#include "Runtime/Core/Public/Misc/DateTime.h"

#include "CG221TrackIRComponent.generated.h"

USTRUCT(BlueprintType)
struct FTrackIR
{
GENERATED_USTRUCT_BODY()

// Pos X
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
float NPX;
// Pos Y
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
float NPY;
// Pos Z
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
float NPZ;

// Pitch Head
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
float NPPitch;
// Yaw Head
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
float NPYaw;
// Roll Head
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
float NPRoll;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
FDateTime TimeStamp;
};


extern FCriticalSection g_CriticalSectionTrackIR;


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class /*CG221TRACKIRCOMPONENT_API*/ UCG221TrackIRComponent : public UActorComponent
{
GENERATED_BODY()

public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
FTrackIR TrackIRData;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
bool bNewDataFlag;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "TrackIR")
int UdpPort;

FSocket *m_pSocket;

public:
UCG221TrackIRComponent(const FObjectInitializer & ObjectInitializer);

virtual void OnRegister() override;

// Called when the game starts
virtual void InitializeComponent() override;

// Ends gameplay for this component.
virtual void UninitializeComponent() override;

// Called when the game starts or when spawned
virtual void BeginPlay() override;

// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

FSocket * CreateUdpSocket(uint32 port);
bool DestroySocket(FSocket *_pSocket);
bool ReceivePayloads(FSocket *_pSocket);

UFUNCTION(BluePrintCallable, Category = "TrackIR")
bool ResetNewDataFlag();
};

0 comments on commit 478face

Please sign in to comment.