AP_CANManager: fix casting without ensuring alignment
This commit is contained in:
parent
e8e5f49640
commit
0b505c491c
@ -94,7 +94,10 @@ void AP_CANTester_KDECAN::loop(void)
|
||||
if (esc_num != BROADCAST_NODE_ID) {
|
||||
for (; i < NUM_ESCS; i++) {
|
||||
if (object_address == UPDATE_NODE_ID_OBJ_ADDR) {
|
||||
if (_esc_info[i].mcu_id == be64toh(*((be64_t*) &(recv_frame.data[0])))) {
|
||||
uint64_t mcu_id;
|
||||
memcpy (&mcu_id, recv_frame.data, sizeof(mcu_id));
|
||||
mcu_id = be64toh(mcu_id);
|
||||
if (_esc_info[i].mcu_id == mcu_id) {
|
||||
n = i + 1;
|
||||
break;
|
||||
}
|
||||
@ -150,16 +153,16 @@ void AP_CANTester_KDECAN::loop(void)
|
||||
break;
|
||||
}
|
||||
case START_ENUM_OBJ_ADDR: {
|
||||
_esc_info[i].enum_timeout_ms = AP_HAL::millis() + be16toh(*((be16_t*) &(recv_frame.data[0])));
|
||||
_esc_info[i].enum_timeout_ms = AP_HAL::millis() + be16toh_ptr(&recv_frame.data[0]);
|
||||
gcs().send_text(MAV_SEVERITY_ALERT, "KDECANTester: Starting enumeration for ESC %d, timeout %u", i, (unsigned)_esc_info[i].enum_timeout_ms);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
case TELEMETRY_OBJ_ADDR: {
|
||||
uint8_t data[8] {};
|
||||
*((be16_t*) &data[0]) = htobe16(get_random16());
|
||||
*((be16_t*) &data[2]) = htobe16(get_random16());
|
||||
*((be16_t*) &data[4]) = htobe16(get_random16());
|
||||
put_le16_ptr(&data[0], get_random16());
|
||||
put_le16_ptr(&data[2], get_random16());
|
||||
put_le16_ptr(&data[4], get_random16());
|
||||
data[6] = uint8_t(float(rand()) / RAND_MAX * 40.0f + 15);
|
||||
|
||||
res_frame.dlc = 8;
|
||||
@ -218,10 +221,10 @@ bool AP_CANTester_KDECAN::send_enumeration(uint8_t num)
|
||||
}
|
||||
|
||||
while (true) {
|
||||
uint8_t mcu[8] {};
|
||||
*((be64_t*) mcu) = htobe64(_esc_info[num].mcu_id);
|
||||
uint64_t mcu = 0;
|
||||
mcu = htobe64(_esc_info[num].mcu_id);
|
||||
AP_HAL::CANFrame res_frame { (_esc_info[num].node_id << 16) | START_ENUM_OBJ_ADDR | AP_HAL::CANFrame::FlagEFF,
|
||||
mcu,
|
||||
(uint8_t*)&mcu,
|
||||
8 };
|
||||
int16_t res = _can_iface->send(res_frame, AP_HAL::micros64() + 1000, 0);
|
||||
if (res == 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user