Subversion Repositories libSerial

Rev

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

  1. #pragma once
  2. #include "libSerial/serial.h"
  3.  
  4. #if defined __cplusplus
  5. extern "C"
  6. {
  7. #endif
  8.  
  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.  
  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.  
  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.  
  32. /// @brief Send a string to the user
  33. /// @param ctl Handle of usart
  34. /// @param string String to send
  35. /// @param length Length of string
  36. extern void sendString(struct usart_ctl *ctl, char const *string, int length);
  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.
  43. extern void initReadLine(editBuffer *context, char *buffer, int limit, char readLines);
  44.  
  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
  49. extern editBufferReturn readLine(struct usart_ctl *ctl, editBuffer *context);
  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);
  59.  
  60. #if defined __cplusplus
  61. }
  62. #endif
  63.