CARMA C++
szacontrol.h
1 #ifndef szacontrol_h
2 #define szacontrol_h
3 
4 /*
5  * In order to get the correct include file definitions for posix
6  * threads, _POSIX_C_SOURCE must be defined to be at least 199506.
7  */
8 #if MAC_OSX == 1
9 #define _POSIX_C_SOURCE 199506L
10 #endif
11 
12 #if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 199506L
13 #error "Add -D_POSIX_C_SOURCE=199506L to the compile line"
14 #endif
15 
16 #include <stdio.h> /* FILENAME_MAX */
17 #include <time.h> /* struct tm */
18 #include <limits.h> /* PIPE_BUF */
19 
20 #include "carma/szaarrayutils/lprintf.h"
21 #include "carma/szaarrayutils/control.h"
22 #include "carma/szaarrayutils/list.h"
23 
24 #define NEW_PIPE
25 #define PIPE_QUEUE
26 
28 
29 #include "carma/szaarrayutils/regmap.h"
30 #include "carma/szaarrayutils/rtcnetcoms.h"
31 
32 #include "carma/szaarrayutils/regdata.h"
33 #include "carma/szaarrayutils/control.h"
34 
35 
36 #include "carma/szautil/AntNum.h"
38 #include "carma/szautil/Directives.h"
39 #include "carma/szautil/MonitorPoint.h"
42 
44 
45 /*
46  * Name the SZA initialization scripts. The
47  * first script is run when szacontrol starts up, whereas the
48  * second is run whenever a new connection is received from the
49  * real time controller.
50  */
51 #if DIR_IS_STABLE
52 #define SZACONTROL_INIT_SCRIPT "$SZA_DIR/conf/szaArrayControl.init"
53 #else
54 #define SZACONTROL_INIT_SCRIPT "$SZA_UDIR/conf/szaArrayControl.init"
55 #endif
56 
57 /*
58  * Set the maximum time to wait for threads to shutdown after being
59  * told to do so. The timeout is measured in seconds.
60  */
61 #define CP_SHUTDOWN_TIMEOUT 5
62 
63 /*
64  * Work out the longest pathname to support. Under Linux
65  * FILENAME_MAX bytes is right at the limit of what can be sent by a
66  * pipe (FILENAME_MAX==PIPE_BUF), so the remaining members of the message
67  * structures cause us not to be able send messages with arrays of
68  * this length included.
69  */
70 #if FILENAME_MAX + 16 > PIPE_BUF
71 #define CP_FILENAME_MAX (PIPE_BUF - 16)
72 #else
73 #define CP_FILENAME_MAX FILENAME_MAX
74 #endif
75 
76 #define CP_REGNAME_MAX CP_FILENAME_MAX/2
77 
78 /*
79  * Declare the type of the resource container of the program.
80  */
81 typedef struct ControlProg ControlProg; /* (see szacontrol.c) */
82 
83 /*
84  * Enumerate the client threads of the control program. The value of
85  * each enumerator is the index of the thread in the table of threads in
86  * szacontrol.c.
87  */
88 typedef enum {
89  CP_SCHEDULER, /* The scheduler thread */
90  CP_ARCHIVER, /* The archiver thread */
91  CP_LOGGER, /* The logger thread */
92  CP_NAVIGATOR, /* The navigator thread */
93  CP_GRABBER, /* The frame-grabber archiver thread */
94  CP_TERM, /* The terminal I/O thread */
95 } CpThreadId;
96 
97 // Look up the resource object of a given thread.
98 
99 void *cp_ThreadData(ControlProg *cp, CpThreadId id);
100 
101 // The following macros declare the method functions of
102 // control-program threads.
103 
104 // Allocate the resource object of a thread
105 
106 #define CP_NEW_FN(fn) void *(fn)(ControlProg *cp, sza::util::Pipe *pipe)
107 
108 // Delete the resource object of a thread and return NULL
109 
110 #define CP_DEL_FN(fn) void *(fn)(void *obj)
111 
112 // The thread start function. The thread resource object is passed via 'arg'
113 
114 #define CP_THREAD_FN(fn) void *(fn)(void *arg)
115 
116 // The following function sends a shutdown message to the thread using
117 // non-blocking I/O. On success it should return 0. If the message
118 // couldn't be sent without blocking, it should return 1.
119 
120 #define CP_STOP_FN(fn) int (fn)(ControlProg *cp)
121 
122 /*-----------------------------------------------------------------------
123  * Declare the API of the logger thread.
124  *-----------------------------------------------------------------------*/
125 
126 typedef struct Logger Logger; // The type of the thread resource object
127 typedef struct Logger SzaArrayLogger;// The type of the thread resource object
128 
129 CP_THREAD_FN(logger_thread); // The logger thread start function
130 CP_NEW_FN(new_Logger); // The logger resource constructor
131 CP_DEL_FN(del_Logger); // The logger resource destructor
132 CP_STOP_FN(stop_Logger); // Send a shutdown message to the logger
133 
134 
135 // Enumerate the message types that the logger task understands.
136 
137 typedef enum {
138  LOG_SHUTDOWN, // Cleanup and shutdown the logger thread
139  LOG_CHDIR, // Change the default log file directory
140  LOG_OPEN, // Open a new log file in a given place
141  LOG_FLUSH, // Flush unwritten text to the current
142  // log file.(Given that line buffering is
143  // requested when log files are opened
144  // this shouldn't ever be necessary.)
145  LOG_CLOSE, // Close the current log file
146  LOG_MESSAGE, // Write a specified message to the log
147  LOG_ADD_CLIENT, // Add a control client to the output list
148  LOG_REM_CLIENT, // Remove a control client from the output list
149  LOG_TRANS_CATALOG, // Read a transaction catalog
150  LOG_LOG_TRANS, // Log a transaction
151  LOG_TRANS_EMAIL // Configure the transaction email list
152 } LoggerMessageType;
153 
154 
155 // Objects of the following form are used to pass messages to the
156 // logger task. Please use pack_logger_<type>() to set up one of these
157 // messages.
158 
159 #define DATE_LEN 20
160 
161 typedef struct {
162  LoggerMessageType type; // The type of logger input message
163  union { // The body of the message
164 
165  struct { // type = LOG_CHDIR
166  char dir[CP_FILENAME_MAX+1];// The directory on which to open the file
167  } chdir;
168 
169  struct { // type = LOG_OPEN
170  char dir[CP_FILENAME_MAX+1];// The directory on which to open the file
171  } open;
172 
173  struct { // type = LOG_MESSAGE
174  unsigned seq; // The sequence number of this message
175  bool end; // True if this is the end of a message
176  bool interactive; // True if this message was generated
177  // by an interactive command
178  sza::array::LogStream nature; // The disposition of the message
179  char text[LOG_MSGLEN+1]; // The text of the message
180  } message;
181 
182  struct { // type = LOG_ADD_CLIENT | L5BOG_REM_CLIENT
183  sza::util::Pipe* pipe; // The control-client reply pipe
184  } client;
185 
186  struct { // type = LOG_TRANSACTION_CATALOG
187  char catalog[CP_FILENAME_MAX+1];// The catalog to open
188  bool clear;
189  } transCatalog;
190 
191  struct { // type = LOG_TRANSACTION_CATALOG
192  // The device name
193  char device[sza::array::TransactionManager::DEV_NAME_MAX+1];
194  // The serial number
195  char serial[sza::array::TransactionManager::SERIAL_NAME_MAX+1];
196  // The location name
197  char location[sza::array::TransactionManager::LOCATION_NAME_MAX+1];
198  // The date
199  double date;
200  // Who?
201  char who[sza::array::TransactionManager::WHO_NAME_MAX+1];
202  // Comment
203  char comment[LOG_MSGLEN-sza::array::TransactionManager::PREFIX_LEN+1];
204  } logTrans;
205 
206  struct {
207  bool add; // If true, add the address, if false, delete it
208  char address[CP_FILENAME_MAX+1]; // An email address
209  } email;
210 
211  } body;
212 
213 } LoggerMessage;
214 
215 // The following functions pack messages into a LoggerMessage object.
216 
217 int pack_logger_shutdown(LoggerMessage *msg);
218 int pack_logger_chdir(LoggerMessage *msg, char *dir);
219 int pack_logger_open(LoggerMessage *msg, char *dir);
220 int pack_logger_flush(LoggerMessage *msg);
221 int pack_logger_close(LoggerMessage *msg);
222 
223 int pack_logger_message(LoggerMessage *msg, char *text,
224  sza::array::LogStream nature,
225  unsigned seq=0, bool end=true, bool interactive=false);
226 
227 int pack_logger_add_client(LoggerMessage *msg, sza::util::Pipe *client);
228 int pack_logger_rem_client(LoggerMessage *msg, sza::util::Pipe *client);
229 
230 int pack_logger_transaction_catalog(LoggerMessage *msg, char *path, bool clear);
231 int pack_logger_log_transaction(LoggerMessage *msg, char *device, char* serial,
232  char* location, double date, char* who,
233  char* comment);
234 int pack_logger_transaction_email(LoggerMessage *msg, bool add, char *email);
235 
236 // Return true if the named device is recognized.
237 
238 bool log_isValidDevice(Logger* log, char* device);
239 
240 /*
241  * The following function attempts to send a packed LoggerMessage to the
242  * logger thread.
243  */
244 PipeState send_LoggerMessage(ControlProg *cp, LoggerMessage *msg,
245  long timeout);
246 
247 int sendLoggerMessage(ControlProg* cp, std::string message, bool isErr, bool interactive);
248 
249 /*
250  * The following function redirects the specified stream (stdout or stderr)
251  * of the calling thread to the input pipe of the logger thread.
252  */
253 int log_thread_stream(ControlProg *cp, FILE *stream);
254 
258 std::vector<std::string>* getTransactionEmailList(ControlProg *cp);
259 
260 /*-----------------------------------------------------------------------
261  * Declare the API of the archiver thread.
262  *-----------------------------------------------------------------------*/
263 
264 typedef struct Archiver Archiver; /* The type of the thread resource object */
265 
266 CP_THREAD_FN(archiver_thread); /* The archiver thread start function */
267 CP_NEW_FN(new_Archiver); /* The archiver resource constructor */
268 CP_DEL_FN(del_Archiver); /* The archiver resource destructor */
269 CP_STOP_FN(stop_Archiver); /* Send a shutdown message to the archiver */
270 
271 /*
272  * Enumerate the archiver message types.
273  */
274 typedef enum {
275  ARC_FRAME, /* Save the latest integration. When done */
276  /* set arc->fb.integrate to 1 and signal */
277  /* arc->fb.start */
278  ARC_SHUTDOWN, /* Cleanup and shutdown the archiver thread */
279  ARC_CHDIR, /* Change the default archive file directory */
280  ARC_OPEN, /* Open a new archive file in a given place */
281  ARC_FLUSH, /* Flush unwritten data to the current file */
282  ARC_CLOSE, /* Close the current archive file */
283  ARC_SAMPLING, /* Set the number of samples per integration */
284  ARC_FILTER, /* Enable/disable feature-based filtering */
285  ARC_FILE_SIZE, /* The number of frames to record in each */
286  /* archive file before automatically opening */
287  /* a new one. */
288  ARC_ADD_CLIENT, /* Add a control client to the list of connected */
289  /* clients */
290  ARC_REM_CLIENT, /* Remove a control client from the list of connected */
291  /* clients */
292  ARC_TV_OFFSET_DONE, /* A message sent by the control program to let
293  the archiver know that a tv_offset command
294  has been successfully completed. This is
295  sent by the scanner task when the new offsets
296  have been written to the latest frame sent to
297  the archiver */
298  ARC_NEW_FRAME /* A message sent by the control program to
299  request the archiver to terminate the current
300  integration and start a new one */
301 } ArchiverMessageType;
302 
303 /*
304  * Objects of the following form are used to pass messages to the
305  * archiver task. Please use pack_archiver_<type>() to set up one of
306  * these messages.
307  */
308 typedef struct {
309  ArchiverMessageType type; /* The type of archiver input message */
310  union { /* The body of the message */
311  struct { /* type = ARC_CHDIR */
312  char dir[CP_FILENAME_MAX+1];/* The current archiving directory */
313  } chdir;
314  struct { /* type = ARC_OPEN */
315  char dir[CP_FILENAME_MAX+1];/* The current archiving directory */
316  } open;
317  struct { /* type = ARC_SAMPLING */
318  unsigned nframe; /* The number of samples per integration */
319  unsigned seq; /* A sequence number associated with this command */
320  } sampling;
321  struct { /* type = ARC_FILTER */
322  int enable; /* True to tell the archiver only record */
323  /* frames who's frame.features register */
324  /* has a non-zero value. False to tell it */
325  /* to archive everything (the default) */
326  } filter;
327  struct { /* type = ARC_FILE_SIZE */
328  unsigned nframe; /* The number of frames per file, or zero to */
329  /* allow any number of frames per file. */
330  } file_size;
331  struct { /* type = ARC_ADD_CLIENT | ARC_REM_CLIENT */
332 #ifndef NEW_PIPE
333  Pipe *pipe; /* The control-client reply pipe */
334 #else
335  sza::util::Pipe *pipe; /* The control-client reply pipe */
336 #endif
337  } client;
338  struct {
339  unsigned seq;
340  } tv_offset_done;
341  struct {
342  unsigned seq;
343  } newFrame;
344  } body;
345 } ArchiverMessage;
346 
347 /*
348  * The following functions pack messages into an ArchiverMessage object.
349  */
350 int pack_archiver_frame(ArchiverMessage *msg);
351 int pack_archiver_shutdown(ArchiverMessage *msg);
352 int pack_archiver_chdir(ArchiverMessage *msg, char *dir);
353 int pack_archiver_open(ArchiverMessage *msg, char *dir);
354 int pack_archiver_flush(ArchiverMessage *msg);
355 int pack_archiver_close(ArchiverMessage *msg);
356 int pack_archiver_sampling(ArchiverMessage *msg, unsigned nframe, unsigned seq);
357 int pack_archiver_filter(ArchiverMessage *msg, int enable);
358 int pack_archiver_file_size(ArchiverMessage *msg, unsigned nframe);
359 
360 #ifndef NEW_PIPE
361 int pack_archiver_add_client(ArchiverMessage *msg, Pipe *client);
362 int pack_archiver_rem_client(ArchiverMessage *msg, Pipe *client);
363 #else
364 int pack_archiver_add_client(ArchiverMessage *msg, sza::util::Pipe *client);
365 int pack_archiver_rem_client(ArchiverMessage *msg, sza::util::Pipe *client);
366 #endif
367 
368 int pack_archiver_tv_offset_done(ArchiverMessage *msg, unsigned seq);
369 int pack_archiver_newFrame(ArchiverMessage *msg, unsigned seq);
370 /*
371  * The following function attempts to send a packed ArchiverMessage to the
372  * archiver thread.
373  */
374 PipeState send_ArchiverMessage(ControlProg *cp, ArchiverMessage *msg,
375  long timeout);
376 
377 /*
378  * This function adds a register frame to the current integration.
379  */
380 int arc_integrate_frame(ControlProg *cp, RegRawData *frame);
381 int arc_integrate_frame_old(ControlProg *cp, RegRawData *frame);
382 
383 /*
384  * Set the default archiver integration duration (frames).
385  */
386 enum {ARC_DEF_NFRAME=10};
387 
388 /*-----------------------------------------------------------------------
389  * Declare the API of the scheduler thread.
390  *-----------------------------------------------------------------------*/
391 
392 typedef struct Scheduler Scheduler; /* The type of the thread resource object */
393 
394 Scheduler *cp_Scheduler(ControlProg *cp);
395 
396 CP_THREAD_FN(scheduler_thread); /* The scheduler thread start function */
397 CP_NEW_FN(new_Scheduler); /* The scheduler resource constructor */
398 CP_DEL_FN(del_Scheduler); /* The scheduler resource destructor */
399 CP_STOP_FN(stop_Scheduler); /* Send a shutdown message to the scheduler */
400 
401 /*
402  * Enumerate scheduler message types.
403  */
404 typedef enum {
405  SCH_SHUTDOWN, /* An instruction to cleanup and shutdown */
406  SCH_COMMAND, /* A user command string */
407  SCH_RTC_STATE, /* Controller connection status */
408  SCH_ADD_CLIENT, /* Add a control client to the output list */
409  SCH_REM_CLIENT, /* Remove a control client from the output list */
410  SCH_RTCNETMSG, /* A message received from the controller */
411  SCH_MARK_DONE, /* A marker transaction completion message */
412  SCH_GRAB_DONE, /* A marker transaction completion message */
413  SCH_SETREG_DONE, /* A setreg transaction completion message */
414  SCH_TV_OFFSET_DONE, /* A tv_offset transaction completion message */
415  SCH_AUTO_DIR, /* An autoqueue chdir operation */
416  SCH_AUTO_POLL, /* An autoqueue polling inerval change */
417  SCH_AUTO_STATE, /* An autoqueue on/off toggle */
418  SCH_FRAME_DONE /* A new frame has begun */
419 } SchedulerMessageType;
420 
421 /*
422  * Objects of the following form are used to pass messages to the
423  * scheduler task. Please use pack_scheduler_<type>() to set up one of
424  * these messages.
425  */
426 typedef struct {
427  SchedulerMessageType type; /* The type of scheduler message */
428  union { /* The body of the message */
429 
430  struct { /* type=SCH_COMMAND */
431  char string[sza::array::CC_CMD_MAX+1]; /* The command string */
432 #ifndef NEW_PIPE
433  Pipe *client; /* The originating client */
434 #else
435  sza::util::Pipe *client; /* The originating client */
436 #endif
437  } command;
438 
439  int rtc_online; /* type=SCH_RTC_STATE */
440 
441  struct { /* type = SCH_ADD_CLIENT | SCH_REM_CLIENT */
442 #ifndef NEW_PIPE
443  Pipe *pipe; /* The control-client reply pipe */
444 #else
445  sza::util::Pipe *pipe; /* The originating client */
446 #endif
447  } client;
448 
449  struct { /* type=SCH_RTCNETMSG */
450  sza::array::NetMsgId id; /* The type of rtc network message */
451  sza::array::RtcNetMsg msg; /* The network message */
452  } rtcnetmsg;
453 
454  struct { /* type=SCH_MARK_DONE */
455  unsigned seq; /* The sequence number of the transaction */
456  } mark_done;
457 
458  struct { /* type=SCH_GRAB_DONE */
459  unsigned seq; /* The sequence number of the transaction */
460  } grab_done;
461 
462  struct { /* type=SCH_SETREG_DONE */
463  unsigned seq; /* The sequence number of the transaction */
464  } setreg_done;
465 
466  struct { /* type=SCH_TV_OFFSET_DONE */
467  unsigned seq; /* The sequence number of the transaction */
468  } tv_offset_done;
469 
470  struct { /* type=SCH_FRAME_DONE */
471  unsigned seq; /* The sequence number of the transaction */
472  } frame_done;
473 
474  struct { /* type=SCH_AUTO_DIR */
475  char dir[CP_FILENAME_MAX] ; /* The name of the directory */
476  } auto_dir;
477 
478  struct { /* type=SCH_AUTO_POLL */
479  long poll; /* The interval in ms to poll */
480  } auto_poll;
481 
482  struct { /* type=SCH_AUTO_STATE */
483  int on; /* The interval in ms to poll */
484  } auto_state;
485 
486  } body;
487 
488 } SchedulerMessage;
489 
490 /*
491  * The following functions pack messages into an SchedulerMessage object.
492  */
493 int pack_scheduler_shutdown(SchedulerMessage *msg);
494 int pack_scheduler_rtc_state(SchedulerMessage *msg, int online);
495 
496 #ifndef NEW_PIPE
497 int pack_scheduler_command(SchedulerMessage *msg, char *command, Pipe *client);
498 int pack_scheduler_add_client(SchedulerMessage *msg, Pipe *client);
499 int pack_scheduler_rem_client(SchedulerMessage *msg, Pipe *client);
500 #else
501 int pack_scheduler_command(SchedulerMessage *msg, char *command, sza::util::Pipe *client);
502 int pack_scheduler_add_client(SchedulerMessage *msg, sza::util::Pipe *client);
503 int pack_scheduler_rem_client(SchedulerMessage *msg, sza::util::Pipe *client);
504 #endif
505 
506 int pack_scheduler_rtcnetmsg(SchedulerMessage *msg, sza::array::NetMsgId id,
507  sza::array::RtcNetMsg *rtcmsg);
508 int pack_scheduler_mark_done(SchedulerMessage *msg, unsigned seq);
509 int pack_scheduler_grab_done(SchedulerMessage *msg, unsigned seq);
510 int pack_scheduler_setreg_done(SchedulerMessage *msg, unsigned seq);
511 int pack_scheduler_tv_offset_done(SchedulerMessage *msg, unsigned seq);
512 int pack_scheduler_frame_done(SchedulerMessage *msg, unsigned seq);
513 
514 /*
515  * The following function attempts to send a packed SchedulerMessage to the
516  * scheduler thread.
517  */
518 PipeState send_SchedulerMessage(ControlProg *cp, SchedulerMessage *msg,
519  long timeout);
520 
521 // Methods to do with the pager
522 
523 int send_paging_state(ControlProg* cp, bool allow);
524 
525 void listPager(ControlProg* cp, ListNode* node=0);
526 
527 int sendPagingState(ControlProg* cp, int allow,
528  unsigned mask=sza::array::PAGE_ENABLE, char* msg=0, ListNode* node=0);
529 
530 int sendPagerCondition(ControlProg* cp, unsigned mode,
531  sza::util::PagerMonitor::RegSpec* reg=0, ListNode* node=0);
532 
533 int sendCmdTimeoutConfiguration(ControlProg* cp, unsigned seconds, ListNode* node=0);
534 int sendCmdTimeoutConfiguration(ControlProg* cp, bool active, ListNode* node=0);
535 
536 // Methods to do with the array configuration
537 
538 int sendArrayConfiguration(ControlProg* cp, ListNode* node,
539  unsigned mode,
540  unsigned array = sza::util::CarmaConfig::NONE,
541  unsigned config = sza::util::CarmaConfig::NONE);
542 
543 int sendAddArrayAntenna(ControlProg* cp, ListNode* node,
544  unsigned array,
545  unsigned iPad,
546  unsigned antType,
547  int iAnt = -1);
548 
549 int sendRemArrayAntenna(ControlProg* cp, ListNode* node,
550  unsigned array, unsigned iPad);
551 
552 void listArrayConfig(ControlProg* cp, ListNode* node, unsigned config);
553 
554 /*-----------------------------------------------------------------------
555  * Declare the API of the navigator thread.
556  *-----------------------------------------------------------------------*/
557 
558 #ifndef navigator_h
559 typedef struct Navigator Navigator; /* The type of the thread resource object */
560 #endif
561 
562 Navigator *cp_Navigator(ControlProg *cp);
563 
564 CP_THREAD_FN(navigator_thread); /* The navigator thread start function */
565 CP_NEW_FN(new_Navigator); /* The navigator resource constructor */
566 CP_DEL_FN(del_Navigator); /* The navigator resource destructor */
567 CP_STOP_FN(stop_Navigator); /* Send a shutdown message to the navigator */
568 
569 /*
570  * Enumerate navigator message types.
571  */
572 typedef enum {
573  NAV_SHUTDOWN, /* An instruction to cleanup and shutdown */
574  NAV_RTC_STATE, /* Controller connection status */
575  NAV_CATALOG, /* A "read source catalog" command */
576  NAV_SCAN_CATALOG, /* A "read scan catalog" command */
577  NAV_UT1UTC, /* A "read UT1-UTC ephemeris" command */
578  NAV_SITE /* A "record sza location" command */
579 } NavigatorMessageType;
580 
581 /*
582  * The following container is used to convey site-location messages.
583  */
584 typedef struct {
585  double longitude; /* East longitude (radians) */
586  double latitude; /* Latitude (radians) */
587  double altitude; /* Altitude ASL (m) */
588 } NavSiteMsg;
589 
590 /*
591  * Objects of the following form are used to pass messages to the
592  * navigator task. Please use pack_navigator_<type>() to set up one of
593  * these messages.
594  */
595 typedef struct {
596  NavigatorMessageType type; // The type of navigator message
597  union { // The body of the message
598  int rtc_online; // type=NAV_RTC_STATE
599  char catalog[CP_FILENAME_MAX+1]; // type=NAV_CATALOG
600  char scan_catalog[CP_FILENAME_MAX+1]; // type=NAV_SCAN_CATALOG
601  char ut1utc[CP_FILENAME_MAX+1]; // type=NAV_UT1UTC
602  NavSiteMsg site; // type=NAV_SITE
603  } body;
604 } NavigatorMessage;
605 
606 /*
607  * The following functions pack messages into an NavigatorMessage object.
608  */
609 int pack_navigator_shutdown(NavigatorMessage *msg);
610 int pack_navigator_rtc_state(NavigatorMessage *msg, int online);
611 int pack_navigator_catalog(NavigatorMessage *msg, char *path);
612 int pack_navigator_scan_catalog(NavigatorMessage *msg, char *path);
613 int pack_navigator_ut1utc(NavigatorMessage *msg, char *path);
614 int pack_navigator_site(NavigatorMessage *msg, double longitude,
615  double latitude, double altitude);
616 /*
617  * The following function attempts to send a packed NavigatorMessage to the
618  * navigator thread.
619  */
620 PipeState send_NavigatorMessage(ControlProg *cp, NavigatorMessage *msg,
621  long timeout);
622 
623 /*-----------------------------------------------------------------------
624  * Declare the API of the grabber thread.
625  *-----------------------------------------------------------------------*/
626 
627 typedef struct Grabber Grabber; /* The type of the thread resource object */
628 
629 CP_THREAD_FN(grabber_thread); /* The grabber thread start function */
630 CP_NEW_FN(new_Grabber); /* The grabber resource constructor */
631 CP_DEL_FN(del_Grabber); /* The grabber resource destructor */
632 CP_STOP_FN(stop_Grabber); /* Send a shutdown message to the grabber */
633 
634 /*
635  * Enumerate the grabber message types.
636  */
637 typedef enum {
638  GRAB_IMAGE, /* Save the latest image. When done */
639  /* set grab->im.save to 1 and signal */
640  /* grab->im.start */
641  GRAB_SHUTDOWN, /* Cleanup and shutdown the grabber thread */
642  GRAB_CHDIR, /* Change the default grabber file directory */
643  GRAB_OPEN, /* Tell the grabber thread to archive suqsequent
644  image */
645  GRAB_FLUSH, /* Flush unwritten data to the current file */
646  GRAB_CLOSE, /* Tell the grabber thread not to archive
647  subsequent images */
648  GRAB_SEQ /* Tell the gabber thread to update its grabber
649  sequence number */
650 } GrabberMessageType;
651 
652 /*
653  * Objects of the following form are used to pass messages to the
654  * grabber task. Please use pack_grabber_<type>() to set up one of
655  * these messages.
656  */
657 typedef struct {
658  GrabberMessageType type; /* The type of grabber input message */
659  union { /* The body of the message */
660  struct { /* type = GRAB_CHDIR */
661  char dir[CP_FILENAME_MAX+1];/* The current archiving directory */
662  } chdir;
663  struct { /* type = GRAB_OPEN */
664  char dir[CP_FILENAME_MAX+1];/* The current archiving directory */
665  } open;
666  unsigned seq;
667  } body;
668 } GrabberMessage;
669 
670 /*
671  * The following functions pack messages into an GrabberMessage object.
672  */
673 int pack_grabber_image(GrabberMessage *msg);
674 int pack_grabber_shutdown(GrabberMessage *msg);
675 int pack_grabber_chdir(GrabberMessage *msg, char *dir);
676 int pack_grabber_open(GrabberMessage *msg, char *dir);
677 int pack_grabber_flush(GrabberMessage *msg);
678 int pack_grabber_close(GrabberMessage *msg);
679 
680 /*
681  * The following function attempts to send a packed GrabberMessage to the
682  * grabber thread.
683  */
684 PipeState send_GrabberMessage(ControlProg *cp, GrabberMessage *msg,
685  long timeout);
686 
687 /*
688  * This function copies the current image to the grabber image buffer for
689  * archiving.
690  */
691 int grabber_save_image(ControlProg *cp, unsigned short *image,
692  unsigned long utc[2], signed actual[3],
693  signed expected[3]);
694 
695 /*-----------------------------------------------------------------------
696  * Declare the API of the terminal thread.
697  *-----------------------------------------------------------------------*/
698 
699 typedef struct Term Term; /* The type of the thread resource object */
700 
701 CP_THREAD_FN(term_thread); /* The term thread start function */
702 CP_NEW_FN(new_Term); /* The term resource constructor */
703 CP_DEL_FN(del_Term); /* The term resource destructor */
704 CP_STOP_FN(stop_Term); /* Send a shutdown message to the term */
705 
706 /*
707  * Enumerate the term message types.
708  */
709 typedef enum {
710  TERM_SHUTDOWN, /* Cleanup and shutdown the term thread */
711  TERM_ENABLE, /* Tell the terminal thread to
712  dis/allow subsequent pager commands */
713  TERM_REG_PAGE, /* De/Activate the pager */
714  TERM_MSG_PAGE, /* De/Activate the pager */
715  TERM_IP, /* Set the IP address to use for the pager */
716  TERM_EMAIL, /* Add an email address */
717  TERM_AUTO_INTERVAL, // Set the interval for auto-reenable of the pager
718  TERM_AUTO_ENABLE // Enable auto-reenabling of the pager
719 } TermMessageType;
720 /*
721  * Enumerate the supported pager devices
722  */
723 typedef enum {
724  PAGER_MAPO_REDLIGHT,
725  PAGER_DOME_PAGER,
726  PAGER_ELDORM_PAGER,
727  PAGER_NONE
728 } PagerDev;
729 /*
730  * Objects of the following form are used to pass messages to the
731  * term task. Please use pack_term_<type>() to set up one of
732  * these messages.
733  */
734 typedef struct {
735 
736  TermMessageType type; /* The type of term input message */
737 
738  union {
739  char ip[CP_FILENAME_MAX+1]; // An IP address for the pager control
740  // device
741  struct {
742  bool add; // If true, add the address, if false, delete it
743  char address[CP_FILENAME_MAX+1]; // An IP address for the pager control device
744  } email;
745 
746  struct {
747  int on; /* 1 -- turn pager on
748  0 -- turn pager off */
749  char msg[CP_FILENAME_MAX+1]; // The message
750  char comment[CP_FILENAME_MAX+1]; // A comment
751  } page;
752 
753  struct {
754  bool enable; // True to enable the pager, false to disable it
755  } enable;
756 
757  struct {
758  bool enable; // True to turn on auto-reenabling of the pager
759  } autoEnable;
760 
761  struct {
762  unsigned seconds; // The interval, in seconds, after which to
763  // automatically reenable the pager
764  } autoInterval;
765 
766  } body;
767 
768  PagerDev dev; /* Which device are we addressing? */
769 
770 } TermMessage;
771 
772 /*
773  * The following functions pack messages into an TermMessage object.
774  */
775 int pack_term_shutdown(TermMessage *msg);
776 int pack_term_reg_page(TermMessage *msg, char* reg=NULL, char* comment=NULL, bool on=true);
777 int pack_term_msg_page(TermMessage *msg, std::string txt, bool on=true);
778 int pack_pager_ip(TermMessage *msg, PagerDev dev, char *ip);
779 int pack_pager_email(TermMessage *msg, bool add, char *email);
780 int pack_pager_enable(TermMessage *msg, bool enable);
781 int packPagerAutoEnable(TermMessage *msg, bool enable);
782 int packPagerAutoEnable(TermMessage *msg, unsigned seconds);
783 
784 int send_reg_page_msg(ControlProg* cp, char* reg, char* comment=0);
785 
786 MONITOR_CONDITION_HANDLER(sendRegPage);
787 
788 /*
789  * The following function attempts to send a packed TermMessage to the
790  * term thread.
791  */
792 PipeState send_TermMessage(ControlProg *cp, TermMessage *msg,
793  long timeout);
794 
798 std::vector<std::string>* getPagerEmailList(ControlProg *cp);
799 
800 /*-----------------------------------------------------------------------
801  * Other functions.
802  *-----------------------------------------------------------------------*/
803 
804 /*
805  * The following function can be called to retrieve the state object of
806  * a given thread.
807  */
808 
809 /*
810  * Get the register map of the control program. Note that
811  * once created by the control program the register map
812  * must be treated as readonly. No locking is then required.
813  */
814 ArrayMap *cp_ArrayMap(ControlProg *cp);
815 
816 /*
817  * Provide access to the default antenna set
818  *
819  * Input:
820  * cp ControlProg * The resource object of the control program.
821  * Output:
822  * return AntNum * The default antenna set
823  */
824 sza::util::AntNum* cp_AntSet(ControlProg *cp);
825 
826 /*
827  * The following functions send messages to control client output
828  * pipes.
829  */
830 
831  /* Send a text message to a control client (timeout=0) */
832 
833 typedef struct {
834  sza::array::CcNetMsgId id; /* The type of network message in 'mgs' */
835  sza::array::CcNetMsg msg; /* The network message to be sent */
836 } CcPipeMsg;
837 
838 #ifndef NEW_PIPE
839 int queue_cc_message(Pipe *client, CcPipeMsg *msg);
840 #else
841 int queue_cc_message(sza::util::Pipe *client, CcPipeMsg *msg);
842 #endif
843 
844 /*
845  * Queue a network command object to be sent to the real-time controller.
846  *
847  * By default, we will deactivate the timer when any command queued by
848  * this method is sent to the translator.
849  */
850 int queue_rtc_command(ControlProg *cp, sza::array::RtcNetCmd *cmd,
851  sza::array::NetCmdId type, bool deactivateTimeout=true);
852 
853 /*
854  * Return true if the real-time controller is currently connected.
855  */
856 int cp_rtc_online(ControlProg *cp);
857 
858 /*
859  * The following functions pack messages into an ControlMessage object.
860  */
861 int cp_request_shutdown(ControlProg *cp);
862 int cp_request_restart(ControlProg *cp);
863 int cp_report_exit(ControlProg *cp);
864 int cp_initialized(ControlProg *cp);
865 
866 void configureCmdTimeout(ControlProg* cp, unsigned int seconds);
867 void configureCmdTimeout(ControlProg* cp, bool activate);
868 void allowTimeOutPaging(ControlProg* cp, bool allow);
869 
870 std::string cp_startupScript(ControlProg *cp);
871 
872 int sendClearPagerMsg(ControlProg* cp);
873 int sendResetPagerMsg(ControlProg* cp);
874 int sendListPagerMsg(ControlProg* cp);
875 int sendEnablePagerMsg(ControlProg* cp, bool enable);
876 
877 int sendAddPagerRegisterMsg(ControlProg* cp, std::string regName,
878  double min, double max, bool delta, unsigned nFrame,
879  bool outOfRange, char* comment);
880 
881 int sendRemPagerRegisterMsg(ControlProg* cp, std::string regName);
882 
883 
884 ControlProg* new_ControlProg();
885 ControlProg* new_ControlProgViewerServer();
886 
887 double getRegVal(ControlProg* cp, sza::util::RegDescription& regDesc);
888 
889 // External methods to send messages about the array configuration
890 
891 int sendArrayConfigMsg(ControlProg* cp, unsigned array, unsigned config);
892 
893 int sendAddArrayAntennaMsg(ControlProg* cp, unsigned array, unsigned iPad,
894  unsigned antType, int iAnt);
895 
896 int sendRemArrayAntennaMsg(ControlProg* cp, unsigned array, unsigned iPad);
897 
898 sza::util::CarmaConfig* getArrayConfig(ControlProg* cp, unsigned array);
899 
900 ControlProg* new_ControlProg(std::string startupScript);
901 ControlProg* del_ControlProg(ControlProg* cp);
902 int cp_event_loop(ControlProg* cp);
903 int cp_event_loop_MonitorServer(ControlProg* cp);
904 
905 /*
906  * Define the continuation statuses of the event loop.
907  */
908 typedef enum {
909  CP_CONTINUE, /* Continue the event loop */
910  CP_SHUTDOWN, /* Shutdown the control program */
911  CP_RESTART /* Restart the control program */
912 } CpWhatNext;
913 
914 CpWhatNext whatNext(ControlProg* cp);
915 
916 //=======================================================================
917 // Define a class for serving up a monitor frame to viewer clients
918 //=======================================================================
919 
920 namespace sza {
921  namespace array {
922 
923  class ViewerServer : public sza::util::NetMonitorFrameServer {
924  public:
925 
926  ViewerServer(bool spawnThread, unsigned port, sza::util::NetMonitorFrame* nmf, int fdRead);
927  ~ViewerServer();
928 
929  void run();
930 
931  private:
932 
933  void registerReceiptOfFrame();
934 
935  ControlProg* cp_;
936  };
937 
938  }
939 }
940 #endif
A class to enumerate a single Antenna, or a set of Antennas.
Definition: AntNum.h:21
Tagged: Wed Jun 16 22:25:23 UTC 2004.
Tagged: Mon May 23 15:48:44 PDT 2011.
A struct for handling information about a single register.
Definition: PagerMonitor.h:45
Tagged: Thu Aug 28 15:18:31 PDT 2008.
Tagged: Fri Nov 14 12:39:31 UTC 2003.
A class to encapsulate a pipe.
Definition: Pipe.h:49
Tagged: Mon May 23 16:22:59 PDT 2011.
Tagged: Fri Nov 14 12:39:34 UTC 2003.