FACT++  1.0
bool ConnectionBias::EvalAnswer ( const uint8_t *  answer,
uint16_t  id,
int  command 
)
inlineprivate

Definition at line 146 of file biasctrl.cc.

References Error(), i, id, BIAS::kCmdChannelSet, BIAS::kCmdGlobalSet, BIAS::kCmdRead, BIAS::kCmdReset, BIAS::kExpertChannelSet, kNumChannels, BIAS::kNumChannelsPerBoard, BIAS::kSynchronize, and Dim::SendCommandNB().

147  {
148  answer += id*3;
149 
150  const uint16_t status = (answer[0]>>7)&1;
151  const uint16_t wrap = (answer[0]>>4)&7;
152  const uint16_t ddd = ((uint16_t(answer[0])&0xf)<<8) | answer[1];
153  const uint16_t error = (answer[2]>>4)&0xf;
154  const uint16_t board = answer[2]&0xf;
155 
156  // 0x10 00 7f
157  // status = 0
158  // wrap = 1
159  // ddd = 0
160  // error = not present
161  // board = 15
162 
163  /*
164  Out() << dec << setw(2) << board << '|' << wrap << " ";
165  if (id%8==7)
166  Out() << endl;
167  */
168 
169  if (fWrapCounter>=0)
170  {
171  if ((fWrapCounter+1)%8 != wrap)
172  {
173  ostringstream msg;
174  msg << "Corrupted answer (id=" << id << "): received wrap counter " << wrap << " doesn't match last one " << fWrapCounter << " ";
175  msg << " (fSendCounter=" << fSendCounter << ")";
176  Error(msg);
177  return false;
178  }
179  }
180 
181  fWrapCounter = wrap;
182 
183  if (command==kSynchronize)
184  {
185  ostringstream msg;
186  msg << hex << setfill('0');
187  msg << "Initial answer received: 0x";
188  msg << setw(2) << (int)answer[2];
189  msg << setw(2) << (int)answer[1];
190  msg << setw(2) << (int)answer[0];
191  Message(msg);
192 
193  if (status!=0 || ddd!=0 || error!=0 || board!=0)
194  {
195  Warn("Initial answer doesn't seem to be a reset as naively expected.");
196 
197  //ostringstream msg;
198  //msg << hex << setfill('0');
199  //msg << "S=" << status << " D=" << ddd << " E=" << error << " B=" << board;
200  //Message(msg);
201  }
202 
203  fSendCounter = wrap;
204 
205  msg.str("");
206  msg << "Setting fSendCounter to " << wrap;
207  Info(msg);
208 
209  return true;
210  }
211 
212  if (error==0x8) // No device
213  {
214  Message("Reset button on crate pressed!");
215  RampAllDacs(0);
216  return true;
217  }
218 
219  if (command==kCmdReset)
220  {
221  if (status==0 && ddd==0 && error==0 && board==0)
222  {
223  Message("Reset successfully executed.");
224  return true;
225  }
226 
227  Warn("Answer to 'reset' command contains unexpected data.");
228  return false;
229  }
230 
231  if (command==kCmdGlobalSet)
232  {
233  if (status==0 && ddd==0 && error==0 && board==0)
234  {
235  for (int i=0; i<kNumChannels; i++)
237 
238  fGlobalDacCmd = -1;
239 
240  return true;
241  }
242 
243  Warn("Answer to 'global set' command contains unexpected data.");
244  return false;
245  }
246 
247  if ((command&0xff)==kExpertChannelSet)
248  id = command>>8;
249 
250  const int cmd = command&3;
251 
252  if (cmd==kCmdRead || cmd==kCmdChannelSet)
253  {
254  if (board!=id/kNumChannelsPerBoard)
255  {
256  ostringstream out;
257  out << "Talked to board " << id/kNumChannelsPerBoard << ", but got answer from board " << board << " (fSendCounter=" << fSendCounter << ")";
258  Error(out);
259  return false;
260  }
261 
262  // Not present
263  if (error==0x7 || error==0xf)
264  {
265  fPresent[board] = false;
266  fCurrent[id] = 0x8000;
267  return true;
268  }
269 
270  // There is no -0 therefore we make a trick and replace it by -1.
271  // This is not harmfull, because typical zero currents are in the
272  // order of one to three bits anyway and they are never stable.
273  fCurrent[id] = status ? -(ddd==0?1:ddd) : ddd;
274  fPresent[board] = true;
275 
276  if (!fEmergencyShutdown)
277  {
278  if (fCurrent[id]<0)
279  {
280  Warn("OverCurrent detected.");
281  fEmergencyShutdown = true;
282  }
283 
285  {
286  Warn("Emergency limit exceeded.");
287  fEmergencyShutdown = true;
288  }
289 
290  if (fEmergencyShutdown)
291  {
292  Error("Emergency ramp down initiated.");
293  Dim::SendCommandNB("MCP/STOP");
294  RampAllDacs(0);
295  }
296  }
297  }
298 
299  if (cmd==kCmdChannelSet)
301 
302  return true;
303 
304  }
vector< int16_t > fCurrent
Definition: biasctrl.cc:72
int64_t fWrapCounter
Definition: biasctrl.cc:47
int i
Definition: db_dim_client.c:21
int16_t fGlobalDacCmd
Definition: biasctrl.cc:50
char id[4]
Definition: FITS.h:71
bool fEmergencyShutdown
Definition: biasctrl.cc:68
int32_t fEmergencyLimit
Definition: biasctrl.cc:67
bool RampAllDacs(uint16_t dac)
Definition: biasctrl.cc:970
int64_t fSendCounter
Definition: biasctrl.cc:48
int Error(const std::string &str)
Definition: MessageImp.h:49
void SendCommandNB(const std::string &command)
Definition: Dim.h:30
int Warn(const std::string &str)
Definition: MessageImp.h:48
int Info(const std::string &str)
Definition: MessageImp.h:47
int Message(const std::string &str)
Definition: MessageImp.h:46
vector< bool > fPresent
Definition: biasctrl.cc:45
vector< uint16_t > fDacActual
Definition: biasctrl.cc:101
vector< uint16_t > fDacCommand
Definition: biasctrl.cc:100

+ Here is the call graph for this function: