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

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