@@ -287,7 +287,7 @@ bool SLCAN::CANIface::init_passthrough(uint8_t i)
287
287
*/
288
288
int16_t SLCAN::CANIface::reportFrame (const AP_HAL::CANFrame& frame, uint64_t timestamp_usec)
289
289
{
290
- if (_port == nullptr ) {
290
+ if (! is_enabled () ) {
291
291
return -1 ;
292
292
}
293
293
#if HAL_CANFD_SUPPORTED
@@ -377,7 +377,7 @@ int16_t SLCAN::CANIface::reportFrame(const AP_HAL::CANFrame& frame, uint64_t tim
377
377
const char * SLCAN::CANIface::processCommand (char * cmd)
378
378
{
379
379
380
- if (_port == nullptr ) {
380
+ if (! is_enabled () ) {
381
381
return nullptr ;
382
382
}
383
383
@@ -461,7 +461,7 @@ const char* SLCAN::CANIface::processCommand(char* cmd)
461
461
// add bytes to parse the received SLCAN Data stream
462
462
inline void SLCAN::CANIface::addByte (const uint8_t byte)
463
463
{
464
- if (_port == nullptr ) {
464
+ if (! is_enabled () ) {
465
465
return ;
466
466
}
467
467
if ((byte >= 32 && byte <= 126 )) { // Normal printable ASCII character
@@ -497,18 +497,20 @@ void SLCAN::CANIface::update_slcan_port()
497
497
{
498
498
const bool armed = hal.util ->get_soft_armed ();
499
499
if (_set_by_sermgr) {
500
- if (armed && _port != nullptr ) {
500
+ if (armed && is_enabled () ) {
501
501
// auto-disable when armed
502
502
_port->lock_port (0 , 0 );
503
- _port = nullptr ;
503
+ _enabled = false ;
504
504
_set_by_sermgr = false ;
505
505
}
506
506
return ;
507
507
}
508
- if (_port == nullptr && !armed) {
509
- _port = AP::serialmanager ().find_serial (AP_SerialManager::SerialProtocol_SLCAN, 0 );
510
- if (_port != nullptr ) {
508
+ if (!is_enabled () && !armed) {
509
+ auto new_port = AP::serialmanager ().find_serial (AP_SerialManager::SerialProtocol_SLCAN, 0 );
510
+ if (new_port != nullptr ) {
511
+ _port = new_port;
511
512
_port->lock_port (_serial_lock_key, _serial_lock_key);
513
+ _enabled = true ;
512
514
_set_by_sermgr = true ;
513
515
return ;
514
516
}
@@ -521,23 +523,25 @@ void SLCAN::CANIface::update_slcan_port()
521
523
if (((AP_HAL::millis () - _slcan_start_req_time) < ((uint32_t )_slcan_start_delay*1000 ))) {
522
524
return ;
523
525
}
524
- _port = AP::serialmanager ().get_serial_by_id (_slcan_ser_port);
525
- if (_port == nullptr ) {
526
+ auto new_port = AP::serialmanager ().get_serial_by_id (_slcan_ser_port);
527
+ if (new_port == nullptr ) {
526
528
_slcan_ser_port.set_and_save (-1 );
527
529
return ;
528
530
}
531
+ _port = new_port;
529
532
_port->lock_port (_serial_lock_key, _serial_lock_key);
533
+ _enabled = true ;
530
534
_prev_ser_port = _slcan_ser_port;
531
535
GCS_SEND_TEXT (MAV_SEVERITY_INFO, " CANManager: Starting SLCAN Passthrough on Serial %d with CAN%d" , _slcan_ser_port.get (), _iface_num);
532
536
_last_had_activity = AP_HAL::millis ();
533
537
}
534
- if (_port == nullptr ) {
538
+ if (! is_enabled () ) {
535
539
return ;
536
540
}
537
541
if (((AP_HAL::millis () - _last_had_activity) > ((uint32_t )_slcan_timeout*1000 )) &&
538
542
(uint32_t )_slcan_timeout != 0 ) {
539
543
_port->lock_port (0 , 0 );
540
- _port = nullptr ;
544
+ _enabled = false ;
541
545
_slcan_ser_port.set_and_save (-1 );
542
546
_prev_ser_port = -1 ;
543
547
_slcan_start_req = false ;
@@ -637,7 +641,7 @@ bool SLCAN::CANIface::select(bool &read, bool &write, const AP_HAL::CANFrame* co
637
641
ret = _can_iface->select (read , write , pending_tx, blocking_deadline);
638
642
}
639
643
640
- if (_port == nullptr ) {
644
+ if (! is_enabled () ) {
641
645
return ret;
642
646
}
643
647
@@ -665,7 +669,7 @@ int16_t SLCAN::CANIface::send(const AP_HAL::CANFrame& frame, uint64_t tx_deadlin
665
669
ret = _can_iface->send (frame, tx_deadline, flags);
666
670
}
667
671
668
- if (_port == nullptr ) {
672
+ if (! is_enabled () ) {
669
673
return ret;
670
674
}
671
675
@@ -699,7 +703,7 @@ int16_t SLCAN::CANIface::receive(AP_HAL::CANFrame& out_frame, uint64_t& rx_time,
699
703
}
700
704
701
705
// We found nothing in HAL's CANIface receive, so look in SLCANIface
702
- if (_port == nullptr ) {
706
+ if (! is_enabled () ) {
703
707
return 0 ;
704
708
}
705
709
0 commit comments