Print

Print


Commit in epics/trunk/epics_example/myexampleApp on MAIN
Db/dbFebTemp.db+7-7782 -> 783
  /dbHybLV.db+2-2782 -> 783
src/client_util.c+49-39782 -> 783
   /dbSubExample.c+93-35782 -> 783
+151-83
4 modified files
More work in progress. Implemented V, I and T reading for hybrid. Addded debug levels.

epics/trunk/epics_example/myexampleApp/Db
dbFebTemp.db 782 -> 783
--- epics/trunk/epics_example/myexampleApp/Db/dbFebTemp.db	2014-07-16 19:28:12 UTC (rev 782)
+++ epics/trunk/epics_example/myexampleApp/Db/dbFebTemp.db	2014-07-17 00:48:42 UTC (rev 783)
@@ -1,18 +1,18 @@
 
 
-record(sub,SVT:lv:fe:0:axixadc:t_rd_sub)
+record(sub,SVT:temp:fe:0:axixadc:t_rd_sub)
 {
+    field(SCAN, "Passive")
     field(INAM,"subTempInit")
     field(SNAM,"subTempProcess")
-    field(SCAN,"Passive")
     field(FLNK,"SVT:lv:hyb:bot:0:dvdd:i_rd")
 }
 
-record(ai, SVT:lv:fe:0:anap:i_rd) {
-  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")
+record(ai, SVT:temp:fe:0:anap:t_rd) {
+    field(SCAN, "Passive")
+    field(FLNK,"SVT:temp:fe:0:axixadc:t_rd_sub")
+    field(INP, "SVT:temp:fe:0:axixadc:t_rd_sub PP")
+    field(DTYP,"Soft Channel")
 }
 
 

epics/trunk/epics_example/myexampleApp/Db
dbHybLV.db 782 -> 783
--- epics/trunk/epics_example/myexampleApp/Db/dbHybLV.db	2014-07-16 19:28:12 UTC (rev 782)
+++ epics/trunk/epics_example/myexampleApp/Db/dbHybLV.db	2014-07-17 00:48:42 UTC (rev 783)
@@ -8,14 +8,14 @@
 
 record(sub,SVT:lv:hyb:bot:0:dvdd:i_rd_sub)
 {
+    field(SCAN,"Passive")
     field(INAM,"subLVInit")
     field(SNAM,"subLVProcess")
-    field(SCAN,"Passive")
     field(FLNK,"SVT:lv:hyb:bot:1:dvdd:i_rd")
 }
 
 record(ai, SVT:lv:hyb:bot:0:dvdd:i_rd) {
-  #field(SCAN, "5 second")
+  field(SCAN, "Passive")
   field(FLNK,"SVT:lv:hyb:bot:0:dvdd:i_rd_sub PP")
   field(INP, "SVT:lv:hyb:bot:0:dvdd:i_rd_sub CPP")
   field(DTYP,"Soft Channel")

epics/trunk/epics_example/myexampleApp/src
client_util.c 782 -> 783
--- epics/trunk/epics_example/myexampleApp/src/client_util.c	2014-07-16 19:28:12 UTC (rev 782)
+++ epics/trunk/epics_example/myexampleApp/src/client_util.c	2014-07-17 00:48:42 UTC (rev 783)
@@ -1,21 +1,27 @@
 #include "client_util.h"
 #include <time.h>
+#include <ctype.h>
 #include "sys/ioctl.h"
 
 const unsigned int BUFFER_SIZE = 256;
 const unsigned int MAX_BUFFERS = 1000;
 const unsigned int XML_STRING_MAX = 65536;
-int client_util_debug = 0;
+int client_util_debug = 1;
 char *xml_string_global = NULL;
 xmlDoc* doc = NULL;
 xmlNode* xml_root = NULL;
 
 char* strToUpper( char* s )
-  {
+{
   char* p = s;
-  while (*p = toupper( *p )) p++;
+  while (*p) {
+    if(islower(*p)) {
+      *p = toupper(*p);
+    }
+    p++;
+  }
   return s;
-  }
+}
 
 double extractTempValFromString(char value[]) {
   double t = 0.0;
@@ -317,9 +323,9 @@
     printf("couldn't get root from document\n");
     return;
   }  
-  if(client_util_debug!=0) printf("retrieve value\n");
+  if(client_util_debug!=0) printf("retrieve value from xml document\n");
   retrieveValue(doc,xml_root,tag,value,MAX);
-  if(client_util_debug!=0) printf("retrieve value done\n");
+  if(client_util_debug!=0) printf("retrieved value \"%s\" from xml\n",value);
 }
 
 
@@ -334,15 +340,18 @@
   getXMLValue(tag,value,MAX);
 }
 
