Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 8999db3dc -> b98fe7095
finished serial server example for ocf To replicate, create two targets targets/ocf_server_ser app=@apache-mynewt-core/apps/ocf_sample bsp=@apache-mynewt-core/hw/bsp/native build_profile=debug cflags=-DOC_SERVER -DOC_TRANSPORT_SERIAL targets/ocf_client_ser app=@apache-mynewt-core/apps/ocf_sample bsp=@apache-mynewt-core/hw/bsp/native build_profile=debug cflags=-DOC_CLIENT -DOC_TRANSPORT_SERIAL Run them (via the debugger) and use socat to connect their serial ports socat -x /dev/ttys004,raw,echo=0 /dev/ttys006,raw,echo=0 You should see the client discover the server and then request obsevations on the client. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f5df33ce Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f5df33ce Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f5df33ce Branch: refs/heads/develop Commit: f5df33ce1bd069c72431342ed096a6415ad06f1a Parents: 8999db3 Author: Paul Dietrich <paulfdietr...@yahoo.com> Authored: Wed Sep 21 16:56:45 2016 -0700 Committer: Paul Dietrich <paulfdietr...@yahoo.com> Committed: Mon Sep 26 10:40:17 2016 -0700 ---------------------------------------------------------------------- apps/ocf_sample/src/main.c | 8 +++++++- libs/console/full/include/console/prompt.h | 2 ++ libs/console/full/src/cons_tty.c | 1 + libs/console/full/src/prompt.c | 10 +++++++++- libs/iotivity/src/port/mynewt/serial_adaptor.c | 16 ++++++++++++---- 5 files changed, 31 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/apps/ocf_sample/src/main.c ---------------------------------------------------------------------- diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c index 78846d2..ebe9988 100644 --- a/apps/ocf_sample/src/main.c +++ b/apps/ocf_sample/src/main.c @@ -20,6 +20,7 @@ #include <os/os.h> #include <bsp/bsp.h> #include <console/console.h> +#include <console/prompt.h> #include <shell/shell.h> #include <log/log.h> @@ -29,7 +30,7 @@ /* Shell */ #define SHELL_TASK_PRIO (8) -#define SHELL_MAX_INPUT_LEN (256) +#define SHELL_MAX_INPUT_LEN (512) #define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(2048)) static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE]; @@ -286,6 +287,11 @@ main(int argc, char **argv) rc = os_msys_register(&default_mbuf_pool); assert(rc == 0); +#ifdef OC_TRANSPORT_SERIAL + console_echo(0); + console_no_prompt(); +#endif + /* Init tasks */ rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE, SHELL_MAX_INPUT_LEN); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/console/full/include/console/prompt.h ---------------------------------------------------------------------- diff --git a/libs/console/full/include/console/prompt.h b/libs/console/full/include/console/prompt.h index f930879..849ec7e 100644 --- a/libs/console/full/include/console/prompt.h +++ b/libs/console/full/include/console/prompt.h @@ -28,4 +28,6 @@ void console_print_prompt(); /* set the console prompt character */ void console_set_prompt(char); +void console_no_prompt(void); + #endif /* __CONSOLE_PROMPT_H__ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/console/full/src/cons_tty.c ---------------------------------------------------------------------- diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c index db8c88e..412f93c 100644 --- a/libs/console/full/src/cons_tty.c +++ b/libs/console/full/src/cons_tty.c @@ -282,6 +282,7 @@ console_rx_char(void *arg, uint8_t data) /* echo */ switch (data) { case '\r': + break; case '\n': /* * linefeed http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/console/full/src/prompt.c ---------------------------------------------------------------------- diff --git a/libs/console/full/src/prompt.c b/libs/console/full/src/prompt.c index 5a811bf..3806310 100644 --- a/libs/console/full/src/prompt.c +++ b/libs/console/full/src/prompt.c @@ -23,18 +23,26 @@ /* console prompt, always followed by a space */ static char console_prompt[] = " > "; +static char do_prompt = 1; /* set the prompt character, leave the space */ void console_set_prompt(char p) { + do_prompt = 1; console_prompt[1] = p; } +void console_no_prompt(void) { + do_prompt = 0; +} + /* print the prompt to the console */ void console_print_prompt(void) { - console_printf("%s", console_prompt); + if (do_prompt) { + console_printf("%s", console_prompt); + } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/iotivity/src/port/mynewt/serial_adaptor.c ---------------------------------------------------------------------- diff --git a/libs/iotivity/src/port/mynewt/serial_adaptor.c b/libs/iotivity/src/port/mynewt/serial_adaptor.c index ddca3bb..7fa94b3 100644 --- a/libs/iotivity/src/port/mynewt/serial_adaptor.c +++ b/libs/iotivity/src/port/mynewt/serial_adaptor.c @@ -54,6 +54,7 @@ oc_connectivity_init_serial(void) { } /* override the eventq type */ oc_serial_mqueue.mq_ev.ev_type = OC_ADATOR_EVENT_SERIAL; + return 0; err: oc_connectivity_shutdown_serial(); @@ -68,25 +69,27 @@ void oc_send_buffer_serial(oc_message_t *message) { /* get a packet header */ m = os_msys_get_pkthdr(0, 0); if (m == NULL) { + ERROR("oc_transport_serial: No mbuf available\n"); goto err; } /* add this data to the mbuf */ rc = os_mbuf_append(m, message->data, message->length); if (rc != 0) { + ERROR("oc_transport_serial: could not append data \n"); goto err; } /* send over the shell output */ rc = shell_nlip_output(m); if (rc != 0) { + ERROR("oc_transport_serial: nlip output failed \n"); goto err; } - return; + LOG("oc_transport_serial: send buffer %lu\n", message->length); - err: - ERROR("Unable to send message via oc_serial %d\n", rc); +err: oc_message_unref(message); return; @@ -103,8 +106,13 @@ oc_attempt_rx_serial(void) { /* get an mbuf from the queue */ m = os_mqueue_get(&oc_serial_mqueue); + if (NULL == m) { + ERROR("oc_transport_serial: Woke for for receive but found no mbufs\n"); + goto rx_attempt_err; + } if (!OS_MBUF_IS_PKTHDR(m)) { + ERROR("oc_transport_serial: received mbuf that wasn't a packet header\n"); goto rx_attempt_err; } @@ -150,4 +158,4 @@ rx_attempt_err: return NULL; } -#endif \ No newline at end of file +#endif