Created
May 18, 2016 21:29
-
-
Save s-light/91435db564f5f84316a69231f145897a to your computer and use it in GitHub Desktop.
ola test for segfault at wrapper.Setup()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ola_test.cpp | |
// based on example from | |
// http://docs.openlighting.org/ola/doc/latest/dmx_cpp_client_tutorial.html | |
// build for local: | |
// g++ -std=c++11 ola_test.cpp -o ola_test.out $(pkg-config --cflags --libs libola) | |
#include <ola/DmxBuffer.h> | |
#include <ola/Logging.h> | |
#include <ola/client/ClientWrapper.h> | |
#include <ola/io/SelectServer.h> | |
#include <unistd.h> | |
#include <string> | |
#include <iostream> | |
#include <fstream> | |
ola::client::OlaClientWrapper wrapper(false); | |
ola::client::OlaClient *client; | |
ola::DmxBuffer channels_out; | |
enum ola_state_t { | |
state_undefined, | |
state_standby, | |
state_waiting, | |
state_connected, | |
state_running, | |
}; | |
ola_state_t system_state = state_undefined; | |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// ola things | |
// Called when universe registration completes. | |
void RegisterComplete(const ola::client::Result& result) { | |
if (!result.Success()) { | |
OLA_WARN << "Failed to register universe: " << result.Error(); | |
} | |
} | |
// Called when new DMX data arrives. | |
void dmx_receive_frame(const ola::client::DMXMetadata &metadata, | |
const ola::DmxBuffer &data) { | |
std::cout << "Received " << data.Size() | |
<< " channels for universe " << metadata.universe | |
<< ", priority " << static_cast<int>(metadata.priority) | |
<< std::endl; | |
// map_channels(data); | |
} | |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// ola state helper | |
void ola_connection_closed(ola::io::SelectServer *ss) { | |
std::cerr << "Connection to olad was closed" << std::endl; | |
ss->Terminate(); | |
system_state = state_waiting; | |
} | |
void ola_waiting_for_connection() { | |
try { | |
std::cout << "try wrapper.Setup() " << std::endl; | |
bool available = wrapper.Setup(); | |
std::cout << "available: " << available << std::endl; | |
if (available) { | |
client = wrapper.GetClient(); | |
system_state = state_connected; | |
} | |
} | |
// catch (const std::exception &exc) { | |
// // catch anything thrown that derives from std::exception | |
// std::cerr << exc.what(); | |
// std::cout << "error!!: " << exc.what() << std::endl; | |
// } | |
catch (...) { | |
// catch all | |
// sleep microseconds | |
// usleep(500000); | |
std::cout << "error!!: " << std::endl; | |
} | |
} | |
void ola_setup() { | |
client->SetCloseHandler( | |
ola::NewSingleCallback( | |
ola_connection_closed, | |
wrapper.GetSelectServer() )); | |
// Set the callback and register our interest in this universe | |
client->SetDMXCallback(ola::NewCallback(&dmx_receive_frame)); | |
client->RegisterUniverse( | |
1, | |
ola::client::REGISTER, | |
ola::NewSingleCallback(&RegisterComplete)); | |
std::cout << "read incoming channels." << std::endl; | |
system_state = state_running; | |
} | |
void ola_run() { | |
wrapper.GetSelectServer()->Run(); | |
system_state = state_waiting; | |
} | |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// main | |
int main() { | |
ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR); | |
// ola_statemaschine() | |
std::cout << "ola_waiting_for_connection()" << std::endl; | |
ola_waiting_for_connection(); | |
std::cout << "ola_setup()" << std::endl; | |
ola_setup(); | |
std::cout << "ola_run()" << std::endl; | |
ola_run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment