Skip to content

Commit

Permalink
Problem: Morse sequence isn't fully interruptible
Browse files Browse the repository at this point in the history
Solution: compile into intermediate code that's executed
step by step.
  • Loading branch information
hintjens committed Mar 8, 2016
1 parent a95910b commit 84ee2d6
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 156 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ IF (ENABLE_DRAFTS)
list(APPEND glar_headers
include/glar_node.h
include/glar_panel.h
include/glar_lamp.h
include/glar_morse.h
)
ENDIF (ENABLE_DRAFTS)

Expand All @@ -138,7 +138,7 @@ IF (ENABLE_DRAFTS)
list (APPEND glar_sources
src/glar_node.c
src/glar_panel.c
src/glar_lamp.c
src/glar_morse.c
)
ENDIF (ENABLE_DRAFTS)

Expand Down Expand Up @@ -235,7 +235,7 @@ IF (ENABLE_DRAFTS)
list (APPEND TEST_CLASSES
glar_node
glar_panel
glar_lamp
glar_morse
)
ENDIF (ENABLE_DRAFTS)

Expand Down
6 changes: 3 additions & 3 deletions doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Please refer to the README for information about making permanent changes. #
################################################################################
MAN1 = glard.1
MAN3 = glar_node.3 glar_panel.3 glar_lamp.3
MAN3 = glar_node.3 glar_panel.3 glar_morse.3
MAN7 = glar150.7
MAN_DOC = $(MAN1) $(MAN3) $(MAN7)

Expand Down Expand Up @@ -38,13 +38,13 @@ glar_node.txt:
./mkman $@
glar_panel.txt:
./mkman $@
glar_lamp.txt:
glar_morse.txt:
./mkman $@
glard.txt:
./mkman $@
clean:
rm -f *.1 *.3 *.7
./mkman glar_node glar_panel glar_lamp glard
./mkman glar_node glar_panel glar_morse glard
endif
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
Expand Down
43 changes: 43 additions & 0 deletions doc/glar_morse.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#### glar_morse - Morse lamp controller

Converts a character string to Morse code on the lamp. Spaces are turned
into word spaces. If a new command arrives, it will always interrupt the
existing command. Ending the string with "*" causes it to repeat until
interrupted.

Please add @discuss section in ../src/glar_morse.c.

This is the class interface:

// Create new glar_morse actor instance.
// @TODO: Describe the purpose of this actor!
//
// zactor_t *glar_morse = zactor_new (glar_morse, NULL);
//
// Destroy glar_morse instance.
//
// zactor_destroy (&glar_morse);
//
// Enable verbose logging of commands and activity:
//
// zstr_send (glar_morse, "VERBOSE");
// zsock_wait (glar_morse);
//
// This is the glar_morse constructor as a zactor_fn;
GLAR_EXPORT void
glar_morse_actor (zsock_t *pipe, void *args);

// Self test of this actor
GLAR_EXPORT void
glar_morse_test (bool verbose);

This is the class self test code:

zactor_t *glar_morse = zactor_new (glar_morse_actor, NULL);
if (verbose)
zstr_send (glar_morse, "VERBOSE");
zstr_send (glar_morse, "SOS*");
zclock_sleep (2000);
zstr_send (glar_morse, "K");
zactor_destroy (&glar_morse);

55 changes: 55 additions & 0 deletions doc/glar_morse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
glar_morse(3)
=============

NAME
----
glar_morse - Morse lamp controller

SYNOPSIS
--------
----
// Create new glar_morse actor instance.
// @TODO: Describe the purpose of this actor!
//
// zactor_t *glar_morse = zactor_new (glar_morse, NULL);
//
// Destroy glar_morse instance.
//
// zactor_destroy (&glar_morse);
//
// Enable verbose logging of commands and activity:
//
// zstr_send (glar_morse, "VERBOSE");
// zsock_wait (glar_morse);
//
// This is the glar_morse constructor as a zactor_fn;
GLAR_EXPORT void
glar_morse_actor (zsock_t *pipe, void *args);

// Self test of this actor
GLAR_EXPORT void
glar_morse_test (bool verbose);
----

