Cat
Server_NI6008.h
Go to the documentation of this file.
1 // $Id: $
2 #ifndef INC_SERVER_NI6008_H
3 #define INC_SERVER_NI6008_H 1
4 
5 #include <iostream>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <vector>
9 #include <string.h>
10 #include <time.h>
11 #include <algorithm>
12 
13 #include <sys/utsname.h>
14 #include <unistd.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 
19 #include <NIDAQmxBase.h>
20 
21 std::string itos(int i){
22  char val[20];
23  sprintf(val,"%d",i);
24  std::string str(val);
25  return str;
26 }
27 
28 std::string ftos(float f){
29  char val[20];
30  sprintf(val,"%f",f);
31  std::string str(val);
32  return str;
33 }
34 
36 const std::string& hostName() {
37  static std::string host = "";
38  if ( host == "" ) {
39  char buffer[512];
40  memset(buffer,0,sizeof(buffer));
41  ::gethostname(buffer, sizeof(buffer));
42  host = buffer;
43  }
44  return host;
45 }
46 
48 const std::string& osName() {
49  static std::string osname = "";
50  struct utsname ut;
51  if (uname(&ut) == 0) {
52  osname = ut.sysname;
53  } else {
54  osname = "UNKNOWN";
55  }
56  return osname;
57 }
58 
59 
61 const std::string& osVersion() {
62  static std::string osver = "";
63  struct utsname ut;
64  if (uname(&ut) == 0) {
65  osver = ut.release;
66  } else {
67  osver = "UNKNOWN";
68  }
69  return osver;
70 }
71 
73 const std::string& machineType() {
74  static std::string mach = "";
75  struct utsname ut;
76  if (uname(&ut) == 0) {
77  mach = ut.machine;
78  } else {
79  mach = "UNKNOWN";
80  }
81  return mach;
82 }
83 
85 const std::string& accountName() {
86  static std::string account = "";
87  if ( account == "" ) {
88  const char* acct = ::getlogin();
89  if ( 0 == acct ) acct = ::getenv("LOGNAME");
90  if ( 0 == acct ) acct = ::getenv("USER");
91  account = (acct) ? acct : "Unknown";
92  }
93  return account;
94 }
95 
104  public:
105  Server_NI6008( int );
106  virtual ~Server_NI6008( );
107  void error(const char *);
108  void start();
109  int cmd();
110  int AI(const char*, double[]);
111  int AO(const char*, double[]);
112  int AO0(double);
113  int AO1(double);
114  int DI(const char*, unsigned char[]);
115  int Reset();
116  void status();
117  int send ( std::string word ){
118  /*
119  char buffer[]=word.c_str());
120  std::cout<<"sending : "<<buffer<<" "<<sizeof(buffer)<<std::endl;
121  int size = -1;
122  size = write(newsockfd, buffer, sizeof(buffer));
123  if (size<0) error("ERROR writing to socket");
124  return size;
125  */
126  return 0;
127  }
128 
131 
132  void msgSvc ( MsgLevel , std::string, std::string call = std::string(""));
133 
134  void setLineLength ( int length ) { lineLength = length ; } //< Set Msg line length
135  void setCallSize ( int size ) { callSize = size ; } //< Set Msg call field size
136  void log ( MsgLevel , std::string, std::string );
137 
138  void setAIRange(double min=-10., double max=10.){
139  if (min<-10.0&&max>10.0){
140  msgSvc(FATAL,"Cannot set such range: "+ftos(min)+","+ftos(max),"setAORange");
141  }
142  m_aiMin = min;
143  m_aiMax = max;
144  }
145 
146  void setAORange(double min=0., double max=5.){
147  if (min<-10.0&&max>10.0){
148  msgSvc(FATAL,"Cannot set such range: "+ftos(min)+","+ftos(max),"setAORange");
149  }
150  m_aoMin = min;
151  m_aoMax = max;
152  }
153 
154  void setTimeout(double timeout = 10.0){
155  m_timeout = timeout;
156  }
157 
158  private:
160  std::string ni6008;
161  socklen_t clilen;
162  char buffer[256];
163  struct sockaddr_in serv_addr, cli_addr;
164  int n;
165  std::vector<std::string> colors;
166  int callSize ;
168  std::string logtime();
169 
170  double m_aiMin, m_aiMax;
171  double m_aoMin, m_aoMax;
172  double m_timeout;
173 
174 };
175 
176 #endif // INC_SERVER_NI6008_H
f
Definition: cat.py:54
void error(const char *)
def size
Definition: cat.py:38
const std::string & machineType()
Machine type.
Definition: Server_NI6008.h:73
int AO1(double)
void setLineLength(int length)
const std::string & hostName()
Host name.
Definition: Server_NI6008.h:36
void setTimeout(double timeout=10.0)
std::string itos(int i)
Definition: Server_NI6008.h:21
std::string ftos(float f)
Definition: Server_NI6008.h:28
int AO(const char *, double[])
const std::string & accountName()
User login name.
Definition: Server_NI6008.h:85
const std::string & osVersion()
OS version.
Definition: Server_NI6008.h:61
int DI(const char *, unsigned char[])
virtual ~Server_NI6008()
Standard constructor.
void msgSvc(MsgLevel, std::string, std::string call=std::string(""))
void log(MsgLevel, std::string, std::string)
int AO0(double)
const std::string & osName()
OS name.
Definition: Server_NI6008.h:48
int AI(const char *, double[])
std::string logtime()
int send(std::string word)
std::vector< std::string > colors
struct sockaddr_in serv_addr cli_addr
void setAIRange(double min=-10., double max=10.)
void setAORange(double min=0., double max=5.)
socklen_t clilen
char buffer[256]
std::string ni6008
void setCallSize(int size)