mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-07 00:01:37 +08:00
uavcan_v1: Fix 'unset' port ID (use 65535)
This commit is contained in:
committed by
Lorenz Meier
parent
935bf75b61
commit
e654fe71f5
@@ -59,7 +59,7 @@ public:
|
|||||||
// Update the uORB Subscription and broadcast a UAVCAN message
|
// Update the uORB Subscription and broadcast a UAVCAN message
|
||||||
virtual void update() override
|
virtual void update() override
|
||||||
{
|
{
|
||||||
if (_gps_sub.updated() && _port_id > 0) {
|
if (_gps_sub.updated() && _port_id != CANARD_PORT_ID_UNSET) {
|
||||||
sensor_gps_s gps {};
|
sensor_gps_s gps {};
|
||||||
_gps_sub.update(&gps);
|
_gps_sub.update(&gps);
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@
|
|||||||
class UavcanPublication
|
class UavcanPublication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static constexpr uint16_t CANARD_PORT_ID_UNSET = 65535U;
|
||||||
|
|
||||||
UavcanPublication(CanardInstance &ins, UavcanParamManager &pmgr, const char *uavcan_pname) :
|
UavcanPublication(CanardInstance &ins, UavcanParamManager &pmgr, const char *uavcan_pname) :
|
||||||
_canard_instance(ins), _param_manager(pmgr), _uavcan_param(uavcan_pname) { };
|
_canard_instance(ins), _param_manager(pmgr), _uavcan_param(uavcan_pname) { };
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ public:
|
|||||||
int32_t new_id = value.integer32.value.elements[0];
|
int32_t new_id = value.integer32.value.elements[0];
|
||||||
|
|
||||||
if (_port_id != new_id) {
|
if (_port_id != new_id) {
|
||||||
if (new_id == 0) {
|
if (new_id == CANARD_PORT_ID_UNSET) {
|
||||||
PX4_INFO("Disabling publication of %s", _uavcan_param);
|
PX4_INFO("Disabling publication of %s", _uavcan_param);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -81,7 +83,7 @@ public:
|
|||||||
|
|
||||||
void printInfo()
|
void printInfo()
|
||||||
{
|
{
|
||||||
if (_port_id > 0) {
|
if (_port_id != CANARD_PORT_ID_UNSET) {
|
||||||
PX4_INFO("Enabled %s on port %d", _uavcan_param, _port_id);
|
PX4_INFO("Enabled %s on port %d", _uavcan_param, _port_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,6 +94,6 @@ protected:
|
|||||||
CanardRxSubscription _canard_sub;
|
CanardRxSubscription _canard_sub;
|
||||||
const char *_uavcan_param; // Port ID parameter
|
const char *_uavcan_param; // Port ID parameter
|
||||||
|
|
||||||
CanardPortID _port_id {0};
|
CanardPortID _port_id {CANARD_PORT_ID_UNSET};
|
||||||
CanardTransferID _transfer_id {0};
|
CanardTransferID _transfer_id {0};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,6 +53,8 @@
|
|||||||
class UavcanSubscription
|
class UavcanSubscription
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static constexpr uint16_t CANARD_PORT_ID_UNSET = 65535U;
|
||||||
|
|
||||||
UavcanSubscription(CanardInstance &ins, UavcanParamManager &pmgr, const char *uavcan_pname) :
|
UavcanSubscription(CanardInstance &ins, UavcanParamManager &pmgr, const char *uavcan_pname) :
|
||||||
_canard_instance(ins), _param_manager(pmgr), _uavcan_param(uavcan_pname) { };
|
_canard_instance(ins), _param_manager(pmgr), _uavcan_param(uavcan_pname) { };
|
||||||
|
|
||||||
@@ -71,12 +73,12 @@ public:
|
|||||||
int32_t new_id = value.integer32.value.elements[0];
|
int32_t new_id = value.integer32.value.elements[0];
|
||||||
|
|
||||||
if (_port_id != new_id) {
|
if (_port_id != new_id) {
|
||||||
if (new_id == 0) {
|
if (new_id == CANARD_PORT_ID_UNSET) {
|
||||||
// Cancel subscription
|
// Cancel subscription
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (_port_id > 0) {
|
if (_port_id != CANARD_PORT_ID_UNSET) {
|
||||||
// Already active; unsubscribe first
|
// Already active; unsubscribe first
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
@@ -91,7 +93,7 @@ public:
|
|||||||
|
|
||||||
void printInfo()
|
void printInfo()
|
||||||
{
|
{
|
||||||
if (_port_id > 0) {
|
if (_port_id != CANARD_PORT_ID_UNSET) {
|
||||||
PX4_INFO("Subscribed %s on port %d", _uavcan_param, _port_id);
|
PX4_INFO("Subscribed %s on port %d", _uavcan_param, _port_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,5 +105,5 @@ protected:
|
|||||||
const char *_uavcan_param; // Port ID parameter
|
const char *_uavcan_param; // Port ID parameter
|
||||||
/// TODO: 'type' parameter? uavcan.pub.PORT_NAME.type (see 384.Access.1.0.uavcan)
|
/// TODO: 'type' parameter? uavcan.pub.PORT_NAME.type (see 384.Access.1.0.uavcan)
|
||||||
|
|
||||||
CanardPortID _port_id {0};
|
CanardPortID _port_id {CANARD_PORT_ID_UNSET};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user