slip.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef SLIP_H__
  13. #define SLIP_H__
  14. #include <stdint.h>
  15. #include "app_fifo.h"
  16. /** @file
  17. *
  18. * @defgroup slip SLIP encoding decoding
  19. * @{
  20. * @ingroup app_common
  21. *
  22. * @brief This module encodes and decodes slip packages (RFC1055).
  23. *
  24. * @details The standard is described in https://tools.ietf.org/html/rfc1055
  25. */
  26. typedef enum {
  27. SLIP_DECODING,
  28. SLIP_END_RECEIVED,
  29. SLIP_ESC_RECEIVED,
  30. SLIP_CLEARING_INVALID_PACKET,
  31. } slip_state_t;
  32. typedef struct {
  33. uint8_t * p_buffer;
  34. uint32_t current_index;
  35. uint32_t current_length;
  36. uint32_t len;
  37. } buffer_t;
  38. /**@brief Encodes a slip packet.
  39. *
  40. * @details Note that the encoded output data will be longer than the input data.
  41. *
  42. * @retval The length of the encoded packet. If it is smaller than the input length, an error has occurred.
  43. */
  44. uint32_t slip_encode(uint8_t * p_output, uint8_t * p_input, uint32_t input_length, uint32_t output_buffer_length);
  45. /**@brief Decodes a slip packet.
  46. *
  47. * @details When decoding a slip packet, a state must be preserved. Initial state must be set to SLIP_DECODING.
  48. *
  49. * @retval NRF_SUCCESS when a packet is parsed. The length of the packet can be read out from p_buf->current_index
  50. * @retval NRF_ERROR_BUSY when packet is not finished parsing
  51. * @retval NRF_ERROR_INVALID_DATA when packet is encoded wrong.
  52. This moves the decoding to SLIP_CLEARING_INVALID_PACKET, and will stay in this state until SLIP_END is encountered.
  53. */
  54. uint32_t slip_decoding_add_char(uint8_t c, buffer_t * p_buf, slip_state_t * current_state);
  55. #endif // SLIP_H__
  56. /** @} */