RunOnceEvery instead of counter

This commit is contained in:
Christophe De Wagter
2024-09-28 13:27:10 +02:00
parent a47af1367c
commit 4601b2010e
3 changed files with 9 additions and 26 deletions
@@ -58,9 +58,7 @@ struct uavcan_iface_t uavcan1 = {
.thread_tx_wa_size = sizeof(uavcan1_tx_wa),
.node_id = UAVCAN_CAN1_NODE_ID,
.transfer_id = 0,
.initialized = false,
.cnt_act_raw = 0,
.cnt_act_cmd = 0
.initialized = false
};
#endif
@@ -86,9 +84,7 @@ struct uavcan_iface_t uavcan2 = {
.thread_tx_wa_size = sizeof(uavcan2_tx_wa),
.node_id = UAVCAN_CAN2_NODE_ID,
.transfer_id = 0,
.initialized = false,
.cnt_act_raw = 0,
.cnt_act_cmd = 0
.initialized = false
};
#endif
@@ -51,9 +51,6 @@ struct uavcan_iface_t {
uint8_t transfer_id;
bool initialized;
uint16_t cnt_act_raw;
uint16_t cnt_act_cmd;
};
/** Generic uavcan callback definition */
@@ -82,4 +79,4 @@ void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_eve
void uavcan_broadcast(struct uavcan_iface_t *iface, uint64_t data_type_signature, uint16_t data_type_id,
uint8_t priority, const void *payload, uint16_t payload_len);
#endif /* MODULES_UAVCAN_ARCH_H */
#endif /* MODULES_UAVCAN_ARCH_H */
@@ -454,14 +454,9 @@ void actuators_uavcan_commit(struct uavcan_iface_t *iface, int16_t *values, uint
offset += 14;
}
iface->cnt_act_raw++;
if(iface->cnt_act_raw >= ACTUATORS_UAVCAN_RAW_DIV) {
iface->cnt_act_raw = 0;
// Broadcast the raw command message on the interface
uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID,
CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8);
}
// Broadcast the raw command message on the interface
RunOnceEvery(ACTUATORS_UAVCAN_RAW_DIV, uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID,
CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8));
}
/**
@@ -493,12 +488,7 @@ void actuators_uavcan_cmd_commit(struct uavcan_iface_t *iface, int16_t *values,
offset += 16;
}
iface->cnt_act_cmd++;
if(iface->cnt_act_cmd >= ACTUATORS_UAVCAN_CMD_DIV) {
iface->cnt_act_cmd = 0;
// Broadcast the raw command message on the interface
uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID,
CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8);
}
// Broadcast the raw command message on the interface
RunOnceEvery(ACTUATORS_UAVCAN_CMD_DIV, uavcan_broadcast(iface, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE, UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID,
CANARD_TRANSFER_PRIORITY_HIGH, buffer, (offset + 7) / 8));
}