162 ** |
155 ** |
163 ** @return |
156 ** @return |
164 **/ |
157 **/ |
165 UNS8 setState(CO_Data* d, e_nodeState newState) |
158 UNS8 setState(CO_Data* d, e_nodeState newState) |
166 { |
159 { |
167 while(newState != d->nodeState){ |
160 if(newState != d->nodeState){ |
168 switch( newState ){ |
161 switch( newState ){ |
169 case Initialisation: |
162 case Initialisation: |
170 { |
163 { |
171 s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0, 0}; |
164 s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0, 0}; |
172 /* This will force a second loop for the state switch */ |
|
173 d->nodeState = Initialisation; |
165 d->nodeState = Initialisation; |
174 newState = Pre_operational; |
166 switchCommunicationState(d, &newCommunicationState); |
175 switchCommunicationState(d, &newCommunicationState); |
167 /* call user app init callback now. */ |
176 /* call user app related state func. */ |
168 /* d->initialisation MUST NOT CALL SetState */ |
177 (*d->initialisation)(); |
169 (*d->initialisation)(d); |
178 |
170 } |
179 } |
171 |
180 break; |
172 /* Automatic transition - No break statement ! */ |
|
173 /* Transition from Initialisation to Pre_operational */ |
|
174 /* is automatic as defined in DS301. */ |
|
175 /* App don't have to call SetState(d, Pre_operational) */ |
181 |
176 |
182 case Pre_operational: |
177 case Pre_operational: |
183 { |
178 { |
184 |
179 |
185 s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0, 1}; |
180 s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0, 1}; |
186 d->nodeState = Pre_operational; |
181 d->nodeState = Pre_operational; |
187 newState = Pre_operational; |
|
188 switchCommunicationState(d, &newCommunicationState); |
182 switchCommunicationState(d, &newCommunicationState); |
189 if (!(*(d->iam_a_slave))) |
183 if (!(*(d->iam_a_slave))) |
190 { |
184 { |
191 //send_consise_dcf(d,0x01); |
|
192 masterSendNMTstateChange (d, 0, NMT_Reset_Node); |
185 masterSendNMTstateChange (d, 0, NMT_Reset_Node); |
193 (*d->preOperational)(); |
|
194 } |
186 } |
195 else |
187 (*d->preOperational)(d); |
196 { |
|
197 (*d->preOperational)(); |
|
198 } |
|
199 } |
188 } |
200 break; |
189 break; |
201 |
190 |
202 case Operational: |
191 case Operational: |
203 if(d->nodeState == Initialisation) return 0xFF; |
192 if(d->nodeState == Initialisation) return 0xFF; |
204 { |
193 { |
205 s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1, 0}; |
194 s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1, 0}; |
206 d->nodeState = Operational; |
195 d->nodeState = Operational; |
207 newState = Operational; |
196 newState = Operational; |
208 switchCommunicationState(d, &newCommunicationState); |
197 switchCommunicationState(d, &newCommunicationState); |
209 (*d->operational)(); |
198 (*d->operational)(d); |
210 } |
199 } |
211 break; |
200 break; |
212 |
201 |
213 case Stopped: |
202 case Stopped: |
214 if(d->nodeState == Initialisation) return 0xFF; |
203 if(d->nodeState == Initialisation) return 0xFF; |
215 { |
204 { |
216 s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0, 1}; |
205 s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0, 1}; |
217 d->nodeState = Stopped; |
206 d->nodeState = Stopped; |
218 newState = Stopped; |
207 newState = Stopped; |
219 switchCommunicationState(d, &newCommunicationState); |
208 switchCommunicationState(d, &newCommunicationState); |
220 (*d->stopped)(); |
209 (*d->stopped)(d); |
221 } |
210 } |
222 break; |
211 break; |
223 #ifdef CO_ENABLE_LSS |
212 #ifdef CO_ENABLE_LSS |
224 case LssTimingDelay: |
213 case LssTimingDelay: |
225 { |
214 { |