Changeset 8835 for trunk/MagicSoft/Cosy/devdrv/macs.cc
- Timestamp:
- 01/24/08 16:38:40 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/macs.cc
r8811 r8835 1 1 #include "macs.h" 2 2 3 #include <iostream>4 3 #include <sys/time.h> // timeval->tv_sec 5 4 … … 29 28 */ 30 29 31 Macs::Macs(const BYTE_t nodeid, const char *name , MLog &out)32 : NodeDrv(nodeid, name , out), fMacId(2*nodeid+1),30 Macs::Macs(const BYTE_t nodeid, const char *name) 31 : NodeDrv(nodeid, name), fMacId(2*nodeid+1), 33 32 fPos(0), fPdoPos(0), fPosActive(0), fRpmActive(0), 34 33 fStatusPdo3(0xff) … … 53 52 if (subidx!=2) 54 53 return; 55 lout<< "- " << GetNodeName() << ": Error[0]=" << dec << val << endl;54 gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << dec << val << endl; 56 55 SetError(val); 57 56 return; 58 57 59 58 case 0x100a: 60 lout<< "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;59 gLog << inf2 << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl; 61 60 fSoftVersion = val; 62 61 return; … … 68 67 69 68 case 0x100c: 70 lout<< "- " << GetNodeName() << ": Guard time:" << dec << val << endl;69 gLog << inf2 << "- " << GetNodeName() << ": Guard time:" << dec << val << endl; 71 70 return; 72 71 73 72 case 0x100d: 74 lout<< "- " << GetNodeName() << ": Life time factor:" << dec << val << endl;73 gLog << inf2 << "- " << GetNodeName() << ": Life time factor:" << dec << val << endl; 75 74 return; 76 75 77 76 case 0x2002: 78 cout<< GetNodeName() << ": Current velocity: " << dec << val << endl;77 gLog << inf2 << GetNodeName() << ": Current velocity: " << dec << val << endl; 79 78 fVel = val; 80 79 return; … … 123 122 124 123 case 0x6002: 125 lout<< "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl;124 gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl; 126 125 fVelRes = val; 127 126 return; 128 127 129 128 case 0x6501: 130 lout<< "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl;129 gLog << inf2 << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl; 131 130 fRes = val; 132 131 return; 133 132 } 134 cout << "Macs: SDO, idx=0x"<< hex << idx << "/" << (int)subidx; 135 cout << ", val=0x"<<val<<endl; 133 134 NodeDrv::HandleSDO(idx, subidx, val, tv); 135 136 // cout << "Macs: SDO, idx=0x"<< hex << idx << "/" << (int)subidx; 137 // cout << ", val=0x"<<val<<endl; 136 138 } 137 139 … … 154 156 case 1: 155 157 //lout << ddev(MLog::eGui); 156 lout<< "- " << GetNodeName() << ": State of node set." << endl;158 gLog << inf2 << "- " << GetNodeName() << ": State of node set." << endl; 157 159 //lout << edev(MLog::eGui); 158 160 return; … … 165 167 case 0: 166 168 //lout << ddev(MLog::eGui); 167 lout<< "- " << GetNodeName() << ": Guard time set." << endl;169 gLog << inf2 << "- " << GetNodeName() << ": Guard time set." << endl; 168 170 //lout << edev(MLog::eGui); 169 171 return; … … 176 178 case 0: 177 179 //lout << ddev(MLog::eGui); 178 lout<< "- " << GetNodeName() << ": Life time factor set." << endl;180 gLog << inf2 << "- " << GetNodeName() << ": Life time factor set." << endl; 179 181 //lout << edev(MLog::eGui); 180 182 return; … … 187 189 case 1: 188 190 //lout << ddev(MLog::eGui); 189 lout<< "- " << GetNodeName() << ": Status of PDO1 set." << endl;191 gLog << inf2 << "- " << GetNodeName() << ": Status of PDO1 set." << endl; 190 192 //lout << edev(MLog::eGui); 191 193 return; … … 198 200 case 0: 199 201 //lout << ddev(MLog::eGui); 200 lout<< "- " << GetNodeName() << ": Velocity set." << endl;202 gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl; 201 203 //lout << edev(MLog::eGui); 202 204 return; … … 209 211 case 0: 210 212 //lout << ddev(MLog::eGui); 211 lout<< "- " << GetNodeName() << ": Acceleration set." << endl;213 gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl; 212 214 //lout << edev(MLog::eGui); 213 215 return; 214 216 case 1: 215 217 //lout << ddev(MLog::eGui); 216 lout<< "- " << GetNodeName() << ": Deceleration set." << endl;218 gLog << inf2 << "- " << GetNodeName() << ": Deceleration set." << endl; 217 219 //lout << edev(MLog::eGui); 218 220 return; … … 225 227 case 0: 226 228 //lout << ddev(MLog::eGui); 227 lout<< "- " << GetNodeName() << ": RPM mode switched." << endl;229 gLog << inf2 << "- " << GetNodeName() << ": RPM mode switched." << endl; 228 230 //lout << edev(MLog::eGui); 229 231 return; … … 245 247 case 0x6000: 246 248 //lout << ddev(MLog::eGui); 247 lout<< "- " << GetNodeName() << ": Rotation direction set." << endl;249 gLog << inf2 << "- " << GetNodeName() << ": Rotation direction set." << endl; 248 250 //lout << edev(MLog::eGui); 249 251 return; … … 251 253 case 0x6002: 252 254 //lout << ddev(MLog::eGui); 253 lout<< "- " << GetNodeName() << ": Velocitz resolution set." << endl;255 gLog << inf2 << "- " << GetNodeName() << ": Velocitz resolution set." << endl; 254 256 //lout << edev(MLog::eGui); 255 257 return; … … 260 262 case 0: 261 263 //lout << ddev(MLog::eGui); 262 lout<< "- " << GetNodeName() << ": Absolute positioning started." << endl;264 gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl; 263 265 //lout << edev(MLog::eGui); 264 266 return; … … 266 268 case 1: 267 269 //lout << ddev(MLog::eGui); 268 lout<< "- " << GetNodeName() << ": Relative positioning started." << endl;270 gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl; 269 271 //lout << edev(MLog::eGui); 270 272 return; … … 277 279 case 0: 278 280 //lout << ddev(MLog::eGui); 279 lout<< "- " << GetNodeName() << ": Absolute positioning started." << endl;281 gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl; 280 282 //lout << edev(MLog::eGui); 281 283 return; … … 283 285 case 1: 284 286 //lout << ddev(MLog::eGui); 285 lout<< "- " << GetNodeName() << ": Relative positioning started." << endl;287 gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl; 286 288 //lout << edev(MLog::eGui); 287 289 return; … … 296 298 void Macs::ReqVelRes() 297 299 { 298 lout<< "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl;300 gLog << inf2 << "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl; 299 301 RequestSDO(0x6002); 300 302 WaitForSdo(0x6002); … … 303 305 void Macs::ReqRes() 304 306 { 305 lout<< "- " << GetNodeName() << ": Requesting encoder resolution (res, 0x6501)." << endl;307 gLog << inf2 << "- " << GetNodeName() << ": Requesting encoder resolution (res, 0x6501)." << endl; 306 308 RequestSDO(0x6501); 307 309 WaitForSdo(0x6501); … … 310 312 void Macs::SetPDO1On(BYTE_t flag) 311 313 { 312 lout<< "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl;314 gLog << inf2 << "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl; 313 315 SendSDO(0x1800, 1, (LWORD_t)(flag?0:1)<<31); 314 316 WaitForSdo(0x1800, 1); … … 322 324 // After this the MACS will react on real movement commands. 323 325 // 324 lout<< "- " << GetNodeName() << ": Starting Node." << endl;326 gLog << inf2 << "- " << GetNodeName() << ": Starting Node." << endl; 325 327 SendSDO(0x1000, 1, (LWORD_t)1); 326 328 WaitForSdo(0x1000, 1); … … 339 341 // error list) 340 342 // 341 lout<< "- " << GetNodeName() << ": Requesting Error[0]." << endl;343 gLog << inf2 << "- " << GetNodeName() << ": Requesting Error[0]." << endl; 342 344 RequestSDO(0x1003, 2); 343 345 WaitForSdo(0x1003, 2); 344 346 if (HasError()) 345 347 { 346 lout<< "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;348 gLog << err << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl; 347 349 SetZombie(); 348 350 } … … 353 355 StopGuarding(); 354 356 355 lout<< "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;357 gLog << inf2 << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl; 356 358 RequestSDO(0x100a); 357 359 WaitForSdo(0x100a); … … 360 362 if (fSoftVersion<0x00000045) // 00.69 361 363 { 362 lout<< GetNodeName() << " - Software Version too old!" << endl;364 gLog << err << GetNodeName() << " - Software Version too old!" << endl; 363 365 SetZombie(); 364 366 return; … … 431 433 void Macs::ReqPos() 432 434 { 433 lout<< "- " << GetNodeName() << ": Requesting Position." << endl;435 gLog << inf2 << "- " << GetNodeName() << ": Requesting Position." << endl; 434 436 RequestSDO(0x6004); 435 437 WaitForSdo(0x6004); … … 438 440 void Macs::ReqVel() 439 441 { 440 lout<< "- " << GetNodeName() << ": Requesting Velocity." << endl;442 gLog << inf2 << "- " << GetNodeName() << ": Requesting Velocity." << endl; 441 443 RequestSDO(0x2002); 442 444 WaitForSdo(0x2002); … … 523 525 // or by a positioning command (POSA, ...) 524 526 // 525 lout<< "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl;527 gLog << inf2 << "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl; 526 528 SendSDO(0x3007, 0, string('s', 'y', 'n', 'c')); 527 529 WaitForSdo(0x3007, 0); … … 534 536 // or by a positioning command (POSA, ...) 535 537 // 536 lout<< "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;538 gLog << inf2 << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl; 537 539 SendSDO(0x3007, 1, string('s', 'y', 'n', 'c')); 538 540 WaitForSdo(0x3007, 1); … … 591 593 if (!errnum) 592 594 { 593 lout<< "- " << GetNodeName() << ": reports Error occursion." << endl;594 lout<< "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl;595 gLog << err << "- " << GetNodeName() << ": reports Error occursion." << endl; 596 gLog << "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl; 595 597 SetZombie(); 596 598 SetError(-1); … … 604 606 if (GetError()>0) 605 607 { 606 lout<< GetNodeName() << ": WARNING! Error #" << GetError() << " unhandled (not cleared) by software." << endl;608 gLog << warn << GetNodeName() << ": WARNING! Error #" << GetError() << " unhandled (not cleared) by software." << endl; 607 609 608 610 // … … 615 617 SetError(errnum); 616 618 617 lout<< GetNodeName() << " reports: ";619 gLog << err << GetNodeName() << " reports: "; 618 620 switch (errnum) 619 621 { 620 622 case 3: 621 lout<< "Axis does not existing." << endl;623 gLog << "Axis does not existing." << endl; 622 624 return; 623 625 case 5: 624 lout<< "Error not cleared (while trying to move axis)" << endl;626 gLog << "Error not cleared (while trying to move axis)" << endl; 625 627 return; 626 628 case 6: … … 630 632 // from reporting this error a thousands of times. 631 633 // 632 lout<< "Home position not the first positioning command." << endl;634 gLog << "Home position not the first positioning command." << endl; 633 635 SetError(0); 634 636 return; 635 637 case 8: 636 lout<< "Control deviation overflow." << endl;638 gLog << "Control deviation overflow." << endl; 637 639 return; 638 640 case 9: 639 lout<< "Zero index not found." << endl;641 gLog << "Zero index not found." << endl; 640 642 return; 641 643 case 10: 642 lout<< "Unknown command, syntax error." << endl;643 lout<< "Please recompile and reload program." << endl;644 gLog << "Unknown command, syntax error." << endl; 645 gLog << "Please recompile and reload program." << endl; 644 646 return; 645 647 case 11: … … 648 650 { 649 651 case -1: 650 lout<< "Negative";652 gLog << "Negative"; 651 653 break; 652 654 case 1: 653 lout<< "Positive";655 gLog << "Positive"; 654 656 break; 655 657 default: 656 lout<< "-unknown-";658 gLog << "-unknown-"; 657 659 } 658 660 switch (errnum) 659 661 { 660 662 case 11: 661 lout<< " software";663 gLog << " software"; 662 664 break; 663 665 case 25: 664 lout<< " hardware";666 gLog << " hardware"; 665 667 break; 666 668 } 667 lout<< " endswitch activated." << endl;669 gLog << " endswitch activated." << endl; 668 670 return; 669 671 case 12: 670 lout<< "Wrong parameter number used in SET command." << endl;672 gLog << "Wrong parameter number used in SET command." << endl; 671 673 return; 672 674 case 14: 673 lout<< " Too many LOOP calls." << endl;675 gLog << " Too many LOOP calls." << endl; 674 676 return; 675 677 case 16: 676 lout<< "Parameter in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl;677 lout<< "Please use APOSS to 'Reset' the MACS and reload the parameters." << endl;678 gLog << "Parameter in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl; 679 gLog << "Please use APOSS to 'Reset' the MACS and reload the parameters." << endl; 678 680 return; 679 681 case 17: 680 lout<< "Program in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl;681 lout<< "Please use APOSS to delete all Programs restore the programs." << endl;682 gLog << "Program in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl; 683 gLog << "Please use APOSS to delete all Programs restore the programs." << endl; 682 684 return; 683 685 case 18: 684 lout<< "Reset by CPU (reset called by Watch-dog cause of CPU halted)" << endl;685 lout<< "Possible reasons: short under-/overvoltage or shortcut." << endl;686 gLog << "Reset by CPU (reset called by Watch-dog cause of CPU halted)" << endl; 687 gLog << "Possible reasons: short under-/overvoltage or shortcut." << endl; 686 688 return; 687 689 case 19: 688 lout<< "User break (autostart program stopped by user)" << endl;690 gLog << "User break (autostart program stopped by user)" << endl; 689 691 return; 690 692 case 51: 691 lout<< "Too many (>=10) GOSUB calls." << endl;693 gLog << "Too many (>=10) GOSUB calls." << endl; 692 694 return; 693 695 case 52: 694 lout<< "Too many RETURN calls." << endl;696 gLog << "Too many RETURN calls." << endl; 695 697 return; 696 698 case 62: 697 lout<< "Error veryfiing EEPROM after access (Try again savaing parameters or program)" << endl;699 gLog << "Error veryfiing EEPROM after access (Try again savaing parameters or program)" << endl; 698 700 return; 699 701 case 70: 700 lout<< "Error in DIM call (call to DIM doesn't fit existing DIM call)" << endl;702 gLog << "Error in DIM call (call to DIM doesn't fit existing DIM call)" << endl; 701 703 return; 702 704 case 71: 703 lout<< "Array out of bound." << endl;705 gLog << "Array out of bound." << endl; 704 706 return; 705 707 case 79: 706 lout<< "Timeout waiting for index (WAITNDX)." << endl;708 gLog << "Timeout waiting for index (WAITNDX)." << endl; 707 709 return; 708 710 case 84: 709 lout<< "Too many (>12) ON TIME calls." << endl;711 gLog << "Too many (>12) ON TIME calls." << endl; 710 712 return; 711 713 case 87: 712 lout<< "Out of memory for variables - Check APOSS predifined number of" << endl;713 lout<< "variables and try deleting the array by doing a 'Reset' from APOSS." << endl;714 gLog << "Out of memory for variables - Check APOSS predifined number of" << endl; 715 gLog << "variables and try deleting the array by doing a 'Reset' from APOSS." << endl; 714 716 return; 715 717 case 89: 716 lout<< "CAN I/O error (REOPEN=" << dec << errinf << " " << (errinf==0?"OK":"ERR") << ")" << endl;718 gLog << "CAN I/O error (REOPEN=" << dec << errinf << " " << (errinf==0?"OK":"ERR") << ")" << endl; 717 719 return; 718 720 … … 723 725 724 726 default: 725 lout<< "Error Nr. " << errnum << ", " << errinf << endl;727 gLog << "Error Nr. " << errnum << ", " << errinf << endl; 726 728 } 727 729 } … … 737 739 time.Now(); 738 740 739 lout<< time << ": " << GetNodeName() << " - PDO3 = ";741 gLog << inf << time << ": " << GetNodeName() << " - PDO3 = "; 740 742 const Bool_t ready = data[3]&0x01; 741 743 const Bool_t fuse = data[3]&0x02; … … 745 747 const Bool_t rf = data[3]&0x20; 746 748 const Bool_t brake = data[3]&0x40; 747 if (ready) lout<< "DKC-Ready ";748 if (fuse) lout<< "FuseOk ";749 if (emcy) lout<< "EmcyOk ";750 if (vltg) lout<< "OvervoltOk ";751 if (mode) lout<< "SwitchToManualMode ";752 if (rf) lout<< "RF ";753 if (brake) lout<< "BrakeOpen ";754 lout<< endl;749 if (ready) gLog << "DKC-Ready "; 750 if (fuse) gLog << "FuseOk "; 751 if (emcy) gLog << "EmcyOk "; 752 if (vltg) gLog << "OvervoltOk "; 753 if (mode) gLog << "SwitchToManualMode "; 754 if (rf) gLog << "RF "; 755 if (brake) gLog << "BrakeOpen "; 756 gLog << endl; 755 757 756 758 fStatusPdo3 = data[3]; … … 780 782 // we can go on working 'as usual' Eg. Initialize a Display Update 781 783 // 782 cout<< GetNodeName() << " Handling Error #" << dec << GetError() << endl;784 gLog << inf << GetNodeName() << " Handling Error #" << dec << GetError() << endl; 783 785 switch (GetError()) 784 786 { … … 787 789 case 9: // zero idx 788 790 case 84: // ON TIME 789 lout<< "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;791 gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl; 790 792 return; 791 793 792 794 case 11: // software endswitch 793 795 case 25: // hardware endswitch 794 lout<< "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl;796 gLog << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl; 795 797 return; 796 798 … … 805 807 */ 806 808 default: 807 lout<< "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;809 gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl; 808 810 809 811 } … … 850 852 WaitForSdo(0x100d); 851 853 852 lout<< "- " << GetNodeName() << ": Hostguarding started (" << dec;853 lout<< GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl;854 gLog << inf2 << "- " << GetNodeName() << ": Hostguarding started (" << dec; 855 gLog << GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl; 854 856 } 855 857 … … 866 868 WaitForSdo(0x100d); 867 869 868 lout<< "- " << GetNodeName() << ": Hostguarding stopped." << endl;869 } 870 870 gLog << inf2 << "- " << GetNodeName() << ": Hostguarding stopped." << endl; 871 } 872
Note:
See TracChangeset
for help on using the changeset viewer.