Cat
NI6008.h
Go to the documentation of this file.
1 // $Id: $
2 #ifndef INC_NI6008_H
3 #define INC_NI6008_H 1
4 
5 // #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <netinet/in.h>
12 #include <netdb.h>
13 
14 // Include files
15 #include "StatusCode.h"
16 #include "Element.h"
17 
26 class NI6008 : public Element {
27 public:
28 
30  NI6008( );
31 
32  virtual ~NI6008( );
33 
37  void help() { info("NI6008 "+name()+". No help.","NI6008::help"); };
38 
44  info("NI6008 "+name()+" initialization.","NI6008:init");
45 
46  /* if (m_device==std::string("")){ */
47  /* error("Device has not been device before opening the server connection. Interrupt."); */
48  /* } */
49 
50  m_sockfd = socket(AF_INET, SOCK_STREAM, 0);
51  if (m_sockfd < 0) {
52  error("ERROR opening socket");
53  return StatusCode::FAILURE;
54  }
55  m_server = gethostbyname(m_host.c_str());
56  if (m_server == NULL) {
57  error("ERROR connecting to host "+m_host+".");
58  return StatusCode::FAILURE;
59  }
60  bzero((char *) &m_serv_addr, sizeof(m_serv_addr));
61  m_serv_addr.sin_family = AF_INET;
62  bcopy((char *)m_server->h_addr,
63  (char *)&m_serv_addr.sin_addr.s_addr,
64  m_server->h_length);
65  m_serv_addr.sin_port = htons(m_portno);
66  if (connect(m_sockfd,(struct sockaddr *) &m_serv_addr,sizeof(m_serv_addr)) < 0) {
67  error("ERROR connecting to the socket.");
68  return StatusCode::FAILURE;
69  }
70  info("Starting client, connecting to host "+m_host+" on port "+itos(m_portno));
71  return StatusCode::SUCCESS;
72  }
73 
81  void reset() { info("NI6008 "+name()+" reset.","NI6008::reset");};
82 
86  void update () {info("NI6008 "+name()+". Nothing to do.","NI6008::update");};
87 
91  std::string cmd(std::string, std::string);
92 
96  int port () { return m_portno; }
97  void setPort( int portno ) { m_portno = portno; }
98 
102  // std::string device () { return m_device; }
103  // void setDevice( std::string device ) { m_device = device; }
104 
108  std::string hostname () { return m_host; }
109  void setHostname( std::string host ) { m_host = host; }
110 
111  std::vector<double> ai();
112  int di();
113 
114  StatusCode addDevice( std::string path){
115  m_device.push_back( path );
116  info("Device associated.");
117  return StatusCode::SUCCESS;
118  };
119 
120  std::string device ( unsigned int dev ) {
121  if (dev>m_device.size()-1){
122  warning("Device not defined.");
123  return NULL;
124  }
125  return m_device[dev];
126  }
127 
129  m_device.clear();
130  return StatusCode::SUCCESS;
131  }
132 
133  unsigned int numberOfDevices(){
134  return m_device.size();
135  }
136 
137 protected:
138  int m_portno;
139  std::string m_host;
140  std::vector<std::string> m_device;
141  int m_sockfd;
142  struct sockaddr_in m_serv_addr;
143  struct hostent *m_server;
144  char buffer[256];
145 
146 private:
147 
148 };
149 #endif // INC_NI6008_H
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
char buffer[256]
Definition: NI6008.h:144
void reset()
Definition: NI6008.h:81
void setHostname(std::string host)
Definition: NI6008.h:109
std::vector< double > ai()
std::string device(unsigned int dev)
Definition: NI6008.h:120
std::vector< std::string > m_device
Definition: NI6008.h:140
void update()
Definition: NI6008.h:86
int port()
Definition: NI6008.h:96
void setPort(int portno)
Definition: NI6008.h:97
struct sockaddr_in m_serv_addr
Definition: NI6008.h:142
virtual ~NI6008()
Destructor.
Definition: NI6008.cpp:30
int m_sockfd
Definition: NI6008.h:141
StatusCode addDevice(std::string path)
Definition: NI6008.h:114
int m_portno
Definition: NI6008.h:138
int di()
void error(std::string mymsg)
Definition: Object.h:40
struct hostent * m_server
Definition: NI6008.h:143
std::string cmd(std::string, std::string)
Definition: NI6008.cpp:38
unsigned int numberOfDevices()
Definition: NI6008.h:133
std::string name() const
Definition: Object.h:28
std::string hostname()
Definition: NI6008.h:108
NI6008()
Standard constructor.
Definition: NI6008.cpp:22
StatusCode init()
Definition: NI6008.h:43
StatusCode clearDevice()
Definition: NI6008.h:128
void warning(std::string mymsg)
Definition: Object.h:39
void help()
Definition: NI6008.h:37
std::string m_host
Definition: NI6008.h:139
Definition: NI6008.h:26
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344