c++ - Websocket++ websocket server class member function not recognised from ISR -
i'm using odroid (raspi-like arm board) run small spi-based radio chip sends data to, among other things, websocket. applied using websocket++: https://github.com/zaphoyd/websocketpp. i've bastardised 1 of simple examples, sends server message clients. program has count_server class handles websocket, has isr handled wiringpi calls nested functions handle different operations.
the issue i've got in order send message, sending function must in count_server class far can tell, access client addresses etc. class method not accesible inside isr, handles data received radio, when try send websocket message inside isr error:
error: 'websocketserver' not declared in scope websocketserver.sendlivedata(); the websocketserver instance of class count_server, instantiated in main(). why can't isr 'see' websocketserver class.
one workaround poll inside count() function, blocks cpu , i'd rather leave ready perform other tasks.]
here's simplest example produce. requires websocket++ , wiringpi attachinterrupt.
#include <cstdlib> #include <unistd.h> #include <iostream> #include <sstream> #include <string> #include <rf24/rf24.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <time.h> //websocket++ includes #include <mutex> #include <set> #include <thread> #include <websocketpp/config/asio_no_tls.hpp> #include <websocketpp/server.hpp> //*/ //websocket++ declarations typedef websocketpp::server<websocketpp::config::asio> server; using websocketpp::connection_hdl; using websocketpp::lib::placeholders::_1; class count_server { public: count_server() : m_count(0) { m_server.init_asio(); m_server.set_open_handler(bind(&count_server::on_open,this,_1)); m_server.set_close_handler(bind(&count_server::on_close,this,_1)); } void on_open(connection_hdl hdl) { std::lock_guard<std::mutex> lock(m_mutex); m_connections.insert(hdl); } void on_close(connection_hdl hdl) { std::lock_guard<std::mutex> lock(m_mutex); m_connections.erase(hdl); } void sendlivedata(){ std::stringstream ss; ss << "foobar"; (auto : m_connections) { m_server.send(it,ss.str(),websocketpp::frame::opcode::text); } } void count() {//simple loop thread, not needed, in working example lef t time being while (1) { sleep(1000); } } void run(uint16_t port) { m_server.listen(port); m_server.start_accept(); m_server.run(); } private: typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list; int m_count; server m_server; con_list m_connections; std::mutex m_mutex; }; /****************** raspberry pi ***********************/ int interruptpin = 6; // gpio pin interrupts - interrupts have been edited handled //by wiringpi, #6 used, not #103, check rf24/utility/spidev/interrupt.c info int i=0; /**************************************************************/ void addlivedata(){ //live data buffer handler + calls sending function when buffer hits max websocketserver.sendlivedata(); } void inthandler(){//when radio chip irq goes low, happened, handles addlivedata();//recvd = 2;//flag data live data } int main(){ attachinterrupt(interruptpin, int_edge_falling, &inthandler); //attach interrupt bcm p in 23 count_server websocketserver; std::thread t(std::bind(&count_server::count,&websocketserver)); websocketserver.sendlivedata(); websocketserver.run(8080); } '
Comments
Post a Comment