Commit in epics/trunk/epics_example/myexampleApp on MAIN
Db/Makefile+1766 -> 767
  /dbFebTemp.db+2-1766 -> 767
src/Makefile+2-1766 -> 767
   /client_util.c+277-215766 -> 767
   /dbSubExample.c+57-9766 -> 767
   /dbSubExample.dbd+2766 -> 767
+341-226
6 modified files
Never ending parser story. Added global poll function for status and config.

epics/trunk/epics_example/myexampleApp/Db
Makefile 766 -> 767
--- epics/trunk/epics_example/myexampleApp/Db/Makefile	2014-07-14 22:00:35 UTC (rev 766)
+++ epics/trunk/epics_example/myexampleApp/Db/Makefile	2014-07-15 05:50:27 UTC (rev 767)
@@ -18,6 +18,7 @@
 DB += hybLV.db
 DB += dbHybLV.db
 DB += dbFebTemp.db
+DB += dbSVT.db
 
 #----------------------------------------------------
 # If <anyname>.db template is not named <anyname>*.template add

epics/trunk/epics_example/myexampleApp/Db
dbFebTemp.db 766 -> 767
--- epics/trunk/epics_example/myexampleApp/Db/dbFebTemp.db	2014-07-14 22:00:35 UTC (rev 766)
+++ epics/trunk/epics_example/myexampleApp/Db/dbFebTemp.db	2014-07-15 05:50:27 UTC (rev 767)
@@ -1,4 +1,5 @@
 
