From b489a1b12f2f574ed24237601b3797b58d302196 Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 27 Feb 2020 14:39:18 +0100 Subject: Add a bunch of deps --- .gitmodules | 9 ++ controller/fw/Makefile | 108 +++++++++------- controller/fw/cmsis | 1 + controller/fw/libsodium | 1 + controller/fw/main.c | 76 ------------ controller/fw/mspdebug_wrapper.c | 207 ------------------------------- controller/fw/mspdebug_wrapper.h | 6 - controller/fw/spi_flash.c | 189 ---------------------------- controller/fw/spi_flash.h | 31 ----- controller/fw/sr_global.h | 8 -- controller/fw/tinyaes | 1 + lab-windows/grid_frequency_spectra.ipynb | 141 ++++++++++++++------- lab-windows/grid_scope.ipynb | 30 ++++- 13 files changed, 192 insertions(+), 616 deletions(-) create mode 160000 controller/fw/cmsis create mode 160000 controller/fw/libsodium delete mode 100644 controller/fw/main.c delete mode 100644 controller/fw/mspdebug_wrapper.c delete mode 100644 controller/fw/mspdebug_wrapper.h delete mode 100644 controller/fw/spi_flash.c delete mode 100644 controller/fw/spi_flash.h delete mode 100644 controller/fw/sr_global.h create mode 160000 controller/fw/tinyaes diff --git a/.gitmodules b/.gitmodules index dee64b1..9560dfb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,12 @@ [submodule "controller/fw/mspdebug"] path = controller/fw/mspdebug url = https://github.com/dlbeer/mspdebug +[submodule "controller/fw/cmsis"] + path = controller/fw/cmsis + url = https://github.com/ARM-software/CMSIS_5 +[submodule "controller/fw/libsodium"] + path = controller/fw/libsodium + url = https://github.com/jedisct1/libsodium +[submodule "controller/fw/tinyaes"] + path = controller/fw/tinyaes + url = https://github.com/kokke/tiny-AES-c diff --git a/controller/fw/Makefile b/controller/fw/Makefile index 52951b1..9895c87 100644 --- a/controller/fw/Makefile +++ b/controller/fw/Makefile @@ -1,13 +1,23 @@ -SOURCES := main.c mspdebug_wrapper.c spi_flash.c -SOURCES += mspdebug/drivers/jtaglib.c +OPENCM3_DIR ?= libopencm3 +CMSIS_DIR ?= cmsis +MSPDEBUG_DIR ?= mspdebug +LIBSODIUM_DIR ?= libsodium +TINYAES_DIR ?= tinyaes +MUSL_DIR ?= musl + +C_SOURCES := src/main.c src/mspdebug_wrapper.c src/spi_flash.c +C_SOURCES += $(MSPDEBUG_DIR)/drivers/jtaglib.c +C_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_rfft_f32.c +C_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_bitreversal.c +C_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_cfft_radix4_f32.c + +CXX_SOURCES += src/ldpc_wrapper.cpp BUILDDIR ?= build BINARY := safetyreset LDSCRIPT := stm32f407.ld -LIBNAME := opencm3_stm32f4 - -OPENCM3_DIR ?= libopencm3 +OPENCM3_LIB := opencm3_stm32f4 PREFIX ?= arm-none-eabi- @@ -21,73 +31,79 @@ OBJCOPY := $(PREFIX)objcopy OBJDUMP := $(PREFIX)objdump GDB := $(PREFIX)gdb +OPENCM3_DIR := $(abspath $(OPENCM3_DIR)) +CMSIS_DIR := $(abspath $(CMSIS_DIR)) +MSPDEBUG_DIR := $(abspath $(MSPDEBUG_DIR)) +LIBSODIUM_DIR := $(abspath $(LIBSODIUM_DIR)) +TINYAES_DIR := $(abspath $(TINYAES_DIR)) +MUSL_DIR := $(abspath $(MUSL_DIR)) CFLAGS += -I$(OPENCM3_DIR)/include -Imspdebug/util -Imspdebug/drivers +CFLAGS += -I$(CMSIS_DIR)/CMSIS/DSP/Include -I$(CMSIS_DIR)/CMSIS/Core/Include CFLAGS += -Os -std=gnu11 -g -DSTM32F4 # Note: libopencm3 requires some standard libc definitions from stdint.h and stdbool.h, so we don't pass -nostdinc here. CFLAGS += -nostdlib -ffreestanding -CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g -CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration -Wundef -CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes +CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 CFLAGS += -fno-common -ffunction-sections -fdata-sections +INT_CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration -Wundef +INT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes + +CXXFLAGS += -Os -g +CXXFLAGS += -nostdlib -ffreestanding +CXXFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 +CXXFLAGS += -fno-common -ffunction-sections -fdata-sections +CXXFLAGS += -Wextra -Wshadow -Wundef -Wredundant-decls +CXXFLAGS += -I. + LDFLAGS += --static -nostartfiles LDFLAGS += -T$(LDSCRIPT) LDFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g LDFLAGS += -Wl,--cre #LDFLAGS += -Wl,--gc-sections LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group -LDFLAGS += -L$(OPENCM3_DIR)/lib -LDFLAGS += -l$(LIBNAME) $(shell $(CC) -print-libgcc-file-name) +LDFLAGS += -L$(OPENCM3_DIR)/lib -l$(OPENCM3_LIB) $(shell $(CC) -print-libgcc-file-name) -all: elf +all: $(BUILDDIR)/$(BINARY).elf -elf: $(BUILDDIR)/$(BINARY).elf -bin: $(BUILDDIR)/$(BINARY).bin -hex: $(BUILDDIR)/$(BINARY).hex -srec: $(BUILDDIR)/$(BINARY).srec -list: $(BUILDDIR)/$(BINARY).list +OBJS := $(addprefix $(BUILDDIR)/,$(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o)) -images: $(BUILDDIR)/$(BINARY).images -$(OPENCM3_DIR)/lib/lib$(LIBNAME).a: - echo "Warning, $@ not found, attempting to rebuild in $(OPENCM3_DIR)" - $(MAKE) -C $(OPENCM3_DIR) +$(BUILDDIR)/%.elf: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(OPENCM3_LIB).a $(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a $(BUILDDIR)/tinyaes/aes.o $(BUILDDIR)/musl/lib/libc.a + $(LD) $(OBJS) $(LDFLAGS) -o $@ -Wl,-Map=$(BUILDDIR)/src/$*.map $(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a $(BUILDDIR)/tinyaes/aes.o -OBJS := $(addprefix $(BUILDDIR)/,$(SOURCES:%.c=%.o)) +$(BUILDDIR)/src/%.o: src/%.c + mkdir -p $(@D) + $(CC) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $< -# Define a helper macro for debugging make errors online -# you can type "make print-OPENCM3_DIR" and it will show you -# how that ended up being resolved by all of the included -# makefiles. -print-%: - @echo $*=$($*) +$(BUILDDIR)/src/%.o: src/%.cpp + mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -o $@ -c $< -$(BUILDDIR)/%.images: $(BUILDDIR)/%.bin $(BUILDDIR)/%.hex $(BUILDDIR)/%.srec $(BUILDDIR)/%.list $(BUILDDIR)/%.map - -$(BUILDDIR)/%.bin: $(BUILDDIR)/%.elf - $(OBJCOPY) -Obinary $< $@ - -$(BUILDDIR)/%.hex: $(BUILDDIR)/%.elf - $(OBJCOPY) -Oihex $< $@ - -$(BUILDDIR)/%.srec: $(BUILDDIR)/%.elf - $(OBJCOPY) -Osrec $< $@ +$(BUILDDIR)/%.o: %.c + mkdir -p $(@D) + $(CC) $(CFLAGS) $(EXT_CFLAGS) -o $@ -c $< -$(BUILDDIR)/%.list: $(BUILDDIR)/%.elf - $(OBJDUMP) -S $< > $@ +$(OPENCM3_DIR)/lib/lib$(OPENCM3_LIB).a: + $(MAKE) -C $(OPENCM3_DIR) -j $(shell nproc) -$(BUILDDIR)/%.elf: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(LIBNAME).a - $(LD) $(OBJS) $(LDFLAGS) -o $@ -Wl,-Map=$*.map +$(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a: + mkdir -p build/libsodium + cd build/libsodium && CFLAGS="$(CFLAGS) -DDEV_MODE=1" $(LIBSODIUM_DIR)/configure --host=arm-none-eabi && $(MAKE) -j $(shell nproc) -$(BUILDDIR)/%.o: %.c - mkdir -p $(dir $@) - $(CC) $(CFLAGS) -o $@ -c $< +$(BUILDDIR)/tinyaes/aes.o: + mkdir -p $(@D) + make -C $(@D) -f $(TINYAES_DIR)/Makefile VPATH=$(TINYAES_DIR) CFLAGS="$(CFLAGS) -c" CC=$(CC) LD=$(LD) AR=$(AR) aes.o clean: - -rm -r $(BUILDDIR) + -rm -r $(BUILDDIR)/src + -rm $(BUILDDIR)/$(BINARY).elf + +mrproper: clean + -rm -r build + -$(MAKE) -C $(OPENCM3_DIR) clean -.PHONY: images clean elf bin hex srec list +.PHONY: clean mrproper -include $(OBJS:.o=.d) diff --git a/controller/fw/cmsis b/controller/fw/cmsis new file mode 160000 index 0000000..02c242d --- /dev/null +++ b/controller/fw/cmsis @@ -0,0 +1 @@ +Subproject commit 02c242de0606a46de29c8deb30954bcf2e9389c3 diff --git a/controller/fw/libsodium b/controller/fw/libsodium new file mode 160000 index 0000000..afae623 --- /dev/null +++ b/controller/fw/libsodium @@ -0,0 +1 @@ +Subproject commit afae623190f025e7cf2fb0222bfe796b69a36941 diff --git a/controller/fw/main.c b/controller/fw/main.c deleted file mode 100644 index 3131df1..0000000 --- a/controller/fw/main.c +++ /dev/null @@ -1,76 +0,0 @@ - -#include - -#include -#include -#include - -#include "spi_flash.h" - -static struct spi_flash_if spif; - -static void clock_setup(void) -{ - rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); - rcc_periph_clock_enable(RCC_GPIOA); - rcc_periph_clock_enable(RCC_GPIOB); - rcc_periph_clock_enable(RCC_SPI1); -} - -static void led_setup(void) -{ - gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6 | GPIO7); -} - -static void spi_flash_if_set_cs(bool val) { - if (val) - gpio_set(GPIOB, GPIO0); - else - gpio_clear(GPIOB, GPIO0); -} - -static void spi_flash_setup(void) -{ - gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3 | GPIO4 | GPIO5); /* SPI flash SCK/MISO/MOSI */ - gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO0); /* SPI flash CS */ - gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO0 | GPIO3 | GPIO4 | GPIO5); - gpio_set_af(GPIOB, 5, GPIO3 | GPIO4 | GPIO5); - - spif_init(&spif, 256, SPI1, &spi_flash_if_set_cs); -} - -/* -void spi_flash_test(void) { - spif_clear_mem(&spif); - - uint32_t buf[1024]; - for (size_t addr=0; addr<0x10000; addr += sizeof(buf)) { - for (size_t i=0; i -#include - -#include - -#include "output.h" -#include "jtaglib.h" - -#include "sr_global.h" -#include "mspdebug_wrapper.h" - -#define BLOCK_SIZE 512 /* bytes */ - - -static struct jtdev sr_jtdev; - - -int flash_and_reset(size_t img_start, size_t img_len, ssize_t (*read_block)(int addr, size_t len, uint8_t *out)) -{ - union { - uint8_t bytes[BLOCK_SIZE]; - uint16_t words[BLOCK_SIZE/2]; - } block; - - /* Initialize JTAG connection */ - unsigned int jtag_id = jtag_init(&sr_jtdev); - - if (sr_jtdev.failed) - return -EPIPE; - - if (jtag_id != 0x89 && jtag_id != 0x91) - return -EINVAL; - - /* Clear flash */ - jtag_erase_flash(&sr_jtdev, JTAG_ERASE_MAIN, 0); - if (sr_jtdev.failed) - return -EPIPE; - - /* Write flash */ - for (size_t p = img_start; p < img_start + img_len; p += BLOCK_SIZE) { - ssize_t nin = read_block(p, BLOCK_SIZE, block.bytes); - - if (nin < 0) - return nin; - - if (nin & 1) { /* pad unaligned */ - block.bytes[nin] = 0; - nin ++; - } - - /* Convert to little-endian */ - for (ssize_t i=0; i - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "spi_flash.h" -#include - -enum { - WRITE_ENABLE = 0x06, - WRITE_DISABLE = 0x04, - READ_IDENTIFICATION = 0x9F, - READ_STATUS = 0x05, - WRITE_STATUS = 0x01, - READ_DATA = 0x03, - READ_DATA_FAST = 0x0B, - PAGE_PROGRAM = 0x02, - SECTOR_ERASE = 0xD8, - BULK_ERASE = 0xC7, - DEEP_POWER_DOWN = 0xB9, - DEEP_POWER_DOWN_RELEASE = 0xAB, -}; - -enum { - STATUS_SRWD = 0x80, // 0b 1000 0000 - STATUS_BP2 = 0x10, // 0b 0001 0000 - STATUS_BP1 = 0x08, // 0b 0000 1000 - STATUS_BP0 = 0x04, // 0b 0000 0100 - STATUS_WEL = 0x02, // 0b 0000 0010 - STATUS_WIP = 0x01, // 0b 0000 0001 -}; - - -static void spif_write_page(struct spi_flash_if *spif, size_t addr, size_t len, const char* data); -static uint8_t spif_read_status(struct spi_flash_if *spif); -static void spif_enable_write(struct spi_flash_if *spif); -static void spif_wait_for_write(struct spi_flash_if *spif); - -#define low_byte(x) (x&0xff) -#define mid_byte(x) ((x>>8)&0xff) -#define high_byte(x) ((x>>16)&0xff) - - -void spif_init(struct spi_flash_if *spif, size_t page_size, uint32_t spi_base, void (*cs)(bool val)) { - - spif->spi_base = spi_base; - spif->page_size = page_size; - spif->cs = cs; - spif->cs(1); - - spi_reset(spif->spi_base); - spi_init_master(spif->spi_base, - SPI_CR1_BAUDRATE_FPCLK_DIV_2, - SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE, - SPI_CR1_CPHA_CLK_TRANSITION_2, - SPI_CR1_DFF_8BIT, - SPI_CR1_MSBFIRST); - - spi_enable_software_slave_management(spif->spi_base); - spi_set_nss_high(spif->spi_base); - - spi_enable(spif->spi_base); - - spif->cs(0); - spi_send(spif->spi_base, READ_IDENTIFICATION); - spif->id.mfg_id = spi_xfer(spif->spi_base, 0); - spif->id.type = spi_xfer(spif->spi_base, 0); - spif->id.size = 1<spi_base, 0); - spif->cs(1); -} - -void spif_read(struct spi_flash_if *spif, size_t addr, size_t len, char* data) { - spif_enable_write(spif); - - spif->cs(0); - spi_xfer(spif->spi_base, READ_DATA); - spi_xfer(spif->spi_base, high_byte(addr)); - spi_xfer(spif->spi_base, mid_byte(addr)); - spi_xfer(spif->spi_base, low_byte(addr)); - - for (size_t i = 0; i < len; i++) - data[i] = spi_xfer(spif->spi_base, 0); - - spif->cs(1); -} - -void spif_write(struct spi_flash_if *spif, size_t addr, size_t len, const char* data) { - size_t written = 0, write_size = 0; - - while (written < len) { - write_size = spif->page_size - ((addr + written) % spif->page_size); - if (written + write_size > len) - write_size = len - written; - - spif_write_page(spif, addr + written, write_size, data + written); - written += write_size; - } -} - -static uint8_t spif_read_status(struct spi_flash_if *spif) { - spif->cs(0); - spi_xfer(spif->spi_base, READ_STATUS); - uint8_t status = spi_xfer(spif->spi_base, 0); - spif->cs(1); - - return status; -} - -void spif_clear_sector(struct spi_flash_if *spif, size_t addr) { - spif_enable_write(spif); - - spif->cs(0); - spi_xfer(spif->spi_base, SECTOR_ERASE); - spi_xfer(spif->spi_base, high_byte(addr)); - spi_xfer(spif->spi_base, mid_byte(addr)); - spi_xfer(spif->spi_base, low_byte(addr)); - spif->cs(1); - - spif_wait_for_write(spif); -} - -void spif_clear_mem(struct spi_flash_if *spif) { - spif_enable_write(spif); - - spif->cs(0); - spi_xfer(spif->spi_base, BULK_ERASE); - spif->cs(1); - - spif_wait_for_write(spif); -} - -static void spif_write_page(struct spi_flash_if *spif, size_t addr, size_t len, const char* data) { - spif_enable_write(spif); - - spif->cs(0); - spi_xfer(spif->spi_base, PAGE_PROGRAM); - spi_xfer(spif->spi_base, high_byte(addr)); - spi_xfer(spif->spi_base, mid_byte(addr)); - spi_xfer(spif->spi_base, low_byte(addr)); - - for (size_t i = 0; i < len; i++) { - spi_xfer(spif->spi_base, data[i]); - } - - spif->cs(1); - spif_wait_for_write(spif); -} - -static void spif_enable_write(struct spi_flash_if *spif) { - spif->cs(0); - spi_xfer(spif->spi_base, WRITE_ENABLE); - spif->cs(1); -} - -static void spif_wait_for_write(struct spi_flash_if *spif) { - while (spif_read_status(spif) & STATUS_WIP) - for (int i = 0; i < 800; i++) - ; -} - -void spif_deep_power_down(struct spi_flash_if *spif) { - spif->cs(0); - spi_xfer(spif->spi_base, DEEP_POWER_DOWN); - spif->cs(1); -} - -void spif_wakeup(struct spi_flash_if *spif) { - spif->cs(0); - spi_xfer(spif->spi_base, DEEP_POWER_DOWN_RELEASE); - spif->cs(1); -} diff --git a/controller/fw/spi_flash.h b/controller/fw/spi_flash.h deleted file mode 100644 index e647c6a..0000000 --- a/controller/fw/spi_flash.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __SPI_FLASH_H__ -#define __SPI_FLASH_H__ - -#include -#include - -struct spi_mem_id { - size_t size; - uint8_t mfg_id; - uint8_t type; -}; - -struct spi_flash_if { - struct spi_mem_id id; - uint32_t spi_base; - size_t page_size; - void (*cs)(bool val); -}; - -void spif_init(struct spi_flash_if *spif, size_t page_size, uint32_t spi_base, void (*cs)(bool val)); - -void spif_write(struct spi_flash_if *spif, size_t addr, size_t len, const char* data); -void spif_read(struct spi_flash_if *spif, size_t addr, size_t len, char* data); - -void spif_clear_mem(struct spi_flash_if *spif); -void spif_clear_sector(struct spi_flash_if *spif, size_t addr); - -void spif_deep_power_down(struct spi_flash_if *spif); -void spif_wakeup(struct spi_flash_if *spif); - -#endif /* __SPI_FLASH_H__ */ diff --git a/controller/fw/sr_global.h b/controller/fw/sr_global.h deleted file mode 100644 index 8aa219d..0000000 --- a/controller/fw/sr_global.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __SR_GLOBAL_H__ -#define __SR_GLOBAL_H__ - -#define UNUSED(x) ((void) x) - -static inline uint16_t htole(uint16_t val) { return val; } - -#endif /* __SR_GLOBAL_H__ */ diff --git a/controller/fw/tinyaes b/controller/fw/tinyaes new file mode 160000 index 0000000..3fe133f --- /dev/null +++ b/controller/fw/tinyaes @@ -0,0 +1 @@ +Subproject commit 3fe133ffa32606b0d0d81e0ba1d8bacb392eb7e9 diff --git a/lab-windows/grid_frequency_spectra.ipynb b/lab-windows/grid_frequency_spectra.ipynb index 7b187f5..75d3cf9 100644 --- a/lab-windows/grid_frequency_spectra.ipynb +++ b/lab-windows/grid_frequency_spectra.ipynb @@ -33,13 +33,13 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "36f1f4d7970e41afa4737b6f63b7c449", + "model_id": "45cbf0c7c4314a3386adf52c261b1505", "version_major": 2, "version_minor": 0 }, @@ -53,10 +53,10 @@ { "data": { "text/plain": [ - "[]" + "[]" ] }, - "execution_count": 9, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -77,7 +77,7 @@ "0.02051102806199375" ] }, - "execution_count": 10, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -88,13 +88,13 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d7fe0512f4254efeb15235a5617ef064", + "model_id": "125cd5cc3ac44df5885f2c82cfa80c11", "version_major": 2, "version_minor": 0 }, @@ -111,7 +111,7 @@ "(1e-06, 0.5)" ] }, - "execution_count": 16, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -141,21 +141,13 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 11, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":20: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n", - " fig, ax = plt.subplots()\n" - ] - }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2991d932b113496a9135d569f9577abe", + "model_id": "65216e331e154ee980d16ae5de7fbfcd", "version_major": 2, "version_minor": 0 }, @@ -172,7 +164,7 @@ "(5e-07, 0.02)" ] }, - "execution_count": 72, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -214,25 +206,22 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "object of type cannot be safely interpreted as an integer.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m~/safety-reset/lab-windows/env/lib/python3.8/site-packages/numpy/core/function_base.py\u001b[0m in \u001b[0;36mlinspace\u001b[0;34m(start, stop, num, endpoint, retstep, dtype, axis)\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 117\u001b[0;31m \u001b[0mnum\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0moperator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 118\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypeError\u001b[0m: 'float' object cannot be interpreted as an integer", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mys\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvolve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mys\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mones\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'valid'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mxs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinspace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1.0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m2.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;31m#xs = np.linspace(len(data)/2, 1, len(data)/2)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m<__array_function__ internals>\u001b[0m in \u001b[0;36mlinspace\u001b[0;34m(*args, **kwargs)\u001b[0m\n", - "\u001b[0;32m~/safety-reset/lab-windows/env/lib/python3.8/site-packages/numpy/core/function_base.py\u001b[0m in \u001b[0;36mlinspace\u001b[0;34m(start, stop, num, endpoint, retstep, dtype, axis)\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[0mnum\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0moperator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 119\u001b[0;31m raise TypeError(\n\u001b[0m\u001b[1;32m 120\u001b[0m \u001b[0;34m\"object of type {} cannot be safely interpreted as an integer.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 121\u001b[0m .format(type(num)))\n", - "\u001b[0;31mTypeError\u001b[0m: object of type cannot be safely interpreted as an integer." - ] + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d5721ab27d01416fb7fce8449b5d2289", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -242,7 +231,7 @@ "\n", "ys = np.convolve(ys, np.ones((s,))/s, mode='valid')\n", "\n", - "xs = np.linspace(0, 1.0/2.0, len(data)/2)\n", + "xs = np.linspace(0, 1.0/2.0, len(data)//2)\n", "#xs = np.linspace(len(data)/2, 1, len(data)/2)\n", "\n", "fig, ax = plt.subplots()\n", @@ -253,9 +242,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c419327f1f4f43c1903d3817d4651241", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "ys = scipy.fftpack.fft(data[:,0])\n", "ys = 2.0/len(data) * np.abs(ys[:len(data)//2])\n", @@ -263,7 +267,7 @@ "\n", "ys = np.convolve(ys, np.ones((s,))/s, mode='valid')\n", "\n", - "xs = np.linspace(0, 1.0/2.0, len(data)/2)\n", + "xs = np.linspace(0, 1.0/2.0, len(data)//2)\n", "#xs = np.linspace(len(data)/2, 1, len(data)/2)\n", "\n", "fig, ax = plt.subplots()\n", @@ -274,9 +278,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "7c1941babb2e4d0c951d060fa9a4ba78", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "ys = scipy.fftpack.fft(data[:,0])\n", "ys = 2.0/len(data) * np.abs(ys[:len(data)//2])\n", @@ -284,7 +303,7 @@ "\n", "ys = np.convolve(ys, np.ones((s,))/s, mode='valid')\n", "\n", - "xs = np.linspace(0, 1.0/2.0, len(data)/2)\n", + "xs = np.linspace(0, 1.0/2.0, len(data)//2)\n", "\n", "ys *= 2*np.pi*xs\n", "#xs = np.linspace(len(data)/2, 1, len(data)/2)\n", @@ -297,9 +316,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6034b96d5f08488a84d94b82cf319047", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "ys = scipy.fftpack.fft(data[:,0])\n", "ys = 2.0/len(data) * np.abs(ys[:len(data)//2])\n", @@ -307,7 +341,7 @@ "\n", "ys = np.convolve(ys, np.ones((s,))/s, mode='valid')\n", "\n", - "xs = np.linspace(0, 1.0/2.0, len(data)/2)\n", + "xs = np.linspace(0, 1.0/2.0, len(data)//2)\n", "\n", "ys *= 2*np.pi*xs[s//2:-s//2+1]\n", "\n", @@ -322,9 +356,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "15.923566878980893" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1/0.0628" ] diff --git a/lab-windows/grid_scope.ipynb b/lab-windows/grid_scope.ipynb index 6ce34fb..3b0b3bc 100644 --- a/lab-windows/grid_scope.ipynb +++ b/lab-windows/grid_scope.ipynb @@ -48,7 +48,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Run 000: 2020-01-31 18:05:24 - 2020-02-01 00:13:45 ( 6:08:21.589, 22126080sp)\n" + "Run 000: 2020-01-31 19:05:24 - 2020-02-01 01:13:45 ( 6:08:21.589, 22126080sp)\n" ] } ], @@ -100,7 +100,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "55690b4f59d54454b83deb5200c05f09", + "model_id": "e612fe37a7c34ceaa77e8bc587b8e065", "version_major": 2, "version_minor": 0 }, @@ -177,7 +177,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "cf5c2e35008740379508eaaedfcf3b31", + "model_id": "f8fa09f5053c4c52866ef240c789e741", "version_major": 2, "version_minor": 0 }, @@ -238,6 +238,26 @@ " nfft = window_len * nfft_factor)" ] }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(200.0, 800.0)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "window_len, window_len * nfft_factor" + ] + }, { "cell_type": "code", "execution_count": 10, @@ -246,7 +266,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "efa9db02cdfc4f6c86d1eadd4769d097", + "model_id": "e8e8458ea5914a939c7188785efd286c", "version_major": 2, "version_minor": 0 }, @@ -279,7 +299,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e4122530c1444f75aca410ad51d4a733", + "model_id": "875deca2c3d84e069dd0a5eaef4ea0aa", "version_major": 2, "version_minor": 0 }, -- cgit