mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Add device sharing support
This commit is contained in:
@@ -24,4 +24,10 @@ endif()
|
||||
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/libicsneo ${CMAKE_CURRENT_BINARY_DIR}/third-party/libicsneo)
|
||||
|
||||
add_executable(libicsneocpp-simple-example src/SimpleExample.cpp)
|
||||
target_link_libraries(libicsneocpp-simple-example icsneocpp)
|
||||
target_link_libraries(libicsneocpp-simple-example icsneocpp)
|
||||
add_executable(libicsneocpp-simple-rx src/SimpleRx.cpp)
|
||||
add_executable(libicsneocpp-simple-tx src/SimpleTx.cpp)
|
||||
target_link_libraries(libicsneocpp-simple-rx icsneocpp)
|
||||
target_link_libraries(libicsneocpp-simple-tx icsneocpp)
|
||||
add_executable(libicsneocpp-simple-events src/SimpleEvents.cpp)
|
||||
target_link_libraries(libicsneocpp-simple-events icsneocpp)
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
if(args.size() != 2) {
|
||||
std::cerr << "usage: " << args.front() << " <device serial>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const auto& deviceSerial = args[1];
|
||||
|
||||
const auto findDevice = [](const auto& serial) -> std::shared_ptr<icsneo::Device> {
|
||||
for(const auto& dev : icsneo::FindAllDevices()) {
|
||||
if(serial == dev->getSerial())
|
||||
return dev;
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
std::cout << "Finding device... " << std::flush;
|
||||
const auto device = findDevice(deviceSerial);
|
||||
if(!device) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Opening device... " << std::flush;
|
||||
if(!device->open()) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Going online... " << std::flush;
|
||||
if(!device->goOnline()) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Getting events from server..." << std::endl;
|
||||
icsneo::EventFilter ef = {};
|
||||
auto events = icsneo::GetEvents(ef, 0UL);
|
||||
if(events.size() == 0)
|
||||
std::cout << "Event return is empty :(" << std::endl;
|
||||
|
||||
for(auto& event: events)
|
||||
std::cout << event.describe() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -9,6 +9,12 @@ int main() {
|
||||
// Print version
|
||||
std::cout << "Running libicsneo " << icsneo::GetVersion() << std::endl;
|
||||
|
||||
// Register an event callback so we can see any errors that come in
|
||||
icsneo::EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
icsneo::EventManager::GetInstance().addEventCallback(icsneo::EventCallback([](std::shared_ptr<icsneo::APIEvent> evt) {
|
||||
std::cerr << evt->describe() << std::endl;
|
||||
}));
|
||||
|
||||
std::cout<< "Supported devices:" << std::endl;
|
||||
for(auto& dev : icsneo::GetSupportedDevices())
|
||||
std::cout << '\t' << dev.getGenericProductName() << std::endl;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
if(args.size() != 2) {
|
||||
std::cerr << "usage: " << args.front() << " <device serial>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const auto& deviceSerial = args[1];
|
||||
|
||||
const auto findDevice = [](const auto& serial) -> std::shared_ptr<icsneo::Device> {
|
||||
for(const auto& dev : icsneo::FindAllDevices()) {
|
||||
if(serial == dev->getSerial())
|
||||
return dev;
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
std::cout << "Finding device... " << std::flush;
|
||||
const auto device = findDevice(deviceSerial);
|
||||
if(!device) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Opening device... " << std::flush;
|
||||
if(!device->open()) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Going online... " << std::flush;
|
||||
if(!device->goOnline()) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Streaming CAN messages in, enter anything to stop..." << std::endl;
|
||||
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> message) {
|
||||
if(message->type == icsneo::Message::Type::Frame) {
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
|
||||
if(frame->network.getType() == icsneo::Network::Type::CAN) {
|
||||
auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message);
|
||||
std::cout << '\r';
|
||||
for(auto& databyte : canMessage->data)
|
||||
std::cout << std::hex << std::setw(2) << (uint32_t)databyte << ' ';
|
||||
std::cout << std::flush;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
std::cin.ignore();
|
||||
|
||||
device->removeMessageCallback(handler);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
if (args.size() != 2) {
|
||||
std::cerr << "usage: " << args.front() << " <device serial>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const auto& deviceSerial = args[1];
|
||||
|
||||
const auto findDevice = [](const auto& serial) -> std::shared_ptr<icsneo::Device> {
|
||||
for (const auto& dev : icsneo::FindAllDevices()) {
|
||||
if (serial == dev->getSerial())
|
||||
return dev;
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
std::cout << "Finding device... " << std::flush;
|
||||
const auto device = findDevice(deviceSerial);
|
||||
if (!device) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Opening device... " << std::flush;
|
||||
if (!device->open()) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "Going online... " << std::flush;
|
||||
if (!device->goOnline()) {
|
||||
std::cerr << "FAIL" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::atomic<bool> stop = false;
|
||||
|
||||
std::thread thread([&] {
|
||||
std::cin.ignore();
|
||||
std::cout << "Stopping..." << std::endl;
|
||||
stop = true;
|
||||
});
|
||||
|
||||
auto txMessage = std::make_shared<icsneo::CANMessage>();
|
||||
txMessage->network = icsneo::Network::NetID::HSCAN;
|
||||
txMessage->arbid = 0x1C5001C5;
|
||||
txMessage->data.insert(txMessage->data.begin(), sizeof(size_t), 0);
|
||||
txMessage->isExtended = true;
|
||||
txMessage->isCANFD = true;
|
||||
|
||||
std::cout << "Streaming CAN messages out, enter anything to stop..." << std::endl;
|
||||
|
||||
size_t& value = *(size_t*)txMessage->data.data();
|
||||
|
||||
while (!stop) {
|
||||
device->transmit(txMessage);
|
||||
value++;
|
||||
}
|
||||
|
||||
thread.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user