tap_esc: add buffer size check for _esc_feedback.esc[]

This commit is contained in:
Beat Küng 2016-07-25 12:26:51 +02:00 committed by Lorenz Meier
parent c55c978145
commit d6d3a56116
1 changed files with 15 additions and 13 deletions

View File

@ -445,7 +445,7 @@ void TAP_ESC:: send_esc_outputs(const float *pwm, const unsigned num_pwm)
void TAP_ESC::read_data_from_uart()
{
uint8_t tmp_serial_buf[UART_BUFFER_SIZE] = {0};
uint8_t tmp_serial_buf[UART_BUFFER_SIZE];
int len =::read(_uart_fd, tmp_serial_buf, arraySize(tmp_serial_buf));
@ -518,7 +518,7 @@ bool TAP_ESC:: parse_tap_esc_feedback(ESC_UART_BUF *serial_buf, EscPacket *packe
if (crc_data_cal == serial_buf->esc_feedback_buf[serial_buf->head]) {
packetdata->crc_data = serial_buf->esc_feedback_buf[serial_buf->head];
if (++serial_buf->head >= 128) {
if (++serial_buf->head >= UART_BUFFER_SIZE) {
serial_buf->head = 0;
}
@ -726,6 +726,7 @@ TAP_ESC::cycle()
if (parse_tap_esc_feedback(&uartbuf, &_packet) == true) {
if (_packet.msg_id == ESCBUS_MSG_ID_RUN_INFO) {
RunInfoRepsonse &feed_back_data = _packet.d.rspRunInfo;
if (feed_back_data.channelID < esc_status_s::CONNECTED_ESC_MAX) {
_esc_feedback.esc[feed_back_data.channelID].esc_rpm = feed_back_data.speed;
// _esc_feedback.esc[feed_back_data.channelID].esc_voltage = feed_back_data.voltage;
_esc_feedback.esc[feed_back_data.channelID].esc_state = feed_back_data.ESCStatus;
@ -742,6 +743,7 @@ TAP_ESC::cycle()
orb_publish(ORB_ID(esc_status), _esc_feedback_pub, &_esc_feedback);
}
}
}
/* and publish for anyone that cares to see */
orb_publish(ORB_ID(actuator_outputs), _outputs_pub, &_outputs);