summaryrefslogtreecommitdiff
path: root/reset-controller/fw/src/protocol.c
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2021-04-09 18:38:02 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2021-04-09 18:38:57 +0200
commit50998fcfb916ae251309bd4b464f2c122e8cb30d (patch)
tree4ecf7a7443b75ab51c4dc0c0fc9289342dc7d6a0 /reset-controller/fw/src/protocol.c
parent312fee491cfab436d52db4b6265107e20f3e1293 (diff)
downloadmaster-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.tar.gz
master-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.tar.bz2
master-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.zip
Repo re-org
Diffstat (limited to 'reset-controller/fw/src/protocol.c')
-rw-r--r--reset-controller/fw/src/protocol.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/reset-controller/fw/src/protocol.c b/reset-controller/fw/src/protocol.c
new file mode 100644
index 0000000..6b7d8b7
--- /dev/null
+++ b/reset-controller/fw/src/protocol.c
@@ -0,0 +1,44 @@
+
+#include <assert.h>
+
+#include "sr_global.h"
+#include "dsss_demod.h"
+#include "con_usart.h"
+#include "rslib.h"
+#include "crypto.h"
+
+void handle_dsss_received(uint8_t data[static TRANSMISSION_SYMBOLS]) {
+ /* Console status output */
+ con_printf("DSSS data received: ");
+ for (int i=0; i<TRANSMISSION_SYMBOLS; i++) {
+ int x = (data[i]>>1) * (data[i]&1 ? 1 : -1);
+ con_printf("%3d ", x);
+ }
+ con_printf("\r\n");
+
+ /* Run reed-solomon error correction */
+ const int sym_bits = DSSS_GOLD_CODE_NBITS + 1; /* +1 for amplitude sign bit */
+ /* TODO identify erasures in DSSS demod layer */
+ (void) rslib_decode(sym_bits, TRANSMISSION_SYMBOLS, (char *)data);
+ /* TODO error detection & handling */
+
+ /* Re-bit-pack data buffer to be bit-continuous:
+ * [ . . a b c d e f ] [ . . g h i j k l ] [ . . m n o p q r ] ...
+ * ==> [ a b c d e f g h ] [ i j k l m n o p ] [ q r ... ] ...
+ */
+ static_assert((TRANSMISSION_SYMBOLS - NPAR) * (DSSS_GOLD_CODE_NBITS + 1) == OOB_TRIGGER_LEN * 8);
+ for (uint8_t i=0, j=0; i < TRANSMISSION_SYMBOLS - NPAR; i++, j += sym_bits) {
+ uint32_t sym = data[i]; /* [ ... | . . X X X X X X ] for 5-bit dsss */
+ data[i] = 0; /* clear for output */
+
+ sym <<= 8-sym_bits; /* left-align: [ ... | X X X X X X . . ] */
+ sym <<= 8; /* shift to second byte: [ ... | X X X X X X . . | . . . . . . . . ]*/
+ sym >>= (j%8); /* shift to bit write offset: [ ... | . . . . X X X X | X X . . . . . . ] for offset 4 */
+ data[j/8] |= sym >> 8; /* write upper byte */
+ data[j/8 + 1] |= sym & 0xff; /* write lower byte */
+ }
+
+ /* hand off to crypto.c */
+ oob_message_received(data);
+}
+