@@ -98,25 +98,28 @@ UavcanNode::~UavcanNode()
98
98
_task_should_exit.store (true );
99
99
ScheduleNow ();
100
100
101
- unsigned i = 10 ;
101
+ unsigned i = 1000 ;
102
102
103
103
do {
104
- /* wait 5ms - it should wake every 10ms or so worst-case */
104
+ /* Wait for it to exit or timeout */
105
105
usleep (5000 );
106
106
107
107
if (--i == 0 ) {
108
+ PX4_ERR (" Failed to Stop Task - reboot needed" );
108
109
break ;
109
110
}
110
111
111
112
} while (_instance);
112
113
}
113
114
114
115
delete _can_interface;
116
+ _can_interface = nullptr ;
115
117
116
118
perf_free (_cycle_perf);
117
119
perf_free (_interval_perf);
118
120
119
- // delete _uavcan_heap;
121
+ delete static_cast <uint8_t *>(_uavcan_heap);
122
+ _uavcan_heap = nullptr ;
120
123
}
121
124
122
125
int UavcanNode::start (uint32_t node_id, uint32_t bitrate)
@@ -163,7 +166,7 @@ void UavcanNode::Run()
163
166
{
164
167
pthread_mutex_lock (&_node_mutex);
165
168
166
- if (!_initialized) {
169
+ if (_instance != nullptr && !_initialized) {
167
170
init ();
168
171
169
172
// return early if still not initialized
@@ -216,7 +219,7 @@ void UavcanNode::Run()
216
219
CanardFrame received_frame{};
217
220
received_frame.payload = &data;
218
221
219
- while (_can_interface->receive (&received_frame) > 0 ) {
222
+ while (!_task_should_exit. load () && _can_interface->receive (&received_frame) > 0 ) {
220
223
CanardTransfer receive{};
221
224
CanardRxSubscription *subscription = NULL ;
222
225
int32_t result = canardRxAccept2 (&_canard_instance, &received_frame, 0 , &receive, &subscription);
@@ -253,10 +256,14 @@ void UavcanNode::Run()
253
256
254
257
perf_end (_cycle_perf);
255
258
256
- if (_task_should_exit.load ()) {
257
- _can_interface->close ();
258
-
259
+ if (_instance && _task_should_exit.load ()) {
259
260
ScheduleClear ();
261
+
262
+ if (_initialized && _can_interface != nullptr ) {
263
+ _can_interface->close ();
264
+ _initialized = false ;
265
+ }
266
+
260
267
_instance = nullptr ;
261
268
}
262
269
0 commit comments