Changeset 1727 for trunk/MagicSoft/Cosy/devdrv/macs.cc
- Timestamp:
- 01/23/03 13:32:58 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/macs.cc
r1703 r1727 33 33 fPosActive(0), fRpmActive(0) 34 34 { 35 fTimeout = new TTimer(this, 100, kFALSE); // 100ms, asynchronous35 // fTimeout = new TTimer(this, 100); //, kFALSE); // 100ms, asynchronous 36 36 } 37 37 38 38 Macs::~Macs() 39 39 { 40 fTimerOn = kFALSE;41 delete fTimeout;40 //fTimerOn = kFALSE; 41 // delete fTimeout; 42 42 } 43 43 … … 60 60 fVel = val; 61 61 return; 62 63 case 0x4000:64 switch (subidx)65 {66 case 1:67 cout << GetNodeName() << ": Timeout timer is " << (val?"en":"dis") << "abled." << endl;68 return;69 case 2:70 cout << GetNodeName() << ": Actual timeout time: " << dec << val << "ms" << endl;71 return;72 }73 break;74 62 75 63 case 0x6004: … … 129 117 } 130 118 131 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx )119 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv) 132 120 { 133 121 switch (idx) … … 137 125 { 138 126 case 0: 139 lout << ddev(MLog::eGui);127 //lout << ddev(MLog::eGui); 140 128 lout << "- " << GetNodeName() << ": Velocity set." << endl; 141 lout << edev(MLog::eGui);129 //lout << edev(MLog::eGui); 142 130 return; 143 131 } 144 132 break; 133 145 134 case 0x2003: 146 135 switch (subidx) 147 136 { 148 137 case 0: 149 lout << ddev(MLog::eGui);138 //lout << ddev(MLog::eGui); 150 139 lout << "- " << GetNodeName() << ": Acceleration set." << endl; 151 lout << edev(MLog::eGui);140 //lout << edev(MLog::eGui); 152 141 return; 153 142 case 1: 154 lout << ddev(MLog::eGui);143 //lout << ddev(MLog::eGui); 155 144 lout << "- " << GetNodeName() << ": Decceleration set." << endl; 156 lout << edev(MLog::eGui);145 //lout << edev(MLog::eGui); 157 146 return; 158 147 } 159 148 break; 149 160 150 case 0x3006: 161 151 switch (subidx) 162 152 { 163 153 case 0: 164 lout << ddev(MLog::eGui);154 //lout << ddev(MLog::eGui); 165 155 lout << "- " << GetNodeName() << ": RPM mode switched." << endl; 166 lout << edev(MLog::eGui);156 //lout << edev(MLog::eGui); 167 157 return; 168 158 … … 176 166 } 177 167 break; 168 178 169 case 0x4000: 179 if (subidx==0 && fTimerOn) 180 { 181 ResetTimeout(); 182 return; 183 } 184 break; 170 HandleNodeguard(tv); 171 return; 172 185 173 case 0x6004: 186 174 switch (subidx) 187 175 { 188 176 case 0: 189 lout << ddev(MLog::eGui);177 //lout << ddev(MLog::eGui); 190 178 lout << "- " << GetNodeName() << ": Absolute positioning started." << endl; 191 lout << edev(MLog::eGui);179 //lout << edev(MLog::eGui); 192 180 return; 193 181 194 182 case 1: 195 lout << ddev(MLog::eGui);183 //lout << ddev(MLog::eGui); 196 184 lout << "- " << GetNodeName() << ": Relative positioning started." << endl; 197 lout << edev(MLog::eGui);185 //lout << edev(MLog::eGui); 198 186 return; 199 187 } … … 202 190 203 191 } 204 NodeDrv::HandleSDOOK(idx, subidx );192 NodeDrv::HandleSDOOK(idx, subidx, tv); 205 193 } 206 194 … … 231 219 RequestSDO(0x100b); 232 220 WaitForSdo(0x100b); 233 234 // FIXME! Not statically linked!235 // if (fSoftVersion<0x00000035)236 // fIsZombie = true;237 221 } 238 222 … … 240 224 void Macs::Init() 241 225 { 226 if (HasError()) 227 { 228 lout << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl; 229 SetZombie(); 230 } 231 232 StopHostGuarding(); 233 StopGuarding(); 234 235 usleep(2000.*GetGuardTime()); 236 242 237 lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl; 243 238 RequestSDO(0x100a); 244 239 WaitForSdo(0x100a); 245 240 246 if ( fIsZombie)241 if (IsZombieNode()) 247 242 { 248 243 lout << GetNodeName() << " - InitDevice failed!" << endl; … … 250 245 } 251 246 252 EnableTimeout(kFALSE); 247 // FIXME! Not statically linked! 248 if (fSoftVersion<0x00000042) // 00.66 249 { 250 lout << GetNodeName() << " - Software Version too old!" << endl; 251 SetZombie(); 252 return; 253 } 254 253 255 SetRpmMode(FALSE); 254 256 … … 270 272 271 273 SetNoWait(TRUE); 274 275 StartGuarding(100, 2); 276 StartHostGuarding(); 272 277 } 273 278 … … 283 288 void Macs::StopDevice() 284 289 { 285 EnableTimeout(kFALSE);290 //EnableTimeout(kFALSE); 286 291 287 292 SetNoWait(FALSE); … … 348 353 { 349 354 SendSDO(0x2002, vel); // velocity 350 WaitForSdo(0x2002 );355 WaitForSdo(0x2002, 0); 351 356 } 352 357 … … 466 471 { 467 472 lout << "- " << GetNodeName() << ": reports Error occursion." << endl; 473 lout << "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl; 474 SetZombie(); 468 475 SetError(-1); 469 476 return; … … 537 544 538 545 case 100: 539 lout << "Connection timed out." << endl;540 EnableTimeout(false);546 //lout << "Connection timed out." << endl; 547 //EnableTimeout(false); 541 548 return; 542 549 … … 562 569 // FIXME: Timeout??? 563 570 // 564 565 571 // while (GetError()<0) 572 // usleep(1); 566 573 567 574 // … … 569 576 // we can go on working 'as usual' Eg. Initialize a Display Update 570 577 // 571 cout << GetNodeName() << " Handling Error #" << GetError() << endl;578 cout << GetNodeName() << " Handling Error #" << dec << GetError() << endl; 572 579 switch (GetError()) 573 580 { … … 576 583 case 9: // zero idx 577 584 case 84: // ON TIME 578 // Stop program?585 lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl; 579 586 return; 580 587 581 588 case 11: // software endswitch 582 589 case 25: // hardware endswitch 590 lout << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl; 591 return; 592 583 593 case 100: // timeout (movement has been stopped, so we can go on) 584 594 DelError(); 585 595 return; 586 596 /* 587 597 case 101: 588 lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl;598 //lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl; 589 599 DelError(); 590 600 return; 601 */ 602 default: 603 lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl; 604 591 605 } 592 606 } … … 633 647 } 634 648 635 void Macs::ReqTimeoutTime() 636 { 637 RequestSDO(0x4000, 2); 638 WaitForSdo(0x4000, 2); 639 } 640 641 void Macs::EnableTimeout(bool enable, LWORDS_t ms) 642 { 643 lout << "- " << GetNodeName() << ": " << (enable?"En":"Dis") << "able timeout, " << dec << ms << "ms." << endl; 644 if (!enable) 645 { 646 SendSDO(0x4000, 1, string('o', 'f', 'f')); 647 WaitForSdo(0x4000, 1); 648 649 lout << "- " << GetNodeName() << ": Stopping handshake (PC)." << endl; 650 651 fTimeout->Stop(); //kTRUE); 652 653 fTimerOn = kFALSE; 654 } 655 else 656 { 657 if (ms>0) 658 SetTimeoutTime(ms); 659 660 ResetTimeout(); 661 662 fTimerOn = kTRUE; 663 fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); //kFALSE); //TRUE); 664 665 // 666 // Start with kFALSE would be a continous timer, but this 667 // timer seems to stop it's activity at some stage without 668 // any reason 669 // 670 lout << "- " << GetNodeName() << ": starting handshake." << endl; 671 SendSDO(0x4000, 1, string('o', 'n')); 672 WaitForSdo(0x4000, 1); 673 } 674 lout << "- " << GetNodeName() << ": Timeout timer turned " 675 << (enable?"on.":"off.") << endl; 676 } 677 678 Bool_t Macs::HandleTimer(TTimer *t) 679 { 680 /* 681 Fons: 682 ----- 683 684 timers never trigger at the same time or when in a TTimer::Notify. 685 Little explanation: 686 687 - there are two types of timers synchronous and a-synchronous. 688 - synchronous timers are only handled via the ROOT eventloop 689 (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard 690 events then the synchronous timer queue is checked. So if the processing 691 of a mouse/keyboard event takes a long time synchronous timers are not 692 called for a while. To prevent this from happening one can call in long 693 procedures gSystem->ProcessEvents(). The system schedules only the 694 next timer in the queue when the current one's Notify() has finished. 695 - a-synchronous timers are triggered via SIGALARM, i.e. the program is 696 interupted and execution jumps to the Notify() function. When the 697 notify is finished the next a-sync timer is scheduled and the system 698 resumes from the place where it was initially interrupted. One of the 699 things to remember when using a-sync timers is don't make any graphics 700 calls in them. X11 is not re-entrant and it might be that the SIGALARM 701 signal interrupted the system while being in X11. A-sync timers are best 702 used to set flags that you can test at a convenient and controlled 703 time. 704 */ 705 706 // 707 // FIXME! Use NMT! 708 // 709 // --- lout << ddev(MLog::eGui); 710 // --- lout << "Send 0x4000: " << GetNodeName() << endl; 711 649 void Macs::SendNodeguard() 650 { 712 651 SendSDO(0x4000, 0, (LWORD_t)0, false); 713 714 // --- lout << "Done 0x4000: " << GetNodeName() << endl; 715 716 Timer time; 717 718 // --- lout << "dT " << GetNodeName() << ": " << dec <<(int)((fTimeoutTime-time.Now())*1000) << endl; 719 // --- lout << edev(MLog::eGui); 720 721 if (time.Now() > fTimeoutTime) 722 { 723 lout << ddev(MLog::eGui); 724 lout << "Warning: " << GetNodeName() << " didn't respond in timeout window." << endl; 725 lout << edev(MLog::eGui); 726 SetError(101); 727 } 728 729 //WaitForSdo(0x4000, 0, kDontWait); 730 // 731 // Would not be necessary if I would Start the timer with 732 // kFALSE. This would be a continous timer, but this 733 // timer seems to stop it's activity at some stage without 734 // any reason 735 // 736 if (fTimerOn) 737 fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); 738 739 return kTRUE; 740 } 741 742 void Macs::ResetTimeout() 743 { 744 Timer time; 745 746 // --- lout << ddev(MLog::eGui); 747 // --- lout << "Reset " << GetNodeName() << ": " << dec << (int)((fTimeoutTime-time.Now())*1000) << endl; 748 // --- lout << edev(MLog::eGui); 749 750 fTimeoutTime = time.Now() + 3.*fGuardTime/1000.; 751 } 752 753 void Macs::SetTimeoutTime(LWORD_t ms) 754 { 755 // FIXME: Is '/2' the best choose? 756 fGuardTime = ms/3; // how often do we send/request the handshake 757 758 SendSDO(0x4000, 2, ms*2); // How often do we check for the handshake 759 WaitForSdo(0x4000, 2); 760 } 761 652 } 653 654 // -------------------------------------------------------------------------- 655 // 656 // This starts the host guarding. The host guarding is only available 657 // if the node guarding is running. The host guarding works with the 658 // guardtime and the lifetimefactor from the nodeguarding. 659 // 660 void Macs::StartHostGuarding() 661 { 662 SendSDO(0x100c, 0, (LWORD_t)GetGuardTime()); 663 WaitForSdo(0x100c); 664 665 SendSDO(0x100d, 0, (LWORD_t)GetLifeTimeFactor()); 666 WaitForSdo(0x100d); 667 668 lout << "- " << GetNodeName() << ": Hostguarding started (" << dec; 669 lout << GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl; 670 } 671 672 // -------------------------------------------------------------------------- 673 // 674 // Stop the host guarding. 675 // 676 void Macs::StopHostGuarding() 677 { 678 SendSDO(0x100c, 0, (LWORD_t)0); 679 WaitForSdo(0x100c); 680 681 SendSDO(0x100d, 0, (LWORD_t)0); 682 WaitForSdo(0x100d); 683 684 lout << "- " << GetNodeName() << ": Hostguarding stopped." << endl; 685 } 686
Note:
See TracChangeset
for help on using the changeset viewer.