source: trunk/Cosy/devdrv/dkc.cc@ 18121

Last change on this file since 18121 was 14593, checked in by tbretz, 12 years ago
Added error f2057
File size: 22.0 KB
Line 
1#include "dkc.h"
2
3#include <sys/time.h> // timeval->tv_sec
4
5#include <TGLabel.h>
6
7#include "network.h"
8
9#include "MLogManip.h"
10
11#include "MString.h"
12
13ClassImp(Dkc);
14
15using namespace std;
16
17//#define EXPERT
18
19Dkc::Dkc(const BYTE_t nodeid, const char *name)
20 : NodeDrv(nodeid, name), fMacId(2*nodeid+1),
21 fPdoPos1(0), fPdoPos2(0), fPosActive(0), fRpmActive(0),
22 fStatus(0xff), fStatusDKC(0), fStatusPdo3(0xff), fArmed(false),
23 fReport(NULL),fLabel(NULL),fUpdPos(0)
24{
25}
26
27TString Dkc::EvalStatusDKC(UInt_t stat) const
28{
29 switch (stat)
30 {
31 case 0: return "offline";
32 case 0xa000: case 0xa0000:
33 case 0xa001: case 0xa0001:
34 case 0xa002: case 0xa0002:
35 case 0xa003: case 0xa0003: return MString::Format("Communication phase %d", stat&0xf);
36 case 0xa010: case 0xa0010: return "Drive HALT";
37 case 0xa012: case 0xa0012: return "Control and power section ready for operation";
38 case 0xa013: case 0xa0013: return "Ready for power on";
39 case 0xa100: case 0xa0100: return "Drive in Torque mode";
40 case 0xa101: case 0xa0101: return "Drive in Velocity mode";
41 case 0xa102: case 0xa0102: return "Position control mode with encoder 1";
42 case 0xa103: case 0xa0103: return "Position control mode with encoder 2";
43 case 0xa104: case 0xa0104: return "Position control mode with encoder 1, lagless";
44 case 0xa105: case 0xa0105: return "Position control mode with encoder 2, lagless";
45 case 0xa106: case 0xa0106: return "Drive controlled interpolated positioning with encoder 1";
46 case 0xa107: case 0xa0107: return "Drive controlled interpolated positioning with encoder 2";
47 case 0xa108: case 0xa0108: return "Drive controlled interpolated positioning with encoder 1, lagless";
48 case 0xa109: case 0xa0109: return "Drive controlled interpolated positioning with encoder 2, lagless";
49 //case 0xa146: return "Drive controlled interpolated relative positioning with encoder 1";
50 //case 0xa147: return "Drive controlled interpolated relative positioning with encoder 2";
51 //case 0xa148: return "Drive controlled interpolated relative positioning lagless with encoder 1";
52 //case 0xa149: return "Drive controlled interpolated relative positioning lagless with encoder 2";
53 case 0xa150: case 0xa0150: return "Drive controlled positioning with encoder 1";
54 case 0xa151: case 0xa0151: return "Drive controlled positioning with encoder 1, lagless";
55 case 0xa152: case 0xa0152: return "Drive controlled positioning with encoder 2";
56 case 0xa153: case 0xa0153: return "Drive controlled positioning with encoder 2, lagless";
57 case 0xa208: return "Jog mode positive";
58 case 0xa218: return "Jog mode negative";
59 case 0xa400: case 0xa4000: return "Automatic drive check and adjustment";
60 case 0xa401: case 0xa4001: return "Drive decelerating to standstill";
61 case 0xa800: case 0xa0800: return "Unknown operation mode";
62 case 0xc217: return "Motor encoder reading error";
63 case 0xc218: return "Shaft encoder reading error";
64 case 0xc220: return "Motor encoder initialization error";
65 case 0xc221: return "Shaft encoder initialization error";
66 case 0xc300: return "Command: set absolute measure";
67 case 0xc400: case 0xc0400: return "Switching to parameter mode";
68 case 0xc401: case 0xc0401: return "Drive active, switching mode not allowed";
69 case 0xc500: case 0xc0500: return "Error reset";
70 case 0xc600: case 0xc0600: return "Drive controlled homing procedure";
71 case 0xe225: return "Motor overload";
72 case 0xe249: case 0xe2049: return "Positioning command velocity exceeds limit bipolar";
73 case 0xe250: return "Drive overtemp warning";
74 case 0xe251: return "Motor overtemp warning";
75 case 0xe252: return "Bleeder overtemp warning";
76 case 0xe257: return "Continous current limit active";
77 case 0xe259: return "Command velocity limit active";
78 case 0xe8260: return "Torque limit active";
79 case 0xe264: return "Target position out of numerical range";
80 case 0xe829: case 0xe8029: return "Positive position limit exceeded";
81 case 0xe830: case 0xe8030: return "Negative position limit exceeded";
82 case 0xe831: return "Position limit reached during jog";
83 case 0xe834: return "Emergency-Stop";
84 case 0xe842: return "Both end-switches activated";
85 case 0xe843: return "Positive end-switch activated";
86 case 0xe844: return "Negative end-switch activated";
87 case 0xf218: case 0xf2018: return "Amplifier overtemp shutdown";
88 case 0xf219: case 0xf2019: return "Motor overtemp shutdown";
89 case 0xf220: return "Bleeder overload shutdown";
90 case 0xf221: case 0xf2021: return "Motor temperature surveillance defective";
91 case 0xf2022: return "Unit temperature surveillance defective";
92 case 0xf224: return "Maximum breaking time exceeded";
93 case 0xf2025: return "Drive not ready for power on";
94 case 0xf228: case 0xf2028: return "Excessive control deviation";
95 case 0xf250: return "Overflow of target position preset memory";
96 case 0xf257: case 0xf2057: return "Command position out of range";
97 case 0xf269: return "Error during release of the motor holding brake";
98 case 0xf276: return "Absolute encoder out of allowed window";
99 case 0xf2174: return "Lost reference of motor encoder";
100 case 0xf409: case 0xf4009: return "Bus error on Profibus interface";
101 case 0xf434: return "Emergency-Stop";
102 case 0xf629: return "Positive position limit exceeded";
103 case 0xf630: return "Negative position limit exceeded";
104 case 0xf634: return "Emergency-Stop";
105 case 0xf643: return "Positive end-switch activated";
106 case 0xf644: return "Negative end-switch activated";
107 case 0xf8069: return "15V DC error";
108 case 0xf870: case 0xf8070: return "24V DC error";
109 case 0xf878: case 0xf8078: return "Velocity loop error";
110 case 0xf8079: return "Velocity limit exceeded";
111 case 0xf2026: return "Undervoltage in power section";
112 }
113 return "unknown";
114}
115
116TString Dkc::GetStatus(LWORD_t val) const
117{
118 const Int_t errnum = val&0xff;
119 const Int_t errinf = val>>8;
120
121 if (errnum!=0xff)
122 return "";
123
124 // DKC offline. This is a fatal error
125 if (errinf==0)
126 return "offline.";
127
128 TString str;
129
130 const Int_t type = (errinf&0xf0000)==0 ? ((errinf>>12)&0xf) : ((errinf>>16)&0xf);
131 switch (type)
132 {
133 case 0xf: str += "ERROR"; break;
134 case 0xe: str += "WARNING"; break;
135 case 0xa: str += "Status"; break;
136 case 0xc:
137 case 0xd: str += "Message"; break;
138 default: str += "Unknown"; break;
139 }
140
141 str += " (";
142 str += MString::Format("%X", errinf);
143 str += "): ";
144 str += EvalStatusDKC(errinf);
145 str += (type==0xf || type==0xe ? "!" : ".");
146
147 return str;
148}
149
150Bool_t Dkc::PrintStatus(LWORD_t val) const
151{
152 const Int_t errnum = val&0xff;
153 const Int_t errinf = val>>8;
154
155 if (errnum!=0xff)
156 return errnum==0;
157
158 gLog << all << MTime(-1) << ": " << GetNodeName() << " " << GetStatus(val) << endl;
159
160 // errinf==0: DKC offline. This is a fatal error
161 const Int_t type = (errinf&0xf0000)==0 ? ((errinf>>12)&0xf) : ((errinf>>16)&0xf);
162 return errinf==0 ? kFALSE : (type&0xf)!=0xf;
163}
164
165void Dkc::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv)
166{
167 // cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx;
168 // cout << ", val=0x" << val << endl;
169 switch (idx)
170 {
171 case 0x1000:
172 gLog << inf2 << "- " << GetNodeName() << ": Node is" << (val?" ":" not ") << "armed." << endl;
173 fArmed = val==1;
174 return;
175
176 case 0x1003:
177 // FIXME, see Init
178 gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << hex << val << dec << endl;
179 CheckErrorDKC(val);
180 return;
181
182 case 0x100a:
183 gLog << inf2 << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;
184 fSoftVersion = val;
185 return;
186
187 case 0x100b:
188 // Do not display, this is used for CheckConnection
189 // lout << "Node ID: " << dec << val << endl;
190 return;
191
192 case 0x2002:
193 gLog << inf2 << GetNodeName() << ": Current velocity: " << dec << val << endl;
194 fVel = val;
195 return;
196
197 case 0x6004:
198 fPdoPos1 = (LWORDS_t)val;
199 fPdoTime1.Set(tv);
200 fHasChangedPos1 = true;
201 return;
202
203 case 0x6005:
204 fPdoPos2 = (LWORDS_t)val;
205 fPdoTime2.Set(tv);
206 fHasChangedPos2 = true;
207 return;
208
209 case 0x6002:
210 gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " (1rpm)" << endl;
211 fVelRes = val;
212 return;
213
214 case 0x6003:
215 gLog << inf2 << "- " << GetNodeName() << ": Maximum velocity = " << dec << val << " (100%)" << endl;
216 fVelMax = val;
217 return;
218
219 case 0x6501:
220 gLog << inf2 << "- " << GetNodeName() << ": Position resolution = " << dec << val << " ticks/revolution" << endl;
221 fPosRes = val;
222 return;
223 }
224
225 NodeDrv::HandleSDO(idx, subidx, val, tv);
226
227 // cout << "Dkc: SDO, idx=0x"<< hex << idx << "/" << (int)subidx;
228 // cout << ", val=0x"<<val<<endl;
229}
230
231void Dkc::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)
232{
233 // cout << "Node #" << dec << (int)GetId() << ": Sdo=" << hex << idx << "/" << (int)subidx << " set." << endl;
234
235 // If a real drive operation is requested from the MACS and
236 // the MACS is not correctly initialized the operation is
237 // rejected. (This is expecially harmfull if the NoWait state
238 // is set incorrectly)
239 if (data)
240 {
241 gLog << warn << "- HandleSDOOK sets zombie." << endl;
242 SetZombie();
243 }
244
245 switch (idx)
246 {
247 case 0x1000:
248 gLog << inf2 << "- " << GetNodeName() << ": State of node set." << endl;
249 return;
250
251 case 0x1001:
252 gLog << inf2 << "- " << GetNodeName() << ": PDOs requested." << endl;
253 return;
254
255 case 0x2002:
256 gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl;
257 return;
258
259 case 0x2003:
260 gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl;
261 return;
262
263 case 0x3006:
264 gLog << inf2 << "- " << GetNodeName() << ": RPM mode switched." << endl;
265 return;
266
267 case 0x3007:
268 //gLog << inf2 << "- Velocity set (" << GetNodeName() << ")" << endl;
269 return;
270
271 case 0x4000:
272 HandleNodeguard(tv);
273 return;
274
275 case 0x6000:
276 gLog << inf2 << "- " << GetNodeName() << ": Rotation direction set." << endl;
277 return;
278
279 case 0x6002:
280 gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution set." << endl;
281 return;
282
283 case 0x6004:
284 gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
285 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
286 return;
287
288 case 0x6005:
289 gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
290 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
291 return;
292 }
293
294 NodeDrv::HandleSDOOK(idx, subidx, data, tv);
295}
296
297void Dkc::ReqVelRes()
298{
299 gLog << inf2 << "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl;
300 RequestSDO(0x6002);
301 WaitForSdo(0x6002);
302}
303
304void Dkc::ReqVelMax()
305{
306 gLog << inf2 << "- " << GetNodeName() << ": Requesting maximum velocity (velmax, 0x6003)." << endl;
307 RequestSDO(0x6003);
308 WaitForSdo(0x6003);
309}
310
311void Dkc::ReqPosRes()
312{
313 gLog << inf2 << "- " << GetNodeName() << ": Requesting position resolution (posres, 0x6501)." << endl;
314 RequestSDO(0x6501);
315 WaitForSdo(0x6501);
316}
317
318void Dkc::Arm()
319{
320 gLog << inf2 << "- " << GetNodeName() << ": Arming node." << endl;
321 SendSDO(0x1000, (LWORD_t)1);
322 WaitForSdo(0x1000);
323}
324
325void Dkc::Disarm()
326{
327 gLog << inf2 << "- " << GetNodeName() << ": Disarming Node." << endl;
328 SendSDO(0x1000, (LWORD_t)0);
329 WaitForSdo(0x1000);
330}
331
332void Dkc::CheckConnection()
333{
334 RequestSDO(0x100b);
335 WaitForSdo(0x100b);
336}
337
338void Dkc::Init()
339{
340 //
341 // Request current error status (FIXME: is the first entry in the
342 // error list)
343 //
344 gLog << inf2 << "- " << GetNodeName() << ": Requesting Error[0]." << endl;
345 RequestSDO(0x1003);
346 WaitForSdo(0x1003);
347
348 /*
349 if (HasError())
350 {
351 gLog << err << "Dkc::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;
352 SetZombie();
353 }
354 if (IsZombieNode())
355 return;
356 */
357
358 SetRpmMode(FALSE);
359
360 ReqPosRes(); // Init fVelRes
361 ReqVelRes(); // Init fVelRes
362 ReqVelMax(); // Init fVelMax
363
364 // Request to send all PDOs at least once
365 ReqPDOs();
366
367#ifdef EXPERT
368 Arm();
369#endif
370 gLog << inf2 << "- " << GetNodeName() << ": Checking armed status." << endl;
371 RequestSDO(0x1000);
372 WaitForSdo(0x1000);
373}
374
375void Dkc::StopDevice()
376{
377 //
378 // FIXME: This isn't called if the initialization isn't done completely!
379 //
380 SetRpmMode(FALSE);
381 Disarm();
382}
383
384void Dkc::ReqPDOs()
385{
386 gLog << inf2 << "- " << GetNodeName() << ": Requesting all PDOs." << endl;
387
388 SendSDO(0x1001, (LWORD_t)1);
389 WaitForSdo(0x1001);
390}
391
392void Dkc::ReqPos1()
393{
394 gLog << inf2 << "- " << GetNodeName() << ": Requesting position feedback 1." << endl;
395 RequestSDO(0x6004);
396 WaitForSdo(0x6004);
397}
398
399void Dkc::ReqPos2()
400{
401 gLog << inf2 << "- " << GetNodeName() << ": Requesting position feedback 2." << endl;
402 RequestSDO(0x6005);
403 WaitForSdo(0x6005);
404}
405
406void Dkc::ReqVel()
407{
408 gLog << inf2 << "- " << GetNodeName() << ": Requesting Velocity." << endl;
409 RequestSDO(0x2002);
410 WaitForSdo(0x2002);
411}
412
413void Dkc::SetVelocity(LWORD_t vel)
414{
415 gLog << dbg << "- Setting velocity to: " << vel << endl;
416 SendSDO(0x2002, vel); // velocity
417 WaitForSdo(0x2002);
418}
419
420void Dkc::SetVelocityRel(Double_t vel)
421{
422 gLog << dbg << "- Setting velocity to: " << vel*100 << "%" << endl;
423 SendSDO(0x2002, (LWORD_t)(vel*fVelMax+0.5)); // velocity
424 WaitForSdo(0x2002);
425}
426
427void Dkc::SetAcceleration(LWORD_t acc)
428{
429 gLog << dbg << "- Setting acceleration to: " << acc << endl;
430 SendSDO(0x2003, acc); // acceleration
431 WaitForSdo(0x2003);
432}
433
434void Dkc::SetRpmMode(BYTE_t mode)
435{
436 //
437 // SetRpmMode(FALSE) stop the motor, but lets the position control unit on
438 //
439 SendSDO(0x3006, mode ? string('s','t','r','t') : string('s','t','o','p'));
440 WaitForSdo(0x3006);
441}
442
443void Dkc::SetRpmVelocity(LWORDS_t cvel)
444{
445 SendSDO(0x3007, (LWORD_t)cvel);
446 WaitForSdo(0x3007);
447}
448
449void Dkc::SetLedVoltage(LWORDS_t volt)
450{
451 SendSDO(0x4000, (LWORD_t)volt);
452 WaitForSdo(0x4000);
453}
454
455void Dkc::StartRelPos(LWORDS_t pos)
456{
457 if (!fArmed)
458 {
459 gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl;
460 SetZombie();
461 return;
462 }
463
464 gLog << dbg << GetNodeName() << ": Starting relative positioning by " << (LWORDS_t)pos << " ticks." << endl;
465 SendSDO(0x6005, (LWORD_t)pos);
466 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
467}
468
469void Dkc::StartAbsPos(LWORDS_t pos)
470{
471 if (!fArmed)
472 {
473 gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl;
474 SetZombie();
475 return;
476 }
477
478 gLog << dbg << GetNodeName() << ": Starting absolute positioning to " << (LWORDS_t)pos << " ticks." << endl;
479 SendSDO(0x6004, (LWORD_t)pos);
480 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
481}
482
483void Dkc::StartAbsPosRev(Double_t pos)
484{
485 if (!fArmed)
486 {
487 gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl;
488 SetZombie();
489 return;
490 }
491
492 const LWORD_t p = (LWORD_t)(pos*fPosRes+.5);
493
494 gLog << dbg << GetNodeName() << ": Starting absolute positioning to " << p << " ticks." << endl;
495 SendSDO(0x6004, p);
496 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
497}
498
499void Dkc::SendMsg(BYTE_t data[6])
500{
501 GetNetwork()->SendCanFrame(fMacId, 0, 0, data[0], data[1], data[2], data[3], data[4], data[5]);
502}
503
504void Dkc::SendMsg(BYTE_t d0, BYTE_t d1, BYTE_t d2,
505 BYTE_t d3, BYTE_t d4, BYTE_t d5)
506{
507 GetNetwork()->SendCanFrame(fMacId, 0, 0, d0, d1, d2, d3, d4, d5);
508}
509
510void Dkc::HandlePDO1(const BYTE_t *data, const timeval_t &tv)
511{
512 // FIXME!!!! Only 0x4000 should do this to be
513 // CanOpen conform
514 //HandleNodeguard(tv);
515
516 fPdoPos1 = (data[3]<<24) | (data[2]<<16) | (data[1]<<8) | data[0];
517 fPdoTime1.Set(tv);
518 fHasChangedPos1 = true;
519
520 fPdoPos2 = (data[7]<<24) | (data[6]<<16) | (data[5]<<8) | data[4];
521 fPdoTime2.Set(tv);
522 fHasChangedPos2 = true;
523
524 if (fReport)
525 {
526 fReport->Lock("ShaftEncoder::HandlePDOType0");
527 *fReport << "FEEDBACK " << (int)GetId() << " " << fPdoTime1 << " PDO0 " << GetNodeName() << " " << fPdoPos1 << " " << fPdoPos2 << endl;
528 fReport->UnLock("ShaftEncoder::HandlePDOType0");
529 }
530}
531
532void Dkc::HandlePDO3(const BYTE_t *data, const timeval_t &tv)
533{
534 if (fStatus!=data[3])
535 {
536 fArmed = data[3]&0x01; // armed status
537 fPosActive = data[3]&0x02; // positioning active
538 fRpmActive = data[3]&0x04; // RPM mode switched on
539 // data[3]&0x08; // - unused -
540 // data[3]&0x10; // - unused -
541 // data[3]&0x20; // - unused -
542 //fInControl = data[3]&0x40; // motor uncontrolled
543 // data[3]&0x80; // axis resetted (after errclr, motor stop, motor on)
544
545 fStatus = data[3];
546 }
547
548 const LWORD_t stat = data[0] | (data[1]<<8);
549 if (fStatusPdo3!=stat)
550 {
551 gLog << inf << MTime(-1) << ": " << GetNodeName() << " - PDO3(0x" << hex << (int)stat << dec << ") = ";
552 const Bool_t ready = stat&0x001;
553 const Bool_t fuse = stat&0x002;
554 const Bool_t emcy = stat&0x004;
555 const Bool_t vltg = stat&0x008;
556 const Bool_t mode = stat&0x010;
557 const Bool_t rf = stat&0x020;
558 const Bool_t brake = stat&0x040;
559 const Bool_t power = stat&0x080;
560 const Bool_t alarm = stat&0x100; // UPS Alarm (FACT only)
561 const Bool_t batt = stat&0x200; // UPS on battery (FACT only)
562 const Bool_t charge = stat&0x400; // UPS charging (FACT only)
563 if (ready) gLog << "DKC-Ready ";
564 if (fuse) gLog << "FuseOk ";
565 if (emcy) gLog << "EmcyOk ";
566 if (vltg) gLog << "OvervoltOk ";
567 if (mode) gLog << "SwitchToManualMode ";
568 if (rf) gLog << "RF ";
569 if (brake) gLog << "BrakeOpen ";
570 if (power) gLog << "PowerOn ";
571 if (alarm) gLog << "UPS-PowerLoss ";
572 if (batt) gLog << "UPS-OnBattery ";
573 if (charge) gLog << "UPS-Charging ";
574 gLog << endl;
575
576 fStatusPdo3 = stat;
577 }
578}
579
580void Dkc::CheckErrorDKC(LWORD_t val)
581{
582 fStatusDKC = val;
583
584 const Bool_t rc = PrintStatus(val);
585 SetError(rc ? 0 : val);
586 if (!rc)
587 {
588 gLog << warn << "- CheckErrorDKC sets zombie." << endl;
589 SetZombie();
590 }
591}
592
593void Dkc::HandlePDO2(const BYTE_t *data, const timeval_t &tv)
594{
595 LWORDS_t errnum = (data[0]<<24) | (data[1]<<16) | (data[2]<<8) | data[3];
596 LWORDS_t errinf = (data[4]<<24) | (data[5]<<16) | (data[6]<<8) | data[7];
597
598 // Check if the DKC changed its status message
599 const Int_t type = (errinf&0xf0000)==0 ? ((errinf>>12)&0xf) : ((errinf>>16)&0xf);
600 if (errnum==0xff && (type&0xf)<=0xe)
601 {
602 CheckErrorDKC(errnum, errinf);
603 return;
604 }
605
606 // Check if MACS report error occursion.
607 // errnum==0 gives a sudden information that something happened. Now the
608 // microcontroller is running inside its interrupt procedure which
609 // stopped the normal program. The interrupt procedure should try to clear
610 // the error state of the hardware. This should never create a new error!
611 //
612 if (!errnum)
613 {
614 gLog << err << "- " << GetNodeName() << ": reports Error occursion." << endl;
615 gLog << "Dkc::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl;
616 SetZombie();
617 SetError(-1);
618 return;
619 }
620
621 //
622 // Now the error is handled by the hardware now it is the software part
623 // to react on it. The Error flag now is set to the correct value.
624 //
625 if (GetError()>0)
626 {
627 gLog << warn << GetNodeName() << ": WARNING! Previous error #" << GetError() << " unhandled (not cleared) by software." << endl;
628
629 //
630 // If the error is unhadled and/or not cleared, don't try it again.
631 //
632 if (GetError()==errnum)
633 return;
634 }
635
636 SetError(errnum);
637
638 gLog << err << GetNodeName() << " reports: ";
639 switch (errnum)
640 {
641 case 0xff:
642 EvalStatus(errnum, errinf);
643 return;
644
645 default:
646 gLog << "Error Nr. " << dec << errnum << ", " << errinf << endl;
647 }
648}
649
650// FIXME? Handling of fIsZombie?
651void Dkc::HandleError()
652{
653 //
654 // If there is no error we must not handle anything
655 //
656 if (!HasError())
657 return;
658
659 //
660 // If the program got into the: HandleError state before the hardware
661 // has finished handeling the error we have to wait for the hardware
662 // handeling the error
663 //
664 // FIXME: Timeout???
665 //
666// while (GetError()<0)
667// usleep(1);
668
669 //
670 // After this software and hardware should be in a state so that
671 // we can go on working 'as usual' Eg. Initialize a Display Update
672 //
673 gLog << inf << GetNodeName() << " Handling Error #" << dec << GetError() << endl;
674 switch (GetError())
675 {
676 case 0xff:
677 gLog << err << "DKC error! Go and check what is going on!" << endl;
678 return;
679
680 default:
681 gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
682
683 }
684}
685
686void Dkc::DisplayVal()
687{
688 const LWORDS_t pos = GetPdoPos2();
689 if (IsZombieNode())
690 {
691 if (fLabel)
692 fLabel->SetText(new TGString(""));
693 fUpdPos = ~pos;
694 return;
695 }
696
697 char text[21]="";
698 if (pos!=fUpdPos && fLabel)
699 {
700 sprintf(text, "%ld", pos);
701 fLabel->SetText(new TGString(text));
702 fUpdPos = pos;
703 }
704}
Note: See TracBrowser for help on using the repository browser.