uavcan_v1: Fix 'unset' port ID (use 65535)

This commit is contained in:
JacobCrabill
2021-02-23 09:58:52 -08:00
committed by Lorenz Meier
parent 935bf75b61
commit e654fe71f5
3 changed files with 12 additions and 8 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ public:
// Update the uORB Subscription and broadcast a UAVCAN message
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 {};
_gps_sub.update(&gps);
@@ -53,6 +53,8 @@
class UavcanPublication
{
public:
static constexpr uint16_t CANARD_PORT_ID_UNSET = 65535U;
UavcanPublication(CanardInstance &ins, UavcanParamManager &pmgr, const char *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];
if (_port_id != new_id) {
if (new_id == 0) {
if (new_id == CANARD_PORT_ID_UNSET) {
PX4_INFO("Disabling publication of %s", _uavcan_param);
} else {
@@ -81,7 +83,7 @@ public:
void printInfo()
{
if (_port_id > 0) {
if (_port_id != CANARD_PORT_ID_UNSET) {
PX4_INFO("Enabled %s on port %d", _uavcan_param, _port_id);
}
}
@@ -92,6 +94,6 @@ protected:
CanardRxSubscription _canard_sub;
const char *_uavcan_param; // Port ID parameter
CanardPortID _port_id {0};
CanardPortID _port_id {CANARD_PORT_ID_UNSET};
CanardTransferID _transfer_id {0};
};
@@ -53,6 +53,8 @@
class UavcanSubscription
{
public:
static constexpr uint16_t CANARD_PORT_ID_UNSET = 65535U;
UavcanSubscription(CanardInstance &ins, UavcanParamManager &pmgr, const char *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];
if (_port_id != new_id) {
if (new_id == 0) {
if (new_id == CANARD_PORT_ID_UNSET) {
// Cancel subscription
unsubscribe();
} else {
if (_port_id > 0) {
if (_port_id != CANARD_PORT_ID_UNSET) {
// Already active; unsubscribe first
unsubscribe();
}
@@ -91,7 +93,7 @@ public:
void printInfo()
{
if (_port_id > 0) {
if (_port_id != CANARD_PORT_ID_UNSET) {
PX4_INFO("Subscribed %s on port %d", _uavcan_param, _port_id);
}
}
@@ -103,5 +105,5 @@ protected:
const char *_uavcan_param; // Port ID parameter
/// 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};
};