The VisAO Camera
dioserver.h
Go to the documentation of this file.
1 /************************************************************
2 * dioserver.h
3 *
4 * Author: Jared R. Males (jrmales@email.arizona.edu)
5 *
6 * Declarations for the dioserver.
7 *
8 * Developed as part of the Magellan Adaptive Optics system.
9 ************************************************************/
10 
11 /** \file dioserver.h
12  * \author Jared R. Males
13  * \brief Declarations for the dioserver.
14  *
15  * Do we need more?
16  *
17  *
18 */
19 
20 #ifndef __dioserver_h__
21 #define __dioserver_h__
22 
23 #define NODIOCARD
24 
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 
29 #include <signal.h>
30 
31 #include <sys/stat.h>
32 
33 #define DIO_CHANNELS 64
34 
35 #include "VisAOApp_standalone.h"
36 #include "libvisao.h"
37 
38 namespace VisAO
39 {
40 
41 class dioserver; //Forward declaration
42 
43 ///Holds the information for one digital I/O channel.
44 typedef struct
45 {
46  int swchannel; /// The software channel number - used to access the channel via the dio fifos.
47  int hwchannel; /// The hardware channel number - used to access the diocard itself.
48  int direction; ///The direction, 0 for output, 1 for input
49  int enabled; /// Whether the channel is enabled or not. Disabled channels (enabled = 0) are ignored.
50  dioserver * dios; /// Pointer to the dioserver managing this channel, for handlers.
51 } dioserver_ch;
52 
53 /// Class to manage access to a digital input/output device
54 /** Allows us to map "software channels" to "hardware channels", so that if we have
55  * to rewire we only have to change the config file.
56  *
57  * Uses a generic DIO interface, consisting of a void * and various function pointers which
58  * take said void * as an argument. To adapt to a new card, just provide the relevant functions
59  * (diocard_init, diocard_sd, diocard_write, and diocard_read). dioserver does the rest.
60  *
61  * Provides only remote and local command fifos. Most interaction with dioserver will be via the
62  * dio channel fifos.
63  *
64  * See \ref VisAOApp_standalone for command line arguments. There are no additional command line arguments for dioserver.
65  *
66  * This is a standalone VisAOApp, so it doesn't depend on MsgD. In addition to the optional standard config options inherited from \ref VisAOApp_standalone this class REQUIRES:
67  * - <b>DIOCHAN_XX</b> <tt>array of int</tt> - XX is the software channel number (how fifos are labeled). The array consists of [hw,dir,en] where hw is hardware channel, dir is the direction (0=out, 1=in), and en is the enable status.
68  *
69  * The following config setting is optional:
70  * - <b>fifo_path</b> <tt>string</tt> - the base bath, relative to VISAO_ROOT, where the dio fifos are created.
71  */
72 
74 {
75 public:
76  /// Command line constructor.
77  dioserver(int argc, char **argv) throw (AOException);
78 
79  /// Config file constructor.
80  dioserver(std::string name, const std::string &conffile) throw (AOException);
81 
82  dioserver_ch diosch[DIO_CHANNELS]; ///< The channels being managed.
83  int n_enabled; ///< Number of channel enabled.
84 
85  /// The base path names for the fifos
86  std::string fifo_path;
87 
88  ///The generic DIO interface. This pointer is passed unaltered to the diocard_* functions.
89  void * diocard_info;
90  int (* diocard_init)(void *); ///< Initialize the card.
91  int (* diocard_sd)(void *); ///< Shutdown the card.
92  int (* diocard_write)(void * card, int ch, int bit); ///< Write a bit to a channel
93  int (* diocard_read)(void * card, int ch); ///< Read a bit from the channel.
94 
95  /// Initialize the dioserver structure
96  int init_dioserver();
97 
98  /// Set a single channel of the server
99  /** Called for each channel in the configuration file. Update n_enabled.
100  * \param chnum the software channel number
101  * \param hwchan the hardware channel number
102  * \param dir the direction (0 = output, 1 = input)
103  * \param enab whether or not the channel is enabled.
104  * \retval 0 on success
105  * \retval -1 on failure
106  */
107  int set_dioserver_channel(int chnum, int hwchan, int dir, int enab);
108 
109  ///Setup the dioserver
110  /** Sets up the fifo_list, and installs the channels*/
111  int setup_dioserver();
112 
113  /// Take all the actions needed to start the server.
114  virtual int Run();
115 
116  /// Overridden from VisAOApp_base::remote_command
117  std::string remote_command(std::string);
118  /// Overridden from VisAOApp_base::local_command
119  std::string local_command(std::string);
120 
121 };
122 
123 /// Handler to read one of the dio channel fifos
124 int read_diofifo(fifo_channel *fc);
125 
126 } //namespace VisAO
127 
128 #endif //__dioserver_h__
std::string local_command(std::string)
Overridden from VisAOApp_base::local_command.
Definition: dioserver.cpp:218
dioserver_ch diosch[DIO_CHANNELS]
The channels being managed.
Definition: dioserver.h:82
Class to manage access to a digital input/output device.
Definition: dioserver.h:73
dioserver * dios
Whether the channel is enabled or not. Disabled channels (enabled = 0) are ignored.
Definition: dioserver.h:50
int(* diocard_init)(void *)
Initialize the card.
Definition: dioserver.h:90
The standalone VisAO application, does not interface with the AO Supervisor.
std::string fifo_path
The base path names for the fifos.
Definition: dioserver.h:86
Declarations for the standalone VisAO application.
int(* diocard_sd)(void *)
Shutdown the card.
Definition: dioserver.h:91
int init_dioserver()
Initialize the dioserver structure.
Definition: dioserver.cpp:34
int(* diocard_read)(void *card, int ch)
Read a bit from the channel.
Definition: dioserver.h:93
int setup_dioserver()
Setup the dioserver.
Definition: dioserver.cpp:123
int n_enabled
Number of channel enabled.
Definition: dioserver.h:83
int(* diocard_write)(void *card, int ch, int bit)
Write a bit to a channel.
Definition: dioserver.h:92
Holds the information for one digital I/O channel.
Definition: dioserver.h:44
VisAO software utilitites, declarations.
dioserver(int argc, char **argv)
Command line constructor.
Definition: dioserver.cpp:24
void * diocard_info
The generic DIO interface. This pointer is passed unaltered to the diocard_* functions.
Definition: dioserver.h:89
int read_diofifo(fifo_channel *fc)
Handler to read one of the dio channel fifos.
Definition: dioserver.cpp:152
int set_dioserver_channel(int chnum, int hwchan, int dir, int enab)
Set a single channel of the server.
Definition: dioserver.cpp:113
virtual int Run()
Take all the actions needed to start the server.
Definition: dioserver.cpp:228
int enabled
The direction, 0 for output, 1 for input.
Definition: dioserver.h:49
The namespace of VisAO software.
int hwchannel
The software channel number - used to access the channel via the dio fifos.
Definition: dioserver.h:47
std::string remote_command(std::string)
Overridden from VisAOApp_base::remote_command.
Definition: dioserver.cpp:208
int direction
The hardware channel number - used to access the diocard itself.
Definition: dioserver.h:48