-void readHybridT(int feb_id, int hyb_id,char ch_name[], char value[],const unsigned int MAX) {
+void readHybridT(int feb_id, int hyb_id, int tId, char value[],const unsigned int MAX) {
   char tag[256];
-  sprintf(tag,"system:status:FrontEndTestFpga:FebCore:PowerMonitor:Hybrid%d_%s_Current",hyb_id,strToUpper(ch_name));
+  sprintf(tag,"system:status:FrontEndTestFpga:FebCore:PowerMonitor:Hybrid%d_HTemp%d",hyb_id,tId);
   getXMLValue(tag,value,MAX);
 }
 
 void readHybridV(int feb_id, int hyb_id,char ch_name[], char ch_pos[], char value[],const unsigned int MAX) {  
   char tag[256];
-  sprintf(tag,"system:status:FrontEndTestFpga:FebCore:PowerMonitor:Hybrid%d_%s_%s",hyb_id,ch_name,strToUpper(ch_pos));
+  char* ch_name_upper;
+  ch_name_upper = strToUpper(ch_name);
+  if(client_util_debug>1) printf("ch_name %s\n",ch_name_upper);
+  sprintf(tag,"system:status:FrontEndTestFpga:FebCore:PowerMonitor:Hybrid%d_%s_%s",hyb_id,ch_name_upper,ch_pos);
   getXMLValue(tag,value,MAX);
 }
 
@@ -354,21 +363,21 @@
   //int debug = 1;
   for(cur_node = node; cur_node; cur_node = cur_node->next) {
     if(found_it!=NULL) {
-      if(client_util_debug!=0) printf("stop at cur_node %s prev %s  \n",cur_node->name,cur_node->prev->name);
+      if(client_util_debug>1) printf("stop at cur_node %s prev %s  \n",cur_node->name,cur_node->prev->name);
       break;
     }
-    if(client_util_debug!=0) printf("Looking for %s and comparing to %s\n",tag,cur_node->name);
+    if(client_util_debug>1) printf("Looking for %s and comparing to %s\n",tag,cur_node->name);
     if( (!xmlStrcmp(cur_node->name,(const xmlChar*)tag)) ) {
-      if(client_util_debug!=0) printf("found an element of type %d\n",cur_node->type);
+      if(client_util_debug>1) printf("found an element of type %d\n",cur_node->type);
       if (cur_node->type == XML_ELEMENT_NODE) {
-        if(client_util_debug!=0) printf("found it\n");
+        if(client_util_debug>1) printf("found it\n");
         found_it = cur_node;
         break;
       }
     }
 
     if(found_it!=NULL) {
-      if(client_util_debug!=0) printf("found it at name %s \n",cur_node->name);
+      if(client_util_debug>1) printf("found it at name %s \n",cur_node->name);
       return found_it;
     }
 
@@ -542,7 +551,7 @@
 
 
 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);
+  if(client_util_debug>1) 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>");
@@ -550,7 +559,7 @@
       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);
+      if(client_util_debug>1) printf("found s at %p and e at %p and *start at %p with len %ld \n",s,e,*start,l);
       return (int)l;
     }
   }
@@ -598,7 +607,7 @@
       
       
       // allocate memory needed
