Revision ba516b61 os/core/inc/aos_shell.h

View differences:

os/core/inc/aos_shell.h
19 19
#ifndef _AMIROOS_SHELL_H_
20 20
#define _AMIROOS_SHELL_H_
21 21

  
22
#include <aosconf.h>
23
#if (AMIROOS_CFG_SHELL_ENABLE == true)
24

  
22 25
#include <hal.h>
23 26
#include <aos_types.h>
27
#include <aos_iostream.h>
24 28

  
25 29
/**
26 30
 * @brief   Shell event flag that is emitted when the thread starts.
27 31
 */
28
#define AOS_SHELL_EVTFLAG_START                 ((eventflags_t)(1 << 0))
32
#define AOS_SHELL_EVTFLAG_START                   ((eventflags_t)(1 << 0))
29 33

  
30 34
/**
31 35
 * @brief   Shell event flag that is emitted when a command is executed.
32 36
 */
33
#define AOS_SHELL_EVTFLAG_EXEC                  ((eventflags_t)(1 << 1))
37
#define AOS_SHELL_EVTFLAG_EXEC                    ((eventflags_t)(1 << 1))
34 38

  
35 39
/**
36 40
 * @brief   Shell event flag that is emitted when a command execution finished.
37 41
 */
38
#define AOS_SHELL_EVTFLAG_DONE                  ((eventflags_t)(1 << 2))
42
#define AOS_SHELL_EVTFLAG_DONE                    ((eventflags_t)(1 << 2))
39 43

  
40 44
/**
41 45
 * @brief   Shell event flag that is emitted when the shread stops.
42 46
 */
43
#define AOS_SHELL_EVTFLAG_EXIT                  ((eventflags_t)(1 << 3))
47
#define AOS_SHELL_EVTFLAG_EXIT                    ((eventflags_t)(1 << 3))
44 48

  
45 49
/**
46 50
 * @brief   Shell event flag that is emitted when an I/O error occurred.
47 51
 */
48
#define AOS_SHELL_EVTFLAG_IOERROR               ((eventflags_t)(1 << 4))
52
#define AOS_SHELL_EVTFLAG_IOERROR                 ((eventflags_t)(1 << 4))
49 53

  
50 54
/**
51 55
 * @brief   Shell input configuration for replacing content by user input.
52 56
 */
53
#define AOS_SHELL_CONFIG_INPUT_OVERWRITE        (1 << 0)
57
#define AOS_SHELL_CONFIG_INPUT_OVERWRITE          (1 << 0)
54 58

  
55 59
/**
56 60
 * @brief   Shell prompt configuration print a minimalistic prompt.
57 61
 */
58
#define AOS_SHELL_CONFIG_PROMPT_MINIMAL         (1 << 1)
62
#define AOS_SHELL_CONFIG_PROMPT_MINIMAL           (1 << 1)
59 63

  
60 64
/**
61 65
 * @brief   Shell prompt configuration to additionally print the system uptime with the prompt.
62 66
 */
63
#define AOS_SHELL_CONFIG_PROMPT_UPTIME          (1 << 2)
67
#define AOS_SHELL_CONFIG_PROMPT_UPTIME            (1 << 2)
64 68

  
65 69
/**
66 70
 * @brief   Shell prompt configuration to additionally print the system uptime with the prompt.
67 71
 */
68
#define AOS_SHELL_CONFIG_MATCH_CASE             (1 << 3)
72
#define AOS_SHELL_CONFIG_MATCH_CASE               (1 << 3)
73

  
74
/**
75
 * @brief   Shell I/O channel flag whether the channel is attached to a list.
76
 */
77
#define AOS_SHELLCHANNEL_ATTACHED                 (1 << 0)
78

  
79
/**
80
 * @brief   Shell I/O channel flag whether the channel is enabled as input.
81
 */
82
#define AOS_SHELLCHANNEL_INPUT_ENABLED            (1 << 1)
83

  
84
/**
85
 * @brief   Shell I/O channel flag whether the channel is enabled as output.
86
 */
