Started work on database handling.

This commit is contained in:
2024-04-08 03:10:24 -07:00
parent 405acb026f
commit beba947c69
22 changed files with 918 additions and 44 deletions

97
src/io/UsbBase.cpp Normal file
View File

@@ -0,0 +1,97 @@
#include "ehs/io/UsbBase.h"
#include "ehs/Util.h"
#include <unistd.h>
namespace ehs
{
UsbBase::UsbBase()
: bus(0), address(0)
{
}
UsbBase::UsbBase(const UInt_32 bus, const UInt_32 address)
: bus(bus), address(address)
{
}
UsbBase::UsbBase(UsbBase&& usb) noexcept
: bus(usb.bus), address(usb.address)
{
usb.bus = 0;
usb.address = 0;
}
UsbBase::UsbBase(const UsbBase& usb)
: bus(usb.bus), address(usb.address)
{
}
UsbBase& UsbBase::operator=(UsbBase&& usb) noexcept
{
if (this == &usb)
return *this;
bus = usb.bus;
address = usb.address;
usb.bus = 0;
usb.address = 0;
return *this;
}
UsbBase& UsbBase::operator=(const UsbBase& usb)
{
if (this == &usb)
return *this;
bus = usb.bus;
address = usb.address;
return *this;
}
void UsbBase::BulkSend(const Byte* const data, const Size size)
{
Size out = 0;
while (out < size)
out = Send(&data[out], size);
}
void UsbBase::BulkReceive(Byte** data, Size* size)
{
Byte *result = nullptr;
Size total = 0;
Size in;
do
{
Byte *resize = new Byte[(total + *size) / *size];
Util::Copy(resize, result, total);
in = Receive(&resize[total], *size);
total += in;
delete[] result;
result = resize;
}
while (in);
*size = total;
}
UInt_32 UsbBase::GetBus() const
{
return bus;
}
UInt_32 UsbBase::GetAddress() const
{
return address;
}
bool UsbBase::IsValid() const
{
return bus && address;
}
}

106
src/io/Usb_LNX.cpp Normal file
View File

@@ -0,0 +1,106 @@
#include "ehs/io/Usb_LNX.h"
#include <fcntl.h>
#include <unistd.h>
namespace ehs
{
Usb::~Usb()
{
}
Usb::Usb()
: hdl(-1)
{
}
Usb::Usb(const UInt_32 bus, const UInt_32 address)
: UsbBase(bus, address), hdl(-1)
{
Initialize();
}
Usb::Usb(Usb&& usb) noexcept
: UsbBase((UsbBase&&)usb), hdl(usb.hdl)
{
usb.hdl = -1;
}
Usb::Usb(const Usb& usb)
: UsbBase(usb), hdl(-1)
{
Initialize();
}
Usb& Usb::operator=(Usb&& usb) noexcept
{
if (this == &usb)
return *this;
UsbBase::operator=((UsbBase&&)usb);
hdl = usb.hdl;
usb.hdl = -1;
return *this;
}
Usb& Usb::operator=(const Usb& usb)
{
if (this == &usb)
return *this;
UsbBase::operator=(usb);
hdl = -1;
Initialize();
return *this;
}
void Usb::Initialize()
{
if (!IsValid())
{
EHS_LOG_INT("Error", 0, "Cannot initialize with an invalid object.");
return;
}
if (IsInitialized())
{
EHS_LOG_INT("Warning", 1, "Object is already initialized.");
return;
}
hdl = open("/dev/bus/usb/" + Str_8::FromNum(GetBus()) + "/" + Str_8::FromNum(GetAddress()), O_RDWR);
if (hdl == -1)
EHS_LOG_INT("Error", 2, "Failed to connect to USB device.");
}
void Usb::Release()
{
if (!IsValid())
{
EHS_LOG_INT("Error", 0, "Cannot release with an invalid object.");
return;
}
if (!IsInitialized())
{
EHS_LOG_INT("Warning", 1, "Object is already released.");
return;
}
close(hdl);
hdl = -1;
}
bool Usb::IsInitialized() const
{
return hdl != -1;
}
}

View File

@@ -275,6 +275,7 @@ namespace ehs
meshes[i].SetIndices(data.ReadArray<UInt_32, UInt_64>());
/*
Bone& skeleton = mdl->GetSkeleton();
UInt_8 boneCount = data.Read<UInt_8>();
for (UInt_8 b = 0; b < boneCount; ++b)
@@ -328,6 +329,7 @@ namespace ehs
}
}
}
*/
}
return true;