[hamradio-commits] [dump1090] 73/389: Get rid of that hideous goto
Matthew Ernisse
mernisse-guest at moszumanska.debian.org
Wed Nov 5 00:19:41 UTC 2014
This is an automated email from the git hooks/post-receive script.
mernisse-guest pushed a commit to branch master
in repository dump1090.
commit f1935b280c4b89ef840b548b3f14a668cf7d1c28
Author: Malcolm Robb <Support at ATTAvionics.com>
Date: Wed Apr 10 11:43:55 2013 +0100
Get rid of that hideous goto
I'm not overly keen on the continues either :-)
---
dump1090.c | 107 +++++++++++++++++++++++++++++++------------------------------
1 file changed, 54 insertions(+), 53 deletions(-)
diff --git a/dump1090.c b/dump1090.c
index 0f7de86..1213e18 100644
--- a/dump1090.c
+++ b/dump1090.c
@@ -1349,67 +1349,68 @@ void detectModeS(uint16_t *m, uint32_t mlen) {
pPreamble = &m[j];
pPayload = &m[j+MODES_PREAMBLE_SAMPLES];
- if (use_correction) goto good_preamble; /* We already checked it. */
-
- /* 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;
- }
+ 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;
+ }
- /* The samples between the two spikes must be < than the average
- * of the high spikes level. We don't test bits too near to
- * the high levels as signals can be out of phase so part of the
- * energy can be in the near samples. */
- high = (pPreamble[0]+pPreamble[2]+pPreamble[7]+pPreamble[9])/6;
- if (pPreamble[4] >= high ||
- pPreamble[5] >= high)
- {
- if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
- *pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
- dumpRawMessage("Too high level in samples between 3 and 6", msg, m, j);
- continue;
- }
+ /* The samples between the two spikes must be < than the average
+ * of the high spikes level. We don't test bits too near to
+ * the high levels as signals can be out of phase so part of the
+ * energy can be in the near samples. */
+ high = (pPreamble[0]+pPreamble[2]+pPreamble[7]+pPreamble[9])/6;
+ if (pPreamble[4] >= high ||
+ pPreamble[5] >= high)
+ {
+ if (Modes.debug & MODES_DEBUG_NOPREAMBLE &&
+ *pPreamble > MODES_DEBUG_NOPREAMBLE_LEVEL)
+ dumpRawMessage("Too high level in samples between 3 and 6", msg, m, j);
+ continue;
+ }
- /* Similarly samples in the range 11-14 must be low, as it is the
- * space between the preamble and real data. Again we don't test
- * bits too near to high levels, see above. */
- if (pPreamble[11] >= high ||
- 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++;
+ /* Similarly samples in the range 11-14 must be low, as it is the
+ * space between the preamble and real data. Again we don't test
+ * bits too near to high levels, see above. */
+ if (pPreamble[11] >= high ||
+ 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) {
+ else {
+ /* If the previous attempt with this message failed, retry using
+ * magnitude correction. */
+ // Make a copy of the Payload, and phase correct the copy
memcpy(aux, pPayload, sizeof(aux));
applyPhaseCorrection(aux);
Modes.stat_out_of_phase++;
pPayload = aux;
/* TODO ... apply other kind of corrections. */
- }
+ }
/* Decode all the next 112 bits, regardless of the actual message
* size. We'll check the actual message type later. */
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git
More information about the pkg-hamradio-commits
mailing list