Subversion Repositories libSerial

Rev

Rev 14 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 mjames 1
#pragma once
2
#include "libSerial/serial.h"
3
 
15 mjames 4
#if defined __cplusplus
5
extern "C"
6
{
7
#endif
8
 
10 mjames 9
/// @brief storage for a string reader
10
typedef struct
11
{
12
    char *buffer;   // pointer to workspace
13
    int limit;      // string limit
14
    int counter;    // byte counter
15
    char complete;  // flag complete
16
    char readLines; // true if reading lines with CR at end
17
} editBuffer;
18
 
14 mjames 19
/// @brief Use this for the readlines parameter  if reading up to buffer length or using CR
20
static const char READLINES_CR = 1;
21
/// @brief Use this for the readlines parameter if reading up to buffer length
22
static const char READLINES_BIN = 0;
23
 
10 mjames 24
///
25
typedef enum
26
{
27
    EDIT_NULL = 0, ///< No result
28
    EDIT_DONE,     ///< All characters read
29
    EDIT_CR        ///< Characters up to CR read
30
} editBufferReturn;
31
 
11 mjames 32
/// @brief Send a string to the user
13 mjames 33
/// @param ctl Handle of usart 
34
/// @param string String to send 
35
/// @param length Length of string 
15 mjames 36
extern void sendString(struct usart_ctl *ctl, char const *string, int length);
11 mjames 37
 
38
/// @brief Prepare the line buffer reader
39
/// @param context editBuffer object to initialise
40
/// @param buffer  Pointer to data: externally allocated memory buffer.
41
/// @param limit   Maximum number of bytes in externally allocated memory buffer.
42
/// @param readLines if 1 then we are reading text with <CR> as line terminator, control codes ignored.
10 mjames 43
extern void initReadLine(editBuffer *context, char *buffer, int limit, char readLines);
44
 
11 mjames 45
/// @brief Poll the line buffer reader
46
/// @param ctl   pointer to a USART control structure
47
/// @param context pointer to the editBuffer context
48
/// @return what kind of state the buffer is now in
15 mjames 49
extern editBufferReturn readLine(struct usart_ctl *ctl, editBuffer *context);
14 mjames 50
 
51
/// @brief Reset the state of the line buffer reader for the next command  
52
/// @param context editBuffer object to reset 
53
extern void resetInput(editBuffer * context);
54
 
55
/// @brief Return number of characters in context
56
/// @param context 
57
/// @return number of characters in the context  
58
extern int charCount(editBuffer * context);
15 mjames 59
 
60
#if defined __cplusplus
61
}
62
#endif