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

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