Files
salmanoff/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp
T

66 lines
1.7 KiB
C++

#include <cstring>
#include <sys/socket.h>
#include <livoxProto1/device.h>
#include "ioUringAssemblyEngine.h"
namespace smo {
namespace stim_buff {
struct DummyLivoxEthHeader
{
enum : uint32_t {
INVALID_ERR_CODE = 0xFFFFFFFFu
};
enum : uint8_t {
INVALID_TIMESTAMP_TYPE = 0xFFu,
INVALID_DATA_TYPE = 0xFFu
};
uint8_t version, slot, id, rsvd;
uint32_t err_code;
uint8_t timestamp_type, data_type;
uint8_t timestamp[8];
};
void IoUringAssemblyEngine::cancelIncompleteAndFillDummies()
{
if (!desc)
{ return; }
for (size_t i = 0; i < desc->numSlots; ++i)
{
// In the real path, decide from CQE accounting whether slot i completed.
// Here, demonstrate dummy header insertion API.
auto* hdr = reinterpret_cast<DummyLivoxEthHeader*>(desc->slots[i].vaddr);
hdr->err_code = DummyLivoxEthHeader::INVALID_ERR_CODE;
hdr->timestamp_type = DummyLivoxEthHeader::INVALID_TIMESTAMP_TYPE;
hdr->data_type = DummyLivoxEthHeader::INVALID_DATA_TYPE;
}
}
size_t IoUringAssemblyEngine::computePointsPerDgram(int returnMode)
{
/*
* Map modes to points per datagram based on Livox docs
* 1: first, 2: strongest -> 96 samples => 96 points
* 3: dual -> 48 samples * 2 points = 96
* 4: triple -> 30 samples * 3 points = 90
*/
switch (returnMode)
{
case static_cast<int>(livoxProto1::Device::ReturnMode::SingleFirst):
case static_cast<int>(livoxProto1::Device::ReturnMode::SingleStrongest):
case static_cast<int>(livoxProto1::Device::ReturnMode::Dual):
return 96u;
case static_cast<int>(livoxProto1::Device::ReturnMode::Triple):
return 90u;
default:
throw std::runtime_error(
std::string(__func__) + ": Unknown returnMode "
+ std::to_string(returnMode));
}
}
} // namespace stim_buff
} // namespace smo