96 lines
1.7 KiB
C++
96 lines
1.7 KiB
C++
#include "ehs/io/UsbBase.h"
|
|
#include "ehs/Util.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;
|
|
}
|
|
}
|