40 for(i=0; i < DIO_CHANNELS; i++)
52 std::string visao_root = getenv(
"VISAO_ROOT");
57 pathtmp = (std::string)(ConfigDictionary())[
"fifo_path"];
59 catch(Config_File_Exception)
63 fifo_path = visao_root +
"/" + pathtmp +
"/diofifo";
66 _logger->log(Logger::LOG_LEV_INFO,
"Set dioserver fifo_path: %s",
fifo_path.c_str());
75 int hwcfg, dircfg, encfg;
76 std::vector<std::string> chvec;
78 for(i=0; i < DIO_CHANNELS; i++)
80 snprintf(chcfg, 11,
"DIOCHAN_%02i", i);
83 chvec = (ConfigDictionary())[chcfg];
84 hwcfg = atoi(chvec[0].c_str());
85 dircfg = atoi(chvec[1].c_str());
86 encfg = atoi(chvec[2].c_str());
89 catch(Config_File_Exception)
101 _logger->log(Logger::LOG_LEV_ERROR,
"Could not create status board.");
106 strncpy(bsb->appname, MyFullName().c_str(), 25);
119 _logger->log(Logger::LOG_LEV_INFO,
"Set dioserver channel %i: hw channel=%i dir=%i enab=%i", chnum, hwchan, dir, enab);
135 for(i = 0; i<DIO_CHANNELS; i++)
154 static int ncalled = 0;
163 chnum = diosch->swchannel;
166 fc->server_response[0] =
'\0';
168 rbuffer = fc->server_response;
170 if(totbytes == 0 || rbuffer[0] ==
'\0')
175 if(fc->seqmsg[0] && diosch->dios->get_use_profiler())
177 clock_gettime(CLOCK_REALTIME, &ts);
178 diosch->dios->get_profile()->logseqmsg(fc->seqmsg,
"dio1", &ts);
181 if(diosch->direction == 0)
183 xput = (rbuffer[0] !=
'0');
185 diosch->dios->diocard_write(diosch->dios->diocard_info, chnum, xput);
187 snprintf(wbuffer,
RWBUFF_SZ,
"%i", xput);
192 xput = diosch->dios->diocard_read(diosch->dios->diocard_info, chnum);
194 snprintf(wbuffer,
RWBUFF_SZ,
"%i", xput);
197 if(fc->seqmsg[0] && diosch->dios->get_use_profiler())
199 clock_gettime(CLOCK_REALTIME, &ts);
200 diosch->dios->get_profile()->logseqmsg(fc->seqmsg,
"dio2", &ts);
215 return "UNKOWN COMMAND: " + com +
"\n";
225 return "UNKOWN COMMAND: " + com +
"\n";
234 _logger->log(Logger::LOG_LEV_INFO,
"dioserver setup complete.");
238 _logger->log(Logger::LOG_LEV_ERROR,
"error during dioserver setup.");
245 _logger->log(Logger::LOG_LEV_INFO,
"Initialized dio card.");
249 _logger->log(Logger::LOG_LEV_ERROR,
"Dio card initialization failed.");
251 _logger->log(Logger::LOG_LEV_WARNING,
"DIO card initialization error checking disabled.");
252 std::cerr <<
"DIO card initialization error checking disabled." <<
"\n";
259 global_fifo_list = &
fl;
260 signal(SIGIO, SIG_IGN);
263 _logger->log(Logger::LOG_LEV_INFO,
"fifo_list connected.");
267 _logger->log(Logger::LOG_LEV_ERROR,
"Error connecting the fifo list.");
274 _logger->log(Logger::LOG_LEV_INFO,
"dioserver starting up . . .");
287 pthread_cond_broadcast(&profile->thcond);
297 usleep(signalth_sleeptime);
300 pthread_cond_broadcast(&profile->thcond);
std::string local_command(std::string)
Overridden from VisAOApp_base::local_command.
int fifo_list_do_pending_read(fifo_list *fl)
Runs through the pending reads, dispatching each handler in turn.
Declarations for the dioserver.
int write_fifo_channel(fifo_channel *fc, const char *com, int comlen)
Write data to the output channel.
dioserver_ch diosch[DIO_CHANNELS]
The channels being managed.
fifo_list * global_fifo_list
The global fifo_list, for signal handling.
int read_fifo_channel(fifo_channel *fc)
Read data from the input fifo channel.
dioserver * dios
Whether the channel is enabled or not. Disabled channels (enabled = 0) are ignored.
int(* diocard_init)(void *)
Initialize the card.
The standalone VisAO application, does not interface with the AO Supervisor.
std::string fifo_path
The base path names for the fifos.
void * statusboard_shmemptr
The pointer to the shared memory block for the statusboard.
int(* diocard_sd)(void *)
Shutdown the card.
A structure to hold a list of fifo_channels.
virtual int update_statusboard()
Update the status board.
virtual int setup_baseApp(bool usethreads=false)
Install fifo channels.
int init_dioserver()
Initialize the dioserver structure.
int(* diocard_read)(void *card, int ch)
Read a bit from the channel.
int setup_dioserver()
Setup the dioserver.
int n_enabled
Number of channel enabled.
int setup_fifo_list(int nfifos)
Allocate the fifo_list.
#define STATUS_dioserver
Shared memory key for the dioserver status board.
int(* diocard_write)(void *card, int ch, int bit)
Write a bit to a channel.
Holds the information for one digital I/O channel.
key_t statusboard_shmemkey
The key used to lookup the shared memory.
int TimeToDie
Global set by SIGTERM.
dioserver(int argc, char **argv)
Command line constructor.
fifo_list fl
The list of named-pipe fifos used for inter-process comms.
int RTSIGIO_overflow
flag indicating that the signal queue has overflown.
void * diocard_info
The generic DIO interface. This pointer is passed unaltered to the diocard_* functions.
int read_diofifo(fifo_channel *fc)
Handler to read one of the dio channel fifos.
double pause_time
Time to pause during application main loop.
int set_dioserver_channel(int chnum, int hwchan, int dir, int enab)
Set a single channel of the server.
int create_statusboard(size_t sz)
Creates and attaches to the statusboard shared memory.
#define MAX_FNAME_SZ
The maximum allowed filename length.
virtual int Run()
Take all the actions needed to start the server.
int setup_RTsigio()
Setup SIGIO signal handling using realtime signals.
int connect_fifo_list_nolock()
Connect the fifo_list without exclusive locking.
int enabled
The direction, 0 for output, 1 for input.
The namespace of VisAO software.
int hwchannel
The software channel number - used to access the channel via the dio fifos.
std::string remote_command(std::string)
Overridden from VisAOApp_base::remote_command.
int tot_pending_reads
The total number of pending reads.
int direction
The hardware channel number - used to access the diocard itself.
#define RWBUFF_SZ
The size of the i/o buffer.
int set_fifo_list_channel(fifo_list *fl, int nch, int buffsz, const char *fin, const char *fout, int(*inp_hand)(fifo_channel *), void *adata)
Set the details of one channel in the list.