Get rid of that hideous goto

I'm not overly keen on the continues either :-)
This commit is contained in:
Malcolm Robb 2013-04-10 11:43:55 +01:00
parent e59142b9dc
commit f1935b280c

View file

@ -1349,67 +1349,68 @@ void detectModeS(uint16_t *m, uint32_t mlen) {
pPreamble = &m[j]; pPreamble = &m[j];
pPayload = &m[j+MODES_PREAMBLE_SAMPLES]; pPayload = &m[j+MODES_PREAMBLE_SAMPLES];
if (use_correction) goto good_preamble; /* We already checked it. */ if (!use_correction) // This is not a re-try with phase correction
{ // so try to find a new preamble
/* First check of relations between the first 10 samples
* representing a valid preamble. We don't even investigate further
* if this simple test is not passed. */
if (!(pPreamble[0] > pPreamble[1] &&
pPreamble[1] < pPreamble[2] &&
pPreamble[2] > pPreamble[3] &&
pPreamble[3] < pPreamble[0] &&
pPreamble[4] < pPreamble[0] &&
pPreamble[5] < pPreamble[0] &&
pPreamble[6] < pPreamble[0] &&
pPreamble[7] > pPreamble[8] &&
pPreamble[8] < pPreamble[9] &&
pPreamble[9] > pPreamble[6]))
{
if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
*pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
dumpRawMessage("Unexpected ratio among first 10 samples", msg, m, j);
continue;
}
/* First check of relations between the first 10 samples /* The samples between the two spikes must be < than the average
* representing a valid preamble. We don't even investigate further * of the high spikes level. We don't test bits too near to
* if this simple test is not passed. */ * the high levels as signals can be out of phase so part of the
if (!(pPreamble[0] > pPreamble[1] && * energy can be in the near samples. */
pPreamble[1] < pPreamble[2] && high = (pPreamble[0]+pPreamble[2]+pPreamble[7]+pPreamble[9])/6;
pPreamble[2] > pPreamble[3] && if (pPreamble[4] >= high ||
pPreamble[3] < pPreamble[0] && pPreamble[5] >= high)
pPreamble[4] < pPreamble[0] && {
pPreamble[5] < pPreamble[0] && if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
pPreamble[6] < pPreamble[0] && *pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
pPreamble[7] > pPreamble[8] && dumpRawMessage("Too high level in samples between 3 and 6", msg, m, j);
pPreamble[8] < pPreamble[9] && continue;
pPreamble[9] > pPreamble[6])) }
{
if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
*pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
dumpRawMessage("Unexpected ratio among first 10 samples", msg, m, j);
continue;
}
/* The samples between the two spikes must be < than the average /* Similarly samples in the range 11-14 must be low, as it is the
* of the high spikes level. We don't test bits too near to * space between the preamble and real data. Again we don't test
* the high levels as signals can be out of phase so part of the * bits too near to high levels, see above. */
* energy can be in the near samples. */ if (pPreamble[11] >= high ||
high = (pPreamble[0]+pPreamble[2]+pPreamble[7]+pPreamble[9])/6; pPreamble[12] >= high ||
if (pPreamble[4] >= high || pPreamble[13] >= high ||
pPreamble[5] >= high) pPreamble[14] >= high)
{ {
if (Modes.debug & MODES_DEBUG_NOPREAMBLE && if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
*pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL) *pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
dumpRawMessage("Too high level in samples between 3 and 6", msg, m, j); dumpRawMessage("Too high level in samples between 10 and 15", msg, m, j);
continue; continue;
} }
Modes.stat_valid_preamble++;
}
/* Similarly samples in the range 11-14 must be low, as it is the else {
* space between the preamble and real data. Again we don't test /* If the previous attempt with this message failed, retry using
* bits too near to high levels, see above. */ * magnitude correction. */
if (pPreamble[11] >= high || // Make a copy of the Payload, and phase correct the copy
pPreamble[12] >= high ||
pPreamble[13] >= high ||
pPreamble[14] >= high)
{
if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
*pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
dumpRawMessage("Too high level in samples between 10 and 15", msg, m, j);
continue;
}
Modes.stat_valid_preamble++;
good_preamble:
/* If the previous attempt with this message failed, retry using
* magnitude correction. */
if (use_correction) {
memcpy(aux, pPayload, sizeof(aux)); memcpy(aux, pPayload, sizeof(aux));
applyPhaseCorrection(aux); applyPhaseCorrection(aux);
Modes.stat_out_of_phase++; Modes.stat_out_of_phase++;
pPayload = aux; pPayload = aux;
/* TODO ... apply other kind of corrections. */ /* TODO ... apply other kind of corrections. */
} }
/* Decode all the next 112 bits, regardless of the actual message /* Decode all the next 112 bits, regardless of the actual message
* size. We'll check the actual message type later. */ * size. We'll check the actual message type later. */