ISIS Logo
ISISBEAM
ISIS Beam Information
1st_nd_post.h
Go to the documentation of this file.
1 #ifndef CONTROLS_H
2 #define CONTROLS_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <string.h>
8 #ifdef __VMS
9 #include <unixio.h>
10 #endif
11 #ifdef _WIN32
12 # include <time.h>
13 # include <winsock2.h>
14 # define INTERNET_SOCKET PF_INET
15 #else
16 #include <unistd.h>
17 # include <sys/socket.h>
18 # include <sys/stat.h>
19 # include <signal.h>
20 # include <fcntl.h>
21 # include <time.h>
22 # include <sys/time.h>
23 # include <netdb.h>
24 # include <netinet/in.h>
25 # include <arpa/inet.h>
26 # define SOCKET int
27 # define INVALID_SOCKET -1
28 # define INTERNET_SOCKET AF_INET
29 # define closesocket close
30 #endif
31 
32 
33 /* port the "isis controls" server posts packets to */
34 #define ND_POST_PORT 7001
35 /* port the "isis instrumentation" server broadcasts packets to */
36 #define ND_MULTICAST_PORT 7002
37 #define ND_BROADCAST_PORT1 7003
38 #define ND_BROADCAST_PORT2 7004
39 #define SHUTTER_SERVER_PORT 7003
40 #define ND_XML_POST_PORT 7005
41 /* multicast address */
42 #define ND_MULTICAST_ADDRESS "224.1.0.2"
43 
44 /*
45  * general data packet definitions
46  */
47 
48 typedef struct
49 {
50  short major;
51  short minor;
52  int len;
53 } data_header;
54 
55 typedef struct
56 {
58  void* data;
59  int check;
61 
62 /*
63  * data for a version 1.0 packet
64  */
65 typedef struct
66 {
67  long beams;
68  long beame1; /* epb1 */
69  long beamt;
70  long beamt2;
71  long inje;
72  long acce;
73  long exte;
74  long repr;
75  long repr2;
76  long mode; /* 0 for 40Hz, 1 for 50Hz */
77  long gms1on; /* 1 if beam enabled to TS1 */
78  long gms2on; /* 1 if beam enabled to TS2 */
79  long shutn;
80  long shuts;
81  long mtemp;
82  long htemp; /* hydrogen moderator */
83  long muon_kicker; /* 0 = supply off, 1 = supply on */
84  long ts1_total; /* uah today * 10*/
85  long ts1_total_yest; /* uah yesterday * 10 */
86  long ts2_total; /* uah today * 10*/
87  long ts2_total_yest; /* uah yesterday * 10 */
88  long e1_shut; /* TS2 shutters: 0:deactivated, 1:open, 2:closed, 3:moving, 4:fault */
89  long e2_shut;
90  long e3_shut;
91  long e4_shut;
92  long e5_shut;
93  long e6_shut;
94  long e7_shut;
95  long e8_shut;
96  long e9_shut;
97  long w1_shut;
98  long w2_shut;
99  long w3_shut;
100  long w4_shut;
101  long w5_shut;
102  long w6_shut;
103  long w7_shut;
104  long w8_shut;
105  long w9_shut;
106  long t2_mtemp1; /* TS2: TE842 * 10 - decoupled methane */
107  long t2_mtemp2; /* TS2: TE852 * 10 - coupled methane */
108  long t2_htemp1; /* TS2: TT706 * 10 - hydrogen */
109  long e1_vat; /* TS2 vacuum VAT status: 0:deactivated, 1:open, 2:closed, 3:moving, 4:fault */
110  long e2_vat;
111  long e3_vat;
112  long e4_vat;
113  long e5_vat;
114  long e6_vat;
115  long e7_vat;
116  long e8_vat;
117  long e9_vat;
118  long w1_vat;
119  long w2_vat;
120  long w3_vat;
121  long w4_vat;
122  long w5_vat;
123  long w6_vat;
124  long w7_vat;
125  long w8_vat;
126  long w9_vat;
127  time_t time;
128  long dmod_runtime; // in minutes
129  long dmod_runtime_lim; // in minutes
130  long dmod_uabeam; // float value, multipled by 100
131  long dmod_annlow1; // Anneal Pressure Flag 0=pressume too low, 1 =OK
132 } data_1_0;
133 
134 typedef struct
135 {
138  int check;
140 
141 /* shutters
142 Where the LSB is bit 1, bit numbers correspond to beam port number N1, N2 etc as follows:
143 
144 
145 shutn 1 SLS
146  2 PRISMA
147  3 SURF
148  4 CRISP
149  5 LOQ
150  6 IRIS/OSIRIS
151  7 POL
152  8 TOSCA
153  9 HET
154 
155 shuts 1 MAPS
156  2 eVS
157  3 SXD
158  4 NO INSTRUMENT
159  5 NO INSTRUMENT
160  6 MARI
161  7 GEM
162  8 HRPD
163  9 PEARL
164 */
165 
166 typedef enum { SLS = 0, PRISMA, SURF, CRISP, LOQ, IRIS, POLARIS, TOSCA, HET } ShutN;
167 
168 /*
169  * If more than one instrument use a beamline, separate the names with "/";
170  * this is the character assumed in shutter_server.c for splitting them up
171  */
172 static const char* ShutN_names[] = {
173  "SLS","PRISMA","SURF","CRISP","LOQ","IRIS_OSIRIS","POL","TOSCA","HET", NULL };
174 
175 typedef enum { MAPS = 0, EVS, SXD, NO_INST1, NO_INST2, MARI, GEM, HRPD, PEARL } ShutS;
176 static const char* ShutS_names[] = {
177  "MAPS","eVS","SXD","NO INSTRUMENT","NO INSTRUMENT","MARI","GEM","HRPD","PEARL", NULL };
178 
179 #define SHUTTER_OPEN(__inst,__var) \
180  ((__var & (1 << __inst)) != 0)
181 
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
185 
186 SOCKET open_connection(const char* servers[], short port);
187 int send_data(SOCKET sd, data_packet_1_0* dp);
188 int send_packet(SOCKET sd, const char* data, int n);
189 int receive_data(SOCKET sd, data_packet_1_0* dp);
190 int receive_data_pattern(SOCKET sd, void* data, int maxdata, const char* pattern);
191 SOCKET setup_socket(unsigned short port, int num_listen);
192 int initialise_data_packet(data_header* dh, short major, short minor);
193 SOCKET setup_broadcast_socket(const char* address, short port, struct sockaddr_in* sockin, int multicast);
194 SOCKET setup_udp_socket(unsigned short port, int multicast);
195 int receive_data_udp(SOCKET sd, char* dp, int n);
196 char* xml_parse(const char* input_string, const char* token);
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif /* CONTROLS_H */
char * xml_parse(const char *input_string, const char *token)
Definition: 1st_nd_lib.c:467
long e6_vat
Definition: 1st_nd_post.h:114
Definition: 1st_nd_post.h:166
Definition: 1st_nd_post.h:166
long w3_vat
Definition: 1st_nd_post.h:120
long w9_shut
Definition: 1st_nd_post.h:105
Definition: 1st_nd_post.h:166
long beamt
Definition: 1st_nd_post.h:69
long inje
Definition: 1st_nd_post.h:71
long e7_vat
Definition: 1st_nd_post.h:115
long e7_shut
Definition: 1st_nd_post.h:94
long repr
Definition: 1st_nd_post.h:74
int send_packet(SOCKET sd, const char *data, int n)
Definition: 1st_nd_lib.c:137
long w2_shut
Definition: 1st_nd_post.h:98
long dmod_runtime
Definition: 1st_nd_post.h:128
Definition: 1st_nd_post.h:166
short major
Definition: 1st_nd_post.h:50
long w3_shut
Definition: 1st_nd_post.h:99
long e9_shut
Definition: 1st_nd_post.h:96
long t2_mtemp2
Definition: 1st_nd_post.h:107
long e8_vat
Definition: 1st_nd_post.h:116
long dmod_annlow1
Definition: 1st_nd_post.h:131
long e6_shut
Definition: 1st_nd_post.h:93
long e5_vat
Definition: 1st_nd_post.h:113
int initialise_data_packet(data_header *dh, short major, short minor)
Definition: 1st_nd_lib.c:129
long w1_vat
Definition: 1st_nd_post.h:118
long ts1_total_yest
Definition: 1st_nd_post.h:85
long dmod_uabeam
Definition: 1st_nd_post.h:130
long e1_shut
Definition: 1st_nd_post.h:88
long t2_mtemp1
Definition: 1st_nd_post.h:106
long mode
Definition: 1st_nd_post.h:76
int receive_data_udp(SOCKET sd, char *dp, int n)
Definition: 1st_nd_lib.c:304
long beams
Definition: 1st_nd_post.h:67
long e5_shut
Definition: 1st_nd_post.h:92
long htemp
Definition: 1st_nd_post.h:82
long e2_shut
Definition: 1st_nd_post.h:89
Definition: 1st_nd_post.h:166
long e2_vat
Definition: 1st_nd_post.h:110
Definition: 1st_nd_post.h:166
long exte
Definition: 1st_nd_post.h:73
long shutn
Definition: 1st_nd_post.h:79
long e9_vat
Definition: 1st_nd_post.h:117
Definition: 1st_nd_post.h:175
data_header header
Definition: 1st_nd_post.h:136
long muon_kicker
Definition: 1st_nd_post.h:83
long w6_vat
Definition: 1st_nd_post.h:123
ShutN
Definition: 1st_nd_post.h:166
long e3_vat
Definition: 1st_nd_post.h:111
long t2_htemp1
Definition: 1st_nd_post.h:108
static const char * ShutN_names[]
Definition: 1st_nd_post.h:172
long repr2
Definition: 1st_nd_post.h:75
long w4_vat
Definition: 1st_nd_post.h:121
Definition: 1st_nd_post.h:166
#define SOCKET
Definition: 1st_nd_post.h:26
long dmod_runtime_lim
Definition: 1st_nd_post.h:129
long ts1_total
Definition: 1st_nd_post.h:84
long gms2on
Definition: 1st_nd_post.h:78
Definition: 1st_nd_post.h:175
Definition: 1st_nd_post.h:175
long shuts
Definition: 1st_nd_post.h:80
SOCKET setup_socket(unsigned short port, int num_listen)
Definition: 1st_nd_lib.c:325
SOCKET setup_broadcast_socket(const char *address, short port, struct sockaddr_in *sockin, int multicast)
Definition: 1st_nd_lib.c:405
int receive_data_pattern(SOCKET sd, void *data, int maxdata, const char *pattern)
Definition: 1st_nd_lib.c:198
Definition: 1st_nd_post.h:175
time_t time
Definition: 1st_nd_post.h:127
long w4_shut
Definition: 1st_nd_post.h:100
Definition: 1st_nd_post.h:166
short minor
Definition: 1st_nd_post.h:51
long w7_vat
Definition: 1st_nd_post.h:124
long mtemp
Definition: 1st_nd_post.h:81
long ts2_total
Definition: 1st_nd_post.h:86
long e4_shut
Definition: 1st_nd_post.h:91
long ts2_total_yest
Definition: 1st_nd_post.h:87
long w8_vat
Definition: 1st_nd_post.h:125
long w7_shut
Definition: 1st_nd_post.h:103
long e3_shut
Definition: 1st_nd_post.h:90
long w9_vat
Definition: 1st_nd_post.h:126
long acce
Definition: 1st_nd_post.h:72
int send_data(SOCKET sd, data_packet_1_0 *dp)
Definition: 1st_nd_lib.c:166
Definition: 1st_nd_post.h:175
long beame1
Definition: 1st_nd_post.h:68
long e8_shut
Definition: 1st_nd_post.h:95
data_header header
Definition: 1st_nd_post.h:57
long w6_shut
Definition: 1st_nd_post.h:102
static const char * ShutS_names[]
Definition: 1st_nd_post.h:176
Definition: 1st_nd_post.h:175
long w8_shut
Definition: 1st_nd_post.h:104
SOCKET setup_udp_socket(unsigned short port, int multicast)
Definition: 1st_nd_lib.c:353
long w2_vat
Definition: 1st_nd_post.h:119
ShutS
Definition: 1st_nd_post.h:175
Definition: 1st_nd_post.h:175
Definition: 1st_nd_post.h:175
Definition: 1st_nd_post.h:175
long gms1on
Definition: 1st_nd_post.h:77
long e4_vat
Definition: 1st_nd_post.h:112
long beamt2
Definition: 1st_nd_post.h:70
long w5_shut
Definition: 1st_nd_post.h:101
long w5_vat
Definition: 1st_nd_post.h:122
SOCKET open_connection(const char *servers[], short port)
Definition: 1st_nd_lib.c:37
Definition: 1st_nd_post.h:166
long w1_shut
Definition: 1st_nd_post.h:97
long e1_vat
Definition: 1st_nd_post.h:109
int receive_data(SOCKET sd, data_packet_1_0 *dp)
Definition: 1st_nd_lib.c:271
Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5