DESCRIPTION
-----------

Converts a character string to Morse code on the lamp. Spaces are turned
into word spaces. If a new command arrives, it will always interrupt the
existing command. Ending the string with "*" causes it to repeat until
interrupted.

Please add @discuss section in ../src/glar_morse.c.

EXAMPLE
-------
.From glar_morse_test method
----
zactor_t *glar_morse = zactor_new (glar_morse_actor, NULL);
if (verbose)
zstr_send (glar_morse, "VERBOSE");
zstr_send (glar_morse, "SOS*");
zclock_sleep (2000);
zstr_send (glar_morse, "K");
zactor_destroy (&glar_morse);
----
6 changes: 3 additions & 3 deletions include/glar_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ typedef struct _glar_node_t glar_node_t;
#define GLAR_NODE_T_DEFINED
typedef struct _glar_panel_t glar_panel_t;
#define GLAR_PANEL_T_DEFINED
typedef struct _glar_lamp_t glar_lamp_t;
#define GLAR_LAMP_T_DEFINED
typedef struct _glar_morse_t glar_morse_t;
#define GLAR_MORSE_T_DEFINED
#endif // GLAR_BUILD_DRAFT_API


// Public classes, each with its own header file
#ifdef GLAR_BUILD_DRAFT_API
#include "glar_node.h"
#include "glar_panel.h"
#include "glar_lamp.h"
#include "glar_morse.h"
#endif // GLAR_BUILD_DRAFT_API

#endif
Expand Down
24 changes: 12 additions & 12 deletions include/glar_lamp.h → include/glar_morse.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* =========================================================================
glar_lamp - LED lamp controller
glar_morse - Morse lamp controller
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of the Glar150 Project.
Expand All @@ -10,36 +10,36 @@
=========================================================================
*/

#ifndef GLAR_LAMP_H_INCLUDED
#define GLAR_LAMP_H_INCLUDED
#ifndef GLAR_MORSE_H_INCLUDED
#define GLAR_MORSE_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif


// @interface
// Create new glar_lamp actor instance.
// Create new glar_morse actor instance.
// @TODO: Describe the purpose of this actor!
//
// zactor_t *glar_lamp = zactor_new (glar_lamp, NULL);
// zactor_t *glar_morse = zactor_new (glar_morse, NULL);
//
// Destroy glar_lamp instance.
// Destroy glar_morse instance.
//
// zactor_destroy (&glar_lamp);
// zactor_destroy (&glar_morse);
//
// Enable verbose logging of commands and activity:
//
// zstr_send (glar_lamp, "VERBOSE");
// zsock_wait (glar_lamp);
// zstr_send (glar_morse, "VERBOSE");
// zsock_wait (glar_morse);
//
// This is the glar_lamp constructor as a zactor_fn;
// This is the glar_morse constructor as a zactor_fn;
GLAR_EXPORT void
glar_lamp_actor (zsock_t *pipe, void *args);
glar_morse_actor (zsock_t *pipe, void *args);

// Self test of this actor
GLAR_EXPORT void
glar_lamp_test (bool verbose);
glar_morse_test (bool verbose);
// @end

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<actor name = "glar_panel">LED panel controller</actor>
<model name = "glar_panel">LED panel controller FSM</model>

<actor name = "glar_lamp">Lamp controller</actor>
<actor name = "glar_morse">Morse lamp controller</actor>

<extra name = "glard_init.sh" />
<extra name = "rc.local" />
Expand Down
4 changes: 2 additions & 2 deletions src/Makemodule.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if ENABLE_DRAFTS
include_HEADERS += \
include/glar_node.h \
include/glar_panel.h \
include/glar_lamp.h
include/glar_morse.h

endif
src_libglar_la_SOURCES = \
Expand All @@ -32,7 +32,7 @@ if ENABLE_DRAFTS
src_libglar_la_SOURCES += \
src/glar_node.c \
src/glar_panel.c \
src/glar_lamp.c
src/glar_morse.c

endif

Expand Down
42 changes: 0 additions & 42 deletions src/glar_lamp.h

This file was deleted.

Loading

0 comments on commit 84ee2d6

Please sign in to comment.