ISIS Logo
ECLAB
An EPICS support module to export potentiostat values as process variables
ECLabParams.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2013 Science and Technology Facilities Council (STFC), GB.
3 * All rights reverved.
4 * This file is distributed subject to a Software License Agreement found
5 * in the file LICENSE.txt that is included with this distribution.
6 \*************************************************************************/
7 
10 
11 #include <string>
12 #include <map>
13 #include <iostream>
14 #include <epicsString.h>
15 #include "asynPortDriver.h"
16 #include "ECLabParams.h"
17 
19 
20 struct technique_t
21 {
22  bool update;
24  std::string technique;
25  std::string label;
26  std::vector<TEccParam_t> value;
27  technique_t() : update(false) { }
28 };
29 
30 typedef std::map<int, std::vector<technique_t> > techniqueMap_t;
31 
33 
34 static asynParamType ECLabToASYNType(ParamType type)
35 {
36  switch(type)
37  {
38  case Integer:
39  return asynParamInt32;
40  case IntegerArray:
41  return asynParamInt32Array;
42  case Boolean:
43  return asynParamInt32;
44  case BooleanArray:
45  return asynParamInt8Array;
46  case Single:
47  return asynParamFloat64;
48  case SingleArray:
49  return asynParamFloat32Array;
50  default:
51  return asynParamInt32;
52  }
53 }
54 
55 static void addTechParam(asynPortDriver* driver, techniqueMap_t& the_map, const std::string& technique, int addr, const std::string& label,
56  ParamType type, const std::string& param, const std::string& desc, int nelem = 1)
57 {
58  int par_id = -1;
59  std::string asyn_param = technique + "_" + param;
60  if (driver->createParam(addr, asyn_param.c_str(), ECLabToASYNType(type), &par_id) != asynSuccess || par_id == -1)
61  {
62  std::cerr << "Error Adding asyn parameter " << asyn_param << " addr " << addr << std::endl;
63  return;
64  }
65  std::vector<technique_t>& ta = the_map[par_id];
66  if ( ta.size() < (addr + 1) )
67  {
68  ta.resize(addr + 1);
69  }
70  technique_t& t = ta[addr];
71  t.update = false;
72  t.type = type;
73  t.technique = technique;
74  t.label = label;
75  std::cerr << "Adding asyn parameter \"" << asyn_param << "\" addr " << addr << " for technique \"" << technique << "\" label \"" << label << "\"" << std::endl;
76 }
77 
78 void setECIntegerParam(asynPortDriver* driver, int addr, int id, epicsInt32 value)
79 {
80  driver->setIntegerParam(addr, id, value);
81  std::vector<technique_t>& ta = g_map[id];
82  technique_t& t = ta[addr];
83  t.update = true;
84  if (t.value.size() == 0)
85  {
86  t.value.resize(1);
87  }
88  if (t.type == Boolean)
89  {
90  BL_DefineBoolParameter(t.label.c_str(), (value != 0 ? true : false), 0, &(t.value[0]));
91  }
92  else
93  {
94  BL_DefineIntParameter(t.label.c_str(), value, 0, &(t.value[0]));
95  }
96 }
97 
98 void setECSingleParam(asynPortDriver* driver, int addr, int id, epicsFloat64 value)
99 {
100  driver->setDoubleParam(addr, id, value);
101  std::vector<technique_t>& ta = g_map[id];
102  technique_t& t = ta[addr];
103  t.update = true;
104  if (t.value.size() == 0)
105  {
106  t.value.resize(1);
107  }
108  BL_DefineSglParameter(t.label.c_str(), static_cast<float>(value), 0, &(t.value[0]));
109 }
110 
111 void getTechniqueParams(const std::string& technique, int addr, std::vector<TEccParam_t>& values, bool changes_only)
112 {
113  for(techniqueMap_t::iterator it = g_map.begin(); it != g_map.end(); ++it)
114  {
115  std::vector<technique_t>& ta = it->second;
116  if ( addr >= ta.size() )
117  {
118  continue;
119  }
120  technique_t& t = ta[addr];
121  if (changes_only && !t.update)
122  {
123  continue;
124  }
125  if ( epicsStrCaseCmp(t.technique.c_str(), technique.c_str()) == 0 )
126  {
127  values.insert(values.end(), t.value.begin(), t.value.end());
128  t.update = false;
129  }
130  }
131 }
132 
133 void printParams(std::ostream& os)
134 {
135  for(techniqueMap_t::iterator it = g_map.begin(); it != g_map.end(); ++it)
136  {
137  std::vector<technique_t>& ta = it->second;
138  for(int j=0; j<ta.size(); ++j)
139  {
140  technique_t& t = ta[j];
141  os << "Technique " << t.technique << " addr " << j << " label " << t.label << std::endl;
142  for(int i=0; i<t.value.size(); ++i)
143  {
144  os << t.value[i].ParamStr << std::endl;
145  }
146  }
147  }
148 }
149 
150 void addAllParameters(asynPortDriver* driver)
151 {
152 #include "BooleanParams.cpp"
153 #include "IntegerParams.cpp"
154 #include "SingleParams.cpp"
155 #include "BooleanArrayParams.cpp"
156 #include "IntegerArrayParams.cpp"
157 #include "SingleArrayParams.cpp"
158 }
std::vector< TEccParam_t > value
Definition: ECLabParams.cpp:26
void getTechniqueParams(const std::string &technique, int addr, std::vector< TEccParam_t > &values, bool changes_only)
std::string technique
Definition: ECLabParams.cpp:24
__int64 t
void setECIntegerParam(asynPortDriver *driver, int addr, int id, epicsInt32 value)
Definition: ECLabParams.cpp:78
ParamType
Definition: ECLabParams.cpp:18
void addAllParameters(asynPortDriver *driver)
static techniqueMap_t g_map
Definition: ECLabParams.cpp:32
void printParams(std::ostream &os)
addTechParam(driver, g_map,"$(TECH)",$(INDEX),"$(LABEL)",$(TYPE),"$(PARAM)","$(DESC)",$(NELM))
ParamType type
Definition: ECLabParams.cpp:23
std::map< int, std::vector< technique_t > > techniqueMap_t
Definition: ECLabParams.cpp:30
static asynParamType ECLabToASYNType(ParamType type)
Definition: ECLabParams.cpp:34
void setECSingleParam(asynPortDriver *driver, int addr, int id, epicsFloat64 value)
Definition: ECLabParams.cpp:98
std::string label
Definition: ECLabParams.cpp:25
Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5