From 7ce755d6664b489336f39d1f11717192a5c26ca9 Mon Sep 17 00:00:00 2001 From: cho45 Date: Fri, 23 Aug 2019 02:22:42 +0900 Subject: [PATCH] optimize protocol of capture function --- main.c | 8 ++++---- python/nanovna.py | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index ae0c100..f18d7dc 100644 --- a/main.c +++ b/main.c @@ -403,17 +403,17 @@ static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[]) int i; ili9341_read_memory(0, 0, 320, 240, PART, buf); for (i = 0; i < PART; i++) { - chprintf(chp, "%04x ", buf[i]); + streamPut(chp, buf[i] >> 8); + streamPut(chp, buf[i] & 0xff); } - chprintf(chp, "\r\n"); len -= PART; while (len > 0) { ili9341_read_memory_continue(PART, buf); for (i = 0; i < PART; i++) { - chprintf(chp, "%04x ", buf[i]); + streamPut(chp, buf[i] >> 8); + streamPut(chp, buf[i] & 0xff); } - chprintf(chp, "\r\n"); len -= PART; } //*/ diff --git a/python/nanovna.py b/python/nanovna.py index aa6eb79..aa70ef8 100755 --- a/python/nanovna.py +++ b/python/nanovna.py @@ -4,6 +4,7 @@ import numpy as np import pylab as pl import scipy.signal as signal import time +import struct REF_LEVEL = (1<<9) @@ -191,11 +192,8 @@ class NanoVNA(): def capture(self): from PIL import Image self.send_command("capture\r") - data = self.fetch_data() - x = [] - for line in data.split('\n'): - if line: - x.extend([int(d, 16) for d in line.strip().split(' ')]) + b = self.serial.read(320 * 240 * 2) + x = struct.unpack(">76800H", b) # convert pixel format from 565(RGB) to 8888(RGBA) arr = np.array(x, dtype=np.uint32) arr = 0xFF000000 + ((arr & 0xF800) >> 8) + ((arr & 0x07E0) << 5) + ((arr & 0x001F) << 19)