This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Emulate a Hexabus device using libhexabus
paalsteek edited this page May 21, 2014
·
1 revision
Libhexabus provides you with an abstraction class to make the emulation of hexabus devices on a linux machine simple.
A hello world example could look like this:
#include <iostream>
#include <boost/asio/io_service.hpp>
#include <libhexabus/device.hpp>
boost::asio::io_service io_service;
std::string myDeviceName = "example";
std::string readDeviceName() {
return myDeviceName;
}
void writeDeviceName(const std::string& name) {
myDeviceName = name;
}
std::string helloWorld() {
return "Hello, World!";
}
int main() {
hexabus::Device device(io_service, "eth1", "bbbb::1");
device.onReadName(&readDeviceName);
device.onWriteName(&writeDeviceName);
hexabus::EndpointRegistry ep_registry;
hexabus::EndpointRegistry::const_iterator ep_it;
ep_it = ep_registry.find(90);
hexabus::TypedEndpointFunctions<std::string>::Ptr helloWorldEP = ep_it != ep_registry.end()
? hexabus::TypedEndpointFunctions<std::string>::fromEndpointDescriptor(ep_it->second)
: hexabus::TypedEndpointFunctions<std::string>::Ptr(new hexabus::TypedEndpointFunctions<std::string>(90, "Hello World!"));
helloWorldEP->onRead(&helloWorld);
device.addEndpoint(helloWorldEP);
io_service.run();
}