ProviewR Programmer's Reference Manual  V6.1.4
ra_appl.cpp
Go to the documentation of this file.
1 
13 #include "pwr.h"
14 #include "co_error.h"
15 #include "co_time.h"
16 #include "rt_gdh.h"
17 #include "rt_appl.h"
18 #include "rt_mh_appl.h"
19 #include "rt_pwr_msg.h"
20 
22 
43 class ra_appl : public rt_appl {
44 private:
45  pwr_tSubid subid[20];
46  int subid_cnt;
47  pwr_tBoolean* dv1_p;
48  pwr_tBoolean* dv2_p;
49  pwr_tBoolean dv2_old;
50  pwr_tFloat32* av1_p;
51 public:
52  ra_appl() : rt_appl("ra_appl", errh_eAnix_appl1), subid_cnt(0)
53  {
54  }
55  void open();
56  void close();
57  void scan();
58  int mh_send(const char* text, mh_eEventPrio prio);
59 };
60 
62 {
63  // Link to database objects
64  pwr_tStatus sts;
65  pwr_tUInt32 active_messages;
66 
67  sts = gdh_RefObjectInfo((char*)"H1-Dv1.ActualValue", (void**)&dv1_p,
68  &subid[subid_cnt++], sizeof(*dv1_p));
69  if (EVEN(sts))
70  throw co_error(sts);
71 
72  sts = gdh_RefObjectInfo((char*)"H1-Dv2.ActualValue", (void**)&dv2_p,
73  &subid[subid_cnt++], sizeof(*dv2_p));
74  if (EVEN(sts))
75  throw co_error(sts);
76 
77  sts = gdh_RefObjectInfo((char*)"H1-Av1.ActualValue", (void**)&av1_p,
78  &subid[subid_cnt++], sizeof(*av1_p));
79  if (EVEN(sts))
80  throw co_error(sts);
81 
82  // Connect to message handler
83  sts = mh_ApplConnect(pwr_cNObjid, (mh_mApplFlags)0, "ra_appl aborted",
84  mh_eEvent_Info, mh_eEventPrio_A,
85  (mh_mEventFlags)(
86  mh_mEventFlags_Bell | mh_mEventFlags_Ack | mh_mEventFlags_Return),
87  "ra_appl aborted", &active_messages);
88  if (EVEN(sts))
89  throw co_error(sts);
90 }
91 
93 {
94  // Unlink to database objects
95  for (int i = 0; i < subid_cnt; i++)
96  gdh_UnrefObjectInfo(subid[i]);
97 }
98 
100 {
101  // Do something
102  if (*dv1_p)
103  *av1_p = 400;
104  else
105  *av1_p = 50;
106 
107  if (*dv2_p && !dv2_old)
108  mh_send("Pump is stopped", mh_eEventPrio_A);
109  dv2_old = *dv2_p;
110 }
111 
113 
117 int ra_appl::mh_send(const char* text, mh_eEventPrio prio)
118 {
119  mh_sApplMessage msg;
120  pwr_tUInt32 id;
121  pwr_tStatus sts;
122 
123  memset(&msg, 0, sizeof(msg));
124  msg.EventPrio = prio;
125  strncpy(msg.EventText, text, sizeof(msg.EventText));
126  strcpy(msg.EventName, "from ra_appl");
127  time_GetTime(&msg.EventTime);
128  msg.EventFlags = (mh_mEventFlags)(
129  mh_mEventFlags_Returned | mh_mEventFlags_NoObject | mh_mEventFlags_Bell);
130  msg.EventType = mh_eEvent_Alarm;
131  msg.SupInfo.SupType = mh_eSupType_None;
132 
133  sts = mh_ApplMessage(&id, &msg);
134  if (EVEN(sts))
135  return sts;
136 
137  return PWR__SUCCESS;
138 }
139 
140 int main()
141 {
142  ra_appl appl;
143 
144  try {
145  appl.init();
146  appl.register_appl("Nodes-opg7-ra_appl");
147 
148  appl.mainloop();
149  } catch (co_error e) {
150  errh_Fatal("Application exception, %s", e.what().c_str());
151  errh_SetStatus(PWR__APPLTERM);
152  exit(0);
153  }
154 }
155 
A simple c++ application example.
Definition: ra_appl.cpp:43
ra_appl()
Pointer to database value Av1.
Definition: ra_appl.cpp:52
Baseclass for applications.
Definition: rt_appl.h:52
Include file for Time management.
void errh_SetStatus(pwr_tStatus sts)
Set application status. The application status is showed in the Node graph. The application can set t...
Definition: rt_errh.c:202
void errh_Fatal(const char *msg,...)
Log a fatal message. The function has a variable argument list similar to sprintf.
Definition: rt_errh.c:364
pwr_tStatus gdh_UnrefObjectInfo(pwr_tSubid subid)
Terminates the subscription defined by the subscription identity.
Definition: rt_gdh.c:3470
pwr_tStatus gdh_RefObjectInfo(char *attributeName, void **objectData, pwr_tSubid *subid, unsigned int sizeOfObjectData)
The routine returns an address to the data that is denoted by Name. The name can be either an object ...
Definition: rt_gdh.c:3426
mh_mApplFlags
Flags governing how mh interacts with the application.
Definition: rt_mh_appl.h:70
pwr_tStatus mh_ApplMessage(pwr_tUInt32 *Id, mh_sApplMessage *Message)
This routine is called by an application to create and send a message.
Definition: rt_mh_appl.c:263
pwr_tStatus mh_ApplConnect(pwr_tObjid ApplObject, mh_mApplFlags Flags, const pwr_tString80 AbortEventName, mh_eEvent AbortEventType, mh_eEventPrio AbortEventPrio, mh_mEventFlags AbortEventFlags, const pwr_tString80 AbortEventText, pwr_tUInt32 *NoOfActMessages)
Connects this application to the local Handler.
Definition: rt_mh_appl.c:112
int time_GetTime(pwr_tTime *ts)
Get current time.
Definition: co_time.c:1427
void close()
Closes the application.
Definition: ra_appl.cpp:92
void scan()
Cyclic function.
Definition: ra_appl.cpp:99
void open()
Initialize the application.
Definition: ra_appl.cpp:61
int mh_send(const char *text, mh_eEventPrio prio)
Send alarm.
Definition: ra_appl.cpp:117
Basic type definitions. This include file contains the Proview basic type definitions.
#define EVEN(a)
Check if value is even.
Definition: pwr.h:623
unsigned int pwr_tUInt32
32-bit unsigned integer type.
Definition: pwr.h:233
unsigned int pwr_tBoolean
Boolean type.
Definition: pwr.h:127
pwr_tRid pwr_tSubid
Subscription identity type.
Definition: pwr.h:312
int pwr_tStatus
Status type.
Definition: pwr.h:284
float pwr_tFloat32
32-bit float.
Definition: pwr.h:131
Include file for the rt_appl class.
Include file for Gdh Global Data Handler.
Include file for MhAppl MessageHandler API.
The structure describing an application message.
Definition: rt_mh_appl.h:87
mh_mEventFlags EventFlags
Definition: rt_mh_appl.h:122
mh_uSupInfo SupInfo
Definition: rt_mh_appl.h:147
pwr_tString80 EventName
Definition: rt_mh_appl.h:129
pwr_tString80 EventText
Definition: rt_mh_appl.h:137
mh_eEventPrio EventPrio
Definition: rt_mh_appl.h:142
pwr_tTime EventTime
Definition: rt_mh_appl.h:124
mh_eEvent EventType
Definition: rt_mh_appl.h:135