Commit 4fbd2426 authored by Your Name's avatar Your Name
Browse files

.

parent 52bfa2dd
LSLBASE=../labstreaminglayer/build/install
CPPFLAGS+=-Wall -Wno-sign-compare -I$(LSLBASE)/include
LDFLAGS+=-L$(LSLBASE)/lib -llsl32 -lboost_system -lpthread
LDFLAGS+=-lpigpio
LDFLAGS+=-L$(LSLBASE)/lib
CXX=g++
CC=gcc
LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
LDLIBS+=-lzmq -lboost_program_options -lpigpio -llsl32
#LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
all: zmq_trigger playtone msgqueue_pubsub zmq_trigger_subscriber playsound
all: zmq_trigger playtone msgqueue_pubsub zmq_trigger_subscriber playsound lsldertc hwserver hwserver2 hwserver3
lsldertc: lsldertc.c
hwserver: hwserver.c
hwserver2: hwserver2.c
hwserver3: hwserver3.cc
pcm_min playsound: LDLIBS+=-lm -lasound
playsound: playsound.c
pcm_min: pcm_min.c
......
//
// Hello World server in C++
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <zmq.hpp>
#include <string>
#include <iostream>
#ifndef _WIN32
#include <unistd.h>
#else
#include <windows.h>
#define sleep(n) Sleep(n)
#endif
int main () {
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REP);
socket.bind ("tcp://*:5555");
zmq::socket_t ssub(context, ZMQ_SUB);
ssub.connect("tcp://lsldert00.local:5557");
ssub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv (&request);
std::cout << "Received Hello" << std::endl;
// Do some 'work'
// Send reply back to client
zmq::message_t reply (5);
memcpy (reply.data (), "World", 5);
socket.send (reply);
//sleep(1);
}
return 0;
}
......@@ -40,6 +40,7 @@ volatile int run=1 ;
void stop(int signum)
{
printf("\nSignal %d caught. Stopping. Please wait...\n", signum);
run = 0;
}
......@@ -272,66 +273,72 @@ int zmq_recv_multi(zmq::socket_t &socket, zmq::message_t parts[], int nmax)
int64_t more;
size_t more_size = sizeof more;
int n = 0;
do {
if (n < nmax) {
socket.recv(&parts[n]);
if (verbose)
cout << "recv part " << n << endl;
n++;
}
else {
zmq::message_t discard;
socket.recv(&discard);
if (verbose)
cout << "recv part " << n << " (discarded)." << endl;
}
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
} while (more);
try {
do {
if (n < nmax) {
socket.recv(&parts[n]);
if (verbose)
cout << "recv part " << n << endl;
n++;
}
else {
zmq::message_t discard;
socket.recv(&discard);
if (verbose)
cout << "recv part " << n << " (discarded)." << endl;
}
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
} while (more);
}
catch (std::exception& error) {
cout << "zmq_rev_multi while receiving frame " << n << ": " << error.what() << endl;
}
return n;
}
int main(int argc, const char* argv[])
{
parse_options(argc, argv);
if (rtpriority(sched_priority) < 0) {
perror("rtpriority");
return 1;
}
if(initialize_gpio() < 0)
{
return 1;
}
// Prepare our context and socket
zmq::context_t context(1);
zmq::socket_t srep(context, ZMQ_REP);
srep.bind("tcp://*:5555");
zmq::socket_t ssub(context, ZMQ_SUB);
ssub.connect("tcp://lsldert00.local:5557");
ssub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
zmq::pollitem_t items [] = {
{ static_cast<void*>(srep), 0, ZMQ_POLLIN, 0 },
{ static_cast<void*>(ssub), 0, ZMQ_POLLIN, 0 }
};
// make a new stream_info and open an outlet with it
stream_info info(
info_name.c_str(),
info_type.c_str(),
1,
lsl::IRREGULAR_RATE,
lsl::cf_string,
info_sourceid.c_str()
);
outlet = new stream_outlet(info);
// try {
while (run)
try {
parse_options(argc, argv);
if (rtpriority(sched_priority) < 0) {
perror("rtpriority");
return 1;
}
if(initialize_gpio() < 0)
{
return 1;
}
// Prepare our context and socket
zmq::context_t context(1);
zmq::socket_t ssub(context, ZMQ_SUB);
ssub.connect("tcp://lsldert00.local:5557");
ssub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
zmq::socket_t srep(context, ZMQ_REP);
srep.bind("tcp://*:5555");
zmq::pollitem_t items [] = {
{ static_cast<void*>(srep), 0, ZMQ_POLLIN, 0 },
{ static_cast<void*>(ssub), 0, ZMQ_POLLIN, 0 }
};
// make a new stream_info and open an outlet with it
stream_info info(
info_name.c_str(),
info_type.c_str(),
1,
lsl::IRREGULAR_RATE,
lsl::cf_string,
info_sourceid.c_str()
);
outlet = new stream_outlet(info);
while (run)
{
const int maxmsg=3;
zmq::message_t msg[maxmsg];
zmq::message_t& request=msg[0];
......@@ -339,21 +346,11 @@ int main(int argc, const char* argv[])
if (verbose)
cout << "polling" << endl;
#if 0
srep.recv(&request);
nmsg=1;
const char* rep = "OK\0";
srep.send(rep, 3);
#else
zmq::poll(items, 2, -1);
if (verbose)
cout << "done" << endl;
while (true) {
zmq::poll(items, 2, 1);
if (items [0].revents & ZMQ_POLLIN) {
//nmsg=zmq_recv_multi(srep, msg, maxmsg);
nmsg=1;
srep.recv(&request);
nmsg=zmq_recv_multi(srep, msg, maxmsg);
const char* rep = "OK\0";
srep.send(rep, 3);
if (verbose)
......@@ -364,9 +361,15 @@ int main(int argc, const char* argv[])
nmsg=zmq_recv_multi(ssub, msg, maxmsg);
//ssub.recv(&request);
}
else
cout << "zmq::poll: unexpected event" << endl;
#endif
else {
//cout << "zmq::poll: unexpected event" << endl;
continue;
}
if (verbose)
cout << "done" << endl;
break;
}
std::string str((char*)request.data());
if (verbose) {
......@@ -434,14 +437,13 @@ int main(int argc, const char* argv[])
}
}
// }
// catch (boost::system::system_error &e)
// {
// error_code ec = e.code();
// std::cerr << ec.value() << '\n';
// std::cerr << ec.category().name() << '\n';
// }
}
catch (zmq::error_t& error) {
cout << "error: " << error.what() << endl;
}
catch (std::exception& error) {
cout << "error: " << error.what() << endl;
}
printf("\nmopping up\n");
int r=gpioHardwarePWM(pwmpin, 0, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment