summaryrefslogtreecommitdiff
path: root/controller/fw/tools
diff options
context:
space:
mode:
Diffstat (limited to 'controller/fw/tools')
-rw-r--r--controller/fw/tools/dsss_demod_test.c2
-rw-r--r--controller/fw/tools/e2e_test.c111
-rw-r--r--controller/fw/tools/freq_meas_test.c6
-rw-r--r--controller/fw/tools/presig_gen.py16
4 files changed, 124 insertions, 11 deletions
diff --git a/controller/fw/tools/dsss_demod_test.c b/controller/fw/tools/dsss_demod_test.c
index 64fd889..7a4ca71 100644
--- a/controller/fw/tools/dsss_demod_test.c
+++ b/controller/fw/tools/dsss_demod_test.c
@@ -70,7 +70,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Reading %zd samples test data...", st.st_size/sizeof(float));
ssize_t nread = 0;
while (nread < st.st_size) {
- ssize_t rc = read(fd, buf, st.st_size - nread);
+ ssize_t rc = read(fd, buf + nread, st.st_size - nread);
if (rc == -EINTR || rc == -EAGAIN)
continue;
diff --git a/controller/fw/tools/e2e_test.c b/controller/fw/tools/e2e_test.c
new file mode 100644
index 0000000..935f70d
--- /dev/null
+++ b/controller/fw/tools/e2e_test.c
@@ -0,0 +1,111 @@
+
+#include <stdint.h>
+#include <math.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+
+#include "freq_meas.h"
+#include "dsss_demod.h"
+
+typedef uint16_t adc_data_t;
+
+void handle_dsss_received(uint8_t data[static TRANSMISSION_SYMBOLS]) {
+ printf("data sequence received: [ ");
+ for (size_t i=0; i<TRANSMISSION_SYMBOLS; i++) {
+ printf("%+3d", ((data[i]&1) ? 1 : -1) * (data[i]>>1));
+ if (i+1 < TRANSMISSION_SYMBOLS)
+ printf(", ");
+ }
+ printf(" ]\n");
+}
+
+void print_usage(void);
+void print_usage() {
+ fprintf(stderr, "Usage: e2e_test [emulated_adc_data.bin]\n");
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ fprintf(stderr, "Error: Invalid arguments.\n");
+ print_usage();
+ return 1;
+ }
+
+ int fd = open(argv[1], O_RDONLY);
+ struct stat st;
+ if (fstat(fd, &st)) {
+ fprintf(stderr, "Error querying test data file size: %s\n", strerror(errno));
+ return 2;
+ }
+
+ if (st.st_size < 0 || st.st_size > 100000000) {
+ fprintf(stderr, "Error reading test data: too much test data (size=%zd)\n", st.st_size);
+ return 2;
+ }
+
+ if (st.st_size % sizeof(adc_data_t) != 0) {
+ fprintf(stderr, "Error reading test data: file size is not divisible by %zd (size=%zd)\n", sizeof(adc_data_t), st.st_size);
+ return 2;
+ }
+
+ char *buf = malloc(st.st_size);
+ if (!buf) {
+ fprintf(stderr, "Error allocating memory");
+ return 2;
+ }
+
+ const size_t n_samples = st.st_size / sizeof(adc_data_t);
+ fprintf(stderr, "Reading %zd samples test data...", n_samples);
+ ssize_t nread = 0;
+ while (nread < st.st_size) {
+ ssize_t rc = read(fd, buf + nread, st.st_size - nread);
+
+ if (rc == -EINTR || rc == -EAGAIN)
+ continue;
+
+ if (rc < 0) {
+ fprintf(stderr, "\nError reading test data: %s\n", strerror(errno));
+ return 2;
+ }
+
+ if (rc == 0) {
+ fprintf(stderr, "\nError reading test data: Unexpected end of file\n");
+ return 2;
+ }
+
+ nread += rc;
+ }
+ fprintf(stderr, " done. Read %zd bytes.\n", nread);
+
+ adc_data_t *buf_d = (adc_data_t *)buf;
+
+ struct dsss_demod_state demod;
+ dsss_demod_init(&demod);
+
+ fprintf(stderr, "Starting simulation.\n");
+ size_t iterations = (n_samples-FMEAS_FFT_LEN)/(FMEAS_FFT_LEN/2);
+ for (size_t i=0; i<iterations; i++) {
+
+ /*
+ fprintf(stderr, "Iteration %zd/%zd\n", i, iterations);
+ */
+ float res = NAN;
+ int rc = adc_buf_measure_freq(buf_d + i*(FMEAS_FFT_LEN/2), &res);
+ if (rc)
+ printf("ERROR: Simulation error in iteration %zd at position %zd: %d\n", i, i*(FMEAS_FFT_LEN/2), rc);
+
+ dsss_demod_step(&demod, res, i);
+ /*
+ printf("%09zd %12f\n", i, res);
+ */
+ }
+
+ free(buf);
+ return 0;
+}
diff --git a/controller/fw/tools/freq_meas_test.c b/controller/fw/tools/freq_meas_test.c
index e80290e..e2900ad 100644
--- a/controller/fw/tools/freq_meas_test.c
+++ b/controller/fw/tools/freq_meas_test.c
@@ -49,9 +49,9 @@ int main(int argc, char **argv) {
}
fprintf(stderr, "Reading %zd samples test data...", st.st_size/sizeof(float));
- size_t nread = 0;
+ ssize_t nread = 0;
while (nread < st.st_size) {
- ssize_t rc = read(fd, buf, st.st_size - nread);
+ ssize_t rc = read(fd, buf + nread, st.st_size - nread);
if (rc == -EINTR || rc == -EAGAIN)
continue;
@@ -100,5 +100,7 @@ int main(int argc, char **argv) {
printf("%09zd %12f\n", i, res);
}
+ free(buf);
+ free(sim_adc_buf);
return 0;
}
diff --git a/controller/fw/tools/presig_gen.py b/controller/fw/tools/presig_gen.py
index ff9dffe..3f85522 100644
--- a/controller/fw/tools/presig_gen.py
+++ b/controller/fw/tools/presig_gen.py
@@ -123,17 +123,17 @@ if __name__ == '__main__':
auth_parser.add_argument('height', type=int, help='Authentication string height, counting from 0 (root key)')
auth_parser.set_defaults(func=auth_cmd)
auth_parser.add_argument('-a', '--all', action='store_const', const='all', help='Vendor name for vendor domain')
- auth_parser.add_argument('-v', '--vendor', type=str, nargs='?', const=test_vendor, help='Vendor name for vendor domain')
- auth_parser.add_argument('-s', '--series', type=str, nargs='?', const=test_series, help='Series identifier for series domain')
- auth_parser.add_argument('-r', '--region', type=str, nargs='?', const=test_region, help='Region name for region domain')
- auth_parser.add_argument('-c', '--country', type=str, nargs='?', const=test_country, help='Country name for country domain')
+ auth_parser.add_argument('-v', '--vendor', type=str, nargs='?', const=TEST_VENDOR, help='Vendor name for vendor domain')
+ auth_parser.add_argument('-s', '--series', type=str, nargs='?', const=TEST_SERIES, help='Series identifier for series domain')
+ auth_parser.add_argument('-r', '--region', type=str, nargs='?', const=TEST_REGION, help='Region name for region domain')
+ auth_parser.add_argument('-c', '--country', type=str, nargs='?', const=TEST_COUNTRY, help='Country name for country domain')
prekey_parser = subparsers.add_parser('prekey', help='Generate prekey data .C source code file')
prekey_parser.add_argument('-m', '--max-height', type=int, default=8, help='Height of generated prekey')
- prekey_parser.add_argument('-v', '--vendor', type=str, default=test_vendor, help='Vendor name for vendor domain')
- prekey_parser.add_argument('-s', '--series', type=str, default=test_series, help='Series identifier for series domain')
- prekey_parser.add_argument('-r', '--region', type=str, default=test_region, help='Region name for region domain')
- prekey_parser.add_argument('-c', '--country', type=str, default=test_country, help='Country name for country domain')
+ prekey_parser.add_argument('-v', '--vendor', type=str, default=TEST_VENDOR, help='Vendor name for vendor domain')
+ prekey_parser.add_argument('-s', '--series', type=str, default=TEST_SERIES, help='Series identifier for series domain')
+ prekey_parser.add_argument('-r', '--region', type=str, default=TEST_REGION, help='Region name for region domain')
+ prekey_parser.add_argument('-c', '--country', type=str, default=TEST_COUNTRY, help='Country name for country domain')
prekey_parser.set_defaults(func=prekey_cmd, all='all')
args = parser.parse_args()