-      if(debug>0) printf("Allocate %d array\n",read_n);      
+      if(debug>1) printf("Allocate %d array\n",read_n);      
       
       if(buf_more!=NULL) {
 	printf("buf_more is not null!\n");
@@ -607,7 +616,7 @@
       
       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));      
+      if(debug>1) 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);
       
@@ -623,26 +632,26 @@
       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);
+      	  if(debug>1) 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);
+      if(debug>1) 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); 
+	if(debug>1) printf("found ending at %p (array index %ld) in this buf!\n",pch,pch-buf_more); 
 	n_endings++; 
 	pch = strchr(pch+1,'\f'); 
       } 
       
 
       // copy to other buffer      
-      if(debug>0) printf("Copy %d to other buffer \n",read_n);      
+      if(debug>1) printf("Copy %d to other buffer \n",read_n);      
       
       
-      if(debug>0) printf("buf at %p before realloc\n",buf);      
+      if(debug>1) 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");
@@ -652,11 +661,11 @@
 	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);      
+      if(debug>1) 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);
 
-      if(debug>0) printf("memcpy done\n");
+      if(debug>1) printf("memcpy done\n");
       
       //update the buffer length
       buf_len += read_n;
@@ -664,7 +673,7 @@
       //terminate 
       //buf[buf_len-1] = '\0';
       
-      if(debug>0) printf("free buf_more\n");
+      if(debug>1) printf("free buf_more\n");
       
       // free buffer
       if(buf_more!=NULL) {
@@ -672,19 +681,19 @@
 	buf_more=NULL;
       }
 
-      if(debug>0) printf("end of read_i %d with buf strlen %ld\n",read_i,strlen(buf));
+      if(debug>1) printf("end of read_i %d with buf strlen %ld\n",read_i,strlen(buf));
 
 
       read_i++;
       
     } // read_n>0
     else {
-      if(debug!=0) printf("Nothing to read from socket. Sleep a little\n");      
+      if(debug>0) printf("Nothing to read from socket. Sleep a little\n");      
       //usleep(wait_interval_usec);
       sleep(1);
     } 
     
-    if(n_endings>=1) {
+    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;
     }
@@ -697,12 +706,13 @@
   }
 
 
-  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));
+  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));
 
   
   
   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);
+    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",n_endings,strlen(buf),buf_len);
+    if(debug>1) printf("\nbuf: \n%s\n",buf);
     
     //assume it's the first system tag string I can find
     
@@ -710,28 +720,28 @@
     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);
+      if(debug>1) 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);
+	  if(debug>1) 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);	
+	  if(debug>1) 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);
+	  if(debug>1) 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");
+	   if(debug>0) printf("\n no status found\n");
 	}
       } else {
-	if(debug!=0) printf("\n no config found\n");
+	if(debug>0) printf("\n no config found\n");
       }
     }
     else {
-      if(debug!=0) printf("Couldn't find system string in xml buffer\n");
+      if(debug>0) printf("Couldn't find system string in xml buffer\n");
     }
   }
   
@@ -739,7 +749,7 @@
     printf("Problem finding proper xml string: found %d endings.\n",n_endings);
   }
   
-    return;
+  return;
 
 }
 

epics/trunk/epics_example/myexampleApp/src
dbSubExample.c 782 -> 783
--- epics/trunk/epics_example/myexampleApp/src/dbSubExample.c	2014-07-16 19:28:12 UTC (rev 782)
+++ epics/trunk/epics_example/myexampleApp/src/dbSubExample.c	2014-07-17 00:48:42 UTC (rev 783)
@@ -9,11 +9,13 @@
 #include <client_util.h>
 
 int mySubDebug = 0;
-char *hostName = "localhost";// "134.79.229.141";
-int port = 8091;
-int sockfd = -1;
+const int BUF_SIZE = 256;
+//char hostName[256] = "";// "134.79.229.141";
+char* hostNameDef = "134.79.229.141";
+char hostName[256];
+int port = 8090;
+int sockfd = 0;
 int counter = 0;
