-
Notifications
You must be signed in to change notification settings - Fork 1
/
alCA.c
794 lines (668 loc) · 25.5 KB
/
alCA.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* alCA.c */
/************************DESCRIPTION***********************************
This file contains routines for channel access.
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "ax.h"
#define DEBUG_CALLBACKS 0
/* global variables */
extern int _global_flag;
extern int _passive_flag;
int toBeConnectedCount = 0;
extern XtAppContext appContext;
static XtIntervalId caTimeoutId = (XtIntervalId) 0;
static unsigned long caDelay = 100; /* ms */
/* forward declarations */
static void alCaNewAlarmEvent(struct event_handler_args args);
static void alCaForcePVValueEvent(struct event_handler_args args);
static void alCaChannelConnectionEvent(struct connection_handler_args args);
static void alCaForcePVConnectionEvent(struct connection_handler_args args);
static void alCaSevrPVConnectionEvent(struct connection_handler_args args);
static void alCaAckPVConnectionEvent(struct connection_handler_args args);
static void alCaAckPVAccessRightsEvent(struct access_rights_handler_args args);
static void alCaChannelAccessRightsEvent(struct access_rights_handler_args args);
static void alCaForcePVAccessRightsEvent(struct access_rights_handler_args args);
static void alCaSevrPVAccessRightsEvent(struct access_rights_handler_args args);
static void alCaUpdate(XtPointer cd, XtIntervalId * id);
static void alCaException(struct exception_handler_args args);
static void alCaHeartbeatPVAccessRightsEvent(struct access_rights_handler_args args);
static void alCaHeartbeatPVConnectionEvent(struct connection_handler_args args);
/*********************************************************************
alCaPend
*********************************************************************/
void alCaPend(double waitSeconds)
{
time_t startTime, currentTime;
currentTime = time(&startTime);
while (toBeConnectedCount > 0 && difftime(currentTime, startTime) < waitSeconds) {
ca_pend_event(.1);
time(¤tTime);
}
}
/*********************************************************************
alCaIsConnected
*********************************************************************/
short alCaIsConnected(chid chid)
{
if (!chid) return FALSE;
if (ca_field_type(chid) == TYPENOTCONN) return FALSE;
else return TRUE;
}
/*********************************************************************
alCaFlushIo
*********************************************************************/
void alCaFlushIo()
{
ca_flush_io();
}
/*********************************************************************
init ca, add excptn handler, reg fd, add timer proc
*********************************************************************/
void alCaInit()
{
int status;
#if DEBUG_CALLBACKS
{
printf("alCaInit: caTimeoutId=%d\n", caTimeoutId);
}
#endif
/* Initialize channel access */
status = ca_task_initialize();
if (status != ECA_NORMAL){
errMsg("ca_task_initialize failed: Return status: %s\n",ca_message(status));
}
/* Register exception handler */
status = ca_add_exception_event(alCaException, NULL);
if (status != ECA_NORMAL){
errMsg("ca_add_exception_event failed: Return status: %s\n",ca_message(status));
}
/* Register file descriptor callback */
status = ca_add_fd_registration(registerCA, NULL);
if (status != ECA_NORMAL){
errMsg("ca_add_fd_registration failed: Return status: %s\n",ca_message(status));
}
/* Start the CA poll and update areas timer proc */
caTimeoutId = XtAppAddTimeOut(appContext, caDelay, alCaUpdate, NULL);
#if DEBUG_CALLBACKS
printf(" caTimeoutId=%d\n", caTimeoutId);
#endif
}
/*********************************************************************
Callback when there is activity on a CA file descriptor
*********************************************************************/
void alCaPoll()
{
#if DEBUG_CALLBACKS
{
static int n = 0;
printf("alCaPoll: n=%d\n", n++);
}
#endif
ca_poll();
}
/*********************************************************************
cancel timer, close channel access
*********************************************************************/
void alCaStop()
{
int status;
/* cancel timeout */
if (caTimeoutId) {
XtRemoveTimeOut(caTimeoutId);
caTimeoutId = (XtIntervalId) 0;
}
/* and close channel access */
status = ca_task_exit();
if (status != ECA_NORMAL){
errMsg("ca_task_exit failed: Return status: %s\n",ca_message(status));
}
}
/*********************************************************************
create chid, start search, add connection event handler, add puser,
add access_rights event handler
*********************************************************************/
void alCaConnectChannel(char *name, chid * pchid, void *puser)
{
int status;
if (strlen(name) <= (size_t) 1) return;
toBeConnectedCount++;
status = ca_search_and_connect(name, pchid, alCaChannelConnectionEvent, puser);
if (status != ECA_NORMAL) {
errMsg("ca_search_and_connect failed for PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
status = ca_replace_access_rights_event(*pchid, alCaChannelAccessRightsEvent);
if (status != ECA_NORMAL) {
errMsg("ca_replace_access_rights_event failed for PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
}
/*********************************************************************
create chid, start search, add connection event handler, add puser,
add access_rights event handler
*********************************************************************/
void alCaConnectForcePV(char *name, chid * pchid, void *puser)
{
int status;
if (strlen(name) <= (size_t) 1) return;
toBeConnectedCount++;
status = ca_search_and_connect(name, pchid, alCaForcePVConnectionEvent, puser);
if (status != ECA_NORMAL){
errMsg("ca_search_and_connect failed for Force PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
status = ca_replace_access_rights_event(*pchid, alCaForcePVAccessRightsEvent);
if (status != ECA_NORMAL){
errMsg("ca_replace_access_rights_event failed for Force PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
}
/*********************************************************************
create chid, start search, add connection event handler, add puser,
add access_rights event handler
*********************************************************************/
void alCaConnectSevrPV(char *name, chid * pchid, void *puser)
{
int status;
if (strlen(name) <= (size_t) 1) return;
toBeConnectedCount++;
status = ca_search_and_connect(name, pchid, alCaSevrPVConnectionEvent, puser);
if (status != ECA_NORMAL){
errMsg("ca_search_and_connect failed for Severity PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
status = ca_replace_access_rights_event(*pchid, alCaSevrPVAccessRightsEvent);
if (status != ECA_NORMAL){
errMsg("ca_replace_access_rights_event failed for Severity PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
}
/*********************************************************************
create chid, start search, add connection event handler, add puser,
add access_rights event handler
*********************************************************************/
void alCaConnectHeartbeatPV(char *name, chid * pchid, void *puser)
{
int status;
if (strlen(name) <= (size_t) 1) return;
toBeConnectedCount++;
status = ca_search_and_connect(name,pchid,alCaHeartbeatPVConnectionEvent,puser);
if (status != ECA_NORMAL){
errMsg("ca_search_and_connect failed for Heartbeat PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
status = ca_replace_access_rights_event(*pchid, alCaHeartbeatPVAccessRightsEvent);
if (status != ECA_NORMAL){
errMsg("ca_replace_access_rights_event failed for Heartbeat PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
}
/*********************************************************************
This is similar to previous function alCaConnectSevrPV
*********************************************************************/
void alCaConnectAckPV(char *name, chid * pchid, void *puser)
{
int status;
if (strlen(name) <= (size_t) 1) return;
toBeConnectedCount++;
status = ca_search_and_connect(name, pchid, alCaAckPVConnectionEvent, puser);
if (status != ECA_NORMAL){
errMsg("ca_search_and_connect failed for Acknowledge PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
status = ca_replace_access_rights_event(*pchid, alCaAckPVAccessRightsEvent);
if (status != ECA_NORMAL){
errMsg("ca_replace_access_rights_event failed for Acknowledge PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
}
/*********************************************************************
clear a channel chid
*********************************************************************/
void alCaClearChannel(chid * pchid)
{
int status;
if (!*pchid) return;
status = ca_clear_channel(*pchid);
if (status != ECA_NORMAL){
errMsg("ca_clear_channel failed for PV %s "
"Return status: %s\n",ca_name(*pchid),ca_message(status));
}
*pchid = NULL;
}
/*********************************************************************
clear event
*********************************************************************/
void alCaClearEvent(evid * pevid)
{
int status;
if (!*pevid) return;
status = ca_clear_event(*pevid);
if (status != ECA_NORMAL){
errMsg("ca_clear_event failed for PV "
"Return status: %s\n",ca_message(status));
}
*pevid = NULL;
}
/*********************************************************************
add channel alarm event handler
*********************************************************************/
void alCaAddEvent(chid chid, evid * pevid, void *clink)
{
int status;
if (!chid) return;
status = ca_add_masked_array_event(DBR_STSACK_STRING, 1,
chid,
alCaNewAlarmEvent,
clink,
(float) 0, (float) 0, (float) 0,
pevid,
DBE_ALARM);
if (status != ECA_NORMAL){
errMsg("ca_add_masked_array_event failed for PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
add forcePV value event handler
*********************************************************************/
void alCaAddForcePVEvent(chid chid, void *userdata, evid * pevid)
{
int status;
if (!chid) return;
status = ca_add_masked_array_event(DBR_DOUBLE, 1,
chid,
alCaForcePVValueEvent,
userdata,
(float) 0, (float) 0, (float) 0,
pevid,
DBE_VALUE);
if (status != ECA_NORMAL){
errMsg("alCaAddForcePVEvent: ca_add_masked_array_event failed for Force PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
send global alarm acknowledgement
*********************************************************************/
void alCaPutGblAck(chid chid, short *psevr)
{
int status;
if (!chid || ca_field_type(chid) == TYPENOTCONN) return;
if (!_global_flag || _passive_flag) return;
status = ca_put(DBR_PUT_ACKS, chid, psevr);
if (status != ECA_NORMAL) {
errMsg("alCaPutGblAck: ca_put alarm acknowledgement failed for PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
global modify acknowledge transients fields
*********************************************************************/
void alCaPutGblAckT(chid chid, short *pstate)
{
int status;
if ( !_global_flag ||_passive_flag) return;
if (!chid || ca_field_type(chid) == TYPENOTCONN) return;
status = ca_put(DBR_PUT_ACKT, chid, pstate);
if (status != ECA_NORMAL) {
errMsg("alCaPutGblAckT: ca_put acknowledge transients failed for PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
alCaPutSevValue - write severity value to sevrPV
*********************************************************************/
void alCaPutSevrValue(chid chid, short *psevr)
{
int status;
#if DEBUG_CALLBACKS
{
printf("alCaPutSevrValue: name=%s value=%d\n", ca_name(chid), *psevr);
}
#endif
if (!_global_flag || _passive_flag) return;
if (!chid || ca_field_type(chid) == TYPENOTCONN) return;
status = ca_put(DBR_SHORT, chid, psevr);
if (status != ECA_NORMAL) {
errMsg("alCaPutSevrValue: ca_put failed for Severity PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
This function is the same as prev. but for ackPV record.
*********************************************************************/
void alCaPutAckValue(chid chid, short *psevr)
{
int status;
#if DEBUG_CALLBACKS
{
printf("alCaPutAckValue: name=%s value=%d\n", ca_name(chid), *psevr);
}
#endif
if (!chid || ca_field_type(chid) == TYPENOTCONN) return;
/* status = ca_put(ca_field_type(chid), chid, psevr); */
status = ca_put(DBR_ENUM, chid, psevr);
if (status != ECA_NORMAL) {
errMsg("alCaPutAckValue: ca_put failed for Acknowledge PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
alCaPutHeartbeatValue - write to heartbeatPV
*********************************************************************/
void alCaPutHeartbeatValue(chid chid, short *pvalue)
{
int status;
if (!_global_flag || _passive_flag) return;
if (!chid || ca_field_type(chid) == TYPENOTCONN) return;
status = ca_put(DBR_SHORT, chid, pvalue);
if (status != ECA_NORMAL) {
errMsg("alCaPutHeartbeatValue: ca_put failed for Heartbeat PV %s "
"Return status: %s\n",ca_name(chid),ca_message(status));
}
}
/*********************************************************************
channel alarm Event
*********************************************************************/
static void alCaNewAlarmEvent(struct event_handler_args args)
{
int stat, sevr;
int ackt, acks;
char value[MAX_STRING_SIZE];
if (args.status != ECA_NORMAL) {
errMsg("alCaNewAlarmEvent failed: Return status: %s "
" for PV %s\n",ca_message(args.status),ca_name(args.chid));
return;
}
stat = ((struct dbr_stsack_string *) args.dbr)->status;
sevr = ((struct dbr_stsack_string *) args.dbr)->severity;
acks = ((struct dbr_stsack_string *) args.dbr)->acks;
ackt = ((struct dbr_stsack_string *) args.dbr)->ackt;
if (stat >= ALARM_NSTATUS) stat = ALARM_NSTATUS-1;
if (stat < 0) stat = 0;
if (sevr >= ALARM_NSEV) sevr = ALARM_NSEV-1;
if (sevr < 0) sevr = 0;
if (acks >= ALARM_NSEV) acks = ALARM_NSEV-1;
if (acks < 0) acks = 0;
if (ackt != TRUE && ackt != FALSE) ackt = TRUE;
strcpy(value, ((struct dbr_stsack_string *) args.dbr)->value);
alNewEvent(stat, sevr, acks, ackt, value, args.usr);
}
/*********************************************************************
channel access_rights event handler
*********************************************************************/
static void alCaChannelAccessRightsEvent(struct access_rights_handler_args args)
{
if (ca_field_type(args.chid) == TYPENOTCONN) return;
if (!ca_read_access(args.chid)) {
alNewEvent(NO_READ_ACCESS, ERROR_STATE, 0, -1, "0", ca_puser(args.chid));
errMsg("No read access for channel %s\n",ca_name(args.chid));
}
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
alNewEvent(NO_WRITE_ACCESS, ERROR_STATE, 0, -1, "0", ca_puser(args.chid));
errMsg("No write access for channel %s\n",ca_name(args.chid));
}
}
/*********************************************************************
forcePV access_rights event handler
*********************************************************************/
static void alCaForcePVAccessRightsEvent(struct access_rights_handler_args args)
{
if (ca_field_type(args.chid) == TYPENOTCONN) return;
if (!ca_read_access(args.chid)) {
errMsg("No read access for Force PV %s\n",ca_name(args.chid));
}
}
/*********************************************************************
sevrPV access_rights event handler
*********************************************************************/
static void alCaSevrPVAccessRightsEvent(struct access_rights_handler_args args)
{
if (ca_field_type(args.chid) == TYPENOTCONN) return;
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
errMsg("No write access for Severity PV %s\n",ca_name(args.chid));
}
}
/*********************************************************************
this is same as previous function but for .DESC-field.
*********************************************************************/
static void alCaAckPVAccessRightsEvent(struct access_rights_handler_args args)
{
if (ca_field_type(args.chid) == TYPENOTCONN) return;
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
errMsg("No write access for Acknowledge PV %s\n",ca_name(args.chid));
}
}
/*********************************************************************
heartbeatPV access_rights event handler
*********************************************************************/
static void alCaHeartbeatPVAccessRightsEvent(struct access_rights_handler_args args)
{
if (ca_field_type(args.chid) == TYPENOTCONN) return;
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
errMsg("No write access for Heartbeat PV %s\n",ca_name(args.chid));
alHeartbeatStop(ca_puser(args.chid));
} else {
alHeartbeatStart(ca_puser(args.chid));
}
}
/*********************************************************************
channel connection event handler
*********************************************************************/
static void alCaChannelConnectionEvent(struct connection_handler_args args)
{
if (args.op == CA_OP_CONN_UP) {
toBeConnectedCount--;
alConnectEvent(ca_puser(args.chid));
if (!ca_read_access(args.chid)) {
alNewEvent(NO_READ_ACCESS, ERROR_STATE, 0, -1, "0", ca_puser(args.chid));
errMsg("No read access for channel %s\n",ca_name(args.chid));
} else if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
alNewEvent(NO_WRITE_ACCESS, ERROR_STATE, 0, -1, "0", ca_puser(args.chid));
errMsg("No write access for channel %s\n",ca_name(args.chid));
}
} else if (args.op == CA_OP_CONN_DOWN) {
alNewEvent(NOT_CONNECTED, ERROR_STATE, 0, -1, "0", ca_puser(args.chid));
} else {
errMsg("Unknown connection event for channel %s\n",ca_name(args.chid));
}
}
/*********************************************************************
forcePV connection event handler
*********************************************************************/
static void alCaForcePVConnectionEvent(struct connection_handler_args args)
{
if (args.op == CA_OP_CONN_UP) {
toBeConnectedCount--;
if (!ca_read_access(args.chid)) {
errMsg("No read access for Force PV %s\n",ca_name(args.chid));
}
} else if (args.op == CA_OP_CONN_DOWN) {
errMsg("Not Connected: Force PV %s for %s\n",
ca_name(args.chid),(char *)ca_puser(args.chid));
} else {
errMsg("Unknown connection event Force PV %s for %s\n",
ca_name(args.chid),(char *)ca_puser(args.chid));
}
}
/*********************************************************************
sevrPV connection event handler
*********************************************************************/
static void alCaSevrPVConnectionEvent(struct connection_handler_args args)
{
if (args.op == CA_OP_CONN_UP) {
toBeConnectedCount--;
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
errMsg("No write access for Severity PV %s\n",ca_name(args.chid));
}
} else if (args.op == CA_OP_CONN_DOWN) {
errMsg("Not Connected: Severity PV %s for %s\n",
ca_name(args.chid),(char *)ca_puser(args.chid));
} else {
errMsg("Unknown connection event Severity PV %s for %s\n",
ca_name(args.chid),(char *)ca_puser(args.chid));
}
}
/*********************************************************************
ackPV connection event handler
*********************************************************************/
static void alCaAckPVConnectionEvent(struct connection_handler_args args)
{
if (args.op == CA_OP_CONN_UP) {
toBeConnectedCount--;
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
errMsg("No write access for Acknowledge PV %s\n",ca_name(args.chid));
}
} else if (args.op == CA_OP_CONN_DOWN) {
errMsg("Not Connected: Acknowledge PV %s for %s\n",
ca_name(args.chid),(char *)ca_puser(args.chid));
} else {
errMsg("Unknown connection event Acknowledge PV %s for %s\n",
ca_name(args.chid),(char *)ca_puser(args.chid));
}
}
/*********************************************************************
heartbeatPV connection event handler
*********************************************************************/
static void alCaHeartbeatPVConnectionEvent(struct connection_handler_args args)
{
if (args.op == CA_OP_CONN_UP) {
toBeConnectedCount--;
if (!ca_write_access(args.chid) && _global_flag && !_passive_flag) {
errMsg("No write access for Heartbeat PV %s\n",ca_name(args.chid));
alHeartbeatStop(ca_puser(args.chid));
} else {
alHeartbeatStart(ca_puser(args.chid));
}
} else if (args.op == CA_OP_CONN_DOWN) {
errMsg("Not Connected: Heartbeat PV %s\n",ca_name(args.chid));
alHeartbeatStop(ca_puser(args.chid));
} else {
errMsg("Unknown connection event Heartbeat PV %s\n",ca_name(args.chid));
}
}
/*********************************************************************
group forcePV value event handler
*********************************************************************/
static void alCaForcePVValueEvent(struct event_handler_args args)
{
if (args.status == ECA_NORMAL) {
alForcePVValueEvent(args.usr, *(double *) args.dbr);
} else {
errMsg("alCaForcePVValueEvent failed: Return status: %s "
" for PV %s\n",ca_message(args.status),ca_name(args.chid));
}
}
/*********************************************************************
alCaUpdate -- Timer proc to update screen
*********************************************************************/
static void alCaUpdate(XtPointer cd, XtIntervalId * id)
{
#if DEBUG_CALLBACKS
{
static int n = 0;
printf("alCaUpdate: n=%d\n", n++);
}
#endif
ca_poll();
alUpdateAreas();
caTimeoutId = XtAppAddTimeOut(appContext, caDelay, alCaUpdate, NULL);
}
/*********************************************************************
ca exception messages
*********************************************************************/
static void alCaException(struct exception_handler_args args)
{
#define MAX_EXCEPTIONS 25
static int nexceptions = 0;
static int ended = 0;
if (ended) return;
if (nexceptions++ > MAX_EXCEPTIONS) {
ended = 1;
errMsg("Channel Access Exception: Too many exceptions [%d]\n",
MAX_EXCEPTIONS);
ca_add_exception_event(NULL, NULL);
return;
}
errMsg("Channel Access Exception: %s Context: %s\n",
ca_message(args.stat) ? ca_message(args.stat) : "Unavailable",
args.ctx ? args.ctx : "Unavailable");
}
static void description_callback (struct event_handler_args args);
/*********************************************************************
getDescriptionRecord
*********************************************************************/
void getDescriptionRecord(char *name,char *description,chid descriptionFieldCaId)
{
int status;
static char desc_name[64];
memset(desc_name,0,64);
strcpy(desc_name,name);
strcat(desc_name,".DESC");
status = ca_search(desc_name, &descriptionFieldCaId);
if (status != ECA_NORMAL) {
SEVCHK(status," CAN'T search description field\n");
fprintf(stderr,"%s: CAN'T search description field\n",desc_name);
*description=0;
return;
}
/* status = ca_pend_io(0.5); */
status = ca_pend_io(5.0);
ca_pend_event(.0001);
if (status != ECA_NORMAL)
{
SEVCHK(status," CAN'T pend description field\n");
fprintf(stderr,"%s: CAN'T pend description field\n",desc_name);
*description=0;
return;
}
status = ca_array_get (DBR_STRING,1,descriptionFieldCaId,description);
if (status != ECA_NORMAL)
{
SEVCHK(status," CAN'T get description field\n");
fprintf(stderr,"%s: CAN'T get description field\n",desc_name);
*description=0;
return;
}
/* status = ca_pend_io(0.5); */
status = ca_pend_io(5.0);
ca_pend_event(.0001);
if (status != ECA_NORMAL)
{
SEVCHK(status," CAN'T pend description field again \n");
fprintf(stderr,"%s: CAN'T pend description field again \n",name);
*description=0;
return;
}
status=ca_add_event
(DBR_STRING,descriptionFieldCaId,description_callback,description,NULL);
/* status = ca_pend_io(0.5); */
status = ca_pend_io(5.0);
ca_pend_event(.0001);
}
/*********************************************************************
description_callback
*********************************************************************/
static void description_callback (struct event_handler_args args)
{
char *string= (char *)args.dbr;
char * descr = (char *)args.usr;
if(strlen(string) > 127) return; /* May be garbage. Avoid overwriting*/
strcpy(descr,string);
}