Changeset 8813


Ignore:
Timestamp:
01/16/08 14:07:42 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/candrv
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/candrv/canopen.cc

    r2518 r8813  
    1818!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>, 2003
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    3232#include "canopen.h"
    3333
    34 #include <iostream> // cout
    35 #include <iomanip>  // setw, setfill
     34#include "MLog.h"
     35#include "MLogManip.h"
     36
     37#include "interface.h"
    3638
    3739ClassImp(CanOpen);
     
    4446// PDO combinations
    4547//
    46 CanOpen::CanOpen(const char *dev, const int baud, MLog &out) : VmodIcan(dev, baud, out)
    47 {
    48     lout << "- CanOpen initialized." << endl;
     48CanOpen::CanOpen() : fInterface(0)
     49{
     50    gLog << inf << "- CanOpen initialized." << endl;
    4951}
    5052
     
    5557CanOpen::~CanOpen()
    5658{
    57     lout << "- CanOpen destroyed." << endl;
    58 }
    59 
    60 // --------------------------------------------------------------------------
    61 //
    62 // This overloads VmodIcan::HandleCanMessage. It is called if a can
     59    gLog << inf << "- CanOpen destroyed." << endl;
     60}
     61
     62// --------------------------------------------------------------------------
     63//
     64// Start the interface
     65//
     66void CanOpen::Start()
     67{
     68    if (fInterface)
     69        fInterface->Start();
     70}
     71
     72// --------------------------------------------------------------------------
     73//
     74// Stop the interface
     75//
     76void CanOpen::Stop()
     77{
     78    if (fInterface)
     79        fInterface->Stop();
     80}
     81
     82// --------------------------------------------------------------------------
     83//
     84// This overloads Interface::HandleCanMessage. It is called if a can
    6385// message was received with all message relevant data (COBId, data, time)
    6486// It distributes the data depending on its function code to several
     
    6991//  HandlePDO1/2/3/4:handles received PDOs
    7092//
    71 void CanOpen::HandleCanMessage(WORD_t cobid, BYTE_t *data, timeval_t *tv)
     93void CanOpen::HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv)
    7294{
    7395    const WORD_t fcode = cobid >> 7;
     
    105127            const WORD_t  subidx = data[3];
    106128
     129            cout << "SND NODE: " << (int)node << " " << flush;
    107130            HandleSDO(node, cmd, idx, subidx, dat, tv);
    108131
     
    145168// --------------------------------------------------------------------------
    146169//
     170// Does a basic message processing and hadles the so called command (cmd)
     171// stamp of the message. This is some kind of message type which is send
     172// by the can interface
     173//
     174void CanOpen::HandleMessage(const Message &msg, const timeval_t &tv)
     175{
     176    //
     177    // Decode message
     178    //
     179    const WORD_t desc  = msg.data[2]<<8 | msg.data[3];
     180    const BYTE_t rtr   = (desc>>4)&1;
     181    const BYTE_t len   = desc&0xf;
     182    const WORD_t cobid = desc>>5;
     183
     184    switch (msg.cmd) // FROM mican.h
     185    {
     186    case M_MSG_LOST:
     187        cout << "Interface reports: " << dec << (int)msg.data[0] << " msg(s) lost!" << endl;
     188        return;
     189
     190    case M_BCAN_TX_con:  /* confirm (+/-) transmission */
     191        cout << "Interface reports: CTXcon=0x35" << endl;
     192        cout << "This normally means, that the transmission of the following CAN frame failed:" << hex << endl;
     193        cout << "Descr: 0x" << cobid << dec;
     194        cout << "  Rtr: "   << (rtr?"Yes":"No");
     195        cout << "  Len: "   << (int)len << endl;
     196        return;
     197
     198    case M_BCAN_EVENT_ind:
     199        cout << "Interface reports: CEVTind=0x37: " << hex;
     200        switch (msg.data[0]) // error indicator
     201        {
     202        case 0x01:
     203            cout << "Error interrup occured" << endl;
     204            cout << "This means noisy network normally. Please check the bus termination." << endl;
     205            switch (msg.data[1]) // msg type (board depending)
     206            {
     207            case 2: // SJA1000
     208                cout << dec;
     209                cout << "ModeReg=" << (int)msg.data[2] << ", ";
     210                cout << "StatReg=" << (int)msg.data[3] << ", ";
     211                cout << "RxErrCnt=" << (int)msg.data[4] << ", ";
     212                cout << "TxErrCnt=" << (int)msg.data[5] << endl;
     213            }
     214            //FIXME? TerminateApp();
     215            return;
     216        case 0x02:
     217            cout << "Overrun interrup occured" << endl;
     218            return;
     219        case 0x04:
     220            cout << "Interrupts lost" << endl;
     221            return;
     222        case 0x08:
     223            cout << "Send queue full" << endl;
     224            return;
     225        case 0x10:
     226            cout << "CANbus bus-error" << endl;
     227            return;
     228        }
     229        return;
     230    case M_BCAN_RX_ind:
     231        //
     232        // Message is a message from the Can bus
     233        //
     234        //cout << "HandleCanMessage " << cobid << endl;
     235        HandleCanMessage(cobid, &msg.data[4], tv);
     236        return;
     237    }
     238
     239    //
     240    // Nothing of the above happened
     241    //
     242    cout << hex;
     243    cout << "Cmd=0x"    << (int)msg.cmd << ":  ";
     244    cout << "Descr: 0x" << cobid << dec;
     245    cout << "  Rtr: "   << (rtr?"Yes":"No");
     246    cout << "  Len: "   << (int)len << endl;
     247
     248    cout << "As Raw Data:" << hex << setfill('0');
     249    for (int i=0; i<msg.len; i++)
     250        cout << " " << setw(2) << (int)(msg.data[i]) << flush;
     251    cout << endl;
     252}
     253
     254bool CanOpen::WaitForSdos(WORDS_t ms)
     255{
     256    // 0: unlimited
     257    // <0: don't do a real wait.
     258    if (ms<0)
     259    {
     260        fSdoList.DelAll();
     261        return true;
     262    }
     263
     264    MTimeout t(ms);
     265    while (fSdoList.IsPending() &&
     266           !StopWaitingForSDO() &&
     267           !t.HasTimedOut())
     268        usleep(1);
     269
     270    bool rc = true;
     271    if (ms && t.HasTimedOut())
     272    {
     273        cout << "WaitForSdos timed out." << endl;
     274        rc = false;
     275    }
     276    /*
     277     if (StopWaitingForSDO())
     278     {
     279     cout << "WaitForSdos stopped." << endl;
     280     rc = false;
     281     }
     282     */
     283    if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
     284        fSdoList.DelAll();
     285
     286    return rc;
     287}
     288
     289bool CanOpen::WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms)
     290{
     291    // 0: unlimited
     292    // <0: don't do a real wait.
     293
     294    if (ms<0)
     295    {
     296        fSdoList.Del(node, idx, subidx);
     297        return true;
     298    }
     299
     300    MTimeout t(ms);
     301    while (fSdoList.IsPending(node, idx, subidx) &&
     302           !StopWaitingForSDO() &&
     303           !t.HasTimedOut())
     304        usleep(1);
     305
     306    bool rc = true;
     307    if (ms && t.HasTimedOut())
     308    {
     309        cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " timed out." << endl;
     310        rc = false;
     311    }
     312    /*
     313     if (StopWaitingForSDO())
     314     {
     315     cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " stopped." << endl;
     316     rc = false;
     317     }
     318     */
     319    if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
     320        fSdoList.Del(node, idx, subidx);
     321
     322    return rc;
     323}
     324
     325// --------------------------------------------------------------------------
     326//
    147327// Enables can messaged for a given node ID and function code.
    148328//
     
    152332        return;
    153333
    154     EnableCobId(CobId(node, fcode), flag);
     334    if (fInterface)
     335        fInterface->EnableCobId(CobId(node, fcode), flag);
    155336}
    156337
     
    260441//
    261442void CanOpen::SendPDO1(BYTE_t node,
    262               BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    263               BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
     443              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
     444              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
    264445{
    265446    BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
     
    272453//
    273454void CanOpen::SendPDO2(BYTE_t node,
    274               BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    275               BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
     455              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
     456              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
    276457{
    277458    BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
     
    284465//
    285466void CanOpen::SendPDO3(BYTE_t node,
    286               BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    287               BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
     467              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
     468              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
    288469{
    289470    BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
     
    296477//
    297478void CanOpen::SendPDO4(BYTE_t node,
    298               BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    299               BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
     479              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
     480              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
    300481{
    301482    BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
     
    394575// --------------------------------------------------------------------------
    395576//
     577// This is IcSendReqBCAN from the Janz software
     578//
     579//  /*
     580//   * IcSendReqBCAN - Send a CANbus message
     581//   *
     582//   * Issue request to send a CAN message. <Spec> controls whether to send with
     583//   * or without spec/confirmation.
     584//   * .CS
     585//   *    spec     action
     586//   *      0      send only
     587//   *      1      send with confirmation to the host.
     588//   *      2      send and echo message to the host.
     589//   *      3      send and generate both echo and confirmation.
     590//   * .CE
     591//   *
     592//   * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq
     593//   *
     594//   * NOTE:
     595//   * Raw ICANOS version of the firmware only.
     596//   */
     597//
     598void CanOpen::SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr)
     599{
     600    if (fInterface)
     601        fInterface->SendCanFrame(cobid, m, rtr);
     602}
     603
     604// --------------------------------------------------------------------------
     605//
     606// Sends a can frame with the given cobid and the given eight bytes
     607// through the can network
     608//
     609void CanOpen::SendCanFrame(WORD_t cobid,
     610                           BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
     611                           BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
     612{
     613    BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
     614    SendCanFrame(cobid, msg);
     615}
     616
     617// --------------------------------------------------------------------------
     618//
    396619// Decodes node and function code into a CobId
    397620//
  • trunk/MagicSoft/Cosy/candrv/canopen.h

    r8812 r8813  
    99#include "sdolist.h"
    1010#endif
    11 #ifndef COSY_VmodIcan
    12 #include "vmodican.h"
     11
     12#ifndef COSY_MTimeout
     13#include "MTimeout.h"
    1314#endif
    14 
    15 #include "MTimeout.h"
    1615
    1716#ifdef __CINT__
     
    6564#define kDontWait      (-1)
    6665
    67 class CanOpen : public VmodIcan
     66class Interface;
     67
     68typedef struct timeval timeval_t;
     69
     70class CanOpen
    6871{
    6972private:
    70     PendingSDOList fSdoList;
     73    Interface     *fInterface;      // Handle to the I/O interface
     74    PendingSDOList fSdoList;        // List for pending SDOs
     75    TCondition     fPdoCond[32][4]; // one for every PDO of every node
    7176
    72     TCondition fPdoCond[32][4]; // one for every PDO of every node
    73 //    pthread_cond_t  fPdoCond[32][4];
    74 //    pthread_mutex_t fPdoMux[32][4];
     77protected:
     78    virtual void Start();           // Start CanOpen communication
     79    virtual void Stop();            // Stop  CanOpen communcation
    7580
    76     void HandleCanMessage(WORD_t cobid, BYTE_t *data, timeval_t *tv);
     81private:
     82    //
     83    // Handle can objects arrived at the CanOpen interface
     84    //
     85    virtual void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)=0;
     86    virtual void HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
     87    virtual void HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
     88    virtual void HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
     89    virtual void HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
     90    virtual void HandleNodeguard(BYTE_t node, const timeval_t &tv)=0;
     91    virtual void HandleEmergency(BYTE_t node, const timeval_t &tv)=0;
    7792
    78     virtual void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)=0;
    79     virtual void HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
    80     virtual void HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
    81     virtual void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
    82     virtual void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
    83     virtual void HandleNodeguard(BYTE_t node, timeval_t *tv)=0;
    84     virtual void HandleEmergency(BYTE_t node, timeval_t *tv)=0;
     93    // Handle message arrived at the CanOpen interface and split into can objects
     94    virtual void HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv);
    8595
    8696public:
    87     CanOpen(const char *dev, const int baud, MLog &out=gLog);
     97    CanOpen();
    8898    virtual ~CanOpen();
    8999
     100    void SetInterface(Interface *f) { fInterface=f; } // Set Handle to the interface
     101
     102    // Send a Process Data Object (PDO) to the CanOpen bus
    90103    void SendPDO1(BYTE_t node, BYTE_t data[8]);
    91104    void SendPDO2(BYTE_t node, BYTE_t data[8]);
     
    105118                  BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
    106119
     120    // Send a Service Data Object (SDO) to a CanOpen device (aka. write parameter)
    107121    void SendSDO(BYTE_t node, WORD_t idx, BYTE_t subidx, BYTE_t val, bool store);
    108122    void SendSDO(BYTE_t node, WORD_t idx, BYTE_t subidx, WORD_t val, bool store);
     
    113127    void SendSDO(BYTE_t node, WORD_t idx, LWORD_t val, bool store)  { SendSDO(node, idx, 0, val, store); }
    114128
     129    // Send other objects
    115130    void SendNMT(BYTE_t node, BYTE_t cmd);
    116131    void SendNodeguard(BYTE_t node);
    117132
     133    // Request a Service Data Object (SDO) from a CanOpen device (aka. read parameter)
    118134    void RequestSDO(BYTE_t node, WORD_t idx, BYTE_t subidx=0);
    119135
    120     void EnableCanMsg(BYTE_t node, BYTE_t fcode, int flag=TRUE);
    121 
     136    // Enable interface for pass-through of a kind of can-object
    122137    void EnableSdoRx(BYTE_t node);
    123138    void EnablePdo1Rx(BYTE_t node);
     
    128143    void EnableNodeguard(BYTE_t node);
    129144
     145    // Enable interface for pass-through of a can-object
     146    void EnableCanMsg(BYTE_t node, BYTE_t fcode, int flag=TRUE);
     147
     148    // Wait until the next Pdo object has arrived
    130149    void WaitForNextPdo1(BYTE_t node) { node -= 1; fPdoCond[node][0].Wait(); }
    131150    void WaitForNextPdo2(BYTE_t node) { node -= 1; fPdoCond[node][1].Wait(); }
     
    133152    void WaitForNextPdo4(BYTE_t node) { node -= 1; fPdoCond[node][3].Wait(); }
    134153
    135     //
    136     // This function must
    137     //
     154    // Wait for arrival of a return to a given Sdo (or all axpected Sdos)
     155    bool WaitForSdos(WORDS_t ms=500);
     156    bool WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms=500);
     157
    138158    virtual int StopWaitingForSDO() const { return FALSE; }
    139159
    140     bool WaitForSdos(WORDS_t ms=500)
    141     {
    142         // 0: unlimited
    143         // <0: don't do a real wait.
    144         if (ms<0)
    145         {
    146             fSdoList.DelAll();
    147             return true;
    148         }
     160    // Low level function to send rawcan frames
     161    void SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr=0);
     162    void SendCanFrame(WORD_t cobid,
     163                      BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
     164                      BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
    149165
    150         MTimeout t(ms);
    151         while (fSdoList.IsPending() &&
    152                !StopWaitingForSDO() &&
    153                !t.HasTimedOut())
    154             usleep(1);
     166    // Extract the CanOpen message from the message delivered by the interface
     167    void HandleMessage(const Message &msg, const timeval_t &tv);
    155168
    156         bool rc = true;
    157         if (ms && t.HasTimedOut())
    158         {
    159             cout << "WaitForSdos timed out." << endl;
    160             rc = false;
    161         }
    162         /*
    163          if (StopWaitingForSDO())
    164         {
    165             cout << "WaitForSdos stopped." << endl;
    166             rc = false;
    167         }
    168         */
    169         if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
    170             fSdoList.DelAll();
    171 
    172         return rc;
    173     }
    174 
    175     bool WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms=500)
    176     {
    177         // 0: unlimited
    178         // <0: don't do a real wait.
    179 
    180         if (ms<0)
    181         {
    182             fSdoList.Del(node, idx, subidx);
    183             return true;
    184         }
    185 
    186         MTimeout t(ms);
    187         while (fSdoList.IsPending(node, idx, subidx) &&
    188                !StopWaitingForSDO() &&
    189                !t.HasTimedOut())
    190             usleep(1);
    191 
    192         bool rc = true;
    193         if (ms && t.HasTimedOut())
    194         {
    195             cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " timed out." << endl;
    196             rc = false;
    197         }
    198         /*
    199         if (StopWaitingForSDO())
    200         {
    201             cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " stopped." << endl;
    202             rc = false;
    203             }
    204             */
    205         if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
    206             fSdoList.Del(node, idx, subidx);
    207 
    208         return rc;
    209     }
    210 
    211 public:
     169    // Compile CobId from node and function code
    212170    WORD_t CobId(BYTE_t node, BYTE_t fcode) const;
    213171
  • trunk/MagicSoft/Cosy/candrv/network.cc

    r6923 r8813  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz <mailto:tbretz@uni-sw.gwdg.de>, 2001
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2001
     18!   Author(s): Thomas Bretz, 2001 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    3232#include "network.h"
    3333
    34 #include <iostream.h> // cout
    35 #include <iomanip.h>  // setw, setfill
     34#include <iostream> // cout
     35#include <iomanip>  // setw, setfill
    3636
    3737ClassImp(Network);
     38
     39using namespace std;
    3840
    3941// --------------------------------------------------------------------------
     
    4446void Network::Start()
    4547{
    46     lout << "- Starting network." << endl;
    47 
    48     VmodIcan::Start();
     48    gLog << "- Starting network." << endl;
     49
     50    CanOpen::Start();
    4951    InitNodes();
    5052
    51     lout << "- Network started." << endl;
     53    gLog << "- Network started." << endl;
    5254}
    5355
     
    5860void Network::Stop()
    5961{
    60     lout << "- Stopping network." << endl;
     62    gLog << "- Stopping network." << endl;
    6163
    6264    StopNodes();
    63     VmodIcan::Stop();
    64 
    65     lout << "- Network stopped." << endl;
     65    CanOpen::Stop();
     66
     67    gLog << "- Network stopped." << endl;
    6668}
    6769
     
    7072// Initialize the network, set all nodes to NULL (n/a)
    7173//
    72 Network::Network(const char *dev, const int baud, MLog &out) : CanOpen(dev, baud, out)
    73 {
    74     for (int i=0; i<32; i++)
    75         fNodes[i] = NULL;
    76 
    77     lout << "- Network initialized." << endl;
     74Network::Network() : CanOpen()
     75{
     76    memset(fNodes,           0, 32*sizeof(*fNodes));
     77    memset(fNodeInitialized, 0, 32*sizeof(*fNodeInitialized));
     78
     79    gLog << "- Network initialized." << endl;
    7880}
    7981
     
    8789//  HandleSDOError: Handles error occursion (see CanOpen standard)
    8890//
    89 void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)
     91void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)
    9092{
    9193    if (fNodes[node])
     
    123125// Distributes PDO1 messages to the correspoding node calling HandlePDO1
    124126//
    125 void Network::HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv)
     127void Network::HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
    126128{
    127129    if (!fNodes[node])
     
    141143// Distributes PDO2 messages to the correspoding node calling HandlePDO2
    142144//
    143 void Network::HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv)
     145void Network::HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
    144146{
    145147    if (!fNodes[node])
     
    159161// Distributes PDO3 messages to the correspoding node calling HandlePDO3
    160162//
    161 void Network::HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv)
     163void Network::HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
    162164{
    163165    if (!fNodes[node])
     
    177179// Distributes PDO4 messages to the correspoding node calling HandlePDO4
    178180//
    179 void Network::HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv)
     181void Network::HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
    180182{
    181183    if (!fNodes[node])
     
    196198// HandleNodeguard
    197199//
    198 void Network::HandleNodeguard(BYTE_t node, timeval_t *tv)
     200void Network::HandleNodeguard(BYTE_t node, const timeval_t &tv)
    199201{
    200202    if (!fNodes[node])
     
    212214// HandleEmergency
    213215//
    214 void Network::HandleEmergency(BYTE_t node, timeval_t *tv)
     216void Network::HandleEmergency(BYTE_t node, const timeval_t &tv)
    215217{
    216218    if (!fNodes[node])
     
    250252        if (fNodes[i])
    251253        {
    252             lout << "- Setting up Node #" << dec << i << " (";
    253             lout << fNodes[i]->GetNodeName() << ")" << endl;
     254            gLog << "- Setting up Node #" << dec << i << " (";
     255            gLog << fNodes[i]->GetNodeName() << ")" << endl;
    254256            if (fNodes[i]->InitDevice(this))
    255257                fNodeInitialized[i] = TRUE;
    256258            else
    257                 lout << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl;
     259                gLog << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl;
    258260        }
    259     lout << "- All Nodes setup." << endl;
     261    gLog << "- All Nodes setup." << endl;
    260262}
    261263
     
    269271        if (fNodes[i] && fNodeInitialized[i])
    270272        {
    271             lout << "- Stopping Node #" << dec << i;
    272             lout << " (" << fNodes[i]->GetNodeName() << ")" << endl;
     273            gLog << "- Stopping Node #" << dec << i;
     274            gLog << " (" << fNodes[i]->GetNodeName() << ")" << endl;
    273275            fNodes[i]->StopDevice();
    274276        }
    275     lout << "- All Nodes stopped." << endl;
     277    gLog << "- All Nodes stopped." << endl;
    276278}
    277279
     
    290292            continue;
    291293
    292         lout << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName() << "' ";
     294        gLog << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName() << "' ";
    293295
    294296        if (fNodes[i]->GetError() <= 0)
    295             lout << "Error occured." << endl;
     297            gLog << "Error occured." << endl;
    296298        else
    297             lout << "has error #" << fNodes[i]->GetError() << endl;
     299            gLog << "has error #" << fNodes[i]->GetError() << endl;
    298300    }
    299301}
     
    320322            continue;
    321323
    322         //lout << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();
    323         //lout << "' has error #" << fNodes[i]->GetError() << endl;
     324        //gLog << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();
     325        //gLog << "' has error #" << fNodes[i]->GetError() << endl;
    324326    }
    325327
     
    350352    bool rc = true;
    351353
    352     lout << "- Trying to reboot all Zombies..." << endl;
     354    gLog << "- Trying to reboot all Zombies..." << endl;
    353355    for (int i=0; i<32; i++)
    354356        if (fNodes[i])
     
    356358                if (!fNodes[i]->Reboot())
    357359                {
    358                     lout << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl;
     360                    gLog << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl;
    359361                    rc = false;
    360362                }
    361363
    362364    if (rc)
    363         lout << "- All Zombies rebooted." << endl;
     365        gLog << "- All Zombies rebooted." << endl;
    364366
    365367    return rc;
  • trunk/MagicSoft/Cosy/candrv/network.h

    r6923 r8813  
    1515    int fNodeInitialized[32];
    1616
    17     void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval *tv);
    18     void HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv);
    19     void HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv);
    20     void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv);
    21     void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv);
    22     void HandleNodeguard(BYTE_t node, timeval_t *tv);
    23     void HandleEmergency(BYTE_t node, timeval_t *tv);
     17    void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval &tv);
     18    void HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
     19    void HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
     20    void HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
     21    void HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
     22    void HandleNodeguard(BYTE_t node, const timeval_t &tv);
     23    void HandleEmergency(BYTE_t node, const timeval_t &tv);
    2424
    2525    void InitNodes();
     
    2727
    2828public:
    29     Network(const char *dev, const int baud, MLog &out=gLog);
     29    Network();
    3030
    3131    void SetNode(NodeDrv *drv);
     
    3434    NodeDrv *GetNode(int i)    { return fNodes[i]; }
    3535
    36     virtual void Start();
    37     virtual void Stop();
     36    void Start();
     37    void Stop();
    3838
    3939    void PrintError() const;
  • trunk/MagicSoft/Cosy/candrv/nodedrv.cc

    r8376 r8813  
    5454#include "MLogManip.h"
    5555
     56#include "MThread.h"
     57
    5658ClassImp(NodeDrv);
    5759
     
    145147// it in the 'non-standard' CANOpen communication with the MACS)
    146148//
    147 void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)
     149void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)
    148150{
    149151    const Bool_t gui = lout.IsOutputDeviceEnabled(MLog::eGui);
     
    175177// Prints the received SDo from this device
    176178//
    177 void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)
     179void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv)
    178180{
    179181    cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx;
     
    496498        : MThread(false), fGuardTime(guard/1000.), fLifeTimeFactor(ltf), fIsCanOpen(canopen), fDrv(drv) { }
    497499
    498     void Reset(timeval_t *tv=NULL)
     500    void Reset(const timeval_t *tv=NULL)
    499501    {
    500502        MTime t;
     
    587589// guard time times lifetimefactor.
    588590//
    589 void NodeDrv::HandleNodeguard(timeval_t *tv)
     591void NodeDrv::HandleNodeguard(const timeval_t &tv)
    590592{
    591593    if (fGuard)
    592         fGuard->Reset(tv);
     594        fGuard->Reset(&tv);
    593595}
    594596
  • trunk/MagicSoft/Cosy/candrv/nodedrv.h

    r6923 r8813  
    6969    void SetZombie(bool stopguard=true);
    7070
    71     virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
    72     virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv);
     71    virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv);
     72    virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv);
    7373    virtual void HandleSDOError(LWORD_t data);
    7474
    75     virtual void HandlePDO1(BYTE_t *data, timeval_t *tv) {}
    76     virtual void HandlePDO2(BYTE_t *data, timeval_t *tv) {}
    77     virtual void HandlePDO3(BYTE_t *data, timeval_t *tv) {}
    78     virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {}
    79     virtual void HandleNodeguard(timeval_t *tv);
    80     virtual void HandleEmergency(timeval_t *tv) {}
     75    virtual void HandlePDO1(const BYTE_t *data, const timeval_t &tv) {}
     76    virtual void HandlePDO2(const BYTE_t *data, const timeval_t &tv) {}
     77    virtual void HandlePDO3(const BYTE_t *data, const timeval_t &tv) {}
     78    virtual void HandlePDO4(const BYTE_t *data, const timeval_t &tv) {}
     79    virtual void HandleNodeguard(const timeval_t &tv);
     80    virtual void HandleEmergency(const timeval_t &tv) {}
    8181
    8282    bool SendPDO1(BYTE_t data[8]);
Note: See TracChangeset for help on using the changeset viewer.