forked from Archive/PX4-Autopilot
Merge pull request #1249 from PX4/uavcan_node_info
Properly filling basic UAVCAN node info
This commit is contained in:
commit
5643bc4bd2
|
@ -65,10 +65,6 @@ override EXTRADEFINES := $(EXTRADEFINES) -DUAVCAN_STM32_NUTTX -DUAVCAN_STM32_NUM
|
|||
|
||||
#
|
||||
# Invoke DSDL compiler
|
||||
# TODO: Add make target for this, or invoke dsdlc manually.
|
||||
# The second option assumes that the generated headers shall be saved
|
||||
# under the version control, which may be undesirable.
|
||||
# The first option requires any Python and the Python Mako library for the sources to be built.
|
||||
#
|
||||
$(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR)))
|
||||
INCLUDE_DIRS += dsdlc_generated
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include <systemlib/err.h>
|
||||
#include <systemlib/systemlib.h>
|
||||
#include <systemlib/mixer/mixer.h>
|
||||
#include <systemlib/board_serial.h>
|
||||
#include <version/version.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <arch/chip/chip.h>
|
||||
|
||||
|
@ -173,6 +175,44 @@ int UavcanNode::start(uavcan::NodeID node_id, uint32_t bitrate)
|
|||
return OK;
|
||||
}
|
||||
|
||||
void UavcanNode::fill_node_info()
|
||||
{
|
||||
/* software version */
|
||||
uavcan::protocol::SoftwareVersion swver;
|
||||
|
||||
// Extracting the last 8 hex digits of FW_GIT and converting them to int
|
||||
const unsigned fw_git_len = std::strlen(FW_GIT);
|
||||
if (fw_git_len >= 8) {
|
||||
char fw_git_short[9] = {};
|
||||
std::memmove(fw_git_short, FW_GIT + fw_git_len - 8, 8);
|
||||
assert(fw_git_short[8] == '\0');
|
||||
char *end = nullptr;
|
||||
swver.vcs_commit = std::strtol(fw_git_short, &end, 16);
|
||||
swver.optional_field_mask |= swver.OPTIONAL_FIELD_MASK_VCS_COMMIT;
|
||||
}
|
||||
|
||||
warnx("SW version vcs_commit: 0x%08x", unsigned(swver.vcs_commit));
|
||||
|
||||
_node.setSoftwareVersion(swver);
|
||||
|
||||
/* hardware version */
|
||||
uavcan::protocol::HardwareVersion hwver;
|
||||
|
||||
if (!std::strncmp(HW_ARCH, "PX4FMU_V1", 9)) {
|
||||
hwver.major = 1;
|
||||
} else if (!std::strncmp(HW_ARCH, "PX4FMU_V2", 9)) {
|
||||
hwver.major = 2;
|
||||
} else {
|
||||
; // All other values of HW_ARCH resolve to zero
|
||||
}
|
||||
|
||||
uint8_t udid[12] = {}; // Someone seems to love magic numbers
|
||||
get_board_serial(udid);
|
||||
uavcan::copy(udid, udid + sizeof(udid), hwver.unique_id.begin());
|
||||
|
||||
_node.setHardwareVersion(hwver);
|
||||
}
|
||||
|
||||
int UavcanNode::init(uavcan::NodeID node_id)
|
||||
{
|
||||
int ret = -1;
|
||||
|
@ -183,6 +223,13 @@ int UavcanNode::init(uavcan::NodeID node_id)
|
|||
if (ret != OK)
|
||||
return ret;
|
||||
|
||||
_node.setName("org.pixhawk.pixhawk");
|
||||
|
||||
_node.setNodeID(node_id);
|
||||
|
||||
fill_node_info();
|
||||
|
||||
/* initializing the bridges UAVCAN <--> uORB */
|
||||
ret = _esc_controller.init();
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
@ -191,20 +238,6 @@ int UavcanNode::init(uavcan::NodeID node_id)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
uavcan::protocol::SoftwareVersion swver;
|
||||
swver.major = 12; // TODO fill version info
|
||||
swver.minor = 34;
|
||||
_node.setSoftwareVersion(swver);
|
||||
|
||||
uavcan::protocol::HardwareVersion hwver;
|
||||
hwver.major = 42; // TODO fill version info
|
||||
hwver.minor = 42;
|
||||
_node.setHardwareVersion(hwver);
|
||||
|
||||
_node.setName("org.pixhawk"); // Huh?
|
||||
|
||||
_node.setNodeID(node_id);
|
||||
|
||||
return _node.start();
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ public:
|
|||
static UavcanNode* instance() { return _instance; }
|
||||
|
||||
private:
|
||||
void fill_node_info();
|
||||
int init(uavcan::NodeID node_id);
|
||||
void node_spin_once();
|
||||
int run();
|
||||
|
|
2
uavcan
2
uavcan
|
@ -1 +1 @@
|
|||
Subproject commit d84fc8a84678d93f97f93b240c81472797ca5889
|
||||
Subproject commit 6980ee824074aa2f7a62221bf6040ee411119520
|
Loading…
Reference in New Issue