87
#define AOS_SHELLCHANNEL_OUTPUT_ENABLED           (1 << 2)
88

  
89
/*
90
 * forward definitions
91
 */
92
typedef struct aos_shellchannel AosShellChannel;
93
typedef struct aos_shellstream AosShellStream;
94

  
95
/**
96
 * @brief   AosShellChannel specific methods.
97
 */
98
#define _aos_shell_channel_methods                                          \
99
  _base_asynchronous_channel_methods
100

  
101
/**
102
 * @brief   AosShellChannel specific data.
103
 */
104
#define _aos_shell_channel_data                                             \
105
  /* pointer to a AosIOChannel object */                                    \
106
  AosIOChannel* iochannel;                                                  \
107
  /* event listener for the associated BaseAsynchronousChannel */           \
108
  event_listener_t listener;                                                \
109
  /* pointer to the next chennal in a AosShellStream */                     \
110
  AosShellChannel* next;                                                    \
111
  /* flags related to the channel */                                        \
112
  uint8_t flags;
113

  
114
/**
115
 * @extends BaseAsynchronousChannelVMT
116
 *
117
 * @brief   AosShellChannel virtual methods table.
118
 */
119
struct AosShellChannelVMT {
120
  _aos_shell_channel_methods
121
};
122

  
123
/**
124
 * @extends BaseAsynchronousChannel
125
 *
126
 * @brief   Shell channel class.
127
 * @details This class implements an asynchronous I/O channel.
128
 */
129
struct aos_shellchannel {
130
  /** @brief Virtual Methods Table. */
131
  const struct AosShellChannelVMT* vmt;
132
  _aos_shell_channel_data
133
};
134

  
135
/**
136
 * @brief   AosShellStream methods.
137
 */
138
#define _aos_shellstream_methods                                            \
139
  _base_sequential_stream_methods
140

  
141
/**
142
 * @brief   AosShellStream data.
143
 */
144
#define _aos_shellstream_data                                               \
145
  /* Pointer to the first channel in a list. */                             \
146
  AosShellChannel* channel;
147

  
148
/**
149
 * @extends BaseSequentialStream
150
 *
151
 * @brief   AosShellStream virtual methods table.
152
 */
153
struct AosShellStreamVMT {
154
  _aos_shellstream_methods
155
};
156

  
157
/**
158
 * @extends BaseSequentialStream
159
 *
160
 * @brief   Shell Stream class.
161
 * @details This class implements an base sequential stream.
162
 * @todo    So far only output but no input is supported.
163
 */
164
struct aos_shellstream {
165
  const struct AosShellStreamVMT* vmt;
166
  _aos_shellstream_data
167
};
69 168

  
70 169
/**
71 170
 * @brief   Shell command calback type.
......
90 189
   * @brief   Pointer to next command in a singly linked list.
91 190
   */
92 191
  struct aos_shellcommand* next;
192

  
93 193
} aos_shellcommand_t;
94 194

  
95 195
/**
96 196
 * @brief   Execution status of a shell command.
97 197
 */
98 198
typedef struct aos_shellexecstatus {
99
  aos_shellcommand_t* command;  /**< Pointer to the command that was executed. */
100
  int retval;                   /**< Return value of the executed command. */
199
  /**
200
   * @brief   Pointer to the command that was executed.
201
   */
202
  aos_shellcommand_t* command;
203

  
204
  /**
205
   * @brief   Return value of the executed command.
206
   */
207
  int retval;
101 208
} aos_shellexecstatus_t;
102 209

  
103 210
/**
211
 * @brief   Enumerator to encode shell actions.
212
 */
