ISIS Logo
ECLAB
An EPICS support module to export potentiostat values as process variables
dummyFunctions.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 
8 
12 
13 #include <string>
14 #include <sstream>
15 #include <iostream>
16 #include <string>
17 #include <vector>
18 #include <time.h>
19 
20 #include <epicsStdio.h>
21 
22 #include "ECLabInterface.h"
23 
24 static int my_connection_id = 2382312;
25 
26 bool ECLabInterface::BLSIM = false;
27 
29 {
30  std::string name;
31  TEccParams_t params;
32  MyTechnique() { params.pParams = 0; }
33  MyTechnique(const char* nname, const TEccParams_t& nparams) { params.pParams = 0; copy(nname, nparams); }
34  MyTechnique(const MyTechnique& t) { params.pParams = 0; copy(t.name.c_str(), t.params); }
35 
36  void copy(const char* nname, const TEccParams_t& nparams)
37  {
38  name = nname;
39  delete params.pParams;
40  params.pParams = new TEccParam_t[nparams.len];
41  params.len = nparams.len;
42  memcpy(params.pParams, nparams.pParams, nparams.len * sizeof(TEccParam_t));
43  }
44  void print(std::ostream& os)
45  {
46  os << "Technique " << name << std::endl;
47  for (int i = 0; i<params.len; ++i)
48  {
49  os << "Param name " << params.pParams[i].ParamStr << std::endl;
50  os << "Param type " << params.pParams[i].ParamType << std::endl;
51  os << "Param val " << params.pParams[i].ParamVal << std::endl;
52  os << "Param index " << params.pParams[i].ParamIndex << std::endl;
53  }
54  }
55 };
56 
57 struct MyChannel
58 {
59  TChannelInfos_t info;
60  time_t start;
61  std::vector<MyTechnique> techniques;
62  void print(std::ostream& os)
63  {
64  for(int i=0; i<techniques.size(); ++i)
65  {
66  techniques[i].print(os);
67  }
68  }
69 };
70 
72 
73 #define NCHANNELS 1 // 1 to `16
74 
75 static void init_channels()
76 {
77  for(int i=0; i<16; ++i)
78  {
79  my_channels[i].info.Channel = i;
80  my_channels[i].info.State = KBIO_STATE_STOP;
81  my_channels[i].info.NbOfTechniques = 0;
82  }
83 }
84 
85 #define CHECK_CONNECTION_ID(__ID) \
86  if (__ID != my_connection_id) \
87  { \
88  return -1; \
89  }
90 #define CHECK_CHANNEL(__CH) \
91  if (__CH >= NCHANNELS) \
92  { \
93  return -1; \
94  }
95 
96 //#define DEBUG_PRINT(__arg) std::cerr << __arg << std::endl
97 #define DEBUG_PRINT(__arg)
98 
99 BIOLOGIC_API(int) BL_GetLibVersionStub(char* pVersion, unsigned int* psize)
100 {
101  DEBUG_PRINT("BL_GetLibVersion");
102  static const char* version = "5.34.0.1";
103  strncpy(pVersion, version, *psize);
104  pVersion[*psize-1] = '\0';
105  *psize = strlen(version);
106  return 0;
107 }
108 
109 //BIOLOGIC_API(int) BL_GetErrorMsgStub( int errorcode, char* pmsg, unsigned int* psize )
110 //{
111 // DEBUG_PRINT("BL_GetErrorMsg");
112 // if (errorcode == 0)
113 // {
114 // strncpy(pmsg, "No ERROR", *psize);
115 // return 0;
116 // }
117 // else if (errorcode < 0)
118 // {
119 // epicsSnprintf(pmsg, *psize, "Dummy Error code %d", errorcode);
120 // return 0;
121 // }
122 // else
123 // {
124 // return -1;
125 // }
126 //}
127 
128 BIOLOGIC_API(int) BL_ConnectStub(const char* address, uint8 timeout, int* pID, TDeviceInfos_t* pInfos)
129 {
130  DEBUG_PRINT("BL_Connect");
131  *pID = my_connection_id;
132  pInfos->DeviceCode = KBIO_DEV_SP200;
133  pInfos->NumberOfChannels = NCHANNELS;
134  pInfos->NumberOfSlots = 1;
135  init_channels();
136  return 0;
137 }
138 
139 BIOLOGIC_API(int) BL_TestConnectionStub(int ID)
140 {
141  DEBUG_PRINT("BL_TestConnection");
143  return 0;
144 }
145 
146 BIOLOGIC_API(int) BL_DisconnectStub(int ID)
147 {
148  DEBUG_PRINT("BL_Disconnect");
149  if (ID == my_connection_id)
150  {
151  ++my_connection_id; // this ensures closing or using a previously closed channel will generate an error
152  return 0;
153  }
154  else
155  {
156  return -1;
157  }
158 }
159 
160 BIOLOGIC_API(int) BL_LoadFirmwareStub( int ID, uint8* pChannels, int* pResults, uint8 Length,
161  bool ShowGauge, bool ForceReload, const char* BinFile, const char* XlxFile)
162 {
163  return 0;
164 }
165 
166 BIOLOGIC_API(bool) BL_IsChannelPluggedStub( int ID, uint8 ch )
167 {
168  DEBUG_PRINT("BL_IsChannelPlugged");
169  if (ID == my_connection_id)
170  {
171  return true;
172  }
173  else
174  {
175  return false;
176  }
177 }
178 
179 BIOLOGIC_API(int) BL_GetChannelsPluggedStub ( int ID, uint8* pChPlugged, uint8 Size )
180 {
181  DEBUG_PRINT("BL_GetChannelsPlugged");
183  if (Size > NCHANNELS)
184  {
185  return -1;
186  }
187  for(int i=0; i<Size; ++i)
188  {
189  pChPlugged[i] = 1;
190  }
191  return 0;
192 }
193 
194 BIOLOGIC_API(int) BL_GetChannelInfosStub( int ID, uint8 ch, TChannelInfos_t* pInfos )
195 {
196  DEBUG_PRINT("BL_GetChannelInfos");
198  CHECK_CHANNEL(ch);
199  memcpy(pInfos, &(my_channels[ch].info), sizeof(TChannelInfos_t));
200  return 0;
201 }
202 
203 
204 BIOLOGIC_API(int) BL_LoadTechniqueStub(int ID, uint8 channel, const char* pFName, TEccParams_t Params, bool FirstTechnique, bool LastTechnique, bool DisplayParams)
205 {
206  DEBUG_PRINT("BL_LoadTechnique");
208  CHECK_CHANNEL(channel);
209  if (FirstTechnique)
210  {
211  my_channels[channel].info.NbOfTechniques = 0;
212  my_channels[channel].techniques.resize(0);
213  }
214  my_channels[channel].techniques.push_back(MyTechnique(pFName, Params));
215  ++(my_channels[channel].info.NbOfTechniques);
216  if (DisplayParams == true)
217  {
218  my_channels[channel].techniques.back().print(std::cout);
219  }
220  return 0;
221 }
222 
223 BIOLOGIC_API(int) BL_UpdateParametersStub( int ID, uint8 channel, int TechIndx, TEccParams_t Params, const char* EccFileName )
224 {
225  DEBUG_PRINT("BL_UpdateParameters");
227  CHECK_CHANNEL(channel);
228  if (TechIndx >= my_channels[channel].techniques.size())
229  {
230  return -1;
231  }
232  my_channels[channel].techniques[TechIndx].copy(EccFileName, Params);
233  my_channels[channel].print(std::cout);
234  return 0;
235 }
236 
237 BIOLOGIC_API(int) BL_StartChannelStub (int ID, uint8 channel)
238 {
239  DEBUG_PRINT("BL_StartChannel");
241  CHECK_CHANNEL(channel);
242  my_channels[channel].info.State = KBIO_STATE_RUN;
243  my_channels[channel].print(std::cout);
244  time(&(my_channels[channel].start));
245  return 0;
246 }
247 
248 BIOLOGIC_API(int) BL_StopChannelStub (int ID, uint8 channel)
249 {
250  DEBUG_PRINT("BL_StopChannel");
252  CHECK_CHANNEL(channel);
253  my_channels[channel].info.State = KBIO_STATE_STOP;
254  return 0;
255 }
256 
257 BIOLOGIC_API(int) BL_GetCurrentValuesStub (int ID, uint8 channel, TCurrentValues_t *pValues)
258 {
259  DEBUG_PRINT("BL_GetCurrentValues");
261  CHECK_CHANNEL(channel);
262  pValues->State = my_channels[channel].info.State;
263  pValues->Ece = 2;
264  pValues->Eoverflow = 3;
265  pValues->TimeBase = 1e-6;
266  pValues->MemFilled = 0;
267  pValues->ElapsedTime = time(NULL) - my_channels[channel].start;
268  return 0;
269 }
270 
271 static unsigned castFloatToInt(float f)
272 {
273  union
274  {
275  float f;
276  unsigned u;
277  } cf;
278  cf.f = f;
279  return cf.u;
280 }
281 
282 BIOLOGIC_API(int) BL_GetDataStub( int ID, uint8 channel, TDataBuffer_t* pBuf, TDataInfos_t* pInfos, TCurrentValues_t* pValues )
283 {
284  DEBUG_PRINT("BL_GetData");
286  CHECK_CHANNEL(channel);
287  BL_GetCurrentValuesStub(ID, channel, pValues);
288  pInfos->NbRows = 0;
289  pInfos->NbCols = 0;
290  for(int i=0; i<my_channels[channel].techniques.size(); ++i)
291  {
292  size_t pos = my_channels[channel].techniques[i].name.find_last_of("\\/");
293  if (pos == std::string::npos)
294  {
295  pos = 0;
296  }
297  if (my_channels[channel].techniques[i].name.substr(pos+1) == "ocv4.ecc")
298  {
299  pInfos->NbRows = 1;
300  pInfos->NbCols = 3;
301  pInfos->TechniqueID = KBIO_TECHID_OCV;
302  pInfos->ProcessIndex = 0;
303  pInfos->StartTime = my_channels[channel].start;
304  __int64 t;
305  t = (time(NULL) - pInfos->StartTime) / pValues->TimeBase;
306  pBuf->data[0] = (t >> 32); // thigh
307  pBuf->data[1] = (t & 0xffffffff); // tlow
308  pBuf->data[2] = castFloatToInt(5); // ewe
309  }
310  if (my_channels[channel].techniques[i].name.substr(pos+1) == "peis4.ecc")
311  {
312  pInfos->TechniqueID = KBIO_TECHID_PEIS;
313  pInfos->NbRows = 1;
314  pInfos->StartTime = my_channels[channel].start;
315  if (time(NULL) % 2 == 0)
316  {
317  pInfos->ProcessIndex = 0;
318  pInfos->NbCols = 4;
319  __int64 t;
320  t = (time(NULL) - pInfos->StartTime) / pValues->TimeBase;
321  pBuf->data[0] = (t >> 32); // thigh
322  pBuf->data[1] = (t & 0xffffffff); // tlow
323  pBuf->data[2] = castFloatToInt(5); // ewe
324  pBuf->data[3] = castFloatToInt(5); // I
325  }
326  else
327  {
328  pInfos->ProcessIndex = 1;
329  pInfos->NbCols = 14;
330  pBuf->data[13] = castFloatToInt(10); // time
331  }
332  }
333  }
334  return 0;
335 }
336 
337 BIOLOGIC_API(int) BL_SetExperimentInfosStub( int ID, uint8 channel, TExperimentInfos_t TExpInfos )
338 {
339  DEBUG_PRINT("BL_SetExperimentInfos");
341  CHECK_CHANNEL(channel);
342  return 0;
343 }
344 
345 BIOLOGIC_API(int) BL_GetExperimentInfosStub( int ID, uint8 channel, TExperimentInfos_t* TExpInfos )
346 {
347  DEBUG_PRINT("BL_GetExperimentInfos");
349  CHECK_CHANNEL(channel);
350  memset(TExpInfos, 0, sizeof(TExperimentInfos_t));
351  return 0;
352 }
353 
354 
TEccParams_t params
uint8 const char TEccParams_t bool FirstTechnique
void copy(const char *nname, const TEccParams_t &nparams)
#define CHECK_CHANNEL(__CH)
uint8 int uint8 bool bool ForceReload
uint8 int TechIndx
uint8 int TDeviceInfos_t * pInfos
memcpy(pInfos,&(my_channels[ch].info), sizeof(TChannelInfos_t))
std::vector< MyTechnique > techniques
pVersion[*psize-1]
uint8 int uint8 bool bool const char const char * XlxFile
uint8 const char TEccParams_t bool bool LastTechnique
#define DEBUG_PRINT(__arg)
MyTechnique(const MyTechnique &t)
void print(std::ostream &os)
uint8 channel
uint8 * pChPlugged
uint8 TExperimentInfos_t TExpInfos
__int64 t
uint8 int uint8 Length
static MyChannel my_channels[16]
uint8 * pChannels
static int my_connection_id
uint8 const char TEccParams_t bool bool bool DisplayParams
uint8 int uint8 bool ShowGauge
uint8 TDataBuffer_t * pBuf
static const char * version
static bool BLSIM
uint8 TCurrentValues_t * pValues
strncpy(pVersion, version,*psize)
uint8 uint8 Size
static unsigned castFloatToInt(float f)
void print(std::ostream &os)
uint8 const char TEccParams_t Params
uint8 int TEccParams_t const char * EccFileName
uint8 int uint8 bool bool const char * BinFile
BIOLOGIC_API(int) BL_GetLibVersionStub(char *pVersion
uint8 int * pResults
std::string name
unsigned int * psize
uint8 timeout
Provide an interface to EC lab functions, converting error codes into C++ exceptions.
MyTechnique(const char *nname, const TEccParams_t &nparams)
uint8 int * pID
#define CHECK_CONNECTION_ID(__ID)
memset(TExpInfos, 0, sizeof(TExperimentInfos_t))
TChannelInfos_t info
#define NCHANNELS
uint8 const char * pFName
BL_GetCurrentValuesStub(ID, channel, pValues)
static void init_channels()
uint8 ch
Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5