encoder.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #include <lib/toolbox/level_duration.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef struct {
  10. bool is_running;
  11. size_t repeat;
  12. size_t front;
  13. size_t size_upload;
  14. LevelDuration* upload;
  15. } SubGhzProtocolBlockEncoder;
  16. typedef enum {
  17. SubGhzProtocolBlockAlignBitLeft,
  18. SubGhzProtocolBlockAlignBitRight,
  19. } SubGhzProtocolBlockAlignBit;
  20. /**
  21. * Set data bit when encoding HEX array.
  22. * @param bit_value The value of the bit to be set
  23. * @param data_array Pointer to a HEX array
  24. * @param set_index_bit Number set a bit in the array starting from the left
  25. * @param max_size_array array size, check not to overflow
  26. */
  27. void subghz_protocol_blocks_set_bit_array(
  28. bool bit_value,
  29. uint8_t data_array[],
  30. size_t set_index_bit,
  31. size_t max_size_array);
  32. /**
  33. * Get data bit when encoding HEX array.
  34. * @param data_array Pointer to a HEX array
  35. * @param read_index_bit Number get a bit in the array starting from the left
  36. * @return bool value bit
  37. */
  38. bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_index_bit);
  39. /**
  40. * Generating an upload from data.
  41. * @param data_array Pointer to a HEX array
  42. * @param count_bit_data_array How many bits in the array are processed
  43. * @param upload Pointer to a LevelDuration
  44. * @param max_size_upload upload size, check not to overflow
  45. * @param duration_bit duration 1 bit
  46. * @param align_bit alignment of useful bits in an array
  47. */
  48. size_t subghz_protocol_blocks_get_upload_from_bit_array(
  49. uint8_t data_array[],
  50. size_t count_bit_data_array,
  51. LevelDuration* upload,
  52. size_t max_size_upload,
  53. uint32_t duration_bit,
  54. SubGhzProtocolBlockAlignBit align_bit);
  55. #ifdef __cplusplus
  56. }
  57. #endif