213
typedef enum aos_shellaction {
214
  AOS_SHELL_ACTION_READCHAR,
215
  AOS_SHELL_ACTION_AUTOFILL,
216
  AOS_SHELL_ACTION_SUGGEST,
217
  AOS_SHELL_ACTION_INSERTTOGGLE,
218
  AOS_SHELL_ACTION_DELETEFORWARD,
219
  AOS_SHELL_ACTION_DELETEBACKWARD,
220
  AOS_SHELL_ACTION_RECALLLAST,
221
  AOS_SHELL_ACTION_CLEAR,
222
  AOS_SHELL_ACTION_CURSOR2START,
223
  AOS_SHELL_ACTION_CURSOR2END,
224
  AOS_SHELL_ACTION_CURSORLEFT,
225
  AOS_SHELL_ACTION_CURSORRIGHT,
226
  AOS_SHELL_ACTION_EXECUTE,
227
  AOS_SHELL_ACTION_ESCSTART,
228
  AOS_SHELL_ACTION_NONE,
229
} aos_shellaction_t;
230

  
231
/**
104 232
 * @brief   Shell structure.
105 233
 */
106 234
typedef struct aos_shell {
......
115 243
  event_source_t eventSource;
116 244

  
117 245
  /**
118
   * @brief   Stream for user I/O.
246
   * @brief   Struct for OS related events
119 247
   */
120
  BaseSequentialStream* stream;
248
  struct {
249
    /**
250
     * @brief   Pointer to the OS' event source.
251
     */
252
    event_source_t* eventSource;
253

  
254
    /**
255
     * @brief   Listener for OS related events.
256
     */
257
    event_listener_t eventListener;
258
  } os;
259

  
260
  /**
261
     * @brief   Pointer to the first I/O channel.
262
     */
263
  AosShellStream stream;
121 264

  
122 265
  /**
123 266
   * @brief   String to printed as prompt.
......
146 289
  size_t linesize;
147 290

  
148 291
  /**
292
   * @brief   Structure containing data for internal input parsing.
293
   */
294
  struct {
295
    /**
296
     * @brief   The last action executed by the shell.
297
     */
298
    aos_shellaction_t lastaction;
299

  
300
    /**
301
     * @brief   Number of character in the current escape sequence.
302
     */
303
    uint8_t escp;
304

  
305
    /**
306
     * @brief   Buffer to store an escape sequence.
307
     */
308
    char escseq[5];
309

  
310
    /**
311
     * @brief   Current curso position.
312
     */
313
    size_t cursorpos;
314

  
315
    /**
316
     * @brief   Current line width.
317
     */
318
    size_t lineend;
319

  
320
    /**
321
     * @brief   Flag whether there was input since the prompt was printed the last time.
322
     */
323
    bool noinput;
324
  } inputdata;
325

  
326
  /**
149 327
   * @brief   Argument buffer.
150 328
   */
151 329
  char** arglist;
......
164 342
#ifdef __cplusplus
165 343
extern "C" {
166 344
#endif
167
  void aosShellInit(aos_shell_t* shell, BaseSequentialStream* stream, const char* prompt, char* line, size_t linesize, char** arglist, size_t arglistsize);
345
  void aosShellInit(aos_shell_t* shell, event_source_t* oseventsource, const char* prompt, char* line, size_t linesize, char** arglist, size_t arglistsize);
346
  void aosShellStreamInit(AosShellStream* stream);
347
  void aosShellChannelInit(AosShellChannel* channel, AosIOChannel* iochannel);
168 348
  aos_status_t aosShellAddCommand(aos_shell_t* shell, aos_shellcommand_t* cmd);
169 349
  aos_status_t aosShellRemoveCommand(aos_shell_t* shell, char* cmd, aos_shellcommand_t** removed);
350
  void aosShellStreamAddChannel(AosShellStream* stream, AosShellChannel* channel);
351
  aos_status_t aosShellStreamRemoveChannel(AosShellStream* stream, AosShellChannel* channel);
352
  void aosShellChannelInputEnable(AosShellChannel* channel);
353
  void aosShellChannelInputDisable( AosShellChannel* channel);
354
  void aosShellChannelOutputEnable(AosShellChannel* channel);
355
  void aosShellChannelOutputDisable(AosShellChannel* channel);
170 356
  THD_FUNCTION(aosShellThread, shell);
171 357
#ifdef __cplusplus
172 358
}
173 359
#endif
174 360

  
361
#endif /* AMIROOS_CFG_SHELL_ENABLE == true */
362

  
175 363
#endif /* _AMIROOS_SHELL_H_ */

Also available in: Unified diff