Hardware Reference
In-Depth Information
The main program initiates curses mode in lines 204 through 207. Prior to that, the
ØMQ library is used to subscribe to the sensor's published data in lines 184 through 196.
Notice that when subscribing, you must indicate what subscriptions you want. Not setting
any ZMQ_SUBSCRIBE options will result in no messages being received.
Lines 198 to 202 initiate a push connection to the sensor, so commands may be
delivered from the console to the sensor. Note that all running consoles will also establish
this connection. Any console can control the sensor.
The main console loop from lines 226 through 243 receives the subscribed messages
and displays them on the console. That's all it does.
The command_center thread is shown in lines 112 to 161. It simply reads a keystroke
in line 125 and then dispatches the command in line 132.
The ncurses library is not thread safe, so mutex locking is used to prevent more than
one thread from attempting to use that library simultaneously.
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
console.c − Raspberry Pi Sensor Console
3
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <assert.h>
10 #include <pthread.h>
11 #include <curses.h>
12
13 #include <zmq.h>
14
15 #include "mutex.c"
16
17 static char
host_name = "local host"; /
Default host name
/
18 static char service_sensor_pub[128]; /
Service name for sensor
/
19 static char service_sensor_pull[128]; /
Service name for sensor's cmds
/
20
21 static void
context = 0; /
ZMQ context object
/
22 static void
subscriber = 0; /
Subscriber socket
/
23 static void
console = 0; /
Push socket
/
24
25 static int SW1 = −1; /
Known status of SW1
/
26 static int LED = −1; /
Known status of LED
/
27
28 /
29
Post the status of SW1 to the console screen
30
/
Search WWH ::




Custom Search