Commit 1a88cb54 authored by Gunter Windau's avatar Gunter Windau
Browse files

more

parent e34579fb
LSLBASE=../labstreaminglayer/build/install/lsl_Release/LSL
LSLBASE=../labstreaminglayer/build/install
CPPFLAGS+=-Wall -Wno-sign-compare -I$(LSLBASE)/include
LDFLAGS+=-L$(LSLBASE)/lib -llsl32 -lboost_system -lpthread
LDFLAGS+=-lpigpio
......@@ -10,7 +10,8 @@ LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
all: zmq_trigger playtone
all: zmq_trigger zmq_trigger_via_broker playtone
playtone: playtone.cc
zmq_trigger: zmq_trigger.cc
zmq_trigger_via_broker: zmq_trigger_via_broker.cc
#!/bin/bash
#run this as root
cd /home/pi/firmware/lsldert
export LD_LIBRARY_PATH=../labstreaminglayer/build/install/lsl_Release/LSL/lib/
export LD_LIBRARY_PATH=../labstreaminglayer/build/install/lib
./zmq_trigger
#!/bin/bash
#run this as root
cd /home/pi/firmware/lsldert
export LD_LIBRARY_PATH=../labstreaminglayer/build/install/lib
./zmq_trigger_via_broker
No preview for this file type
......@@ -129,7 +129,12 @@ int main(int argc, const char* argv[])
printf("Press control C to stop.\n");
if (gpioSetMode(pin, PI_ALT0) < 0) {
if (gpioSetMode(chan_right, PI_ALT0) < 0) {
perror("gpioSetMode");
return 1;
}
if (gpioSetMode(chan_left, PI_ALT0) < 0) {
perror("gpioSetMode");
return 1;
}
......@@ -166,12 +171,12 @@ int main(int argc, const char* argv[])
if (verbose)
cout << "Received: " << str << endl;
if (str == "b")
beep(freq, 500);
// Wait for the reply from the Arduino
// Return result
std::string result = str;
socket.send(asio::buffer(result));
if (str == "b")
beep(freq, 500);
}
printf("\nmopping up\n");
......
//
// Hello World server in C++ with azmq and boost
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <lsl_cpp.h>
#include <memory>
#include <iostream>
#include <iomanip>
#include <azmq/socket.hpp>
#include <boost/asio.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/program_options.hpp>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pigpio.h>
using namespace std;
using namespace boost;
using namespace lsl;
const int chan_left = 13; // PWM1 audio to jack
const int chan_right = 12; // PWM0 audio to jack
int pin = chan_left;
int freq = 400;
int dt = 1000;
stream_outlet *outlet;
volatile int run=1 ;
void stop(int signum)
{
run = 0;
}
static int verbose = 0;
void parse_options(int argc, const char* argv[])
{
namespace po = boost::program_options;
// Declare the supported options.
po::options_description desc("Usage:");
desc.add_options()
("help,h", "show this message")
("channel,c", po::value<char>(), "select channel")
("verbose,v", "enable verbose output")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
exit(0);
}
if (vm.count("verbose")) {
verbose = 1;
}
if (vm.count("channel")) {
char c = vm["channel"].as<char>();
switch (c) {
case 'l': case 'L':
pin = chan_left;
break;
case 'r': case 'R':
pin = chan_right;
break;
default:
cerr << "channel must be 'L' or 'R'" << endl;
exit(1);
}
}
}
std::string str2hex(const std::string& s)
{
const static char str2hex_lookup[] = "0123456789abcdef";
unsigned int i=0,leng=s.length();
std::stringstream r;
for(i=0; i<leng; i++)
{
r<< str2hex_lookup[ s[i] >> 4 ];
r<< str2hex_lookup[ s[i] & 0x0f ];
}
return r.str();
}
void beep(int freq, int durationmsec)
{
int d=500000;
int r=gpioHardwarePWM(pin, freq, d);
if (r < 0)
{
perror("gpioHardwarePWM");
exit(1);
}
std::this_thread::sleep_for(std::chrono::milliseconds(durationmsec));
r=gpioHardwarePWM(pin, 0, 0);
if (r < 0)
{
perror("gpioHardwarePWM");
exit(1);
}
}
int main(int argc, const char* argv[])
{
parse_options(argc, argv);
// Prepare sound output
int r = gpioInitialise(); // use Broadcom pin numbering
if (r < 0)
{
perror("gpioInitialise");
return 1;
}
gpioSetSignalFunc(SIGINT, stop);
printf("Press control C to stop.\n");
if (gpioSetMode(chan_right, PI_ALT0) < 0) {
perror("gpioSetMode");
return 1;
}
if (gpioSetMode(chan_left, PI_ALT0) < 0) {
perror("gpioSetMode");
return 1;
}
// Prepare our context and socket
asio::io_service ios;
azmq::socket socket(ios, ZMQ_REP);
// socket.bind("tcp://*:5555");
socket.bind("tcp://localhost:5560");
char hostname[255];
gethostname(hostname,255);
// make a new stream_info and open an outlet with it
char info_name[255];
sprintf(info_name, "Digital Triggers");
char info_type[512];
sprintf(info_type,"Digital Triggers @ %s",hostname);
stream_info info(info_name, info_type, 1, lsl::IRREGULAR_RATE,
lsl::cf_int8,"Raspberry Pi Digital Triggers");
outlet = new stream_outlet(info);
while (run)
{
std::array<char,4096> request;
// Wait for next request from client
socket.receive(asio::buffer(request));
std::string str(request.data());
int sample = 1;
outlet->push_sample(&sample);
if (verbose)
cout << "Received: " << str << endl;
// Return result
std::string result = str;
socket.send(asio::buffer(result));
if (str == "b")
beep(freq, 500);
}
printf("\nmopping up\n");
r=gpioHardwarePWM(pin, 0, 0);
if (r < 0)
{
perror("gpioHardwarePWM");
return 1;
}
gpioTerminate();
return 0;
}
CPPFLAGS+=-Wall -Wno-sign-compare
CXX=g++
CC=gcc
LDLIBS+=-lzmq
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
all: zmqmqbroker
zmqmqbroker: zmqmqbroker.c
// Simple message queuing broker
// Same as request-reply broker but using shared queue proxy
#include "zmq.h"
#include <assert.h>
int main (void)
{
void *context = zmq_ctx_new ();
// Socket facing clients
void *frontend = zmq_socket (context, ZMQ_ROUTER);
int rc = zmq_bind (frontend, "tcp://*:5559");
assert (rc == 0);
// Socket facing services
void *backend = zmq_socket (context, ZMQ_DEALER);
rc = zmq_bind (backend, "tcp://*:5560");
assert (rc == 0);
// Start the proxy
zmq_proxy (frontend, backend, NULL);
// We never get here, but clean up anyway
zmq_close (frontend);
zmq_close (backend);
zmq_ctx_destroy (context);
return 0;
}
Supports Markdown
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