+
 record(sub,SVT:lv:fe:0:axixadc:t_rd_sub)
 {
     field(INAM,"subTempInit")
@@ -7,7 +8,7 @@
 }
 
 record(ai, SVT:lv:fe:0:anap:i_rd) {
-  field(SCAN, "5 second")
+  field(SCAN, "PASSIVE")
   field(FLNK,"SVT:lv:fe:0:axixadc:t_rd_sub PP")
   field(INP, "SVT:lv:fe:0:axixadc:t_rd_sub CPP")
   field(DTYP,"Soft Channel")

epics/trunk/epics_example/myexampleApp/src
Makefile 766 -> 767
--- epics/trunk/epics_example/myexampleApp/src/Makefile	2014-07-14 22:00:35 UTC (rev 766)
+++ epics/trunk/epics_example/myexampleApp/src/Makefile	2014-07-15 05:50:27 UTC (rev 767)
@@ -60,7 +60,8 @@
 myexample_LIBS += myexampleSupport
 #myexample_LIBS += mysvtdaq
 #mysvtdaq_DIR += /root/daq/lib
-xml2_DIR += /usr/lib  
+#xml2_DIR += /usr/lib  
+xml2_DIR += /usr/lib64  
 xml2_LIBS += xml2  
 myexample_LIBS += xml2
 #myexample_LIBS += m

epics/trunk/epics_example/myexampleApp/src
client_util.c 766 -> 767
--- epics/trunk/epics_example/myexampleApp/src/client_util.c	2014-07-14 22:00:35 UTC (rev 766)
+++ epics/trunk/epics_example/myexampleApp/src/client_util.c	2014-07-15 05:50:27 UTC (rev 767)
@@ -4,9 +4,14 @@
 
 const unsigned int BUFFER_SIZE = 256;
 const unsigned int MAX_BUFFERS = 1000;
-const unsigned int XML_STRING_MAX = 65536*10;
+const unsigned int XML_STRING_MAX = 65536;
 int client_util_debug = 0;
+char *xml_string_global = NULL;
+xmlDoc* doc = NULL;
+xmlNode* xml_root = NULL;
 
+
+
 double extractTempValFromString(char value[]) {
   double t = 0.0;
   char* p_start = strstr(value,"C (");
@@ -114,15 +119,70 @@
 }
 
 
+
+void pollXmlStr(int sockfd) {
+  if(client_util_debug!=0) printf("pollXmlStr\n");
+  //clear old documents
+  if(client_util_debug!=0) printf("free xml string\n");
+  if(xml_string_global!=NULL) {
+    free(xml_string_global);
+  }
+  if(client_util_debug!=0) printf("free xml string done\n");
+  if(client_util_debug!=0) printf("free xml doc\n");
+  if(doc!=NULL) {
+    xmlFreeDoc(doc);
+    xmlCleanupParser();
+    doc=NULL;
+    xml_root=NULL;
+  }
+  if(client_util_debug!=0) printf("free xml doc done\n");
+
+  if(client_util_debug!=0) printf("ReadConfig\n");
+
+  writeReadConfig(sockfd);
+  
+  if(client_util_debug!=0) printf("Before reading xml string (%p)\n",xml_string_global);
+
+  read_system_xml_string4(sockfd);
+
+  if(client_util_debug!=0) printf("After reading xml string (%p)\n",xml_string_global);
+
+  if(xml_string_global!=NULL) {
+    if(client_util_debug!=0) printf("create xml document from xml strlen %ld\n",strlen(xml_string_global));
+    if(strlen(xml_string_global)>0) {
+      doc = xmlReadMemory(xml_string_global,strlen(xml_string_global),"noname.xml",NULL,0);
+      if(client_util_debug!=0) printf("xml doc done %p\n",doc);
+      if(doc!=NULL) {
+	xml_root = xmlDocGetRootElement(doc);
+	if(xml_root!=NULL) {
+	  if(client_util_debug!=0) printf("found xml_root name %s\n",(xml_root)->name);
+	}
+      } else {
+	if(client_util_debug!=0) printf("problem building xml doc %p\n",doc);	
+      }
+    } else {
+      if(client_util_debug!=0) printf("ERROR: xml_string has zero length!\n");	
+    }
+  } else {
+    if(client_util_debug!=0) printf("ERROR: xml_string is NULL!\n");	
+  }
+    
+}
+
+
+
 void getSystemDOM(int* sockfd, xmlDoc** document, xmlNode** root){
+
+/*
   if(client_util_debug!=0) printf("getSystemDOM\n");
   //int debug = 0;
-  char xml_string[XML_STRING_MAX];
-  read_system_xml_string3(sockfd,xml_string,XML_STRING_MAX);
-  //read_system_xml_string2(sockfd,xml_string,300*256);
-  if(client_util_debug!=0) printf("Got %d long xml string:\n\n%s\n",strlen(xml_string),xml_string);
-  if(client_util_debug!=0) printf("create xml document\n");
-  if(xml_string!=NULL) {
+  free_xml_string();
+  if(client_util_debug!=0) printf("Before reading xml string (%p)\n",xml_string_global);
+  read_system_xml_string4(sockfd);
+  //read_system_xml_string2(sockfd,xml_string,300*256);  
+  if(client_util_debug!=0) printf("After reading xml string (%p)\n",xml_string_global);
+  if(xml_string_global!=NULL) {
+    if(client_util_debug!=0) printf("create xml document from xml strlen %ld\n",strlen(xml_string_global));
     if(strlen(xml_string)>0) {
       *document = xmlReadMemory(xml_string,strlen(xml_string),"noname.xml",NULL,0);
       if(client_util_debug!=0) printf("xml doc done %p\n",*document);
@@ -135,15 +195,16 @@
 	if(client_util_debug!=0) printf("problem building xml doc %p\n",*document);	
       }
     } else {
-      if(client_util_debug!=0) printf("ERROR: xml_string is zero length!\n");	
+      if(client_util_debug!=0) printf("ERROR: xml_string has zero length!\n");	
     }
   } else {
-    if(client_util_debug!=0) printf("ERROR: xml_string is NULL!\n");	
+   if(client_util_debug!=0) printf("ERROR: xml_string is NULL!\n");	
   }
-
+*/  
 }
 
 
+
 void writeCalDelay(int* sockfd,char value[],const unsigned int MAX) {
   
   char buffer[256];
@@ -240,6 +301,24 @@
   xmlCleanupParser();
 }
 
+void readXadcT(int feb_id, char value[],const unsigned int MAX) {
+  char tag[] = "system:status:FrontEndTestFpga:FebCore:AxiXadc:Temperature";
+  if(client_util_debug!=0) printf("readAxiXadcT: get DOM\n");
+  if(doc==NULL) {
+    printf("couldn't get xml document %p\n",doc);
+    return;
+  }
+  if(xml_root==NULL) {
+    printf("couldn't get root from document\n");
+    return;
+  }  
+  if(client_util_debug!=0) printf("retrieve value\n");
+  retrieveValue(doc,xml_root,tag,value,MAX);
+  if(client_util_debug!=0) printf("free the xml\n");
+  //xmlFreeDoc(document);
+  //xmlCleanupParser();
+}
+
 void readHybridI(int sockfd,int feb_id, int hyb_id,char ch_name[], char value[],const unsigned int MAX) {
   char tag[256];
   sprintf(tag,"system:status:FrontEndTestFpga:FebCore:PowerMonitor:Hybrid%d_%s_Current",hyb_id,ch_name);
@@ -303,20 +382,30 @@
 
 
 void read_system_xml_string3(int* socketfd, char buffer[], const int MAX) {
+  printf("read xml3 buffer at %p and buffer length %d\n",buffer,MAX);
   const unsigned int READ_BUFFER_SIZE = 65536;
   const float wait_interval_usec = 100000;  
   char buffer_read[MAX];
   char buf[READ_BUFFER_SIZE];
   int read_i = 0;
   int read_n;
-  int debug = 0;
+  int debug = client_util_debug;
   int n_endings = 0;
   int offset = 0;
+  printf("time\n");
   clock_t start_time;
   clock_t diff;
   //reset
-  bzero(buffer,MAX);
-  if(debug>0) printf("read xml3\n");
+  printf(" reset buffer1\n");
+  //bzero(buffer_read,MAX);
+  memset(buffer_read,0,MAX);
+  printf(" reset buffer2\n");
+  bzero(buf,READ_BUFFER_SIZE);
+  printf(" reset buffer3\n");
+  //bzero(buffer,MAX);
+  memset(buffer,0,MAX);
+  //if(debug>0) 
+  printf("read xml3 debug=%d\n",debug);
   start_time = clock();
   diff = (start_time - start_time);
 
@@ -357,7 +446,7 @@
       char *pch;
       pch = strchr(buf,'\f');
       while(pch!=NULL) {
-	if(debug>0) printf("found ending at %p (array index %d) in this buf!\n",pch,pch-buf);
+	if(debug>0) printf("found ending at %p (array index %ld) in this buf!\n",pch,pch-buf);
 	n_endings++;
 	pch = strchr(pch+1,'\f');
       }
@@ -424,16 +513,16 @@
     //char* end2 = strchr(buffer_read,'\f');
     char* end2 = NULL;
     if(start!=NULL) {
-      if(debug!=0) printf("\nstart at %p offset %d\n",start,start-buffer_read);
+      if(debug!=0) printf("\nstart at %p offset %ld\n",start,start-buffer_read);
       if(end2!=NULL) {
-	if(debug!=0) printf("\n end2 at %p offset %d\n",end2,end2-buffer_read);
+	if(debug!=0) printf("\n end2 at %p offset %ld\n",end2,end2-buffer_read);
       }
       char* end = strchr(start,'\f');
       if(end!=NULL) {
 	if(debug!=0) printf("\nend at %p\n",end);
 	memcpy(buffer,start,end-start);
 	buffer[end-(start+1)+1] = '\0'; // terminate it
-	if(debug!=0) printf("\ncopied %d chars to %p\n%s\n",end-(start+1),buffer,buffer);
+	if(debug!=0) printf("\ncopied %ld chars to %p\n%s\n",end-(start+1),buffer,buffer);
       } else {
 	if(debug!=0) printf("\n no end found\n");
       }
@@ -450,238 +539,211 @@
 
 
 
+int findSystemStr(char* buf, const int MAX, char** start) {
+  if(client_util_debug!=0) printf("finding system string from %p and %d chars len with start at %p\n",buf,MAX,*start);
+  char* s = strstr(buf,"<system>");  
+  if(s!=NULL) {
+    char* e = strstr(s,"</system>");
+    if(e!=NULL) {	
+      e = e + strlen("</system>");
+      *start = s;
+      long int l = e-s;
+      if(client_util_debug!=0) printf("found s at %p and e at %p and *start at %p with len %ld \n",s,e,*start,l);
+      return (int)l;
+    }
+  }
+  return -1;
+}
 
 
-void read_system_xml_string2(int* socketfd, char buffer[], const int MAX) {
-  const unsigned int READ_BUFFER_SIZE = 256;
-  char buffer_read[MAX];
-  char buf[READ_BUFFER_SIZE];
+
+
+void read_system_xml_string4(int socketfd) {
+  const float wait_interval_usec = 100000;  
+  char* buf = NULL;
+  char* buf_more = NULL;
+  int buf_len = 0;
   int read_i = 0;
   int read_n;
-  int debug = 1;
+  int debug = client_util_debug;
   int n_endings = 0;
-  int offset = 0;
-  //reset
-  bzero(buffer,MAX);
-  if(debug>0) printf("read xml2\n");
+  clock_t start_time;
+  clock_t diff;
+  char *pch;
+  if(xml_string_global!=NULL) {
+    if(debug!=0) printf("xml string is not NULL in read_system_xml_string4 so clear it!\n");
+    //exit(1);
+  }
+  if(client_util_debug!=0) printf("xml_string at %p \n",xml_string_global);
+  start_time = clock();
+  diff = (start_time - start_time);
+  
+  if(debug>0) printf("start_time at %f clocks\n",(float)start_time);
+  
+  while(((float)(diff/CLOCKS_PER_SEC))<5.0) { 
+    if(debug>0) printf("at read_i %d clocks %f time %f\n",read_i,(float)diff,(float)((float)diff)/CLOCKS_PER_SEC);
+    
+    //bzero(buf,READ_BUFFER_SIZE);
+    
+    read_n = 0;
+    ioctl(socketfd, FIONREAD, &read_n);
+    
+    if(debug>0) {
+      printf("%d available on socket\n",read_n);
+    }
+    
+    if(read_n>0) {      
+      
+      
+      // allocate memory needed
+      if(debug>0) printf("Allocate %d array\n",read_n);      
+      
+      if(buf_more!=NULL) {
+	printf("buf_more is not null!\n");
+	exit(1);
+      }
+      
+      buf_more = (char*) calloc(read_n+1,sizeof(char));
+      
+      if(debug>0) printf("Allocated buf_more array at %p strlen %ld with %d length \n",buf_more,strlen(buf_more),(int)sizeof(char)*(read_n+1));      
+      
+      read_n = read(socketfd,buf_more,read_n);
+      
+      if(debug>0) printf("read_n %d from socket and buf_more strlen %ld\n",read_n,strlen(buf_more));
+      
+      if (read_n < 0) {
+	printf("ERROR reading from socket");
+	exit(1);
+      }
+      
+      //fix terminations
+      int k;
+      for(k=0;k<read_n;++k) {
+      	//printf("'%c'\n",buf_more[k]);
+      	if(buf_more[k]=='\0') {
+      	  if(debug!=0) printf("fix termination at idx %d in this buf_more!!!\n",k);
+	  buf_more[k]=' ';
+      	}
+      }
+      
+      if(debug>0) printf("read_n %d from socket and fixed buf_more strlen %ld:\n%s\n",read_n,strlen(buf_more),buf_more);
+      
+      pch = strchr(buf_more,'\f'); 
+      while(pch!=NULL) { 
+	if(debug>0) printf("found ending at %p (array index %ld) in this buf!\n",pch,pch-buf_more); 
+	n_endings++; 
+	pch = strchr(pch+1,'\f'); 
+      } 
+      
 
-  while(read_i<10000) { // some large number to avoid problems
-    if(debug>0) printf("at read_i %d\n",read_i);
+      // copy to other buffer      
+      if(debug>0) printf("Copy %d to other buffer \n",read_n);      
+      
+      
+      if(debug>0) printf("buf at %p before realloc\n",buf);      
+      buf = (char*) realloc(buf,sizeof(char)*(buf_len+read_n));
+      if(buf==NULL) {
+	printf("failed to allocated more buf\n");
+	if(buf_more==NULL) {
+	  free(buf_more);
+	}
+	exit(1);
+      }
+      
+      if(debug>0) printf("Allocated longer buf at %p and copy to pointer %p (offset= %d) \n",buf,buf+buf_len,buf_len);      
+      
+      memcpy(buf+buf_len,buf_more,sizeof(char)*read_n);
 
-    //strcpy(buffer_read_overlap,buffer_read);//,READ_BUFFER_SIZE); 
-    bzero(buf,READ_BUFFER_SIZE);
+      if(debug>0) printf("memcpy done\n");
+      
+      //update the buffer length
+      buf_len += read_n;
 
-    if(debug>0) printf("read from socket\n");
+      //terminate 
+      //buf[buf_len-1] = '\0';
+      
+      if(debug>0) printf("free buf_more\n");
+      
+      // free buffer
+      if(buf_more!=NULL) {
+	free(buf_more);
+	buf_more=NULL;
+      }
 
-    read_n = read((*socketfd),buf,(READ_BUFFER_SIZE-1));
-    if(debug>0) printf("read_n %d\n",read_n);
+      if(debug>0) printf("end of read_i %d with buf strlen %ld\n",read_i,strlen(buf));
 
-    if (read_n < 0) 
-      error("ERROR reading from socket");
-    //printf("buffer_read_overlap after clearing the old buffer:\n%s\nbuffer below:\n",buffer_read_overlap);
-    if(debug!=0) printf("%s\n",buf);
 
-
-    //if(strstr(buf,"\f")!=0) {
-    if(strchr(buf,'\f')!=0) {
-      if(debug>0) printf("found ending in this buf!\n");
-      n_endings++;
-    }
-
-    //check for overflow
-    if(offset > MAX) {
-      printf("\nread offset %d exceeds available buffer length %d at  read_i %d\n",offset, MAX,read_i);
-      return;
-    }
-
-    if(debug!=0) printf("\ncopy buf to %d offset after %p\n",offset,buffer_read);
-    strcpy(buffer_read+offset,buf);
-    offset = offset + strlen(buf);
-    //memcpy(buffer_read+read_i*(READ_BUFFER_SIZE),buf,READ_BUFFER_SIZE-1);
-    //buffer_read[read_i*READ_BUFFER_SIZE+READ_BUFFER_SIZE] = NULL;
-
-    if(debug!=0) {
-      printf("\nlen is %d after read_i %d\n%s\n",strlen(buffer_read),read_i,buffer_read);
-      //int k;
-      //for(k=253;k<260;++k) printf("%d \'%c\'\n",k,buffer_read[k]);
-    }
+      read_i++;
+      
+    } // read_n>0
+    else {
+      if(debug!=0) printf("Nothing to read from socket. Sleep a little\n");      
+      //usleep(wait_interval_usec);
+      sleep(1);
+    } 
     
-    if(n_endings>=2) {
-      if(debug!=0) printf("\nfound two endings at read_i %d with total len %d\n",read_i,strlen(buffer_read));      
+    if(n_endings>=1) {
+      if(debug!=0) printf("\nfound %d endings at read_i %d with at len %d and strlen %ld\n",n_endings,read_i,buf_len,strlen(buf));      
       break;
     }
+    
+    
+    //update timing
+    diff = clock()-start_time;
 
-    if(read_i>10000) {
-      if(debug!=0) printf("\ntoo many reads, error getting xml string at read_i %d\n",read_i);
-      break;
-    }
-
-    ++read_i;
-  }
-
-  if(n_endings==2) {
     
-    if(debug!=0) printf("\nPick out string between endings \n%s\n",buffer_read);
-    //int k=0;
-    //for(k=read_i*READ_BUFFER_SIZE;k>(read_i-2)*READ_BUFFER_SIZE;--k) printf("%d \'%c\'\n",k,buffer_read[k]);
-    if(debug!=0) printf("\ndone\n");
-    if(debug!=0) printf("\nlen %d\n",strlen(buffer_read));
-    //char* start = strstr(buffer_read,"\f");
-    char* start = strchr(buffer_read,'\f');
-    char* end2 = strrchr(buffer_read,'\f');
-    if(start!=NULL) {
-      if(debug!=0) printf("\nstart at %p offset %d\n",start,start-buffer_read);
-      if(end2!=NULL) {
-	if(debug!=0) printf("\nend at %p\n",end2);
-	if (start!=end2) { 
-	  memcpy(buffer,start+1,end2-(start+1));
-	  buffer[end2-(start+1)+1] = '\0'; // terminate it
-	  if(debug!=0) printf("\ncopied %d chars to %p\n%s\n",end2-(start+1),buffer,buffer);	
-	} else {
-	  if(debug!=0) printf("\n start and end are the same\n");
-	}
-      }else {
-	if(debug!=0) printf("\n no end found\n");
-      }
-    } else {
-      if(debug!=0) printf("\n no start found found\n");
-    }    
   }
 
-  return;
 
-}
+  if(debug!=0) printf("\nDone reading from socket. Found %d endings and a buf_len of %d and strlen of %ld\n",n_endings, buf_len, strlen(buf));
 
-
-
-char* read_system_xml_string(int* socketfd) {
-  int debug = 0;
-  int read_ii;
-  int read_i;
-  int read_s;
-  int read_n;
-  int read_cur_buff;
-  int read_offset;
-  const unsigned int READ_BUFFER_SIZE = 256;
-  const unsigned int READ_MAX_BUFFERS = 1000;
-  char buffer_read[READ_BUFFER_SIZE];
-  char buffer_read_overlap[READ_BUFFER_SIZE*2];
-  char* buffers_read[READ_MAX_BUFFERS];
   
-  read_i = 0;
-  read_ii = 0;
-  read_s = 0;
-  read_n = 0;
-  read_cur_buff = 0;
-  read_offset = 0;
   
-  if(debug!=0) printf("reset buffers\n");
-  for(read_i=0;read_i<READ_MAX_BUFFERS;++read_i) {
-    //    if(buffers_read[read_i] != NULL) {
-    //if(debug!=0) printf("reset buffers\n");
-    //free(buffers_read[read_i]);
-    //}
-    buffers_read[read_i] = NULL;
-  }
-  
-  while(read_ii<10000) { // some large number to avoid problems
-    ++read_ii;
-    //strcpy(buffer_read_overlap,buffer_read);//,READ_BUFFER_SIZE); 
-    bzero(buffer_read,READ_BUFFER_SIZE);
-    read_n = read((*socketfd),buffer_read,(READ_BUFFER_SIZE-1));
-    if (read_n < 0) 
-      error("ERROR reading from socket");
-    //printf("buffer_read_overlap after clearing the old buffer:\n%s\nbuffer below:\n",buffer_read_overlap);
-    if(debug!=0) printf("\nRead %d\n%s\n",read_ii,buffer_read);
-    read_cur_buff = read_ii-1; 
-    buffers_read[read_cur_buff] = (char*) malloc(sizeof(char)*strlen(buffer_read)); //READ_BUFFER_SIZE-1);
-    if(debug!=0) printf("malloc %d of length %d at %p\n",read_cur_buff,sizeof(char)*strlen(buffer_read),buffers_read[read_cur_buff]);
-    strcpy(buffers_read[read_cur_buff],buffer_read);
+  if(n_endings>=1) {
+    if(debug!=0) printf("\nPick out config and status string between <system> and %d endings in string with strlen %ld and buf_len %d: \n%s\n",n_endings,strlen(buf),buf_len,buf);
     
-    // first find start and then end to make sure to see the whole xml string
-    if(read_s==0) {
-      if(strstr(buffer_read,"<system>")!=0) {
-	read_s=1;
-	if(debug!=0) printf("\n found start of xml string in buffer (read_ii=%d)\n",read_ii);
-	bzero(buffer_read_overlap,2*READ_BUFFER_SIZE);
-	continue;
+    //assume it's the first system tag string I can find
+    
+    char* start = NULL;
+    int len = findSystemStr(buf, buf_len,&start);    
+    if(len>0) {      
+      char* stop = start+len;
+      if(debug!=0) printf("len %d start at %p stop at %p\n",len,start, stop);
+      char* config = strstr(start,"<config>");
+      if(config!=NULL && ((config-start)<len)) {
+	char* status = strstr(start,"<status>");
+	if(status!=NULL && ((status-start)<len)) {
+	  // seems we found all of them. 
+	  if(debug!=0) printf("\ncalloc xml string len %d\n",len);
+	  xml_string_global = (char*) calloc(len,sizeof(char));
+	  //xml_string_global = (char*) malloc(sizeof(char)*len);
+	  if(debug!=0) printf("copy to xml string at %p\n",xml_string_global);	
+	  memcpy(xml_string_global,start,len);
+	  if(debug!=0) printf("\ncopied %d chars to %p with strlen %ld\n%s\n",len,xml_string_global,strlen(xml_string_global),xml_string_global);
+	  
+	} else {
+	   if(debug!=0) printf("\n no status found\n");
+	}
+      } else {
+	if(debug!=0) printf("\n no config found\n");
       }
-      // check if we cut the element by adding prev buffer
-      strcpy(buffer_read_overlap+READ_BUFFER_SIZE-1,buffer_read);//avoid last char that ends string
-      if(strstr(buffer_read_overlap,"<system>")!=0) {
-	if(debug!=0) printf("\n found start of xml string in buffer_read_overlap (read_ii=%d)\n",read_ii);
-	continue;
-      }
     }
     else {
-      if(strstr(buffer_read,"</system>")!=0) {
-	if(debug!=0) printf("\n found end of xml string in buffer (read_ii=%d)\n",read_ii);
-	break;
-      } 
-      // check if we cut the element by adding prev buffer
-      strcpy(buffer_read_overlap+READ_BUFFER_SIZE-1,buffer_read);//avoid last char that ends string
-      //printf("\nbuffer_read_overlap (strlen=%d) after adding prev and new buffer to dest:\n%s\n",strlen(buffer_read_overlap),buffer_read_overlap);
-      if(strstr(buffer_read_overlap,"</system>")!=0) {
-	if(debug!=0) printf("\n found end of xml string in buffer_read_overlap (read_ii=%d)\n",read_ii);
-	break;
-      }
-      if(debug!=0) printf("\n found NO end of xml string in buffer (read_ii=%d)\n",read_ii);	  
-      strcpy(buffer_read_overlap,buffer_read);//,READ_BUFFER_SIZE); 
+      if(debug!=0) printf("Couldn't find system string in xml buffer\n");
     }
   }
-
-  if(read_ii==(10000-1)) {
-    printf("\n ERROR couldn't find the complete xml string\n");
-    return NULL;
-  }
   
-  char* xml_string = (char*)malloc(sizeof(char)*(read_cur_buff+1)*READ_BUFFER_SIZE);
-  read_offset = 0;
-  if(debug!=0) {
-    printf("\nallocating xml_string size %d\n",sizeof(char)*(read_cur_buff+1)*READ_BUFFER_SIZE);
-    printf("read_cur_buff = %d\n",read_cur_buff);
+  if(xml_string_global==NULL) {
+    printf("Problem finding proper xml string: found %d endings.\n",n_endings);
   }
-  read_i=0;
-  for(read_i=0;read_i<READ_MAX_BUFFERS;++read_i) {	
-    if(buffers_read[read_i]!=NULL) {	  
-      strcpy(xml_string+read_offset,buffers_read[read_i]);
-      read_offset += strlen(buffers_read[read_i]);
-      if(debug!=0) printf("copying i%d to %p with offset %d and strlen %d:\n",read_i,(xml_string+read_offset),read_offset,strlen(buffers_read[read_i]));
-      //printf("%s",buffers_read[i]);
-      //printf("\nfreeing %d at %p:\n%s\n",i,buffers_read[i],buffers_read[i]);
-      free(buffers_read[read_i]);
-      
-    }
-  }
-  if(debug!=0) {
-    printf("after copying to xml_string offset is %d\n",read_offset);
-    printf("\n\nxml_string is %d chars\n",strlen(xml_string));
-    //printf("%s\n",xml_string);
-  }
-  // remove stuff outside the xml tags
-  // monkey around with null character to terminate strings correctly
-  char* p_start_system = strstr(xml_string,"<system>");
-  char* p_end_system = strstr(xml_string,"</system>");
-  int len = p_end_system+sizeof(char)*strlen("</system>")-p_start_system;
-  if(debug!=0) printf("found start %p and end %p which is of length %d (strlen(</system>)=%d)\n",p_start_system,p_end_system,len,strlen("</system>"));
-  char* xml_string_pruned =(char*) malloc(sizeof(char)*len+1);
-  memcpy(xml_string_pruned, p_start_system,sizeof(char)*len);
-  // add termination to string
-  xml_string_pruned[sizeof(char)*len] = '\0';
   
-  //printf("free xml_string\n");
-  free(xml_string);
-  //printf("after free xml_string\n");
+    return;
 
-  if(debug!=0) printf("xml_string_pruned at %p below\n%s\n",xml_string_pruned,xml_string_pruned);
+}
 
-  return xml_string_pruned;
 
- }
 
 
-
-
 void retrieveValue(xmlDoc* doc, xmlNode* node, char* tags, char value[], const unsigned int MAX) {
   int debug = 0;
   xmlChar* value_str = NULL;
@@ -726,10 +788,10 @@
       if(value_str!=NULL) {
         if(debug!=0) printf("Found value %s\n",value_str);
         if(strlen((char*) value_str)>=MAX) {
-  	  if(debug!=0) printf("the value for tags=%s is %d i.e. larger than MAX=%d, return no value!\n",tags,strlen((char*)value_str),MAX);
+  	  if(debug!=0) printf("the value for tags=%s is %ld i.e. larger than MAX=%d, return no value!\n",tags,strlen((char*)value_str),MAX);
           value_str = NULL;
         } else {
-	  if(debug!=0) printf("copy the value_str=\"%s\" (%d) to %p\n",value_str,strlen((char*)value_str),value);
+	  if(debug!=0) printf("copy the value_str=\"%s\" (%ld) to %p\n",value_str,strlen((char*)value_str),value);
           strcpy((char*)value,(char*)value_str);
         }
       } else {

epics/trunk/epics_example/myexampleApp/src
dbSubExample.c 766 -> 767
--- epics/trunk/epics_example/myexampleApp/src/dbSubExample.c	2014-07-14 22:00:35 UTC (rev 766)
+++ epics/trunk/epics_example/myexampleApp/src/dbSubExample.c	2014-07-15 05:50:27 UTC (rev 767)
@@ -9,7 +9,7 @@
 #include <client_util.h>
 
 int mySubDebug = 0;
-char *hostName = "134.79.229.141";
+char *hostName = "localhost";// "134.79.229.141";
 int port = 8090;
 int sockfd = -1;
 int counter = 0;
@@ -34,8 +34,18 @@
   return 0;
 }
 
+static long subPollInit(subRecord *precord) {
+  if (mySubDebug) {
+    printf("Record %s called subPollInit(%p)\n", precord->name, (void*) precord);
+    //sockfd = open_socket(hostName,port);
+    //printf("Opened socket %d\n",sockfd);    
+  }
+  
+  return 0;
+}
 
 
+
 static void readAxiXadcTemp(subRecord* precord, int fpga_id)
 {
   if(mySubDebug) {
@@ -47,7 +57,7 @@
 
   sockfd = open_socket(hostName,port);
   if(sockfd<0) {
-    printf("ERROR could not open socket in readAxiXadcTemp\n");
+    printf("ERROR could not open socket %d for host %s in readAxiXadcTemp\n",port,hostName);
     return;
   }
   if (mySubDebug) {
@@ -80,21 +90,31 @@
 static void readFebTemp(subRecord *precord,char id[],char ch_name[]) {
   
   if(mySubDebug) {
-    printf("Record %s called readFebTemp %s for fgpa_id=%s\n",precord->name,ch_name,id);
+    printf("Record %s called readFebTemp %s for id=%s\n",precord->name,ch_name,id);
   }
-
+  
   precord->val=def_AxiXadcTemp;
   char* p_end = id;
   long int li_id = strtol(id,&p_end,0);
   if(p_end!=id) {
     if(li_id>=0 && li_id<10) {     
       if(strcmp(ch_name,"axixadc")==0) {
-	readAxiXadcTemp(precord,(int)li_id);
-	
+	//readAxiXadcTemp(precord,(int)li_id);
+	char value[BUF_SIZE];
+	memset(value,0,BUF_SIZE);
+	readXadcT((int)li_id,value,BUF_SIZE);    
+	if (mySubDebug) {
+	  printf("Got value=\"%s\"\n",value);
+	}
+	if(strlen(value)>0) {
+	  precord->val = atof(value);
+	  if (mySubDebug) {
+	    printf("precord-val is now %f \n",precord->val);
+	  }
+	}	
       } else {
 	printf("Invalid FEB ch_name %s \n",ch_name);
-      }
-      
+      }      
     } else {
       printf("Invalid FEB id %s (%ld) \n",id,li_id);
     }
@@ -120,7 +140,7 @@
   //sockfd = open_socket("134.79.229.141",8090);
   sockfd = open_socket(hostName,port);
   if(sockfd<0) {
-    printf("ERROR could not open socket in readHybridVoltageNear\n");
+    printf("ERROR could not open socket %s:%d in readHybridVoltage\n",hostName,port);
     return;
   }
   if (mySubDebug) {
@@ -365,7 +385,33 @@
 }
 
 
+static long subPollProcess(subRecord *precord) {
+  if (mySubDebug) {
+    printf("Record %s called subPollProcess(%p)\n", precord->name, (void*) precord);
+    printf("sockfd %d\n",sockfd);
+  }
+  if(sockfd<=0) {
+    printf("Re-opening socket\n");    
+    sockfd = open_socket(hostName,port);
+  }
+  
+  if (mySubDebug) {
+    printf("Poll xml string\n");
+  }
+  
+  pollXmlStr(sockfd);
+    
+  if (mySubDebug) {
+    printf(" Poll XML done. Close socket\n");
+  }
+  
+  sockfd = close_socket(sockfd);
+  
+  return 0;
+}
 
+
+
 static long mySubInit(subRecord *precord)
 {
     if (mySubDebug) {
@@ -500,6 +546,8 @@
 epicsRegisterFunction(subLVProcess);
 epicsRegisterFunction(subTempInit);
 epicsRegisterFunction(subTempProcess);
+epicsRegisterFunction(subPollInit);
+epicsRegisterFunction(subPollProcess);
 epicsRegisterFunction(mySubInit);
 epicsRegisterFunction(mySubProcess);
 epicsRegisterFunction(mySubTempInit);

epics/trunk/epics_example/myexampleApp/src
dbSubExample.dbd 766 -> 767
--- epics/trunk/epics_example/myexampleApp/src/dbSubExample.dbd	2014-07-14 22:00:35 UTC (rev 766)
+++ epics/trunk/epics_example/myexampleApp/src/dbSubExample.dbd	2014-07-15 05:50:27 UTC (rev 767)
@@ -5,6 +5,8 @@
 function(subLVProcess)
 function(subTempInit)
 function(subTempProcess)
+function(subPollInit)
+function(subPollProcess)
 function(mySubTempInit)
 function(mySubTempProcess)
 function(mySubCalDelayInit)
SVNspam 0.1