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

Last change on this file since 926 was 926, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 3.6 KB
Line 
1#include "nodedrv.h"
2
3#include <iomanip.h>
4#include <iostream.h>
5
6#include "network.h"
7#include "MLogManip.h"
8
9NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0)
10{
11 if (nodeid>31)
12 {
13 cout << "SetNode - Error: Only node Numbers < 32 are allowed"<< endl;
14 return;
15 }
16
17 fId = nodeid;
18
19 if (name)
20 {
21 fName = new char[strlen(name)+1];
22 strcpy(fName, name);
23 }
24 else
25 {
26 fName = new char[9];
27 sprintf(fName, "Node#%d", nodeid);
28 }
29}
30
31NodeDrv::~NodeDrv()
32{
33 delete fName;
34}
35
36void NodeDrv::InitDevice(Network *net)
37{
38 fNetwork = net;
39
40 EnableCanMsg(kPDO1_TX);
41 EnableCanMsg(kPDO2_TX);
42 EnableCanMsg(kPDO3_TX);
43 EnableCanMsg(kPDO4_TX);
44 EnableCanMsg(kSDO_RX);
45 EnableCanMsg(kSDO_TX);
46}
47
48void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx)
49{
50 const Bool_t gui = lout.IsOutputDeviceEnabled(MLog::eGui);
51
52 if (gui)
53 lout << ddev(MLog::eGui);
54
55 lout << hex << setfill('0');
56 lout << "Sdo=" << idx << "/" << (int)subidx << " set.";
57 lout << endl;
58
59 if (gui)
60 lout << edev(MLog::eGui);
61}
62
63void NodeDrv::HandleSDOError(LWORD_t data)
64{
65 lout << "Nodedrv: SDO Error: Entry not found in deictionary (data=0x";
66 lout << hex << setfill('0') << setw(4) << data << ")";
67 lout << endl;
68}
69
70void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv)
71{
72 cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx;
73 cout << ", val=0x" << val << endl;
74}
75
76void NodeDrv::SendPDO1(BYTE_t data[8])
77{
78 fNetwork->SendPDO1(fId, data);
79}
80
81void NodeDrv::SendPDO2(BYTE_t data[8])
82{
83 fNetwork->SendPDO2(fId, data);
84}
85
86void NodeDrv::SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
87 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
88{
89 fNetwork->SendPDO1(fId, m0, m1, m2, m3, m4, m5, m6, m7);
90}
91
92void NodeDrv::SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
93 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
94{
95 fNetwork->SendPDO2(fId, m0, m1, m2, m3, m4, m5, m6, m7);
96}
97
98void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store)
99{
100 fNetwork->SendSDO(fId, idx, subidx, val, store);
101}
102
103void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store)
104{
105 fNetwork->SendSDO(fId, idx, subidx, val, store);
106}
107
108void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store)
109{
110 fNetwork->SendSDO(fId, idx, subidx, val, store);
111}
112
113void NodeDrv::SendSDO(WORD_t idx, BYTE_t val)
114{
115 fNetwork->SendSDO(fId, idx, val, true);
116}
117
118void NodeDrv::SendSDO(WORD_t idx, WORD_t val)
119{
120 fNetwork->SendSDO(fId, idx, val, true);
121}
122
123void NodeDrv::SendSDO(WORD_t idx, LWORD_t val)
124{
125 fNetwork->SendSDO(fId, idx, val, true);
126}
127
128void NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx)
129{
130 fNetwork->RequestSDO(fId, idx, subidx);
131}
132
133void NodeDrv::SendNMT(BYTE_t cmd)
134{
135 fNetwork->SendNMT(fId, cmd);
136}
137
138void NodeDrv::EnableCanMsg(BYTE_t fcode)
139{
140 fNetwork->EnableCanMsg(fId, fcode, TRUE);
141}
142
143void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout)
144{
145 fNetwork->WaitForSdo(fId, idx, subidx, timeout);
146}
147
148/*
149void NodeDrv::WaitForSdos()
150{
151 while (fNetwork->WaitingForSdo(fId))
152 usleep(1);
153}
154*/
155
156void NodeDrv::WaitForNextPdo1()
157{
158 fNetwork->WaitForNextPdo1(fId);
159}
160
161void NodeDrv::WaitForNextPdo2()
162{
163 cout << "WAIT: " << (int)fId << " " << fNetwork << endl;
164 fNetwork->WaitForNextPdo2(fId);
165}
166
167void NodeDrv::WaitForNextPdo3()
168{
169 fNetwork->WaitForNextPdo3(fId);
170}
171
172void NodeDrv::WaitForNextPdo4()
173{
174 fNetwork->WaitForNextPdo4(fId);
175}
176
Note: See TracBrowser for help on using the repository browser.