-const int BUF_SIZE = 256;
 const double def_hyb_v = -1.0;
 const double def_hyb_i = -2.0;
 const double def_AxiXadcTemp = -1.0;
@@ -40,7 +42,53 @@
     //sockfd = open_socket(hostName,port);
     //printf("Opened socket %d\n",sockfd);    
   }
+  // look for host name and port in DB
+  //initialize the string
+  memset(hostName,0,BUF_SIZE);  
+  struct link* inpa;
+  struct link* inpb;
+  inpa = &precord->inpa;
+  inpb = &precord->inpb;
+  if(inpa && inpb) {
+    if(inpa->value.constantStr && inpb->value.constantStr) {
+      //union value va = inpa->value;
+      //union value vb = inpb->value;
+      if (mySubDebug) { 
+	printf("inpa type %d value %p %s\n",inpa->type,inpa->value.constantStr,inpa->value.constantStr);
+	printf("inpb type %d value %p %s\n",inpb->type,inpb->value.constantStr,inpb->value.constantStr);  
+      }
+      printf("%s\n",inpa->value.constantStr);
+      //sprintf(hostName,"%s",inpa->value.constantStr);
+      strcpy(hostName,inpa->value.constantStr);
+      printf("%s\n",hostName);
+      
+      int p = (int)strtol(inpb->value.constantStr,NULL,0);
+      if(p) {
+	port = p;
+      }
+      else {
+	printf("problem converting to in for port %s\n",inpb->value.constantStr);  
+      }
+    } else {
+      printf("inpa and inpb strings are null when getting host and port\n");
+    }
+    
+  } else {
+    printf("inpa and inpb are null when getting host and port\n");
+  }
+
+  if(strlen(hostName)==0) {
+    printf("No hostname found in DB. USe default\b");
+    strcpy(hostName,hostNameDef);
+  }
+  printf("hostName %s port %d\n",hostName,port);  
   
+  if(strcmp(hostName,"")==0) {
+    printf("ERROR no valid hostname found\n");
+    return 1;
+  }
+  
+
   return 0;
 }
 
@@ -70,10 +118,11 @@
     constant = 1e3;
   } 
   else if(strcmp(action,"t_rd_sub")==0) {
-    readHybridT(feb_id, id, ch_name, value, BUF_SIZE);
+    int tId = atoi(ch_name);
+    readHybridT(feb_id, id, tId, value, BUF_SIZE);
   } 
   else if(strcmp(action,"vn_sub")==0) {
-    readHybridV(feb_id, id, ch_name, "NEAR", value, BUF_SIZE);
+    readHybridV(feb_id, id, ch_name, "Near", value, BUF_SIZE);
   } 
   else if(strcmp(action,"v_set_sub")==0) {
     // need to move this to a write function?
@@ -99,12 +148,12 @@
   }
 
   //set to default
-  precord->val=def_AxiXadcTemp;
   
   char value[BUF_SIZE];
   memset(value,0,BUF_SIZE);
   if(strcmp(action,"t_rd_sub")==0) {
     if(strcmp(ch_name,"axixadc") ==0 ) {
+      precord->val=def_AxiXadcTemp;
       readFebT(feb_id, value, BUF_SIZE);
     } else {
       printf("No such ch_name %s implemented for readFeb!\n",ch_name);
@@ -212,7 +261,7 @@
       printf("ERROR wrong option for hybrid ch: %s\n",ch_name);
       return 0;
     }
-    if(strcmp(action,"vn_sub")!=0 || strcmp(action,"i_rd_sub")!=0  || strcmp(action,"v_set_sub")!=0) { 
+    if(strcmp(action,"vn_sub")!=0 && strcmp(action,"i_rd_sub")!=0  && strcmp(action,"v_set_sub")!=0) { 
       printf("ERROR this hybrid action type is not valid \"%s\"\n",action);
       return 0;
     }
@@ -229,7 +278,7 @@
     }
     readHybrid(precord,action,half,(int)li_id,feb_id,ch_name);  
   }
