qmca  0.0.20
epicsdouble.cpp
Go to the documentation of this file.
1 #include "epicsdouble.h"
2 #include <QMutexLocker>
3 #include <math.h>
4 #include <stdio.h>
5 
6 EpicsDouble::EpicsDouble(QString pvName, QObject *parent, int dbg)
7  : EpicsObject(pvName, parent, dbg)
8 {
9  if (debug()) {
10  printf("EpicsDouble::EpicsDouble(%s)\n", qPrintable(pvName));
11  }
12 
13  m_Value.value = NAN;
14 }
15 
17 {
18 }
19 
21 {
22  if (!m_HasEventHandler) {
23  SEVCHK(ca_create_subscription(DBR_GR_DOUBLE, 0, m_ChannelID, DBE_VALUE|DBE_ALARM,
24  get_event_handler(), this, &m_EventID), NULL);
25 
27 
28  if (debug()) {
29  printf("Channel %s connected\n", qPrintable(pvName()));
30  }
31  }
32 }
33 
34 void EpicsDouble::event_handler(struct event_handler_args args)
35 {
36  union db_access_val *pb = (union db_access_val *) args.dbr;
37 
38  dbr_gr_double res;
39  memset(&res, 0xff, sizeof(dbr_gr_double));
40 
41  switch (args.type) {
42  case DBR_GR_DOUBLE:
43  res=pb->gdblval;
44  break;
45  default:
46  printf("data type %ld not supported\n", args.type);
47  }
48 
49  EpicsDouble *r = ((EpicsDouble*) args.usr);
50 
51  if (r && r->debug()) {
52  printf("%s Epics Double Event Handler called %ld = %g\n", ca_name(args.chid), args.type, res.value);
53  }
54 
55  ((EpicsDouble*) args.usr) -> changeValue(res);
56 }
57 
58 caEventCallBackFunc *EpicsDouble::get_event_handler()
59 {
61 }
62 
63 void EpicsDouble::changeValue(dbr_gr_double newval)
64 {
65  if (debug()) {
66  printf("ca_put(%d,%p,%g)\n", DBR_DOUBLE, channelID(), newval);
67  }
68 
69 // ca_put(DBR_DOUBLE, channelID(), &newval);
70 
71  QMutexLocker lock(&m_Mutex);
72 
73  int valchanged=0;
74  int grpchanged=0;
75 
76  if (m_Value.value != newval.value) {
77  valchanged=1;
78  }
79 
80  if ((m_Value.status != newval.status) ||
81  (m_Value.severity != newval.severity) ||
82  (m_Value.precision != newval.precision) ||
83  (m_Value.upper_disp_limit != newval.upper_disp_limit) ||
84  (m_Value.lower_disp_limit != newval.lower_disp_limit) ||
85  (m_Value.upper_warning_limit != newval.upper_warning_limit) ||
86  (m_Value.lower_warning_limit != newval.lower_warning_limit) ||
87  (m_Value.upper_alarm_limit != newval.upper_alarm_limit) ||
88  (m_Value.lower_alarm_limit != newval.lower_alarm_limit) ||
89  (strcmp(m_Value.units,newval.units) != 0)) {
90  grpchanged = 1;
91  }
92 
93  m_Value = newval;
94 
95  if (valchanged) {
96  emit valueChanged(m_Value.value);
97  }
98 
99  if (grpchanged) {
101  }
102 }
103 
104 void EpicsDouble::caput(double val)
105 {
106  ca_put(DBR_DOUBLE, channelID(), &val);
107  ca_pend_io(0.5);
108 }
109 
111 {
112  QMutexLocker lock(&m_Mutex);
113 
114  return m_Value.value;
115 }
dbr_gr_double m_Value
Definition: epicsdouble.h:35
double value()
bool m_HasEventHandler
Definition: epicsobject.h:50
QString pvName()
Definition: epicsobject.cpp:30
void changeValue(dbr_gr_double val)
Definition: epicsdouble.cpp:63
evid m_EventID
Definition: epicsobject.h:49
static void event_handler(struct event_handler_args arg)
Definition: epicsdouble.cpp:34
void connected()
Definition: epicsdouble.cpp:20
virtual ~EpicsDouble()
Definition: epicsdouble.cpp:16
void valueChanged()
static QMutex m_Mutex
Definition: epicsobject.h:42
chid channelID()
Definition: epicsobject.cpp:63
void caput(double val)
virtual caEventCallBackFunc * get_event_handler()
Definition: epicsdouble.cpp:58
void valueGraphicChanged(dbr_gr_double val)
chid m_ChannelID
Definition: epicsobject.h:48
void ca_pend_io(double t)
EpicsDouble(QString pvName, QObject *parent=0, int debug=0)
Definition: epicsdouble.cpp:6