AP_Mount: viewpro calc_crc len arg fix
Also remove one unnecessary length check Also correct length check that meant last byte of buffer was unusable
This commit is contained in:
parent
e0353666d4
commit
d5977b6d96
@ -191,7 +191,7 @@ void AP_Mount_Viewpro::read_incoming_packets()
|
|||||||
_msg_buff[_msg_buff_len++] = b;
|
_msg_buff[_msg_buff_len++] = b;
|
||||||
|
|
||||||
// protect against overly long messages
|
// protect against overly long messages
|
||||||
if (_msg_buff_len >= AP_MOUNT_VIEWPRO_PACKETLEN_MAX) {
|
if (_msg_buff_len > AP_MOUNT_VIEWPRO_PACKETLEN_MAX) {
|
||||||
reset_parser = true;
|
reset_parser = true;
|
||||||
debug("vp buff full s:%u len:%u", (unsigned)_parsed_msg.state, (unsigned)_msg_buff_len);
|
debug("vp buff full s:%u len:%u", (unsigned)_parsed_msg.state, (unsigned)_msg_buff_len);
|
||||||
}
|
}
|
||||||
@ -233,12 +233,7 @@ void AP_Mount_Viewpro::read_incoming_packets()
|
|||||||
// length held in bits 0 ~ 5. length includes this length byte, frame id and final crc
|
// length held in bits 0 ~ 5. length includes this length byte, frame id and final crc
|
||||||
// ignore frame counter held in bits 6~7
|
// ignore frame counter held in bits 6~7
|
||||||
_parsed_msg.data_len = b & 0x3F;
|
_parsed_msg.data_len = b & 0x3F;
|
||||||
if (_parsed_msg.data_len <= AP_MOUNT_VIEWPRO_DATALEN_MAX) {
|
_parsed_msg.state = ParseState::WAITING_FOR_FRAMEID;
|
||||||
_parsed_msg.state = ParseState::WAITING_FOR_FRAMEID;
|
|
||||||
} else {
|
|
||||||
reset_parser = true;
|
|
||||||
debug("data len too long:%u (>%u)", (unsigned)_parsed_msg.data_len, (unsigned)AP_MOUNT_VIEWPRO_DATALEN_MAX);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ParseState::WAITING_FOR_FRAMEID:
|
case ParseState::WAITING_FOR_FRAMEID:
|
||||||
@ -327,7 +322,7 @@ void AP_Mount_Viewpro::process_packet()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculate crc of the received message
|
// calculate crc of the received message
|
||||||
uint8_t AP_Mount_Viewpro::calc_crc(const uint8_t *buf, uint32_t len) const
|
uint8_t AP_Mount_Viewpro::calc_crc(const uint8_t *buf, uint8_t len) const
|
||||||
{
|
{
|
||||||
uint8_t res = 0;
|
uint8_t res = 0;
|
||||||
for (uint8_t i=0; i<len; i++) {
|
for (uint8_t i=0; i<len; i++) {
|
||||||
|
@ -281,7 +281,7 @@ private:
|
|||||||
void process_packet();
|
void process_packet();
|
||||||
|
|
||||||
// calculate crc of the received message
|
// calculate crc of the received message
|
||||||
uint8_t calc_crc(const uint8_t *buf, uint32_t length) const;
|
uint8_t calc_crc(const uint8_t *buf, uint8_t length) const;
|
||||||
|
|
||||||
// get the length and frame count byte (3rd byte of all messages)
|
// get the length and frame count byte (3rd byte of all messages)
|
||||||
// length is all bytes after the header including CRC
|
// length is all bytes after the header including CRC
|
||||||
|
Loading…
Reference in New Issue
Block a user