source: trunk/MagicSoft/Cosy/candrv/nodedrv.cc@ 1139

Last change on this file since 1139 was 1139, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 10.3 KB
Line 
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, 2001 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////
26//
27// NodeDrv
28//
29// Base class for a class describing the interface for the CAN nodes.
30//
31// to be overloaded:
32// virtual void InitDevice(Network *net)
33// virtual void StopDevice()
34// virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv)
35// virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx)
36// virtual void HandleSDOError(LWORD_t data)
37// virtual void HandlePDO1(BYTE_t *data, struct timeval *tv)
38// virtual void HandlePDO2(BYTE_t *data, struct timeval *tv)
39// virtual void HandlePDO3(BYTE_t *data, struct timeval *tv)
40// virtual void HandlePDO4(BYTE_t *data, struct timeval *tv)
41//
42///////////////////////////////////////////////////////////////////////
43#include "nodedrv.h"
44
45#include <iomanip.h>
46#include <iostream.h>
47
48#include "network.h"
49#include "MLogManip.h"
50
51ClassImp(NodeDrv);
52
53// --------------------------------------------------------------------------
54//
55// Constructor for one node. Sets the Node Id (<32) the logging stream
56// and the node name. The name is a name for debug output.
57//
58NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0)
59{
60 if (nodeid>0x1f)
61 {
62 cout << "SetNode - Error: Only node Numbers < 32 are allowed"<< endl;
63 return;
64 }
65
66 fId = nodeid;
67
68 if (name)
69 fName = name;
70 else
71 {
72 fName = "Node#";
73 fName += (int)nodeid;
74 }
75}
76
77// --------------------------------------------------------------------------
78//
79// Empty destructor
80//
81NodeDrv::~NodeDrv()
82{
83}
84
85// --------------------------------------------------------------------------
86//
87// Init device, sets the pointer to the whole network and enables
88// the Can messages to be passed through the interface:
89// PDO1 tx
90// PDO2 tx
91// PDO3 tx
92// PDO4 tx
93// SDO rx
94// SDO tx
95//
96void NodeDrv::InitDevice(Network *net)
97{
98 fNetwork = net;
99
100 EnableCanMsg(kPDO1_TX);
101 EnableCanMsg(kPDO2_TX);
102 EnableCanMsg(kPDO3_TX);
103 EnableCanMsg(kPDO4_TX);
104 EnableCanMsg(kSDO_RX);
105 EnableCanMsg(kSDO_TX);
106}
107
108// --------------------------------------------------------------------------
109//
110// Print an "SDO idx/subidx set." from this device message.
111// This output is never redirected to the GUI
112//
113void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx)
114{
115 const Bool_t gui = lout.IsOutputDeviceEnabled(MLog::eGui);
116
117 if (gui)
118 lout << ddev(MLog::eGui);
119
120 lout << hex << setfill('0');
121 lout << "Sdo=" << idx << "/" << (int)subidx << " set.";
122 lout << endl;
123
124 if (gui)
125 lout << edev(MLog::eGui);
126}
127
128// --------------------------------------------------------------------------
129//
130// Print an error message with the corresponding data from this device.
131//
132void NodeDrv::HandleSDOError(LWORD_t data)
133{
134 lout << "Nodedrv: SDO Error: Entry not found in dictionary (data=0x";
135 lout << hex << setfill('0') << setw(4) << data << ")";
136 lout << endl;
137}
138
139// --------------------------------------------------------------------------
140//
141// Prints the received SDo from this device
142//
143void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv)
144{
145 cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx;
146 cout << ", val=0x" << val << endl;
147}
148
149// --------------------------------------------------------------------------
150//
151// Sends the given PDO1 through the network to this device
152// A PDO is carrying up to eight bytes of information.
153//
154void NodeDrv::SendPDO1(BYTE_t data[8])
155{
156 fNetwork->SendPDO1(fId, data);
157}
158
159// --------------------------------------------------------------------------
160//
161// Sends the given PDO2 through the network to this device
162// A PDO is carrying up to eight bytes of information.
163//
164void NodeDrv::SendPDO2(BYTE_t data[8])
165{
166 fNetwork->SendPDO2(fId, data);
167}
168
169// --------------------------------------------------------------------------
170//
171// Sends the given PDO1 through the network to this device
172// A PDO is carrying up to eight bytes of information.
173//
174void NodeDrv::SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
175 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
176{
177 fNetwork->SendPDO1(fId, m0, m1, m2, m3, m4, m5, m6, m7);
178}
179
180// --------------------------------------------------------------------------
181//
182// Sends the given PDO2 through the network to this device
183// A PDO is carrying up to eight bytes of information.
184//
185void NodeDrv::SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
186 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
187{
188 fNetwork->SendPDO2(fId, m0, m1, m2, m3, m4, m5, m6, m7);
189}
190
191// --------------------------------------------------------------------------
192//
193// Sends the given SDO through the network to this device
194// An SDO message contains
195// an address (this device)
196// an index of the dictionary entry to address
197// a subindex of this dictionary entry to access
198// and a value to set for this dictionary entry
199//
200void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store)
201{
202 fNetwork->SendSDO(fId, idx, subidx, val, store);
203}
204
205// --------------------------------------------------------------------------
206//
207// Sends the given SDO through the network to this device
208// An SDO message contains
209// an address (this device)
210// an index of the dictionary entry to address
211// a subindex of this dictionary entry to access
212// and a value to set for this dictionary entry
213//
214void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store)
215{
216 fNetwork->SendSDO(fId, idx, subidx, val, store);
217}
218
219// --------------------------------------------------------------------------
220//
221// Sends the given SDO through the network to this device
222// An SDO message contains
223// an address (this device)
224// an index of the dictionary entry to address
225// a subindex of this dictionary entry to access
226// and a value to set for this dictionary entry
227//
228void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store)
229{
230 fNetwork->SendSDO(fId, idx, subidx, val, store);
231}
232
233// --------------------------------------------------------------------------
234//
235// Sends the given SDO through the network to this device
236// An SDO message contains
237// an address (this device)
238// an index of the dictionary entry to address
239// a subindex of this dictionary entry to access
240// and a value to set for this dictionary entry
241//
242void NodeDrv::SendSDO(WORD_t idx, BYTE_t val)
243{
244 fNetwork->SendSDO(fId, idx, val, true);
245}
246
247// --------------------------------------------------------------------------
248//
249// Sends the given SDO through the network to this device
250// An SDO message contains
251// an address (this device)
252// an index of the dictionary entry to address
253// a subindex of this dictionary entry to access
254// and a value to set for this dictionary entry
255//
256void NodeDrv::SendSDO(WORD_t idx, WORD_t val)
257{
258 fNetwork->SendSDO(fId, idx, val, true);
259}
260
261// --------------------------------------------------------------------------
262//
263// Sends the given SDO through the network to this device
264// An SDO message contains
265// an address (this device)
266// an index of the dictionary entry to address
267// a subindex of this dictionary entry to access
268// and a value to set for this dictionary entry
269//
270void NodeDrv::SendSDO(WORD_t idx, LWORD_t val)
271{
272 fNetwork->SendSDO(fId, idx, val, true);
273}
274
275// --------------------------------------------------------------------------
276//
277// Request a SDO for a given idx/subidx
278// An SDO message contains
279// an address (this device)
280// an index of the dictionary entry to read
281// a subindex of this dictionary entry to access
282//
283void NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx)
284{
285 fNetwork->RequestSDO(fId, idx, subidx);
286}
287
288// --------------------------------------------------------------------------
289//
290// Send an NMT message (command) to this device
291//
292void NodeDrv::SendNMT(BYTE_t cmd)
293{
294 fNetwork->SendNMT(fId, cmd);
295}
296
297// --------------------------------------------------------------------------
298//
299// Enable passthrough for the given functioncode of this device
300//
301void NodeDrv::EnableCanMsg(BYTE_t fcode)
302{
303 fNetwork->EnableCanMsg(fId, fcode, TRUE);
304}
305
306// --------------------------------------------------------------------------
307//
308// Wait a given timeout until the SDO with the given idx/subidx from
309// this device has been received.
310// You can stop waiting by StopWaitingForSDO.
311//
312void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout)
313{
314 fNetwork->WaitForSdo(fId, idx, subidx, timeout);
315}
316
317/*
318void NodeDrv::WaitForSdos()
319{
320 while (fNetwork->WaitingForSdo(fId))
321 usleep(1);
322}
323*/
324
325// --------------------------------------------------------------------------
326//
327// Waits until the next Pdo1 from this device has been received
328//
329void NodeDrv::WaitForNextPdo1()
330{
331 fNetwork->WaitForNextPdo1(fId);
332}
333
334// --------------------------------------------------------------------------
335//
336// Waits until the next Pdo2 from this device has been received
337//
338void NodeDrv::WaitForNextPdo2()
339{
340 fNetwork->WaitForNextPdo2(fId);
341}
342
343// --------------------------------------------------------------------------
344//
345// Waits until the next Pdo3 from this device has been received
346//
347void NodeDrv::WaitForNextPdo3()
348{
349 fNetwork->WaitForNextPdo3(fId);
350}
351
352// --------------------------------------------------------------------------
353//
354// Waits until the next Pdo4 from this device has been received
355//
356void NodeDrv::WaitForNextPdo4()
357{
358 fNetwork->WaitForNextPdo4(fId);
359}
360
Note: See TracBrowser for help on using the repository browser.