| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of Stesy, the MAGIC Steering System
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz 1/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2008
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | ///////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // Interface
|
|---|
| 28 | //
|
|---|
| 29 | // Class describing the interface to the Janz card in RawCan mode.
|
|---|
| 30 | //
|
|---|
| 31 | ///////////////////////////////////////////////////////////////////////
|
|---|
| 32 | #include "interface.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <sys/time.h> // gettimeofday
|
|---|
| 35 |
|
|---|
| 36 | #include "MLog.h"
|
|---|
| 37 | #include "MLogManip.h"
|
|---|
| 38 |
|
|---|
| 39 | #include "canopen.h"
|
|---|
| 40 |
|
|---|
| 41 | //ClassImp(Interface);
|
|---|
| 42 |
|
|---|
| 43 | using namespace std;
|
|---|
| 44 |
|
|---|
| 45 | Interface::Interface(CanOpen *rx) : fReceiver(rx)
|
|---|
| 46 | {
|
|---|
| 47 | fReceiver->SetInterface(this);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | Interface::~Interface()
|
|---|
| 51 | {
|
|---|
| 52 | gLog << inf2 << " - Interface::~Interface()" << endl;
|
|---|
| 53 | fReceiver->SetInterface(NULL);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | void Interface::HandleMessage(const Message &msg) const
|
|---|
| 57 | {
|
|---|
| 58 | if (!fReceiver)
|
|---|
| 59 | return;
|
|---|
| 60 |
|
|---|
| 61 | //
|
|---|
| 62 | // read the time for the message as soon as possible
|
|---|
| 63 | //
|
|---|
| 64 | timeval_t tv;
|
|---|
| 65 | gettimeofday(&tv, NULL);
|
|---|
| 66 |
|
|---|
| 67 | fReceiver->HandleMessage(msg, tv);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | // --------------------------------------------------------------------------
|
|---|
| 71 | //
|
|---|
| 72 | // Prints a CAN Message.
|
|---|
| 73 | //
|
|---|
| 74 | void Interface::PrintMsg(const Message &m)
|
|---|
| 75 | {
|
|---|
| 76 | cout << "Cmd=0x" << hex << (int)m.cmd << dec << " " << flush;
|
|---|
| 77 | cout << "len=" << (int)m.len << ":" << flush;
|
|---|
| 78 |
|
|---|
| 79 | cout << hex << flush;
|
|---|
| 80 | for (int i=0; i<m.len; i++)
|
|---|
| 81 | cout << " " << (int)m.data[i] << flush;
|
|---|
| 82 | cout << dec << endl;
|
|---|
| 83 | }
|
|---|