From 5fd91e7ce10136d7f9e60a95195c858f9027a03c Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Thu, 27 Feb 2020 09:40:41 -0800 Subject: [PATCH] remove dated code that will be moved to own repo --- test/lora32/Makefile | 8 - test/lora32/components/esp32-lora | 1 - .../components/esp32-uart-cmdr/Makefile | 18 -- .../components/esp32-uart-cmdr/component.mk | 5 - .../esp32-uart-cmdr/include/esp32-uart-cmdr.h | 19 -- .../components/esp32-uart-cmdr/main/cmdr.c | 44 --- .../esp32-uart-cmdr/main/esp32_uart_cmdr.c | 52 ---- .../components/esp32-uart-cmdr/string-util.c | 28 -- .../components/esp32-uart-cmdr/string-util.h | 7 - .../components/esp32-uart-cmdr/test/test.c | 140 --------- test/lora32/main/component.mk | 4 - test/lora32/main/main.c | 201 ------------ test/lora32/sdkconfig.defaults | 2 - test/test.js | 285 ------------------ 14 files changed, 814 deletions(-) delete mode 100644 test/lora32/Makefile delete mode 120000 test/lora32/components/esp32-lora delete mode 100644 test/lora32/components/esp32-uart-cmdr/Makefile delete mode 100644 test/lora32/components/esp32-uart-cmdr/component.mk delete mode 100644 test/lora32/components/esp32-uart-cmdr/include/esp32-uart-cmdr.h delete mode 100644 test/lora32/components/esp32-uart-cmdr/main/cmdr.c delete mode 100644 test/lora32/components/esp32-uart-cmdr/main/esp32_uart_cmdr.c delete mode 100644 test/lora32/components/esp32-uart-cmdr/string-util.c delete mode 100644 test/lora32/components/esp32-uart-cmdr/string-util.h delete mode 100644 test/lora32/components/esp32-uart-cmdr/test/test.c delete mode 100644 test/lora32/main/component.mk delete mode 100644 test/lora32/main/main.c delete mode 100644 test/lora32/sdkconfig.defaults delete mode 100644 test/test.js diff --git a/test/lora32/Makefile b/test/lora32/Makefile deleted file mode 100644 index 1528d1f..0000000 --- a/test/lora32/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# -# This is a project Makefile. It is assumed the directory this Makefile resides in is a -# project subdirectory. -# - -PROJECT_NAME := lora32 - -include $(IDF_PATH)/make/project.mk diff --git a/test/lora32/components/esp32-lora b/test/lora32/components/esp32-lora deleted file mode 120000 index 1b20c9f..0000000 --- a/test/lora32/components/esp32-lora +++ /dev/null @@ -1 +0,0 @@ -../../../ \ No newline at end of file diff --git a/test/lora32/components/esp32-uart-cmdr/Makefile b/test/lora32/components/esp32-uart-cmdr/Makefile deleted file mode 100644 index 9eed097..0000000 --- a/test/lora32/components/esp32-uart-cmdr/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -CC=gcc -src := $(wildcard *.c) test/test.c main/cmdr.c -obj = $(src:.c=.o) - -CFLAGS=-I. -Iinclude -std=gnu99 -Og -ggdb -Wall -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration -LDFLAGS = -Wno-error=unused-but-set-variable -lcheck -lsubunit -pthread -pthread -lrt -lm -lsubunit -ggdb -Og - -all: tst - -test.o: - $(CC) -o $@ *.o $(CFLAGS) $(LDFLAGS) - -tst: $(obj) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) - -.PHONY: clean -clean: - rm -f $(obj) tst diff --git a/test/lora32/components/esp32-uart-cmdr/component.mk b/test/lora32/components/esp32-uart-cmdr/component.mk deleted file mode 100644 index 9475402..0000000 --- a/test/lora32/components/esp32-uart-cmdr/component.mk +++ /dev/null @@ -1,5 +0,0 @@ -COMPONENT_SRCDIRS := main -COMPONENT_ADD_INCLUDEDIRS := main include -COMPONENT_ADD_LDFLAGS := -lesp32-uart-cmdr - -COMPONENT_EXTRA_CLEAN := diff --git a/test/lora32/components/esp32-uart-cmdr/include/esp32-uart-cmdr.h b/test/lora32/components/esp32-uart-cmdr/include/esp32-uart-cmdr.h deleted file mode 100644 index 745ebc6..0000000 --- a/test/lora32/components/esp32-uart-cmdr/include/esp32-uart-cmdr.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __UART_CMDR_H__ -#define __UART_CMDR_H__ -#include -#include -#include -#include - -static volatile uint8_t cmd_count; - -typedef struct Cmd { - char *cmd; - void (*callback)(void *p); -}; - -void ucmdr_init(); -uint8_t ucmdr_install(char *cmd, void(*callback)(void *p)); -uint8_t ucmdr_match(char *str, struct Cmd **handler); - -#endif diff --git a/test/lora32/components/esp32-uart-cmdr/main/cmdr.c b/test/lora32/components/esp32-uart-cmdr/main/cmdr.c deleted file mode 100644 index 36839c3..0000000 --- a/test/lora32/components/esp32-uart-cmdr/main/cmdr.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include - -#include "esp32-uart-cmdr.h" - -#define MAX_COMMANDS (10) - -static struct Cmd cmd_list[MAX_COMMANDS]; -static volatile uint8_t cmd_count = 0; - -uint8_t ucmdr_install(char *cmd, void(*callback)(void *p)) { - //printf("installing: %s\n", cmd); - cmd_list[cmd_count].cmd = cmd; - cmd_list[cmd_count].callback = callback; - - //printf("cmd_count: %d\n", cmd_count); - ++cmd_count; - //printf("cmd_count: %d\n", cmd_count); - - return cmd_count; -}; - -uint8_t ucmdr_match(char *str, struct Cmd **handler) { - uint8_t i = 0; - - //printf("Checking against %d handlers\n", cmd_count); - - for(; i < cmd_count; i++) { - //printf("checking %s\n", (const char*)cmd_list[i].cmd); - - if(strstr(str, (const char*)cmd_list[i].cmd) != NULL) { - *handler = &cmd_list[i]; - - return 1; - } - } - - return 0; -}; - -void ucmdr_init() { - bzero(&cmd_list, sizeof(cmd_list)); - cmd_count = 0; -}; diff --git a/test/lora32/components/esp32-uart-cmdr/main/esp32_uart_cmdr.c b/test/lora32/components/esp32-uart-cmdr/main/esp32_uart_cmdr.c deleted file mode 100644 index 1103e0c..0000000 --- a/test/lora32/components/esp32-uart-cmdr/main/esp32_uart_cmdr.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "driver/uart.h" -#include "esp_log.h" - -static const char *TAG = "uart_cmdr"; -static QueueHandle_t uart0_queue; - -#define BUF_SIZE (1024) -#define RD_BUF_SIZE (BUF_SIZE) - -static void uart_event_task(void *pvParameters) { - uart_event_t event; - uint8_t *dtmp = (uint8_t*) malloc(RD_BUF_SIZE); - uint8_t size = 0; - - bzero(dtmp, RD_BUF_SIZE); - - for(;;) { - //Waiting for UART event. - if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) { - switch(event.type) { - case UART_DATA: - uart_read_bytes(UART_NUM_0, dtmp + size, event.size, portMAX_DELAY); - //uart_write_bytes(UART_NUM_0, (const char*) dtmp + size, event.size); - - size += event.size; - - if(dtmp[size - 1] == '\n' || dtmp[size - 1] == '\r') { - //uart_write_bytes(UART_NUM_0, (const char*) dtmp, size); - - bzero(dtmp, RD_BUF_SIZE); - } - - break; - - case UART_BREAK: - case UART_BUFFER_FULL: - case UART_FIFO_OVF: - case UART_FRAME_ERR: - case UART_PARITY_ERR: - case UART_DATA_BREAK: - case UART_PATTERN_DET: - case UART_EVENT_MAX: - break; - } - } - } -} diff --git a/test/lora32/components/esp32-uart-cmdr/string-util.c b/test/lora32/components/esp32-uart-cmdr/string-util.c deleted file mode 100644 index 67ac8a8..0000000 --- a/test/lora32/components/esp32-uart-cmdr/string-util.c +++ /dev/null @@ -1,28 +0,0 @@ -void trim_leading(char *str) { - char *i = str; - char *j = str; - - while(*j != 0) - if(*++j != ' ') break; - - while(*j != 0) - *i++ = *j++; - - *i = 0; -} - -void trim_multi(char *str) { - char *i = str; - char *j = str; - - while(*j != 0) { - *i = *j++; - - if( - (*j != ' ') || - (*j == ' ' && *(j - 1) != ' ') - ) i++; - } - - *i = 0; -} diff --git a/test/lora32/components/esp32-uart-cmdr/string-util.h b/test/lora32/components/esp32-uart-cmdr/string-util.h deleted file mode 100644 index d49ded2..0000000 --- a/test/lora32/components/esp32-uart-cmdr/string-util.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __STRING_UTIL_H -#define __STRING_UTIL_H - -void trim_leading(char *str); -void trim_multi(char *str); - -#endif diff --git a/test/lora32/components/esp32-uart-cmdr/test/test.c b/test/lora32/components/esp32-uart-cmdr/test/test.c deleted file mode 100644 index 070116d..0000000 --- a/test/lora32/components/esp32-uart-cmdr/test/test.c +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include -#include - -#include "string-util.h" -#include "esp32-uart-cmdr.h" - -START_TEST(leading) -{ - char str[] = " I had a leading space"; - trim_leading(str); - - ck_assert_str_eq(str, "I had a leading space"); -} -END_TEST - -START_TEST(multi) -{ - char str[] = " I had a leading space "; - trim_multi(str); - - ck_assert_str_eq(str, " I had a leading space "); -} -END_TEST - -uint8_t cb_count = 0; -static int8_t count = 0; -void inc(void *p) { - ++count; - ++cb_count; -} - -void set(void *p) { - count = (int8_t)p; -} - -void down(void *p) { - --count; - ++cb_count; -} - -START_TEST(install) { - uint8_t cnt = ucmdr_install("inc", inc); - - ck_assert_uint_eq(cnt, 1); - - cnt = ucmdr_install("down", down); - - ck_assert_uint_eq(cnt, 2); -} -END_TEST - -START_TEST(match) { - struct Cmd *handler; - - bool matched = ucmdr_match("inc", &handler); - ck_assert_uint_eq(matched, 1); - - printf("caling callback\n"); - handler->callback((void*)1); - - return; - ck_assert_uint_eq(cb_count, 1); - ck_assert_uint_eq(count, 1); - - ucmdr_match("down", &handler); - - handler->callback((void*)1); - - ck_assert_uint_eq(cb_count, 2); - ck_assert_uint_eq(count, 0); -} -END_TEST - -START_TEST(args) { - uint8_t cnt = ucmdr_install("set", set); - - ck_assert_uint_eq(cnt, 3); - - struct Cmd *handler; - - ucmdr_match("set", &handler); - - handler->callback((void*)42); - - ck_assert_uint_eq(count, 42); -} -END_TEST - -START_TEST(nomatch) { - struct Cmd *handler; - - uint8_t match = ucmdr_match("nomatch", &handler); - - ck_assert_uint_eq(match, 0); -} -END_TEST - -Suite* suite_string(void) -{ - Suite* s; - TCase* tc_str; - TCase* tc_cmdr; - s = suite_create("CMDR Test Suite"); - - tc_str = tcase_create("String utils"); - tcase_add_test(tc_str, leading); - tcase_add_test(tc_str, multi); - - tc_cmdr = tcase_create("CMDR"); - tcase_add_test(tc_cmdr, install); - tcase_add_test(tc_cmdr, nomatch); - tcase_add_test(tc_cmdr, match); - tcase_add_test(tc_cmdr, args); - - suite_add_tcase(s, tc_str); - suite_add_tcase(s, tc_cmdr); - - return s; -} - -int main(void) -{ - int number_failed; - SRunner* sr; - - ucmdr_init(); - - Suite* s_string = suite_string(); - - sr = srunner_create(s_string); - - srunner_set_fork_status(sr, CK_NOFORK); - srunner_run_all(sr, CK_VERBOSE); - - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/test/lora32/main/component.mk b/test/lora32/main/component.mk deleted file mode 100644 index a98f634..0000000 --- a/test/lora32/main/component.mk +++ /dev/null @@ -1,4 +0,0 @@ -# -# "main" pseudo-component makefile. -# -# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) diff --git a/test/lora32/main/main.c b/test/lora32/main/main.c deleted file mode 100644 index 815ea09..0000000 --- a/test/lora32/main/main.c +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/**************************************************************************** - * - * This file is for gatt server. It can send adv data, be connected by clent. - * Run the gatt_client demo, the client demo will automatically connect to the gatt_server demo. - * Client demo will enable gatt_server's notify after connection. Then two devices will exchange - * data. - * - ****************************************************************************/ - - -#include -#include -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/event_groups.h" -#include "driver/uart.h" -#include "esp_system.h" -#include "esp_log.h" -#include "nvs_flash.h" -#include "sdkconfig.h" -#include "esp32-lora.h" -#include "esp32-uart-cmdr.h" - -#define TAG "LORA32" -#define BUF_SIZE (1024) -#define RD_BUF_SIZE (BUF_SIZE) -#define EX_UART_NUM UART_NUM_0 - -uint8_t data_available = 0; -static lora32_cfg_t lora; -static QueueHandle_t uart0_queue; - -static void uart_event_task(void *pvParameters) { - uart_event_t event; - uint8_t *dtmp = (uint8_t*) malloc(RD_BUF_SIZE); - uint8_t size = 0; - - bzero(dtmp, RD_BUF_SIZE); - - for(;;) { - //Waiting for UART event. - if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) { - switch(event.type) { - case UART_DATA: - uart_read_bytes(UART_NUM_0, dtmp + size, event.size, portMAX_DELAY); - //uart_write_bytes(UART_NUM_0, (const char*) dtmp + size, event.size); - - size += event.size; - - if(dtmp[size - 1] == '\n' || dtmp[size - 1] == '\r') { - uart_write_bytes(UART_NUM_0, (const char*) dtmp, size); - - struct Cmd *handler; - uint8_t match = ucmdr_match((char *)dtmp, &handler); - - ESP_LOGD(TAG, "command size: %d", strlen(handler->cmd)); - - if(match) { - handler->callback(dtmp + strlen(handler->cmd)); - } else { - printf("command not found\n"); - } - - bzero(dtmp, RD_BUF_SIZE); - size = 0; - } - - break; - - case UART_BREAK: - case UART_BUFFER_FULL: - case UART_FIFO_OVF: - case UART_FRAME_ERR: - case UART_PARITY_ERR: - case UART_DATA_BREAK: - case UART_PATTERN_DET: - case UART_EVENT_MAX: - break; - } - } - } -} - -static void handle_lora_receive(uint8_t *data, uint8_t size) { - uint8_t j; - - ESP_LOGI(TAG, "received: " LOG_RESET_COLOR "%s", data+13); - - for(uint8_t i = 0; i < size; i += 16) { - for(j = 0; j < 16; j++) { - printf("%02X ", data[i + j]); - } - - printf("\n"); - } -} - -void loop(void *p) { - ESP_LOGI(TAG, "starting main loop"); - - while(true) { - vTaskDelay(100 / portTICK_PERIOD_MS); - } -} - -void dump_mem() { - lora32_dump_regs(&lora); -} - -void set_mode(void *args) { - int mode = atoi(args); - ESP_LOGI(TAG, "mode: %d", mode); - - if(mode == 1) { - } -} - -void send(void *args) { - ESP_LOGI(TAG, "sending: %s", (char*)args); - - lora32_send(&lora, (uint8_t *)args, strlen(args)); - - ESP_LOGI(TAG, "done"); -}; - -void set_spreadfactor(void *args) { - uint32_t sf = atoi(args); - - printf("spreadfactor: %d\n", sf); - - lora32_set_spreadfactor(&lora, sf); -} - -void set_coderate(void *args) { - uint8_t cr = atoi(args); - - printf("coding rate: %d\n", cr); - - lora32_set_coding_rate(&lora, cr); -} - -void app_main() { - esp_err_t ret; - - // Initialize NVS. - ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - ESP_ERROR_CHECK( ret ); - - xTaskCreate(&loop, "loop", 2048, NULL, 6, NULL); - - lora = lora32_create(); - //lora.frequency = frequencies[F915]; - lora.receive = &handle_lora_receive; - //lora.poll_rx = true; - - lora32_init(&lora); - //lora32_set_spreadfactor(&lora, 12); - - lora32_dump_regs(&lora); - - ucmdr_init(); - ucmdr_install("send", send); - ucmdr_install("dump", dump_mem); - ucmdr_install("sf", set_spreadfactor); - ucmdr_install("cr", set_coderate); - - uart_config_t uart_config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE - }; - uart_param_config(EX_UART_NUM, &uart_config); - - esp_log_level_set(TAG, ESP_LOG_INFO); - uart_set_pin(EX_UART_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0); - - //Create a task to handler UART event from ISR - xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, 12, NULL); -}; diff --git a/test/lora32/sdkconfig.defaults b/test/lora32/sdkconfig.defaults deleted file mode 100644 index 5cf195f..0000000 --- a/test/lora32/sdkconfig.defaults +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ESP32_XTAL_FREQ_26=y -CONFIG_ESP32_XTAL_FREQ=26 diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 30c9ead..0000000 --- a/test/test.js +++ /dev/null @@ -1,285 +0,0 @@ -var async = require("async"); -var esptool = require("esptool-wrapper"); -var homedir = require("homedir")(); -var spawn = require("child_process").spawn; -var SerialPort = require("serialport"); -var path = require("path"); -var test = require("tape"); -var testbed = require("testbed-query-fixtures"); - -const buildPath = path.join(__dirname, "lora32", "build"); - -try { - var testbedConfig = require(path.join(homedir, ".testbed.json")); -} catch(e) { - console.log(e); - console.error("testbed.json fixture file not found."); - - process.exit(1); -} - -var devices = testbed({ - f: [ "esp32", "lora" ], - fixtures: testbedConfig.fixtures -}); - -if(devices.length < 2) { - throw new Error("Not enough test devices available"); -} - -const TB_DEV1 = devices[0].DEVNAME; -const TB_DEV2 = devices[1].DEVNAME; - -var testBins = { - 0x1000: path.join(buildPath, "bootloader/bootloader.bin"), - 0x8000: path.join(buildPath, "partitions_singleapp.bin"), - 0x10000: path.join(buildPath, "lora32.bin") -}; - -function flash(port, cb) { - var argsReset = [ - "--before", - "default_reset", - "--after", - "hard_reset" - ]; - - var argsWriteFlash = [ - "-z", - "--flash_mode", - "dio", - "--flash_freq", - "40m", - "--flash_size", - "detect" - ]; - - console.log("Flashing devices at %s", port); - - esptool({ - port: port, - baud: 460800, - files: testBins, - args: argsReset, - cmdArgs: argsWriteFlash - }, cb); -} - -function toggleReset(sp) { - sp.set({ - dtr: false - }, function() { - setTimeout(function() { - sp.set({ - dtr: true - }); - }, 1000); - }); -} - -function serial(port, cb) { - var to = -1; - var buf = ""; - var sp = new SerialPort(port, { - baudRate: 115200 - }); - - sp.once("open", function() { - console.log("port open %s", port); - - sp.on("data", onData); - - toggleReset(sp); - }); - - function done(reason) { - console.log("%s ready%s", port, reason || ""); - - cb(null, sp); - sp.removeListener("data", onData); - } - - function onData(chunk) { - buf += chunk.toString(); - - clearTimeout(to); - - to = setTimeout(function() { - done(" (timeout)"); - }, 3000); - - if(buf.indexOf("set_spread") !== -1) { - clearTimeout(to); - done(" (got set_spreadfactor)"); - } - } -} - -async.series([ - function(next) { - if(process.env.NOFLASH) { - - return next(null); - } - - async.parallel([ - function(done) { - flash(TB_DEV1, done); - }, function(done) { - flash(TB_DEV2, done); - }], next); - }, - - function(next) { - async.parallel({ - dev1: function(done) { - serial(TB_DEV1, done); - }, - - dev2: function(done) { - serial(TB_DEV2, done); - } - }, next); - } -], function(err, results) { - var ports = results[1]; - - console.log("init done"); - - var buf = ""; - var message = "test"; - - test.onFinish(function() { - console.log("Cleaning up"); - - ports.dev1.close(); - ports.dev2.close(); - }); - - test(function(t) { - t.plan(1); - - ports.dev1.on("data", function onData(chunk) { - //process.stdout.write(chunk); - - buf += chunk.toString(); - - if(buf.indexOf(`msg: ${message}`) !== -1) { - ports.dev1.removeListener("data", onData); - - t.pass("got round-trip message!"); - } - }); - - ports.dev2.on("data", function(chunk) { - //process.stdout.write(chunk); - }); - - ports.dev2.write(`send${message}\n`); - }, "round-trip message"); - - test(function(t) { - t.plan(2); - - var sf = 9; - var msg = `sf${sf}\n`; - - testSetSpreadFactor(ports.dev1); - testSetSpreadFactor(ports.dev2); - - function testSetSpreadFactor(port) { - var buf = ""; - - port.on("data", function onData(c) { - buf += c.toString(); - - if(buf.indexOf(`spreadfactor: ${sf}`) !== -1) { - t.pass("spreadfactor set"); - port.removeListener("data", onData); - } - }); - - port.write(msg); - }; - }, "set spreadfactor"); - - test(function(t) { - t.plan(4); - - var i = 0; - - async.doWhilst(function(done) { - var write = ports["dev" + (1 + i % 2)]; - var read = ports["dev" + (1 + (i + 1) % 2)]; - - var buf = ""; - var msg = `tick${i}`; - - read.on("data", onData); - - write.write(`send${msg}\n`); - - function onData(c) { - buf += c.toString(); - - if(buf.indexOf(msg) !== -1) { - t.pass((i % 2 === 0 ? ">" : "<") + " got message " + i); - - read.removeListener("data", onData); - - done(null); - } - } - }, function() { - return i++ < 3; - }) - }, "exchange"); - - test(function(t) { - t.plan(2); - - var cr = 7; - var msg = `cr${cr}\n`; - - testSetCodingRate(ports.dev1); - testSetCodingRate(ports.dev2); - - function testSetCodingRate(port) { - var buf = ""; - - port.on("data", function onData(c) { - buf += c.toString(); - - if(buf.indexOf(`coding rate: ${cr}`) !== -1) { - t.pass("coding factor set"); - - port.removeListener("data", onData); - } - }); - - port.write(msg); - }; - }, "set coding rate"); - - test(function(t) { - t.plan(1); - - ports.dev1.on("data", function onData(chunk) { - //process.stdout.write(chunk); - - buf += chunk.toString(); - - if(buf.indexOf(`msg: ${message}`) !== -1) { - ports.dev1.removeListener("data", onData); - - t.pass("got round-trip message!"); - } - }); - - ports.dev2.on("data", function(chunk) { - //process.stdout.write(chunk); - }); - - ports.dev2.write(`send${message}\n`); - }, "round-trip message"); -});