epics/trunk/epics_example/myexampleApp/src
--- epics/trunk/epics_example/myexampleApp/src/client_util.c 2014-08-22 01:12:48 UTC (rev 907)
+++ epics/trunk/epics_example/myexampleApp/src/client_util.c 2014-08-22 01:13:48 UTC (rev 908)
@@ -197,6 +197,15 @@
}
if(client_util_debug>1) printf("getXmlDoc: free xml doc done\n");
+ // check that the socket is open
+ if(sockfd<=0) {
+ if(client_util_debug>0) printf("getXmlDoc: socket is not open.\n");
+ //clear the flag
+ xml_poll_status = 0;
+ return;
+ }
+
+
// Do a status and config read to be sure to catch all info
// Need to see exactly how the falgs are set in the return string
// from the server to see what to do here.
@@ -252,7 +261,21 @@
}
+int getXMLPollStatus() {
+ int status = 0;
+ if(xml_string!=NULL) {
+ if(strlen(xml_string)>0) {
+ if(doc!=NULL) {
+ if(xml_root!=NULL) {
+ status = 1;
+ }
+ }
+ }
+ }
+ return status;
+}
+
void writeHybridVSwitch(int sockid, int value, int hyb_id) {
char buffer[256];
char hyb_tag[256];
epics/trunk/epics_example/myexampleApp/src
--- epics/trunk/epics_example/myexampleApp/src/dbSubExample.c 2014-08-22 01:12:48 UTC (rev 907)
+++ epics/trunk/epics_example/myexampleApp/src/dbSubExample.c 2014-08-22 01:13:48 UTC (rev 908)
@@ -21,6 +21,8 @@
int port;
int sockfd = 0;
int counter = 0;
+int status_poll_flag=0;
+int status_flag=0;
const double def_hyb_v = -999.9;
const double def_hyb_i = -999.9;
const double def_hyb_t = -999.9;
@@ -138,7 +140,16 @@
}
+static long subPollStatInit(subRecord *precord) {
+ process_order++;
+ if (mySubDebug) {
+ printf("%d: Record %s called subPollStatInit(%p)\n", process_order, precord->name, (void*) precord);
+ }
+
+ return 0;
+}
+
static void writeHybrid(subRecord* precord,char action[], int id, int feb_id, char ch_name[])
{
if(mySubDebug) {
@@ -509,7 +520,26 @@
+static void updatePollStatusFlag() {
+ // get the status from the client utils
+ int status = getXMLPollStatus();
+ // flip the status flag if xml poll was ok.
+ if (mySubDebug) {
+ printf("updatePollStatusFlag: start status_poll_flag = %d\n",status_poll_flag);
+ printf("updatePollStatusFlag: getXMLPollStatus=%d\n",status);
+ }
+ if(status==1) {
+ if(status_poll_flag==0) {
+ status_poll_flag = 1;
+ } else {
+ status_poll_flag = 0;
+ }
+ }
+ if (mySubDebug) printf("updatePollStatusFlag: end status_poll_flag = %d\n",status_poll_flag);
+}
+
+
static long subPollProcess(subRecord *precord) {
time_t cur_time;
int dt;
@@ -558,22 +588,61 @@
}
- // only poll the xml string if the socket is open
+ // poll the xml string
+ if(sockfd<=0) {
+ printf("subPollProcess: couldn't open a socket (tried over %ds period). Check host and port?\n",dt);
+ }
+
+ if (mySubDebug) printf("subPollProcess: Poll xml string\n");
+
+ getXmlDoc(sockfd,1,0);
+
+ if (mySubDebug) printf("subPollProcess: Poll XML done. Close socket if needed\n");
if(sockfd>0) {
-
- if (mySubDebug) printf("subPollProcess: Poll xml string\n");
-
- getXmlDoc(sockfd,1,0);
-
- if (mySubDebug) printf("subPollProcess: Poll XML done. Close socket\n");
-
sockfd = close_socket(sockfd);
}
- else {
- printf("subPollProcess: couldn't open a socket (tried over %ds period). Check host and port?\n",dt);
+
+ if (mySubDebug) printf("subPollProcess: before update status_poll_flag = %d\n", status_poll_flag);
+
+ updatePollStatusFlag();
+
+ if (mySubDebug) printf("subPollProcess: after update status_poll_flag = %d\n", status_poll_flag);
+
+
+ return 0;
+}
+
+
+
+
+static long subPollStatProcess(subRecord *precord) {
+ process_order++;
+ if (mySubDebug>0) {
+ printf("%d: Record %s called subPollStatProcess(%p)\n",process_order, precord->name, (void*) precord);
+ printf("status_flag: %d\n",status_flag);
+ printf("status_poll_flag: %d\n",status_poll_flag);
+ }
+
+ if(status_flag==status_poll_flag) {
+ if (mySubDebug>0) {
+ printf("same flag: no update was done\n");
+ }
+ precord->val = 0;
+ } else {
+ if (mySubDebug>0) {
+ printf("diff flag: update was done, flip the status_flag\n");
+ }
+ precord->val = 1;
+ // update status_flag
+ if(status_flag==1) {
+ status_flag = 0;
+ } else {
+ status_flag = 1;
+ }
}
+
return 0;
}
@@ -591,3 +660,5 @@
epicsRegisterFunction(subTempProcess);
epicsRegisterFunction(subPollInit);
epicsRegisterFunction(subPollProcess);
+epicsRegisterFunction(subPollStatInit);
+epicsRegisterFunction(subPollStatProcess);