RPi Locator and Display Services
skn_common_headers.h
Go to the documentation of this file.
1 /*
2  * skn_common_headers.h
3  *
4  * Created on: Jul 22, 2015
5  * Author: jscott
6  */
7 
8 #ifndef SRC_SKN_COMMON_HEADERS_H_
9 #define SRC_SKN_COMMON_HEADERS_H_
10 
11 #include <sys/types.h>
12 #include <pwd.h> /* umask() */
13 #include <sys/stat.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <fcntl.h>
17 #include <errno.h>
18 #include <unistd.h>
19 #include <string.h>
20 #include <assert.h>
21 #include <signal.h>
22 #include <getopt.h>
23 #include <pthread.h>
24 #include <stdint.h>
25 #include <ctype.h>
26 #include <stddef.h>
27 #include <sys/socket.h>
28 #include <sys/time.h> // for clock_gettime()
29 #include <netinet/in.h>
30 #include <netdb.h>
31 #include <arpa/inet.h>
32 #include <net/if.h>
33 #include <ifaddrs.h>
34 #include <time.h>
35 #include <stdarg.h>
36 #include <math.h>
37 
38 
39 //#include <systemd/sd-daemon.h>
40 
41 #define SD_EMERG "<0>" /* system is unusable */
42 #define SD_ALERT "<1>" /* action must be taken immediately */
43 #define SD_CRIT "<2>" /* critical conditions */
44 #define SD_ERR "<3>" /* error conditions */
45 #define SD_WARNING "<4>" /* warning conditions */
46 #define SD_NOTICE "<5>" /* normal but significant condition */
47 #define SD_INFO "<6>" /* informational */
48 #define SD_DEBUG "<7>" /* debug-level messages */
49 
75 /*
76  * Program Standards passed from compiler
77  */
78 #ifndef PACKAGE_VERSION
79  #define PACKAGE_VERSION "1.1"
80 #endif
81 #ifndef PACKAGE_NAME
82  #define PACKAGE_NAME "lcd_display_service"
83 #endif
84 #ifndef PACKAGE_DESCRIPTION
85  #define PACKAGE_DESCRIPTION "Locate Raspberry Pi's on the network."
86 #endif
87 
88 
89 #define SKN_FIND_RPI_PORT 48028
90 #define SKN_RPI_DISPLAY_SERVICE_PORT 48029
91 #define SKN_RPI_REGULAR_SERVICE_PORT 48027
92 
93 #define SZ_CHAR_LABEL 48
94 #define SZ_INFO_BUFF 256
95 #define SZ_CHAR_BUFF 128
96 #define SZ_LINE_BUFF 512
97 #define SZ_COMM_BUFF 256
98 
99 #define ARY_MAX_INTF 8
100 #define ARY_MAX_REGISTRY 128
101 #define ARY_MAX_DM_LINES 24
102 #define SKN_RUN_MODE_RUN 0
103 #define SKN_RUN_MODE_STOP 1
104 
105 #ifndef TRUE
106  #define TRUE (1==1)
107  #define FALSE (1==2)
108 #endif
109 
110 #define SCROLL_WAIT 1
111 #define SCROLL_NOWAIT 0
112 #define MAX_DISPLAY_ROWS 4
113 #define PLATFORM_ERROR -1
114 
115 /*
116  * Defines for the Adafruit IC2/SPI LCD Backpack
117  * - which use the I2C controller MCP23008
118 */
119 //
120 // #define AF_BASE 100
121 // #define AF_BACKLIGHT (AF_BASE + 7)
122 //
123 // #define AF_E (AF_BASE + 2)
124 // #define AF_RW (AF_BASE + 0)
125 // #define AF_RS (AF_BASE + 1)
126 //
127 // #define AF_DB4 (AF_BASE + 3)
128 // #define AF_DB5 (AF_BASE + 4)
129 // #define AF_DB6 (AF_BASE + 5)
130 // #define AF_DB7 (AF_BASE + 6)
131 
132 /*
133  * Defines for the 'YwRobot Arduino LCM1602 IIC V1'
134  * - which use the I2C controller PCF8574
135 */
136 // #define AF_BASE 100
137 // #define AF_BACKLIGHT (AF_BASE + 3)
138 //
139 // #define AF_E (AF_BASE + 2)
140 // #define AF_RW (AF_BASE + 1)
141 // #define AF_RS (AF_BASE + 0)
142 //
143 // #define AF_DB4 (AF_BASE + 4)
144 // #define AF_DB5 (AF_BASE + 5)
145 // #define AF_DB6 (AF_BASE + 6)
146 // #define AF_DB7 (AF_BASE + 7)
147 
148 /*
149  * Defines for the Adafruit RGB Negative 16x2 LCD+Keypad Kit
150  * - which use the I2C controller MCP23017
151 */
152 //#define AF_BASE 100
153 //#define AF_RED (AF_BASE + 6)
154 //#define AF_GREEN (AF_BASE + 7)
155 //#define AF_BLUE (AF_BASE + 8)
156 //
157 //#define AF_E (AF_BASE + 13)
158 //#define AF_RW (AF_BASE + 14)
159 //#define AF_RS (AF_BASE + 15)
160 //
161 //#define AF_DB4 (AF_BASE + 12)
162 //#define AF_DB5 (AF_BASE + 11)
163 //#define AF_DB6 (AF_BASE + 10)
164 //#define AF_DB7 (AF_BASE + 9)
165 //
166 //#define AF_SELECT (AF_BASE + 0)
167 //#define AF_RIGHT (AF_BASE + 1)
168 //#define AF_DOWN (AF_BASE + 2)
169 //#define AF_UP (AF_BASE + 3)
170 //#define AF_LEFT (AF_BASE + 4)
171 
172 /*
173  * Defines for the serial port version
174 */
175 // clr = [ 0xfe, 0x58 ].pack("C*")
176 // home = [ 0xfe, 0x48 ].pack("C*")
177 // line1 = [ 0xfe, 0x47, 0x01, 0x01 ].pack("C*")
178 // line2 = [ 0xfe, 0x47, 0x01, 0x02 ].pack("C*")
179 // bright = [ 0xfe, 0x99, 0x96 ].pack("C*")
180 // setup = [ 0xfe, 0xd1, 0x10, 0x02 ].pack("C*")
181 // SerialPort.open("/dev/ttyACM0", 9600, 8, 1, SerialPort::NONE) do |serial|
182 //
183 // serial.syswrite home # clr
184 // serial.syswrite bright
185 //
186 // begin
187 // tm = Time.now
188 // serial.syswrite line1
189 // serial.write " #{tm.strftime('%m-%d-%Y')}"
190 // serial.syswrite line2
191 // serial.write " #{tm.strftime('%H:%M:%S.%3N')}"
192 // sleep 1
193 // end while true
194 //
195 // end
196 
197 // Flags for display on/off control
198 // #define LCD_BLINKON 0x01
199 // #define LCD_CURSORON 0x02
200 // #define LCD_DISPLAYON 0x04
201 
202 // Flags for display size
203 // #define LCD_2LINE 0x02
204 // #define LCD_4LINE 0x04
205 // #define LCD_16CHAR 0x10
206 // #define LCD_20CHAR 0x14
207 
208 // Flags for setting display size
209 // #define LCD_SET2LINE 0x06
210 // #define LCD_SET4LINE 0x05
211 // #define LCD_SET16CHAR 0x04
212 // #define LCD_SET20CHAR 0x03
213 
214 
215 
216 typedef struct _IICLCD {
218  char ch_serial_port_name[SZ_CHAR_BUFF]; // SerialPort.open("/dev/ttyACM0", 9600, 8, 1, SerialPort::NONE)
221  int af_base;
223  int af_red;
224  int af_green;
225  int af_blue;
226 
227  int af_e;
228  int af_rs;
229  int af_rw;
230 
231  int af_db0; // 0-3 are not used for 4bit display connections
232  int af_db1;
233  int af_db2;
234  int af_db3;
235  int af_db4;
236  int af_db5;
237  int af_db6;
238  int af_db7;
239  int (*setup)(const int, const int);
241 
242 
243 typedef struct _ipBroadcastArray {
244  char cbName[SZ_CHAR_BUFF];
245  char chDefaultIntfName[SZ_CHAR_BUFF];
246  char ifNameStr[ARY_MAX_INTF][SZ_CHAR_BUFF];
247  char ipAddrStr[ARY_MAX_INTF][SZ_CHAR_BUFF];
248  char maskAddrStr[ARY_MAX_INTF][SZ_CHAR_BUFF];
249  char broadAddrStr[ARY_MAX_INTF][SZ_CHAR_BUFF];
250  int defaultIndex;
251  int count; // index = count - 1
253 
254 typedef struct _serviceEntry {
256  char name[SZ_INFO_BUFF];
257  char ip[SZ_INFO_BUFF];
258  int port;
260 
261 typedef struct _serviceRegistry {
263  int count; // current number of entries
264  int computedMax; // computed container size of .entry
265  PRegistryEntry entry[ARY_MAX_REGISTRY];
267 
268 typedef struct _serviceRequest {
270  PRegistryEntry pre;
271  char request[SZ_INFO_BUFF];
272  char response[SZ_INFO_BUFF];
273  int socket;
275 
276 /*
277  * Char bufs for cpu temperature
278 */
279 #define TZ_ADJUST 4
280 typedef struct _temps {
282  char c[SZ_CHAR_LABEL];
283  char f[SZ_CHAR_LABEL];
284  long raw;
285 } CpuTemps, *PCpuTemps;
286 
287 typedef struct _DISPLAY_LINE {
289  int active;
290  char ch_display_msg[SZ_INFO_BUFF];
291  int msg_len;
294  void * next;
295  void * prev;
297 
298 typedef struct _DISPLAY_MANAGER {
300  char ch_welcome_msg[SZ_INFO_BUFF];
301  int msg_len;
303  int dsp_rows;
304  int dsp_cols;
305  PDisplayLine pdsp_collection[ARY_MAX_DM_LINES]; // all available lines
306  int current_line; // top of display
307  int next_line; // actual index -- should be within display_lines of current
309  pthread_t dm_thread; // new message thread
311  int i_socket;
312  LCDDevice lcd; // selected device
314 
315 
316 #endif /* SRC_SKN_COMMON_HEADERS_H_ */
struct _serviceRequest ServiceRequest
struct _serviceRequest * PServiceRequest
struct _serviceRegistry ServiceRegistry
int port
int(* setup)(const int, const int)
char ch_serial_port_name[SZ_CHAR_BUFF]
#define SZ_INFO_BUFF
#define ARY_MAX_REGISTRY
struct _ipBroadcastArray * PIPBroadcastArray
struct _temps * PCpuTemps
#define SZ_CHAR_LABEL
struct _IICLCD LCDDevice
#define ARY_MAX_INTF
char cbName[SZ_CHAR_BUFF]
struct _DISPLAY_MANAGER DisplayManager
#define ARY_MAX_DM_LINES
struct _ipBroadcastArray IPBroadcastArray
struct _DISPLAY_LINE * PDisplayLine
struct _DISPLAY_LINE DisplayLine
struct _serviceRegistry * PServiceRegistry
struct _serviceEntry RegistryEntry
struct _serviceEntry * PRegistryEntry
struct _DISPLAY_MANAGER * PDisplayManager
struct _IICLCD * PLCDDevice
PRegistryEntry pre
struct _temps CpuTemps
#define SZ_CHAR_BUFF