Ignore:
Timestamp:
01/24/08 16:38:40 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r8811 r8835  
    11#include "macs.h"
    22
    3 #include <iostream>
    43#include <sys/time.h>   // timeval->tv_sec
    54
     
    2928*/
    3029
    31 Macs::Macs(const BYTE_t nodeid, const char *name, MLog &out)
    32     : NodeDrv(nodeid, name, out), fMacId(2*nodeid+1),
     30Macs::Macs(const BYTE_t nodeid, const char *name)
     31    : NodeDrv(nodeid, name), fMacId(2*nodeid+1),
    3332    fPos(0), fPdoPos(0), fPosActive(0), fRpmActive(0),
    3433    fStatusPdo3(0xff)
     
    5352        if (subidx!=2)
    5453            return;
    55         lout << "- " << GetNodeName() << ": Error[0]=" << dec << val << endl;
     54        gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << dec << val << endl;
    5655        SetError(val);
    5756        return;
    5857
    5958    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;
    6160        fSoftVersion = val;
    6261        return;
     
    6867
    6968    case 0x100c:
    70         lout << "- " << GetNodeName() << ": Guard time:" << dec << val << endl;
     69        gLog << inf2 << "- " << GetNodeName() << ": Guard time:" << dec << val << endl;
    7170        return;
    7271
    7372    case 0x100d:
    74         lout << "- " << GetNodeName() << ": Life time factor:" << dec << val << endl;
     73        gLog << inf2 << "- " << GetNodeName() << ": Life time factor:" << dec << val << endl;
    7574        return;
    7675
    7776    case 0x2002:
    78         cout << GetNodeName() << ": Current velocity: " << dec << val << endl;
     77        gLog << inf2 << GetNodeName() << ": Current velocity: " << dec << val << endl;
    7978        fVel = val;
    8079        return;
     
    123122
    124123    case 0x6002:
    125         lout << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl;
     124        gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl;
    126125        fVelRes = val;
    127126        return;
    128127
    129128    case 0x6501:
    130         lout << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl;
     129        gLog << inf2 << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl;
    131130        fRes = val;
    132131        return;
    133132    }
    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;
    136138}
    137139
     
    154156        case 1:
    155157            //lout << ddev(MLog::eGui);
    156             lout << "- " << GetNodeName() << ": State of node set." << endl;
     158            gLog << inf2 << "- " << GetNodeName() << ": State of node set." << endl;
    157159            //lout << edev(MLog::eGui);
    158160            return;
     
    165167        case 0:
    166168            //lout << ddev(MLog::eGui);
    167             lout << "- " << GetNodeName() << ": Guard time set." << endl;
     169            gLog << inf2 << "- " << GetNodeName() << ": Guard time set." << endl;
    168170            //lout << edev(MLog::eGui);
    169171            return;
     
    176178        case 0:
    177179            //lout << ddev(MLog::eGui);
    178             lout << "- " << GetNodeName() << ": Life time factor set." << endl;
     180            gLog << inf2 << "- " << GetNodeName() << ": Life time factor set." << endl;
    179181            //lout << edev(MLog::eGui);
    180182            return;
     
    187189        case 1:
    188190            //lout << ddev(MLog::eGui);
    189             lout << "- " << GetNodeName() << ": Status of PDO1 set." << endl;
     191            gLog << inf2 << "- " << GetNodeName() << ": Status of PDO1 set." << endl;
    190192            //lout << edev(MLog::eGui);
    191193            return;
     
    198200        case 0:
    199201            //lout << ddev(MLog::eGui);
    200             lout << "- " << GetNodeName() << ": Velocity set." << endl;
     202            gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl;
    201203            //lout << edev(MLog::eGui);
    202204            return;
     
    209211        case 0:
    210212            //lout << ddev(MLog::eGui);
    211             lout << "- " << GetNodeName() << ": Acceleration set." << endl;
     213            gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl;
    212214            //lout << edev(MLog::eGui);
    213215            return;
    214216        case 1:
    215217            //lout << ddev(MLog::eGui);
    216             lout << "- " << GetNodeName() << ": Deceleration set." << endl;
     218            gLog << inf2 << "- " << GetNodeName() << ": Deceleration set." << endl;
    217219            //lout << edev(MLog::eGui);
    218220            return;
     
    225227        case 0:
    226228            //lout << ddev(MLog::eGui);
    227             lout << "- " << GetNodeName() << ": RPM mode switched." << endl;
     229            gLog << inf2 << "- " << GetNodeName() << ": RPM mode switched." << endl;
    228230            //lout << edev(MLog::eGui);
    229231            return;
     
    245247    case 0x6000:
    246248        //lout << ddev(MLog::eGui);
    247         lout << "- " << GetNodeName() << ": Rotation direction set." << endl;
     249        gLog << inf2 << "- " << GetNodeName() << ": Rotation direction set." << endl;
    248250        //lout << edev(MLog::eGui);
    249251        return;
     
    251253    case 0x6002:
    252254        //lout << ddev(MLog::eGui);
    253         lout << "- " << GetNodeName() << ": Velocitz resolution set." << endl;
     255        gLog << inf2 << "- " << GetNodeName() << ": Velocitz resolution set." << endl;
    254256        //lout << edev(MLog::eGui);
    255257        return;
     
    260262        case 0:
    261263            //lout << ddev(MLog::eGui);
    262             lout << "- " << GetNodeName() << ": Absolute positioning started." << endl;
     264            gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
    263265            //lout << edev(MLog::eGui);
    264266            return;
     
    266268        case 1:
    267269            //lout << ddev(MLog::eGui);
    268             lout << "- " << GetNodeName() << ": Relative positioning started." << endl;
     270            gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
    269271            //lout << edev(MLog::eGui);
    270272            return;
     
    277279        case 0:
    278280            //lout << ddev(MLog::eGui);
    279             lout << "- " << GetNodeName() << ": Absolute positioning started." << endl;
     281            gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
    280282            //lout << edev(MLog::eGui);
    281283            return;
     
    283285        case 1:
    284286            //lout << ddev(MLog::eGui);
    285             lout << "- " << GetNodeName() << ": Relative positioning started." << endl;
     287            gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
    286288            //lout << edev(MLog::eGui);
    287289            return;
     
    296298void Macs::ReqVelRes()
    297299{
    298     lout << "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl;
     300    gLog << inf2 << "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl;
    299301    RequestSDO(0x6002);
    300302    WaitForSdo(0x6002);
     
    303305void Macs::ReqRes()
    304306{
    305     lout << "- " << GetNodeName() << ": Requesting encoder resolution (res, 0x6501)." << endl;
     307    gLog << inf2 << "- " << GetNodeName() << ": Requesting encoder resolution (res, 0x6501)." << endl;
    306308    RequestSDO(0x6501);
    307309    WaitForSdo(0x6501);
     
    310312void Macs::SetPDO1On(BYTE_t flag)
    311313{
    312     lout << "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl;
     314    gLog << inf2 << "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl;
    313315    SendSDO(0x1800, 1, (LWORD_t)(flag?0:1)<<31);
    314316    WaitForSdo(0x1800, 1);           
     
    322324    // After this the MACS will react on real movement commands.
    323325    //
    324     lout << "- " << GetNodeName() << ": Starting Node." << endl;
     326    gLog << inf2 << "- " << GetNodeName() << ": Starting Node." << endl;
    325327    SendSDO(0x1000, 1, (LWORD_t)1);
    326328    WaitForSdo(0x1000, 1);
     
    339341    // error list)
    340342    //
    341     lout << "- " << GetNodeName() << ": Requesting Error[0]." << endl;
     343    gLog << inf2 << "- " << GetNodeName() << ": Requesting Error[0]." << endl;
    342344    RequestSDO(0x1003, 2);
    343345    WaitForSdo(0x1003, 2);
    344346    if (HasError())
    345347    {
    346         lout << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;
     348        gLog << err << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;
    347349        SetZombie();
    348350    }
     
    353355    StopGuarding();
    354356
    355     lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;
     357    gLog << inf2 << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;
    356358    RequestSDO(0x100a);
    357359    WaitForSdo(0x100a);
     
    360362    if (fSoftVersion<0x00000045) // 00.69
    361363    {
    362         lout << GetNodeName() << " - Software Version too old!" << endl;
     364        gLog << err << GetNodeName() << " - Software Version too old!" << endl;
    363365        SetZombie();
    364366        return;
     
    431433void Macs::ReqPos()
    432434{
    433     lout << "- " << GetNodeName() << ": Requesting Position." << endl;
     435    gLog << inf2 << "- " << GetNodeName() << ": Requesting Position." << endl;
    434436    RequestSDO(0x6004);
    435437    WaitForSdo(0x6004);
     
    438440void Macs::ReqVel()
    439441{
    440     lout << "- " << GetNodeName() << ": Requesting Velocity." << endl;
     442    gLog << inf2 << "- " << GetNodeName() << ": Requesting Velocity." << endl;
    441443    RequestSDO(0x2002);
    442444    WaitForSdo(0x2002);
     
    523525    // or by a positioning command (POSA, ...)
    524526    //
    525     lout << "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl;
     527    gLog << inf2 << "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl;
    526528    SendSDO(0x3007, 0, string('s', 'y', 'n', 'c'));
    527529    WaitForSdo(0x3007, 0);
     
    534536    // or by a positioning command (POSA, ...)
    535537    //
    536     lout << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;
     538    gLog << inf2 << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;
    537539    SendSDO(0x3007, 1, string('s', 'y', 'n', 'c'));
    538540    WaitForSdo(0x3007, 1);
     
    591593    if (!errnum)
    592594    {
    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;
    595597        SetZombie();
    596598        SetError(-1);
     
    604606    if (GetError()>0)
    605607    {
    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;
    607609
    608610        //
     
    615617    SetError(errnum);
    616618
    617     lout << GetNodeName() << " reports: ";
     619    gLog << err << GetNodeName() << " reports: ";
    618620    switch (errnum)
    619621    {
    620622    case 3:
    621         lout << "Axis does not existing." << endl;
     623        gLog << "Axis does not existing." << endl;
    622624        return;
    623625    case 5:
    624         lout << "Error not cleared (while trying to move axis)" << endl;
     626        gLog << "Error not cleared (while trying to move axis)" << endl;
    625627        return;
    626628    case 6:
     
    630632        // from reporting this error a thousands of times.
    631633        //
    632         lout << "Home position not the first positioning command." << endl;
     634        gLog << "Home position not the first positioning command." << endl;
    633635        SetError(0);
    634636        return;
    635637    case 8:
    636         lout << "Control deviation overflow." << endl;
     638        gLog << "Control deviation overflow." << endl;
    637639        return;
    638640    case 9:
    639         lout << "Zero index not found." << endl;
     641        gLog << "Zero index not found." << endl;
    640642        return;
    641643    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;
    644646        return;
    645647    case 11:
     
    648650        {
    649651        case -1:
    650             lout << "Negative";
     652            gLog << "Negative";
    651653            break;
    652654        case 1:
    653             lout << "Positive";
     655            gLog << "Positive";
    654656            break;
    655657        default:
    656             lout << "-unknown-";
     658            gLog << "-unknown-";
    657659        }
    658660        switch (errnum)
    659661        {
    660662        case 11:
    661             lout << " software";
     663            gLog << " software";
    662664            break;
    663665        case 25:
    664             lout << " hardware";
     666            gLog << " hardware";
    665667            break;
    666668        }
    667         lout << " endswitch activated." << endl;
     669        gLog << " endswitch activated." << endl;
    668670        return;
    669671    case 12:
    670         lout << "Wrong parameter number used in SET command." << endl;
     672        gLog << "Wrong parameter number used in SET command." << endl;
    671673        return;
    672674    case 14:
    673         lout << " Too many LOOP calls." << endl;
     675        gLog << " Too many LOOP calls." << endl;
    674676        return;
    675677    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;
    678680        return;
    679681    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;
    682684        return;
    683685    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;
    686688        return;
    687689    case 19:
    688         lout << "User break (autostart program stopped by user)" << endl;
     690        gLog << "User break (autostart program stopped by user)" << endl;
    689691        return;
    690692    case 51:
    691         lout << "Too many (>=10) GOSUB calls." << endl;
     693        gLog << "Too many (>=10) GOSUB calls." << endl;
    692694        return;
    693695    case 52:
    694         lout << "Too many RETURN calls." << endl;
     696        gLog << "Too many RETURN calls." << endl;
    695697        return;
    696698    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;
    698700        return;
    699701    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;
    701703        return;
    702704    case 71:
    703         lout << "Array out of bound." << endl;
     705        gLog << "Array out of bound." << endl;
    704706        return;
    705707    case 79:
    706         lout << "Timeout waiting for index (WAITNDX)." << endl;
     708        gLog << "Timeout waiting for index (WAITNDX)." << endl;
    707709        return;
    708710    case 84:
    709         lout << "Too many (>12) ON TIME calls." << endl;
     711        gLog << "Too many (>12) ON TIME calls." << endl;
    710712        return;
    711713    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;
    714716        return;
    715717    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;
    717719        return;
    718720
     
    723725
    724726    default:
    725         lout << "Error Nr. " << errnum << ", " << errinf << endl;
     727        gLog << "Error Nr. " << errnum << ", " << errinf << endl;
    726728    }
    727729}
     
    737739    time.Now();
    738740
    739     lout << time << ": " << GetNodeName() << " - PDO3 = ";
     741    gLog << inf << time << ": " << GetNodeName() << " - PDO3 = ";
    740742    const Bool_t ready = data[3]&0x01;
    741743    const Bool_t fuse  = data[3]&0x02;
     
    745747    const Bool_t rf    = data[3]&0x20;
    746748    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;
    755757
    756758    fStatusPdo3 = data[3];
     
    780782    // we can go on working 'as usual' Eg. Initialize a Display Update
    781783    //
    782     cout << GetNodeName() << " Handling Error #" << dec << GetError() << endl;
     784    gLog << inf << GetNodeName() << " Handling Error #" << dec << GetError() << endl;
    783785    switch (GetError())
    784786    {
     
    787789    case   9: // zero idx
    788790    case  84: // ON TIME
    789         lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
     791        gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
    790792        return;
    791793
    792794    case 11:  // software endswitch
    793795    case 25:  // hardware endswitch
    794         lout << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl;
     796        gLog << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl;
    795797        return;
    796798
     
    805807        */
    806808    default:
    807         lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
     809        gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
    808810 
    809811    }
     
    850852    WaitForSdo(0x100d);
    851853
    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;
    854856}
    855857
     
    866868    WaitForSdo(0x100d);
    867869
    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.