author | Edouard Tisserant |
Thu, 24 Jan 2019 13:53:01 +0100 | |
changeset 808 | de1fc3261f21 |
parent 631 | 08b6b903f84a |
permissions | -rw-r--r-- |
0 | 1 |
/* |
208 | 2 |
This file is part of CanFestival, a library implementing CanOpen |
3 |
Stack. |
|
0 | 4 |
|
208 | 5 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
0 | 6 |
|
208 | 7 |
See COPYING file for copyrights details. |
0 | 8 |
|
208 | 9 |
This library is free software; you can redistribute it and/or |
10 |
modify it under the terms of the GNU Lesser General Public |
|
11 |
License as published by the Free Software Foundation; either |
|
12 |
version 2.1 of the License, or (at your option) any later version. |
|
0 | 13 |
|
208 | 14 |
This library is distributed in the hope that it will be useful, |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
Lesser General Public License for more details. |
|
0 | 18 |
|
208 | 19 |
You should have received a copy of the GNU Lesser General Public |
20 |
License along with this library; if not, write to the Free Software |
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
22 |
USA |
|
0 | 23 |
*/ |
208 | 24 |
/*! |
25 |
** @file nmtMaster.c |
|
26 |
** @author Edouard TISSERANT and Francis DUPIN |
|
27 |
** @date Tue Jun 5 08:47:18 2007 |
|
28 |
** |
|
29 |
** @brief |
|
30 |
** |
|
31 |
** |
|
32 |
*/ |
|
0 | 33 |
#include "nmtMaster.h" |
149 | 34 |
#include "canfestival.h" |
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
35 |
#include "sysdep.h" |
0 | 36 |
|
208 | 37 |
/*! |
38 |
** |
|
39 |
** |
|
40 |
** @param d |
|
41 |
** @param Node_ID |
|
42 |
** @param cs |
|
43 |
** |
|
44 |
** @return |
|
45 |
**/ |
|
0 | 46 |
UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs) |
47 |
{ |
|
48 |
Message m; |
|
49 |
||
50 |
MSG_WAR(0x3501, "Send_NMT cs : ", cs); |
|
51 |
MSG_WAR(0x3502, " to node : ", Node_ID); |
|
215 | 52 |
/* message configuration */ |
365 | 53 |
m.cob_id = 0x0000; /*(NMT) << 7*/ |
0 | 54 |
m.rtr = NOT_A_REQUEST; |
55 |
m.len = 2; |
|
56 |
m.data[0] = cs; |
|
57 |
m.data[1] = Node_ID; |
|
208 | 58 |
|
149 | 59 |
return canSend(d->canHandle,&m); |
0 | 60 |
} |
61 |
||
62 |
||
208 | 63 |
/*! |
64 |
** |
|
65 |
** |
|
66 |
** @param d |
|
67 |
** @param nodeId |
|
68 |
** |
|
69 |
** @return |
|
70 |
**/ |
|
0 | 71 |
UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId) |
72 |
{ |
|
73 |
Message m; |
|
208 | 74 |
|
0 | 75 |
/* message configuration */ |
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
76 |
UNS16 tmp = nodeId | (NODE_GUARD << 7); |
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
77 |
m.cob_id = UNS16_LE(tmp); |
0 | 78 |
m.rtr = REQUEST; |
597
ea32aa303987
Fixed wrong cast in sdo.c and wrong message length in nodeguarding
edouard
parents:
370
diff
changeset
|
79 |
m.len = 0; |
208 | 80 |
|
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
81 |
MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId); |
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
82 |
|
149 | 83 |
return canSend(d->canHandle,&m); |
0 | 84 |
} |
85 |
||
208 | 86 |
/*! |
87 |
** |
|
88 |
** |
|
89 |
** @param d |
|
90 |
** @param nodeId |
|
631 | 91 |
** |
92 |
** @return |
|
208 | 93 |
**/ |
631 | 94 |
UNS8 masterRequestNodeState(CO_Data* d, UNS8 nodeId) |
0 | 95 |
{ |
215 | 96 |
/* FIXME: should warn for bad toggle bit. */ |
0 | 97 |
|
215 | 98 |
/* NMTable configuration to indicate that the master is waiting |
208 | 99 |
for a Node_Guard frame from the slave whose node_id is ID |
100 |
*/ |
|
215 | 101 |
d->NMTable[nodeId] = Unknown_state; /* A state that does not exist |
208 | 102 |
*/ |
0 | 103 |
|
215 | 104 |
if (nodeId == 0) { /* NMT broadcast */ |
0 | 105 |
UNS8 i = 0; |
106 |
for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) { |
|
107 |
d->NMTable[i] = Unknown_state; |
|
108 |
} |
|
109 |
} |
|
631 | 110 |
return masterSendNMTnodeguard(d,nodeId); |
0 | 111 |
} |
112 |