subghz_protocol_common.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <m-string.h>
  3. #include <api-hal.h>
  4. #include <stdint.h>
  5. #define bit_read(value, bit) (((value) >> (bit)) & 0x01)
  6. #define bit_set(value, bit) ((value) |= (1UL << (bit)))
  7. #define bit_clear(value, bit) ((value) &= ~(1UL << (bit)))
  8. #define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
  9. #define SUBGHZ_TX_PIN_HIGTH()
  10. #define SUBGHZ_TX_PIN_LOW()
  11. #define DURATION_DIFF(x, y) ((x < y) ? (y - x) : (x - y))
  12. typedef struct SubGhzProtocolCommon SubGhzProtocolCommon;
  13. typedef void (*SubGhzProtocolCommonCallback)(SubGhzProtocolCommon* parser, void* context);
  14. typedef void (*SubGhzProtocolCommonToStr)(SubGhzProtocolCommon* instance, string_t output);
  15. struct SubGhzProtocolCommon {
  16. const char* name;
  17. uint16_t te_long;
  18. uint16_t te_shot;
  19. uint16_t te_delta;
  20. uint64_t code_found;
  21. uint64_t code_last_found;
  22. uint8_t code_count_bit;
  23. uint8_t code_min_count_bit_for_found;
  24. uint8_t parser_step;
  25. uint32_t te_last;
  26. uint8_t header_count;
  27. uint16_t cnt;
  28. uint32_t serial;
  29. uint8_t btn;
  30. /* Standard Callback for on rx complete event */
  31. SubGhzProtocolCommonCallback callback;
  32. void* context;
  33. /* Dump To String */
  34. SubGhzProtocolCommonToStr to_string;
  35. };
  36. /** Add data bit to code_found
  37. *
  38. * @param common - SubGhzProtocolCommon common
  39. * @param bit - add bit
  40. */
  41. void subghz_protocol_common_add_bit(SubGhzProtocolCommon *common, uint8_t bit);
  42. /** Checking that the duration is included in the interval
  43. *
  44. * @param common - SubGhzProtocolCommon common
  45. * @param duration duration reference
  46. * @param duration_check duration checked
  47. * @return true on success
  48. */
  49. bool subghz_protocol_common_check_interval(SubGhzProtocolCommon *common, uint32_t duration, uint16_t duration_check);
  50. /** Bit-by-bit data mirroring
  51. *
  52. * @param key - data to mirror
  53. * @param count_bit number of data bits
  54. * @return mirrored data
  55. */
  56. uint64_t subghz_protocol_common_reverse_key(uint64_t key, uint8_t count_bit);
  57. /** Callback protocol
  58. *
  59. * @param instance - SubGhzProtocolCommon* instance
  60. * @param callback
  61. * @param context
  62. */
  63. void subghz_protocol_common_set_callback(SubGhzProtocolCommon* instance, SubGhzProtocolCommonCallback callback, void* context);
  64. /** outputting information from the parser
  65. *
  66. * @param instance - SubGhzProtocolCommon* instance
  67. * @param output - output string
  68. */
  69. void subghz_protocol_common_to_str(SubGhzProtocolCommon* instance, string_t output);