From f9cb76069186a716028193c60aa162d6e4a70607 Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Mon, 6 Jun 2016 10:50:53 -0300 Subject: [PATCH] AP_Mount: use ARRAY_SUBSCRIPT instead of bytes field That fixed compilation issues and seems more semantically correct. Using array of length 0 fails compilation because of -Werror=array-bounds in GCC 6.1. --- libraries/AP_Mount/AP_Mount_Alexmos.cpp | 2 +- libraries/AP_Mount/AP_Mount_Alexmos.h | 2 +- libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp | 7 ++++--- libraries/AP_Mount/AP_Mount_SToRM32_serial.h | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Mount/AP_Mount_Alexmos.cpp b/libraries/AP_Mount/AP_Mount_Alexmos.cpp index 235ea469a7..4b5568b9b1 100644 --- a/libraries/AP_Mount/AP_Mount_Alexmos.cpp +++ b/libraries/AP_Mount/AP_Mount_Alexmos.cpp @@ -267,7 +267,7 @@ void AP_Mount_Alexmos::read_incoming() case 4: // parsing body _checksum += data; if (_payload_counter < sizeof(_buffer)) { - _buffer.bytes[_payload_counter] = data; + _buffer[_payload_counter] = data; } if (++_payload_counter == _payload_length) _step++; diff --git a/libraries/AP_Mount/AP_Mount_Alexmos.h b/libraries/AP_Mount/AP_Mount_Alexmos.h index 513ab7342b..6a8b42b476 100644 --- a/libraries/AP_Mount/AP_Mount_Alexmos.h +++ b/libraries/AP_Mount/AP_Mount_Alexmos.h @@ -284,11 +284,11 @@ private: }; union PACKED alexmos_parameters { + DEFINE_BYTE_ARRAY_METHODS alexmos_version version; alexmos_angles angles; alexmos_params params; alexmos_angles_speed angle_speed; - uint8_t bytes[0]; } _buffer,_current_parameters; AP_HAL::UARTDriver *_port; diff --git a/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp b/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp index cf1ed1e35d..b44447588e 100644 --- a/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp +++ b/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp @@ -236,7 +236,7 @@ void AP_Mount_SToRM32_serial::read_incoming() { continue; } - _buffer.bytes[_reply_counter++] = data; + _buffer[_reply_counter++] = data; if (_reply_counter == _reply_length) { parse_reply(); @@ -266,7 +266,7 @@ void AP_Mount_SToRM32_serial::parse_reply() { switch (_reply_type) { case ReplyType_DATA: - crc = crc_calculate(_buffer.bytes, sizeof(_buffer.data)-3); + crc = crc_calculate(&_buffer[0], sizeof(_buffer.data) - 3); crc_ok = crc == _buffer.data.crc; if (!crc_ok) { break; @@ -277,7 +277,8 @@ void AP_Mount_SToRM32_serial::parse_reply() { _current_angle.z = _buffer.data.imu1_yaw; break; case ReplyType_ACK: - crc = crc_calculate(&_buffer.bytes[1], sizeof(SToRM32_reply_ack_struct)-3); + crc = crc_calculate(&_buffer[1], + sizeof(SToRM32_reply_ack_struct) - 3); crc_ok = crc == _buffer.ack.crc; break; default: diff --git a/libraries/AP_Mount/AP_Mount_SToRM32_serial.h b/libraries/AP_Mount/AP_Mount_SToRM32_serial.h index 32c8a60d46..1f9ff51b84 100644 --- a/libraries/AP_Mount/AP_Mount_SToRM32_serial.h +++ b/libraries/AP_Mount/AP_Mount_SToRM32_serial.h @@ -143,9 +143,9 @@ private: union PACKED SToRM32_reply { + DEFINE_BYTE_ARRAY_METHODS SToRM32_reply_data_struct data; SToRM32_reply_ack_struct ack; - uint8_t bytes[0]; } _buffer; // keep the last _current_angle values