Livox: Add new loadable libs for Protocolv1 and gen1 lidars
We've added two new libs: * commonLibs/livoxProto1 * senseApis/livoxGen1 They currently get to the point of detecting my Livox Avia on the network over UDP. This was really easy to get done in one night using boost::asio and Cursor, honestly.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#include <user/senseApiDesc.h>
|
||||
#include "livoxProto1Protocol.h"
|
||||
#include "livoxProto1Core.h"
|
||||
|
||||
namespace livoxProto1 {
|
||||
|
||||
struct ProtoState
|
||||
{
|
||||
bool isInitialized = false;
|
||||
std::shared_ptr<smo::ComponentThread> componentThread;
|
||||
std::unique_ptr<DeviceManager> deviceManager;
|
||||
};
|
||||
|
||||
static ProtoState protoState =
|
||||
{
|
||||
.isInitialized = false,
|
||||
.componentThread = nullptr,
|
||||
.deviceManager = nullptr
|
||||
};
|
||||
|
||||
DeviceManager::DeviceManager()
|
||||
: broadcastListener(protoState.componentThread)
|
||||
{
|
||||
broadcastListener.setDeviceGoneAwayCb(deviceGoneAwayInd);
|
||||
}
|
||||
|
||||
void DeviceManager::deviceGoneAwayInd(const comms::DiscoveredDevice &device)
|
||||
{
|
||||
std::cout << "Device gone away: " << device.stringify() << std::endl;
|
||||
auto it = std::find_if(
|
||||
protoState.deviceManager->devices.begin(),
|
||||
protoState.deviceManager->devices.end(),
|
||||
[&device](const Device &d) {
|
||||
return d.discoveredDevice == device;
|
||||
}
|
||||
);
|
||||
|
||||
if (it != protoState.deviceManager->devices.end()) {
|
||||
protoState.deviceManager->devices.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void main(const std::shared_ptr<smo::ComponentThread> &componentThread)
|
||||
{
|
||||
if (protoState.isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
protoState.isInitialized = true;
|
||||
protoState.componentThread = componentThread;
|
||||
protoState.deviceManager = std::make_unique<DeviceManager>();
|
||||
protoState.deviceManager->broadcastListener.start();
|
||||
}
|
||||
|
||||
void exit(void)
|
||||
{
|
||||
if (!protoState.isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
protoState.deviceManager->broadcastListener.stop();
|
||||
protoState.deviceManager.reset();
|
||||
protoState.isInitialized = false;
|
||||
protoState.componentThread = nullptr;
|
||||
}
|
||||
|
||||
} // namespace livoxProto1
|
||||
Reference in New Issue
Block a user