Skip to content

Commit 090331c

Browse files
committed
AP_AIS: fix multi part message decoding
1 parent d529601 commit 090331c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

libraries/AP_AIS/AP_AIS.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,25 @@ void AP_AIS::update()
145145
} else if (_incoming.num == _incoming.total) {
146146
// last part of a multi part message
147147
uint8_t index = 0;
148-
uint8_t msg_parts[_incoming.num - 1];
148+
149+
// We have the last part, need to find preceding fragments
150+
const uint8_t parts = _incoming.num - 1;
151+
152+
uint8_t msg_parts[parts];
149153
for (uint8_t i = 0; i < AIVDM_BUFFER_SIZE; i++) {
150154
// look for the rest of the message from the start of the buffer
151155
// we assume the message has be received in the correct order
152156
if (_AIVDM_buffer[i].num == (index + 1) && _AIVDM_buffer[i].total == _incoming.total && _AIVDM_buffer[i].ID == _incoming.ID) {
153157
msg_parts[index] = i;
154158
index++;
155-
if (index >= _incoming.num) {
159+
if (index >= parts) {
156160
break;
157161
}
158162
}
159163
}
160164

161165
// did we find the right number?
162-
if (_incoming.num != index) {
166+
if (_incoming.num != parts) {
163167
// could not find all of the message, save messages
164168
#if HAL_LOGGING_ENABLED
165169
if (log_unsupported) {

0 commit comments

Comments
 (0)