-  else if(strcmp(board_type,"feb")==0) {
+  else if(strcmp(board_type,"fe")==0) {
     printf("No LV implementation exists for feb\n");
     return 0;
   } 
@@ -260,13 +309,11 @@
   char id[BUF_SIZE];
   char ch_name[BUF_SIZE];
   char action[BUF_SIZE];
+
   getType(precord->name,type,BUF_SIZE);
   getBoardType(precord->name,board_type,BUF_SIZE);
-  getHalf(precord->name,half,BUF_SIZE);
-  getId(precord->name,id,BUF_SIZE);
-  getChName(precord->name,ch_name,BUF_SIZE);
-  getAction(precord->name,action,BUF_SIZE);
 
+
   if (mySubDebug) {
     printf("Record %s has type %s board type \"%s\"\n", precord->name, type,board_type);
   }
@@ -276,25 +323,25 @@
     return 0;
   }
 
-  if(strcmp(action,"t_rd_sub")!=0) {
-    printf("ERROR this action type is not valid \"%s\"\n",action);
-      return 0;
-  }
-  
+  if(strcmp(board_type,"hyb")==0) {  
+    getHalf(precord->name,half,BUF_SIZE);
+    getId(precord->name,id,BUF_SIZE);
+    getChName(precord->name,ch_name,BUF_SIZE);
+    getAction(precord->name,action,BUF_SIZE);
 
-  // use default value until the DAQ map can be added
-  if(strcmp(half,"bot")==0) {
-    feb_id = 0;
-  } else {
-    printf("ERROR only bot half can be used. Need to implement DAQ map!\n");
-    return 0;
-  }
-
-  if(strcmp(board_type,"hyb")==0) {
     if(strcmp(ch_name,"temp1")!=0 && strcmp(ch_name,"temp2")!=0) {
       printf("ERROR wrong option for hybrid ch: %s\n",ch_name);
       return 0;
     }
+
+
+    // use default value until the DAQ map can be added
+    if(strcmp(half,"bot")==0) {
+      feb_id = 0;
+    } else {
+      printf("ERROR only bot half can be used. Need to implement DAQ map!\n");
+      return 0;
+    } 
     char* p_end = id;
     long int li_id = strtol(id,&p_end,0);
     if(p_end!=id) {
@@ -306,29 +353,39 @@
       printf("ERROR converting this hybrid id %s is not valid\n",id);
       return 0;      
     }
-
+    
     readHybrid(precord,action,half,(int)li_id,feb_id,ch_name);  
 
-  }
-  else if(strcmp(board_type,"feb")==0) {
+
+  } 
+  else if(strcmp(board_type,"fe")==0) {  
+    sprintf(half,"%s","bot");
+    getFebId(precord->name,id,BUF_SIZE);
+    getFebChName(precord->name,ch_name,BUF_SIZE);
+    getFebAction(precord->name,action,BUF_SIZE);  
+    feb_id = atoi(id);
+    if(strcmp(action,"t_rd_sub")!=0) {
+      printf("ERROR this feb action type is not valid \"%s\"\n",action);
+      return 0;
+    }  
+
     if(strcmp(ch_name,"axixadc") ) {
-      printf("ERROR wrong option for hybrid ch: %s\n",ch_name);
+      printf("ERROR wrong option for feb ch: %s\n",ch_name);
       return 0;
     }
     
     readFeb(precord,action,feb_id,ch_name);  
     
-    //SVT:temp:fe:0:axixadc:t_rd_sub)
-    
+
   } 
   else {
     printf("ERROR this board type is not valid \"%s\"\n",board_type);
     return 0;
   }
   
+
   
   
-  
   return 0;
 }
 
@@ -341,8 +398,9 @@
     printf("sockfd %d\n",sockfd);
   }
   if(sockfd<=0) {
-    printf("Re-opening socket\n");    
+    printf("Re-opening socket: host: %s:%d\n",hostName, port);    
     sockfd = open_socket(hostName,port);
+    printf("Opened socket : %d\n",sockfd);    
   }
   
   if (mySubDebug) {
SVNspam 0.1