2 // Product: Serial Command/Response library for QPnano
4 // Date: 25 November 2010
6 // +-----------------------+
7 // | d e c i s i o n s |
8 // +-----------------------|
9 // | a n d d e s i g n s |
10 // +-----------------------+
12 // Copyright (C) 2010 Decisions and Designs Pty Ltd. All rights reserved.
14 // This software may be distributed and modified under the terms of the GNU
15 // General Public License version 2 (GPL) as published by the Free Software
16 // Foundation and appearing in the file GPL.TXT included in the packaging of
17 // this file. Please note that GPL Section 2[b] requires that all works based
18 // on this software must also be made publicly available under the terms of
19 // the GPL ("Copyleft").
21 // Contact information:
22 // Decisions and Designs Web site: http://www.decisions-and-designs.com.au
26 #ifndef serial_command_h
27 #define serial_command_h
31 // This Serial command parser and response transmitter is based on Samek's
32 // implementation of the Orthoganol Component state pattern (see PSiC/C++,
33 // Second Ed., Section 5.4). The serial parser could have been built as a
34 // library that maintains state for the parser attached to each serial port
35 // but the Orthagonal Component approach is intended to allow reuse of this
36 // machine with minimal support code in the container HSM. BSP driver code
37 // is passed the container HSM address for delivery of the received serial
38 // characters and the Serial component is passed function pointers to the
39 // serial transmission services in the BSP driver. When Serial parses a
40 // serial command (and optional arguments) it delivers a signal for that
41 // command (asynchronously) to the container's queue. The container can
42 // access the arguments and perform some action in response.
45 /* Serial I/O class (public to allow access to VArgs by a container class) */
47 typedef uint8_t (*SerialTransmit)(uint8_t ch);
48 typedef void (*SerialTransmitComplete)(void);
51 // #define PACKED_VARGS 1 /* disallow leading argument spaces */
52 #define VARG_COUNT 4 /* there are four two bit ids in the uint8_t */
53 #define VARG_TYPE 0x3 /* right shifted varg type mask */
58 #define VARG_NEGATIVE 0x80
61 /* VArg number processor errors */
70 typedef struct varg_s {
80 typedef struct MenuTag {
85 typedef struct MenuSignalTag {
90 typedef struct SerialCommandTag {
93 SerialTransmit serialTransmit;
94 SerialTransmitComplete serialTransmitComplete;
97 MenuSignal *menuSignals;
98 VArg vargs[VARG_COUNT];
107 /* Services available to the container class for SerialCommand */
109 #define SerialCommand_init(S) QHsm_init((QHsm *)(S))
\r
111 void SerialCommand_ctor(SerialCommand *me, QActive *container, Menu *menu,
112 MenuSignal *menuSignals, char *txBuffer, uint8_t txSize,
\r
113 uint8_t port, uint32_t baud);
115 void serialDispatch(SerialCommand *me, QSignal sig, QParam par);
117 /* If a command accepted more than one varg then the container must release
118 the vargs when that signal has been processed. If not, SerialCommand will
119 fail subsequent commands when the need to refill the vargs is reached */
120 void serialReleaseVargs(SerialCommand *me);
122 /* Print data to the serial transmitter */
123 void serialDumpArgs(SerialCommand *me);
124 void serialChar(SerialCommand *me, char c);
125 void serialStr(SerialCommand *me, char *s);
126 void serialUnum(SerialCommand *me, uint32_t v);
127 void serialNum(SerialCommand *me, int32_t v);
128 void serialDbl(SerialCommand *me, double number, uint8_t digits);
129 void serialNACK(SerialCommand *me, uint8_t unused);
130 void serialACK(SerialCommand *me, uint8_t only);
132 #endif /* serial_command_h */